diff options
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | src/bytecode.c | 136 | ||||
-rw-r--r-- | src/bytecode.h | 18 | ||||
-rw-r--r-- | src/declare.cc | 22 | ||||
-rw-r--r-- | src/parsedata.h | 2 | ||||
-rw-r--r-- | src/parsetree.h | 4 | ||||
-rw-r--r-- | src/tree.c | 23 | ||||
-rw-r--r-- | src/tree.h | 4 | ||||
-rw-r--r-- | test/factor5.lm | 1 | ||||
-rw-r--r-- | test/generate2.lm | 38 | ||||
-rw-r--r-- | test/lookup1.lm | 271 |
11 files changed, 324 insertions, 197 deletions
@@ -12,3 +12,5 @@ /config.log /config.status /Makefile +/compile +/test-driver diff --git a/src/bytecode.c b/src/bytecode.c index 4aa5b108..3d783243 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -414,7 +414,7 @@ Tree *constructArgv( Program *prg, int argc, const char **argv ) Head *head = stringAllocPointer( prg, argv[i], strlen(argv[i]) ); Tree *arg = constructString( prg, head ); treeUpref( arg ); - listAppend2( prg, (List*)list, arg ); + listPushTail( prg, (List*)list, arg ); } return list; } @@ -606,15 +606,28 @@ again: stringFree( prg, head ); break; } - case IN_LIST_APPEND_BKT: { - debug( prg, REALM_BYTECODE, "IN_LIST_APPEND_BKT\n" ); + case IN_LIST_PUSH_HEAD_BKT: { + debug( prg, REALM_BYTECODE, "IN_LIST_PUSH_HEAD_BKT\n" ); break; } - case IN_LIST_REMOVE_END_BKT: { + case IN_LIST_POP_HEAD_BKT: { Tree *val; read_tree( val ); - debug( prg, REALM_BYTECODE, "IN_LIST_REMOVE_END_BKT\n" ); + debug( prg, REALM_BYTECODE, "IN_LIST_POP_HEAD_BKT\n" ); + + treeDownref( prg, sp, val ); + break; + } + case IN_LIST_PUSH_TAIL_BKT: { + debug( prg, REALM_BYTECODE, "IN_LIST_PUSH_TAIL_BKT\n" ); + break; + } + case IN_LIST_POP_TAIL_BKT: { + Tree *val; + read_tree( val ); + + debug( prg, REALM_BYTECODE, "IN_LIST_POP_TAIL_BKT\n" ); treeDownref( prg, sp, val ); break; @@ -2938,38 +2951,38 @@ again: vm_push( res ); break; } - case IN_LIST_APPEND_WV: { - debug( prg, REALM_BYTECODE, "IN_LIST_APPEND_WV\n" ); + case IN_LIST_PUSH_TAIL_WV: { + debug( prg, REALM_BYTECODE, "IN_LIST_PUSH_TAIL_WV\n" ); Tree *obj = vm_pop(); Tree *val = vm_pop(); treeDownref( prg, sp, obj ); - listAppend2( prg, (List*)obj, val ); + listPushTail( prg, (List*)obj, val ); treeUpref( prg->trueVal ); vm_push( prg->trueVal ); /* Set up reverse code. Needs no args. */ - rcodeCode( exec, IN_LIST_APPEND_BKT ); + rcodeCode( exec, IN_LIST_PUSH_TAIL_BKT ); rcodeUnitTerm( exec ); break; } - case IN_LIST_APPEND_WC: { - debug( prg, REALM_BYTECODE, "IN_LIST_APPEND_WC\n" ); + case IN_LIST_PUSH_TAIL_WC: { + debug( prg, REALM_BYTECODE, "IN_LIST_PUSH_TAIL_WC\n" ); Tree *obj = vm_pop(); Tree *val = vm_pop(); treeDownref( prg, sp, obj ); - listAppend2( prg, (List*)obj, val ); + listPushTail( prg, (List*)obj, val ); treeUpref( prg->trueVal ); vm_push( prg->trueVal ); break; } - case IN_LIST_APPEND_BKT: { - debug( prg, REALM_BYTECODE, "IN_LIST_APPEND_BKT\n" ); + case IN_LIST_PUSH_TAIL_BKT: { + debug( prg, REALM_BYTECODE, "IN_LIST_PUSH_TAIL_BKT\n" ); Tree *obj = vm_pop(); treeDownref( prg, sp, obj ); @@ -2978,8 +2991,8 @@ again: treeDownref( prg, sp, tree ); break; } - case IN_LIST_REMOVE_END_WC: { - debug( prg, REALM_BYTECODE, "IN_LIST_REMOVE_END_WC\n" ); + case IN_LIST_POP_TAIL_WC: { + debug( prg, REALM_BYTECODE, "IN_LIST_POP_TAIL_WC\n" ); Tree *obj = vm_pop(); treeDownref( prg, sp, obj ); @@ -2988,8 +3001,8 @@ again: vm_push( end ); break; } - case IN_LIST_REMOVE_END_WV: { - debug( prg, REALM_BYTECODE, "IN_LIST_REMOVE_END_WV\n" ); + case IN_LIST_POP_TAIL_WV: { + debug( prg, REALM_BYTECODE, "IN_LIST_POP_TAIL_WV\n" ); Tree *obj = vm_pop(); treeDownref( prg, sp, obj ); @@ -3000,13 +3013,92 @@ again: /* Set up reverse. The result comes off the list downrefed. * Need it up referenced for the reverse code too. */ treeUpref( end ); - rcodeCode( exec, IN_LIST_REMOVE_END_BKT ); + rcodeCode( exec, IN_LIST_POP_TAIL_BKT ); + rcodeWord( exec, (Word)end ); + rcodeUnitTerm( exec ); + break; + } + case IN_LIST_POP_TAIL_BKT: { + debug( prg, REALM_BYTECODE, "IN_LIST_POP_TAIL_BKT\n" ); + + Tree *val; + read_tree( val ); + + Tree *obj = vm_pop(); + treeDownref( prg, sp, obj ); + + listPushTail( prg, (List*)obj, val ); + break; + } + case IN_LIST_PUSH_HEAD_WV: { + debug( prg, REALM_BYTECODE, "IN_LIST_PUSH_HEAD_WV\n" ); + + Tree *obj = vm_pop(); + Tree *val = vm_pop(); + + treeDownref( prg, sp, obj ); + + listPushHead( prg, (List*)obj, val ); + treeUpref( prg->trueVal ); + vm_push( prg->trueVal ); + + /* Set up reverse code. Needs no args. */ + rcodeCode( exec, IN_LIST_PUSH_HEAD_BKT ); + rcodeUnitTerm( exec ); + break; + } + case IN_LIST_PUSH_HEAD_WC: { + debug( prg, REALM_BYTECODE, "IN_LIST_PUSH_HEAD_WC\n" ); + + Tree *obj = vm_pop(); + Tree *val = vm_pop(); + + treeDownref( prg, sp, obj ); + + listPushHead( prg, (List*)obj, val ); + treeUpref( prg->trueVal ); + vm_push( prg->trueVal ); + break; + } + case IN_LIST_PUSH_HEAD_BKT: { + debug( prg, REALM_BYTECODE, "IN_LIST_PUSH_HEAD_BKT\n" ); + + Tree *obj = vm_pop(); + treeDownref( prg, sp, obj ); + + Tree *tree = listRemoveHead( prg, (List*)obj ); + treeDownref( prg, sp, tree ); + break; + } + case IN_LIST_POP_HEAD_WC: { + debug( prg, REALM_BYTECODE, "IN_LIST_POP_HEAD_WC\n" ); + + Tree *obj = vm_pop(); + treeDownref( prg, sp, obj ); + + Tree *end = listRemoveHead( prg, (List*)obj ); + vm_push( end ); + break; + } + case IN_LIST_POP_HEAD_WV: { + debug( prg, REALM_BYTECODE, "IN_LIST_POP_HEAD_WV\n" ); + + Tree *obj = vm_pop(); + treeDownref( prg, sp, obj ); + + Tree *end = listRemoveHead( prg, (List*)obj ); + vm_push( end ); + + /* Set up reverse. The result comes off the list downrefed. + * Need it up referenced for the reverse code too. */ + treeUpref( end ); + rcodeCode( exec, IN_LIST_POP_HEAD_BKT ); rcodeWord( exec, (Word)end ); rcodeUnitTerm( exec ); break; } - case IN_LIST_REMOVE_END_BKT: { - debug( prg, REALM_BYTECODE, "IN_LIST_REMOVE_END_BKT\n" ); + case IN_LIST_POP_HEAD_BKT: { + debug( prg, REALM_BYTECODE, "IN_LIST_POP_HEAD_BKT\n" ); Tree *val; read_tree( val ); @@ -3014,7 +3106,7 @@ again: Tree *obj = vm_pop(); treeDownref( prg, sp, obj ); - listAppend2( prg, (List*)obj, val ); + listPushHead( prg, (List*)obj, val ); break; } case IN_GET_LIST_MEM_R: { diff --git a/src/bytecode.h b/src/bytecode.h index bfc7eb4f..78654c9e 100644 --- a/src/bytecode.h +++ b/src/bytecode.h @@ -172,12 +172,18 @@ typedef unsigned char uchar; #define IN_MAP_REMOVE_BKT 0x71 #define IN_LIST_LENGTH 0x72 -#define IN_LIST_APPEND_WV 0x73 -#define IN_LIST_APPEND_WC 0x74 -#define IN_LIST_APPEND_BKT 0x75 -#define IN_LIST_REMOVE_END_WV 0x76 -#define IN_LIST_REMOVE_END_WC 0x77 -#define IN_LIST_REMOVE_END_BKT 0x78 +#define IN_LIST_PUSH_TAIL_WV 0x73 +#define IN_LIST_PUSH_TAIL_WC 0x74 +#define IN_LIST_PUSH_TAIL_BKT 0x75 +#define IN_LIST_POP_TAIL_WV 0x76 +#define IN_LIST_POP_TAIL_WC 0x77 +#define IN_LIST_POP_TAIL_BKT 0x78 +#define IN_LIST_PUSH_HEAD_WV 0xe7 +#define IN_LIST_PUSH_HEAD_WC 0xe8 +#define IN_LIST_PUSH_HEAD_BKT 0xe9 +#define IN_LIST_POP_HEAD_WV 0xea +#define IN_LIST_POP_HEAD_WC 0xeb +#define IN_LIST_POP_HEAD_BKT 0xec #define IN_GET_LIST_MEM_R 0x79 #define IN_GET_LIST_MEM_WC 0x7a diff --git a/src/declare.cc b/src/declare.cc index d18ce5db..34fd0280 100644 --- a/src/declare.cc +++ b/src/declare.cc @@ -1072,15 +1072,23 @@ void Compiler::initListFunctions( GenericType *gen ) { addLengthField( gen->objDef, IN_LIST_LENGTH ); - initFunction( uniqueTypeInt, gen->objDef, "append", - IN_LIST_APPEND_WV, IN_LIST_APPEND_WC, gen->utArg, false ); + initFunction( uniqueTypeInt, gen->objDef, "push_head", + IN_LIST_PUSH_HEAD_WV, IN_LIST_PUSH_HEAD_WC, gen->utArg, false ); + + initFunction( uniqueTypeInt, gen->objDef, "push_tail", + IN_LIST_PUSH_TAIL_WV, IN_LIST_PUSH_TAIL_WC, gen->utArg, false ); + initFunction( uniqueTypeInt, gen->objDef, "push", - IN_LIST_APPEND_WV, IN_LIST_APPEND_WC, gen->utArg, false ); + IN_LIST_PUSH_HEAD_WV, IN_LIST_PUSH_HEAD_WC, gen->utArg, false ); + + initFunction( gen->utArg, gen->objDef, "pop_head", + IN_LIST_POP_HEAD_WV, IN_LIST_POP_HEAD_WC, false ); + + initFunction( gen->utArg, gen->objDef, "pop_tail", + IN_LIST_POP_TAIL_WV, IN_LIST_POP_TAIL_WC, false ); - initFunction( gen->utArg, gen->objDef, "remove_end", - IN_LIST_REMOVE_END_WV, IN_LIST_REMOVE_END_WC, false ); initFunction( gen->utArg, gen->objDef, "pop", - IN_LIST_REMOVE_END_WV, IN_LIST_REMOVE_END_WC, false ); + IN_LIST_POP_HEAD_WV, IN_LIST_POP_HEAD_WC, false ); } void Compiler::initListField( GenericType *gen, const char *name, int offset ) @@ -1109,7 +1117,7 @@ void Compiler::initListFields( GenericType *gen ) { initListField( gen, "head", 0 ); initListField( gen, "tail", 1 ); - initListField( gen, "top", 1 ); + initListField( gen, "top", 0 ); } void Compiler::initVectorFunctions( GenericType *gen ) diff --git a/src/parsedata.h b/src/parsedata.h index cbbe5b9b..9077757c 100644 --- a/src/parsedata.h +++ b/src/parsedata.h @@ -131,7 +131,7 @@ struct Production { Production() : - loc(loc), prodName(0), prodElList(0), prodCommit(false), redBlock(0), + prodName(0), prodElList(0), prodCommit(false), redBlock(0), prodId(0), prodNum(0), fsm(0), fsmLength(0), uniqueEmptyLeader(0), isLeftRec(false), localFrame(0), lhsField(0), predOf(0) {} diff --git a/src/parsetree.h b/src/parsetree.h index f03ab3f0..ee47f372 100644 --- a/src/parsetree.h +++ b/src/parsetree.h @@ -1042,7 +1042,7 @@ struct LexFactorRep factorRep(0), factorNeg(0), lowerRep(0), - upperRep(upperRep), + upperRep(0), type((Type)-1) { } @@ -1816,7 +1816,7 @@ struct UniqueType : public AvlTreeEl<UniqueType> UniqueType( int typeId, IterDef *iterDef ) : typeId(typeId), - langEl(langEl), + langEl(0), iterDef(iterDef) {} int typeId; @@ -37,8 +37,8 @@ #define BUFFER_INITIAL_SIZE 4096 -void listPrepend( List *list, ListEl *new_el) { listAddBefore(list, list->head, new_el); } -void listAppend( List *list, ListEl *new_el) { listAddAfter(list, list->tail, new_el); } +void listPrepend( List *list, ListEl *newEl ) { listAddBefore(list, list->head, newEl ); } +void listAppend( List *list, ListEl *newEl ) { listAddAfter(list, list->tail, newEl ); } ListEl *listDetach( List *list, ListEl *el ); ListEl *listDetachFirst(List *list ) { return listDetach(list, list->head); } @@ -1563,7 +1563,7 @@ long mapLength( Map *map ) return map->treeSize; } -void listAppend2( Program *prg, List *list, Tree *val ) +void listPushTail( Program *prg, List *list, Tree *val ) { assert( list->refs == 1 ); if ( val != 0 ) @@ -1573,6 +1573,16 @@ void listAppend2( Program *prg, List *list, Tree *val ) listAppend( list, listEl ); } +void listPushHead( Program *prg, List *list, Tree *val ) +{ + assert( list->refs == 1 ); + if ( val != 0 ) + assert( val->refs >= 1 ); + ListEl *listEl = listElAllocate( prg ); + listEl->value = val; + listPrepend( list, listEl ); +} + Tree *listRemoveEnd( Program *prg, List *list ) { Tree *tree = list->tail->value; @@ -1580,6 +1590,13 @@ Tree *listRemoveEnd( Program *prg, List *list ) return tree; } +Tree *listRemoveHead( Program *prg, List *list ) +{ + Tree *tree = list->head->value; + listElFree( prg, listDetachFirst( list ) ); + return tree; +} + Tree *getListMem( List *list, Word field ) { Tree *result = 0; @@ -299,8 +299,10 @@ Tree *copyRealTree( struct colm_program *prg, Tree *tree, Kid *oldNextDown, Kid void splitIterCur( struct colm_program *prg, Tree ***psp, TreeIter *iter ); Tree *setListMem( List *list, Half field, Tree *value ); -void listAppend2( struct colm_program *prg, List *list, Tree *val ); +void listPushTail( struct colm_program *prg, List *list, Tree *val ); +void listPushHead( struct colm_program *prg, List *list, Tree *val ); Tree *listRemoveEnd( struct colm_program *prg, List *list ); +Tree *listRemoveHead( struct colm_program *prg, List *list ); Tree *getListMem( List *list, Word field ); Tree *getListMemSplit( struct colm_program *prg, List *list, Word field ); Tree *getParserMem( Parser *parser, Word field ); diff --git a/test/factor5.lm b/test/factor5.lm index e2be8c0c..bc2d8115 100644 --- a/test/factor5.lm +++ b/test/factor5.lm @@ -1,4 +1,5 @@ ##### LM ##### +argv.pop() print( argv.pop() '\n' ) ##### ARGS ##### a diff --git a/test/generate2.lm b/test/generate2.lm index 946c4787..9d2319cf 100644 --- a/test/generate2.lm +++ b/test/generate2.lm @@ -30,14 +30,14 @@ context generate token tmp1 /'}'+/ { - if OpenStack.length > 0 && OpenStack.tail.type == '{' { + if OpenStack.length > 0 && OpenStack.top.type == '{' { length: int = 3 if ( length > match_length ) length = match_length - Tail: open_item = OpenStack.pop() - if ( length > Tail.num ) - length = Tail.num + Top: open_item = OpenStack.pop() + if ( length > Top.num ) + length = Top.num if ( length == 1 ) input.push( make_token( typeid<ccurly1> input.pull( 1 ) ) ) @@ -46,10 +46,10 @@ context generate else if ( length == 3 ) input.push( make_token( typeid<ccurly3> input.pull( 3 ) ) ) - Tail.num = Tail.num - length + Top.num = Top.num - length - if ( Tail.num > 0 ) - OpenStack.push( Tail ) + if ( Top.num > 0 ) + OpenStack.push( Top ) } else { input.push( make_token( typeid<stray_close> input.pull( match_length ) ) ) @@ -74,24 +74,24 @@ context generate token tmp2 /']'+/ { - if OpenStack.length > 0 && OpenStack.tail.type == '[' { + if OpenStack.length > 0 && OpenStack.top.type == '[' { length: int = 2 if ( length > match_length ) length = match_length - Tail: open_item = OpenStack.pop() - if ( length > Tail.num ) - length = Tail.num + Top: open_item = OpenStack.pop() + if ( length > Top.num ) + length = Top.num if ( length == 1 ) input.push( make_token( typeid<csquare1> input.pull( 1 ) ) ) else if ( length == 2 ) input.push( make_token( typeid<csquare2> input.pull( 2 ) ) ) - Tail.num = Tail.num - length + Top.num = Top.num - length - if ( Tail.num > 0 ) - OpenStack.push( Tail ) + if ( Top.num > 0 ) + OpenStack.push( Top ) } else { input.push( make_token( typeid<stray_close> input.pull( match_length ) ) ) @@ -103,18 +103,18 @@ context generate preeof { while ( OpenStack.length > 0 ) { - Tail: open_item = OpenStack.pop() + Top: open_item = OpenStack.pop() i: int - if ( Tail.type == '{' ) { + if ( Top.type == '{' ) { i = 0 - while ( i < Tail.num ) { + while ( i < Top.num ) { input.push( make_token( typeid<missing_curly> '}' ) ) i = i + 1 } } - else if ( Tail.type == '[' ) { + else if ( Top.type == '[' ) { i = 0 - while ( i < Tail.num ) { + while ( i < Top.num ) { input.push( make_token( typeid<missing_square> ']' ) ) i = i + 1 } diff --git a/test/lookup1.lm b/test/lookup1.lm index 7eaf58f7..0f80098a 100644 --- a/test/lookup1.lm +++ b/test/lookup1.lm @@ -125,7 +125,7 @@ context lookup if !found { # Iterator over the objects starting at the head of the lookup stack # and going up through the lookup parents. - lookupIn: ptr<lang_object> = lookupNs.top + lookupIn: ptr<lang_object> = lookupNs.tail while lookupIn { found = lookupWithInheritance( lookupIn name ) if found @@ -188,12 +188,12 @@ context lookup name: str = match_text found: ptr<lang_object> = nil qualObj: ptr<lang_object> = nil - if qualNs.top { + if qualNs.tail { # LOG print( 'qualified lookup of ', name, '\n' ) # Transfer the qualification to the token and reset it. - qualObj = qualNs.top - qualNs.top = nil + qualObj = qualNs.tail + qualNs.tail = nil # Lookup using the qualification. found = lookupWithInheritance( qualObj name ) @@ -212,7 +212,6 @@ context lookup LookupId: any = make_token( typeid<lookup_id> input.pull(match_length) found qualObj ) input.push( make_tree( id LookupId ) ) - } # Floats. @@ -272,7 +271,7 @@ context lookup # Element not in the map already ol = construct list<ptr<lang_object>> [] } - ol.append( obj ) + ol.push_tail( obj ) definedIn->objectMap.store( name ol ) } @@ -320,33 +319,33 @@ context lookup def qualifying_name [class_name] { - qualNs.top = r1.lookupId.obj + qualNs.tail = r1.lookupId.obj } | [namespace_id] { match r1 [Id: lookup_id] - qualNs.top = Id.obj + qualNs.tail = Id.obj } | [typedef_id] { match r1 [Id: lookup_id] - qualNs.top = Id.obj->typedefOf + qualNs.tail = Id.obj->typedefOf } def designated_qualifying_name [`template any_id] { # FIXME: nulling qualNs is not the right thing to do here. - qualNs.top = nil + qualNs.tail = nil } | [`template any_id templ_arg_open template_argument_list_opt templ_arg_close] { # FIXME: nulling qualNs is not the right thing to do here. - qualNs.top = nil + qualNs.tail = nil } # @@ -370,8 +369,8 @@ context lookup { # Normally the token translation transfers the qualification. Since # the operator_function_id does not end in a lookup we must do it ourselves. - qualObj: ptr<lang_object> = qualNs.top - qualNs.top = nil + qualObj: ptr<lang_object> = qualNs.tail + qualNs.tail = nil lhs.lookupId = construct lookup_id ["x"] lhs.lookupId.data = '<operator_function_id>' @@ -382,8 +381,8 @@ context lookup { # Normally the token translation transfers the qualification. Since # the operator_function_id does not } in a lookup we must do it ourselves. - qualObj: ptr<lang_object> = qualNs.top - qualNs.top = nil + qualObj: ptr<lang_object> = qualNs.tail + qualNs.tail = nil # Do we need qual reset here becauase operator_function_id does not do it? lhs.lookupId = construct lookup_id ["x"] @@ -441,13 +440,13 @@ context lookup def templ_arg_open [`<] { - qualNs.push( nil ) + qualNs.push_tail( nil ) } def templ_arg_close [`>] { - qualNs.pop() + qualNs.pop_tail() } def declaration @@ -482,20 +481,20 @@ context lookup def declaration_start [] { - # LOG print( 'opening new declaration_data with templDecl: ', templDecl.top, '\n' ) - declarationData.push( construct declaration_data ( 0 0 0 ) [] ) + # LOG print( 'opening new declaration_data with templDecl: ', templDecl.tail, '\n' ) + declarationData.push_tail( construct declaration_data ( 0 0 0 ) [] ) # Transfer the template flag and reset it. - declarationData.top.isTemplate = templDecl.top - templDecl.push( 0 ) + declarationData.tail.isTemplate = templDecl.tail + templDecl.push_tail( 0 ) } def declaration_end [] { # LOG print( 'closing declaration_data\n' ) - declarationData.pop() - templDecl.pop() + declarationData.pop_tail() + templDecl.pop_tail() } def decl_specifier_sing @@ -503,7 +502,7 @@ context lookup { # Store the object type of the declaration (if any) for use # by typedefs. - declarationData.top.typeObj = r1.lookupId.obj + declarationData.tail.typeObj = r1.lookupId.obj } def type_specifier_seq @@ -653,7 +652,7 @@ context lookup name: str = Id.data # Get the ns the class is declared in. - parentObj: ptr<lang_object> = declNs.top + parentObj: ptr<lang_object> = declNs.tail if Id.qualObj parentObj = Id.qualObj @@ -668,12 +667,12 @@ context lookup # Class does not exist in the parent scope, create it. nsType: int = declaredClassType() - declaredClass = createLangObject( nsType name lookupNs.top ) + declaredClass = createLangObject( nsType name lookupNs.tail ) # FIXME: handle friends. Make the class visible only if we are NOT # in a friend declaration. The new class object is necessary to # properly process the body of the class. - if declarationData.top.isFriend == 0 + if declarationData.tail.isFriend == 0 insertObject( parentObj name declaredClass ) } } @@ -687,8 +686,8 @@ context lookup # TODO: should look for existing enums of the same name. Id: lookup_id = lookup_id in r3 # LOG print( 'creating enumeration ' Id.data '\n' ) - enum: ptr<lang_object> = createLangObject( EnumType Id.data lookupNs.top ) - insertObject( declNs.top Id.data enum ) + enum: ptr<lang_object> = createLangObject( EnumType Id.data lookupNs.tail ) + insertObject( declNs.tail Id.data enum ) } def decl_specifier_mult_seq_opt @@ -706,12 +705,12 @@ context lookup | [`friend] { - declarationData.top.isFriend = 1 + declarationData.tail.isFriend = 1 } | [`typedef] { - declarationData.top.isTypedef = 1 + declarationData.tail.isTypedef = 1 } def storage_class_specifier @@ -757,8 +756,8 @@ context lookup # TODO: should look for existing enums of the same name. Id: lookup_id = lookup_id in r3 # LOG print( 'creating enumeration ' Id.data '\n' ) - enum: ptr<lang_object> = createLangObject( EnumType Id.data lookupNs.top ) - insertObject( declNs.top Id.data enum ) + enum: ptr<lang_object> = createLangObject( EnumType Id.data lookupNs.tail ) + insertObject( declNs.tail Id.data enum ) } | [`enum `{ enumerator_list_opt `}] @@ -786,15 +785,15 @@ context lookup [enumerator_id] { Id: lookup_id = lookup_id in r1 - enumId: ptr<lang_object> = createLangObject( IdType Id.data lookupNs.top ) - insertObject( declNs.top Id.data enumId ) + enumId: ptr<lang_object> = createLangObject( IdType Id.data lookupNs.tail ) + insertObject( declNs.tail Id.data enumId ) } | [enumerator_id `= constant_expression] { Id: lookup_id = lookup_id in r1 - enumId: ptr<lang_object> = createLangObject( IdType Id.data lookupNs.top ) - insertObject( declNs.top Id.data enumId ) + enumId: ptr<lang_object> = createLangObject( IdType Id.data lookupNs.tail ) + insertObject( declNs.tail Id.data enumId ) } def enumerator_id @@ -1091,17 +1090,17 @@ context lookup def compound_begin [] { - newCompound: ptr<lang_object> = createLangObject( 0 '<compound_begin>' lookupNs.top ) - lookupNs.push( newCompound ) - declNs.push( newCompound ) + newCompound: ptr<lang_object> = createLangObject( 0 '<compound_begin>' lookupNs.tail ) + lookupNs.push_tail( newCompound ) + declNs.push_tail( newCompound ) # LOG print( 'opening <compound>\n' ) } def compound_end [] { - lookupNs.pop() - declNs.pop() + lookupNs.pop_tail() + declNs.pop_tail() # LOG print( 'closing <compound>\n' ) } @@ -1205,7 +1204,7 @@ context lookup name: str = r1.lookupId.data qualObj: ptr<lang_object> = r1.lookupId.qualObj - parentObj: ptr<lang_object> = declNs.top + parentObj: ptr<lang_object> = declNs.tail if qualObj { parentObj = qualObj } @@ -1225,29 +1224,29 @@ context lookup } obj: ptr<lang_object> = nil - if name && !isConstructor && declarationData.top.isFriend == 0 { - if declarationData.top.isTypedef { - obj = createLangObject( TypedefType name lookupNs.top ) - obj->typedefOf = declarationData.top.typeObj + if name && !isConstructor && declarationData.tail.isFriend == 0 { + if declarationData.tail.isTypedef { + obj = createLangObject( TypedefType name lookupNs.tail ) + obj->typedefOf = declarationData.tail.typeObj insertObject( parentObj name obj ) # LOG print( 'making declarator ' name ' a typedef\n' ) } else { if !qualObj { - if declarationData.top.isTemplate { + if declarationData.tail.isTemplate { # If in a template declaration and the name is not qualified then # create the template id. - obj = createLangObject( TemplateIdType name lookupNs.top ) - #object->objType = declarationData.top.type - insertObject( declNs.top name obj ) + obj = createLangObject( TemplateIdType name lookupNs.tail ) + #object->objType = declarationData.tail.type + insertObject( declNs.tail name obj ) # LOG print( 'making declarator ' name ' a template id\n' ) } else { - obj = createLangObject( IdType name lookupNs.top ) - #object->objType = declarationData.top().type; - insertObject( declNs.top name obj ) + obj = createLangObject( IdType name lookupNs.tail ) + #object->objType = declarationData.tail().type; + insertObject( declNs.tail name obj ) # LOG print( 'making declarator ' name ' an id\n' ) } @@ -1255,15 +1254,15 @@ context lookup } } - declaratorData.push( construct declarator_data ( - qualObj nil lookupNs.top ) [] ) + declaratorData.push_tail( construct declarator_data ( + qualObj nil lookupNs.tail ) [] ) # If the declarator is qualified, push the qualification to the lookup # stack. Also save it in the declarator data so it can be passed to a # function body if needed. if qualObj { - lookupNs.push( qualObj ) - declaratorData.top.lookupObj = qualObj + lookupNs.push_tail( qualObj ) + declaratorData.tail.lookupObj = qualObj } # LOG print( 'reduced declarator_id: ' name '\n' ) @@ -1277,22 +1276,22 @@ context lookup { # Get the lookupObject from the scope and pass it up. If we are about to # parse a function body it will be needed. - lhs.lookupObj = declaratorData.top.lookupObj + lhs.lookupObj = declaratorData.tail.lookupObj - pdcScope: ptr<lang_object> = declaratorData.top.pdcScope - qualObj: ptr<lang_object> = declaratorData.top.qualObj + pdcScope: ptr<lang_object> = declaratorData.tail.pdcScope + qualObj: ptr<lang_object> = declaratorData.tail.qualObj - declaratorData.pop() + declaratorData.pop_tail() if pdcScope { # LOG print( 'closing <pdc_scope>\n' ) - lookupNs.pop() - declNs.pop() + lookupNs.pop_tail() + declNs.pop_tail() } if qualObj { # LOG print( 'popping lookupNs\n' ) - lookupNs.pop() + lookupNs.pop_tail() } } @@ -1354,7 +1353,7 @@ context lookup [] { # Make scope for declarator. - declaratorData.push( construct declarator_data [] ) + declaratorData.push_tail( construct declarator_data [] ) } def abstract_decl_array_or_param_seq_opt @@ -1380,14 +1379,14 @@ context lookup def pdc_start [] { - if !declaratorData.top.pdcScope { + if !declaratorData.tail.pdcScope { # We are going to need a scope for the declarator. - pdcScope: ptr<lang_object> = createLangObject( 0 '<pdc_scope>' lookupNs.top ) - lookupNs.push( pdcScope ) - declNs.push( pdcScope ) + pdcScope: ptr<lang_object> = createLangObject( 0 '<pdc_scope>' lookupNs.tail ) + lookupNs.push_tail( pdcScope ) + declNs.push_tail( pdcScope ) - declaratorData.top.pdcScope = pdcScope - declaratorData.top.lookupObj = pdcScope + declaratorData.tail.pdcScope = pdcScope + declaratorData.tail.lookupObj = pdcScope # LOG print( 'opening <pdc_scope>\n' ) } } @@ -1450,14 +1449,14 @@ context lookup # The lookupObj from the declarator is the deepest lookup object found # while parsing the declarator. Make it visible in the function body. # This could be the args, the qualObj, or the parent to the function. - lookupNs.push( r1.lookupObj ) + lookupNs.push_tail( r1.lookupObj ) } def function_def_end [] { # Pop the lookup object. - lookupNs.pop() + lookupNs.pop_tail() } def function_body @@ -1467,10 +1466,10 @@ context lookup [] { newFunctionBody: ptr<lang_object> = createLangObject( 0 - '<function_body_begin>' lookupNs.top ) - lookupNs.push( newFunctionBody ) - declNs.push( newFunctionBody ) - templDecl.push( 0 ) + '<function_body_begin>' lookupNs.tail ) + lookupNs.push_tail( newFunctionBody ) + declNs.push_tail( newFunctionBody ) + templDecl.push_tail( 0 ) # LOG print( 'opening <function_body>\n' ) } @@ -1479,9 +1478,9 @@ context lookup { # First undoes the function body begin work. Then undoes the setup in # function_def_declarator. - declNs.pop() - lookupNs.pop() - templDecl.pop() + declNs.pop_tail() + lookupNs.pop_tail() + templDecl.pop_tail() # LOG print( 'closing <function_body>\n' ) } @@ -1493,7 +1492,7 @@ context lookup int declaredClassType() { - if declarationData.top.isTemplate { + if declarationData.tail.isTemplate { return TemplateClassType } else { return ClassType @@ -1524,9 +1523,9 @@ context lookup # LOG print( 'creating new anonymous class\n' ) newClass: ptr<lang_object> = createLangObject( nsType - '<anon_class>' lookupNs.top ) - lookupNs.push( newClass ) - declNs.push( newClass ) + '<anon_class>' lookupNs.tail ) + lookupNs.push_tail( newClass ) + declNs.push_tail( newClass ) } | [class_key nested_name_specifier_opt class_head_name] @@ -1535,7 +1534,7 @@ context lookup name: str = Id.data # Get the ns the class is declared in. - parentObj: ptr<lang_object> = declNs.top + parentObj: ptr<lang_object> = declNs.tail if Id.qualObj parentObj = Id.qualObj @@ -1550,18 +1549,18 @@ context lookup # Class does not exist in the parent scope, create it. nsType: int = declaredClassType() - declaredClass = createLangObject( nsType name lookupNs.top ) + declaredClass = createLangObject( nsType name lookupNs.tail ) # FIXME: handle friends. Make the class visible only if we are NOT # in a friend declaration. The new class object is necessary to # properly process the body of the class. - if declarationData.top.isFriend == 0 + if declarationData.tail.isFriend == 0 insertObject( parentObj name declaredClass ) } # Push the found/new class. - lookupNs.push( declaredClass ) - declNs.push( declaredClass ) + lookupNs.push_tail( declaredClass ) + declNs.push_tail( declaredClass ) } | [class_key nested_name_specifier_opt templ_class_id @@ -1580,23 +1579,23 @@ context lookup if !declaredClass { # LOG print( 'making new template specialization\n' ) nsType: int = declaredClassType() - declaredClass = createLangObject( nsType id lookupNs.top ) + declaredClass = createLangObject( nsType id lookupNs.tail ) # LOG print( 'declaredClass: ' declaredClass '\n' ) declaredClass->specializationOf = classObj # $$->typeListMapEl = classObj->typeListMap.insert( typeList declaredClass ); } # Push the found/new class. - lookupNs.push( declaredClass ) - declNs.push( declaredClass ) + lookupNs.push_tail( declaredClass ) + declNs.push_tail( declaredClass ) } def class_body_end [] { # Pop the class ns. - lookupNs.pop() - declNs.pop() + lookupNs.pop_tail() + declNs.pop_tail() # LOG print( 'closing off class\n' ) } @@ -1695,14 +1694,14 @@ context lookup { obj: ptr<lang_object> = r2.lookupId.obj if obj - insertObject( declNs.top obj->name obj ) + insertObject( declNs.tail obj->name obj ) } | [`using type_id `;] { obj: ptr<lang_object> = r2.lookupId.obj if obj - insertObject( declNs.top obj->name obj ) + insertObject( declNs.tail obj->name obj ) } def using_directive @@ -1714,9 +1713,9 @@ context lookup # for longer cycles as well. Note that even gcc 3.3.5 does not bother. match r5 [Id: lookup_id] usingObject: ptr<lang_object> = Id.obj - inObject: ptr<lang_object> = declNs.top + inObject: ptr<lang_object> = declNs.tail if usingObject != inObject - inObject->inherited.append( usingObject ) + inObject->inherited.push_tail( usingObject ) } @@ -1741,23 +1740,23 @@ context lookup if inheritedObject->typeId == TypedefType inheritedObject = inheritedObject->typedefOf - inObject->inherited.append( inheritedObject ) + inObject->inherited.push_tail( inheritedObject ) } def base_specifier [root_qual_opt nested_name_specifier_opt type_name] { - addBaseSpecifier( declNs.top r3.lookupId.obj ) + addBaseSpecifier( declNs.tail r3.lookupId.obj ) } | [`virtual access_specifier_opt root_qual_opt nested_name_specifier_opt type_name] { - addBaseSpecifier( declNs.top r5.lookupId.obj ) + addBaseSpecifier( declNs.tail r5.lookupId.obj ) } | [access_specifier virtual_opt root_qual_opt nested_name_specifier_opt type_name] { - addBaseSpecifier( declNs.top r5.lookupId.obj ) + addBaseSpecifier( declNs.tail r5.lookupId.obj ) } def virtual_opt @@ -1859,19 +1858,19 @@ context lookup def template_declaration [template_declaration_params declaration] { - templDecl.pop() - templateParamNs.pop() + templDecl.pop_tail() + templateParamNs.pop_tail() } def template_declaration_params [`template `< tpl_start template_parameter_list `>] { - templDecl.push( 1 ) + templDecl.push_tail( 1 ) } | [`export `template `< tpl_start template_parameter_list `>] { - templDecl.push( 1 ) + templDecl.push_tail( 1 ) } def tpl_start @@ -1879,8 +1878,8 @@ context lookup { # Create a new scope for the template parameters. newTemplateParamScope: ptr<lang_object> = - createLangObject( 0 '<tpl_start>' lookupNs.top ) - templateParamNs.push( newTemplateParamScope ) + createLangObject( 0 '<tpl_start>' lookupNs.tail ) + templateParamNs.push_tail( newTemplateParamScope ) } def template_parameter_list @@ -1922,8 +1921,8 @@ context lookup if Id { # The lookup ns should be a template param scope. newClass: ptr<lang_object> = - createLangObject( ClassType Id.data lookupNs.top ) - insertObject( templateParamNs.top Id.data newClass ) + createLangObject( ClassType Id.data lookupNs.tail ) + insertObject( templateParamNs.tail Id.data newClass ) } } @@ -1933,8 +1932,8 @@ context lookup if Id { # The lookup ns should be a template param scope. newClass: ptr<lang_object> = - createLangObject( ClassType Id.data lookupNs.top ) - insertObject( templateParamNs.top Id.data newClass ) + createLangObject( ClassType Id.data lookupNs.tail ) + insertObject( templateParamNs.tail Id.data newClass ) } } @@ -1944,8 +1943,8 @@ context lookup Id: lookup_id = lookup_id in r7 if Id { newClass: ptr<lang_object> = - createLangObject( TemplateClassType Id.data lookupNs.top ) - insertObject( templateParamNs.top Id.data newClass ) + createLangObject( TemplateClassType Id.data lookupNs.tail ) + insertObject( templateParamNs.tail Id.data newClass ) } } @@ -2004,15 +2003,15 @@ context lookup { match r2 [Id: lookup_id] nspace: ptr<lang_object> = createLangObject( - NamespaceType Id.data lookupNs.top ) + NamespaceType Id.data lookupNs.tail ) # Insert the new object into the dictionary of the parent. - insertObject( curNamespace.top Id.data nspace ) + insertObject( curNamespace.tail Id.data nspace ) # Push the namespace - curNamespace.push( nspace ) - declNs.push( nspace ) - lookupNs.push( nspace ) + curNamespace.push_tail( nspace ) + declNs.push_tail( nspace ) + lookupNs.push_tail( nspace ) # LOG print( 'created original namespace: ' Id.data '\n' ) } @@ -2020,9 +2019,9 @@ context lookup def namespace_end [] { # Pop the namespace. - curNamespace.pop() - declNs.pop() - lookupNs.pop() + curNamespace.pop_tail() + declNs.pop_tail() + lookupNs.pop_tail() # LOG print( 'closed namespace\n' ) } @@ -2040,9 +2039,9 @@ context lookup nspace: ptr<lang_object> = Id.obj # Push the namespace - curNamespace.push( nspace ) - declNs.push( nspace ) - lookupNs.push( nspace ) + curNamespace.push_tail( nspace ) + declNs.push_tail( nspace ) + lookupNs.push_tail( nspace ) # LOG print( 'found extended namespace: ' Id.data '\n' ) } @@ -2057,12 +2056,12 @@ context lookup { nspace: ptr<lang_object> = createLangObject( NamespaceType '<unnamed_namespace>' - lookupNs.top ) + lookupNs.tail ) # Push the namespace - curNamespace.push( nspace ) - declNs.push( nspace ) - lookupNs.push( nspace ) + curNamespace.push_tail( nspace ) + declNs.push_tail( nspace ) + lookupNs.push_tail( nspace ) # LOG print( 'parsed unnamed namespace\n' ) } @@ -2175,15 +2174,15 @@ Lookup.templDecl = construct list<int> [] Lookup.rootNamespace = createLangObject( Lookup.NamespaceType '<root_namespace>' nil ) # Initialize the namespace and declaration stacks with the root namespace -Lookup.curNamespace.push( Lookup.rootNamespace ) -Lookup.declNs.push( Lookup.rootNamespace ) -Lookup.lookupNs.push( Lookup.rootNamespace ) +Lookup.curNamespace.push_tail( Lookup.rootNamespace ) +Lookup.declNs.push_tail( Lookup.rootNamespace ) +Lookup.lookupNs.push_tail( Lookup.rootNamespace ) # Start with no qualification (note variables are initialized to zero) -Lookup.qualNs.push( nil ) +Lookup.qualNs.push_tail( nil ) -Lookup.templDecl.push( 0 ) -Lookup.declarationData.push( construct lookup::declaration_data( 0 0 0 ) [] ) +Lookup.templDecl.push_tail( 0 ) +Lookup.declarationData.push_tail( construct lookup::declaration_data( 0 0 0 ) [] ) parse S: lookup::start( Lookup )[ stdin ] if ! S { |