aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-01-17 15:45:40 +1000
committerDavid Walter Seikel2012-01-17 15:45:40 +1000
commitc300df8ea35ff75530b6cfd187c92c41658cb52d (patch)
tree3889b3e41781945be05f250f859b4324f760c8f3 /LuaSL
parentUsing eina string buffer for ignorable text. (diff)
downloadSledjHamr-c300df8ea35ff75530b6cfd187c92c41658cb52d.zip
SledjHamr-c300df8ea35ff75530b6cfd187c92c41658cb52d.tar.gz
SledjHamr-c300df8ea35ff75530b6cfd187c92c41658cb52d.tar.bz2
SledjHamr-c300df8ea35ff75530b6cfd187c92c41658cb52d.tar.xz
Use eina hash for functions, states, and variables.
Diffstat (limited to 'LuaSL')
-rw-r--r--LuaSL/src/LuaSL_LSL_tree.h19
-rw-r--r--LuaSL/src/LuaSL_compile.c30
-rw-r--r--LuaSL/src/LuaSL_lemon_yaccer.y4
3 files changed, 23 insertions, 30 deletions
diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h
index fd9c65a..2674542 100644
--- a/LuaSL/src/LuaSL_LSL_tree.h
+++ b/LuaSL/src/LuaSL_LSL_tree.h
@@ -223,9 +223,9 @@ struct _LSL_Statement
223struct _LSL_Block 223struct _LSL_Block
224{ 224{
225 LSL_Block *outerBlock; 225 LSL_Block *outerBlock;
226 LSL_Statement **statements; 226// Eina_Hash *statements; // Probably should be some sort of eina list.
227 LSL_Identifier **variables; // Those variables in this scope. 227 Eina_Hash *variables; // Those variables in this scope.
228 int scount, vcount; 228 int scount;
229}; 229};
230 230
231struct _LSL_Function 231struct _LSL_Function
@@ -240,16 +240,15 @@ struct _LSL_State
240{ 240{
241 const char *name; 241 const char *name;
242 LSL_Leaf *block; 242 LSL_Leaf *block;
243 LSL_Function **handlers; 243 Eina_Hash *handlers;
244}; 244};
245 245
246struct _LSL_Script 246struct _LSL_Script
247{ 247{
248 const char *name; 248 const char *name;
249 LSL_Function **functions; 249 Eina_Hash *functions;
250 LSL_State **states; 250 Eina_Hash *states;
251 LSL_Identifier **variables; 251 Eina_Hash *variables;
252 int fcount, scount, vcount;
253}; 252};
254 253
255// Define the type for flex and lemon. 254// Define the type for flex and lemon.
@@ -277,8 +276,8 @@ typedef struct
277#endif 276#endif
278 277
279 278
280void burnLeaf(LSL_Leaf *leaf); 279void burnLeaf(void *data);
281LSL_Leaf *addFunction(LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *open, LSL_Leaf *params, LSL_Leaf *close, LSL_Leaf *block); 280LSL_Leaf *addFunction(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *open, LSL_Leaf *params, LSL_Leaf *close, LSL_Leaf *block);
282LSL_Leaf *addOperation(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right); 281LSL_Leaf *addOperation(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right);
283LSL_Leaf *addParameter(LSL_Leaf *type, LSL_Leaf *newParam); 282LSL_Leaf *addParameter(LSL_Leaf *type, LSL_Leaf *newParam);
284LSL_Leaf *addParenthesis(LSL_Leaf *lval, LSL_Leaf *expr, LSL_Type type, LSL_Leaf *rval); 283LSL_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 277e278..445014e 100644
--- a/LuaSL/src/LuaSL_compile.c
+++ b/LuaSL/src/LuaSL_compile.c
@@ -196,8 +196,9 @@ static LSL_Leaf *newLeaf(LSL_Type type, LSL_Leaf *left, LSL_Leaf *right)
196 return leaf; 196 return leaf;
197} 197}
198 198
199void burnLeaf(LSL_Leaf *leaf) 199void burnLeaf(void *data)
200{ 200{
201 LSL_Leaf *leaf = data;
201 if (leaf) 202 if (leaf)
202 { 203 {
203 burnLeaf(leaf->left); 204 burnLeaf(leaf->left);
@@ -326,7 +327,7 @@ LSL_Leaf *collectParameters(LSL_Leaf *list, LSL_Leaf *comma, LSL_Leaf *newParam)
326 return newList; 327 return newList;
327} 328}
328 329
329LSL_Leaf *addFunction(LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *open, LSL_Leaf *params, LSL_Leaf *close, LSL_Leaf *block) 330LSL_Leaf *addFunction(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *open, LSL_Leaf *params, LSL_Leaf *close, LSL_Leaf *block)
330{ 331{
331 LSL_Function *func = calloc(1, sizeof(LSL_Function)); 332 LSL_Function *func = calloc(1, sizeof(LSL_Function));
332 333
@@ -334,11 +335,9 @@ LSL_Leaf *addFunction(LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *open, LSL_
334 { 335 {
335 if (identifier) 336 if (identifier)
336 { 337 {
337 const char *temp = identifier->value.stringValue; 338 func->name = identifier->value.stringValue;
338
339 identifier->token = tokens[LSL_FUNCTION - lowestToken]; 339 identifier->token = tokens[LSL_FUNCTION - lowestToken];
340 identifier->value.functionValue = func; 340 identifier->value.functionValue = func;
341 identifier->value.functionValue->name = temp;
342 identifier->value.functionValue->block = block; 341 identifier->value.functionValue->block = block;
343 func->type = type; 342 func->type = type;
344 if (type) 343 if (type)
@@ -346,6 +345,7 @@ LSL_Leaf *addFunction(LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *open, LSL_
346 else 345 else
347 identifier->basicType = OT_nothing; 346 identifier->basicType = OT_nothing;
348 func->params = addParenthesis(open, params, LSL_PARAMETER_LIST, close); 347 func->params = addParenthesis(open, params, LSL_PARAMETER_LIST, close);
348 eina_hash_add(compiler->script.functions, func->name, identifier);
349 } 349 }
350 } 350 }
351 return identifier; 351 return identifier;
@@ -380,9 +380,7 @@ LSL_Leaf *addState(LuaSL_compiler *compiler, LSL_Leaf *identifier, LSL_Leaf *blo
380 result->name = identifier->value.stringValue; 380 result->name = identifier->value.stringValue;
381 result->block = block; 381 result->block = block;
382 identifier->value.stateValue = result; 382 identifier->value.stateValue = result;
383 compiler->script.scount++; 383 eina_hash_add(compiler->script.states, result->name, identifier);
384 compiler->script.states = realloc(compiler->script.states, compiler->script.scount * sizeof(LSL_State *));
385 compiler->script.states[compiler->script.scount - 1] = result;
386 } 384 }
387 385
388 return identifier; 386 return identifier;
@@ -446,17 +444,9 @@ LSL_Leaf *addVariable(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identi
446 result->value.basicType = type->basicType; 444 result->value.basicType = type->basicType;
447 } 445 }
448 if (compiler->currentBlock) 446 if (compiler->currentBlock)
449 { 447 eina_hash_add(compiler->currentBlock->variables, result->name, identifier);
450// compiler->currentBlock->vcount++;
451// compiler->currentBlock->variables = realloc(compiler->currentBlock->variables, compiler->currentBlock->vcount * sizeof(LSL_Identifier *));
452// compiler->currentBlock->variables[compiler->currentBlock->vcount - 1] = result;
453 }
454 else 448 else
455 { 449 eina_hash_add(compiler->script.variables, result->name, identifier);
456 compiler->script.vcount++;
457 compiler->script.variables = realloc(compiler->script.variables, compiler->script.vcount * sizeof(LSL_Identifier *));
458 compiler->script.variables[compiler->script.vcount - 1] = result;
459 }
460 } 450 }
461 451
462 return identifier; 452 return identifier;
@@ -468,6 +458,7 @@ void beginBlock(LuaSL_compiler *compiler, LSL_Leaf *block)
468 458
469 if (blok) 459 if (blok)
470 { 460 {
461 blok->variables = eina_hash_string_superfast_new(burnLeaf);
471 block->value.blockValue = blok; 462 block->value.blockValue = blok;
472 blok->outerBlock = compiler->currentBlock; 463 blok->outerBlock = compiler->currentBlock;
473 compiler->currentBlock = blok; 464 compiler->currentBlock = blok;
@@ -947,6 +938,9 @@ Eina_Bool compileLSL(gameGlobals *game, char *script)
947 938
948 memset(&compiler, 0, sizeof(LuaSL_compiler)); 939 memset(&compiler, 0, sizeof(LuaSL_compiler));
949 compiler.game = game; 940 compiler.game = game;
941 compiler.script.functions = eina_hash_string_superfast_new(burnLeaf);
942 compiler.script.states = eina_hash_string_superfast_new(burnLeaf);
943 compiler.script.variables = eina_hash_string_superfast_new(burnLeaf);
950 compiler.ignorableText = eina_strbuf_new(); 944 compiler.ignorableText = eina_strbuf_new();
951 945
952 strncpy(compiler.fileName, script, PATH_MAX - 1); 946 strncpy(compiler.fileName, script, PATH_MAX - 1);
diff --git a/LuaSL/src/LuaSL_lemon_yaccer.y b/LuaSL/src/LuaSL_lemon_yaccer.y
index e62776b..e163991 100644
--- a/LuaSL/src/LuaSL_lemon_yaccer.y
+++ b/LuaSL/src/LuaSL_lemon_yaccer.y
@@ -45,8 +45,8 @@ parameterList(A) ::= parameter(D). { A = collectParameters(NULL, NULL, D);
45parameterList(A) ::= . { A = collectParameters(NULL, NULL, NULL); } 45parameterList(A) ::= . { A = collectParameters(NULL, NULL, NULL); }
46parameter(A) ::= type(B) LSL_IDENTIFIER(C). { A = addParameter(B, C); } 46parameter(A) ::= type(B) LSL_IDENTIFIER(C). { A = addParameter(B, C); }
47// Causes a conflict when it's an empty parameterList with calling the same type of function. 47// Causes a conflict when it's an empty parameterList with calling the same type of function.
48function(A) ::= LSL_IDENTIFIER(C) LSL_PARENTHESIS_OPEN(D) parameterList(E) LSL_PARENTHESIS_CLOSE(F) funcBlock(G). { A = addFunction(NULL, C, D, E, F, G); } 48function(A) ::= LSL_IDENTIFIER(C) LSL_PARENTHESIS_OPEN(D) parameterList(E) LSL_PARENTHESIS_CLOSE(F) funcBlock(G). { A = addFunction(compiler, NULL, C, D, E, F, G); }
49function(A) ::= type(B) LSL_IDENTIFIER(C) LSL_PARENTHESIS_OPEN(D) parameterList(E) LSL_PARENTHESIS_CLOSE(F) funcBlock(G). { A = addFunction(B, C, D, E, F, G); } 49function(A) ::= type(B) LSL_IDENTIFIER(C) LSL_PARENTHESIS_OPEN(D) parameterList(E) LSL_PARENTHESIS_CLOSE(F) funcBlock(G). { A = addFunction(compiler, B, C, D, E, F, G); }
50 50
51// Blocks. 51// Blocks.
52 52