aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-01-21 16:09:59 +1000
committerDavid Walter Seikel2012-01-21 16:09:59 +1000
commit77e246b31f8892594d389a75e5f9b4cfe5c25315 (patch)
tree863b5b827f00fd860c2c1c91ae4a21b640ed4743
parentComments about LSL identifier quirks. (diff)
downloadSledjHamr-77e246b31f8892594d389a75e5f9b4cfe5c25315.zip
SledjHamr-77e246b31f8892594d389a75e5f9b4cfe5c25315.tar.gz
SledjHamr-77e246b31f8892594d389a75e5f9b4cfe5c25315.tar.bz2
SledjHamr-77e246b31f8892594d389a75e5f9b4cfe5c25315.tar.xz
Parse function calls, at least the basics.
-rw-r--r--LuaSL/src/LuaSL_LSL_tree.h1
-rw-r--r--LuaSL/src/LuaSL_compile.c49
2 files changed, 49 insertions, 1 deletions
diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h
index 41435ff..54cc0d8 100644
--- a/LuaSL/src/LuaSL_LSL_tree.h
+++ b/LuaSL/src/LuaSL_LSL_tree.h
@@ -324,6 +324,7 @@ typedef struct
324void burnLeaf(void *data); 324void burnLeaf(void *data);
325LSL_Leaf *addFunction(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *open, LSL_Leaf *params, LSL_Leaf *close); 325LSL_Leaf *addFunction(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *open, LSL_Leaf *params, LSL_Leaf *close);
326LSL_Leaf *addFunctionBody(LuaSL_compiler *compiler, LSL_Leaf *function, LSL_Leaf *block); 326LSL_Leaf *addFunctionBody(LuaSL_compiler *compiler, LSL_Leaf *function, LSL_Leaf *block);
327LSL_Leaf *addFunctionCall(LuaSL_compiler *compiler, LSL_Leaf *identifier, LSL_Leaf *open, LSL_Leaf *params, LSL_Leaf *close);
327LSL_Leaf *addOperation(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right); 328LSL_Leaf *addOperation(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right);
328LSL_Leaf *addParameter(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *newParam); 329LSL_Leaf *addParameter(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *newParam);
329LSL_Leaf *addParenthesis(LSL_Leaf *lval, LSL_Leaf *expr, LSL_Type type, LSL_Leaf *rval); 330LSL_Leaf *addParenthesis(LSL_Leaf *lval, LSL_Leaf *expr, LSL_Type type, LSL_Leaf *rval);
diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c
index 0b15215..4feba5a 100644
--- a/LuaSL/src/LuaSL_compile.c
+++ b/LuaSL/src/LuaSL_compile.c
@@ -114,6 +114,7 @@ LSL_Token LSL_Tokens[] =
114 {LSL_TYPE_VECTOR, ST_NONE, "vector", LSL_NONE, NULL, NULL}, 114 {LSL_TYPE_VECTOR, ST_NONE, "vector", LSL_NONE, NULL, NULL},
115 115
116 // Then the rest of the syntax tokens. 116 // Then the rest of the syntax tokens.
117 {LSL_FUNCTION_CALL, ST_NONE, "funccall", LSL_NONE, NULL, NULL},
117 {LSL_IDENTIFIER, ST_NONE, "identifier", LSL_NONE, outputIdentifierToken, NULL}, 118 {LSL_IDENTIFIER, ST_NONE, "identifier", LSL_NONE, outputIdentifierToken, NULL},
118 119
119 {LSL_LABEL, ST_NONE, "@", LSL_NONE, NULL, NULL}, 120 {LSL_LABEL, ST_NONE, "@", LSL_NONE, NULL, NULL},
@@ -236,6 +237,21 @@ void burnLeaf(void *data)
236 } 237 }
237} 238}
238 239
240static LSL_Leaf *findFunction(LuaSL_compiler *compiler, const char *name)
241{
242 LSL_Leaf *func = NULL;
243
244 if (name)
245 {
246 if (NULL == func)
247 func = eina_hash_find(constants.functions, name);
248 if (NULL == func)
249 func = eina_hash_find(compiler->script.functions, name);
250 }
251
252 return func;
253}
254
239static LSL_Leaf *findVariable(LuaSL_compiler *compiler, const char *name) 255static LSL_Leaf *findVariable(LuaSL_compiler *compiler, const char *name)
240{ 256{
241 LSL_Leaf *var = NULL; 257 LSL_Leaf *var = NULL;
@@ -273,13 +289,28 @@ static LSL_Leaf *findVariable(LuaSL_compiler *compiler, const char *name)
273 return var; 289 return var;
274} 290}
275 291
292LSL_Leaf *checkFunction(LuaSL_compiler *compiler, LSL_Leaf *identifier)
293{
294 gameGlobals *game = compiler->game;
295 LSL_Leaf *func = findFunction(compiler, identifier->value.stringValue);
296
297 if (NULL == func)
298 PE("NOT found %s @ line %d column %d!", identifier->value.stringValue, identifier->line, identifier->column);
299#ifdef LUASL_DEBUG
300 else
301 PI("Found %s!", identifier->value.stringValue);
302#endif
303
304 return func;
305}
306
276LSL_Leaf *checkVariable(LuaSL_compiler *compiler, LSL_Leaf *identifier) 307LSL_Leaf *checkVariable(LuaSL_compiler *compiler, LSL_Leaf *identifier)
277{ 308{
278 gameGlobals *game = compiler->game; 309 gameGlobals *game = compiler->game;
279 LSL_Leaf *var = findVariable(compiler, identifier->value.stringValue); 310 LSL_Leaf *var = findVariable(compiler, identifier->value.stringValue);
280 311
281 if (NULL == var) 312 if (NULL == var)
282 PE("NOT found %s!", identifier->value.stringValue); 313 PE("NOT found %s @ line %d column %d!", identifier->value.stringValue, identifier->line, identifier->column);
283#ifdef LUASL_DEBUG 314#ifdef LUASL_DEBUG
284 else 315 else
285 PI("Found %s!", identifier->value.stringValue); 316 PI("Found %s!", identifier->value.stringValue);
@@ -502,6 +533,22 @@ LSL_Leaf *addFunctionBody(LuaSL_compiler *compiler, LSL_Leaf *function, LSL_Leaf
502 return function; 533 return function;
503} 534}
504 535
536LSL_Leaf *addFunctionCall(LuaSL_compiler *compiler, LSL_Leaf *identifier, LSL_Leaf *open, LSL_Leaf *params, LSL_Leaf *close)
537{
538 LSL_Leaf *func = checkFunction(compiler, identifier);
539
540 identifier->token = tokens[LSL_UNKNOWN - lowestToken];
541
542 if (func)
543 {
544 // TODO - Add some structure here to hold the params.
545 identifier->token = tokens[LSL_FUNCTION_CALL - lowestToken];
546 identifier->basicType = func->basicType;
547 }
548
549 return identifier;
550}
551
505LSL_Leaf *addParenthesis(LSL_Leaf *lval, LSL_Leaf *expr, LSL_Type type, LSL_Leaf *rval) 552LSL_Leaf *addParenthesis(LSL_Leaf *lval, LSL_Leaf *expr, LSL_Type type, LSL_Leaf *rval)
506{ 553{
507 LSL_Parenthesis *parens = calloc(1, sizeof(LSL_Parenthesis)); 554 LSL_Parenthesis *parens = calloc(1, sizeof(LSL_Parenthesis));