diff options
author | David Walter Seikel | 2012-02-02 15:46:04 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-02-02 15:46:04 +1000 |
commit | e2d2065555f9405f23a138d5aac408b26595dc99 (patch) | |
tree | b07c45bd868b10da536cf5171b1b137fd8f3f13d | |
parent | Old comment-- (diff) | |
download | SledjHamr-e2d2065555f9405f23a138d5aac408b26595dc99.zip SledjHamr-e2d2065555f9405f23a138d5aac408b26595dc99.tar.gz SledjHamr-e2d2065555f9405f23a138d5aac408b26595dc99.tar.bz2 SledjHamr-e2d2065555f9405f23a138d5aac408b26595dc99.tar.xz |
Some Lua conversions. Types, typecasts, blocks, list, vector, rotation.
-rw-r--r-- | LuaSL/src/LuaSL_LSL_tree.h | 3 | ||||
-rw-r--r-- | LuaSL/src/LuaSL_compile.c | 135 |
2 files changed, 102 insertions, 36 deletions
diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h index 00094b1..615a905 100644 --- a/LuaSL/src/LuaSL_LSL_tree.h +++ b/LuaSL/src/LuaSL_LSL_tree.h | |||
@@ -81,7 +81,8 @@ typedef enum | |||
81 | LSL_UNARY = 8, | 81 | LSL_UNARY = 8, |
82 | LSL_ASSIGNMENT = 16, | 82 | LSL_ASSIGNMENT = 16, |
83 | LSL_CREATION = 32, | 83 | LSL_CREATION = 32, |
84 | LSL_NOIGNORE = 64 | 84 | LSL_NOIGNORE = 64, |
85 | LSL_TYPE = 128 | ||
85 | } LSL_Flags; | 86 | } LSL_Flags; |
86 | 87 | ||
87 | 88 | ||
diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c index 5c59594..b4ed295 100644 --- a/LuaSL/src/LuaSL_compile.c +++ b/LuaSL/src/LuaSL_compile.c | |||
@@ -109,13 +109,13 @@ LSL_Token LSL_Tokens[] = | |||
109 | {LSL_VECTOR, ST_NONE, "vector", LSL_NONE, outputListToken, NULL}, | 109 | {LSL_VECTOR, ST_NONE, "vector", LSL_NONE, outputListToken, NULL}, |
110 | 110 | ||
111 | // Types names. | 111 | // Types names. |
112 | {LSL_TYPE_FLOAT, ST_NONE, "float", LSL_NONE, NULL, NULL}, | 112 | {LSL_TYPE_FLOAT, ST_NONE, "float", LSL_TYPE, NULL, NULL}, |
113 | {LSL_TYPE_INTEGER, ST_NONE, "integer", LSL_NONE, NULL, NULL}, | 113 | {LSL_TYPE_INTEGER, ST_NONE, "integer", LSL_TYPE, NULL, NULL}, |
114 | {LSL_TYPE_KEY, ST_NONE, "key", LSL_NONE, NULL, NULL}, | 114 | {LSL_TYPE_KEY, ST_NONE, "key", LSL_TYPE, NULL, NULL}, |
115 | {LSL_TYPE_LIST, ST_NONE, "list", LSL_NONE, NULL, NULL}, | 115 | {LSL_TYPE_LIST, ST_NONE, "list", LSL_TYPE, NULL, NULL}, |
116 | {LSL_TYPE_ROTATION, ST_NONE, "rotation", LSL_NONE, NULL, NULL}, | 116 | {LSL_TYPE_ROTATION, ST_NONE, "rotation", LSL_TYPE, NULL, NULL}, |
117 | {LSL_TYPE_STRING, ST_NONE, "string", LSL_NONE, NULL, NULL}, | 117 | {LSL_TYPE_STRING, ST_NONE, "string", LSL_TYPE, NULL, NULL}, |
118 | {LSL_TYPE_VECTOR, ST_NONE, "vector", LSL_NONE, NULL, NULL}, | 118 | {LSL_TYPE_VECTOR, ST_NONE, "vector", LSL_TYPE, NULL, NULL}, |
119 | 119 | ||
120 | // Then the rest of the syntax tokens. | 120 | // Then the rest of the syntax tokens. |
121 | {LSL_FUNCTION_CALL, ST_NONE, "funccall", LSL_NONE, outputFunctionCallToken, NULL}, | 121 | {LSL_FUNCTION_CALL, ST_NONE, "funccall", LSL_NONE, outputFunctionCallToken, NULL}, |
@@ -1495,7 +1495,12 @@ static void outputLeaf(FILE *file, outputMode mode, LSL_Leaf *leaf) | |||
1495 | if (leaf->toKen->output) | 1495 | if (leaf->toKen->output) |
1496 | leaf->toKen->output(file, mode, leaf); | 1496 | leaf->toKen->output(file, mode, leaf); |
1497 | else | 1497 | else |
1498 | fprintf(file, "%s", leaf->toKen->toKen); | 1498 | { |
1499 | if ((OM_LUA == mode) && (LSL_TYPE & leaf->toKen->flags)) | ||
1500 | fprintf(file, "--[[%s]] ", leaf->toKen->toKen); | ||
1501 | else | ||
1502 | fprintf(file, "%s", leaf->toKen->toKen); | ||
1503 | } | ||
1499 | outputLeaf(file, mode, leaf->right); | 1504 | outputLeaf(file, mode, leaf->right); |
1500 | } | 1505 | } |
1501 | } | 1506 | } |
@@ -1512,9 +1517,13 @@ static void outputRawBlock(FILE *file, outputMode mode, LSL_Block *block) | |||
1512 | #if LUASL_DIFF_CHECK | 1517 | #if LUASL_DIFF_CHECK |
1513 | if (block->openIgnorable) | 1518 | if (block->openIgnorable) |
1514 | fwrite(eina_strbuf_string_get(block->openIgnorable), 1, eina_strbuf_length_get(block->openIgnorable), file); | 1519 | fwrite(eina_strbuf_string_get(block->openIgnorable), 1, eina_strbuf_length_get(block->openIgnorable), file); |
1515 | fprintf(file, "{"); | 1520 | if (OM_LSL == mode) |
1521 | fprintf(file, "{"); | ||
1516 | #else | 1522 | #else |
1517 | fprintf(file, "\n{\n"); | 1523 | if (OM_LSL == mode) |
1524 | fprintf(file, "\n{\n"); | ||
1525 | else if (OM_LUA == mode) | ||
1526 | fprintf(file, "\n"); | ||
1518 | #endif | 1527 | #endif |
1519 | EINA_CLIST_FOR_EACH_ENTRY(stat, &(block->statements), LSL_Statement, statement) | 1528 | EINA_CLIST_FOR_EACH_ENTRY(stat, &(block->statements), LSL_Statement, statement) |
1520 | { | 1529 | { |
@@ -1524,12 +1533,22 @@ static void outputRawBlock(FILE *file, outputMode mode, LSL_Block *block) | |||
1524 | if (block->closeIgnorable) | 1533 | if (block->closeIgnorable) |
1525 | fwrite(eina_strbuf_string_get(block->closeIgnorable), 1, eina_strbuf_length_get(block->closeIgnorable), file); | 1534 | fwrite(eina_strbuf_string_get(block->closeIgnorable), 1, eina_strbuf_length_get(block->closeIgnorable), file); |
1526 | #endif | 1535 | #endif |
1527 | fprintf(file, "}"); | 1536 | if (OM_LSL == mode) |
1537 | fprintf(file, "}"); | ||
1538 | else if (OM_LUA == mode) | ||
1539 | fprintf(file, "end "); | ||
1528 | } | 1540 | } |
1529 | } | 1541 | } |
1530 | 1542 | ||
1531 | static void outputRawParenthesisToken(FILE *file, outputMode mode, LSL_Parenthesis *parenthesis, const char *typeName) | 1543 | static void outputRawParenthesisToken(FILE *file, outputMode mode, LSL_Parenthesis *parenthesis, const char *typeName) |
1532 | { | 1544 | { |
1545 | if ((OM_LUA == mode) && (LSL_TYPECAST_OPEN == parenthesis->type)) | ||
1546 | { | ||
1547 | fprintf(file, "--[[(%s)]] ", typeName); | ||
1548 | outputLeaf(file, mode, parenthesis->contents); | ||
1549 | return; | ||
1550 | } | ||
1551 | |||
1533 | fprintf(file, "("); | 1552 | fprintf(file, "("); |
1534 | if (LSL_TYPECAST_OPEN == parenthesis->type) | 1553 | if (LSL_TYPECAST_OPEN == parenthesis->type) |
1535 | fprintf(file, "%s", typeName); // TODO - We are missing the type ignorable text here. | 1554 | fprintf(file, "%s", typeName); // TODO - We are missing the type ignorable text here. |
@@ -1769,24 +1788,44 @@ static void outputFunctionToken(FILE *file, outputMode mode, LSL_Leaf *content) | |||
1769 | LSL_Leaf *param = NULL; | 1788 | LSL_Leaf *param = NULL; |
1770 | int first = TRUE; | 1789 | int first = TRUE; |
1771 | 1790 | ||
1772 | outputText(file, &(func->type), !(LSL_NOIGNORE & content->toKen->flags)); | 1791 | if (OM_LSL == mode) |
1773 | outputText(file, &(func->name), !(LSL_NOIGNORE & content->toKen->flags)); | ||
1774 | // TODO - should print comma and parenthesis ignorables. | ||
1775 | fprintf(file, "("); | ||
1776 | EINA_INARRAY_FOREACH((&(func->vars)), param) | ||
1777 | { | 1792 | { |
1778 | if (!LUASL_DIFF_CHECK) | 1793 | outputText(file, &(func->type), !(LSL_NOIGNORE & content->toKen->flags)); |
1794 | outputText(file, &(func->name), !(LSL_NOIGNORE & content->toKen->flags)); | ||
1795 | // TODO - should print comma and parenthesis ignorables. | ||
1796 | fprintf(file, "("); | ||
1797 | EINA_INARRAY_FOREACH((&(func->vars)), param) | ||
1779 | { | 1798 | { |
1780 | if (!first) | 1799 | if (!LUASL_DIFF_CHECK) |
1781 | fprintf(file, ", "); | 1800 | { |
1801 | if (!first) | ||
1802 | fprintf(file, ", "); | ||
1803 | } | ||
1804 | outputLeaf(file, mode, param); | ||
1805 | first = FALSE; | ||
1782 | } | 1806 | } |
1783 | outputLeaf(file, mode, param); | 1807 | fprintf(file, ")"); |
1784 | first = FALSE; | 1808 | outputRawBlock(file, mode, func->block); |
1809 | if (!LUASL_DIFF_CHECK) | ||
1810 | fprintf(file, "\n"); | ||
1811 | } | ||
1812 | else if (OM_LUA == mode) | ||
1813 | { | ||
1814 | fprintf(file, "\n\nfunction "); | ||
1815 | if (func->type.text) | ||
1816 | fprintf(file, "--[[%s]] ", func->type.text); | ||
1817 | fprintf(file, "%s(", func->name.text); | ||
1818 | EINA_INARRAY_FOREACH((&(func->vars)), param) | ||
1819 | { | ||
1820 | // TODO - comment out param types. | ||
1821 | // if (!first) | ||
1822 | // fprintf(file, ", "); | ||
1823 | outputLeaf(file, mode, param); | ||
1824 | first = FALSE; | ||
1825 | } | ||
1826 | fprintf(file, ")"); | ||
1827 | outputRawBlock(file, mode, func->block); | ||
1785 | } | 1828 | } |
1786 | fprintf(file, ")"); | ||
1787 | outputRawBlock(file, mode, func->block); | ||
1788 | if (!LUASL_DIFF_CHECK) | ||
1789 | fprintf(file, "\n"); | ||
1790 | } | 1829 | } |
1791 | } | 1830 | } |
1792 | 1831 | ||
@@ -1842,12 +1881,25 @@ static void outputListToken(FILE *file, outputMode mode, LSL_Leaf *content) | |||
1842 | const char *ig = ""; | 1881 | const char *ig = ""; |
1843 | 1882 | ||
1844 | // TODO - should output it's own ignorable here. | 1883 | // TODO - should output it's own ignorable here. |
1845 | switch (parens->type) | 1884 | if (OM_LSL == mode) |
1885 | { | ||
1886 | switch (parens->type) | ||
1887 | { | ||
1888 | case LSL_LIST : fprintf(file, "["); break; | ||
1889 | case LSL_ROTATION : | ||
1890 | case LSL_VECTOR : fprintf(file, "<"); | ||
1891 | default : break; | ||
1892 | } | ||
1893 | } | ||
1894 | else if (OM_LUA == mode) | ||
1846 | { | 1895 | { |
1847 | case LSL_LIST : fprintf(file, "["); break; | 1896 | switch (parens->type) |
1848 | case LSL_ROTATION : | 1897 | { |
1849 | case LSL_VECTOR : fprintf(file, "<"); | 1898 | case LSL_LIST : fprintf(file, "{"); break; |
1850 | default : break; | 1899 | case LSL_ROTATION : |
1900 | case LSL_VECTOR : fprintf(file, "{"); | ||
1901 | default : break; | ||
1902 | } | ||
1851 | } | 1903 | } |
1852 | EINA_INARRAY_FOREACH((&(call->params)), param) | 1904 | EINA_INARRAY_FOREACH((&(call->params)), param) |
1853 | { | 1905 | { |
@@ -1856,12 +1908,25 @@ static void outputListToken(FILE *file, outputMode mode, LSL_Leaf *content) | |||
1856 | #if LUASL_DIFF_CHECK | 1908 | #if LUASL_DIFF_CHECK |
1857 | ig = eina_strbuf_string_get(parens->rightIgnorable); | 1909 | ig = eina_strbuf_string_get(parens->rightIgnorable); |
1858 | #endif | 1910 | #endif |
1859 | switch (parens->type) | 1911 | if (OM_LSL == mode) |
1860 | { | 1912 | { |
1861 | case LSL_LIST : fprintf(file, "%s]", ig); break; | 1913 | switch (parens->type) |
1862 | case LSL_ROTATION : | 1914 | { |
1863 | case LSL_VECTOR : fprintf(file, "%s>", ig); | 1915 | case LSL_LIST : fprintf(file, "%s]", ig); break; |
1864 | default : break; | 1916 | case LSL_ROTATION : |
1917 | case LSL_VECTOR : fprintf(file, "%s>", ig); | ||
1918 | default : break; | ||
1919 | } | ||
1920 | } | ||
1921 | else if (OM_LUA == mode) | ||
1922 | { | ||
1923 | switch (parens->type) | ||
1924 | { | ||
1925 | case LSL_LIST : fprintf(file, "%s}", ig); break; | ||
1926 | case LSL_ROTATION : | ||
1927 | case LSL_VECTOR : fprintf(file, "%s}", ig); | ||
1928 | default : break; | ||
1929 | } | ||
1865 | } | 1930 | } |
1866 | } | 1931 | } |
1867 | } | 1932 | } |