aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/libraries/Runnr.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libraries/Runnr.c')
-rw-r--r--src/libraries/Runnr.c157
1 files changed, 49 insertions, 108 deletions
diff --git a/src/libraries/Runnr.c b/src/libraries/Runnr.c
index 760a860..1f10d33 100644
--- a/src/libraries/Runnr.c
+++ b/src/libraries/Runnr.c
@@ -410,85 +410,20 @@ static int luaWriter(lua_State *L, const void* p, size_t sz, void* ud)
410 return result; 410 return result;
411} 411}
412 412
413// TODO - This didn't help the compile time much, perhaps move the rest of the compiling stage into this thread as a callback? 413// Gets called on the main thread when the compile thread ends or fails.
414/* 414static void _compileEnd(void *data, Ecore_Thread *thread)
415
416LuaSL.c : _data( ... "compile(" ...
417 allocate LuaSL_compiler
418 extract SID, file, and name from data stream
419 massage data into LuaCompiler
420 compileLSL(LuaCompiler, FALSE)
421LuaSL_compile.c : compileLSL()
422 init it
423* open the .LSL file
424* init lexer
425* run lexer in a loop
426* setup second pass in a loop
427* may do a sendBack()
428* secondPass(LuaSL_compiler, ... )
429* open the .lua file
430* generate Lua source code
431 compileScript(LuaSL_compiler)
432Runnr;c : compileScript(
433 start a feedback thread
434
435LuaSL.c : _compileCb
436 scriptAdd( ... )
437 Needs LuaCompiler-> file, SID, client, data
438 adds the compiled script to the list of scripts being run.
439 sendBack results
440 frees LuaCompiler-> luaName, SID, file. Alse frees LuaCompiler.
441
442
443typedef void (* compileCb)(LuaCompile *compiler);
444
445typedef struct _LuaCompile
446{
447 char *file, *SID, *luaName;
448 int bugCount;
449 void *data; OurGlobals, Passed to the call back, to be passed to scriptAdd, which stores it as a void pointer, then ... ????? Don't think it's actually used.
450 Ecore_Con_Client *client;
451 compileCb parser;
452 compileCb cb;
453} LuaCompiler;
454
455typedef struct
456{
457 LuaCompiler compiler;
458 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.
459 int argc;
460 char **argv;
461 FILE *file;
462 LSL_Leaf *ast;
463 LSL_Script script;
464 LSL_State state;
465#if LUASL_DIFF_CHECK
466 Eina_Strbuf *ignorable;
467#endif
468 LSL_Leaf *lval;
469 LSL_Block *currentBlock;
470 LSL_Function *currentFunction;
471 Eina_Clist danglingCalls; // HEAD for function calls used before the function is defined.
472 int column, line;
473 int undeclared;
474 boolean inState;
475 boolean doConstants;
476 boolean result;
477} LuaSL_compiler;
478
479
480*/
481
482static void _compileNotify(void *data, Ecore_Thread *thread, void *message)
483{ 415{
484 LuaCompiler *compiler = data; 416 LuaCompiler *compiler = data;
485 417
486 if (compiler->cb) compiler->cb(compiler); 418 if (compiler->cb) compiler->cb(compiler);
419 free(compiler->file);
420 free(compiler->luaName);
421 free(compiler->SID);
487} 422}
488 423
489// TODO - Should pass error messages back through a linked list. 424// TODO - Should pass error messages back through a linked list.
490// To eventually get passed back to the calling app via compiler->cb 425// To eventually get passed back to the calling app via compiler->errors and compiler->warnings.
491// We use - luaName, bugCount, cb 426// Will need ageneric "add this formatted string to a linked list" function, in SledjHamr.c
492static void _compileThread(void *data, Ecore_Thread *thread) 427static void _compileThread(void *data, Ecore_Thread *thread)
493{ 428{
494 LuaCompiler *compiler = data; 429 LuaCompiler *compiler = data;
@@ -499,62 +434,68 @@ static void _compileThread(void *data, Ecore_Thread *thread)
499 434
500 if (compiler->parser) compiler->parser(compiler); 435 if (compiler->parser) compiler->parser(compiler);
501 436
502 strcpy(name, compiler->luaName); 437 if (compiler->luaName)
503 if ((L = luaL_newstate()))
504 { 438 {
505 luaL_openlibs(L); 439 strcpy(name, compiler->luaName);
506 // This ends up pushing a function onto the stack. The function is the compiled code. 440 if ((L = luaL_newstate()))
507 err = luaL_loadfile(L, name);
508 if (err)
509 { 441 {
510 compiler->bugCount++; 442 luaL_openlibs(L);
511 if (LUA_ERRSYNTAX == err) 443 // This ends up pushing a function onto the stack. The function is the compiled code.
512 printf("Lua syntax error in %s: %s\n", name, lua_tostring(L, -1)); 444 err = luaL_loadfile(L, name);
513 else if (LUA_ERRFILE == err) 445 if (err)
514 printf("Lua compile file error in %s: %s\n", name, lua_tostring(L, -1));
515 else if (LUA_ERRMEM == err)
516 printf("Lua compile memory allocation error in %s: %s\n", name, lua_tostring(L, -1));
517 }
518 else
519 {
520 // Write the compiled code to a file.
521 strcat(name, ".out");
522 out = fopen(name, "w");
523 if (out)
524 { 446 {
525 err = lua_dump(L, luaWriter, out); 447 compiler->bugCount++;
526 if (err) 448 if (LUA_ERRSYNTAX == err)
527 { 449 printf("Lua syntax error in %s: %s\n", name, lua_tostring(L, -1));
528 compiler->bugCount++; 450 else if (LUA_ERRFILE == err)
529 printf("Lua compile file error writing to %s\n", name); 451 printf("Lua compile file error in %s: %s\n", name, lua_tostring(L, -1));
530 } 452 else if (LUA_ERRMEM == err)
531 fclose(out); 453 printf("Lua compile memory allocation error in %s: %s\n", name, lua_tostring(L, -1));
532 } 454 }
533 else 455 else
534 { 456 {
535 compiler->bugCount++; 457 // Write the compiled code to a file.
536 printf("CRITICAL! Unable to open file %s for writing!\n", name); 458 strcat(name, ".out");
459 out = fopen(name, "w");
460 if (out)
461 {
462 err = lua_dump(L, luaWriter, out);
463 if (err)
464 {
465 compiler->bugCount++;
466 printf("Lua compile file error writing to %s\n", name);
467 }
468 fclose(out);
469 }
470 else
471 {
472 compiler->bugCount++;
473 printf("CRITICAL! Unable to open file %s for writing!\n", name);
474 }
537 } 475 }
538 } 476 }
477 else if (!compiler->doConstants)
478 {
479 compiler->bugCount++;
480 printf("Can't create a new Lua state!\n");
481 }
539 } 482 }
540 else 483 else
541 { 484 {
542 compiler->bugCount++; 485 compiler->bugCount++;
543 printf("Can't create a new Lua state!\n"); 486 printf("Nothing for Lua to compile!\n");
544 } 487 }
545
546 if (thread)
547 ecore_thread_feedback(thread, compiler);
548 else
549 _compileNotify(compiler, thread, NULL);
550} 488}
551 489
552void compileScript(LuaCompiler *compiler, int threadIt) 490void compileScript(LuaCompiler *compiler, int threadIt)
553{ 491{
554 if (threadIt) 492 if (threadIt)
555 ecore_thread_feedback_run(_compileThread, _compileNotify, NULL, NULL, compiler, EINA_FALSE); 493 ecore_thread_run(_compileThread, _compileEnd, _compileEnd, compiler);
556 else 494 else
495 {
557 _compileThread(compiler, NULL); 496 _compileThread(compiler, NULL);
497 _compileEnd(compiler, NULL);
498 }
558} 499}
559 500
560// Assumes the scripts mutex is taken already. 501// Assumes the scripts mutex is taken already.