aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-02-12 02:34:41 +1000
committerDavid Walter Seikel2012-02-12 02:34:41 +1000
commit16fce1165cebdf772f39d9af55c4ee024c57d18a (patch)
tree682caa7aac682e737df71d9cfc69bb002fee56d3 /LuaSL
parentMake sendBack and Forth varargs. (diff)
downloadSledjHamr-16fce1165cebdf772f39d9af55c4ee024c57d18a.zip
SledjHamr-16fce1165cebdf772f39d9af55c4ee024c57d18a.tar.gz
SledjHamr-16fce1165cebdf772f39d9af55c4ee024c57d18a.tar.bz2
SledjHamr-16fce1165cebdf772f39d9af55c4ee024c57d18a.tar.xz
Implement compilerError() and compilerWarning(), and pass the client to the compiler so it can use them..
Diffstat (limited to 'LuaSL')
-rw-r--r--LuaSL/src/LuaSL_LSL_tree.h3
-rw-r--r--LuaSL/src/LuaSL_compile.c25
-rw-r--r--LuaSL/src/LuaSL_main.c2
-rw-r--r--LuaSL/src/LuaSL_test.c60
4 files changed, 68 insertions, 22 deletions
diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h
index 286d22d..600fb6f 100644
--- a/LuaSL/src/LuaSL_LSL_tree.h
+++ b/LuaSL/src/LuaSL_LSL_tree.h
@@ -387,6 +387,7 @@ Need to do something about that.
387typedef struct 387typedef struct
388{ 388{
389 gameGlobals *game; 389 gameGlobals *game;
390 Ecore_Con_Client *client;
390 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. 391 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.
391 int argc; 392 int argc;
392 char **argv; 393 char **argv;
@@ -415,7 +416,7 @@ typedef struct
415 416
416 417
417boolean compilerSetup(gameGlobals *game); 418boolean compilerSetup(gameGlobals *game);
418boolean compileLSL(gameGlobals *game, char *script, boolean doConstants); 419boolean compileLSL(gameGlobals *game, Ecore_Con_Client *client, char *script, boolean doConstants);
419void burnLeaf(void *data); 420void burnLeaf(void *data);
420 421
421LSL_Leaf *addBlock(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right); 422LSL_Leaf *addBlock(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right);
diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c
index 95761a2..8e9bd01 100644
--- a/LuaSL/src/LuaSL_compile.c
+++ b/LuaSL/src/LuaSL_compile.c
@@ -358,7 +358,7 @@ LSL_Leaf *checkVariable(LuaSL_compiler *compiler, LSL_Leaf *identifier, LSL_Leaf
358 else 358 else
359 { 359 {
360 compiler->script.bugCount++; 360 compiler->script.bugCount++;
361 PE("NOT found %s @ line %d, column %d!", identifier->value.stringValue, identifier->line, identifier->column); 361 sendBack(game, compiler->client, compiler->fileName, "compilerError(%d,%d,NOT found %s)", identifier->line, identifier->column, identifier->value.stringValue);
362 } 362 }
363 } 363 }
364 364
@@ -402,7 +402,7 @@ LSL_Leaf *addOperation(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval,
402 if (OT_undeclared == lType) 402 if (OT_undeclared == lType)
403 { 403 {
404 compiler->script.warningCount++; 404 compiler->script.warningCount++;
405 PW("Undeclared identifier issue, deferring this until the second pass. @ line %d, column %d.", lval->line, lval->column); 405 sendBack(game, compiler->client, compiler->fileName, "compilerWarning(%d,%d,Undeclared identifier issue, deferring this until the second pass)", lval->line, lval->column);
406 lval->basicType = OT_undeclared; 406 lval->basicType = OT_undeclared;
407 return lval; 407 return lval;
408 } 408 }
@@ -430,7 +430,7 @@ LSL_Leaf *addOperation(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval,
430 if (OT_undeclared == rType) 430 if (OT_undeclared == rType)
431 { 431 {
432 compiler->script.warningCount++; 432 compiler->script.warningCount++;
433 PW("Undeclared identifier issue, deferring this until the second pass. @ line %d, column %d.", lval->line, lval->column); 433 sendBack(game, compiler->client, compiler->fileName, "compilerWarning(%d,%d,Undeclared identifier issue, deferring this until the second pass)", lval->line, lval->column);
434 lval->basicType = OT_undeclared; 434 lval->basicType = OT_undeclared;
435 return lval; 435 return lval;
436 } 436 }
@@ -587,7 +587,7 @@ else
587 } 587 }
588 588
589 compiler->script.bugCount++; 589 compiler->script.bugCount++;
590 PE("Invalid operation [%s(%s) %s %s(%s)] @ line %d, column %d!", leftType, leftToken, lval->toKen->toKen, rightType, rightToken, lval->line, lval->column); 590 sendBack(game, compiler->client, compiler->fileName, "compilerError(%d,%d,Invalid operation [%s(%s) %s %s(%s)])", lval->line, lval->column, leftType, leftToken, lval->toKen->toKen, rightType, rightToken);
591 } 591 }
592 } 592 }
593 593
@@ -2120,7 +2120,7 @@ boolean compilerSetup(gameGlobals *game)
2120 2120
2121 // Compile the constants. 2121 // Compile the constants.
2122 snprintf(buf, sizeof(buf), "%s/src/constants.lsl", PACKAGE_DATA_DIR); 2122 snprintf(buf, sizeof(buf), "%s/src/constants.lsl", PACKAGE_DATA_DIR);
2123 compileLSL(game, buf, TRUE); 2123 compileLSL(game, NULL, buf, TRUE);
2124 2124
2125 return TRUE; 2125 return TRUE;
2126 } 2126 }
@@ -2140,7 +2140,7 @@ static int luaWriter(lua_State *L, const void* p, size_t sz, void* ud)
2140 return result; 2140 return result;
2141} 2141}
2142 2142
2143boolean compileLSL(gameGlobals *game, char *script, boolean doConstants) 2143boolean compileLSL(gameGlobals *game, Ecore_Con_Client *client, char *script, boolean doConstants)
2144{ 2144{
2145 boolean result = FALSE; 2145 boolean result = FALSE;
2146 LuaSL_compiler compiler; 2146 LuaSL_compiler compiler;
@@ -2152,6 +2152,7 @@ boolean compileLSL(gameGlobals *game, char *script, boolean doConstants)
2152 2152
2153 memset(&compiler, 0, sizeof(LuaSL_compiler)); 2153 memset(&compiler, 0, sizeof(LuaSL_compiler));
2154 compiler.game = game; 2154 compiler.game = game;
2155 compiler.client = client;
2155 compiler.script.functions = eina_hash_stringshared_new(burnLeaf); 2156 compiler.script.functions = eina_hash_stringshared_new(burnLeaf);
2156 compiler.script.states = eina_hash_stringshared_new(burnLeaf); 2157 compiler.script.states = eina_hash_stringshared_new(burnLeaf);
2157 compiler.script.variables = eina_hash_stringshared_new(burnLeaf); 2158 compiler.script.variables = eina_hash_stringshared_new(burnLeaf);
@@ -2215,7 +2216,7 @@ boolean compileLSL(gameGlobals *game, char *script, boolean doConstants)
2215 call->call->basicType = func->basicType; 2216 call->call->basicType = func->basicType;
2216 } 2217 }
2217 else 2218 else
2218 PE("Undeclared function %s called @ line %d, column %d!", call->call->value.stringValue, call->call->line, call->call->column); 2219 sendBack(game, compiler.client, compiler.fileName, "compilerError(%d,%d,Undeclared function %s called)", call->call->line, call->call->column, call->call->value.stringValue);
2219 } 2220 }
2220 } 2221 }
2221 secondPass(&compiler, compiler.ast); 2222 secondPass(&compiler, compiler.ast);
@@ -2319,16 +2320,8 @@ boolean compileLSL(gameGlobals *game, char *script, boolean doConstants)
2319 PC("Unable to open file %s for writing!", luaName); 2320 PC("Unable to open file %s for writing!", luaName);
2320 } 2321 }
2321 2322
2322 if (compiler.script.bugCount) 2323 if (0 == compiler.script.bugCount)
2323 PE("%d errors and %d warnings in %s", compiler.script.bugCount, compiler.script.warningCount, compiler.fileName);
2324 else
2325 {
2326 if (compiler.script.warningCount)
2327 PW("%d errors and %d warnings in %s", compiler.script.bugCount, compiler.script.warningCount, compiler.fileName);
2328// else
2329// PI("%d errors and %d warnings in %s", compiler.script.bugCount, compiler.script.warningCount, compiler.fileName);
2330 result = TRUE; 2324 result = TRUE;
2331 }
2332 } 2325 }
2333 2326
2334 if (NULL != compiler.file) 2327 if (NULL != compiler.file)
diff --git a/LuaSL/src/LuaSL_main.c b/LuaSL/src/LuaSL_main.c
index 7dad1c0..1056535 100644
--- a/LuaSL/src/LuaSL_main.c
+++ b/LuaSL/src/LuaSL_main.c
@@ -36,7 +36,7 @@ static Eina_Bool _data(void *data, int type __UNUSED__, Ecore_Con_Event_Client_D
36 if (0 == strcmp(command, "compile()")) 36 if (0 == strcmp(command, "compile()"))
37 { 37 {
38 PD("Compiling %s.", SID); 38 PD("Compiling %s.", SID);
39 if (compileLSL(game, SID, FALSE)) 39 if (compileLSL(game, ev->client, SID, FALSE))
40 sendBack(game, ev->client, SID, "compiled(true)"); 40 sendBack(game, ev->client, SID, "compiled(true)");
41 else 41 else
42 sendBack(game, ev->client, SID, "compiled(false)"); 42 sendBack(game, ev->client, SID, "compiled(false)");
diff --git a/LuaSL/src/LuaSL_test.c b/LuaSL/src/LuaSL_test.c
index f7087cf..ec7824a 100644
--- a/LuaSL/src/LuaSL_test.c
+++ b/LuaSL/src/LuaSL_test.c
@@ -8,7 +8,7 @@ typedef struct
8 char fileName[PATH_MAX]; 8 char fileName[PATH_MAX];
9 struct timeval startTime; 9 struct timeval startTime;
10 float compileTime; 10 float compileTime;
11 int errors, warnings; 11 int bugs, warnings;
12 boolean running; 12 boolean running;
13 13
14} script; 14} script;
@@ -144,6 +144,7 @@ static Eina_Bool _data(void *data, int type __UNUSED__, Ecore_Con_Event_Server_D
144{ 144{
145 gameGlobals *game = data; 145 gameGlobals *game = data;
146 146
147 char buf[PATH_MAX];
147 char SID[PATH_MAX]; 148 char SID[PATH_MAX];
148 const char *command; 149 const char *command;
149 char *ext; 150 char *ext;
@@ -160,14 +161,65 @@ static Eina_Bool _data(void *data, int type __UNUSED__, Ecore_Con_Event_Server_D
160 ext = rindex(SID, '.'); 161 ext = rindex(SID, '.');
161 if (ext) 162 if (ext)
162 { 163 {
164 script *me;
165
163 ext[0] = '\0'; 166 ext[0] = '\0';
164 command = ext + 1; 167 command = ext + 1;
165 if (0 == strcmp(command, "compiled(false)")) 168 me = eina_hash_find(game->scripts, SID);
169 if (0 == strncmp(command, "compilerWarning(", 16))
170 {
171 char *temp;
172 char *line;
173 char *column;
174 char *text;
175
176 strcpy(buf, &command[16]);
177 temp = buf;
178 line = temp;
179 while (',' != temp[0])
180 temp++;
181 temp[0] = '\0';
182 column = ++temp;
183 while (',' != temp[0])
184 temp++;
185 temp[0] = '\0';
186 text = ++temp;
187 while (')' != temp[0])
188 temp++;
189 temp[0] = '\0';
190 PW("%s @ line %s, column %s.", text, line, column);
191 if (me)
192 me->warnings++;
193 }
194 else if (0 == strncmp(command, "compilerError(", 14))
195 {
196 char *temp;
197 char *line;
198 char *column;
199 char *text;
200
201 strcpy(buf, &command[14]);
202 temp = buf;
203 line = temp;
204 while (',' != temp[0])
205 temp++;
206 temp[0] = '\0';
207 column = ++temp;
208 while (',' != temp[0])
209 temp++;
210 temp[0] = '\0';
211 text = ++temp;
212 while (')' != temp[0])
213 temp++;
214 temp[0] = '\0';
215 PE("%s @ line %s, column %s.", text, line, column);
216 if (me)
217 me->bugs++;
218 }
219 else if (0 == strcmp(command, "compiled(false)"))
166 PE("The compile of %s failed!", SID); 220 PE("The compile of %s failed!", SID);
167 else if (0 == strcmp(command, "compiled(true)")) 221 else if (0 == strcmp(command, "compiled(true)"))
168 { 222 {
169 script *me = eina_hash_find(game->scripts, SID);
170
171 if (me) 223 if (me)
172 { 224 {
173 struct timeval now; 225 struct timeval now;