summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2014-12-20 12:07:22 -0500
committerAdrian Thurston <thurston@complang.org>2014-12-20 12:07:22 -0500
commit9153bb402e7f18df2c600a716021e004438aaf1e (patch)
tree07f0101a684424b80ea78790260d09fe43d167e9 /src
parent0b6d8c987f90868c6fc6ed1aa3346d6cd10201aa (diff)
downloadcolm-9153bb402e7f18df2c600a716021e004438aaf1e.tar.gz
added structElInfo to the runtime data
Storing size and can add trees offsets for downreffing on free.
Diffstat (limited to 'src')
-rw-r--r--src/bytecode.c6
-rw-r--r--src/compiler.cc1
-rw-r--r--src/compiler.h1
-rw-r--r--src/parsetree.h3
-rw-r--r--src/pdabuild.cc20
-rw-r--r--src/pdacodegen.cc14
-rw-r--r--src/pdacodegen.h1
-rw-r--r--src/pdarun.h5
-rw-r--r--src/program.h7
-rw-r--r--src/synthesis.cc2
-rw-r--r--src/tree.c21
-rw-r--r--src/tree.h2
12 files changed, 67 insertions, 16 deletions
diff --git a/src/bytecode.c b/src/bytecode.c
index 07636546..293062dc 100644
--- a/src/bytecode.c
+++ b/src/bytecode.c
@@ -1552,7 +1552,7 @@ again:
Tree *obj = vm_pop();
- Tree *val = ((Tree**)obj)[2+field];
+ Tree *val = ((Tree**)(((HeapItem*)obj)+1))[field];
treeUpref( val );
vm_push( val );
break;
@@ -1613,8 +1613,8 @@ again:
Tree *val = vm_pop();
/* Downref the old value. */
- treeDownref( prg, sp, ((Tree**)obj)[2+field] );
- ((Tree**)obj)[2+field] = val;
+ treeDownref( prg, sp, ((Tree**)(((HeapItem*)obj)+1))[field] );
+ ((Tree**)(((HeapItem*)obj)+1))[field] = val;
break;
}
case IN_SET_STRUCT_FIELD_WV: {
diff --git a/src/compiler.cc b/src/compiler.cc
index 2378f3dd..0894cbaa 100644
--- a/src/compiler.cc
+++ b/src/compiler.cc
@@ -1087,6 +1087,7 @@ void Compiler::prepGrammar()
wrapNonTerminals();
makeLangElIds();
+ makeStructElIds();
makeLangElNames();
makeDefinitionNames();
noUndefindLangEls();
diff --git a/src/compiler.h b/src/compiler.h
index 0bdc4042..7123c3db 100644
--- a/src/compiler.h
+++ b/src/compiler.h
@@ -634,6 +634,7 @@ struct Compiler
void noUndefindLangEls();
void declareBaseLangEls();
void makeLangElIds();
+ void makeStructElIds();
void makeLangElNames();
void makeTerminalWrappers();
void makeEofElements();
diff --git a/src/parsetree.h b/src/parsetree.h
index cf63a365..b8461896 100644
--- a/src/parsetree.h
+++ b/src/parsetree.h
@@ -572,11 +572,12 @@ struct ContextDefList : DList<ContextDef> {};
struct StructEl
{
StructEl( Namespace *nspace, const String &name )
- : nspace(nspace), name(name), context(0) {}
+ : nspace(nspace), name(name), context(0), id(-1) {}
Namespace *nspace;
String name;
Context *context;
+ int id;
StructEl *prev, *next;
};
diff --git a/src/pdabuild.cc b/src/pdabuild.cc
index f644d2e7..67bdd262 100644
--- a/src/pdabuild.cc
+++ b/src/pdabuild.cc
@@ -199,6 +199,13 @@ void Compiler::makeLangElIds()
assert( ignoreLangEl->id == LEL_ID_IGNORE );
}
+void Compiler::makeStructElIds()
+{
+ int nextId = 0;
+ for ( StructElList::Iter sel = structEls; sel.lte(); sel++ )
+ sel->id = nextId++;
+}
+
void Compiler::refNameSpace( LangEl *lel, Namespace *nspace )
{
if ( nspace == rootNamespace ) {
@@ -1446,6 +1453,19 @@ void Compiler::makeRuntimeData()
}
/*
+ * selInfo
+ */
+
+ count = structEls.length();
+ runtimeData->selInfo = new StructElInfo[count];
+ runtimeData->numStructEls = count;
+ memset( runtimeData->selInfo, 0, sizeof(StructElInfo)*count );
+ StructElList::Iter sel = structEls;
+ for ( int i = 0; i < count; i++, sel++ ) {
+ runtimeData->selInfo[i].size = sel->context->objectDef->size();
+ }
+
+ /*
* FunctionInfo
*/
count = functionList.length();
diff --git a/src/pdacodegen.cc b/src/pdacodegen.cc
index c41f4012..96b1df1a 100644
--- a/src/pdacodegen.cc
+++ b/src/pdacodegen.cc
@@ -198,6 +198,17 @@ void PdaCodeGen::writeRuntimeData( RuntimeData *runtimeData, PdaTables *pdaTable
out << "\n};\n\n";
/*
+ * selInfo
+ */
+ out << "static StructElInfo " << selInfo() << "[] = {\n";
+ for ( int i = 0; i < runtimeData->numStructEls; i++ ) {
+ out << "\t{ ";
+ out << runtimeData->selInfo[i].size << ", ";
+ out << " }";
+ }
+ out << "\n};\n\n";
+
+ /*
* frameInfo
*/
out << "static FrameInfo " << frameInfo() << "[] = {\n";
@@ -410,6 +421,9 @@ void PdaCodeGen::writeRuntimeData( RuntimeData *runtimeData, PdaTables *pdaTable
" " << lelInfo() << ",\n"
" " << runtimeData->numLangEls << ",\n"
"\n"
+ " " << selInfo() << ",\n"
+ " " << runtimeData->numStructEls << ",\n"
+ "\n"
" " << prodInfo() << ",\n"
" " << runtimeData->numProds << ",\n"
"\n"
diff --git a/src/pdacodegen.h b/src/pdacodegen.h
index abe67aee..89a7d8db 100644
--- a/src/pdacodegen.h
+++ b/src/pdacodegen.h
@@ -46,6 +46,7 @@ struct PdaCodeGen
String prodLhsIds() { return PARSER() + "prodLhsIds"; }
String prodNames() { return PARSER() + "prodNames"; }
String lelInfo() { return PARSER() + "lelInfo"; }
+ String selInfo() { return PARSER() + "selInfo"; }
String prodInfo() { return PARSER() + "prodInfo"; }
String tokenRegionInds() { return PARSER() + "tokenRegionInds"; }
String tokenRegions() { return PARSER() + "tokenRegions"; }
diff --git a/src/pdarun.h b/src/pdarun.h
index 4a262cff..7f7aa39b 100644
--- a/src/pdarun.h
+++ b/src/pdarun.h
@@ -164,6 +164,11 @@ typedef struct _LangElInfo
long numCaptureAttr;
} LangElInfo;
+typedef struct _StructElInfo
+{
+ long size;
+} StructElInfo;
+
typedef struct _ObjFieldInfo
{
int typeId;
diff --git a/src/program.h b/src/program.h
index 130a6532..4e119ca4 100644
--- a/src/program.h
+++ b/src/program.h
@@ -20,6 +20,9 @@ typedef struct colm_sections
LangElInfo *lelInfo;
long numLangEls;
+ StructElInfo *selInfo;
+ long numStructEls;
+
ProdInfo *prodInfo;
long numProds;
@@ -82,7 +85,9 @@ typedef struct colm_sections
typedef struct colm_heap_item
{
- struct colm_heap_item *prev, *next;
+ short id;
+ struct colm_heap_item *prev;
+ struct colm_heap_item *next;
} HeapItem;
typedef struct colm_program
diff --git a/src/synthesis.cc b/src/synthesis.cc
index aac9f5e7..16514c75 100644
--- a/src/synthesis.cc
+++ b/src/synthesis.cc
@@ -1066,7 +1066,7 @@ UniqueType *LangTerm::evaluateNew2( Compiler *pd, CodeVect &code ) const
error(loc) << "can only new2 a struct" << endp;
code.append( IN_NEW_STRUCT );
- code.appendHalf( replUT->structEl->context->objectDef->size() );
+ code.appendHalf( replUT->structEl->id );
return replUT;
}
diff --git a/src/tree.c b/src/tree.c
index 5984a204..754d810a 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -253,22 +253,25 @@ Tree *constructPointer( Program *prg, Tree *tree )
return (Tree*)pointer;
}
-HeapItem *newStruct( Program *prg, int size )
+HeapItem *newStruct( Program *prg, int id )
{
- HeapItem *hi = (HeapItem*) malloc( sizeof(Tree*) * ( 2 + size ) );
+ int structSize = prg->rtd->selInfo[id].size;
+ size_t memsize = sizeof(HeapItem) + ( sizeof(Tree*) * structSize );
+ HeapItem *item = (HeapItem*) malloc( memsize );
+ memset( item, 0, memsize );
if ( prg->heapHead == 0 ) {
- prg->heapHead = prg->heapTail = hi;
- hi->prev = hi->next = 0;
+ prg->heapHead = prg->heapTail = item;
+ item->prev = item->next = 0;
}
else {
- hi->prev = prg->heapTail;
- hi->next = 0;
- prg->heapTail->next = hi;
- prg->heapTail = hi;
+ item->prev = prg->heapTail;
+ item->next = 0;
+ prg->heapTail->next = item;
+ prg->heapTail = item;
}
- return hi;
+ return item;
}
Tree *constructTerm( Program *prg, Word id, Head *tokdata )
diff --git a/src/tree.h b/src/tree.h
index 4f6447ab..424dd256 100644
--- a/src/tree.h
+++ b/src/tree.h
@@ -360,7 +360,7 @@ void userIterDestroy2( struct colm_program *prg, Tree ***psp, UserIter *uiter );
Tree *castTree( struct colm_program *prg, int langElId, Tree *tree );
StreamImpl *streamToImpl( Stream *ptr );
-struct colm_heap_item *newStruct( struct colm_program *prg, int size );
+struct colm_heap_item *newStruct( struct colm_program *prg, int id );
#if defined(__cplusplus)
}