aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--LuaSL/src/LuaSL_LSL_tree.h7
-rw-r--r--LuaSL/src/LuaSL_compile.c106
2 files changed, 59 insertions, 54 deletions
diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h
index 9f1aaee..4858d99 100644
--- a/LuaSL/src/LuaSL_LSL_tree.h
+++ b/LuaSL/src/LuaSL_LSL_tree.h
@@ -150,7 +150,11 @@ typedef enum
150{ 150{
151 MF_NONE = 0, 151 MF_NONE = 0,
152 MF_LOCAL = 1, 152 MF_LOCAL = 1,
153 MF_NOASSIGN = 2 153 MF_NOASSIGN = 2,
154 MF_PREDEC = 4,
155 MF_PREINC = 8,
156 MF_POSTDEC = 16,
157 MF_POSTINC = 32
154} miscFlags; 158} miscFlags;
155 159
156struct _allowedTypes 160struct _allowedTypes
@@ -236,6 +240,7 @@ struct _LSL_Identifier // For variables and function parameters.
236 Eina_Strbuf *ignorable; 240 Eina_Strbuf *ignorable;
237 const char *sub; 241 const char *sub;
238 LSL_Leaf value; 242 LSL_Leaf value;
243 miscFlags flags;
239}; 244};
240 245
241struct _LSL_Statement 246struct _LSL_Statement
diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c
index a73233d..ea3a2ef 100644
--- a/LuaSL/src/LuaSL_compile.c
+++ b/LuaSL/src/LuaSL_compile.c
@@ -523,6 +523,13 @@ LSL_Leaf *addCrement(LuaSL_compiler *compiler, LSL_Leaf *variable, LSL_Leaf *cre
523#endif 523#endif
524 crement->basicType = variable->basicType; 524 crement->basicType = variable->basicType;
525 crement->toKen = tokens[type - lowestToken]; 525 crement->toKen = tokens[type - lowestToken];
526 switch (crement->toKen->type)
527 {
528 case LSL_DECREMENT_PRE : variable->value.identifierValue->flags |= MF_PREDEC; break;
529 case LSL_INCREMENT_PRE : variable->value.identifierValue->flags |= MF_PREINC; break;
530 case LSL_DECREMENT_POST : variable->value.identifierValue->flags |= MF_POSTDEC; break;
531 case LSL_INCREMENT_POST : variable->value.identifierValue->flags |= MF_POSTINC; break;
532 }
526 } 533 }
527 534
528 return crement; 535 return crement;
@@ -1098,7 +1105,11 @@ LSL_Leaf *addVariable(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identi
1098 if (type) 1105 if (type)
1099 { 1106 {
1100 if (compiler->currentBlock) 1107 if (compiler->currentBlock)
1108 {
1109 identifier->flags |= MF_LOCAL;
1110 result->flags |= MF_LOCAL;
1101 type->flags |= MF_LOCAL; 1111 type->flags |= MF_LOCAL;
1112 }
1102 identifier->basicType = type->basicType; 1113 identifier->basicType = type->basicType;
1103 result->value.basicType = type->basicType; 1114 result->value.basicType = type->basicType;
1104 result->value.toKen = type->toKen; // This is the LSL_TYPE_* toKen instead of the LSL_* toKen. Not sure if that's a problem. 1115 result->value.toKen = type->toKen; // This is the LSL_TYPE_* toKen instead of the LSL_* toKen. Not sure if that's a problem.
@@ -1934,60 +1945,29 @@ static void outputCrementsToken(FILE *file, outputMode mode, LSL_Leaf *content)
1934 } 1945 }
1935 else if (OM_LUA == mode) 1946 else if (OM_LUA == mode)
1936 { 1947 {
1937 /*
1938 This gets tricky, coz crements can be embedded inside other expressions.
1939 Even worse, assignment in Lua is a statement, NOT an expression.
1940 Tend to be used in for statements, but we convert those to whiles with seperate statements anyway.
1941 Tend to be used in conditionals to.
1942 For later - Lua does not have assignment shortcuts like +=, which can't help here either.
1943 */
1944 switch (content->toKen->type) 1948 switch (content->toKen->type)
1945 { 1949 {
1946 case LSL_DECREMENT_PRE : 1950 case LSL_DECREMENT_PRE : fprintf(file, " preDecrement"); break;
1947 case LSL_INCREMENT_PRE : 1951 case LSL_INCREMENT_PRE : fprintf(file, " preIncrement"); break;
1948 { 1952 case LSL_DECREMENT_POST : fprintf(file, " postDecrement"); break;
1949 /* TODO - 1953 case LSL_INCREMENT_POST : fprintf(file, " postIncrement"); break;
1950 Damn, gotta put the function call out BEFORE the statment, which has already been put out.
1951 Trickier case - while (++i)
1952 */
1953// outputText(file, &(content->value.identifierValue->name), FALSE);
1954 if (LSL_DECREMENT_PRE == content->toKen->type)
1955 fprintf(file, " preDecrement(");
1956 else
1957 fprintf(file, " preIncrement(");
1958#if LUASL_DIFF_CHECK
1959 if (content->value.identifierValue->ignorable)
1960 fwrite(eina_strbuf_string_get(content->value.identifierValue->ignorable), 1, eina_strbuf_length_get(content->value.identifierValue->ignorable), file);
1961#endif
1962 outputText(file, &(content->value.identifierValue->name), FALSE);
1963 fprintf(file, ")");
1964 break;
1965 }
1966 case LSL_DECREMENT_POST :
1967 case LSL_INCREMENT_POST :
1968 {
1969 /* TODO -
1970 Find the end of the statement and put it there.
1971 Bound to be a trickier case as above. lol
1972 */
1973// outputText(file, &(content->value.identifierValue->name), FALSE);
1974 if (LSL_DECREMENT_POST == content->toKen->type)
1975 fprintf(file, " postDecrement(");
1976 else
1977 fprintf(file, " postIncrement(");
1978#if LUASL_DIFF_CHECK
1979 if (content->value.identifierValue->ignorable)
1980 fwrite(eina_strbuf_string_get(content->value.identifierValue->ignorable), 1, eina_strbuf_length_get(content->value.identifierValue->ignorable), file);
1981#endif
1982 outputText(file, &(content->value.identifierValue->name), FALSE);
1983 fprintf(file, ")");
1984 break;
1985 }
1986 default : 1954 default :
1987 break; 1955 break;
1988 } 1956 }
1957 if (MF_LOCAL & content->value.identifierValue->flags)
1958 fprintf(file, "_");
1959 else
1960 fprintf(file, "(\"");
1961#if LUASL_DIFF_CHECK
1962 if (content->value.identifierValue->ignorable)
1963 fwrite(eina_strbuf_string_get(content->value.identifierValue->ignorable), 1, eina_strbuf_length_get(content->value.identifierValue->ignorable), file);
1964#endif
1965 outputText(file, &(content->value.identifierValue->name), FALSE);
1966 if (MF_LOCAL & content->value.identifierValue->flags)
1967 fprintf(file, "()");
1968 else
1969 fprintf(file, "\")");
1989 } 1970 }
1990
1991 } 1971 }
1992} 1972}
1993 1973
@@ -2091,10 +2071,29 @@ static void outputIdentifierToken(FILE *file, outputMode mode, LSL_Leaf *content
2091 if ((LSL_VARIABLE == content->toKen->type) && (MF_NOASSIGN & content->flags)) 2071 if ((LSL_VARIABLE == content->toKen->type) && (MF_NOASSIGN & content->flags))
2092 { 2072 {
2093 outputText(file, &(content->value.identifierValue->name), !(LSL_NOIGNORE & content->toKen->flags)); 2073 outputText(file, &(content->value.identifierValue->name), !(LSL_NOIGNORE & content->toKen->flags));
2094 fprintf(file, " = nil"); 2074 if (OM_LUA == mode)
2075 {
2076 // TODO - should output a default value depending on type.
2077 fprintf(file, " = nil");
2078 }
2095 } 2079 }
2096 else 2080 else
2097 outputText(file, &(content->value.identifierValue->name), !(LSL_NOIGNORE & content->toKen->flags)); 2081 outputText(file, &(content->value.identifierValue->name), !(LSL_NOIGNORE & content->toKen->flags));
2082
2083 if (OM_LUA == mode)
2084 {
2085 if ((LSL_VARIABLE == content->toKen->type) && (MF_LOCAL & content->flags))
2086 {
2087 const char *name = content->value.identifierValue->name.text;
2088
2089 if ((MF_PREDEC | MF_PREINC | MF_POSTDEC | MF_POSTINC) & content->value.identifierValue->flags)
2090 fprintf(file, "\n");
2091 if (MF_PREDEC & content->value.identifierValue->flags) fprintf(file, "local function preDecrement_%s() %s = %s - 1; return %s; end\n", name, name, name, name);
2092 if (MF_PREINC & content->value.identifierValue->flags) fprintf(file, "local function preIncrement_%s() %s = %s + 1; return %s; end\n", name, name, name, name);
2093 if (MF_POSTDEC & content->value.identifierValue->flags) fprintf(file, "local function postDecrement_%s() local temp = %s; %s = %s - 1; return temp; end\n", name, name, name, name);
2094 if (MF_POSTDEC & content->value.identifierValue->flags) fprintf(file, "local function postDecrement_%s() local temp = %s; %s = %s + 1; return temp; end\n", name, name, name, name);
2095 }
2096 }
2098 } 2097 }
2099} 2098}
2100 2099
@@ -2168,6 +2167,7 @@ static void outputParameterListToken(FILE *file, outputMode mode, LSL_Leaf *cont
2168{ 2167{
2169 if (content) 2168 if (content)
2170 outputLeaf(file, mode, content->value.listValue); 2169 outputLeaf(file, mode, content->value.listValue);
2170 // TODO - Should go through the list, and output any crements functions we need at the top of the block.
2171} 2171}
2172 2172
2173static void outputParenthesisToken(FILE *file, outputMode mode, LSL_Leaf *content) 2173static void outputParenthesisToken(FILE *file, outputMode mode, LSL_Leaf *content)
@@ -2261,10 +2261,10 @@ static boolean doneParsing(LuaSL_compiler *compiler)
2261 { 2261 {
2262 fprintf(out, "--// Pre declared helper stuff.\n"); 2262 fprintf(out, "--// Pre declared helper stuff.\n");
2263 fprintf(out, "local bit = require(\"bit\")\n"); 2263 fprintf(out, "local bit = require(\"bit\")\n");
2264 fprintf(out, "function preDecrement(x) x = x - 1; return x; end;\n"); 2264 fprintf(out, "function preDecrement(name) _G[name] = _G[name] - 1; return _G[name]; end;\n");
2265 fprintf(out, "function preIncrement(x) x = x + 1; return x; end;\n"); 2265 fprintf(out, "function preIncrement(name) _G[name] = _G[name] + 1; return _G[name]; end;\n");
2266 fprintf(out, "function postDecrement(x) x = x - 1; return x; end;\n"); 2266 fprintf(out, "function postDecrement(name) local temp = _G[name]; _G[name] = _G[name] - 1; return temp; end;\n");
2267 fprintf(out, "function postIncrement(x) x = x + 1; return x; end;\n"); 2267 fprintf(out, "function postIncrement(name) local temp = _G[name]; _G[name] = _G[name] + 1; return temp; end;\n");
2268 fprintf(out, "function stateChange(x) end;\n"); 2268 fprintf(out, "function stateChange(x) end;\n");
2269 fprintf(out, "--// Generated code goes here.\n\n"); 2269 fprintf(out, "--// Generated code goes here.\n\n");
2270 outputLeaf(out, OM_LUA, compiler->ast); 2270 outputLeaf(out, OM_LUA, compiler->ast);