diff options
author | David Walter Seikel | 2012-01-17 19:52:21 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-01-17 19:52:21 +1000 |
commit | 36f91bf237a2d48e27171c6661eff9cc255214d0 (patch) | |
tree | 9991a29a402c321ab1d83f00cb3a81e3cf8ba5a6 /LuaSL/src/LuaSL_compile.c | |
parent | Change to the stringshared hash, it's way faster. (diff) | |
download | SledjHamr-36f91bf237a2d48e27171c6661eff9cc255214d0.zip SledjHamr-36f91bf237a2d48e27171c6661eff9cc255214d0.tar.gz SledjHamr-36f91bf237a2d48e27171c6661eff9cc255214d0.tar.bz2 SledjHamr-36f91bf237a2d48e27171c6661eff9cc255214d0.tar.xz |
Add function parameters to the search list.
Diffstat (limited to '')
-rw-r--r-- | LuaSL/src/LuaSL_compile.c | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c index c28a6fc..4e089c7 100644 --- a/LuaSL/src/LuaSL_compile.c +++ b/LuaSL/src/LuaSL_compile.c | |||
@@ -219,10 +219,13 @@ static LSL_Leaf *findVariable(LuaSL_compiler *compiler, const char *name) | |||
219 | 219 | ||
220 | while ((block) && (NULL == var)) | 220 | while ((block) && (NULL == var)) |
221 | { | 221 | { |
222 | if (block->variables) | 222 | if (block->function) |
223 | var = eina_hash_find(block->function->variables, name); | ||
224 | if ((NULL == var) && block->variables) | ||
223 | var = eina_hash_find(block->variables, name); | 225 | var = eina_hash_find(block->variables, name); |
224 | block = block->outerBlock; | 226 | block = block->outerBlock; |
225 | } | 227 | } |
228 | |||
226 | if (NULL == var) | 229 | if (NULL == var) |
227 | var = eina_hash_find(compiler->script.variables, name); | 230 | var = eina_hash_find(compiler->script.variables, name); |
228 | } | 231 | } |
@@ -351,7 +354,7 @@ LSL_Leaf *addOperation(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, | |||
351 | return lval; | 354 | return lval; |
352 | } | 355 | } |
353 | 356 | ||
354 | LSL_Leaf *addParameter(LSL_Leaf *type, LSL_Leaf *identifier) | 357 | LSL_Leaf *addParameter(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identifier) |
355 | { | 358 | { |
356 | LSL_Identifier *result = calloc(1, sizeof(LSL_Identifier)); | 359 | LSL_Identifier *result = calloc(1, sizeof(LSL_Identifier)); |
357 | 360 | ||
@@ -370,7 +373,7 @@ LSL_Leaf *addParameter(LSL_Leaf *type, LSL_Leaf *identifier) | |||
370 | return identifier; | 373 | return identifier; |
371 | } | 374 | } |
372 | 375 | ||
373 | LSL_Leaf *collectParameters(LSL_Leaf *list, LSL_Leaf *comma, LSL_Leaf *newParam) | 376 | LSL_Leaf *collectParameters(LuaSL_compiler *compiler, LSL_Leaf *list, LSL_Leaf *comma, LSL_Leaf *newParam) |
374 | { | 377 | { |
375 | LSL_Leaf *newList = newLeaf(LSL_PARAMETER_LIST, NULL, NULL); | 378 | LSL_Leaf *newList = newLeaf(LSL_PARAMETER_LIST, NULL, NULL); |
376 | 379 | ||
@@ -379,15 +382,13 @@ LSL_Leaf *collectParameters(LSL_Leaf *list, LSL_Leaf *comma, LSL_Leaf *newParam) | |||
379 | newList->left = list; | 382 | newList->left = list; |
380 | newList->value.listValue = newParam; | 383 | newList->value.listValue = newParam; |
381 | if ((list) && (list->value.listValue)) | 384 | if ((list) && (list->value.listValue)) |
382 | { | ||
383 | list->value.listValue->right = comma; | 385 | list->value.listValue->right = comma; |
384 | } | ||
385 | } | 386 | } |
386 | 387 | ||
387 | return newList; | 388 | return newList; |
388 | } | 389 | } |
389 | 390 | ||
390 | LSL_Leaf *addFunction(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *open, LSL_Leaf *params, LSL_Leaf *close, LSL_Leaf *block) | 391 | LSL_Leaf *addFunction(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *open, LSL_Leaf *params, LSL_Leaf *close) |
391 | { | 392 | { |
392 | LSL_Function *func = calloc(1, sizeof(LSL_Function)); | 393 | LSL_Function *func = calloc(1, sizeof(LSL_Function)); |
393 | 394 | ||
@@ -398,19 +399,40 @@ LSL_Leaf *addFunction(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identi | |||
398 | func->name = identifier->value.stringValue; | 399 | func->name = identifier->value.stringValue; |
399 | identifier->token = tokens[LSL_FUNCTION - lowestToken]; | 400 | identifier->token = tokens[LSL_FUNCTION - lowestToken]; |
400 | identifier->value.functionValue = func; | 401 | identifier->value.functionValue = func; |
401 | identifier->value.functionValue->block = block; | ||
402 | func->type = type; | 402 | func->type = type; |
403 | if (type) | 403 | if (type) |
404 | identifier->basicType = type->basicType; | 404 | identifier->basicType = type->basicType; |
405 | else | 405 | else |
406 | identifier->basicType = OT_nothing; | 406 | identifier->basicType = OT_nothing; |
407 | func->params = addParenthesis(open, params, LSL_PARAMETER_LIST, close); | ||
408 | eina_hash_add(compiler->script.functions, func->name, identifier); | 407 | eina_hash_add(compiler->script.functions, func->name, identifier); |
408 | func->variables = eina_hash_stringshared_new(burnLeaf); | ||
409 | func->params = addParenthesis(open, params, LSL_PARAMETER_LIST, close); | ||
410 | while (params) | ||
411 | { | ||
412 | if (params->value.listValue) | ||
413 | { | ||
414 | LSL_Identifier *identifier = params->value.listValue->value.identifierValue; | ||
415 | |||
416 | if (identifier) | ||
417 | eina_hash_add(func->variables, identifier->name, identifier); | ||
418 | } | ||
419 | params = params->left; | ||
420 | } | ||
421 | if (compiler->currentBlock) | ||
422 | compiler->currentBlock->function = func; | ||
409 | } | 423 | } |
410 | } | 424 | } |
411 | return identifier; | 425 | return identifier; |
412 | } | 426 | } |
413 | 427 | ||
428 | LSL_Leaf *addFunctionBody(LuaSL_compiler *compiler, LSL_Leaf *function, LSL_Leaf *block) | ||
429 | { | ||
430 | if (function) | ||
431 | function->value.functionValue->block = block; | ||
432 | |||
433 | return function; | ||
434 | } | ||
435 | |||
414 | LSL_Leaf *addParenthesis(LSL_Leaf *lval, LSL_Leaf *expr, LSL_Type type, LSL_Leaf *rval) | 436 | LSL_Leaf *addParenthesis(LSL_Leaf *lval, LSL_Leaf *expr, LSL_Type type, LSL_Leaf *rval) |
415 | { | 437 | { |
416 | LSL_Parenthesis *parens = malloc(sizeof(LSL_Parenthesis)); | 438 | LSL_Parenthesis *parens = malloc(sizeof(LSL_Parenthesis)); |
@@ -514,7 +536,7 @@ LSL_Leaf *addVariable(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identi | |||
514 | 536 | ||
515 | void beginBlock(LuaSL_compiler *compiler, LSL_Leaf *block) | 537 | void beginBlock(LuaSL_compiler *compiler, LSL_Leaf *block) |
516 | { | 538 | { |
517 | LSL_Block *blok = malloc(sizeof(LSL_Block)); | 539 | LSL_Block *blok = calloc(1, sizeof(LSL_Block)); |
518 | 540 | ||
519 | if (blok) | 541 | if (blok) |
520 | { | 542 | { |