diff options
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/bytecode.c | 30 | ||||
-rw-r--r-- | src/bytecode.h | 2 | ||||
-rw-r--r-- | src/pdacodegen.cc | 59 | ||||
-rw-r--r-- | src/struct.h | 5 | ||||
-rw-r--r-- | src/synthesis.cc | 4 | ||||
-rw-r--r-- | src/tree.c | 1 |
7 files changed, 64 insertions, 39 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index ce8a1162..869ddc62 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -14,7 +14,7 @@ RUNTIME_SRC = \ RUNTIME_HDR = \ bytecode.h config.h defs.h debug.h pool.h input.h \ - pdarun.h map.h tree.h program.h colm.h + pdarun.h map.h tree.h struct.h program.h colm.h lib_LIBRARIES = libcolmp.a libcolmd.a diff --git a/src/bytecode.c b/src/bytecode.c index 293062dc..87d2b701 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -8,6 +8,7 @@ #include <colm/pool.h> #include <colm/debug.h> #include <colm/config.h> +#include <colm/struct.h> #include <alloca.h> #include <sys/mman.h> @@ -1552,11 +1553,22 @@ again: Tree *obj = vm_pop(); - Tree *val = ((Tree**)(((HeapItem*)obj)+1))[field]; + Tree *val = colm_struct_val( obj, field ); treeUpref( val ); vm_push( val ); break; } + case IN_GET_STRUCT_FIELD_VAL: { + short field; + read_half( field ); + + debug( prg, REALM_BYTECODE, "IN_GET_STRUCT_FIELD_VAL %d\n", field ); + + Tree *obj = vm_pop(); + Tree *val = colm_struct_val( obj, field ); + vm_push( val ); + break; + } case IN_GET_STRUCT_FIELD_WC: { short field; read_half( field ); @@ -1613,8 +1625,20 @@ again: Tree *val = vm_pop(); /* Downref the old value. */ - treeDownref( prg, sp, ((Tree**)(((HeapItem*)obj)+1))[field] ); - ((Tree**)(((HeapItem*)obj)+1))[field] = val; + treeDownref( prg, sp, colm_struct_val( obj, field ) ); + colm_struct_val( obj, field ) = val; + break; + } + case IN_SET_STRUCT_FIELD_VAL: { + short field; + read_half( field ); + + debug( prg, REALM_BYTECODE, "IN_SET_STRUCT_FIELD_VAL %d\n", field ); + + Tree *obj = vm_pop(); + Tree *val = vm_pop(); + + colm_struct_val( obj, field ) = val; break; } case IN_SET_STRUCT_FIELD_WV: { diff --git a/src/bytecode.h b/src/bytecode.h index c5c639b6..40724d20 100644 --- a/src/bytecode.h +++ b/src/bytecode.h @@ -326,6 +326,8 @@ typedef unsigned char uchar; #define IN_SET_STRUCT_FIELD_WC 0xfb #define IN_SET_STRUCT_FIELD_WV 0xfc #define IN_SET_STRUCT_FIELD_BKT 0xfd +#define IN_GET_STRUCT_FIELD_VAL 0x93 +#define IN_SET_STRUCT_FIELD_VAL 0x94 #define IN_NEW_STRUCT 0xfe #define IN_GET_LOCAL_VAL 0x91 diff --git a/src/pdacodegen.cc b/src/pdacodegen.cc index 21518079..5ac78e44 100644 --- a/src/pdacodegen.cc +++ b/src/pdacodegen.cc @@ -151,44 +151,33 @@ void PdaCodeGen::writeRuntimeData( RuntimeData *runtimeData, PdaTables *pdaTable */ out << "static LangElInfo " << lelInfo() << "[] = {\n"; for ( int i = 0; i < runtimeData->numLangEls; i++ ) { + LangElInfo *el = &runtimeData->lelInfo[i]; out << "\t{"; /* Name. */ out << " \""; - escapeLiteralString( out, runtimeData->lelInfo[i].name ); + escapeLiteralString( out, el->name ); out << "\", "; /* Name. */ out << " \""; - escapeLiteralString( out, runtimeData->lelInfo[i].xmlTag ); + escapeLiteralString( out, el->xmlTag ); out << "\", "; /* Repeat, literal, ignore flags. */ - out << (int)runtimeData->lelInfo[i].repeat << ", " << - (int)runtimeData->lelInfo[i].list << ", " << - (int)runtimeData->lelInfo[i].literal << ", " << - (int)runtimeData->lelInfo[i].ignore << ", "; - - out << runtimeData->lelInfo[i].frameId << ", "; - - out << runtimeData->lelInfo[i].objectTypeId << ", "; - - out << runtimeData->lelInfo[i].ofiOffset << ", "; - - out << runtimeData->lelInfo[i].objectLength << ", "; - -// out << runtimeData->lelInfo[i].contextTypeId << ", "; -// out << runtimeData->lelInfo[i].contextLength << ", "; - - out << runtimeData->lelInfo[i].termDupId << ", "; - - out << runtimeData->lelInfo[i].genericId << ", "; - - out << runtimeData->lelInfo[i].markId << ", "; - - out << runtimeData->lelInfo[i].captureAttr << ", "; - - out << runtimeData->lelInfo[i].numCaptureAttr; + out << (int)el->repeat << ", "; + out << (int)el->list << ", "; + out << (int)el->literal << ", "; + out << (int)el->ignore << ", "; + out << el->frameId << ", "; + out << el->objectTypeId << ", "; + out << el->ofiOffset << ", "; + out << el->objectLength << ", "; + out << el->termDupId << ", "; + out << el->genericId << ", "; + out << el->markId << ", "; + out << el->captureAttr << ", "; + out << el->numCaptureAttr; out << " }"; @@ -199,11 +188,12 @@ void PdaCodeGen::writeRuntimeData( RuntimeData *runtimeData, PdaTables *pdaTable for ( int i = 0; i < runtimeData->numStructEls; i++ ) { - if ( runtimeData->selInfo[i].treesLen > 0 ) { + StructElInfo *el = &runtimeData->selInfo[i]; + if ( el->treesLen > 0 ) { out << "static short struct_trees_" << i << "[] = {\n\t"; - short *ti = runtimeData->selInfo[i].trees; - for ( int j = 0; j < runtimeData->selInfo[i].treesLen; j++ ) + short *ti = el->trees; + for ( int j = 0; j < el->treesLen; j++ ) out << ti[j] << ", "; out << "\n};\n\n"; } @@ -214,17 +204,18 @@ void PdaCodeGen::writeRuntimeData( RuntimeData *runtimeData, PdaTables *pdaTable */ out << "static StructElInfo " << selInfo() << "[] = {\n"; for ( int i = 0; i < runtimeData->numStructEls; i++ ) { + StructElInfo *el = &runtimeData->selInfo[i]; out << "\t{ "; - out << runtimeData->selInfo[i].size << ", "; + out << el->size << ", "; /* trees. */ - if ( runtimeData->selInfo[i].treesLen > 0 ) + if ( el->treesLen > 0 ) out << "struct_trees_" << i << ", "; else out << "0, "; - out << runtimeData->selInfo[i].treesLen << ", "; + out << el->treesLen << ", "; - out << " }"; + out << " },\n"; } out << "\n};\n\n"; diff --git a/src/struct.h b/src/struct.h new file mode 100644 index 00000000..ddf2081e --- /dev/null +++ b/src/struct.h @@ -0,0 +1,5 @@ +#ifndef _COLM_STRUCT_H + +#define colm_struct_val(obj, field) ((Tree**)(((HeapItem*)obj)+1))[field] + +#endif diff --git a/src/synthesis.cc b/src/synthesis.cc index 16514c75..abda68be 100644 --- a/src/synthesis.cc +++ b/src/synthesis.cc @@ -2685,8 +2685,10 @@ void ObjectField::initField() inGetWV = IN_GET_STRUCT_FIELD_WV; inSetWC = IN_SET_STRUCT_FIELD_WC; inSetWV = IN_SET_STRUCT_FIELD_WV; - break; + inGetVal = IN_GET_STRUCT_FIELD_VAL; + inSetVal = IN_SET_STRUCT_FIELD_VAL; + break; case RhsNameType: inGetR = IN_GET_RHS_VAL_R; @@ -259,6 +259,7 @@ HeapItem *newStruct( Program *prg, int id ) size_t memsize = sizeof(HeapItem) + ( sizeof(Tree*) * structSize ); HeapItem *item = (HeapItem*) malloc( memsize ); memset( item, 0, memsize ); + item->id = id; if ( prg->heapHead == 0 ) { prg->heapHead = prg->heapTail = item; |