aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/src/LuaSL_compile.c
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-01-30 13:33:11 +1000
committerDavid Walter Seikel2012-01-30 13:33:11 +1000
commit8b71bc2d2905ca2ded0789a5534efc914ea84858 (patch)
treea0d16e863f4a65c6dc60bfbe77504e22b950dc3a /LuaSL/src/LuaSL_compile.c
parenttoken -> toKen. Seems to be a key word somewhere, best to be safe. (diff)
downloadSledjHamr-8b71bc2d2905ca2ded0789a5534efc914ea84858.zip
SledjHamr-8b71bc2d2905ca2ded0789a5534efc914ea84858.tar.gz
SledjHamr-8b71bc2d2905ca2ded0789a5534efc914ea84858.tar.bz2
SledjHamr-8b71bc2d2905ca2ded0789a5534efc914ea84858.tar.xz
Change the way blocks start and end, the look ahead was screwing things.
Diffstat (limited to 'LuaSL/src/LuaSL_compile.c')
-rw-r--r--LuaSL/src/LuaSL_compile.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c
index 48f2910..e4a526a 100644
--- a/LuaSL/src/LuaSL_compile.c
+++ b/LuaSL/src/LuaSL_compile.c
@@ -446,6 +446,13 @@ LSL_Leaf *addOperation(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval,
446 return lval; 446 return lval;
447} 447}
448 448
449LSL_Leaf *addBlock(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right)
450{
451 // Damn, look ahead. The } symbol is getting read (and thus endBlock called) before the last statement in the block is reduced (which actually calls the add*() functions).
452 compiler->currentBlock = compiler->currentBlock->outerBlock;
453 return lval;
454}
455
449LSL_Leaf *addCrement(LuaSL_compiler *compiler, LSL_Leaf *variable, LSL_Leaf *crement) 456LSL_Leaf *addCrement(LuaSL_compiler *compiler, LSL_Leaf *variable, LSL_Leaf *crement)
450{ 457{
451 if ((variable) && (crement)) 458 if ((variable) && (crement))
@@ -541,8 +548,7 @@ LSL_Leaf *addFunction(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identi
541 func->params = addParenthesis(open, params, LSL_PARAMETER_LIST, close); 548 func->params = addParenthesis(open, params, LSL_PARAMETER_LIST, close);
542#endif 549#endif
543 } 550 }
544 if (compiler->currentBlock) 551 compiler->currentFunction = func;
545 compiler->currentBlock->function = func;
546 } 552 }
547 } 553 }
548 554
@@ -725,12 +731,13 @@ LSL_Leaf *addStatement(LuaSL_compiler *compiler, LSL_Leaf *lval, LSL_Type type,
725 731
726LSL_Leaf *collectStatements(LuaSL_compiler *compiler, LSL_Leaf *list, LSL_Leaf *statement) 732LSL_Leaf *collectStatements(LuaSL_compiler *compiler, LSL_Leaf *list, LSL_Leaf *statement)
727{ 733{
734 boolean wasNull = FALSE;
728 if (NULL == list) 735 if (NULL == list)
729 { 736 {
730 list = newLeaf(LSL_BLOCK_OPEN, NULL, NULL); 737 list = newLeaf(LSL_BLOCK_OPEN, NULL, NULL);
731 if (list) 738 if (list)
732 { 739 {
733 list->value.blockValue = compiler->currentBlock; // Maybe NULL. 740 wasNull = TRUE;
734 } 741 }
735 } 742 }
736 743
@@ -738,6 +745,8 @@ LSL_Leaf *collectStatements(LuaSL_compiler *compiler, LSL_Leaf *list, LSL_Leaf *
738 { 745 {
739 if (statement) 746 if (statement)
740 { 747 {
748 if (!wasNull)
749 list->value.blockValue = compiler->currentBlock; // Maybe NULL.
741 if (list->value.blockValue) 750 if (list->value.blockValue)
742 { 751 {
743 eina_clist_add_tail(&(list->value.blockValue->statements), &(statement->value.statementValue->statement)); 752 eina_clist_add_tail(&(list->value.blockValue->statements), &(statement->value.statementValue->statement));
@@ -792,7 +801,7 @@ LSL_Leaf *addVariable(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identi
792 return identifier; 801 return identifier;
793} 802}
794 803
795void beginBlock(LuaSL_compiler *compiler, LSL_Leaf *block) 804LSL_Leaf *beginBlock(LuaSL_compiler *compiler, LSL_Leaf *block)
796{ 805{
797 LSL_Block *blok = calloc(1, sizeof(LSL_Block)); 806 LSL_Block *blok = calloc(1, sizeof(LSL_Block));
798 807
@@ -803,12 +812,10 @@ void beginBlock(LuaSL_compiler *compiler, LSL_Leaf *block)
803 block->value.blockValue = blok; 812 block->value.blockValue = blok;
804 blok->outerBlock = compiler->currentBlock; 813 blok->outerBlock = compiler->currentBlock;
805 compiler->currentBlock = blok; 814 compiler->currentBlock = blok;
815 blok->function = compiler->currentFunction;
816 compiler->currentFunction = NULL;
806 } 817 }
807} 818 return block;
808
809void endBlock(LuaSL_compiler *compiler, LSL_Leaf *block)
810{
811 compiler->currentBlock = compiler->currentBlock->outerBlock;
812} 819}
813 820
814static void secondPass(LuaSL_compiler *compiler, LSL_Leaf *leaf) 821static void secondPass(LuaSL_compiler *compiler, LSL_Leaf *leaf)