summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2012-07-31 20:00:25 +0000
committerAdrian Thurston <thurston@complang.org>2012-07-31 20:00:25 +0000
commit39c9b4a6f1014cb30ee535d4f534d0dcc4fe5905 (patch)
treeb4b33795f9206bdc26d63888fd066ab0a974cbe4
parent08343d0ee997c788a720a4c9756161dc8f881b15 (diff)
downloadcolm-39c9b4a6f1014cb30ee535d4f534d0dcc4fe5905.tar.gz
munmap (free) the stack, relevant to long-lived programs
-rw-r--r--src/program.c46
1 files changed, 24 insertions, 22 deletions
diff --git a/src/program.c b/src/program.c
index f1c47691..63763fc6 100644
--- a/src/program.c
+++ b/src/program.c
@@ -44,6 +44,14 @@ void colmInit( long debugRealm )
colm_log_conds = 1;
colmActiveRealm = debugRealm;
initInputFuncs();
+
+ 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) );
}
void clearGlobal( Program *prg, Tree **sp )
@@ -76,6 +84,11 @@ Tree **stackAlloc()
PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0 );
}
+void stackFree( Tree **stack )
+{
+ munmap( stack, sizeof(Tree*)*VM_STACK_SIZE );
+}
+
Tree **vm_root( struct ColmProgram *prg )
{
return prg->vm_root;
@@ -128,43 +141,35 @@ Program *colmNewProgram( RuntimeData *rtd )
prg->returnVal = 0;
prg->lastParseError = 0;
- 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];
+ return prg;
+}
+
+void colmRunProgram( Program *prg, int argc, const char **argv )
+{
+ /* Make the arguments available to the program. */
+ prg->argc = argc;
+ prg->argv = argv;
+
/*
* 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 );
}
+ /* Clear the arg and stack. */
prg->argc = 0;
prg->argv = 0;
}
@@ -242,8 +247,6 @@ int colmDeleteProgram( Program *prg )
mapElClear( prg );
locationClear( prg );
- //memset( vm_stack, 0, sizeof(Tree*) * VM_STACK_SIZE);
-
RunBuf *rb = prg->allocRunBuf;
while ( rb != 0 ) {
RunBuf *next = rb->next;
@@ -251,9 +254,8 @@ int colmDeleteProgram( Program *prg )
rb = next;
}
+ stackFree( prg->vm_stack );
free( prg );
return exitStatus;
}
-
-