diff options
author | Adrian Thurston <thurston@complang.org> | 2015-06-05 10:26:36 -0400 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2015-06-05 10:26:36 -0400 |
commit | db0fd98a4f646abef622684d4228d879a933cbce (patch) | |
tree | b8a7662b964b597ae91e05dae7247caf2d5afe27 | |
parent | 009deb74e036c25053246ce9b8a21069f8440834 (diff) | |
download | colm-db0fd98a4f646abef622684d4228d879a933cbce.tar.gz |
more of the vlist implementation .. moved all test cases to vlist
-rw-r--r-- | src/bytecode.c | 162 | ||||
-rw-r--r-- | src/bytecode.h | 2 | ||||
-rw-r--r-- | src/declare.cc | 22 | ||||
-rw-r--r-- | src/iter.c | 31 | ||||
-rw-r--r-- | src/parsetree.h | 6 | ||||
-rw-r--r-- | src/synthesis.cc | 25 | ||||
-rw-r--r-- | src/tree.h | 18 | ||||
-rw-r--r-- | test/binary1.lm | 30 | ||||
-rw-r--r-- | test/generate1.lm | 22 | ||||
-rw-r--r-- | test/generate2.lm | 6 | ||||
-rw-r--r-- | test/list1.lm | 9 | ||||
-rw-r--r-- | test/list4.lm | 25 | ||||
-rw-r--r-- | test/lookup1.lm | 337 | ||||
-rw-r--r-- | test/undolist1.lm | 23 |
14 files changed, 420 insertions, 298 deletions
diff --git a/src/bytecode.c b/src/bytecode.c index c956e477..749a6f85 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -2011,7 +2011,7 @@ again: read_half( arg_size ); read_half( generic_id ); - debug( prg, REALM_BYTECODE, "IN_LIST_ITER_FROM_REF " + debug( prg, REALM_BYTECODE, "IN_GEN_ITER_FROM_REF " "%hd %hd %hd\n", field, arg_size, generic_id ); ref_t root_ref; @@ -2050,6 +2050,18 @@ again: vm_push_tree( res ); break; } + case IN_REV_LIST_ITER_ADVANCE: { + short field; + read_half( field ); + + debug( prg, REALM_BYTECODE, "IN_RE_LIST_ITER_ADVANCE\n" ); + + generic_iter_t *iter = (generic_iter_t*) vm_get_plocal(exec, field); + tree_t *res = colm_rev_list_iter_advance( prg, &sp, iter ); + //colm_tree_upref( res ); + vm_push_tree( res ); + break; + } case IN_MAP_ITER_ADVANCE: { short field; read_half( field ); @@ -3862,8 +3874,7 @@ again: vm_push_struct( s ); - /* Set up reverse. The result comes off the list downrefed. - * Need it up referenced for the reverse code too. */ + /* Set up reverse. */ rcode_code( exec, IN_FN ); rcode_code( exec, IN_LIST_POP_TAIL_BKT ); rcode_half( exec, gen_id ); @@ -4142,6 +4153,32 @@ again: vm_push_tree( prg->true_val ); break; } + case IN_VLIST_PUSH_TAIL_WV: { + short gen_id; + read_half( gen_id ); + + debug( prg, REALM_BYTECODE, "IN_VLIST_PUSH_TAIL_WV %hd\n", gen_id ); + + list_t *list = vm_pop_list(); + value_t value = vm_pop_value(); + + colm_vlist_append( prg, list, value ); + + vm_push_tree( prg->true_val ); + + /* Set up reverse code. Needs no args. */ + rcode_code( exec, IN_FN ); + rcode_code( exec, IN_VLIST_PUSH_TAIL_BKT ); + rcode_unit_term( exec ); + break; + } + case IN_VLIST_PUSH_TAIL_BKT: { + debug( prg, REALM_BYTECODE, "IN_VLIST_PUSH_TAIL_BKT\n" ); + + list_t *list = vm_pop_list(); + colm_list_detach_tail( list ); + break; + } case IN_VLIST_PUSH_HEAD_WC: { short gen_id; read_half( gen_id ); @@ -4156,6 +4193,32 @@ again: vm_push_tree( prg->true_val ); break; } + case IN_VLIST_PUSH_HEAD_WV: { + short gen_id; + read_half( gen_id ); + + debug( prg, REALM_BYTECODE, "IN_VLIST_PUSH_HEAD_WV %hd\n", gen_id ); + + list_t *list = vm_pop_list(); + value_t value = vm_pop_value(); + + colm_vlist_prepend( prg, list, value ); + + vm_push_tree( prg->true_val ); + + /* Set up reverse code. Needs no args. */ + rcode_code( exec, IN_FN ); + rcode_code( exec, IN_VLIST_PUSH_HEAD_BKT ); + rcode_unit_term( exec ); + break; + } + case IN_VLIST_PUSH_HEAD_BKT: { + debug( prg, REALM_BYTECODE, "IN_VLIST_PUSH_HEAD_BKT\n" ); + + list_t *list = vm_pop_list(); + colm_list_detach_head( list ); + break; + } case IN_VLIST_POP_HEAD_WC: { short gen_id; read_half( gen_id ); @@ -4168,6 +4231,38 @@ again: vm_push_value( result ); break; } + case IN_VLIST_POP_HEAD_WV: { + short gen_id; + read_half( gen_id ); + + debug( prg, REALM_BYTECODE, "IN_VLIST_POP_HEAD_WV %hd\n", gen_id ); + + list_t *list = vm_pop_list(); + + value_t result = colm_vlist_detach_head( prg, list ); + vm_push_value( result ); + + /* Set up reverse. */ + rcode_code( exec, IN_FN ); + rcode_code( exec, IN_VLIST_POP_HEAD_BKT ); + rcode_half( exec, gen_id ); + rcode_word( exec, (word_t)result ); + rcode_unit_term( exec ); + break; + } + case IN_VLIST_POP_HEAD_BKT: { + short gen_id; + tree_t *val; + read_half( gen_id ); + read_tree( val ); + + debug( prg, REALM_BYTECODE, "IN_VLIST_POP_HEAD_BKT\n" ); + + list_t *list = vm_pop_list(); + + colm_vlist_prepend( prg, list, val ); + break; + } case IN_VLIST_POP_TAIL_WC: { short gen_id; read_half( gen_id ); @@ -4180,6 +4275,38 @@ again: vm_push_value( result ); break; } + case IN_VLIST_POP_TAIL_WV: { + short gen_id; + read_half( gen_id ); + + debug( prg, REALM_BYTECODE, "IN_VLIST_POP_TAIL_WV %hd\n", gen_id ); + + list_t *list = vm_pop_list(); + + value_t result = colm_vlist_detach_tail( prg, list ); + vm_push_value( result ); + + /* Set up reverse. */ + rcode_code( exec, IN_FN ); + rcode_code( exec, IN_VLIST_POP_TAIL_BKT ); + rcode_half( exec, gen_id ); + rcode_word( exec, (word_t)result ); + rcode_unit_term( exec ); + break; + } + case IN_VLIST_POP_TAIL_BKT: { + short gen_id; + tree_t *val; + read_half( gen_id ); + read_tree( val ); + + debug( prg, REALM_BYTECODE, "IN_VLIST_POP_TAIL_BKT\n" ); + + list_t *list = vm_pop_list(); + + colm_vlist_append( prg, list, val ); + break; + } case IN_EXIT_HARD: { debug( prg, REALM_BYTECODE, "IN_EXIT\n" ); @@ -4513,6 +4640,35 @@ again: colm_tree_downref( prg, sp, key ); colm_tree_downref( prg, sp, val ); break; + } + + case IN_VLIST_PUSH_TAIL_BKT: { + break; + } + + case IN_VLIST_PUSH_HEAD_BKT: { + break; + } + + case IN_VLIST_POP_HEAD_BKT: { + short gen_id; + word_t result; + read_half( gen_id ); + read_word( result ); + break; + } + + case IN_VLIST_POP_TAIL_BKT: { + short gen_id; + word_t result; + read_half( gen_id ); + read_word( result ); + break; + } + + default: { + fatal( "UNKNOWN FN 0x%2x: -- reverse code downref\n", *(instr-1)); + assert(false); }} break; } diff --git a/src/bytecode.h b/src/bytecode.h index af03db77..bddaed91 100644 --- a/src/bytecode.h +++ b/src/bytecode.h @@ -83,6 +83,7 @@ typedef unsigned long colm_value_t; #define IN_GEN_ITER_GET_CUR_R 0xdf #define IN_GEN_VITER_GET_CUR_R 0xe7 #define IN_LIST_ITER_ADVANCE 0xde +#define IN_REV_LIST_ITER_ADVANCE 0x77 #define IN_MAP_ITER_ADVANCE 0xe6 #define IN_NOT_VAL 0x14 @@ -211,7 +212,6 @@ typedef unsigned long colm_value_t; #define IN_GET_VLIST_MEM_BKT 0x5c // 0x76 -// 0x77 #define IN_DONE 0x78 diff --git a/src/declare.cc b/src/declare.cc index 2179c7e8..05073547 100644 --- a/src/declare.cc +++ b/src/declare.cc @@ -708,6 +708,28 @@ void Compiler::makeDefaultIterators() objMethod->iterDef = triter; } + /* Value List iterator. */ + { + UniqueType *anyRefUT = findUniqueType( TYPE_REF, anyLangEl ); + ObjectMethod *objMethod = initFunction( uniqueTypeAny, globalObjectDef, + "vlist_iter", IN_HALT, IN_HALT, anyRefUT, true ); + + IterDef *triter = findIterDef( IterDef::ValueList ); + objMethod->iterDef = triter; + } + + /* Reverse Value List iterator. */ + { + UniqueType *anyRefUT = findUniqueType( TYPE_REF, anyLangEl ); + ObjectMethod *objMethod = initFunction( uniqueTypeAny, globalObjectDef, + "rev_vlist_iter", IN_HALT, IN_HALT, anyRefUT, true ); + + IterDef *triter = findIterDef( IterDef::RevValueList ); + objMethod->iterDef = triter; + } + + + /* Map iterator. */ { UniqueType *anyRefUT = findUniqueType( TYPE_REF, anyLangEl ); @@ -88,6 +88,37 @@ tree_t *colm_list_iter_advance( program_t *prg, tree_t ***psp, generic_iter_t *i return (iter->ref.kid ? prg->true_val : prg->false_val ); } +tree_t *colm_rev_list_iter_advance( program_t *prg, tree_t ***psp, generic_iter_t *iter ) +{ + tree_t **sp = *psp; + assert( iter->yield_size == (vm_ssize() - iter->root_size) ); + + if ( iter->ref.kid == 0 ) { + /* kid_t is zero, start from the root. */ + list_t *list = *((list_t**)iter->root_ref.kid); + iter->ref.kid = (kid_t*)list->tail; + iter->ref.next = 0; + + //= iter->rootRef; + //iter + //iterFind( prg, psp, iter, true ); + } + else { + /* Have a previous item, continue searching from there. */ + //iterFind( prg, psp, iter, false ); + + list_el_t *list_el = (list_el_t*)iter->ref.kid; + list_el = list_el->list_prev; + iter->ref.kid = (kid_t*)list_el; + iter->ref.next = 0; + } + + sp = *psp; + iter->yield_size = vm_ssize() - iter->root_size; + + return (iter->ref.kid ? prg->true_val : prg->false_val ); +} + tree_t *colm_map_iter_advance( program_t *prg, tree_t ***psp, generic_iter_t *iter ) { tree_t **sp = *psp; diff --git a/src/parsetree.h b/src/parsetree.h index afd63834..718f2dc3 100644 --- a/src/parsetree.h +++ b/src/parsetree.h @@ -1733,7 +1733,8 @@ struct Function; struct IterDef { enum Type { Tree, Child, RevChild, Repeat, - RevRepeat, User, List, Map }; + RevRepeat, User, List, ValueList, + RevValueList, Map }; IterDef( Type type, Function *func ); IterDef( Type type ); @@ -1746,7 +1747,8 @@ struct IterDef struct IterImpl { enum Type { Tree, Child, RevChild, Repeat, - RevRepeat, User, List, ValueList, Map, ValueMap }; + RevRepeat, User, List, ValueList, + RevValueList, Map, ValueMap }; IterImpl( Type type, Function *func ); IterImpl( Type type ); diff --git a/src/synthesis.cc b/src/synthesis.cc index 65e48656..539cf5ed 100644 --- a/src/synthesis.cc +++ b/src/synthesis.cc @@ -149,6 +149,21 @@ IterImpl::IterImpl( Type type ) : useGenericId = true; break; + case RevValueList: + inCreateWV = IN_GEN_ITER_FROM_REF; + inCreateWC = IN_GEN_ITER_FROM_REF; + inUnwind = IN_GEN_ITER_UNWIND; + inDestroy = IN_GEN_ITER_DESTROY; + inAdvance = IN_REV_LIST_ITER_ADVANCE; + + inGetCurR = IN_GEN_VITER_GET_CUR_R; + inGetCurWC = //IN_LIST_ITER_GET_CUR_WC; + inSetCurWC = //IN_HALT; + inRefFromCur = //IN_LIST_ITER_REF_FROM_CUR; + useGenericId = true; + break; + + case ValueMap: inCreateWV = IN_GEN_ITER_FROM_REF; inCreateWC = IN_GEN_ITER_FROM_REF; @@ -307,6 +322,8 @@ long sizeOfField( UniqueType *fieldUT ) case IterDef::Map: case IterDef::List: + case IterDef::ValueList: + case IterDef::RevValueList: size = sizeof(generic_iter_t) / sizeof(word_t); break; @@ -2297,6 +2314,12 @@ void LangStmt::compileForIter( Compiler *pd, CodeVect &code ) const case IterDef::List: iterImpl = new IterImpl( IterImpl::List ); break; + case IterDef::ValueList: + iterImpl = new IterImpl( IterImpl::ValueList ); + break; + case IterDef::RevValueList: + iterImpl = new IterImpl( IterImpl::RevValueList ); + break; case IterDef::Map: iterImpl = new IterImpl( IterImpl::Map ); break; @@ -2614,6 +2637,8 @@ void Compiler::findLocals( ObjectDef *localFrame, CodeBlock *block ) case IterDef::Map: case IterDef::List: + case IterDef::ValueList: + case IterDef::RevValueList: /* ? */ type = LT_Iter; break; @@ -326,8 +326,12 @@ void colm_init_rev_tree_iter( rev_tree_iter_t *rev_triter, tree_t **stack_root, void colm_init_user_iter( user_iter_t *user_iter, tree_t **stack_root, long root_size, long arg_size, long search_id ); -void colm_tree_iter_destroy( struct colm_program *prg, tree_t ***psp, tree_iter_t *iter ); -void colm_rev_tree_iter_destroy( struct colm_program *prg, tree_t ***psp, rev_tree_iter_t *iter ); +void colm_tree_iter_destroy( struct colm_program *prg, + tree_t ***psp, tree_iter_t *iter ); + +void colm_rev_tree_iter_destroy( struct colm_program *prg, + tree_t ***psp, rev_tree_iter_t *iter ); + void colm_uiter_destroy( struct colm_program *prg, tree_t ***psp, user_iter_t *uiter ); void colm_uiter_unwind( struct colm_program *prg, tree_t ***psp, user_iter_t *uiter ); @@ -336,8 +340,14 @@ struct stream_impl *stream_to_impl( stream_t *ptr ); void colm_init_list_iter( generic_iter_t *list_iter, tree_t **stack_root, long arg_size, long root_size, const ref_t *root_ref, int generic_id ); -void colm_list_iter_destroy( struct colm_program *prg, tree_t ***psp, generic_iter_t *iter ); -tree_t *colm_list_iter_advance( struct colm_program *prg, tree_t ***psp, generic_iter_t *iter ); +void colm_list_iter_destroy( struct colm_program *prg, + tree_t ***psp, generic_iter_t *iter ); + +tree_t *colm_list_iter_advance( struct colm_program *prg, + tree_t ***psp, generic_iter_t *iter ); +tree_t *colm_rev_list_iter_advance( struct colm_program *prg, + tree_t ***psp, generic_iter_t *iter ); + tree_t *colm_list_iter_deref_cur( struct colm_program *prg, generic_iter_t *iter ); void colm_list_append( struct colm_list *list, struct colm_list_el *new_el ); void colm_list_prepend( struct colm_list *list, struct colm_list_el *new_el ); diff --git a/test/binary1.lm b/test/binary1.lm index f484c136..7ea32885 100644 --- a/test/binary1.lm +++ b/test/binary1.lm @@ -116,19 +116,11 @@ def count # end # -struct int_el - Int: int - - list_el el -end - -CL: list<int_el> +CL: vlist<int> int start_list( count: int ) { - IntEl: int_el = new int_el() - IntEl->Int = count - CL->push( IntEl ) + CL->push( count ) } def count_inc @@ -503,25 +495,21 @@ int print_all_names( s: start ) end # binary Binary: binary = new binary() -Binary->CL = new list<binary::int_el>() +Binary->CL = new vlist<int>() -int top( L: list<binary::int_el> ) +int top( L: vlist<int> ) { - Top: binary::int_el = L->top - return Top->Int + return L->top } -int pop( L: list<binary::int_el> ) +int pop( L: vlist<int> ) { - Top: binary::int_el = L->pop() - return Top->Int + return L->pop() } -int push( L: list<binary::int_el>, Int: int ) +int push( L: vlist<int>, Int: int ) { - Top: binary::int_el = new binary::int_el() - Top->Int = Int - L->push( Top ) + L->push( Int ) } parse S: binary::start(Binary) [ stdin ] diff --git a/test/generate1.lm b/test/generate1.lm index 18042bd5..e7936a6f 100644 --- a/test/generate1.lm +++ b/test/generate1.lm @@ -3,11 +3,7 @@ context generate rl ident_char /[a-zA-Z_]/ # List used as a stack of indentations. - struct int_el - Int: int - list_el el - end - IndentStack: list<int_el> + IndentStack: vlist<int> # Has a newline been sent for this '\n' .. whitespace match. newline_sent: int @@ -106,18 +102,16 @@ context generate # We have already sent the newline, compute the indentation level. data_length: int = match_length - 1 - Top: int_el = IndentStack->top - if data_length > Top->Int { + Top: int = IndentStack->top + if data_length > Top { # The indentation level is more than the level on the top # of the stack. This is an indent event. Send as an INDENT. input->push( make_token( typeid<INDENT>, '' ) ) # Push to the stack as per python manual. - IntEl: int_el = new int_el() - IntEl->Int = data_length - IndentStack->push( IntEl ) + IndentStack->push( data_length ) } else { - while data_length < Top->Int { + while data_length < Top { # The indentation level is less than the level on the top of # the stack. Pop the level and send one dedent. This flow of # control will execute until we find the right indentation level @@ -568,10 +562,8 @@ int print_primary_subscriptions_and_slicings( Start: generate::start ) Generate: generate = new generate() # List used as a stack of indentations. -Generate->IndentStack = new list<generate::int_el>() -IntEl: generate::int_el = new generate::int_el() -IntEl->Int = 0 -Generate->IndentStack->push( IntEl ) +Generate->IndentStack = new vlist<int>() +Generate->IndentStack->push( 0 ) # Has a newline been sent for this '\n' .. whitespace match. Generate->newline_sent = 0 diff --git a/test/generate2.lm b/test/generate2.lm index d8f9d248..32260003 100644 --- a/test/generate2.lm +++ b/test/generate2.lm @@ -2,8 +2,6 @@ context generate struct open_item type: str num: int - - list_el el end open_item new_open_item( type: str, num: int ) @@ -14,7 +12,7 @@ context generate return OI } - OpenStack: list<open_item> + OpenStack: vlist<open_item> lex token stray_close // @@ -202,7 +200,7 @@ end # generate Generate: generate = new generate() -Generate->OpenStack = new list<generate::open_item>() +Generate->OpenStack = new vlist<generate::open_item>() Sentinal: generate::open_item = new_open_item( '** SENTINAL **', 1 ) Generate->OpenStack->push( Sentinal ) diff --git a/test/list1.lm b/test/list1.lm index 90c75dbe..b51e0fe1 100644 --- a/test/list1.lm +++ b/test/list1.lm @@ -19,10 +19,9 @@ struct start_el B1: start B2: start B3: start - list_el el end -L: list<start_el> = new list<start_el>() +L: vlist<start_el> = new vlist<start_el>() E: start_el = new start_el() E->S = S @@ -32,10 +31,8 @@ E = new start_el() E->S = S L->push_head( E ) -E = L->head -while ( E ) { - print( E->S ) - E = E->next +for SE: start_el in L { + print( SE->S ) } ##### IN ###### diff --git a/test/list4.lm b/test/list4.lm new file mode 100644 index 00000000..a7cb9dbb --- /dev/null +++ b/test/list4.lm @@ -0,0 +1,25 @@ + +new L: vlist<str>() + +L->push_tail( "dear" ) +L->push_tail( "friend" ) +L->push_tail( "---" ) + +L->push_head( "my" ) +L->push_head( "hello" ) + +L->push_head( "..." ) + + +L->pop_tail() +L->pop_head() + +for S: str in rev_vlist_iter(L) { + print "[S] +} + +##### EXP ##### +friend +dear +my +hello diff --git a/test/lookup1.lm b/test/lookup1.lm index 9925dee3..51385cb3 100644 --- a/test/lookup1.lm +++ b/test/lookup1.lm @@ -1,26 +1,16 @@ context lookup - struct list_lang_object_el - Obj: lang_object - list_el el - end - alias list_lang_object - list<list_lang_object_el> + vlist<lang_object> alias list_declaration_data - list<declaration_data> + vlist<declaration_data> alias list_declarator_data - list<declarator_data> - - struct list_int_el - Int: int - list_el el - end + vlist<declarator_data> alias list_int - list<list_int_el> + vlist<int> struct map_list_lang_object_el List: list_lang_object @@ -57,16 +47,12 @@ context lookup isTemplate: int typeObj: lang_object - - list_el el end struct declarator_data qualObj: lang_object pdcScope: lang_object lookupObj: lang_object - - list_el el end # Constants for language object types. @@ -111,7 +97,7 @@ context lookup ol: map_list_lang_object_el = obj->objectMap->find( name ) if ol { # LOG print( ' * found an object: ', ol.head, '\n' ) - return ol->List->head->Obj + return ol->List->head } return nil @@ -125,11 +111,7 @@ context lookup if found return found - localObjInherited: list_lang_object = obj->inherited - II: list_lang_object_el = localObjInherited->head - while II { - inh: lang_object = II->Obj - + for inh: lang_object in obj->inherited { # First check if the inherited object is the one we are after. if inh->name == name && inh->typeId == ClassType { # LOG print( ' * found a class name\n' ) @@ -140,8 +122,6 @@ context lookup found = lookupWithInheritance( inh, name ) if found return found - - II = II->next } return nil @@ -152,19 +132,16 @@ context lookup found: lang_object # Start with the objects in the templateParamNs. - localTemplateParamNs: list_lang_object = templateParamNs - TemplParaObjIter: list_lang_object_el = localTemplateParamNs->tail - while ( TemplParaObjIter ) { - found = lookupWithInheritance( TemplParaObjIter->Obj, name ) + for Obj: lang_object in rev_vlist_iter( templateParamNs ) { + found = lookupWithInheritance( Obj, name ) if found break - TemplParaObjIter = TemplParaObjIter->prev } if !found { # Iterator over the objects starting at the head of the lookup stack # and going up through the lookup parents. - lookupIn: lang_object = lookupNs->tail->Obj + lookupIn: lang_object = lookupNs->tail while lookupIn { found = lookupWithInheritance( lookupIn, name ) if found @@ -227,12 +204,13 @@ context lookup name: str = match_text found: lang_object = nil qualObj: lang_object = nil - if qualNs->tail->Obj { + if qualNs->tail { # LOG print( 'qualified lookup of ', name, '\n' ) # Transfer the qualification to the token and reset it. - qualObj = qualNs->tail->Obj - qualNs->tail->Obj = nil + qualObj = qualNs->tail + qualNs->pop_tail() + qualNs->push_tail( nil ) # Lookup using the qualification. found = lookupWithInheritance( qualObj, name ) @@ -318,22 +296,17 @@ context lookup ol->List = new list_lang_object() definedIn->objectMap->insert( ol ) } - E: list_lang_object_el = new list_lang_object_el() - E->Obj = obj - ol->List->push_tail( E ) + ol->List->push_tail( obj ) } lang_object findClass( inObj: lang_object, lang_objectname: str ) { ol: map_list_lang_object_el = inObj->objectMap->find( name ) if ol { - ObjIter: list_lang_object_el = ol->List->head - while ( ObjIter ) { - obj: lang_object = ObjIter->Obj + for obj: lang_object in ol->List { if obj->typeId == ClassType { return obj } - ObjIter = ObjIter->next } } return nil @@ -343,12 +316,9 @@ context lookup { ol: map_list_lang_object_el = inObj->objectMap->find( name ) if ol { - ObjIter: list_lang_object_el = ol->List->head - while ( ObjIter ) { - obj: lang_object = ObjIter->Obj + for obj: lang_object in ol->List { if obj->typeId == TemplateClassType return obj - ObjIter = ObjIter->next } } return nil @@ -371,33 +341,38 @@ context lookup def qualifying_name [class_name] { - qualNs->tail->Obj = r1.lookupId.obj + qualNs->pop_tail() + qualNs->push_tail( r1.lookupId.obj ) } | [namespace_id] { match r1 [Id: lookup_id] - qualNs->tail->Obj = Id.obj + qualNs->pop_tail() + qualNs->push_tail( Id.obj ) } | [typedef_id] { match r1 [Id: lookup_id] - qualNs->tail->Obj = Id.obj->typedefOf + qualNs->pop_tail() + qualNs->push_tail( Id.obj->typedefOf ) } def designated_qualifying_name [`template any_id] { # FIXME: nulling qualNs is not the right thing to do here. - qualNs->tail->Obj = nil + qualNs->pop_tail() + qualNs->push_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->tail->Obj = nil + qualNs->pop_tail() + qualNs->push_tail( nil ) } # @@ -421,8 +396,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: lang_object = qualNs->tail->Obj - qualNs->tail->Obj = nil + qualObj: lang_object = qualNs->pop_tail() + qualNs->push_tail( nil ) lhs.lookupId = construct lookup_id ["x"] lhs.lookupId.data = '<operator_function_id>' @@ -433,8 +408,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: lang_object = qualNs->tail->Obj - qualNs->tail->Obj = nil + qualObj: lang_object = qualNs->pop_tail() + qualNs->push_tail( nil ) # Do we need qual reset here becauase operator_function_id does not do it? lhs.lookupId = construct lookup_id ["x"] @@ -492,9 +467,7 @@ context lookup def templ_arg_open [`<] { - E: list_lang_object_el = new list_lang_object_el() - E->Obj = nil - qualNs->push_tail( E ) + qualNs->push_tail( nil ) } def templ_arg_close @@ -543,10 +516,8 @@ context lookup declarationData->push_tail( DD ) # Transfer the template flag and reset it. - declarationData->tail->isTemplate = templDecl->tail->Int - IntEl: list_int_el = new list_int_el() - IntEl->Int = 0 - templDecl->push_tail( IntEl ) + declarationData->tail->isTemplate = templDecl->tail + templDecl->push_tail( 0 ) } def declaration_end @@ -712,7 +683,7 @@ context lookup name: str = Id.data # Get the ns the class is declared in. - parentObj: lang_object = declNs->tail->Obj + parentObj: lang_object = declNs->tail if Id.qualObj parentObj = Id.qualObj @@ -727,7 +698,7 @@ context lookup # Class does not exist in the parent scope, create it. nsType: int = declaredClassType() - declaredClass = createLangObject( nsType, name, lookupNs->tail->Obj ) + 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 @@ -746,8 +717,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: lang_object = createLangObject( EnumType, Id.data, lookupNs->tail->Obj ) - insertObject( declNs->tail->Obj, Id.data, enum ) + enum: lang_object = createLangObject( EnumType, Id.data, lookupNs->tail ) + insertObject( declNs->tail, Id.data, enum ) } def decl_specifier_mult_seq_opt @@ -816,8 +787,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: lang_object = createLangObject( EnumType, Id.data, lookupNs->tail->Obj ) - insertObject( declNs->tail->Obj, Id.data, enum ) + enum: lang_object = createLangObject( EnumType, Id.data, lookupNs->tail ) + insertObject( declNs->tail, Id.data, enum ) } | [`enum `{ enumerator_list_opt `}] @@ -845,15 +816,15 @@ context lookup [enumerator_id] { Id: lookup_id = lookup_id in r1 - enumId: lang_object = createLangObject( IdType, Id.data, lookupNs->tail->Obj ) - insertObject( declNs->tail->Obj, Id.data, enumId ) + enumId: 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: lang_object = createLangObject( IdType, Id.data, lookupNs->tail->Obj ) - insertObject( declNs->tail->Obj, Id.data, enumId ) + enumId: lang_object = createLangObject( IdType, Id.data, lookupNs->tail ) + insertObject( declNs->tail, Id.data, enumId ) } def enumerator_id @@ -1151,14 +1122,10 @@ context lookup [] { newCompound: lang_object = createLangObject( 0, - '<compound_begin>', lookupNs->tail->Obj ) - E1: list_lang_object_el = new list_lang_object_el() - E1->Obj = newCompound - lookupNs->push_tail( E1 ) - - E2: list_lang_object_el = new list_lang_object_el() - E2->Obj = newCompound - declNs->push_tail( E2 ) + '<compound_begin>', lookupNs->tail ) + lookupNs->push_tail( newCompound ) + + declNs->push_tail( newCompound ) # LOG print( 'opening <compound>\n' ) } @@ -1270,10 +1237,9 @@ context lookup name: str = r1.lookupId.data qualObj: lang_object = r1.lookupId.qualObj - parentObj: lang_object = declNs->tail->Obj - if qualObj { + parentObj: lang_object = declNs->tail + if qualObj parentObj = qualObj - } # Decide if we are declaring a constructor/destructor. isConstructor: bool @@ -1292,7 +1258,7 @@ context lookup obj: lang_object = nil if name && !isConstructor && declarationData->tail->isFriend == 0 { if declarationData->tail->isTypedef { - obj = createLangObject( TypedefType, name, lookupNs->tail->Obj ) + obj = createLangObject( TypedefType, name, lookupNs->tail ) obj->typedefOf = declarationData->tail->typeObj insertObject( parentObj, name, obj ) @@ -1303,16 +1269,16 @@ context lookup 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->tail->Obj ) + obj = createLangObject( TemplateIdType, name, lookupNs->tail ) #object->objType = declarationData.tail.type - insertObject( declNs->tail->Obj, name, obj ) + insertObject( declNs->tail, name, obj ) # LOG print( 'making declarator ' name ' a template id\n' ) } else { - obj = createLangObject( IdType, name, lookupNs->tail->Obj ) + obj = createLangObject( IdType, name, lookupNs->tail ) #object->objType = declarationData.tail().type; - insertObject( declNs->tail->Obj, name, obj ) + insertObject( declNs->tail, name, obj ) # LOG print( 'making declarator ' name ' an id\n' ) } @@ -1324,7 +1290,7 @@ context lookup DD: declarator_data = new declarator_data() DD->qualObj = qualObj DD->pdcScope = nil - DD->lookupObj = lookupNs->tail->Obj + DD->lookupObj = lookupNs->tail declaratorData->push_tail( DD ) @@ -1332,9 +1298,7 @@ context lookup # stack. Also save it in the declarator data so it can be passed to a # function body if needed. if qualObj { - E: list_lang_object_el = new list_lang_object_el() - E->Obj = qualObj - lookupNs->push_tail( E ) + lookupNs->push_tail( qualObj ) declaratorData->tail->lookupObj = qualObj } @@ -1456,15 +1420,10 @@ context lookup if !declaratorData->tail->pdcScope { # We are going to need a scope for the declarator. pdcScope: lang_object = createLangObject( 0, - '<pdc_scope>', lookupNs->tail->Obj ) - - E1: list_lang_object_el = new list_lang_object_el() - E1->Obj = pdcScope - lookupNs->push_tail( E1 ) + '<pdc_scope>', lookupNs->tail ) - E2: list_lang_object_el = new list_lang_object_el() - E2->Obj = pdcScope - declNs->push_tail( E2 ) + lookupNs->push_tail( pdcScope ) + declNs->push_tail( pdcScope ) declaratorData->tail->pdcScope = pdcScope declaratorData->tail->lookupObj = pdcScope @@ -1530,9 +1489,7 @@ 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. - E: list_lang_object_el = new list_lang_object_el() - E->Obj = r1.lookupObj - lookupNs->push_tail( E ) + lookupNs->push_tail( r1.lookupObj ) } def function_def_end @@ -1549,19 +1506,13 @@ context lookup [] { newFunctionBody: lang_object = createLangObject( 0, - '<function_body_begin>', lookupNs->tail->Obj ) + '<function_body_begin>', lookupNs->tail ) - E1: list_lang_object_el = new list_lang_object_el() - E1->Obj = newFunctionBody - lookupNs->push_tail( E1 ) + lookupNs->push_tail( newFunctionBody ) - E2: list_lang_object_el = new list_lang_object_el() - E2->Obj = newFunctionBody - declNs->push_tail( E2 ) + declNs->push_tail( newFunctionBody ) - IntEl: list_int_el = new list_int_el() - IntEl->Int = 0 - templDecl->push_tail( IntEl ) + templDecl->push_tail( 0 ) # LOG print( 'opening <function_body>\n' ) } @@ -1615,15 +1566,10 @@ context lookup # LOG print( 'creating new anonymous class\n' ) newClass: lang_object = createLangObject( nsType, - '<anon_class>', lookupNs->tail->Obj ) + '<anon_class>', lookupNs->tail ) - E1: list_lang_object_el = new list_lang_object_el() - E1->Obj = newClass - lookupNs->push_tail( E1 ) - - E2: list_lang_object_el = new list_lang_object_el() - E2->Obj = newClass - declNs->push_tail( E2 ) + lookupNs->push_tail( newClass ) + declNs->push_tail( newClass ) } | [class_key nested_name_specifier_opt class_head_name] @@ -1632,7 +1578,7 @@ context lookup name: str = Id.data # Get the ns the class is declared in. - parentObj: lang_object = declNs->tail->Obj + parentObj: lang_object = declNs->tail if Id.qualObj parentObj = Id.qualObj @@ -1647,7 +1593,7 @@ context lookup # Class does not exist in the parent scope, create it. nsType: int = declaredClassType() - declaredClass = createLangObject( nsType, name, lookupNs->tail->Obj ) + 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 @@ -1657,13 +1603,8 @@ context lookup } # Push the found/new class. - E1: list_lang_object_el = new list_lang_object_el() - E1->Obj = declaredClass - lookupNs->push_tail( E1 ) - - E2: list_lang_object_el = new list_lang_object_el() - E2->Obj = declaredClass - declNs->push_tail( E2 ) + lookupNs->push_tail( declaredClass ) + declNs->push_tail( declaredClass ) } | [class_key nested_name_specifier_opt templ_class_id @@ -1682,20 +1623,15 @@ context lookup if !declaredClass { # LOG print( 'making new template specialization\n' ) nsType: int = declaredClassType() - declaredClass = createLangObject( nsType, id, lookupNs->tail->Obj ) + 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. - E1: list_lang_object_el = new list_lang_object_el() - E1->Obj = declaredClass - lookupNs->push_tail( E1 ) - - E2: list_lang_object_el = new list_lang_object_el() - E2->Obj = declaredClass - declNs->push_tail( E2 ) + lookupNs->push_tail( declaredClass ) + declNs->push_tail( declaredClass ) } def class_body_end @@ -1802,14 +1738,14 @@ context lookup { obj: lang_object = r2.lookupId.obj if obj - insertObject( declNs->tail->Obj, obj->name, obj ) + insertObject( declNs->tail, obj->name, obj ) } | [`using type_id `;] { obj: lang_object = r2.lookupId.obj if obj - insertObject( declNs->tail->Obj, obj->name, obj ) + insertObject( declNs->tail, obj->name, obj ) } def using_directive @@ -1821,12 +1757,9 @@ context lookup # for longer cycles as well. Note that even gcc 3.3.5 does not bother. match r5 [Id: lookup_id] usingObject: lang_object = Id.obj - inObject: lang_object = declNs->tail->Obj - if usingObject != inObject { - E: list_lang_object_el = new list_lang_object_el() - E->Obj = usingObject - inObject->inherited->push_tail( E ) - } + inObject: lang_object = declNs->tail + if usingObject != inObject + inObject->inherited->push_tail( usingObject ) } @@ -1851,25 +1784,23 @@ context lookup if inheritedObject->typeId == TypedefType inheritedObject = inheritedObject->typedefOf - E: list_lang_object_el = new list_lang_object_el() - E->Obj = inheritedObject - inObject->inherited->push_tail( E ) + inObject->inherited->push_tail( inheritedObject ) } def base_specifier [root_qual_opt nested_name_specifier_opt type_name] { - addBaseSpecifier( declNs->tail->Obj, r3.lookupId.obj ) + addBaseSpecifier( declNs->tail, r3.lookupId.obj ) } | [`virtual access_specifier_opt root_qual_opt nested_name_specifier_opt type_name] { - addBaseSpecifier( declNs->tail->Obj, r5.lookupId.obj ) + addBaseSpecifier( declNs->tail, r5.lookupId.obj ) } | [access_specifier virtual_opt root_qual_opt nested_name_specifier_opt type_name] { - addBaseSpecifier( declNs->tail->Obj, r5.lookupId.obj ) + addBaseSpecifier( declNs->tail, r5.lookupId.obj ) } def virtual_opt @@ -1978,16 +1909,12 @@ context lookup def template_declaration_params [`template `< tpl_start template_parameter_list `>] { - IntEl: list_int_el = new list_int_el() - IntEl->Int = 1 - templDecl->push_tail( IntEl ) + templDecl->push_tail( 1 ) } | [`export `template `< tpl_start template_parameter_list `>] { - IntEl: list_int_el = new list_int_el() - IntEl->Int = 1 - templDecl->push_tail( IntEl ) + templDecl->push_tail( 1 ) } def tpl_start @@ -1995,11 +1922,9 @@ context lookup { # Create a new scope for the template parameters. newTemplateParamScope: lang_object = - createLangObject( 0, '<tpl_start>', lookupNs->tail->Obj ) + createLangObject( 0, '<tpl_start>', lookupNs->tail ) - E: list_lang_object_el = new list_lang_object_el() - E->Obj = newTemplateParamScope - templateParamNs->push_tail( E ) + templateParamNs->push_tail( newTemplateParamScope ) } def template_parameter_list @@ -2041,8 +1966,8 @@ context lookup if Id { # The lookup ns should be a template param scope. newClass: lang_object = - createLangObject( ClassType, Id.data, lookupNs->tail->Obj ) - insertObject( templateParamNs->tail->Obj, Id.data, newClass ) + createLangObject( ClassType, Id.data, lookupNs->tail ) + insertObject( templateParamNs->tail, Id.data, newClass ) } } @@ -2052,8 +1977,8 @@ context lookup if Id { # The lookup ns should be a template param scope. newClass: lang_object = - createLangObject( ClassType, Id.data, lookupNs->tail->Obj ) - insertObject( templateParamNs->tail->Obj, Id.data, newClass ) + createLangObject( ClassType, Id.data, lookupNs->tail ) + insertObject( templateParamNs->tail, Id.data, newClass ) } } @@ -2063,8 +1988,8 @@ context lookup Id: lookup_id = lookup_id in r7 if Id { newClass: lang_object = - createLangObject( TemplateClassType, Id.data, lookupNs->tail->Obj ) - insertObject( templateParamNs->tail->Obj, Id.data, newClass ) + createLangObject( TemplateClassType, Id.data, lookupNs->tail ) + insertObject( templateParamNs->tail, Id.data, newClass ) } } @@ -2123,23 +2048,15 @@ context lookup { match r2 [Id: lookup_id] nspace: lang_object = createLangObject( - NamespaceType, Id.data, lookupNs->tail->Obj ) + NamespaceType, Id.data, lookupNs->tail ) # Insert the new object into the dictionary of the parent. - insertObject( curNamespace->tail->Obj, Id.data, nspace ) + insertObject( curNamespace->tail, Id.data, nspace ) # Push the namespace - E1: list_lang_object_el = new list_lang_object_el() - E1->Obj = nspace - curNamespace->push_tail( E1 ) - - E2: list_lang_object_el = new list_lang_object_el() - E2->Obj = nspace - declNs->push_tail( E2 ) - - E3: list_lang_object_el = new list_lang_object_el() - E3->Obj = nspace - lookupNs->push_tail( E3 ) + curNamespace->push_tail( nspace ) + declNs->push_tail( nspace ) + lookupNs->push_tail( nspace ) # LOG print( 'created original namespace: ' Id.data '\n' ) } @@ -2167,17 +2084,9 @@ context lookup nspace: lang_object = Id.obj # Push the namespace - E1: list_lang_object_el = new list_lang_object_el() - E1->Obj = nspace - curNamespace->push_tail( E1 ) - - E2: list_lang_object_el = new list_lang_object_el() - E2->Obj = nspace - declNs->push_tail( E2 ) - - E3: list_lang_object_el = new list_lang_object_el() - E3->Obj = nspace - lookupNs->push_tail( E3 ) + curNamespace->push_tail( nspace ) + declNs->push_tail( nspace ) + lookupNs->push_tail( nspace ) # LOG print( 'found extended namespace: ' Id.data '\n' ) } @@ -2192,20 +2101,12 @@ context lookup { nspace: lang_object = createLangObject( NamespaceType, '<unnamed_namespace>', - lookupNs->tail->Obj ) + lookupNs->tail ) # Push the namespace - E1: list_lang_object_el = new list_lang_object_el() - E1->Obj = nspace - curNamespace->push_tail( E1 ) - - E2: list_lang_object_el = new list_lang_object_el() - E2->Obj = nspace - declNs->push_tail( E2 ) - - E3: list_lang_object_el = new list_lang_object_el() - E3->Obj = nspace - lookupNs->push_tail( E3 ) + curNamespace->push_tail( nspace ) + declNs->push_tail( nspace ) + lookupNs->push_tail( nspace ) # LOG print( 'parsed unnamed namespace\n' ) } @@ -2273,10 +2174,8 @@ context lookup ChildNames: map_list_lang_object = obj->objectMap MapEl: map_list_lang_object_el = ChildNames->head while ( MapEl ) { - El: list_lang_object_el = MapEl->List->head - while ( El ) { - printObject( indent + ' ', El->Obj ) - El = El->next + for Obj: lang_object in MapEl->List { + printObject( indent + ' ', Obj ) } MapEl = MapEl->next } @@ -2323,26 +2222,14 @@ Lookup->templDecl = new lookup::list_int() Lookup->rootNamespace = createLangObject( Lookup->NamespaceType, '<root_namespace>', nil ) # Initialize the namespace and declaration stacks with the root namespace -E1: lookup::list_lang_object_el = new lookup::list_lang_object_el() -E1->Obj = Lookup->rootNamespace -Lookup->curNamespace->push_tail( E1 ) - -E2: lookup::list_lang_object_el = new lookup::list_lang_object_el() -E2->Obj = Lookup->rootNamespace -Lookup->declNs->push_tail( E2 ) - -E3: lookup::list_lang_object_el = new lookup::list_lang_object_el() -E3->Obj = Lookup->rootNamespace -Lookup->lookupNs->push_tail( E3 ) +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) -E4: lookup::list_lang_object_el = new lookup::list_lang_object_el() -E4->Obj = nil -Lookup->qualNs->push_tail( E4 ) +Lookup->qualNs->push_tail( nil ) -IntEl: lookup::list_int_el = new lookup::list_int_el() -IntEl->Int = 0 -Lookup->templDecl->push_tail( IntEl ) +Lookup->templDecl->push_tail( 0 ) DD: lookup::declaration_data = new lookup::declaration_data() DD->isTypedef = 0 diff --git a/test/undolist1.lm b/test/undolist1.lm index 7874ac0a..c9760eb0 100644 --- a/test/undolist1.lm +++ b/test/undolist1.lm @@ -7,25 +7,16 @@ context undo token id /[a-zA-Z_]+/ end - struct item_el - Item: item - list_el el - end - - List: list<item_el> + List: vlist<item> def item [id] { - E: item_el = new item_el() - E->Item = lhs - List->push_tail( E ) + List->push_tail( lhs ) } | [`( item* `)] { - E: item_el = new item_el() - E->Item = lhs - List->push_tail( E ) + List->push_tail( lhs ) } def A1 [] @@ -35,17 +26,15 @@ context undo [A1 item* `^] | [A2 item* `; NL] { - E: item_el = List->head - while ( E ) { - print "list el: [E->Item] - E = E->next + for Item: item in List { + print "list el: [Item] } } end Undo: undo = new undo() -Undo->List = new list<undo::item_el>() +Undo->List = new vlist<undo::item>() parse Input: undo::start(Undo)[ stdin ] print( Input ) |