diff options
author | Adrian Thurston <thurston@complang.org> | 2014-01-22 22:19:47 -0500 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2014-01-22 22:19:47 -0500 |
commit | 146b354bed2618fbe7d9d807fa85691254b5a68f (patch) | |
tree | b1e057a8ea4dcedcbf07bd97485d7c4d3cbaae88 /src | |
parent | e838d570382dc4e68e62001fab78ba41b801a15f (diff) | |
download | colm-146b354bed2618fbe7d9d807fa85691254b5a68f.tar.gz |
eliminated stack offset from make-token instruction
Diffstat (limited to 'src')
-rw-r--r-- | src/bytecode.c | 14 | ||||
-rw-r--r-- | src/tree.c | 20 | ||||
-rw-r--r-- | src/tree.h | 2 |
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; } @@ -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; @@ -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 ); |