aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-01-21 10:08:06 +1000
committerDavid Walter Seikel2012-01-21 10:08:06 +1000
commit7cec8639839e7e48d274570c7a9c915d6565c8cb (patch)
tree725c603da23f6649d561bec815f9e359272cc4df /LuaSL
parentSome extra debugging. (diff)
downloadSledjHamr-7cec8639839e7e48d274570c7a9c915d6565c8cb.zip
SledjHamr-7cec8639839e7e48d274570c7a9c915d6565c8cb.tar.gz
SledjHamr-7cec8639839e7e48d274570c7a9c915d6565c8cb.tar.bz2
SledjHamr-7cec8639839e7e48d274570c7a9c915d6565c8cb.tar.xz
A better way to do function parameters. NOTE - using an unreleased Eina API from SVN.
Diffstat (limited to 'LuaSL')
-rw-r--r--LuaSL/src/LuaSL_LSL_tree.h6
-rw-r--r--LuaSL/src/LuaSL_compile.c108
2 files changed, 78 insertions, 36 deletions
diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h
index be3896e..2bda3b4 100644
--- a/LuaSL/src/LuaSL_LSL_tree.h
+++ b/LuaSL/src/LuaSL_LSL_tree.h
@@ -207,8 +207,10 @@ struct _LSL_Function
207{ 207{
208 const char *name; 208 const char *name;
209 LSL_Leaf *type; 209 LSL_Leaf *type;
210 LSL_Leaf *params; // Probably should be some sort of eina list. 210#ifdef LUASL_DIFF_CHECK
211 Eina_Hash *variables; // And this actually duplicates params. 211 LSL_Leaf *params; // So we store the parenthesis, and their ignorables.
212#endif
213 Eina_Inarray vars; // Eina Inarray has not been released yet (Eina 1.2).
212 LSL_Leaf *block; 214 LSL_Leaf *block;
213}; 215};
214 216
diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c
index 504e866..fd5bbb2 100644
--- a/LuaSL/src/LuaSL_compile.c
+++ b/LuaSL/src/LuaSL_compile.c
@@ -245,7 +245,18 @@ static LSL_Leaf *findVariable(LuaSL_compiler *compiler, const char *name)
245 while ((block) && (NULL == var)) 245 while ((block) && (NULL == var))
246 { 246 {
247 if (block->function) 247 if (block->function)
248 var = eina_hash_find(block->function->variables, name); 248 {
249 LSL_Leaf *param = NULL;
250 EINA_INARRAY_FOREACH((&(block->function->vars)), param)
251 {
252 if ((param) && (LSL_PARAMETER == param->token->type))
253 {
254// if (name == param->value.identifierValue->name) // Assuming they are stringshares.
255 if (0 == strcmp(name, param->value.identifierValue->name)) // Not assuming they are stringeshares.
256 var = param;
257 }
258 }
259 }
249 if ((NULL == var) && block->variables) 260 if ((NULL == var) && block->variables)
250 var = eina_hash_find(block->variables, name); 261 var = eina_hash_find(block->variables, name);
251 block = block->outerBlock; 262 block = block->outerBlock;
@@ -410,53 +421,72 @@ LSL_Leaf *addParameter(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *ident
410 421
411LSL_Leaf *collectParameters(LuaSL_compiler *compiler, LSL_Leaf *list, LSL_Leaf *comma, LSL_Leaf *newParam) 422LSL_Leaf *collectParameters(LuaSL_compiler *compiler, LSL_Leaf *list, LSL_Leaf *comma, LSL_Leaf *newParam)
412{ 423{
413 LSL_Leaf *newList = newLeaf(LSL_PARAMETER_LIST, NULL, NULL); 424 LSL_Function *func = NULL;
414 425
415 if (newList) 426 if (NULL == list)
427 list = newLeaf(LSL_FUNCTION, NULL, NULL);
428
429 if (list)
416 { 430 {
417 newList->left = list; 431 func = list->value.functionValue;
418 newList->value.listValue = newParam; 432 if (NULL == func)
419 if ((list) && (list->value.listValue)) 433 {
420 list->value.listValue->right = comma; 434 func = calloc(1, sizeof(LSL_Function));
421 } 435 if (func)
436 {
437 list->value.functionValue = func;
438 eina_inarray_setup(&(func->vars), sizeof(LSL_Leaf), 3);
439 }
440 }
422 441
423 return newList; 442 if (func)
443 {
444 if (newParam)
445 {
446#ifdef LUASL_DIFF_CHECK
447 // Stash the comma for diff later.
448 if (comma)
449 eina_inarray_append(&(func->vars), comma);
450#endif
451 eina_inarray_append(&(func->vars), newParam);
452 // At this point, pointers to newParams are not pointing to the one in func->vars, AND newParam is no longer needed.
453 }
454 }
455 }
456 return list;
424} 457}
425 458
426LSL_Leaf *addFunction(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *open, LSL_Leaf *params, LSL_Leaf *close) 459LSL_Leaf *addFunction(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *open, LSL_Leaf *params, LSL_Leaf *close)
427{ 460{
428 LSL_Function *func = calloc(1, sizeof(LSL_Function)); 461 LSL_Function *func = NULL;
429 462
430 if (func) 463 if (params)
431 { 464 {
432 if (identifier) 465 func = params->value.functionValue;
466 // At this point, params is no longer needed, except if we are doing diff.
467 // open and close are not needed either if we are not doing diff.
468 if (func)
433 { 469 {
434 func->name = identifier->value.stringValue; 470 if (identifier)
435 identifier->token = tokens[LSL_FUNCTION - lowestToken];
436 identifier->value.functionValue = func;
437 func->type = type;
438 if (type)
439 identifier->basicType = type->basicType;
440 else
441 identifier->basicType = OT_nothing;
442 eina_hash_add(compiler->script.functions, func->name, identifier);
443 func->variables = eina_hash_stringshared_new(burnLeaf);
444 func->params = addParenthesis(open, params, LSL_PARAMETER_LIST, close);
445 while (params)
446 { 471 {
447 if (params->value.listValue) 472 func->name = identifier->value.stringValue;
448 { 473 identifier->token = tokens[LSL_FUNCTION - lowestToken];
449 LSL_Leaf *param = params->value.listValue; 474 identifier->value.functionValue = func;
450 475 func->type = type;
451 if (identifier) 476 if (type)
452 eina_hash_add(func->variables, param->value.identifierValue->name, param); 477 identifier->basicType = type->basicType;
453 } 478 else
454 params = params->left; 479 identifier->basicType = OT_nothing;
480 eina_hash_add(compiler->script.functions, func->name, identifier);
481#ifdef LUASL_DIFF_CHECK
482 func->params = addParenthesis(open, params, LSL_PARAMETER_LIST, close);
483#endif
455 } 484 }
456 if (compiler->currentBlock) 485 if (compiler->currentBlock)
457 compiler->currentBlock->function = func; 486 compiler->currentBlock->function = func;
458 } 487 }
459 } 488 }
489
460 return identifier; 490 return identifier;
461} 491}
462 492
@@ -911,10 +941,20 @@ static void outputFunctionToken(FILE *file, outputMode mode, LSL_Leaf *content)
911 if (content) 941 if (content)
912 { 942 {
913 LSL_Function *func = content->value.functionValue; 943 LSL_Function *func = content->value.functionValue;
944 LSL_Leaf *param = NULL;
945 int first = TRUE;
914 946
915 outputLeaf(file, mode, func->type); 947 outputLeaf(file, mode, func->type);
916 fprintf(file, "%s", func->name); 948// TODO - should print comma and parenthesis ignorables.
917 outputLeaf(file, mode, func->params); 949 fprintf(file, "%s(", func->name);
950 EINA_INARRAY_FOREACH((&(func->vars)), param)
951 {
952 if (!first)
953 fprintf(file, ", ");
954 outputLeaf(file, mode, param);
955 first = FALSE;
956 }
957 fprintf(file, ")");
918 outputLeaf(file, mode, func->block); 958 outputLeaf(file, mode, func->block);
919#ifndef LUASL_DIFF_CHECK 959#ifndef LUASL_DIFF_CHECK
920 fprintf(file, "\n"); 960 fprintf(file, "\n");