From 77e246b31f8892594d389a75e5f9b4cfe5c25315 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sat, 21 Jan 2012 16:09:59 +1000 Subject: Parse function calls, at least the basics. --- LuaSL/src/LuaSL_LSL_tree.h | 1 + LuaSL/src/LuaSL_compile.c | 49 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) 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 void burnLeaf(void *data); LSL_Leaf *addFunction(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *open, LSL_Leaf *params, LSL_Leaf *close); LSL_Leaf *addFunctionBody(LuaSL_compiler *compiler, LSL_Leaf *function, LSL_Leaf *block); +LSL_Leaf *addFunctionCall(LuaSL_compiler *compiler, LSL_Leaf *identifier, LSL_Leaf *open, LSL_Leaf *params, LSL_Leaf *close); LSL_Leaf *addOperation(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right); LSL_Leaf *addParameter(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *newParam); LSL_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[] = {LSL_TYPE_VECTOR, ST_NONE, "vector", LSL_NONE, NULL, NULL}, // Then the rest of the syntax tokens. + {LSL_FUNCTION_CALL, ST_NONE, "funccall", LSL_NONE, NULL, NULL}, {LSL_IDENTIFIER, ST_NONE, "identifier", LSL_NONE, outputIdentifierToken, NULL}, {LSL_LABEL, ST_NONE, "@", LSL_NONE, NULL, NULL}, @@ -236,6 +237,21 @@ void burnLeaf(void *data) } } +static LSL_Leaf *findFunction(LuaSL_compiler *compiler, const char *name) +{ + LSL_Leaf *func = NULL; + + if (name) + { + if (NULL == func) + func = eina_hash_find(constants.functions, name); + if (NULL == func) + func = eina_hash_find(compiler->script.functions, name); + } + + return func; +} + static LSL_Leaf *findVariable(LuaSL_compiler *compiler, const char *name) { LSL_Leaf *var = NULL; @@ -273,13 +289,28 @@ static LSL_Leaf *findVariable(LuaSL_compiler *compiler, const char *name) return var; } +LSL_Leaf *checkFunction(LuaSL_compiler *compiler, LSL_Leaf *identifier) +{ + gameGlobals *game = compiler->game; + LSL_Leaf *func = findFunction(compiler, identifier->value.stringValue); + + if (NULL == func) + PE("NOT found %s @ line %d column %d!", identifier->value.stringValue, identifier->line, identifier->column); +#ifdef LUASL_DEBUG + else + PI("Found %s!", identifier->value.stringValue); +#endif + + return func; +} + LSL_Leaf *checkVariable(LuaSL_compiler *compiler, LSL_Leaf *identifier) { gameGlobals *game = compiler->game; LSL_Leaf *var = findVariable(compiler, identifier->value.stringValue); if (NULL == var) - PE("NOT found %s!", identifier->value.stringValue); + PE("NOT found %s @ line %d column %d!", identifier->value.stringValue, identifier->line, identifier->column); #ifdef LUASL_DEBUG else PI("Found %s!", identifier->value.stringValue); @@ -502,6 +533,22 @@ LSL_Leaf *addFunctionBody(LuaSL_compiler *compiler, LSL_Leaf *function, LSL_Leaf return function; } +LSL_Leaf *addFunctionCall(LuaSL_compiler *compiler, LSL_Leaf *identifier, LSL_Leaf *open, LSL_Leaf *params, LSL_Leaf *close) +{ + LSL_Leaf *func = checkFunction(compiler, identifier); + + identifier->token = tokens[LSL_UNKNOWN - lowestToken]; + + if (func) + { + // TODO - Add some structure here to hold the params. + identifier->token = tokens[LSL_FUNCTION_CALL - lowestToken]; + identifier->basicType = func->basicType; + } + + return identifier; +} + LSL_Leaf *addParenthesis(LSL_Leaf *lval, LSL_Leaf *expr, LSL_Type type, LSL_Leaf *rval) { LSL_Parenthesis *parens = calloc(1, sizeof(LSL_Parenthesis)); -- cgit v1.1