aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/src
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-02-03 23:59:13 +1000
committerDavid Walter Seikel2012-02-03 23:59:13 +1000
commitd042b1e2fb8418059f2acef4e5fb803cb73e183f (patch)
treea851a00d903441d605004d5178f21ea2f9cc83ec /LuaSL/src
parentAssignments in the middle of expressions is legal in LSL, but not in Lua. Bu... (diff)
downloadSledjHamr-d042b1e2fb8418059f2acef4e5fb803cb73e183f.zip
SledjHamr-d042b1e2fb8418059f2acef4e5fb803cb73e183f.tar.gz
SledjHamr-d042b1e2fb8418059f2acef4e5fb803cb73e183f.tar.bz2
SledjHamr-d042b1e2fb8418059f2acef4e5fb803cb73e183f.tar.xz
Implement basic states.
Diffstat (limited to 'LuaSL/src')
-rw-r--r--LuaSL/src/LuaSL_LSL_tree.h1
-rw-r--r--LuaSL/src/LuaSL_compile.c27
2 files changed, 22 insertions, 6 deletions
diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h
index 2a66bd7..8909c7e 100644
--- a/LuaSL/src/LuaSL_LSL_tree.h
+++ b/LuaSL/src/LuaSL_LSL_tree.h
@@ -293,6 +293,7 @@ struct _LSL_Function
293{ 293{
294 LSL_Text name; 294 LSL_Text name;
295 LSL_Text type; 295 LSL_Text type;
296 const char *state;
296#if LUASL_DIFF_CHECK 297#if LUASL_DIFF_CHECK
297// LSL_Leaf *params; // So we store the parenthesis, and their ignorables. 298// LSL_Leaf *params; // So we store the parenthesis, and their ignorables.
298 // This points to the params leaf, which is a function, pointing to this structure. The actual params are in vars. 299 // This points to the params leaf, which is a function, pointing to this structure. The actual params are in vars.
diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c
index 8194947..66f5174 100644
--- a/LuaSL/src/LuaSL_compile.c
+++ b/LuaSL/src/LuaSL_compile.c
@@ -856,6 +856,9 @@ LSL_Leaf *addState(LuaSL_compiler *compiler, LSL_Leaf *state, LSL_Leaf *identifi
856 856
857 if ((identifier) && (result)) 857 if ((identifier) && (result))
858 { 858 {
859 Eina_Iterator *handlers;
860 LSL_Function *func;
861
859 memcpy(result, &(compiler->state), sizeof(LSL_State)); 862 memcpy(result, &(compiler->state), sizeof(LSL_State));
860 compiler->state.block = NULL; 863 compiler->state.block = NULL;
861 compiler->state.handlers = NULL; 864 compiler->state.handlers = NULL;
@@ -864,6 +867,11 @@ LSL_Leaf *addState(LuaSL_compiler *compiler, LSL_Leaf *state, LSL_Leaf *identifi
864 result->name.ignorable = identifier->ignorable; 867 result->name.ignorable = identifier->ignorable;
865 identifier->ignorable = NULL; 868 identifier->ignorable = NULL;
866#endif 869#endif
870 handlers = eina_hash_iterator_data_new(result->handlers);
871 while(eina_iterator_next(handlers, (void **) &func))
872 {
873 func->state = result->name.text;
874 }
867 result->block = block->value.blockValue; 875 result->block = block->value.blockValue;
868 if (state) 876 if (state)
869 { 877 {
@@ -2085,10 +2093,15 @@ static void outputFunctionToken(FILE *file, outputMode mode, LSL_Leaf *content)
2085 } 2093 }
2086 else if (OM_LUA == mode) 2094 else if (OM_LUA == mode)
2087 { 2095 {
2088 fprintf(file, "\n\nfunction "); 2096 if (func->state)
2089 if (func->type.text) 2097 fprintf(file, "\n\n%s.%s = function(", func->state, func->name.text);
2090 fprintf(file, " --[[%s]] ", func->type.text); 2098 else
2091 fprintf(file, "%s(", func->name.text); 2099 {
2100 fprintf(file, "\n\nfunction ");
2101 if (func->type.text)
2102 fprintf(file, " --[[%s]] ", func->type.text);
2103 fprintf(file, "%s(", func->name.text);
2104 }
2092 EINA_INARRAY_FOREACH((&(func->vars)), param) 2105 EINA_INARRAY_FOREACH((&(func->vars)), param)
2093 { 2106 {
2094 // TODO - comment out param types. 2107 // TODO - comment out param types.
@@ -2323,14 +2336,16 @@ static boolean doneParsing(LuaSL_compiler *compiler)
2323 { 2336 {
2324 fprintf(out, "--// Pre declared helper stuff.\n"); 2337 fprintf(out, "--// Pre declared helper stuff.\n");
2325 fprintf(out, "local bit = require(\"bit\")\n"); 2338 fprintf(out, "local bit = require(\"bit\")\n");
2339 fprintf(out, "currentState = { state_exit = function() end }\n");
2326 fprintf(out, "function preDecrement(name) _G[name] = _G[name] - 1; return _G[name]; end;\n"); 2340 fprintf(out, "function preDecrement(name) _G[name] = _G[name] - 1; return _G[name]; end;\n");
2327 fprintf(out, "function preIncrement(name) _G[name] = _G[name] + 1; return _G[name]; end;\n"); 2341 fprintf(out, "function preIncrement(name) _G[name] = _G[name] + 1; return _G[name]; end;\n");
2328 fprintf(out, "function postDecrement(name) local temp = _G[name]; _G[name] = _G[name] - 1; return temp; end;\n"); 2342 fprintf(out, "function postDecrement(name) local temp = _G[name]; _G[name] = _G[name] - 1; return temp; end;\n");
2329 fprintf(out, "function postIncrement(name) local temp = _G[name]; _G[name] = _G[name] + 1; return temp; end;\n"); 2343 fprintf(out, "function postIncrement(name) local temp = _G[name]; _G[name] = _G[name] + 1; return temp; end;\n");
2330 fprintf(out, "function stateChange(x) end;\n"); 2344 fprintf(out, "function stateChange(x) currentState.state_exit(); curruntState = x; currentState.state_entry(); end;\n");
2331 fprintf(out, "--// Generated code goes here.\n\n"); 2345 fprintf(out, "--// Generated code goes here.\n\n");
2332 outputLeaf(out, OM_LUA, compiler->ast); 2346 outputLeaf(out, OM_LUA, compiler->ast);
2333 fprintf(out, "\n\n--// End of generated code.\n\n"); 2347// fprintf(out, "\n\nstateChange(default)\n");
2348 fprintf(out, "\n--// End of generated code.\n\n");
2334 fclose(out); 2349 fclose(out);
2335 sprintf(buffer, "../../libraries/luajit-2.0/src/luajit \"%s\"", luaName); 2350 sprintf(buffer, "../../libraries/luajit-2.0/src/luajit \"%s\"", luaName);
2336 count = system(buffer); 2351 count = system(buffer);