aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--LuaSL/src/LuaSL.h3
-rw-r--r--LuaSL/src/LuaSL_LSL_tree.h3
-rw-r--r--LuaSL/src/LuaSL_compile.c32
-rw-r--r--LuaSL/src/LuaSL_lemon_yaccer.y72
-rw-r--r--LuaSL/src/LuaSL_main.c4
5 files changed, 71 insertions, 43 deletions
diff --git a/LuaSL/src/LuaSL.h b/LuaSL/src/LuaSL.h
index 509f155..852847d 100644
--- a/LuaSL/src/LuaSL.h
+++ b/LuaSL/src/LuaSL.h
@@ -56,11 +56,12 @@ typedef struct
56} gameGlobals; 56} gameGlobals;
57 57
58 58
59Eina_Bool compilerSetup(); 59Eina_Bool compilerSetup(gameGlobals *game);
60Eina_Bool compileLSL(gameGlobals *game, char *script); 60Eina_Bool compileLSL(gameGlobals *game, char *script);
61 61
62void loggingStartup(gameGlobals *game); 62void loggingStartup(gameGlobals *game);
63char *getDateTime(struct tm **nowOut, char *dateOut, time_t *tiemOut); 63char *getDateTime(struct tm **nowOut, char *dateOut, time_t *tiemOut);
64float timeDiff(struct timeval *now, struct timeval *then); 64float timeDiff(struct timeval *now, struct timeval *then);
65 65
66#include "LuaSL_LSL_tree.h"
66 67
diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h
index b287b8f..4b6e3c4 100644
--- a/LuaSL/src/LuaSL_LSL_tree.h
+++ b/LuaSL/src/LuaSL_LSL_tree.h
@@ -277,6 +277,7 @@ struct _LSL_Script
277 277
278typedef struct 278typedef struct
279{ 279{
280 gameGlobals *game;
280 void *scanner; // This should be of type yyscan_t, which is typedef to void * anyway, but that does not get defined until LuaSL_lexer.h, which depends on this struct being defined first. 281 void *scanner; // This should be of type yyscan_t, which is typedef to void * anyway, but that does not get defined until LuaSL_lexer.h, which depends on this struct being defined first.
281 int argc; 282 int argc;
282 char **argv; 283 char **argv;
@@ -298,7 +299,7 @@ typedef struct
298 299
299void burnLeaf(LSL_Leaf *leaf); 300void burnLeaf(LSL_Leaf *leaf);
300LSL_Leaf *addFunction(LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *open, LSL_Leaf *params, LSL_Leaf *close, LSL_Leaf *block); 301LSL_Leaf *addFunction(LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *open, LSL_Leaf *params, LSL_Leaf *close, LSL_Leaf *block);
301LSL_Leaf *addOperation(LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right); 302LSL_Leaf *addOperation(LuaSL_yyparseParam *param, LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right);
302LSL_Leaf *addParameter(LSL_Leaf *type, LSL_Leaf *newParam); 303LSL_Leaf *addParameter(LSL_Leaf *type, LSL_Leaf *newParam);
303LSL_Leaf *addParenthesis(LSL_Leaf *lval, LSL_Leaf *expr, LSL_Type type, LSL_Leaf *rval); 304LSL_Leaf *addParenthesis(LSL_Leaf *lval, LSL_Leaf *expr, LSL_Type type, LSL_Leaf *rval);
304LSL_Leaf *addState(LuaSL_yyparseParam *param, LSL_Leaf *identifier, LSL_Leaf *block); 305LSL_Leaf *addState(LuaSL_yyparseParam *param, LSL_Leaf *identifier, LSL_Leaf *block);
diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c
index 01657bc..030f140 100644
--- a/LuaSL/src/LuaSL_compile.c
+++ b/LuaSL/src/LuaSL_compile.c
@@ -1,5 +1,4 @@
1#include "LuaSL.h" 1#include "LuaSL.h"
2#include "LuaSL_LSL_tree.h"
3 2
4 3
5static LSL_Leaf *evaluateFloatToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right); 4static LSL_Leaf *evaluateFloatToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right);
@@ -210,8 +209,10 @@ void burnLeaf(LSL_Leaf *leaf)
210 } 209 }
211} 210}
212 211
213LSL_Leaf *addOperation(LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right) 212LSL_Leaf *addOperation(LuaSL_yyparseParam *param, LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right)
214{ 213{
214 gameGlobals *game = param->game;
215
215 if (lval) 216 if (lval)
216 { 217 {
217 opType lType, rType; 218 opType lType, rType;
@@ -283,7 +284,7 @@ LSL_Leaf *addOperation(LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right)
283 if (right) 284 if (right)
284 rightType = allowed[right->basicType].name; 285 rightType = allowed[right->basicType].name;
285 286
286 fprintf(stderr, "Invalid operation [%s %s %s] @ line %d column %d\n", leftType, lval->token->token, rightType, lval->line, lval->column); 287 PE("Invalid operation [%s %s %s] @ line %d column %d", leftType, lval->token->token, rightType, lval->line, lval->column);
287 } 288 }
288 } 289 }
289 290
@@ -870,6 +871,8 @@ static void outputVariableToken(FILE *file, outputMode mode, LSL_Leaf *content)
870 871
871static void doneParsing(LuaSL_yyparseParam *param) 872static void doneParsing(LuaSL_yyparseParam *param)
872{ 873{
874 gameGlobals *game = param->game;
875
873 if (param->ast) 876 if (param->ast)
874 { 877 {
875 FILE *out; 878 FILE *out;
@@ -894,12 +897,12 @@ static void doneParsing(LuaSL_yyparseParam *param)
894 fclose(out); 897 fclose(out);
895 sprintf(buffer, "diff %s %s", param->fileName, outName); 898 sprintf(buffer, "diff %s %s", param->fileName, outName);
896// count = system(buffer); 899// count = system(buffer);
897// printf("Return value of %s is %d\n", buffer, count); 900// PI("Return value of %s is %d", buffer, count);
898// if (0 != count) 901// if (0 != count)
899// fprintf(stderr, "%s says they are different!\n", buffer); 902// PE("%s says they are different!", buffer);
900 } 903 }
901 else 904 else
902 fprintf(stderr, "Unable to open file %s for writing!\n", outName); 905 PC("Unable to open file %s for writing!", outName);
903 out = fopen(luaName, "w"); 906 out = fopen(luaName, "w");
904 if (out) 907 if (out)
905 { 908 {
@@ -907,11 +910,11 @@ static void doneParsing(LuaSL_yyparseParam *param)
907 fclose(out); 910 fclose(out);
908 } 911 }
909 else 912 else
910 fprintf(stderr, "Unable to open file %s for writing!\n", luaName); 913 PC("Unable to open file %s for writing!", luaName);
911 } 914 }
912} 915}
913 916
914Eina_Bool compilerSetup() 917Eina_Bool compilerSetup(gameGlobals *game)
915{ 918{
916 int i; 919 int i;
917 920
@@ -934,7 +937,7 @@ Eina_Bool compilerSetup()
934 return EINA_TRUE; 937 return EINA_TRUE;
935 } 938 }
936 else 939 else
937 fprintf(stderr, "No memory for tokens!"); 940 PC("No memory for tokens!");
938 941
939 return EINA_FALSE; 942 return EINA_FALSE;
940} 943}
@@ -950,15 +953,18 @@ Eina_Bool compileLSL(gameGlobals *game, char *script)
950// 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.
951 954
952 memset(&param, 0, sizeof(LuaSL_yyparseParam)); 955 memset(&param, 0, sizeof(LuaSL_yyparseParam));
956 param.game = game;
957
958
953 strncpy(param.fileName, script, PATH_MAX - 1); 959 strncpy(param.fileName, script, PATH_MAX - 1);
954 param.fileName[PATH_MAX - 1] = '\0'; 960 param.fileName[PATH_MAX - 1] = '\0';
955 param.file = fopen(param.fileName, "r"); 961 param.file = fopen(param.fileName, "r");
956 if (NULL == param.file) 962 if (NULL == param.file)
957 { 963 {
958 fprintf(stderr, "Error opening file %s.\n", param.fileName); 964 PE("Error opening file %s.", param.fileName);
959 return FALSE; 965 return FALSE;
960 } 966 }
961 printf("Opened %s.\n", param.fileName); 967 PI("Opened %s.", param.fileName);
962 param.ast = NULL; 968 param.ast = NULL;
963 param.lval = calloc(1, sizeof(LSL_Leaf)); 969 param.lval = calloc(1, sizeof(LSL_Leaf));
964 // Text editors usually start counting at 1, even programmers editors. 970 // Text editors usually start counting at 1, even programmers editors.
@@ -1025,10 +1031,10 @@ static int nextFile(LuaSL_yyparseParam *param)
1025 param->file = fopen(param->fileName, "r"); 1031 param->file = fopen(param->fileName, "r");
1026 if (NULL == param->file) 1032 if (NULL == param->file)
1027 { 1033 {
1028 fprintf(stderr, "Error opening file %s.\n", param->fileName); 1034 PE(stderr, "Error opening file %s.", param->fileName);
1029 return FALSE; 1035 return FALSE;
1030 } 1036 }
1031 printf("Opened %s.\n", param->fileName); 1037 PE("Opened %s.", param->fileName);
1032 burnLeaf(param->ast); 1038 burnLeaf(param->ast);
1033 param->ast = NULL; 1039 param->ast = NULL;
1034 param->lval = calloc(1, sizeof(LSL_Leaf)); 1040 param->lval = calloc(1, sizeof(LSL_Leaf));
diff --git a/LuaSL/src/LuaSL_lemon_yaccer.y b/LuaSL/src/LuaSL_lemon_yaccer.y
index 5899052..3df7def 100644
--- a/LuaSL/src/LuaSL_lemon_yaccer.y
+++ b/LuaSL/src/LuaSL_lemon_yaccer.y
@@ -1,5 +1,5 @@
1%include { 1%include {
2#include "LuaSL_LSL_tree.h" 2#include "LuaSL.h"
3} 3}
4 4
5%extra_argument {LuaSL_yyparseParam *param} 5%extra_argument {LuaSL_yyparseParam *param}
@@ -89,40 +89,40 @@ exprList ::= expr.
89exprList ::= . 89exprList ::= .
90 90
91%right LSL_BOOL_AND. 91%right LSL_BOOL_AND.
92expr(A) ::= expr(B) LSL_BOOL_AND(C) expr(D). { A = addOperation(B, C, D); } 92expr(A) ::= expr(B) LSL_BOOL_AND(C) expr(D). { A = addOperation(param, B, C, D); }
93%right LSL_BOOL_OR. 93%right LSL_BOOL_OR.
94expr(A) ::= expr(B) LSL_BOOL_OR(C) expr(D). { A = addOperation(B, C, D); } 94expr(A) ::= expr(B) LSL_BOOL_OR(C) expr(D). { A = addOperation(param, B, C, D); }
95 95
96%left LSL_BIT_AND LSL_BIT_XOR LSL_BIT_OR. 96%left LSL_BIT_AND LSL_BIT_XOR LSL_BIT_OR.
97expr(A) ::= expr(B) LSL_BIT_OR(C) expr(D). { A = addOperation(B, C, D); } 97expr(A) ::= expr(B) LSL_BIT_OR(C) expr(D). { A = addOperation(param, B, C, D); }
98expr(A) ::= expr(B) LSL_BIT_XOR(C) expr(D). { A = addOperation(B, C, D); } 98expr(A) ::= expr(B) LSL_BIT_XOR(C) expr(D). { A = addOperation(param, B, C, D); }
99expr(A) ::= expr(B) LSL_BIT_AND(C) expr(D). { A = addOperation(B, C, D); } 99expr(A) ::= expr(B) LSL_BIT_AND(C) expr(D). { A = addOperation(param, B, C, D); }
100 100
101%right LSL_EQUAL LSL_NOT_EQUAL. 101%right LSL_EQUAL LSL_NOT_EQUAL.
102expr(A) ::= expr(B) LSL_NOT_EQUAL(C) expr(D). { A = addOperation(B, C, D); } 102expr(A) ::= expr(B) LSL_NOT_EQUAL(C) expr(D). { A = addOperation(param, B, C, D); }
103expr(A) ::= expr(B) LSL_EQUAL(C) expr(D). { A = addOperation(B, C, D); } 103expr(A) ::= expr(B) LSL_EQUAL(C) expr(D). { A = addOperation(param, B, C, D); }
104%right LSL_LESS_THAN LSL_GREATER_THAN LSL_LESS_EQUAL LSL_GREATER_EQUAL. 104%right LSL_LESS_THAN LSL_GREATER_THAN LSL_LESS_EQUAL LSL_GREATER_EQUAL.
105expr(A) ::= expr(B) LSL_GREATER_EQUAL(C) expr(D). { A = addOperation(B, C, D); } 105expr(A) ::= expr(B) LSL_GREATER_EQUAL(C) expr(D). { A = addOperation(param, B, C, D); }
106expr(A) ::= expr(B) LSL_LESS_EQUAL(C) expr(D). { A = addOperation(B, C, D); } 106expr(A) ::= expr(B) LSL_LESS_EQUAL(C) expr(D). { A = addOperation(param, B, C, D); }
107expr(A) ::= expr(B) LSL_GREATER_THAN(C) expr(D). { A = addOperation(B, C, D); } 107expr(A) ::= expr(B) LSL_GREATER_THAN(C) expr(D). { A = addOperation(param, B, C, D); }
108expr(A) ::= expr(B) LSL_LESS_THAN(C) expr(D). { A = addOperation(B, C, D); } 108expr(A) ::= expr(B) LSL_LESS_THAN(C) expr(D). { A = addOperation(param, B, C, D); }
109 109
110%left LSL_LEFT_SHIFT LSL_RIGHT_SHIFT. 110%left LSL_LEFT_SHIFT LSL_RIGHT_SHIFT.
111expr(A) ::= expr(B) LSL_RIGHT_SHIFT(C) expr(D). { A = addOperation(B, C, D); } 111expr(A) ::= expr(B) LSL_RIGHT_SHIFT(C) expr(D). { A = addOperation(param, B, C, D); }
112expr(A) ::= expr(B) LSL_LEFT_SHIFT(C) expr(D). { A = addOperation(B, C, D); } 112expr(A) ::= expr(B) LSL_LEFT_SHIFT(C) expr(D). { A = addOperation(param, B, C, D); }
113 113
114%left LSL_SUBTRACT LSL_ADD LSL_CONCATENATE. 114%left LSL_SUBTRACT LSL_ADD LSL_CONCATENATE.
115expr(A) ::= expr(B) LSL_ADD(C) expr(D). { A = addOperation(B, C, D); } 115expr(A) ::= expr(B) LSL_ADD(C) expr(D). { A = addOperation(param, B, C, D); }
116expr(A) ::= expr(B) LSL_SUBTRACT(C) expr(D). { A = addOperation(B, C, D); } 116expr(A) ::= expr(B) LSL_SUBTRACT(C) expr(D). { A = addOperation(param, B, C, D); }
117%left LSL_DIVIDE LSL_MODULO LSL_MULTIPLY LSL_DOT_PRODUCT LSL_CROSS_PRODUCT. 117%left LSL_DIVIDE LSL_MODULO LSL_MULTIPLY LSL_DOT_PRODUCT LSL_CROSS_PRODUCT.
118expr(A) ::= expr(B) LSL_MULTIPLY(C) expr(D). { A = addOperation(B, C, D); } 118expr(A) ::= expr(B) LSL_MULTIPLY(C) expr(D). { A = addOperation(param, B, C, D); }
119expr(A) ::= expr(B) LSL_MODULO(C) expr(D). { A = addOperation(B, C, D); } 119expr(A) ::= expr(B) LSL_MODULO(C) expr(D). { A = addOperation(param, B, C, D); }
120expr(A) ::= expr(B) LSL_DIVIDE(C) expr(D). { A = addOperation(B, C, D); } 120expr(A) ::= expr(B) LSL_DIVIDE(C) expr(D). { A = addOperation(param, B, C, D); }
121 121
122%right LSL_BIT_NOT LSL_BOOL_NOT LSL_NEGATION. 122%right LSL_BIT_NOT LSL_BOOL_NOT LSL_NEGATION.
123expr(A) ::= LSL_BIT_NOT(B) expr(C). { A = addOperation(NULL, B, C); } 123expr(A) ::= LSL_BIT_NOT(B) expr(C). { A = addOperation(param, NULL, B, C); }
124expr(A) ::= LSL_BOOL_NOT(B) expr(C). { A = addOperation(NULL, B, C); } 124expr(A) ::= LSL_BOOL_NOT(B) expr(C). { A = addOperation(param, NULL, B, C); }
125expr(A) ::= LSL_SUBTRACT(B) expr(C). [LSL_NEGATION] { A = addOperation(NULL, B, C); } 125expr(A) ::= LSL_SUBTRACT(B) expr(C). [LSL_NEGATION] { A = addOperation(param, NULL, B, C); }
126 126
127// Types, typecasts, and expression reordering. 127// Types, typecasts, and expression reordering.
128 128
@@ -198,13 +198,33 @@ expr ::= LSL_ANGLE_OPEN expr LSL_COMMA expr LSL_COMMA expr LSL_ANGLE_CLOSE. [L
198 198
199// Parser callbacks. 199// Parser callbacks.
200 200
201%parse_accept {printf("Parsing complete.\n");} 201%parse_accept
202{
203 gameGlobals *game = param->game;
202 204
203%parse_failure {fprintf(stderr,"Giving up. Parser is hopelessly lost!\n");} 205 PI("Parsing complete.");
206}
207
208%parse_failure
209{
210 gameGlobals *game = param->game;
211
212 PE("Giving up. Parser is hopelessly lost!");
213}
204 214
205%stack_overflow {fprintf(stderr,"*******************************************************************Giving up. Parser stack overflow @ line %04d column %04d\n", yypMinor->yy0->line, yypMinor->yy0->column);} // Gotta love consistancy, if it ever happens. 215%stack_overflow
216{
217 gameGlobals *game = param->game;
206 218
207%syntax_error {fprintf(stderr,"*******************************************************************Syntax error @ line %04d column %04d\n", yyminor.yy0->line, yyminor.yy0->column);} 219 PE("Giving up. Parser stack overflow @ line %04d column %04d.", yypMinor->yy0->line, yypMinor->yy0->column); // Gotta love consistancy, if it ever happens.
220}
221
222%syntax_error
223{
224 gameGlobals *game = param->game;
225
226 PE("Syntax error @ line %04d column %04d.", yyminor.yy0->line, yyminor.yy0->column);
227}
208 228
209 229
210/* Undocumented shit that might be useful later. Pffft 230/* Undocumented shit that might be useful later. Pffft
diff --git a/LuaSL/src/LuaSL_main.c b/LuaSL/src/LuaSL_main.c
index fb2a8ba..b1141c6 100644
--- a/LuaSL/src/LuaSL_main.c
+++ b/LuaSL/src/LuaSL_main.c
@@ -161,13 +161,13 @@ main(int argc, char **argv)
161 edje_object_signal_callback_add(game.edje, "*", "game_*", _edje_signal_cb, &game); 161 edje_object_signal_callback_add(game.edje, "*", "game_*", _edje_signal_cb, &game);
162 162
163 // Setup for the compler. 163 // Setup for the compler.
164 compilerSetup(); 164 compilerSetup(&game);
165// snprintf(buf, sizeof(buf), "%s/Test sim/objects/onefang's test bed/~run", PACKAGE_DATA_DIR); 165// snprintf(buf, sizeof(buf), "%s/Test sim/objects/onefang's test bed/~run", PACKAGE_DATA_DIR);
166 snprintf(buf, sizeof(buf), "%s/test2.lsl", PACKAGE_DATA_DIR); 166 snprintf(buf, sizeof(buf), "%s/test2.lsl", PACKAGE_DATA_DIR);
167 if (compileLSL(&game, buf)) 167 if (compileLSL(&game, buf))
168 PIm("Against all odds, the compile of %s worked! lol", buf); 168 PIm("Against all odds, the compile of %s worked! lol", buf);
169 else 169 else
170 PEm("The compile of %s failed, as expected!", buf); 170 PEm("The compile of %s failed!", buf);
171 171
172// ecore_main_loop_begin(); 172// ecore_main_loop_begin();
173 173