diff options
author | Adrian Thurston <thurston@complang.org> | 2015-01-05 14:23:39 -0500 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2015-01-05 14:23:39 -0500 |
commit | b383decdd1652dc3384a24a57971283e40dd9b71 (patch) | |
tree | 6808f1706755740fffd0391e638625da458d209c /src | |
parent | dedc10d8fa47f41afb0e700786b374fda944090c (diff) | |
download | colm-b383decdd1652dc3384a24a57971283e40dd9b71.tar.gz |
some work on list access and traversal
Diffstat (limited to 'src')
-rw-r--r-- | src/bytecode.c | 96 | ||||
-rw-r--r-- | src/declare.cc | 30 | ||||
-rw-r--r-- | src/parser.cc | 1 | ||||
-rw-r--r-- | src/struct.c | 46 | ||||
-rw-r--r-- | src/struct.h | 5 |
5 files changed, 90 insertions, 88 deletions
diff --git a/src/bytecode.c b/src/bytecode.c index cbac75e9..73dff46a 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -3014,11 +3014,49 @@ again: vm_push( res ); break; } + case IN_LIST_PUSH_HEAD_WC: { + debug( prg, REALM_BYTECODE, "IN_LIST_PUSH_HEAD_WC\n" ); + + List *list = vm_pop_type( List* ); + Struct *s = vm_pop_type( Struct* ); + ListEl *listEl = colm_struct_get_addr_type( s, ListEl, 1 ); + + colm_list_prepend( list, listEl ); + + treeUpref( prg->trueVal ); + vm_push( prg->trueVal ); + break; + } + case IN_LIST_PUSH_HEAD_WV: { + debug( prg, REALM_BYTECODE, "IN_LIST_PUSH_HEAD_WV\n" ); + + List *list = vm_pop_type(List*); + Struct *s = vm_pop_type(Struct*); + ListEl *listEl = colm_struct_get_addr_type( s, ListEl, 1 ); + + colm_list_prepend( list, listEl ); + + 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_BKT: { + debug( prg, REALM_BYTECODE, "IN_LIST_PUSH_HEAD_BKT\n" ); + + List *list = vm_pop_type(List*); + colm_list_detach_head( list ); + break; + } case IN_LIST_PUSH_TAIL_WC: { debug( prg, REALM_BYTECODE, "IN_LIST_PUSH_TAIL_WC\n" ); List *list = vm_pop_type(List*); - ListEl *listEl = vm_pop_type(ListEl*); + Struct *s = vm_pop_type(Struct*); + ListEl *listEl = colm_struct_get_addr_type( s, ListEl, 1 ); colm_list_append( list, listEl ); @@ -3030,7 +3068,8 @@ again: debug( prg, REALM_BYTECODE, "IN_LIST_PUSH_TAIL_WV\n" ); List *list = vm_pop_type(List*); - ListEl *listEl = vm_pop_type(ListEl*); + Struct *s = vm_pop_type(Struct*); + ListEl *listEl = colm_struct_get_addr_type( s, ListEl, 1 ); colm_list_append( list, listEl ); @@ -3055,9 +3094,10 @@ again: debug( prg, REALM_BYTECODE, "IN_GET_LIST_EL_MEM_R\n" ); - Tree *obj = vm_pop(); - Tree *val = colm_list_el_get( (ListEl*)obj, field ); - vm_push( val ); + Struct *s = vm_pop_type( Struct * ); + ListEl *listEl = colm_struct_get_addr_type( s, ListEl, 1 ); + Struct *val = colm_list_el_get( listEl, field ); + vm_push_type( Struct *, val ); break; } case IN_LIST_POP_TAIL_WC: { @@ -3099,46 +3139,6 @@ again: 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" ); @@ -3186,9 +3186,9 @@ again: debug( prg, REALM_BYTECODE, "IN_GET_LIST_MEM_R\n" ); - Tree *obj = vm_pop(); - Tree *val = colm_list_get( (List*)obj, field ); - vm_push( val ); + List *list = vm_pop_type( List* ); + Struct *val = colm_list_get( list, field ); + vm_push_type( Struct *, val ); break; } case IN_GET_LIST_MEM_WC: { diff --git a/src/declare.cc b/src/declare.cc index a1e66843..ab3f2da6 100644 --- a/src/declare.cc +++ b/src/declare.cc @@ -297,9 +297,10 @@ void GenericType::declare( Compiler *pd, Namespace *nspace ) case GEN_LIST: pd->initListFunctions( this ); pd->initListFields( this ); + pd->initListElFields( this ); break; case GEN_LIST_EL: - pd->initListElFields( this ); +// pd->initListElFields( this ); break; case GEN_PARSER: utArg->langEl->parserId = pd->nextParserId++; @@ -927,15 +928,14 @@ void Compiler::initListFunctions( GenericType *gen ) void Compiler::initListElField( GenericType *gen, const char *name, int offset ) { -#if 0 - TypeRef *typeRef = TypeRef::cons( - internal, TypeRef::ListEl, 0, gen->typeArg, 0 ); - - typeRef->resolveType( this ); +// TypeRef *typeRef = TypeRef::cons( +// internal, TypeRef::ListEl, 0, gen->typeArg, 0 ); +// +// typeRef->resolveType( this ); /* Make the type ref and create the field. */ ObjectField *el = ObjectField::cons( internal, - ObjectField::InbuiltOffType, typeRef, name ); + ObjectField::InbuiltOffType, gen->typeArg, name ); el->inGetR = IN_GET_LIST_EL_MEM_R; el->inGetValR = IN_GET_LIST_EL_MEM_R; @@ -944,28 +944,22 @@ void Compiler::initListElField( GenericType *gen, const char *name, int offset ) // el->inSetWC = IN_SET_LIST2EL_MEM_WC; // el->inSetWV = IN_SET_LIST2EL_MEM_WV; - gen->objDef->rootScope->insertField( el->name, el ); - /* Zero for head, One for tail. */ el->offset = offset; -#endif + + gen->utArg->structEl->context->objectDef->rootScope->insertField( el->name, el ); + } void Compiler::initListElFields( GenericType *gen ) { - initListElField( gen, "next", 0 ); - initListElField( gen, "value", 2 ); + initListElField( gen, "prev", 0 ); + initListElField( gen, "next", 1 ); } void Compiler::initListField( GenericType *gen, const char *name, int offset ) { -// /* Type reference for the list element. */ -// TypeRef *typeRef = TypeRef::cons( -// internal, TypeRef::ListEl, 0, gen->typeArg, 0 ); -// -// typeRef->resolveType( this ); - /* Make the type ref and create the field. */ ObjectField *el = ObjectField::cons( internal, ObjectField::InbuiltOffType, gen->typeArg, name ); diff --git a/src/parser.cc b/src/parser.cc index 896e26d1..9457dfe4 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -43,6 +43,7 @@ void BaseParser::listElDef( String name ) ObjectField *of = ObjectField::cons( InputLoc(), ObjectField::UserFieldType, elTr, name ); + structVarDef( InputLoc(), of ); } diff --git a/src/struct.c b/src/struct.c index ba224f2d..ae200329 100644 --- a/src/struct.c +++ b/src/struct.c @@ -109,12 +109,12 @@ void colm_list_destroy( Program *prg, Tree **sp, struct colm_struct *s ) struct colm_list *list = (struct colm_list*) s; ListEl *el = list->head; - while ( el != 0 ) { - ListEl *next = el->list_next; +// while ( el != 0 ) { +// ListEl *next = el->list_next; // treeDownref( prg, sp, el->value ); - //listElFree( prg, el ); - el = next; - } +// //listElFree( prg, el ); +// el = next; +// } } List *colm_list_new( struct colm_program *prg ) @@ -152,41 +152,49 @@ Map *colm_map_new( struct colm_program *prg ) return map; } -Tree *colm_list_get( List *list, Word field ) +struct colm_struct *colm_list_get( List *list, Word field ) { - Tree *result = 0; + ListEl *result = 0; switch ( field ) { case 0: - result = (Tree*)list->head; + result = list->head; break; case 1: - result = (Tree*)list->tail; + result = list->tail; break; default: assert( 0 ); break; } - return result; + + struct colm_struct *s = result != 0 ? + ((void*)result) - sizeof(Tree*) - sizeof(struct colm_struct) + : 0; + return s; } -Tree *colm_list_el_get( ListEl *listEl, Word field ) +struct colm_struct *colm_list_el_get( ListEl *listEl, Word field ) { - Tree *result = 0; + ListEl *result = 0; switch ( field ) { case 0: - result = (Tree*)listEl->list_prev; + result = listEl->list_prev; break; case 1: - result = (Tree*)listEl->list_next; + result = listEl->list_next; break; - case 2: +// case 2: // result = listEl->value; // treeUpref( result ); - break; -// default: -// assert( false ); // break; + default: + assert( 0 ); + break; } - return result; + + struct colm_struct *s = result != 0 ? + ((void*)result) - sizeof(Tree*) - sizeof(struct colm_struct) + : 0; + return s; } diff --git a/src/struct.h b/src/struct.h index 7aea468b..a573b7c5 100644 --- a/src/struct.h +++ b/src/struct.h @@ -125,14 +125,13 @@ struct colm_struct *colm_struct_inbuilt( struct colm_program *prg, int size, #define colm_struct_set_field_type( obj, type, field, val ) \ ((type*)(((struct colm_struct*)obj)+1))[field] = val - Parser *colm_parser_new( struct colm_program *prg, GenericInfo *gi ); Stream *colm_stream_new( struct colm_program *prg ); Stream *colm_stream_new2( struct colm_program *prg ); List *colm_list_new( struct colm_program *prg ); -Tree *colm_list_get( List *list, Word field ); -Tree *colm_list_el_get( ListEl *listEl, Word field ); +struct colm_struct *colm_list_get( List *list, Word field ); +struct colm_struct *colm_list_el_get( ListEl *listEl, Word field ); ListEl *colm_list_detach_head( List *list ); long colm_list_length( List *list ); |