aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/src/LuaSL_compile.c
diff options
context:
space:
mode:
Diffstat (limited to 'LuaSL/src/LuaSL_compile.c')
-rw-r--r--LuaSL/src/LuaSL_compile.c144
1 files changed, 69 insertions, 75 deletions
diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c
index dbc2c17..42b0798 100644
--- a/LuaSL/src/LuaSL_compile.c
+++ b/LuaSL/src/LuaSL_compile.c
@@ -234,9 +234,8 @@ void burnLeaf(void *data)
234// burnLeaf(leaf->left); 234// burnLeaf(leaf->left);
235// burnLeaf(leaf->right); 235// burnLeaf(leaf->right);
236 // TODO - Should free up the value to. 236 // TODO - Should free up the value to.
237#ifdef LUASL_DIFF_CHECK 237// if (LUASL_DIFF_CHECK)
238// eina_strbuf_free(leaf->ignorableText); 238// eina_strbuf_free(leaf->ignorableText);
239#endif
240// free(leaf); 239// free(leaf);
241 } 240 }
242} 241}
@@ -300,10 +299,8 @@ LSL_Leaf *checkVariable(LuaSL_compiler *compiler, LSL_Leaf *identifier)
300 299
301 if (NULL == var) 300 if (NULL == var)
302 PE("NOT found %s @ line %d, column %d!", identifier->value.stringValue, identifier->line, identifier->column); 301 PE("NOT found %s @ line %d, column %d!", identifier->value.stringValue, identifier->line, identifier->column);
303#ifdef LUASL_DEBUG 302 else if (LUASL_DEBUG)
304 else
305 PI("Found %s!", identifier->value.stringValue); 303 PI("Found %s!", identifier->value.stringValue);
306#endif
307 304
308 return var; 305 return var;
309} 306}
@@ -491,11 +488,12 @@ LSL_Leaf *collectParameters(LuaSL_compiler *compiler, LSL_Leaf *list, LSL_Leaf *
491 { 488 {
492 if (newParam) 489 if (newParam)
493 { 490 {
494#ifdef LUASL_DIFF_CHECK 491 if (LUASL_DIFF_CHECK)
495 // Stash the comma for diff later. 492 {
496 if (comma) 493 // Stash the comma for diff later.
497 eina_inarray_append(&(func->vars), comma); 494 if (comma)
498#endif 495 eina_inarray_append(&(func->vars), comma);
496 }
499 eina_inarray_append(&(func->vars), newParam); 497 eina_inarray_append(&(func->vars), newParam);
500 // At this point, pointers to newParams are not pointing to the one in func->vars, AND newParam is no longer needed. 498 // At this point, pointers to newParams are not pointing to the one in func->vars, AND newParam is no longer needed.
501 } 499 }
@@ -526,7 +524,7 @@ LSL_Leaf *addFunction(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identi
526 else 524 else
527 identifier->basicType = OT_nothing; 525 identifier->basicType = OT_nothing;
528 eina_hash_add(compiler->script.functions, func->name, identifier); 526 eina_hash_add(compiler->script.functions, func->name, identifier);
529#ifdef LUASL_DIFF_CHECK 527#if LUASL_DIFF_CHECK
530 func->params = addParenthesis(open, params, LSL_PARAMETER_LIST, close); 528 func->params = addParenthesis(open, params, LSL_PARAMETER_LIST, close);
531#endif 529#endif
532 } 530 }
@@ -597,7 +595,7 @@ LSL_Leaf *addParenthesis(LSL_Leaf *lval, LSL_Leaf *expr, LSL_Type type, LSL_Leaf
597 { 595 {
598 parens->contents = expr; 596 parens->contents = expr;
599 parens->type = type; 597 parens->type = type;
600#ifdef LUASL_DIFF_CHECK 598#if LUASL_DIFF_CHECK
601 parens->rightIgnorableText = rval->ignorableText; 599 parens->rightIgnorableText = rval->ignorableText;
602 // Actualy, at this point, rval is no longer needed. 600 // Actualy, at this point, rval is no longer needed.
603// rval->ignorableText = eina_strbuf_new(); 601// rval->ignorableText = eina_strbuf_new();
@@ -789,9 +787,8 @@ static LSL_Leaf *evaluateFloatToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf
789 787
790 if (content && result) 788 if (content && result)
791 { 789 {
792#ifdef LUASL_DEBUG 790 if (LUASL_DEBUG)
793 printf(" <%g> ", content->value.floatValue); 791 printf(" <%g> ", content->value.floatValue);
794#endif
795 memcpy(result, content, sizeof(LSL_Leaf)); 792 memcpy(result, content, sizeof(LSL_Leaf));
796 result->basicType = OT_float; 793 result->basicType = OT_float;
797 } 794 }
@@ -804,9 +801,8 @@ static LSL_Leaf *evaluateIntegerToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Lea
804 801
805 if (content && result) 802 if (content && result)
806 { 803 {
807#ifdef LUASL_DEBUG 804 if (LUASL_DEBUG)
808 printf(" <%d> ", content->value.integerValue); 805 printf(" <%d> ", content->value.integerValue);
809#endif
810 memcpy(result, content, sizeof(LSL_Leaf)); 806 memcpy(result, content, sizeof(LSL_Leaf));
811 result->basicType = OT_integer; 807 result->basicType = OT_integer;
812 } 808 }
@@ -886,9 +882,8 @@ static LSL_Leaf *evaluateOperationToken(LSL_Leaf *content, LSL_Leaf *left, LSL_L
886 882
887 if (content && result) 883 if (content && result)
888 { 884 {
889#ifdef LUASL_DEBUG 885 if (LUASL_DEBUG)
890 printf(" [%s] ", content->token->token); 886 printf(" [%s] ", content->token->token);
891#endif
892 887
893 memcpy(result, content, sizeof(LSL_Leaf)); 888 memcpy(result, content, sizeof(LSL_Leaf));
894 889
@@ -940,9 +935,8 @@ static LSL_Leaf *evaluateOperationToken(LSL_Leaf *content, LSL_Leaf *left, LSL_L
940 case LSL_EQUAL : result->value.floatValue = fleft == fright; break; 935 case LSL_EQUAL : result->value.floatValue = fleft == fright; break;
941 case LSL_NOT_EQUAL : result->value.floatValue = fleft != fright; break; 936 case LSL_NOT_EQUAL : result->value.floatValue = fleft != fright; break;
942 } 937 }
943#ifdef LUASL_DEBUG 938 if (LUASL_DEBUG)
944 printf(" (=%g) ", result->value.floatValue); 939 printf(" (=%g) ", result->value.floatValue);
945#endif
946 break; 940 break;
947 } 941 }
948 942
@@ -991,9 +985,8 @@ static LSL_Leaf *evaluateOperationToken(LSL_Leaf *content, LSL_Leaf *left, LSL_L
991 case LSL_BOOL_OR : result->value.integerValue = left->value.integerValue || right->value.integerValue; break; 985 case LSL_BOOL_OR : result->value.integerValue = left->value.integerValue || right->value.integerValue; break;
992 case LSL_BOOL_AND : result->value.integerValue = left->value.integerValue && right->value.integerValue; break; 986 case LSL_BOOL_AND : result->value.integerValue = left->value.integerValue && right->value.integerValue; break;
993 } 987 }
994#ifdef LUASL_DEBUG 988 if (LUASL_DEBUG)
995 printf(" (=%d) ", result->value.integerValue); 989 printf(" (=%d) ", result->value.integerValue);
996#endif
997 break; 990 break;
998 } 991 }
999 992
@@ -1047,7 +1040,7 @@ static void outputLeaf(FILE *file, outputMode mode, LSL_Leaf *leaf)
1047 if (leaf) 1040 if (leaf)
1048 { 1041 {
1049 outputLeaf(file, mode, leaf->left); 1042 outputLeaf(file, mode, leaf->left);
1050#ifdef LUASL_DIFF_CHECK 1043#if LUASL_DIFF_CHECK
1051 if ((!(LSL_NOIGNORE & leaf->token->flags)) && (leaf->ignorableText)) 1044 if ((!(LSL_NOIGNORE & leaf->token->flags)) && (leaf->ignorableText))
1052 fwrite(eina_strbuf_string_get(leaf->ignorableText), 1, eina_strbuf_length_get(leaf->ignorableText), file); 1045 fwrite(eina_strbuf_string_get(leaf->ignorableText), 1, eina_strbuf_length_get(leaf->ignorableText), file);
1053#endif 1046#endif
@@ -1105,9 +1098,8 @@ static void outputFunctionToken(FILE *file, outputMode mode, LSL_Leaf *content)
1105 } 1098 }
1106 fprintf(file, ")"); 1099 fprintf(file, ")");
1107 outputLeaf(file, mode, func->block); 1100 outputLeaf(file, mode, func->block);
1108#ifndef LUASL_DIFF_CHECK 1101 if (!LUASL_DIFF_CHECK)
1109 fprintf(file, "\n"); 1102 fprintf(file, "\n");
1110#endif
1111 } 1103 }
1112} 1104}
1113 1105
@@ -1132,11 +1124,12 @@ static void outputIntegerToken(FILE *file, outputMode mode, LSL_Leaf *content)
1132static void outputIdentifierToken(FILE *file, outputMode mode, LSL_Leaf *content) 1124static void outputIdentifierToken(FILE *file, outputMode mode, LSL_Leaf *content)
1133{ 1125{
1134 if (content) 1126 if (content)
1135#ifdef LUASL_DIFF_CHECK 1127 {
1136 fprintf(file, "%s", content->value.identifierValue->name); 1128 if (LUASL_DIFF_CHECK)
1137#else 1129 fprintf(file, "%s", content->value.identifierValue->name);
1138 fprintf(file, " %s", content->value.identifierValue->name); 1130 else
1139#endif 1131 fprintf(file, " %s", content->value.identifierValue->name);
1132 }
1140} 1133}
1141 1134
1142static void outputParameterListToken(FILE *file, outputMode mode, LSL_Leaf *content) 1135static void outputParameterListToken(FILE *file, outputMode mode, LSL_Leaf *content)
@@ -1154,7 +1147,7 @@ static void outputParenthesisToken(FILE *file, outputMode mode, LSL_Leaf *conten
1154 fprintf(file, "%s", allowed[content->basicType].name); // TODO - We are missing the type ignorable text here. 1147 fprintf(file, "%s", allowed[content->basicType].name); // TODO - We are missing the type ignorable text here.
1155 else 1148 else
1156 outputLeaf(file, mode, content->value.parenthesis->contents); 1149 outputLeaf(file, mode, content->value.parenthesis->contents);
1157#ifdef LUASL_DIFF_CHECK 1150#if LUASL_DIFF_CHECK
1158 fprintf(file, "%s)", eina_strbuf_string_get(content->value.parenthesis->rightIgnorableText)); 1151 fprintf(file, "%s)", eina_strbuf_string_get(content->value.parenthesis->rightIgnorableText));
1159#else 1152#else
1160 fprintf(file, ")"); 1153 fprintf(file, ")");
@@ -1187,15 +1180,14 @@ static void outputStatementToken(FILE *file, outputMode mode, LSL_Leaf *content)
1187 if (content) 1180 if (content)
1188 { 1181 {
1189 outputLeaf(file, mode, content->value.statementValue->expressions); 1182 outputLeaf(file, mode, content->value.statementValue->expressions);
1190#ifdef LUASL_DIFF_CHECK 1183#if LUASL_DIFF_CHECK
1191 if (content->ignorableText) 1184 if (content->ignorableText)
1192 fwrite(eina_strbuf_string_get(content->ignorableText), 1, eina_strbuf_length_get(content->ignorableText), file); 1185 fwrite(eina_strbuf_string_get(content->ignorableText), 1, eina_strbuf_length_get(content->ignorableText), file);
1193#endif 1186#endif
1194 if (LSL_FUNCTION != content->value.statementValue->type) 1187 if (LSL_FUNCTION != content->value.statementValue->type)
1195 fprintf(file, "%s", content->token->token); 1188 fprintf(file, "%s", content->token->token);
1196#ifndef LUASL_DIFF_CHECK 1189 if (!LUASL_DIFF_CHECK)
1197 fprintf(file, "\n"); 1190 fprintf(file, "\n");
1198#endif
1199 } 1191 }
1200} 1192}
1201 1193
@@ -1209,7 +1201,6 @@ static boolean doneParsing(LuaSL_compiler *compiler)
1209 FILE *out; 1201 FILE *out;
1210 char buffer[PATH_MAX]; 1202 char buffer[PATH_MAX];
1211 char outName[PATH_MAX]; 1203 char outName[PATH_MAX];
1212 char diffName[PATH_MAX];
1213 char luaName[PATH_MAX]; 1204 char luaName[PATH_MAX];
1214 1205
1215// outputLeaf(stdout, OM_LSL, compiler->ast); 1206// outputLeaf(stdout, OM_LSL, compiler->ast);
@@ -1217,31 +1208,32 @@ static boolean doneParsing(LuaSL_compiler *compiler)
1217 evaluateLeaf(compiler->ast, NULL, NULL); 1208 evaluateLeaf(compiler->ast, NULL, NULL);
1218// printf("\n"); 1209// printf("\n");
1219 1210
1220 strcpy(outName, compiler->fileName); 1211 if (LUASL_DIFF_CHECK)
1221 strcat(outName, "2");
1222 strcpy(diffName, compiler->fileName);
1223 strcat(diffName, ".diff");
1224 strcpy(luaName, compiler->fileName);
1225 strcat(luaName, ".lua");
1226 out = fopen(outName, "w");
1227 if (out)
1228 { 1212 {
1229#ifdef LUASL_DIFF_CHECK 1213 strcpy(outName, compiler->fileName);
1230// int count; 1214 strcat(outName, "2");
1231#endif 1215 out = fopen(outName, "w");
1232 outputLeaf(out, OM_LSL, compiler->ast); 1216 if (out)
1233 fclose(out); 1217 {
1234 sprintf(buffer, "diff \"%s\" \"%s\" > \"%s\"", compiler->fileName, outName, diffName); 1218 char diffName[PATH_MAX];
1235#ifdef LUASL_DIFF_CHECK 1219// int count;
1236// count = system(buffer); 1220
1237// if (0 != count) 1221 strcpy(diffName, compiler->fileName);
1238// PE("LSL output file is different - %s!", outName); 1222 strcat(diffName, ".diff");
1239// else 1223 outputLeaf(out, OM_LSL, compiler->ast);
1240// result = TRUE; 1224 fclose(out);
1241#endif 1225 sprintf(buffer, "diff \"%s\" \"%s\" > \"%s\"", compiler->fileName, outName, diffName);
1226// count = system(buffer);
1227// if (0 != count)
1228// PE("LSL output file is different - %s!", outName);
1229// else
1230// result = TRUE;
1231 }
1232 else
1233 PC("Unable to open file %s for writing!", outName);
1242 } 1234 }
1243 else 1235 strcpy(luaName, compiler->fileName);
1244 PC("Unable to open file %s for writing!", outName); 1236 strcat(luaName, ".lua");
1245 out = fopen(luaName, "w"); 1237 out = fopen(luaName, "w");
1246 if (out) 1238 if (out)
1247 { 1239 {
@@ -1306,7 +1298,7 @@ boolean compileLSL(gameGlobals *game, char *script, boolean doConstants)
1306 compiler.script.states = eina_hash_stringshared_new(burnLeaf); 1298 compiler.script.states = eina_hash_stringshared_new(burnLeaf);
1307 compiler.script.variables = eina_hash_stringshared_new(burnLeaf); 1299 compiler.script.variables = eina_hash_stringshared_new(burnLeaf);
1308 eina_clist_init(&(compiler.danglingCalls)); 1300 eina_clist_init(&(compiler.danglingCalls));
1309#ifdef LUASL_DIFF_CHECK 1301#if LUASL_DIFF_CHECK
1310 compiler.ignorableText = eina_strbuf_new(); 1302 compiler.ignorableText = eina_strbuf_new();
1311#endif 1303#endif
1312 1304
@@ -1328,10 +1320,11 @@ boolean compileLSL(gameGlobals *game, char *script, boolean doConstants)
1328 1320
1329 if (yylex_init_extra(&compiler, &(compiler.scanner))) 1321 if (yylex_init_extra(&compiler, &(compiler.scanner)))
1330 return result; 1322 return result;
1331#ifdef LUASL_DEBUG 1323 if (LUASL_DEBUG)
1332 yyset_debug(1, compiler.scanner); 1324 {
1333 ParseTrace(stdout, "LSL_lemon "); 1325 yyset_debug(1, compiler.scanner);
1334#endif 1326 ParseTrace(stdout, "LSL_lemon ");
1327 }
1335 yyset_in(compiler.file, compiler.scanner); 1328 yyset_in(compiler.file, compiler.scanner);
1336 // on EOF yylex will return 0 1329 // on EOF yylex will return 0
1337 while((yv = yylex(compiler.lval, compiler.scanner)) != 0) 1330 while((yv = yylex(compiler.lval, compiler.scanner)) != 0)
@@ -1504,10 +1497,11 @@ int main(int argc, char **argv)
1504 1497
1505 if (yylex_init_extra(&param, &(param.scanner))) 1498 if (yylex_init_extra(&param, &(param.scanner)))
1506 return 1; 1499 return 1;
1507#ifdef LUASL_DEBUG 1500 if (LUASL_DEBUG)
1508 yyset_debug(1, param.scanner); 1501 {
1509 ParseTrace(stdout, "LSL_lemon "); 1502 yyset_debug(1, param.scanner);
1510#endif 1503 ParseTrace(stdout, "LSL_lemon ");
1504 }
1511 yyset_in(param.file, param.scanner); 1505 yyset_in(param.file, param.scanner);
1512 // on EOF yylex will return 0 1506 // on EOF yylex will return 0
1513 while((yv = yylex(param.lval, param.scanner)) != 0) 1507 while((yv = yylex(param.lval, param.scanner)) != 0)