aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/LuaSL/LuaSL_LSL_tree.h4
-rw-r--r--src/LuaSL/LuaSL_compile.c17
-rw-r--r--src/LuaSL/LuaSL_main.c23
-rw-r--r--src/libraries/Runnr.c90
-rw-r--r--src/libraries/Runnr.h7
5 files changed, 78 insertions, 63 deletions
diff --git a/src/LuaSL/LuaSL_LSL_tree.h b/src/LuaSL/LuaSL_LSL_tree.h
index e7c5e36..514443a 100644
--- a/src/LuaSL/LuaSL_LSL_tree.h
+++ b/src/LuaSL/LuaSL_LSL_tree.h
@@ -3,8 +3,6 @@
3#define __LUASL_TREE_H__ 3#define __LUASL_TREE_H__
4 4
5#define LUASL_DEBUG 0 5#define LUASL_DEBUG 0
6#define COMPILE_THREADED 1
7#define COMPILE_OUTPUT 0
8#define LUASL_DIFF_CHECK 0 6#define LUASL_DIFF_CHECK 0
9#define LUASL_BAD_CHECK 0 7#define LUASL_BAD_CHECK 0
10 8
@@ -408,8 +406,6 @@ typedef struct
408#endif 406#endif
409 407
410 408
411void finishMessage(LuaCompile *compiler, compileMessage *message, int type, int column, int line);
412
413boolean compilerSetup(gameGlobals *ourGlobals); 409boolean compilerSetup(gameGlobals *ourGlobals);
414void compileLSL(LuaCompiler *compiler); 410void compileLSL(LuaCompiler *compiler);
415void burnLeaf(void *data); 411void burnLeaf(void *data);
diff --git a/src/LuaSL/LuaSL_compile.c b/src/LuaSL/LuaSL_compile.c
index 13ebe1e..2b838e3 100644
--- a/src/LuaSL/LuaSL_compile.c
+++ b/src/LuaSL/LuaSL_compile.c
@@ -220,15 +220,6 @@ LSL_Script constants;
220int lowestToken = 999999; 220int lowestToken = 999999;
221 221
222 222
223void finishMessage(LuaCompile *compiler, compileMessage *message, int type, int column, int line)
224{
225 message->type = type;
226 message->column = column;
227 message->line = line;
228 if (type)
229 compiler->bugCount++;
230}
231
232static LSL_Leaf *newLeaf(LSL_Type type, LSL_Leaf *left, LSL_Leaf *right) 223static LSL_Leaf *newLeaf(LSL_Type type, LSL_Leaf *left, LSL_Leaf *right)
233{ 224{
234 LSL_Leaf *leaf = calloc(1, sizeof(LSL_Leaf)); 225 LSL_Leaf *leaf = calloc(1, sizeof(LSL_Leaf));
@@ -596,7 +587,7 @@ else if (right)
596 printf("NOLEFT %s %s\n", lval->toKen->toKen, right->toKen->toKen); 587 printf("NOLEFT %s %s\n", lval->toKen->toKen, right->toKen->toKen);
597else 588else
598 printf("NOLEFT %s NORIGHT\n", lval->toKen->toKen); 589 printf("NOLEFT %s NORIGHT\n", lval->toKen->toKen);
599 printf("############################################################################## left\n"); 590 printf("############################################################################## left - column %i, line %i %s\n", lval->column, lval->line, compiler->compiler->file);
600#endif 591#endif
601 left->flags |= MF_WRAPFUNC; 592 left->flags |= MF_WRAPFUNC;
602 if (LSL_PARENTHESIS_OPEN == left->toKen->type) 593 if (LSL_PARENTHESIS_OPEN == left->toKen->type)
@@ -2222,7 +2213,7 @@ boolean compilerSetup(gameGlobals *ourGlobals)
2222 if (tokens) 2213 if (tokens)
2223 { 2214 {
2224 char buf[PATH_MAX]; 2215 char buf[PATH_MAX];
2225 LuaCompiler *compiler = calloc(1, sizeof(LuaCompiler)); 2216 LuaCompiler *compiler;
2226 2217
2227 // Sort the token table. 2218 // Sort the token table.
2228 for (i = 0; LSL_Tokens[i].toKen != NULL; i++) 2219 for (i = 0; LSL_Tokens[i].toKen != NULL; i++)
@@ -2236,10 +2227,8 @@ boolean compilerSetup(gameGlobals *ourGlobals)
2236 snprintf(buf, sizeof(buf), "luajit -e 'require(\"LSL\").gimmeLSL()' > %s/constants.lsl", prefix_lib_get()); 2227 snprintf(buf, sizeof(buf), "luajit -e 'require(\"LSL\").gimmeLSL()' > %s/constants.lsl", prefix_lib_get());
2237 system(buf); 2228 system(buf);
2238 snprintf(buf, sizeof(buf), "%s/constants.lsl", prefix_lib_get()); 2229 snprintf(buf, sizeof(buf), "%s/constants.lsl", prefix_lib_get());
2239 compiler->file = strdup(buf); 2230 compiler = createCompiler("FAKE_SID", buf, (compileCb) compileLSL, NULL);
2240 compiler->SID = strdup("FAKE_SID");
2241 compiler->doConstants = TRUE; 2231 compiler->doConstants = TRUE;
2242 compiler->parser = (compileCb) compileLSL;
2243 compileScript(compiler, FALSE); 2232 compileScript(compiler, FALSE);
2244 2233
2245 return TRUE; 2234 return TRUE;
diff --git a/src/LuaSL/LuaSL_main.c b/src/LuaSL/LuaSL_main.c
index 664cdd1..b72a155 100644
--- a/src/LuaSL/LuaSL_main.c
+++ b/src/LuaSL/LuaSL_main.c
@@ -228,7 +228,7 @@ static Eina_Bool parser(void *data, Connection *connection, char *SID, char *com
228 { 228 {
229 char *temp; 229 char *temp;
230 char *file; 230 char *file;
231 LuaCompiler *compiler = calloc(1, sizeof(LuaCompiler)); 231 LuaCompiler *compiler;
232 232
233 strcpy(buf, &command[8]); 233 strcpy(buf, &command[8]);
234 temp = buf; 234 temp = buf;
@@ -237,15 +237,10 @@ static Eina_Bool parser(void *data, Connection *connection, char *SID, char *com
237 temp++; 237 temp++;
238 temp[0] = '\0'; 238 temp[0] = '\0';
239 239
240 eina_clist_init(&(compiler->messages)); 240 compiler = createCompiler(SID, file, (compileCb) compileLSL, _compileCb);
241 compiler->file = strdup(file);
242 compiler->SID = strdup(SID);
243 compiler->client = connection; 241 compiler->client = connection;
244 compiler->doConstants = FALSE; 242 PI("Compiling script %s", file);
245 compiler->parser = (compileCb) compileLSL; 243 compileScript(compiler, TRUE);
246 compiler->cb = _compileCb;
247PD("Compiling script %s", file);
248 compileScript(compiler, COMPILE_THREADED);
249 } 244 }
250 else if (0 == strncmp(command, "run(", 4)) 245 else if (0 == strncmp(command, "run(", 4))
251 { 246 {
@@ -266,7 +261,7 @@ PD("Compiling script %s", file);
266 me = getScript(SID); 261 me = getScript(SID);
267 if (me) 262 if (me)
268 { 263 {
269PD("Running script %s", me->fileName); 264 PI("Running script %s", me->fileName);
270 runScript(me); 265 runScript(me);
271 releaseScript(me); 266 releaseScript(me);
272 } 267 }
@@ -311,13 +306,9 @@ int main(int argc, char **argv)
311 // get the arguments passed in 306 // get the arguments passed in
312 while (--argc > 0 && *++argv != '\0') 307 while (--argc > 0 && *++argv != '\0')
313 { 308 {
314 LuaCompiler *compiler = calloc(1, sizeof(LuaCompiler)); 309 LuaCompiler *compiler;
315 310
316 eina_clist_init(&(compiler->messages)); 311 compiler = createCompiler("0", *argv, (compileCb) compileLSL, _compileCbSingle);
317 compiler->file = strdup(*argv);
318 compiler->SID = strdup("0");
319 compiler->doConstants = FALSE;
320 compiler->parser = (compileCb) compileLSL;
321 compiler->cb = _compileCbSingle; 312 compiler->cb = _compileCbSingle;
322 compileScript(compiler, FALSE); 313 compileScript(compiler, FALSE);
323 } 314 }
diff --git a/src/libraries/Runnr.c b/src/libraries/Runnr.c
index 04547b4..9324800 100644
--- a/src/libraries/Runnr.c
+++ b/src/libraries/Runnr.c
@@ -21,6 +21,14 @@ static const struct luaL_reg runnrFunctions[] =
21 { NULL, NULL } 21 { NULL, NULL }
22}; 22};
23 23
24void finishMessage(LuaCompile *compiler, compileMessage *message, int type, int column, int line)
25{
26 message->type = type;
27 message->column = column;
28 message->line = line;
29 if (type)
30 compiler->bugCount++;
31}
24 32
25void dumpStack(lua_State *L, int i) 33void dumpStack(lua_State *L, int i)
26{ 34{
@@ -201,7 +209,7 @@ static void _workerFunction(void *data, Ecore_Thread *thread)
201 // The documentation is not clear on which thread is which inside and out, 209 // The documentation is not clear on which thread is which inside and out,
202 // but states that at least for some they are different. 210 // but states that at least for some they are different.
203 // So store the internal one as well. 211 // So store the internal one as well.
204#if THREADIT 212#if COMPILE_THREADED
205 s->me = thread; 213 s->me = thread;
206#endif 214#endif
207 215
@@ -289,7 +297,7 @@ static void _workerFunction(void *data, Ecore_Thread *thread)
289 if (RUNNR_FINISHED == s->status) 297 if (RUNNR_FINISHED == s->status)
290 { 298 {
291//PD("_workerFunction() FINISHED %s", s->name); 299//PD("_workerFunction() FINISHED %s", s->name);
292#if THREADIT 300#if COMPILE_THREADED
293 ecore_thread_cancel(thread); 301 ecore_thread_cancel(thread);
294#else 302#else
295 _cancel(s, NULL); 303 _cancel(s, NULL);
@@ -299,7 +307,7 @@ static void _workerFunction(void *data, Ecore_Thread *thread)
299 { 307 {
300;//PD("_workerFunction() WAIT %s", s->name); 308;//PD("_workerFunction() WAIT %s", s->name);
301 } 309 }
302#if THREADIT 310#if COMPILE_THREADED
303 else if (RUNNR_READY == s->status) 311 else if (RUNNR_READY == s->status)
304 ecore_thread_reschedule(thread); 312 ecore_thread_reschedule(thread);
305#endif 313#endif
@@ -326,13 +334,13 @@ static void _cancel(void *data, Ecore_Thread *thread)
326//PD("^^^^^^^^^^^^^^^^^^^_del(, %s)", s->name); 334//PD("^^^^^^^^^^^^^^^^^^^_del(, %s)", s->name);
327 // TODO - Perhaps have our own deletion callback to pass back? 335 // TODO - Perhaps have our own deletion callback to pass back?
328 releaseScript(s); 336 releaseScript(s);
329#if THREADIT 337#if COMPILE_THREADED
330 eina_lock_free(&s->mutex); 338 eina_lock_free(&s->mutex);
331#endif 339#endif
332 free(s); 340 free(s);
333} 341}
334 342
335#if THREADIT 343#if COMPILE_THREADED
336static void _end(void *data, Ecore_Thread *thread) 344static void _end(void *data, Ecore_Thread *thread)
337{ 345{
338} 346}
@@ -348,7 +356,7 @@ static Eina_Bool _enterer(void *data)
348 if ((RUNNR_WAIT == s->status) && (eina_clist_count(&s->messages))) 356 if ((RUNNR_WAIT == s->status) && (eina_clist_count(&s->messages)))
349 { 357 {
350 s->status = RUNNR_READY; 358 s->status = RUNNR_READY;
351#if THREADIT 359#if COMPILE_THREADED
352 ecore_thread_feedback_run(_workerFunction, _notify, _end, _cancel, s, EINA_FALSE); 360 ecore_thread_feedback_run(_workerFunction, _notify, _end, _cancel, s, EINA_FALSE);
353#else 361#else
354 _workerFunction(s, NULL); 362 _workerFunction(s, NULL);
@@ -356,7 +364,7 @@ static Eina_Bool _enterer(void *data)
356 } 364 }
357 if ((RUNNR_RESET == s->status) || (RUNNR_READY == s->status) || (RUNNR_RUNNING == s->status) || (RUNNR_NOT_STARTED == s->status)) 365 if ((RUNNR_RESET == s->status) || (RUNNR_READY == s->status) || (RUNNR_RUNNING == s->status) || (RUNNR_NOT_STARTED == s->status))
358 { 366 {
359#if THREADIT 367#if COMPILE_THREADED
360 ecore_thread_feedback_run(_workerFunction, _notify, _end, _cancel, s, EINA_FALSE); 368 ecore_thread_feedback_run(_workerFunction, _notify, _end, _cancel, s, EINA_FALSE);
361#else 369#else
362 _workerFunction(s, NULL); 370 _workerFunction(s, NULL);
@@ -389,7 +397,7 @@ script *scriptAdd(char *file, char *SID, RunnrServerCb send2server, void *data)
389 result->name = &result->fileName[strlen(prefix_data_get())]; 397 result->name = &result->fileName[strlen(prefix_data_get())];
390 sprintf(result->binName, "%s.lua.out", result->fileName); 398 sprintf(result->binName, "%s.lua.out", result->fileName);
391 399
392#if THREADIT 400#if COMPILE_THREADED
393 eina_lock_new(&result->mutex); 401 eina_lock_new(&result->mutex);
394#endif 402#endif
395 eina_clist_init(&(result->messages)); 403 eina_clist_init(&(result->messages));
@@ -400,6 +408,20 @@ script *scriptAdd(char *file, char *SID, RunnrServerCb send2server, void *data)
400 return result; 408 return result;
401} 409}
402 410
411LuaCompiler *createCompiler(char *SID, char *file, compileCb parser, compileCb cb)
412{
413 LuaCompiler *compiler = calloc(1, sizeof(LuaCompiler));
414
415 eina_clist_init(&(compiler->messages));
416 compiler->file = strdup(file);
417 compiler->SID = strdup(SID);
418 compiler->doConstants = FALSE;
419 compiler->parser = parser;
420 compiler->cb = cb;
421
422 return compiler;
423}
424
403static int luaWriter(lua_State *L, const void* p, size_t sz, void* ud) 425static int luaWriter(lua_State *L, const void* p, size_t sz, void* ud)
404{ 426{
405 FILE *out = ud; 427 FILE *out = ud;
@@ -441,15 +463,21 @@ static void _compileThread(void *data, Ecore_Thread *thread)
441 err = luaL_loadfile(L, name); 463 err = luaL_loadfile(L, name);
442 if (err) 464 if (err)
443 { 465 {
444 compiler->bugCount++; 466 compileMessage *message;
445#if COMPILE_OUTPUT 467
446 if (LUA_ERRSYNTAX == err) 468 if (LUA_ERRSYNTAX == err)
447 PI("Lua syntax error in %s: %s", name, lua_tostring(L, -1)); 469 message = addMessage(&(compiler->messages), sizeof(compileMessage),
470 "Lua syntax error in %s: %s", name, lua_tostring(L, -1));
448 else if (LUA_ERRFILE == err) 471 else if (LUA_ERRFILE == err)
449 PE("Lua compile file error in %s: %s", name, lua_tostring(L, -1)); 472 message = addMessage(&(compiler->messages), sizeof(compileMessage),
473 "Lua compile file error in %s: %s", name, lua_tostring(L, -1));
450 else if (LUA_ERRMEM == err) 474 else if (LUA_ERRMEM == err)
451 PC("Lua compile memory allocation error in %s: %s", name, lua_tostring(L, -1)); 475 message = addMessage(&(compiler->messages), sizeof(compileMessage),
452#endif 476 "Lua compile memory allocation error in %s: %s", name, lua_tostring(L, -1));
477 else
478 message = addMessage(&(compiler->messages), sizeof(compileMessage),
479 "Lua unknown error %d in %s.", err, name);
480 finishMessage(compiler, message, 1, 0, 0);
453 } 481 }
454 else 482 else
455 { 483 {
@@ -461,29 +489,33 @@ static void _compileThread(void *data, Ecore_Thread *thread)
461 err = lua_dump(L, luaWriter, out); 489 err = lua_dump(L, luaWriter, out);
462 if (err) 490 if (err)
463 { 491 {
464 compiler->bugCount++; 492 finishMessage(compiler, addMessage(&(compiler->messages), sizeof(compileMessage),
465 PE("Lua compile file error writing to %s", name); 493 "Lua compile file error writing to %s", name),
494 1, 0, 0);
466 } 495 }
467 fclose(out); 496 fclose(out);
468 } 497 }
469 else 498 else
470 { 499 {
471 compiler->bugCount++; 500 finishMessage(compiler, addMessage(&(compiler->messages), sizeof(compileMessage),
472 PE("CRITICAL! Unable to open file %s for writing!", name); 501 "CRITICAL! Unable to open file %s for writing!", name),
502 1, 0, 0);
473 } 503 }
474 } 504 }
475 } 505 }
476 else if (!compiler->doConstants) 506 else if (!compiler->doConstants)
477 { 507 {
478 compiler->bugCount++; 508 finishMessage(compiler, addMessage(&(compiler->messages), sizeof(compileMessage),
479 PC("Can't create a new Lua state!"); 509 "Can't create a new Lua state!"),
510 1, 0, 0);
480 } 511 }
481 } 512 }
482 else 513 else
483 { 514 {
484 compiler->bugCount++;
485#if COMPILE_OUTPUT 515#if COMPILE_OUTPUT
486 PW("Nothing for Lua to compile!"); 516 finishMessage(compiler, addMessage(&(compiler->messages), sizeof(compileMessage),
517 "Nothing for Lua to compile!"),
518 1, 0, 0);
487#endif 519#endif
488 } 520 }
489} 521}
@@ -493,9 +525,11 @@ static void _compileThread(void *data, Ecore_Thread *thread)
493// But with outputting to the console - 450 - 700 750 - 800 525// But with outputting to the console - 450 - 700 750 - 800
494void compileScript(LuaCompiler *compiler, int threadIt) 526void compileScript(LuaCompiler *compiler, int threadIt)
495{ 527{
528#if COMPILE_THREADED
496 if (threadIt) 529 if (threadIt)
497 ecore_thread_run(_compileThread, _compileEnd, _compileEnd, compiler); 530 ecore_thread_run(_compileThread, _compileEnd, _compileEnd, compiler);
498 else 531 else
532#endif
499 { 533 {
500 _compileThread(compiler, NULL); 534 _compileThread(compiler, NULL);
501 _compileEnd(compiler, NULL); 535 _compileEnd(compiler, NULL);
@@ -505,11 +539,11 @@ void compileScript(LuaCompiler *compiler, int threadIt)
505// Assumes the scripts mutex is taken already. 539// Assumes the scripts mutex is taken already.
506void runScript(script *s) 540void runScript(script *s)
507{ 541{
508#if THREADIT 542#if COMPILE_THREADED
509 if ((RUNNR_NOT_STARTED == s->status) || (RUNNR_FINISHED == s->status)) 543 if ((RUNNR_NOT_STARTED == s->status) || (RUNNR_FINISHED == s->status))
510#endif 544#endif
511 { 545 {
512#if THREADIT 546#if COMPILE_THREADED
513 ecore_thread_feedback_run(_workerFunction, _notify, _end, _cancel, s, EINA_FALSE); 547 ecore_thread_feedback_run(_workerFunction, _notify, _end, _cancel, s, EINA_FALSE);
514#else 548#else
515 _workerFunction(s, NULL); 549 _workerFunction(s, NULL);
@@ -542,7 +576,7 @@ script *getScript(char *SID)
542 576
543void takeScript(script *s) 577void takeScript(script *s)
544{ 578{
545#if THREADIT 579#if COMPILE_THREADED
546 Eina_Lock_Result result = eina_lock_take(&s->mutex); 580 Eina_Lock_Result result = eina_lock_take(&s->mutex);
547 if (EINA_LOCK_DEADLOCK == result) PE("Script %s IS DEADLOCKED!", s->name); 581 if (EINA_LOCK_DEADLOCK == result) PE("Script %s IS DEADLOCKED!", s->name);
548 if (EINA_LOCK_FAIL == result) PE("Script %s LOCK FAILED!", s->name); 582 if (EINA_LOCK_FAIL == result) PE("Script %s LOCK FAILED!", s->name);
@@ -551,7 +585,7 @@ void takeScript(script *s)
551 585
552void releaseScript(script *s) 586void releaseScript(script *s)
553{ 587{
554#if THREADIT 588#if COMPILE_THREADED
555 eina_lock_release(&s->mutex); 589 eina_lock_release(&s->mutex);
556#endif 590#endif
557} 591}
@@ -580,7 +614,7 @@ void send2script(const char *SID, const char *message)
580 stat = s->status; 614 stat = s->status;
581 s->status = RUNNR_READY; 615 s->status = RUNNR_READY;
582 if (RUNNR_WAIT == stat) 616 if (RUNNR_WAIT == stat)
583#if THREADIT 617#if COMPILE_THREADED
584 ecore_thread_feedback_run(_workerFunction, _notify, _end, _cancel, s, EINA_FALSE); 618 ecore_thread_feedback_run(_workerFunction, _notify, _end, _cancel, s, EINA_FALSE);
585#else 619#else
586 _workerFunction(s, NULL); 620 _workerFunction(s, NULL);
@@ -616,7 +650,7 @@ static int _send(lua_State *L)
616 else 650 else
617 { 651 {
618 takeScript(self); 652 takeScript(self);
619#if THREADIT 653#if COMPILE_THREADED
620 ecore_thread_feedback(self->me, strdup(message)); 654 ecore_thread_feedback(self->me, strdup(message));
621#else 655#else
622 _notify(self, NULL, strdup(message)); 656 _notify(self, NULL, strdup(message));
diff --git a/src/libraries/Runnr.h b/src/libraries/Runnr.h
index b44dca4..b3b394c 100644
--- a/src/libraries/Runnr.h
+++ b/src/libraries/Runnr.h
@@ -18,6 +18,9 @@
18// TODO - Should make this choosable at run time after more testing of Ecore_Thead. 18// TODO - Should make this choosable at run time after more testing of Ecore_Thead.
19#define THREADIT 0 19#define THREADIT 0
20 20
21#define COMPILE_THREADED 0
22#define COMPILE_OUTPUT 1
23
21typedef enum 24typedef enum
22{ 25{
23 RUNNR_COMPILING, 26 RUNNR_COMPILING,
@@ -56,7 +59,7 @@ typedef void (* RunnrServerCb)(script *me, const char *message);
56typedef struct _script 59typedef struct _script
57{ 60{
58 Eina_Clist node; 61 Eina_Clist node;
59#if THREADIT 62#if COMPILE_THREADED
60 Eina_Lock mutex; 63 Eina_Lock mutex;
61 Ecore_Thread *me; 64 Ecore_Thread *me;
62#endif 65#endif
@@ -83,7 +86,9 @@ typedef struct
83} scriptMessage; 86} scriptMessage;
84 87
85 88
89void finishMessage(LuaCompile *compiler, compileMessage *message, int type, int column, int line);
86script *scriptAdd(char *file, char *SID, RunnrServerCb send2server, void *data); 90script *scriptAdd(char *file, char *SID, RunnrServerCb send2server, void *data);
91LuaCompiler *createCompiler(char *SID, char *file, compileCb parser, compileCb cb);
87void compileScript(LuaCompiler *compiler, int threadIt); 92void compileScript(LuaCompiler *compiler, int threadIt);
88void runScript(script *me); 93void runScript(script *me);
89void resetScript(script *me); 94void resetScript(script *me);