diff options
Diffstat (limited to '')
-rw-r--r-- | LuaSL/src/LuaSL_compile.c | 99 |
1 files changed, 81 insertions, 18 deletions
diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c index 3488545..7457f0c 100644 --- a/LuaSL/src/LuaSL_compile.c +++ b/LuaSL/src/LuaSL_compile.c | |||
@@ -1837,33 +1837,90 @@ static void outputCrementsToken(FILE *file, outputMode mode, LSL_Leaf *content) | |||
1837 | { | 1837 | { |
1838 | if (content) | 1838 | if (content) |
1839 | { | 1839 | { |
1840 | switch (content->toKen->type) | 1840 | if (OM_LSL == mode) |
1841 | { | 1841 | { |
1842 | case LSL_DECREMENT_PRE : | 1842 | switch (content->toKen->type) |
1843 | case LSL_INCREMENT_PRE : | ||
1844 | { | 1843 | { |
1845 | fprintf(file, "%s", content->toKen->toKen); | 1844 | case LSL_DECREMENT_PRE : |
1845 | case LSL_INCREMENT_PRE : | ||
1846 | { | ||
1847 | fprintf(file, "%s", content->toKen->toKen); | ||
1846 | #if LUASL_DIFF_CHECK | 1848 | #if LUASL_DIFF_CHECK |
1847 | if (content->value.identifierValue->ignorable) | 1849 | if (content->value.identifierValue->ignorable) |
1848 | fwrite(eina_strbuf_string_get(content->value.identifierValue->ignorable), 1, eina_strbuf_length_get(content->value.identifierValue->ignorable), file); | 1850 | fwrite(eina_strbuf_string_get(content->value.identifierValue->ignorable), 1, eina_strbuf_length_get(content->value.identifierValue->ignorable), file); |
1849 | #endif | 1851 | #endif |
1850 | outputText(file, &(content->value.identifierValue->name), FALSE); | 1852 | outputText(file, &(content->value.identifierValue->name), FALSE); |
1851 | break; | 1853 | break; |
1854 | } | ||
1855 | case LSL_DECREMENT_POST : | ||
1856 | case LSL_INCREMENT_POST : | ||
1857 | { | ||
1858 | #if LUASL_DIFF_CHECK | ||
1859 | if (content->value.identifierValue->ignorable) | ||
1860 | fwrite(eina_strbuf_string_get(content->value.identifierValue->ignorable), 1, eina_strbuf_length_get(content->value.identifierValue->ignorable), file); | ||
1861 | #endif | ||
1862 | outputText(file, &(content->value.identifierValue->name), FALSE); | ||
1863 | fprintf(file, "%s", content->toKen->toKen); | ||
1864 | break; | ||
1865 | } | ||
1866 | default : | ||
1867 | break; | ||
1852 | } | 1868 | } |
1853 | case LSL_DECREMENT_POST : | 1869 | } |
1854 | case LSL_INCREMENT_POST : | 1870 | else if (OM_LUA == mode) |
1855 | { | 1871 | { |
1872 | /* | ||
1873 | This gets tricky, coz crements can be embedded inside other expressions. | ||
1874 | Even worse, assignment in Lua is a statement, NOT an expression. | ||
1875 | Tend to be used in for statements, but we convert those to whiles with seperate statements anyway. | ||
1876 | Tend to be used in conditionals to. | ||
1877 | For later - Lua does not have assignment shortcuts like +=, which can't help here either. | ||
1878 | */ | ||
1879 | switch (content->toKen->type) | ||
1880 | { | ||
1881 | case LSL_DECREMENT_PRE : | ||
1882 | case LSL_INCREMENT_PRE : | ||
1883 | { | ||
1884 | /* TODO - | ||
1885 | Damn, gotta put the function call out BEFORE the statment, which has alreadf been put out. | ||
1886 | */ | ||
1887 | outputText(file, &(content->value.identifierValue->name), FALSE); | ||
1888 | if (LSL_DECREMENT_PRE == content->toKen->type) | ||
1889 | fprintf(file, " = preDecrement("); | ||
1890 | else | ||
1891 | fprintf(file, " = preIncrement("); | ||
1856 | #if LUASL_DIFF_CHECK | 1892 | #if LUASL_DIFF_CHECK |
1857 | if (content->value.identifierValue->ignorable) | 1893 | if (content->value.identifierValue->ignorable) |
1858 | fwrite(eina_strbuf_string_get(content->value.identifierValue->ignorable), 1, eina_strbuf_length_get(content->value.identifierValue->ignorable), file); | 1894 | fwrite(eina_strbuf_string_get(content->value.identifierValue->ignorable), 1, eina_strbuf_length_get(content->value.identifierValue->ignorable), file); |
1859 | #endif | 1895 | #endif |
1860 | outputText(file, &(content->value.identifierValue->name), FALSE); | 1896 | outputText(file, &(content->value.identifierValue->name), FALSE); |
1861 | fprintf(file, "%s", content->toKen->toKen); | 1897 | fprintf(file, ")"); |
1862 | break; | 1898 | break; |
1899 | } | ||
1900 | case LSL_DECREMENT_POST : | ||
1901 | case LSL_INCREMENT_POST : | ||
1902 | { | ||
1903 | /* TODO - | ||
1904 | Find the end of the statement and put it there. | ||
1905 | */ | ||
1906 | outputText(file, &(content->value.identifierValue->name), FALSE); | ||
1907 | if (LSL_DECREMENT_POST == content->toKen->type) | ||
1908 | fprintf(file, " = postDecrement("); | ||
1909 | else | ||
1910 | fprintf(file, " = postIncrement("); | ||
1911 | #if LUASL_DIFF_CHECK | ||
1912 | if (content->value.identifierValue->ignorable) | ||
1913 | fwrite(eina_strbuf_string_get(content->value.identifierValue->ignorable), 1, eina_strbuf_length_get(content->value.identifierValue->ignorable), file); | ||
1914 | #endif | ||
1915 | outputText(file, &(content->value.identifierValue->name), FALSE); | ||
1916 | fprintf(file, ")"); | ||
1917 | break; | ||
1918 | } | ||
1919 | default : | ||
1920 | break; | ||
1863 | } | 1921 | } |
1864 | default : | ||
1865 | break; | ||
1866 | } | 1922 | } |
1923 | |||
1867 | } | 1924 | } |
1868 | } | 1925 | } |
1869 | 1926 | ||
@@ -2117,6 +2174,12 @@ static boolean doneParsing(LuaSL_compiler *compiler) | |||
2117 | out = fopen(luaName, "w"); | 2174 | out = fopen(luaName, "w"); |
2118 | if (out) | 2175 | if (out) |
2119 | { | 2176 | { |
2177 | fprintf(out, "--// Pre declared helper stuff.\n"); | ||
2178 | fprintf(out, "function preDecrement(x) x = x - 1; return x; end;\n"); | ||
2179 | fprintf(out, "function preIncrement(x) x = x + 1; return x; end;\n"); | ||
2180 | fprintf(out, "function postDecrement(x) x = x - 1; return x; end;\n"); | ||
2181 | fprintf(out, "function postIncrement(x) x = x + 1; return x; end;\n"); | ||
2182 | fprintf(out, "--// Generated code goes here.\n\n"); | ||
2120 | outputLeaf(out, OM_LUA, compiler->ast); | 2183 | outputLeaf(out, OM_LUA, compiler->ast); |
2121 | fclose(out); | 2184 | fclose(out); |
2122 | } | 2185 | } |