aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/src/LuaSL_compile.c
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-01-17 13:39:35 +1000
committerDavid Walter Seikel2012-01-17 13:39:35 +1000
commit7d9c4da112a2c97f32c734393256498c023a0ebb (patch)
treec72efa9f13e30aaed1224280b286c4f51b0c4219 /LuaSL/src/LuaSL_compile.c
parentCleanups for EFL. (diff)
downloadSledjHamr-7d9c4da112a2c97f32c734393256498c023a0ebb.zip
SledjHamr-7d9c4da112a2c97f32c734393256498c023a0ebb.tar.gz
SledjHamr-7d9c4da112a2c97f32c734393256498c023a0ebb.tar.bz2
SledjHamr-7d9c4da112a2c97f32c734393256498c023a0ebb.tar.xz
Change that butt ugly name.
Diffstat (limited to '')
-rw-r--r--LuaSL/src/LuaSL_compile.c111
1 files changed, 55 insertions, 56 deletions
diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c
index 030f140..583f940 100644
--- a/LuaSL/src/LuaSL_compile.c
+++ b/LuaSL/src/LuaSL_compile.c
@@ -209,9 +209,9 @@ void burnLeaf(LSL_Leaf *leaf)
209 } 209 }
210} 210}
211 211
212LSL_Leaf *addOperation(LuaSL_yyparseParam *param, LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right) 212LSL_Leaf *addOperation(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right)
213{ 213{
214 gameGlobals *game = param->game; 214 gameGlobals *game = compiler->game;
215 215
216 if (lval) 216 if (lval)
217 { 217 {
@@ -372,7 +372,7 @@ LSL_Leaf *addParenthesis(LSL_Leaf *lval, LSL_Leaf *expr, LSL_Type type, LSL_Leaf
372 return lval; 372 return lval;
373} 373}
374 374
375LSL_Leaf *addState(LuaSL_yyparseParam *param, LSL_Leaf *identifier, LSL_Leaf *block) 375LSL_Leaf *addState(LuaSL_compiler *compiler, LSL_Leaf *identifier, LSL_Leaf *block)
376{ 376{
377 LSL_State *result = calloc(1, sizeof(LSL_State)); 377 LSL_State *result = calloc(1, sizeof(LSL_State));
378 378
@@ -381,9 +381,9 @@ LSL_Leaf *addState(LuaSL_yyparseParam *param, LSL_Leaf *identifier, LSL_Leaf *bl
381 result->name = identifier->value.stringValue; 381 result->name = identifier->value.stringValue;
382 result->block = block; 382 result->block = block;
383 identifier->value.stateValue = result; 383 identifier->value.stateValue = result;
384 param->script.scount++; 384 compiler->script.scount++;
385 param->script.states = realloc(param->script.states, param->script.scount * sizeof(LSL_State *)); 385 compiler->script.states = realloc(compiler->script.states, compiler->script.scount * sizeof(LSL_State *));
386 param->script.states[param->script.scount - 1] = result; 386 compiler->script.states[compiler->script.scount - 1] = result;
387 } 387 }
388 388
389 return identifier; 389 return identifier;
@@ -429,7 +429,7 @@ LSL_Leaf *addTypecast(LSL_Leaf *lval, LSL_Leaf *type, LSL_Leaf *rval, LSL_Leaf *
429 return lval; 429 return lval;
430} 430}
431 431
432LSL_Leaf *addVariable(LuaSL_yyparseParam *param, LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *assignment, LSL_Leaf *expr) 432LSL_Leaf *addVariable(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *assignment, LSL_Leaf *expr)
433{ 433{
434 LSL_Identifier *result = calloc(1, sizeof(LSL_Identifier)); 434 LSL_Identifier *result = calloc(1, sizeof(LSL_Identifier));
435 435
@@ -446,38 +446,38 @@ LSL_Leaf *addVariable(LuaSL_yyparseParam *param, LSL_Leaf *type, LSL_Leaf *ident
446 identifier->basicType = type->basicType; 446 identifier->basicType = type->basicType;
447 result->value.basicType = type->basicType; 447 result->value.basicType = type->basicType;
448 } 448 }
449 if (param->currentBlock) 449 if (compiler->currentBlock)
450 { 450 {
451 param->currentBlock->vcount++; 451 compiler->currentBlock->vcount++;
452 param->currentBlock->variables = realloc(param->currentBlock->variables, param->currentBlock->vcount * sizeof(LSL_Identifier *)); 452 compiler->currentBlock->variables = realloc(compiler->currentBlock->variables, compiler->currentBlock->vcount * sizeof(LSL_Identifier *));
453 param->currentBlock->variables[param->currentBlock->vcount - 1] = result; 453 compiler->currentBlock->variables[compiler->currentBlock->vcount - 1] = result;
454 } 454 }
455 else 455 else
456 { 456 {
457 param->script.vcount++; 457 compiler->script.vcount++;
458 param->script.variables = realloc(param->script.variables, param->script.vcount * sizeof(LSL_Identifier *)); 458 compiler->script.variables = realloc(compiler->script.variables, compiler->script.vcount * sizeof(LSL_Identifier *));
459 param->script.variables[param->script.vcount - 1] = result; 459 compiler->script.variables[compiler->script.vcount - 1] = result;
460 } 460 }
461 } 461 }
462 462
463 return identifier; 463 return identifier;
464} 464}
465 465
466void beginBlock(LuaSL_yyparseParam *param, LSL_Leaf *block) 466void beginBlock(LuaSL_compiler *compiler, LSL_Leaf *block)
467{ 467{
468 LSL_Block *blok = malloc(sizeof(LSL_Block)); 468 LSL_Block *blok = malloc(sizeof(LSL_Block));
469 469
470 if (blok) 470 if (blok)
471 { 471 {
472 block->value.blockValue = blok; 472 block->value.blockValue = blok;
473 blok->outerBlock = param->currentBlock; 473 blok->outerBlock = compiler->currentBlock;
474 param->currentBlock = blok; 474 compiler->currentBlock = blok;
475 } 475 }
476} 476}
477 477
478void endBlock(LuaSL_yyparseParam *param, LSL_Leaf *block) 478void endBlock(LuaSL_compiler *compiler, LSL_Leaf *block)
479{ 479{
480 param->currentBlock = param->currentBlock->outerBlock; 480 compiler->currentBlock = compiler->currentBlock->outerBlock;
481} 481}
482 482
483static LSL_Leaf *evaluateLeaf(LSL_Leaf *leaf, LSL_Leaf *left, LSL_Leaf *right) 483static LSL_Leaf *evaluateLeaf(LSL_Leaf *leaf, LSL_Leaf *left, LSL_Leaf *right)
@@ -869,33 +869,33 @@ static void outputVariableToken(FILE *file, outputMode mode, LSL_Leaf *content)
869 fprintf(file, "%s", content->value.variableValue->name); 869 fprintf(file, "%s", content->value.variableValue->name);
870} 870}
871 871
872static void doneParsing(LuaSL_yyparseParam *param) 872static void doneParsing(LuaSL_compiler *compiler)
873{ 873{
874 gameGlobals *game = param->game; 874 gameGlobals *game = compiler->game;
875 875
876 if (param->ast) 876 if (compiler->ast)
877 { 877 {
878 FILE *out; 878 FILE *out;
879 char buffer[PATH_MAX]; 879 char buffer[PATH_MAX];
880 char outName[PATH_MAX]; 880 char outName[PATH_MAX];
881 char luaName[PATH_MAX]; 881 char luaName[PATH_MAX];
882 882
883 outputLeaf(stdout, OM_LSL, param->ast); 883 outputLeaf(stdout, OM_LSL, compiler->ast);
884 printf("\n"); 884 printf("\n");
885 evaluateLeaf(param->ast, NULL, NULL); 885 evaluateLeaf(compiler->ast, NULL, NULL);
886 printf("\n"); 886 printf("\n");
887 887
888 strcpy(outName, param->fileName); 888 strcpy(outName, compiler->fileName);
889 strcat(outName, "2"); 889 strcat(outName, "2");
890 strcpy(luaName, param->fileName); 890 strcpy(luaName, compiler->fileName);
891 strcat(luaName, ".lua"); 891 strcat(luaName, ".lua");
892 out = fopen(outName, "w"); 892 out = fopen(outName, "w");
893 if (out) 893 if (out)
894 { 894 {
895// int count; 895// int count;
896 outputLeaf(out, OM_LSL, param->ast); 896 outputLeaf(out, OM_LSL, compiler->ast);
897 fclose(out); 897 fclose(out);
898 sprintf(buffer, "diff %s %s", param->fileName, outName); 898 sprintf(buffer, "diff %s %s", compiler->fileName, outName);
899// count = system(buffer); 899// count = system(buffer);
900// PI("Return value of %s is %d", buffer, count); 900// PI("Return value of %s is %d", buffer, count);
901// if (0 != count) 901// if (0 != count)
@@ -906,7 +906,7 @@ static void doneParsing(LuaSL_yyparseParam *param)
906 out = fopen(luaName, "w"); 906 out = fopen(luaName, "w");
907 if (out) 907 if (out)
908 { 908 {
909 outputLeaf(out, OM_LUA, param->ast); 909 outputLeaf(out, OM_LUA, compiler->ast);
910 fclose(out); 910 fclose(out);
911 } 911 }
912 else 912 else
@@ -945,57 +945,56 @@ Eina_Bool compilerSetup(gameGlobals *game)
945Eina_Bool compileLSL(gameGlobals *game, char *script) 945Eina_Bool compileLSL(gameGlobals *game, char *script)
946{ 946{
947 Eina_Bool result = EINA_FALSE; 947 Eina_Bool result = EINA_FALSE;
948 LuaSL_yyparseParam param; 948 LuaSL_compiler compiler;
949 void *pParser = ParseAlloc(malloc); 949 void *pParser = ParseAlloc(malloc);
950 int yv; 950 int yv;
951 951
952// Parse the LSL script, validating it and reporting errors. 952// Parse the LSL script, validating it and reporting errors.
953// Just pass all constants and function names through to Lua, assume they are globals there. 953// Just pass all constants and function names through to Lua, assume they are globals there.
954 954
955 memset(&param, 0, sizeof(LuaSL_yyparseParam)); 955 memset(&compiler, 0, sizeof(LuaSL_compiler));
956 param.game = game; 956 compiler.game = game;
957 957
958 958 strncpy(compiler.fileName, script, PATH_MAX - 1);
959 strncpy(param.fileName, script, PATH_MAX - 1); 959 compiler.fileName[PATH_MAX - 1] = '\0';
960 param.fileName[PATH_MAX - 1] = '\0'; 960 compiler.file = fopen(compiler.fileName, "r");
961 param.file = fopen(param.fileName, "r"); 961 if (NULL == compiler.file)
962 if (NULL == param.file)
963 { 962 {
964 PE("Error opening file %s.", param.fileName); 963 PE("Error opening file %s.", compiler.fileName);
965 return FALSE; 964 return FALSE;
966 } 965 }
967 PI("Opened %s.", param.fileName); 966 PI("Opened %s.", compiler.fileName);
968 param.ast = NULL; 967 compiler.ast = NULL;
969 param.lval = calloc(1, sizeof(LSL_Leaf)); 968 compiler.lval = calloc(1, sizeof(LSL_Leaf));
970 // Text editors usually start counting at 1, even programmers editors. 969 // Text editors usually start counting at 1, even programmers editors.
971 param.column = 1; 970 compiler.column = 1;
972 param.line = 1; 971 compiler.line = 1;
973 972
974#ifdef LUASL_DEBUG 973#ifdef LUASL_DEBUG
975// yydebug= 5; 974// yydebug= 5;
976#endif 975#endif
977 if (yylex_init_extra(&param, &(param.scanner))) 976 if (yylex_init_extra(&compiler, &(compiler.scanner)))
978 return result; 977 return result;
979#ifdef LUASL_DEBUG 978#ifdef LUASL_DEBUG
980 yyset_debug(1, param.scanner); 979 yyset_debug(1, compiler.scanner);
981#endif 980#endif
982 yyset_in(param.file, param.scanner); 981 yyset_in(compiler.file, compiler.scanner);
983#ifdef LUASL_DEBUG 982#ifdef LUASL_DEBUG
984 ParseTrace(stdout, "LSL_lemon "); 983 ParseTrace(stdout, "LSL_lemon ");
985#endif 984#endif
986 // on EOF yylex will return 0 985 // on EOF yylex will return 0
987 while((yv = yylex(param.lval, param.scanner)) != 0) 986 while((yv = yylex(compiler.lval, compiler.scanner)) != 0)
988 { 987 {
989 Parse(pParser, yv, param.lval, &param); 988 Parse(pParser, yv, compiler.lval, &compiler);
990 if (LSL_SCRIPT == yv) 989 if (LSL_SCRIPT == yv)
991 break; 990 break;
992 param.lval = calloc(1, sizeof(LSL_Leaf)); 991 compiler.lval = calloc(1, sizeof(LSL_Leaf));
993 } 992 }
994 993
995 yylex_destroy(param.scanner); 994 yylex_destroy(compiler.scanner);
996 Parse (pParser, 0, param.lval, &param); 995 Parse (pParser, 0, compiler.lval, &compiler);
997 ParseFree(pParser, free); 996 ParseFree(pParser, free);
998 doneParsing(&param); 997 doneParsing(&compiler);
999 998
1000// Take the result of the parse, and convert it into Lua source. 999// Take the result of the parse, and convert it into Lua source.
1001// Each LSL script becomes a Lua state. 1000// Each LSL script becomes a Lua state.
@@ -1004,12 +1003,12 @@ Eina_Bool compileLSL(gameGlobals *game, char *script)
1004 1003
1005// Compile the Lua source by the Lua compiler. 1004// Compile the Lua source by the Lua compiler.
1006 1005
1007 if (NULL != param.file) 1006 if (NULL != compiler.file)
1008 { 1007 {
1009 fclose(param.file); 1008 fclose(compiler.file);
1010 param.file = NULL; 1009 compiler.file = NULL;
1011 } 1010 }
1012 burnLeaf(param.ast); 1011 burnLeaf(compiler.ast);
1013 1012
1014 return result; 1013 return result;
1015} 1014}