diff options
author | David Walter Seikel | 2012-01-17 15:45:40 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-01-17 15:45:40 +1000 |
commit | c300df8ea35ff75530b6cfd187c92c41658cb52d (patch) | |
tree | 3889b3e41781945be05f250f859b4324f760c8f3 /LuaSL/src/LuaSL_compile.c | |
parent | Using eina string buffer for ignorable text. (diff) | |
download | SledjHamr-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 '')
-rw-r--r-- | LuaSL/src/LuaSL_compile.c | 30 |
1 files changed, 12 insertions, 18 deletions
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 | ||
199 | void burnLeaf(LSL_Leaf *leaf) | 199 | void 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 | ||
329 | LSL_Leaf *addFunction(LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *open, LSL_Leaf *params, LSL_Leaf *close, LSL_Leaf *block) | 330 | LSL_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); |