aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/src/LuaSL_compile.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--LuaSL/src/LuaSL_compile.c49
1 files changed, 48 insertions, 1 deletions
diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c
index 29c45f3..b1efddd 100644
--- a/LuaSL/src/LuaSL_compile.c
+++ b/LuaSL/src/LuaSL_compile.c
@@ -7,6 +7,7 @@ static LSL_Leaf *evaluateNoToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *ri
7static LSL_Leaf *evaluateOperationToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right); 7static LSL_Leaf *evaluateOperationToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right);
8static LSL_Leaf *eveluateParenthesisToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right); 8static LSL_Leaf *eveluateParenthesisToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right);
9static LSL_Leaf *evaluateStatementToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right); 9static LSL_Leaf *evaluateStatementToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right);
10static void outputBlockToken(FILE *file, outputMode mode, LSL_Leaf *content);
10static void outputFloatToken(FILE *file, outputMode mode, LSL_Leaf *content); 11static void outputFloatToken(FILE *file, outputMode mode, LSL_Leaf *content);
11static void outputFunctionToken(FILE *file, outputMode mode, LSL_Leaf *content); 12static void outputFunctionToken(FILE *file, outputMode mode, LSL_Leaf *content);
12static void outputIntegerToken(FILE *file, outputMode mode, LSL_Leaf *content); 13static void outputIntegerToken(FILE *file, outputMode mode, LSL_Leaf *content);
@@ -129,7 +130,7 @@ LSL_Token LSL_Tokens[] =
129 {LSL_STATEMENT, ST_NONE, ";", LSL_NOIGNORE, outputStatementToken, evaluateStatementToken}, 130 {LSL_STATEMENT, ST_NONE, ";", LSL_NOIGNORE, outputStatementToken, evaluateStatementToken},
130 131
131 {LSL_BLOCK_CLOSE, ST_NONE, "}", LSL_NONE, NULL, NULL}, 132 {LSL_BLOCK_CLOSE, ST_NONE, "}", LSL_NONE, NULL, NULL},
132 {LSL_BLOCK_OPEN, ST_NONE, "{", LSL_NONE, NULL, NULL}, 133 {LSL_BLOCK_OPEN, ST_NONE, "{", LSL_NONE, outputBlockToken, NULL},
133 {LSL_PARAMETER, ST_NONE, "parameter", LSL_NONE, outputIdentifierToken, NULL}, 134 {LSL_PARAMETER, ST_NONE, "parameter", LSL_NONE, outputIdentifierToken, NULL},
134 {LSL_PARAMETER_LIST, ST_NONE, "plist", LSL_NONE, outputParameterListToken, NULL}, 135 {LSL_PARAMETER_LIST, ST_NONE, "plist", LSL_NONE, outputParameterListToken, NULL},
135 {LSL_FUNCTION, ST_NONE, "function", LSL_NONE, outputFunctionToken, NULL}, 136 {LSL_FUNCTION, ST_NONE, "function", LSL_NONE, outputFunctionToken, NULL},
@@ -547,6 +548,7 @@ LSL_Leaf *addStatement(LSL_Leaf *lval, LSL_Type type, LSL_Leaf *expr)
547 { 548 {
548 stat->type = type; 549 stat->type = type;
549 stat->expressions = expr; 550 stat->expressions = expr;
551 eina_clist_element_init(&(stat->statement));
550 if (lval) 552 if (lval)
551 lval->value.statementValue = stat; 553 lval->value.statementValue = stat;
552 } 554 }
@@ -554,6 +556,31 @@ LSL_Leaf *addStatement(LSL_Leaf *lval, LSL_Type type, LSL_Leaf *expr)
554 return lval; 556 return lval;
555} 557}
556 558
559LSL_Leaf *collectStatements(LuaSL_compiler *compiler, LSL_Leaf *list, LSL_Leaf *statement)
560{
561 if (NULL == list)
562 {
563 list = newLeaf(LSL_BLOCK_OPEN, NULL, NULL);
564 if (list)
565 {
566 list->value.blockValue = compiler->currentBlock; // Maybe NULL.
567 }
568 }
569
570 if (list)
571 {
572 if (statement)
573 {
574 if (list->value.blockValue)
575 {
576 eina_clist_add_tail(&(list->value.blockValue->statements), &(statement->value.statementValue->statement));
577 }
578 }
579 }
580
581 return list;
582}
583
557LSL_Leaf *addTypecast(LSL_Leaf *lval, LSL_Leaf *type, LSL_Leaf *rval, LSL_Leaf *expr) 584LSL_Leaf *addTypecast(LSL_Leaf *lval, LSL_Leaf *type, LSL_Leaf *rval, LSL_Leaf *expr)
558{ 585{
559 addParenthesis(lval, expr, LSL_TYPECAST_OPEN, rval); 586 addParenthesis(lval, expr, LSL_TYPECAST_OPEN, rval);
@@ -604,6 +631,7 @@ void beginBlock(LuaSL_compiler *compiler, LSL_Leaf *block)
604 631
605 if (blok) 632 if (blok)
606 { 633 {
634 eina_clist_init(&(blok->statements));
607 blok->variables = eina_hash_stringshared_new(burnLeaf); 635 blok->variables = eina_hash_stringshared_new(burnLeaf);
608 block->value.blockValue = blok; 636 block->value.blockValue = blok;
609 blok->outerBlock = compiler->currentBlock; 637 blok->outerBlock = compiler->currentBlock;
@@ -933,6 +961,25 @@ static void outputLeaf(FILE *file, outputMode mode, LSL_Leaf *leaf)
933 } 961 }
934} 962}
935 963
964static void outputBlockToken(FILE *file, outputMode mode, LSL_Leaf *content)
965{
966 if (content)
967 {
968 fprintf(file, "\n{\n");
969 if (content->value.blockValue)
970 {
971 LSL_Statement *statement = NULL;
972
973 EINA_CLIST_FOR_EACH_ENTRY(statement, &(content->value.blockValue->statements), LSL_Statement, statement)
974 {
975 outputLeaf(file, mode, statement->expressions);
976 fprintf(file, ";\n");
977 }
978 }
979 fprintf(file, "}\n");
980 }
981}
982
936static void outputFloatToken(FILE *file, outputMode mode, LSL_Leaf *content) 983static void outputFloatToken(FILE *file, outputMode mode, LSL_Leaf *content)
937{ 984{
938 if (content) 985 if (content)