summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2014-01-22 22:19:47 -0500
committerAdrian Thurston <thurston@complang.org>2014-01-22 22:19:47 -0500
commit77fd6f623b41cc879b6721288ddbb7c6285b116a (patch)
treeb1e057a8ea4dcedcbf07bd97485d7c4d3cbaae88
parentb5bbdede0f61db92750934452d58b5da6db4a07d (diff)
downloadcolm-77fd6f623b41cc879b6721288ddbb7c6285b116a.tar.gz
eliminated stack offset from make-token instruction
-rw-r--r--src/bytecode.c14
-rw-r--r--src/tree.c20
-rw-r--r--src/tree.h2
3 files changed, 18 insertions, 18 deletions
diff --git a/src/bytecode.c b/src/bytecode.c
index 434eec02..e35a5373 100644
--- a/src/bytecode.c
+++ b/src/bytecode.c
@@ -2636,16 +2636,18 @@ again:
}
case IN_MAKE_TOKEN: {
uchar nargs;
+ int i;
read_byte( nargs );
debug( prg, REALM_BYTECODE, "IN_MAKE_TOKEN\n" );
- Tree *result = constructToken( prg, sp, nargs );
- long i;
- for ( i = 0; i < nargs; i++ ) {
- Tree *arg = vm_pop();
- treeDownref( prg, sp, arg );
- }
+ Tree *arg[nargs];
+ for ( i = nargs-1; i >= 0; i-- )
+ arg[i] = vm_pop();
+
+ Tree *result = constructToken( prg, arg, nargs );
+ for ( i = 0; i < nargs; i++ )
+ treeDownref( prg, sp, arg[i] );
vm_push( result );
break;
}
diff --git a/src/tree.c b/src/tree.c
index a8c1f393..1abb720e 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -627,13 +627,10 @@ Kid *constructReplacementKid( Tree **bindings, Program *prg, Kid *prev, long pat
return kid;
}
-Tree *constructToken( Program *prg, Tree **root, long nargs )
+Tree *constructToken( Program *prg, Tree **args, long nargs )
{
- Tree **const sp = root;
- Tree **base = vm_ptop() + nargs;
-
- Int *idInt = (Int*)base[-1];
- Str *textStr = (Str*)base[-2];
+ Int *idInt = (Int*)args[0];
+ Str *textStr = (Str*)args[1];
long id = idInt->value;
Head *tokdata = stringCopy( prg, textStr->value );
@@ -649,6 +646,8 @@ Tree *constructToken( Program *prg, Tree **root, long nargs )
}
else {
long objectLength = lelInfo[id].objectLength;
+ assert( nargs-2 <= objectLength );
+
Kid *attrs = allocAttrs( prg, objectLength );
tree = treeAllocate( prg );
@@ -658,11 +657,10 @@ Tree *constructToken( Program *prg, Tree **root, long nargs )
tree->child = attrs;
- assert( nargs-2 <= objectLength );
- long id;
- for ( id = 0; id < nargs-2; id++ ) {
- setAttr( tree, id, base[-3-id] );
- treeUpref( colm_get_attr( tree, id) );
+ long i;
+ for ( i = 2; i < nargs; i++ ) {
+ setAttr( tree, i-2, args[i] );
+ treeUpref( colm_get_attr( tree, i-2 ) );
}
}
return tree;
diff --git a/src/tree.h b/src/tree.h
index 6d76b661..7072326b 100644
--- a/src/tree.h
+++ b/src/tree.h
@@ -263,7 +263,7 @@ Tree *constructPointer( struct colm_program *prg, Tree *tree );
Tree *constructTerm( struct colm_program *prg, Word id, Head *tokdata );
Tree *constructReplacementTree( Kid *kid, Tree **bindings, struct colm_program *prg, long pat );
Tree *createGeneric( struct colm_program *prg, long genericId );
-Tree *constructToken( struct colm_program *prg, Tree **root, long nargs );
+Tree *constructToken( struct colm_program *prg, Tree **args, long nargs );
Tree *constructStream( struct colm_program *prg );