diff options
author | Adrian Thurston <thurston@complang.org> | 2012-07-31 19:25:34 +0000 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2012-07-31 19:25:34 +0000 |
commit | 08343d0ee997c788a720a4c9756161dc8f881b15 (patch) | |
tree | 697fce2e94d94607bef74f87177a65582cac92b2 /src | |
parent | d5a996a46e9244c363f93d346ae532ded759fccf (diff) | |
download | colm-08343d0ee997c788a720a4c9756161dc8f881b15.tar.gz |
pass program arguments to colmRunProgram instead of colmNewProgram.
Idea with this is to make it possible to re-use an allocated program for more
than one invocation.
Diffstat (limited to 'src')
-rw-r--r-- | src/codegen.cc | 4 | ||||
-rw-r--r-- | src/colm.h | 4 | ||||
-rw-r--r-- | src/compiler.cc | 2 | ||||
-rw-r--r-- | src/program.c | 79 |
4 files changed, 47 insertions, 42 deletions
diff --git a/src/codegen.cc b/src/codegen.cc index 4403cf8f..f55257e7 100644 --- a/src/codegen.cc +++ b/src/codegen.cc @@ -37,8 +37,8 @@ void FsmCodeGen::writeMain() " struct ColmProgram *prg;\n" " int exitStatus;\n" " colmInit( " << colmActiveRealm << " );\n" - " prg = colmNewProgram( &main_runtimeData, argc, argv );\n" - " colmRunProgram( prg );\n" + " prg = colmNewProgram( &main_runtimeData );\n" + " colmRunProgram( prg, argc, argv );\n" " exitStatus = colmDeleteProgram( prg );\n" " return exitStatus;\n" "}\n" @@ -11,8 +11,8 @@ struct ColmProgram; struct ColmRuntimeData; void colmInit( long debugRealm ); -struct ColmProgram *colmNewProgram( struct ColmRuntimeData *rtd, int argc, const char **argv ); -void colmRunProgram( struct ColmProgram *prg ); +struct ColmProgram *colmNewProgram( struct ColmRuntimeData *rtd ); +void colmRunProgram( struct ColmProgram *prg, int argc, const char **argv ); int colmDeleteProgram( struct ColmProgram *prg ); struct ColmPrintArgs diff --git a/src/compiler.cc b/src/compiler.cc index e3676768..1e0c8c7f 100644 --- a/src/compiler.cc +++ b/src/compiler.cc @@ -1283,7 +1283,7 @@ void Compiler::initEmptyScanners() void Compiler::parsePatterns() { - Program *prg = colmNewProgram( runtimeData, 0, 0 ); + Program *prg = colmNewProgram( runtimeData ); /* Turn off context-dependent parsing. */ prg->ctxDepParsing = 0; diff --git a/src/program.c b/src/program.c index c17b8bb4..f1c47691 100644 --- a/src/program.c +++ b/src/program.c @@ -46,38 +46,6 @@ void colmInit( long debugRealm ) initInputFuncs(); } -void colmRunProgram( Program *prg ) -{ - assert( sizeof(Int) <= sizeof(Tree) ); - assert( sizeof(Str) <= sizeof(Tree) ); - assert( sizeof(Pointer) <= sizeof(Tree) ); - assert( sizeof(Map) <= sizeof(MapEl) ); - assert( sizeof(List) <= sizeof(MapEl) ); - assert( sizeof(Stream) <= sizeof(MapEl) ); - assert( sizeof(Parser) <= sizeof(MapEl) ); - - /* Allocate the global variable. */ - allocGlobal( prg ); - - /* - * Allocate the VM stack. - */ - - prg->vm_stack = stackAlloc(); - prg->vm_root = &prg->vm_stack[VM_STACK_SIZE]; - - /* - * Execute - */ - if ( prg->rtd->rootCodeLen > 0 ) { - //RtCodeVect rcodeCollect; - Execution execution; - - initExecution( &execution, 0, 0, 0, 0, prg->rtd->rootFrameId ); - mainExecution( prg, &execution, prg->rtd->rootCode ); - } -} - void clearGlobal( Program *prg, Tree **sp ) { /* Downref all the fields in the global object. */ @@ -104,8 +72,6 @@ void allocGlobal( Program *prg ) Tree **stackAlloc() { - //return new Tree*[VM_STACK_SIZE]; - return (Tree**)mmap( 0, sizeof(Tree*)*VM_STACK_SIZE, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0 ); } @@ -121,12 +87,12 @@ Tree *returnVal( struct ColmProgram *prg ) } -Program *colmNewProgram( RuntimeData *rtd, int argc, const char **argv ) +Program *colmNewProgram( RuntimeData *rtd ) { Program *prg = malloc(sizeof(Program)); memset( prg, 0, sizeof(Program) ); - prg->argc = argc; - prg->argv = argv; + prg->argc = 0; + prg->argv = 0; prg->rtd = rtd; prg->ctxDepParsing = 1; prg->global = 0; @@ -165,6 +131,45 @@ Program *colmNewProgram( RuntimeData *rtd, int argc, const char **argv ) return prg; } +void colmRunProgram( Program *prg, int argc, const char **argv ) +{ + prg->argc = argc; + prg->argv = argv; + + assert( sizeof(Int) <= sizeof(Tree) ); + assert( sizeof(Str) <= sizeof(Tree) ); + assert( sizeof(Pointer) <= sizeof(Tree) ); + assert( sizeof(Map) <= sizeof(MapEl) ); + assert( sizeof(List) <= sizeof(MapEl) ); + assert( sizeof(Stream) <= sizeof(MapEl) ); + assert( sizeof(Parser) <= sizeof(MapEl) ); + + /* Allocate the global variable. */ + allocGlobal( prg ); + + /* + * Allocate the VM stack. + */ + + prg->vm_stack = stackAlloc(); + prg->vm_root = &prg->vm_stack[VM_STACK_SIZE]; + + /* + * Execute + */ + if ( prg->rtd->rootCodeLen > 0 ) { + //RtCodeVect rcodeCollect; + Execution execution; + + initExecution( &execution, 0, 0, 0, 0, prg->rtd->rootFrameId ); + mainExecution( prg, &execution, prg->rtd->rootCode ); + } + + prg->argc = 0; + prg->argv = 0; +} + + int colmDeleteProgram( Program *prg ) { Tree **sp = prg->vm_root; |