summaryrefslogtreecommitdiff
path: root/src/program.c
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2012-07-31 19:25:34 +0000
committerAdrian Thurston <thurston@complang.org>2012-07-31 19:25:34 +0000
commit08343d0ee997c788a720a4c9756161dc8f881b15 (patch)
tree697fce2e94d94607bef74f87177a65582cac92b2 /src/program.c
parentd5a996a46e9244c363f93d346ae532ded759fccf (diff)
downloadcolm-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/program.c')
-rw-r--r--src/program.c79
1 files changed, 42 insertions, 37 deletions
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;