summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2015-03-28 16:47:27 -0400
committerAdrian Thurston <thurston@complang.org>2015-03-28 16:48:22 -0400
commit9be83dad1c830dc96801a672281578ffe5838668 (patch)
treeadc4fd5d11c343a6ee2a508d8c528e316e12de5f
parentefab3b8fe98850e7c092001e162d977e5f16b94b (diff)
downloadcolm-9be83dad1c830dc96801a672281578ffe5838668.tar.gz
transmit return value to caller via a register
This avoids the awkward top swapping after coming back from a call. This will get worse once we we start plaing call args on the caller's side of the call stack boundary.
-rw-r--r--src/bytecode.c24
-rw-r--r--src/bytecode.h5
-rw-r--r--src/synthesis.cc17
3 files changed, 22 insertions, 24 deletions
diff --git a/src/bytecode.c b/src/bytecode.c
index 1bed2e5b..c2b0cb6c 100644
--- a/src/bytecode.c
+++ b/src/bytecode.c
@@ -1743,15 +1743,6 @@ again:
vm_push_value( val );
break;
}
- case IN_TOP_SWAP: {
- debug( prg, REALM_BYTECODE, "IN_TOP_SWAP\n" );
-
- Tree *v1 = vm_pop_tree();
- Tree *v2 = vm_pop_tree();
- vm_push_tree( v1 );
- vm_push_tree( v2 );
- break;
- }
case IN_DUP_VAL: {
debug( prg, REALM_BYTECODE, "IN_DUP_VAL\n" );
@@ -2277,6 +2268,12 @@ again:
break;
}
+ case IN_LOAD_RETVAL: {
+ debug( prg, REALM_BYTECODE, "IN_LOAD_RETVAL\n" );
+ vm_push_tree( exec->retVal );
+ break;
+ }
+
case IN_PCR_RET: {
debug( prg, REALM_BYTECODE, "IN_PCR_RET\n" );
@@ -3299,8 +3296,8 @@ again:
userIterDestroy( prg, &sp, uiter );
break;
}
- case IN_RET: {
+ case IN_RET: {
FrameInfo *fi = &prg->rtd->frameInfo[exec->frameId];
downref_local_trees( prg, sp, exec->framePtr, fi->locals, fi->localsLen );
vm_popn( fi->frameSize );
@@ -3308,9 +3305,8 @@ again:
exec->frameId = vm_pop_type(long);
exec->framePtr = vm_pop_type(Tree**);
instr = vm_pop_type(Code*);
- Tree *retVal = vm_pop_tree();
+ exec->retVal = vm_pop_tree();
vm_popn( fi->argSize );
- vm_push_tree( retVal );
fi = &prg->rtd->frameInfo[exec->frameId];
debug( prg, REALM_BYTECODE, "IN_RET %s\n", fi->name );
@@ -3991,9 +3987,6 @@ again:
prg->exitStatus = vm_pop_type(long);
prg->induceExit = 1;
- /* The callArgs push for exit. */
- vm_pop_value();
-
while ( true ) {
FrameInfo *fi = &prg->rtd->frameInfo[exec->frameId];
int frameId = exec->frameId;
@@ -4021,7 +4014,6 @@ again:
Tree *retVal = vm_pop_tree();
vm_popn( fi->argSize );
-
/* The CONTIGUOS PUSH. */
vm_pop_tree();
diff --git a/src/bytecode.h b/src/bytecode.h
index c24913bb..8cc4ae25 100644
--- a/src/bytecode.h
+++ b/src/bytecode.h
@@ -78,6 +78,9 @@ typedef unsigned long colm_value_t;
// 0xeb
// 0xec
// 0xd4
+// 0x20
+
+#define IN_LOAD_RETVAL 0xd4
#define IN_PREP_ARGS 0xe8
#define IN_CLEAR_ARGS 0xe9
@@ -107,7 +110,6 @@ typedef unsigned long colm_value_t;
#define IN_POP_VAL 0xbe
#define IN_DUP_VAL 0x1f
#define IN_DUP_TREE 0xf2
-#define IN_TOP_SWAP 0x20
#define IN_REJECT 0x21
#define IN_MATCH 0x22
@@ -590,6 +592,7 @@ typedef struct colm_execution
Parser *parser;
long steps;
long pcr;
+ Tree *retVal;
} Execution;
long stringLength( Head *str );
diff --git a/src/synthesis.cc b/src/synthesis.cc
index 92afd5c8..442ac8c0 100644
--- a/src/synthesis.cc
+++ b/src/synthesis.cc
@@ -1085,10 +1085,8 @@ void Compiler::endContiguous( CodeVect &code, bool resetContiguous )
void Compiler::clearContiguous( CodeVect &code, bool resetContiguous )
{
- if ( resetContiguous ) {
- code.append( IN_TOP_SWAP );
+ if ( resetContiguous )
code.append( IN_POP );
- }
}
UniqueType *LangVarRef::evaluateCall( Compiler *pd, CodeVect &code, CallArgVect *args )
@@ -1096,11 +1094,13 @@ UniqueType *LangVarRef::evaluateCall( Compiler *pd, CodeVect &code, CallArgVect
/* Evaluate the object. */
VarRefLookup lookup = lookupMethod( pd );
+ Function *func = lookup.objMethod->func;
+
/* Prepare the contiguous call args space. */
- code.append( IN_PREP_ARGS );
+ if ( func != 0 )
+ code.append( IN_PREP_ARGS );
bool resetContiguous = false;
- Function *func = lookup.objMethod->func;
if ( func != 0 ) {
long stretch = func->paramListSize + 5 + func->localFrame->size();
resetContiguous = pd->beginContiguous( code, stretch );
@@ -1121,8 +1121,11 @@ UniqueType *LangVarRef::evaluateCall( Compiler *pd, CodeVect &code, CallArgVect
pd->endContiguous( code, resetContiguous );
pd->clearContiguous( code, resetContiguous );
- code.append( IN_TOP_SWAP );
- code.append( IN_CLEAR_ARGS );
+ if ( func != 0 )
+ code.append( IN_CLEAR_ARGS );
+
+ if ( func != 0 )
+ code.append( IN_LOAD_RETVAL );
/* Return the type to the expression. */
return lookup.uniqueType;