diff options
author | Adrian Thurston <thurston@complang.org> | 2015-04-05 12:15:40 -0400 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2015-04-05 12:15:40 -0400 |
commit | 54a7d0ec8bed21f2a9dfd8c3fc6631a48122fda3 (patch) | |
tree | 59d590588290c700e223ae55792b1afc1ed19ac2 | |
parent | c8b421d4412cf96f2408b63cc7a5497884e5e672 (diff) | |
download | colm-54a7d0ec8bed21f2a9dfd8c3fc6631a48122fda3.tar.gz |
warning elim, and impl of vlist files _R only
-rw-r--r-- | src/bytecode.c | 180 | ||||
-rw-r--r-- | src/bytecode.h | 17 | ||||
-rw-r--r-- | src/compiler.h | 2 | ||||
-rw-r--r-- | src/declare.cc | 31 | ||||
-rw-r--r-- | src/tree.h | 1 |
5 files changed, 156 insertions, 75 deletions
diff --git a/src/bytecode.c b/src/bytecode.c index a143e54e..f0eab2cc 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -33,6 +33,7 @@ #include <assert.h> #include <stdlib.h> #include <unistd.h> +#include <signal.h> typedef struct colm_struct Struct; @@ -76,19 +77,21 @@ Tree **host_call( Program *prg, long code, Tree **sp ); i |= ((Type) p[3]) << 24; \ } while(0) + #define consume_word() instr += 4 + #else #define read_type( type, i ) do { \ - Word w; \ - w = ((Word) *instr++); \ - w |= ((Word) *instr++) << 8; \ - w |= ((Word) *instr++) << 16; \ - w |= ((Word) *instr++) << 24; \ - w |= ((Word) *instr++) << 32; \ - w |= ((Word) *instr++) << 40; \ - w |= ((Word) *instr++) << 48; \ - w |= ((Word) *instr++) << 56; \ - i = (type) w; \ + Word _w; \ + _w = ((Word) *instr++); \ + _w |= ((Word) *instr++) << 8; \ + _w |= ((Word) *instr++) << 16; \ + _w |= ((Word) *instr++) << 24; \ + _w |= ((Word) *instr++) << 32; \ + _w |= ((Word) *instr++) << 40; \ + _w |= ((Word) *instr++) << 48; \ + _w |= ((Word) *instr++) << 56; \ + i = (type) _w; \ } while(0) #define read_type_p( type, i, p ) do { \ @@ -101,6 +104,8 @@ Tree **host_call( Program *prg, long code, Tree **sp ); i |= ((type) p[6]) << 48; \ i |= ((type) p[7]) << 56; \ } while(0) + + #define consume_word() instr += 8 #endif #define read_tree( i ) read_type( Tree*, i ) @@ -110,6 +115,9 @@ Tree **host_call( Program *prg, long code, Tree **sp ); #define read_word_p( i, p ) read_type_p( Word, i, p ) +#define consume_byte() instr += 1 +#define consume_half() instr += 2 + static void rcode_downref( Program *prg, Tree **sp, Code *instr ); void colm_parser_set_context( Program *prg, Tree **sp, Parser *parser, Struct *val ) @@ -827,8 +835,7 @@ again: } case IN_INIT_CAPTURES: { - uchar ncaps; - read_byte(ncaps); + consume_byte(); debug( prg, REALM_BYTECODE, "IN_INIT_CAPTURES\n" ); @@ -2271,7 +2278,7 @@ again: case IN_GET_ERROR: { debug( prg, REALM_BYTECODE, "IN_GET_ERROR\n" ); - Tree *obj = vm_pop_tree(); + vm_pop_tree(); treeUpref( prg->error ); vm_push_tree( prg->error ); break; @@ -2482,8 +2489,6 @@ again: case IN_PARSE_FRAG_EXIT_BKT: { debug( prg, REALM_BYTECODE, "IN_PARSE_FRAG_EXIT_BKT\n" ); - Parser *parser = exec->parser; - exec->steps = vm_pop_type(long); exec->pcr = vm_pop_type(long); exec->parser = vm_pop_parser(); @@ -2738,8 +2743,8 @@ again: debug( prg, REALM_BYTECODE, "IN_CONSTRUCT\n" ); - LangElInfo *lelInfo = prg->rtd->lelInfo; - PatConsNode *nodes = prg->rtd->patReplNodes; + //LangElInfo *lelInfo = prg->rtd->lelInfo; + //PatConsNode *nodes = prg->rtd->patReplNodes; int rootNode = prg->rtd->patReplInfo[patternId].offset; /* Note that bindIds are indexed at one. Add one spot for them. */ @@ -3131,6 +3136,67 @@ again: vm_push_tree( res ); break; } + case IN_GET_VLIST_MEM_R: { + short genId, field; + read_half( genId ); + read_half( field ); + + debug( prg, REALM_BYTECODE, + "IN_GET_VLIST_MEM_R %hd %hd\n", genId, field ); + + List *list = vm_pop_list(); + Struct *el = colm_list_get( prg, list, genId, field ); + + Value val = colm_struct_get_field( el, Value, 0 ); + vm_push_value( val ); + break; + } + case IN_GET_VLIST_MEM_WC: { + short field; + read_half( field ); + + debug( prg, REALM_BYTECODE, "IN_GET_VLIST_MEM_WC\n" ); + + Tree *obj = vm_pop_tree(); + treeDownref( prg, sp, obj ); + + Tree *val = getListMemSplit( prg, (List*)obj, field ); + treeUpref( val ); + vm_push_tree( val ); + break; + } + case IN_GET_VLIST_MEM_WV: { + short field; + read_half( field ); + + debug( prg, REALM_BYTECODE, "IN_GET_VLIST_MEM_WV\n" ); + + Tree *obj = vm_pop_tree(); + treeDownref( prg, sp, obj ); + + Tree *val = getListMemSplit( prg, (List*)obj, field ); + treeUpref( val ); + vm_push_tree( val ); + + /* Set up the reverse instruction. */ + rcode_code( exec, IN_GET_LIST_MEM_BKT ); + rcodeHalf( exec, field ); + break; + } + case IN_GET_VLIST_MEM_BKT: { + short field; + read_half( field ); + + debug( prg, REALM_BYTECODE, "IN_GET_VLIST_MEM_BKT\n" ); + + Tree *obj = vm_pop_tree(); + treeDownref( prg, sp, obj ); + + Tree *res = getListMemSplit( prg, (List*)obj, field ); + treeUpref( res ); + vm_push_tree( res ); + break; + } case IN_GET_PARSER_MEM_R: { short field; read_half( field ); @@ -3505,7 +3571,7 @@ again: debug( prg, REALM_BYTECODE, "IN_GET_STDIN\n" ); /* Pop the root object. */ - Tree *obj = vm_pop_tree(); + vm_pop_tree(); if ( prg->stdinVal == 0 ) prg->stdinVal = colm_stream_open_fd( prg, "<stdin>", 0 ); @@ -3516,7 +3582,7 @@ again: debug( prg, REALM_BYTECODE, "IN_GET_STDOUT\n" ); /* Pop the root object. */ - Tree *obj = vm_pop_tree(); + vm_pop_tree(); if ( prg->stdoutVal == 0 ) prg->stdoutVal = colm_stream_open_fd( prg, "<stdout>", 1 ); @@ -3527,7 +3593,7 @@ again: debug( prg, REALM_BYTECODE, "IN_GET_STDERR\n" ); /* Pop the root object. */ - Tree *obj = vm_pop_tree(); + vm_pop_tree(); if ( prg->stderrVal == 0 ) prg->stderrVal = colm_stream_open_fd( prg, "<stderr>", 2 ); @@ -4109,7 +4175,7 @@ again: case IN_EXIT_HARD: { debug( prg, REALM_BYTECODE, "IN_EXIT\n" ); - Tree *global = vm_pop_tree(); + vm_pop_tree(); prg->exitStatus = vm_pop_type(long); prg->induceExit = 1; exit( prg->exitStatus ); @@ -4117,7 +4183,7 @@ again: case IN_EXIT: { debug( prg, REALM_BYTECODE, "IN_EXIT\n" ); - Tree *global = vm_pop_tree(); + vm_pop_tree(); prg->exitStatus = vm_pop_type(long); prg->induceExit = 1; @@ -4198,29 +4264,24 @@ again: break; } case IN_PARSE_INIT_BKT: { - Parser *parser; - Word pcr; - Word steps; - debug( prg, REALM_BYTECODE, "IN_PARSE_INIT_BKT\n" ); - read_parser( parser ); - read_word( pcr ); - read_word( steps ); + consume_word(); //( parser ); + consume_word(); //( pcr ); + consume_word(); //( steps ); break; } case IN_LOAD_TREE: { - Word w; - read_word( w ); - debug( prg, REALM_BYTECODE, "IN_LOAD_TREE %p\n", (Tree*)w ); - treeDownref( prg, sp, (Tree*)w ); + Tree *w; + read_tree( w ); + debug( prg, REALM_BYTECODE, "IN_LOAD_TREE %p\n", w ); + treeDownref( prg, sp, w ); break; } case IN_LOAD_WORD: { - Word w; - read_word( w ); + consume_word(); debug( prg, REALM_BYTECODE, "IN_LOAD_WORD\n" ); break; } @@ -4265,26 +4326,20 @@ again: return; } case IN_PARSE_APPEND_BKT: { - Parser *parser; - Tree *input; - Word len; - - read_parser( parser ); - read_tree( input ); - read_word( len ); + consume_word(); //( parser ); + consume_word(); //( input ); + consume_word(); //( len ); debug( prg, REALM_BYTECODE, "IN_PARSE_APPEND_BKT\n" ); break; } case IN_PARSE_APPEND_STREAM_BKT: { - Tree *sptr; Tree *input; - Word len; - read_tree( sptr ); + consume_word(); //( sptr ); read_tree( input ); - read_word( len ); + consume_word(); //( len ); debug( prg, REALM_BYTECODE, "IN_PARSE_APPEND_STREAM_BKT\n" ); @@ -4302,8 +4357,7 @@ again: break; } case IN_INPUT_PUSH_BKT: { - Word len; - read_word( len ); + consume_word(); //( len ); debug( prg, REALM_BYTECODE, "IN_INPUT_PUSH_BKT\n" ); break; @@ -4317,8 +4371,7 @@ again: break; } case IN_LOAD_INPUT_BKT: { - Stream *input; - read_stream( input ); + consume_word(); //( input ); debug( prg, REALM_BYTECODE, "IN_LOAD_INPUT_BKT\n" ); break; } @@ -4352,17 +4405,14 @@ again: break; } case IN_SET_STRUCT_VAL_BKT: { - short field; - Tree *val; - read_half( field ); - read_tree( val ); + consume_half(); //( field ); + consume_word(); //( val ); debug( prg, REALM_BYTECODE, "IN_SET_STRUCT_VAL_BKT\n" ); break; } case IN_PTR_ACCESS_BKT: { - Tree *ptr; - read_tree( ptr ); + consume_word(); //( ptr ); debug( prg, REALM_BYTECODE, "IN_PTR_ACCESS_BKT\n" ); break; @@ -4401,10 +4451,8 @@ again: break; } case IN_LIST_POP_HEAD_BKT: { - short genId; - Tree *val; - read_half( genId ); - read_tree( val ); + consume_half(); //( genId ); + consume_word(); //( val ); debug( prg, REALM_BYTECODE, "IN_LIST_POP_HEAD_BKT\n" ); @@ -4415,23 +4463,19 @@ again: break; } case IN_LIST_POP_TAIL_BKT: { - short genId; - Tree *val; - read_half( genId ); - read_tree( val ); + consume_half(); //( genId ); + consume_word(); //( val ); debug( prg, REALM_BYTECODE, "IN_LIST_POP_TAIL_BKT\n" ); break; } case IN_MAP_INSERT_BKT: { - short genId; uchar inserted; - Word wmapEl; - read_half( genId ); + consume_half(); //( genId ); read_byte( inserted ); - read_word( wmapEl ); + consume_word(); //( wmapEl ); debug( prg, REALM_BYTECODE, "IN_MAP_INSERT_BKT %d\n", (int)inserted ); diff --git a/src/bytecode.h b/src/bytecode.h index 9474b432..34bca5af 100644 --- a/src/bytecode.h +++ b/src/bytecode.h @@ -74,10 +74,6 @@ typedef unsigned long colm_value_t; #define IN_TST_NZ_TREE 0xd1 -// 0xeb -// 0xec -// 0xd4 -// 0x5c #define IN_LOAD_RETVAL 0xd4 @@ -209,6 +205,19 @@ typedef unsigned long colm_value_t; #define IN_GET_LIST_MEM_WV 0x7b #define IN_GET_LIST_MEM_BKT 0x7c +#define IN_GET_VLIST_MEM_R 0xeb +#define IN_GET_VLIST_MEM_WC 0xec +#define IN_GET_VLIST_MEM_WV 0x70 +#define IN_GET_VLIST_MEM_BKT 0x5c + +// 0x71 +// 0x73 +// 0x74 +// 0x75 +// 0x76 +// 0x77 +// 0x78 + #define IN_GET_LIST_EL_MEM_R 0xf5 #define IN_GET_MAP_MEM_R 0x6d diff --git a/src/compiler.h b/src/compiler.h index 13eb6e7d..4ad67e79 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -768,8 +768,10 @@ struct Compiler void initListFunctions( GenericType *gen ); void initListElFields( GenericType *gen ); + void initValueListField( GenericType *gen, const char *name, int offset ); void initValueListFields( GenericType *gen ); void initValueListFunctions( GenericType *gen ); + void initValueMapFunctions( GenericType *gen ); void initValueMapFields( GenericType *gen ); diff --git a/src/declare.cc b/src/declare.cc index 676631d3..7f38a643 100644 --- a/src/declare.cc +++ b/src/declare.cc @@ -1302,11 +1302,36 @@ void Compiler::initListFields( GenericType *gen ) initListField( gen, "top", 0 ); } +void Compiler::initValueListField( GenericType *gen, const char *name, int offset ) +{ + /* Make the type ref and create the field. */ + ObjectField *el = ObjectField::cons( internal, + ObjectField::InbuiltOffType, gen->valueTr, name ); + + el->inGetR = IN_GET_VLIST_MEM_R; + el->inGetWC = IN_GET_VLIST_MEM_WC; + el->inGetWV = IN_GET_VLIST_MEM_WV; +// el->inSetWC = IN_SET_VLIST_MEM_WC; +// el->inSetWV = IN_SET_VLIST_MEM_WV; + + el->inGetValR = IN_GET_VLIST_MEM_R; + el->inGetValWC = IN_GET_VLIST_MEM_WC; + el->inGetValWV = IN_GET_VLIST_MEM_WV; + + gen->objDef->rootScope->insertField( el->name, el ); + + el->useGenericId = true; + el->generic = gen; + + /* Zero for head, One for tail. */ + el->offset = offset; +} + void Compiler::initValueListFields( GenericType *gen ) { - initListField( gen, "head", 0 ); - initListField( gen, "tail", 1 ); - initListField( gen, "top", 0 ); + initValueListField( gen, "head", 0 ); + initValueListField( gen, "tail", 1 ); + initValueListField( gen, "top", 0 ); } void Compiler::initParserFunctions( GenericType *gen ) @@ -348,6 +348,7 @@ void colm_list_iter_destroy( struct colm_program *prg, Tree ***psp, GenericIter Tree *colm_list_iter_advance( struct colm_program *prg, Tree ***psp, GenericIter *iter ); Tree *colm_list_iter_deref_cur( struct colm_program *prg, GenericIter *iter ); void colm_list_append( struct colm_list *list, struct colm_list_el *newEl ); +void colm_list_prepend( struct colm_list *list, struct colm_list_el *newEl ); void colm_vlist_append( struct colm_program *prg, List *list, Value value ); void colm_vlist_prepend( struct colm_program *prg, List *list, Value value ); |