diff options
Diffstat (limited to '')
-rw-r--r-- | src/libraries/Runnr.c | 90 | ||||
-rw-r--r-- | src/libraries/Runnr.h | 7 |
2 files changed, 68 insertions, 29 deletions
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 | ||
24 | void 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 | ||
25 | void dumpStack(lua_State *L, int i) | 33 | void 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 |
336 | static void _end(void *data, Ecore_Thread *thread) | 344 | static 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 | ||
411 | LuaCompiler *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 | |||
403 | static int luaWriter(lua_State *L, const void* p, size_t sz, void* ud) | 425 | static 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 |
494 | void compileScript(LuaCompiler *compiler, int threadIt) | 526 | void 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. |
506 | void runScript(script *s) | 540 | void 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 | ||
543 | void takeScript(script *s) | 577 | void 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 | ||
552 | void releaseScript(script *s) | 586 | void 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 | |||
21 | typedef enum | 24 | typedef enum |
22 | { | 25 | { |
23 | RUNNR_COMPILING, | 26 | RUNNR_COMPILING, |
@@ -56,7 +59,7 @@ typedef void (* RunnrServerCb)(script *me, const char *message); | |||
56 | typedef struct _script | 59 | typedef 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 | ||
89 | void finishMessage(LuaCompile *compiler, compileMessage *message, int type, int column, int line); | ||
86 | script *scriptAdd(char *file, char *SID, RunnrServerCb send2server, void *data); | 90 | script *scriptAdd(char *file, char *SID, RunnrServerCb send2server, void *data); |
91 | LuaCompiler *createCompiler(char *SID, char *file, compileCb parser, compileCb cb); | ||
87 | void compileScript(LuaCompiler *compiler, int threadIt); | 92 | void compileScript(LuaCompiler *compiler, int threadIt); |
88 | void runScript(script *me); | 93 | void runScript(script *me); |
89 | void resetScript(script *me); | 94 | void resetScript(script *me); |