diff options
-rw-r--r-- | src/bytecode.c | 36 | ||||
-rw-r--r-- | src/bytecode.h | 4 | ||||
-rw-r--r-- | src/compiler.h | 4 | ||||
-rw-r--r-- | src/declare.cc | 54 | ||||
-rw-r--r-- | src/input.c | 4 | ||||
-rw-r--r-- | src/stream.c | 2 | ||||
-rw-r--r-- | src/string.c | 6 |
7 files changed, 86 insertions, 24 deletions
diff --git a/src/bytecode.c b/src/bytecode.c index a0cfdfac..74d1a25f 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -3093,25 +3093,49 @@ again: colm_tree_downref( prg, sp, tree ); break; } - case IN_GET_TOKEN_POS_R: { - debug( prg, REALM_BYTECODE, "IN_GET_TOKEN_POS_R\n" ); + case IN_GET_TOKEN_FILE_R: { + debug( prg, REALM_BYTECODE, "IN_GET_TOKEN_FILE_R\n" ); + tree_t *tree = vm_pop_tree(); + tree_t *str = 0; + if ( tree->tokdata->location ) { + const char *fn = tree->tokdata->location->name; + head_t *data = string_alloc_full( prg, fn, strlen(fn) ); + str = construct_string( prg, data ); + colm_tree_upref( prg, str ); + } + vm_push_tree( str ); + colm_tree_downref( prg, sp, tree ); + break; + } + case IN_GET_TOKEN_LINE_R: { + debug( prg, REALM_BYTECODE, "IN_GET_TOKEN_LINE_R\n" ); tree_t *tree = vm_pop_tree(); value_t integer = 0; if ( tree->tokdata->location ) - integer = tree->tokdata->location->byte; + integer = tree->tokdata->location->line; vm_push_value( integer ); colm_tree_downref( prg, sp, tree ); break; } - case IN_GET_TOKEN_LINE_R: { - debug( prg, REALM_BYTECODE, "IN_GET_TOKEN_LINE_R\n" ); + case IN_GET_TOKEN_COL_R: { + debug( prg, REALM_BYTECODE, "IN_GET_TOKEN_COL_R\n" ); tree_t *tree = vm_pop_tree(); value_t integer = 0; if ( tree->tokdata->location ) - integer = tree->tokdata->location->line; + integer = tree->tokdata->location->column; + vm_push_value( integer ); + colm_tree_downref( prg, sp, tree ); + break; + } + case IN_GET_TOKEN_POS_R: { + debug( prg, REALM_BYTECODE, "IN_GET_TOKEN_POS_R\n" ); + tree_t *tree = vm_pop_tree(); + value_t integer = 0; + if ( tree->tokdata->location ) + integer = tree->tokdata->location->byte; vm_push_value( integer ); colm_tree_downref( prg, sp, tree ); break; diff --git a/src/bytecode.h b/src/bytecode.h index 5a37fdea..8793c909 100644 --- a/src/bytecode.h +++ b/src/bytecode.h @@ -142,8 +142,10 @@ typedef unsigned char uchar; #define IN_SET_TOKEN_DATA_WV 0x38 #define IN_SET_TOKEN_DATA_BKT 0x39 -#define IN_GET_TOKEN_POS_R 0x3a +#define IN_GET_TOKEN_FILE_R 0x80 #define IN_GET_TOKEN_LINE_R 0x3b +#define IN_GET_TOKEN_POS_R 0x3a +#define IN_GET_TOKEN_COL_R 0x81 #define IN_INIT_RHS_EL 0x3c #define IN_INIT_LHS_EL 0x3d diff --git a/src/compiler.h b/src/compiler.h index 46c33952..9ad38ee2 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -1012,8 +1012,10 @@ struct Compiler CodeVect unwindCode; ObjectField *makeDataEl(); - ObjectField *makePosEl(); + ObjectField *makeFileEl(); ObjectField *makeLineEl(); + ObjectField *makeColEl(); + ObjectField *makePosEl(); IterDef *findIterDef( IterDef::Type type, GenericType *generic ); IterDef *findIterDef( IterDef::Type type, Function *func ); diff --git a/src/declare.cc b/src/declare.cc index 6e92bdf0..d521e7c6 100644 --- a/src/declare.cc +++ b/src/declare.cc @@ -926,22 +926,22 @@ ObjectField *Compiler::makeDataEl() return el; } -ObjectField *Compiler::makePosEl() +ObjectField *Compiler::makeFileEl() { - /* Create the "data" field. */ - TypeRef *typeRef = TypeRef::cons( internal, uniqueTypeInt ); + /* Create the "file" field. */ + TypeRef *typeRef = TypeRef::cons( internal, uniqueTypeStr ); ObjectField *el = ObjectField::cons( internal, - ObjectField::InbuiltFieldType, typeRef, "pos" ); + ObjectField::InbuiltFieldType, typeRef, "file" ); el->isConst = true; - el->inGetR = IN_GET_TOKEN_POS_R; - el->inGetValR = IN_GET_TOKEN_POS_R; + el->inGetR = IN_GET_TOKEN_FILE_R; + el->inGetValR = IN_GET_TOKEN_FILE_R; return el; } ObjectField *Compiler::makeLineEl() { - /* Create the "data" field. */ + /* Create the "line" field. */ TypeRef *typeRef = TypeRef::cons( internal, uniqueTypeInt ); ObjectField *el = ObjectField::cons( internal, ObjectField::InbuiltFieldType, typeRef, "line" ); @@ -952,6 +952,32 @@ ObjectField *Compiler::makeLineEl() return el; } +ObjectField *Compiler::makeColEl() +{ + /* Create the "col" field. */ + TypeRef *typeRef = TypeRef::cons( internal, uniqueTypeInt ); + ObjectField *el = ObjectField::cons( internal, + ObjectField::InbuiltFieldType, typeRef, "col" ); + + el->isConst = true; + el->inGetR = IN_GET_TOKEN_COL_R; + el->inGetValR = IN_GET_TOKEN_COL_R; + return el; +} + +ObjectField *Compiler::makePosEl() +{ + /* Create the "data" field. */ + TypeRef *typeRef = TypeRef::cons( internal, uniqueTypeInt ); + ObjectField *el = ObjectField::cons( internal, + ObjectField::InbuiltFieldType, typeRef, "pos" ); + + el->isConst = true; + el->inGetR = IN_GET_TOKEN_POS_R; + el->inGetValR = IN_GET_TOKEN_POS_R; + return el; +} + /* Add a constant length field to the object. * Opcode supplied by the caller. */ void Compiler::addLengthField( ObjectDef *objDef, code_t getLength ) @@ -977,13 +1003,21 @@ void Compiler::declareTokenFields( ) ObjectField *dataEl = makeDataEl(); lel->objectDef->rootScope->insertField( dataEl->name, dataEl ); - /* Create the "pos" field. */ - ObjectField *posEl = makePosEl(); - lel->objectDef->rootScope->insertField( posEl->name, posEl ); + /* Create the "file" field. */ + ObjectField *fileEl = makeFileEl(); + lel->objectDef->rootScope->insertField( fileEl->name, fileEl ); /* Create the "line" field. */ ObjectField *lineEl = makeLineEl(); lel->objectDef->rootScope->insertField( lineEl->name, lineEl ); + + /* Create the "col" field. */ + ObjectField *colEl = makeColEl(); + lel->objectDef->rootScope->insertField( colEl->name, colEl ); + + /* Create the "pos" field. */ + ObjectField *posEl = makePosEl(); + lel->objectDef->rootScope->insertField( posEl->name, posEl ); } } } diff --git a/src/input.c b/src/input.c index 99e65ec5..a0b7a337 100644 --- a/src/input.c +++ b/src/input.c @@ -475,7 +475,7 @@ static void input_prepend_data( struct colm_program *prg, struct input_impl_seq maybe_split( prg, si ); - struct stream_impl *sub_si = colm_impl_new_text( "<text>", data, length ); + struct stream_impl *sub_si = colm_impl_new_text( "<text1>", data, length ); struct seq_buf *new_buf = new_seq_buf(); new_buf->type = SB_ACCUM; @@ -557,7 +557,7 @@ static void input_append_data( struct colm_program *prg, struct input_impl_seq * if ( si->queue.tail == 0 || si->queue.tail->type != SB_ACCUM ) { debug( prg, REALM_INPUT, "input_append_data: creating accum\n" ); - struct stream_impl *sub_si = colm_impl_new_accum( "<text>" ); + struct stream_impl *sub_si = colm_impl_new_accum( "<text2>" ); struct seq_buf *new_buf = new_seq_buf(); new_buf->type = SB_ACCUM; diff --git a/src/stream.c b/src/stream.c index ee939fff..6fb3901b 100644 --- a/src/stream.c +++ b/src/stream.c @@ -234,7 +234,7 @@ static struct stream_impl *data_split_consumed( program_t *prg, struct stream_im struct stream_impl *split_off = 0; if ( sid->consumed > 0 ) { debug( prg, REALM_INPUT, "maybe split: consumed is > 0, splitting\n" ); - split_off = colm_impl_consumed( "<text>", sid->consumed ); + split_off = colm_impl_consumed( "<text3>", sid->consumed ); sid->consumed = 0; } return split_off; diff --git a/src/string.c b/src/string.c index 6e0c7c38..8a852e8b 100644 --- a/src/string.c +++ b/src/string.c @@ -55,9 +55,9 @@ tree_t *construct_string( program_t *prg, head_t *s ) /* * In this system strings are not null terminated. Often strings come from a - * parse, in which case the string is just a pointer into the the data string. - * A block in a parsed stream can house many tokens and there is no room for - * nulls. + * parse, in which case the string is just a pointer into the the data stream. + * A block in a parsed stream can hold many tokens and there is no room + * allocated for nulls. */ head_t *string_copy( program_t *prg, head_t *head ) |