summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2015-04-03 15:54:28 -0400
committerAdrian Thurston <thurston@complang.org>2015-04-03 15:54:28 -0400
commit3173d2e67c276514be2c9ee61e508a36f7570545 (patch)
tree6015c68107a025fa3fc582c78e5275eb370719ef
parentfa5f9a998a4138abed01557eadb577d316e3482d (diff)
downloadcolm-3173d2e67c276514be2c9ee61e508a36f7570545.tar.gz
removed the contiguous computation
Now that we have a separate contiguos space for args we no longer need to precompute the contiguous size before a function call. Can just issue a vm_congiguous immediately before a call for the callling convention items and the local frame.
-rw-r--r--src/bytecode.c43
-rw-r--r--src/bytecode.h2
-rw-r--r--src/compiler.h4
-rw-r--r--src/iter.c3
-rw-r--r--src/synthesis.cc55
-rw-r--r--test/load1.lm2
6 files changed, 17 insertions, 92 deletions
diff --git a/src/bytecode.c b/src/bytecode.c
index 87a2ad62..60f9666e 100644
--- a/src/bytecode.c
+++ b/src/bytecode.c
@@ -375,7 +375,7 @@ void colm_execute( Program *prg, Execution *exec, Code *code )
/* Set up the stack as if we have
* called. We allow a return value. */
- long stretch = 5 + fi->frameSize;
+ long stretch = FR_AA + fi->frameSize;
vm_contiguous( stretch );
vm_push_tree( 0 );
@@ -435,7 +435,7 @@ Tree *colm_run_func( struct colm_program *prg, int frameId,
}
}
- long stretch = 5 + fi->frameSize;
+ long stretch = FR_AA + fi->frameSize;
vm_contiguous( stretch );
/* Set up the stack as if we have called. We allow a return value. */
@@ -455,10 +455,7 @@ Tree *colm_run_func( struct colm_program *prg, int frameId,
sp = colm_execute_code( prg, &execution, sp, code );
treeDownref( prg, sp, prg->returnVal );
- prg->returnVal = execution.retVal; //vm_pop_tree();
-
-// downref_local_trees( prg, sp, &execution, fi->locals, fi->localsLen );
-// vm_popn( fi->frameSize );
+ prg->returnVal = execution.retVal;
vm_popn( paramCount );
@@ -2321,12 +2318,14 @@ again:
case IN_PCR_CALL: {
debug( prg, REALM_BYTECODE, "IN_PCR_CALL\n" );
+ int frameSize = 0;
if ( exec->parser->pdaRun->frameId >= 0 ) {
FrameInfo *fi = &prg->rtd->frameInfo[exec->parser->pdaRun->frameId];
- long stretch = fi->argSize + 4 + fi->frameSize;
- vm_contiguous( stretch );
+ frameSize = fi->frameSize;
}
+ vm_contiguous( 4 + frameSize );
+
vm_push_type( Tree**, exec->framePtr );
vm_push_type( Tree**, exec->iframePtr );
vm_push_type( long, exec->frameId );
@@ -3233,14 +3232,6 @@ again:
vm_push_tree( res );
break;
}
- case IN_CONTIGUOUS: {
- Half size;
- read_half( size );
- debug( prg, REALM_BYTECODE, "IN_CONTIGUOUS %hd\n", size );
- vm_contiguous( size );
- vm_push_tree( 0 );
- break;
- }
case IN_STASH_ARG: {
Half pos;
@@ -3302,6 +3293,8 @@ again:
debug( prg, REALM_BYTECODE, "IN_CALL_WV %s\n", fr->name );
+ vm_contiguous( FR_AA + fi->frameSize );
+
vm_push_type( Tree**, exec->callArgs );
vm_push_value( 0 ); /* Return value. */
vm_push_type( Code*, instr );
@@ -3325,6 +3318,8 @@ again:
debug( prg, REALM_BYTECODE, "IN_CALL_WC %s %d\n", fr->name, fr->frameSize );
+ vm_contiguous( FR_AA + fi->frameSize );
+
vm_push_type( Tree**, exec->callArgs );
vm_push_value( 0 ); /* Return value. */
vm_push_type( Code*, instr );
@@ -3382,6 +3377,8 @@ again:
UserIter *uiter = uiterCreate( prg, &sp, fi, searchId );
vm_set_local(exec, field, (SW) uiter);
+ vm_contiguous( FR_AA + fi->frameSize );
+
/* This is a setup similar to as a call, only the frame structure
* is slightly different for user iterators. We aren't going to do
* the call. We don't need to set up the return ip because the
@@ -3414,6 +3411,8 @@ again:
UserIter *uiter = uiterCreate( prg, &sp, fi, searchId );
vm_set_local(exec, field, (SW) uiter);
+ vm_contiguous( FR_AA + fi->frameSize );
+
/* This is a setup similar to as a call, only the frame structure
* is slightly different for user iterators. We aren't going to do
* the call. We don't need to set up the return ip because the
@@ -4134,24 +4133,12 @@ again:
vm_popn( fi->frameSize );
- /* This can help solve some crashes, but really need to move to
- * a register machine to make unwinding easier. Mixed values
- * living on the stack cannot be easily cleaned up in a
- * type-appropriate way. */
- //while ( vm_ptop() != exec->framePtr )
- // vm_pop_value();
-
-
/* Call layout. */
exec->frameId = vm_pop_type(long);
exec->framePtr = vm_pop_type(Tree**);
instr = vm_pop_type(Code*);
Tree *retVal = vm_pop_tree();
vm_pop_value();
-// vm_popn( fi->argSize );
-
- /* The CONTIGUOS PUSH. */
- vm_pop_tree();
/* The IN_PREP_ARGS stack data. */
vm_popn( fi->argSize );
diff --git a/src/bytecode.h b/src/bytecode.h
index 92938d53..9474b432 100644
--- a/src/bytecode.h
+++ b/src/bytecode.h
@@ -77,6 +77,7 @@ typedef unsigned long colm_value_t;
// 0xeb
// 0xec
// 0xd4
+// 0x5c
#define IN_LOAD_RETVAL 0xd4
@@ -284,7 +285,6 @@ typedef unsigned long colm_value_t;
#define IN_PCR_CALL 0xb1
#define IN_PCR_RET 0xb2
#define IN_PCR_END_DECK 0xb3
-#define IN_CONTIGUOUS 0x5c
#define IN_OPEN_FILE 0xb4
#define IN_GET_STDIN 0xb5
diff --git a/src/compiler.h b/src/compiler.h
index 178ed5a8..13eb6e7d 100644
--- a/src/compiler.h
+++ b/src/compiler.h
@@ -1011,10 +1011,6 @@ struct Compiler
int contiguousOffset;
int contiguousStretch;
- bool beginContiguous( CodeVect &code, int stretch );
- void endContiguous( CodeVect &code, bool resetContiguous );
- void clearContiguous( CodeVect &code, bool resetContiguous );
-
void declareReVars();
};
diff --git a/src/iter.c b/src/iter.c
index 402b8ae5..866d12b7 100644
--- a/src/iter.c
+++ b/src/iter.c
@@ -289,9 +289,6 @@ void userIterDestroy2( Program *prg, Tree ***psp, UserIter *uiter )
vm_popn( uiter->yieldSize );
vm_popn( sizeof(UserIter) / sizeof(Word) );
- /* Contiguous push. */
- vm_pop_tree();
-
/* The IN_PREP_ARGS stack data. */
vm_popn( argSize );
vm_pop_value();
diff --git a/src/synthesis.cc b/src/synthesis.cc
index ccc88dda..cb2cde87 100644
--- a/src/synthesis.cc
+++ b/src/synthesis.cc
@@ -1036,41 +1036,6 @@ void LangVarRef::popRefQuals( Compiler *pd, CodeVect &code,
}
}
-bool Compiler::beginContiguous( CodeVect &code, int stretch )
-{
- bool resetContiguous = false;
-
- if ( inContiguous )
- contiguousStretch += stretch;
- else {
- /* We add one for the push that always comes with the contiguous
- * statement. */
- contiguousStretch = stretch + 1;
-
- code.append( IN_CONTIGUOUS );
- contiguousOffset = code.length();
- code.appendHalf( 0 );
- inContiguous = true;
- resetContiguous = true;
- }
-
- return resetContiguous;
-}
-
-void Compiler::endContiguous( CodeVect &code, bool resetContiguous )
-{
- if ( resetContiguous ) {
- inContiguous = false;
- code.setHalf( contiguousOffset, contiguousStretch );
- contiguousOffset = 0;
- }
-}
-
-void Compiler::clearContiguous( CodeVect &code, bool resetContiguous )
-{
- if ( resetContiguous )
- code.append( IN_POP );
-}
UniqueType *LangVarRef::evaluateCall( Compiler *pd, CodeVect &code, CallArgVect *args )
{
@@ -1087,12 +1052,6 @@ UniqueType *LangVarRef::evaluateCall( Compiler *pd, CodeVect &code, CallArgVect
code.appendHalf( 0 );
}
- bool resetContiguous = false;
- if ( func != 0 && !func->inHost ) {
- long stretch = func->paramListSize + 5 + func->localFrame->size();
- resetContiguous = pd->beginContiguous( code, stretch );
- }
-
/* Evaluate and push the arguments. */
ObjectField **paramRefs = evaluateArgs( pd, code, lookup, args );
@@ -1104,9 +1063,6 @@ UniqueType *LangVarRef::evaluateCall( Compiler *pd, CodeVect &code, CallArgVect
resetActiveRefs( pd, lookup, paramRefs);
delete[] paramRefs;
- pd->endContiguous( code, resetContiguous );
- pd->clearContiguous( code, resetContiguous );
-
if ( func != 0 && !func->inHost ) {
code.append( IN_CLEAR_ARGS );
code.appendHalf( func->paramListSize );
@@ -2249,13 +2205,6 @@ void LangStmt::compileForIter( Compiler *pd, CodeVect &code ) const
code.appendHalf( 0 );
}
- bool resetContiguous = false;
- if ( func != 0 ) {
- /* FIXME: what is the right size here (16)? */
- long stretch = func->paramListSize + 16 + func->localFrame->size();
- resetContiguous = pd->beginContiguous( code, stretch );
- }
-
/*
* Create the iterator from the local var.
*/
@@ -2297,8 +2246,6 @@ void LangStmt::compileForIter( Compiler *pd, CodeVect &code ) const
ObjectField **paramRefs = iterCall->langTerm->varRef->evaluateArgs(
pd, code, lookup, iterCall->langTerm->args );
- pd->endContiguous( code, resetContiguous );
-
if ( pd->revertOn )
code.append( iterImpl->inCreateWV );
else
@@ -2332,8 +2279,6 @@ void LangStmt::compileForIter( Compiler *pd, CodeVect &code ) const
iterCall->langTerm->varRef->resetActiveRefs( pd, lookup, paramRefs );
delete[] paramRefs;
- pd->clearContiguous( code, resetContiguous );
-
if ( func != 0 ) {
code.append( IN_CLEAR_ARGS );
code.appendHalf( func->paramListSize );
diff --git a/test/load1.lm b/test/load1.lm
index 5ac3a924..71a10177 100644
--- a/test/load1.lm
+++ b/test/load1.lm
@@ -28,7 +28,7 @@ int main( int argc, const char **argv )
colm_set_debug( program, 1 );
colm_run_program( program, argc, argv );
- foo F = f( program, "passthrouh" );
+ foo F = f( program, "passthrough" );
std::cout << F.Str().text() << std::endl;