diff options
author | Adrian Thurston <thurston@complang.org> | 2008-11-11 23:07:57 +0000 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2008-11-11 23:07:57 +0000 |
commit | 86c0c6b3be492f8e79795b55970f01a76c86802a (patch) | |
tree | a758b6809cfd68d8fcdf62e9a02a2f65c8d04c9b | |
parent | 0f9262ebc36d0c4ef787990b6bc8c891c32f32a7 (diff) | |
download | colm-86c0c6b3be492f8e79795b55970f01a76c86802a.tar.gz |
Need a VM stack for parsing patterns. The VM stack is now used for more than
just VM execution (eg: printing and deallocation).
-rw-r--r-- | colm/bytecode.cpp | 13 | ||||
-rw-r--r-- | colm/bytecode.h | 2 | ||||
-rw-r--r-- | colm/parsedata.cpp | 7 |
3 files changed, 17 insertions, 5 deletions
diff --git a/colm/bytecode.cpp b/colm/bytecode.cpp index af229e24..ed305c9b 100644 --- a/colm/bytecode.cpp +++ b/colm/bytecode.cpp @@ -350,6 +350,14 @@ void Program::allocGlobal() global = tree; } +Tree **stack_alloc() +{ + //return new Tree*[VM_STACK_SIZE]; + + return (Tree**)mmap( 0, sizeof(Tree*)*VM_STACK_SIZE, + PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0 ); +} + void Program::run() { assert( sizeof(Int) <= sizeof(Tree) ); @@ -366,9 +374,8 @@ void Program::run() * Allocate the VM stack. */ - //vm_stack = new Tree*[VM_STACK_SIZE]; - Tree **vm_stack = (Tree**)mmap( 0, sizeof(Tree*)*VM_STACK_SIZE, - PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0 ); + Tree **vm_stack = stack_alloc(); + Tree **root = &vm_stack[VM_STACK_SIZE]; /* diff --git a/colm/bytecode.h b/colm/bytecode.h index 9d207087..5126c04f 100644 --- a/colm/bytecode.h +++ b/colm/bytecode.h @@ -495,6 +495,8 @@ Tree *tree_search( Kid *kid, long id ); Tree *tree_search( Tree *tree, long id ); void split_ref( Tree **&sp, Program *prg, Ref *fromRef ); +Tree **stack_alloc(); + /* * Maps */ diff --git a/colm/parsedata.cpp b/colm/parsedata.cpp index 3fadf73d..7d42f03b 100644 --- a/colm/parsedata.cpp +++ b/colm/parsedata.cpp @@ -1630,13 +1630,15 @@ void ParseData::parsePatterns() { Program program( false, runtimeData ); FsmRun fsmRun( &program ); + Tree **vm_stack = stack_alloc(); for ( ReplList::Iter repl = replList; repl.lte(); repl++ ) { //cerr << "parsing replacement: " << repl->data << endl; InputStreamRepl in( repl ); fsmRun.attachInputStream( &in ); - repl->pdaRun = new PdaRun( 0, &program, repl->langEl->pdaTables, &fsmRun, 0, false ); + repl->pdaRun = new PdaRun( vm_stack, &program, + repl->langEl->pdaTables, &fsmRun, 0, false ); repl->pdaRun->run(); //#ifdef COLM_LOG_COMPILE @@ -1649,7 +1651,8 @@ void ParseData::parsePatterns() InputStreamPattern in( pat ); fsmRun.attachInputStream( &in ); - pat->pdaRun = new PdaRun( 0, &program, pat->langEl->pdaTables, &fsmRun, 0, false ); + pat->pdaRun = new PdaRun( vm_stack, &program, + pat->langEl->pdaTables, &fsmRun, 0, false ); pat->pdaRun->run(); //#ifdef COLM_LOG_COMPILE |