summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2015-01-04 09:32:08 -0500
committerAdrian Thurston <thurston@complang.org>2015-01-04 09:32:08 -0500
commit650b70f4a55af12ee1ebb22a9afdd9fba7a3b626 (patch)
tree6bdcebe0091aed9936964cf37b4670ba21a7ef3c /src
parente682fbd4a5f83142ada2aa92d7a642035c010348 (diff)
downloadcolm-650b70f4a55af12ee1ebb22a9afdd9fba7a3b626.tar.gz
no longer allocating a langEl to generics
enerics are now structs. Also added the TYPE_GERERIC unique type.
Diffstat (limited to 'src')
-rw-r--r--src/bytecode.c18
-rw-r--r--src/bytecode.h1
-rw-r--r--src/compiler.cc24
-rw-r--r--src/compiler.h1
-rw-r--r--src/declare.cc44
-rw-r--r--src/lookup.cc3
-rw-r--r--src/parsetree.cc6
-rw-r--r--src/parsetree.h24
-rw-r--r--src/pdabuild.cc34
-rw-r--r--src/resolve.cc10
-rw-r--r--src/synthesis.cc23
11 files changed, 114 insertions, 74 deletions
diff --git a/src/bytecode.c b/src/bytecode.c
index 8d24fd7b..b561b306 100644
--- a/src/bytecode.c
+++ b/src/bytecode.c
@@ -1312,7 +1312,6 @@ again:
debug( prg, REALM_BYTECODE, "IN_GET_STRUCT_R %d\n", field );
Tree *obj = vm_pop();
-
Tree *val = colm_struct_get_field( obj, field );
treeUpref( val );
vm_push( val );
@@ -1325,11 +1324,10 @@ again:
debug( prg, REALM_BYTECODE, "IN_GET_STRUCT_WC %d\n", field );
Tree *obj = vm_pop();
- treeDownref( prg, sp, obj );
+ Tree *val = colm_struct_get_field( obj, field );
+ treeUpref( val );
+ vm_push( val );
- Tree *split = getFieldSplit( prg, obj, field );
- treeUpref( split );
- vm_push( split );
break;
}
case IN_GET_STRUCT_WV: {
@@ -1339,14 +1337,12 @@ again:
debug( prg, REALM_BYTECODE, "IN_GET_STRUCT_WV\n" );
Tree *obj = vm_pop();
- treeDownref( prg, sp, obj );
-
- Tree *split = getFieldSplit( prg, obj, field );
- treeUpref( split );
- vm_push( split );
+ Tree *val = colm_struct_get_field( obj, field );
+ treeUpref( val );
+ vm_push( val );
/* Set up the reverse instruction. */
- rcodeCode( exec, IN_GET_FIELD_BKT );
+ rcodeCode( exec, IN_GET_STRUCT_BKT );
rcodeHalf( exec, field );
break;
}
diff --git a/src/bytecode.h b/src/bytecode.h
index f4be8826..64091880 100644
--- a/src/bytecode.h
+++ b/src/bytecode.h
@@ -362,6 +362,7 @@ enum TYPE
TYPE_PTR = 0x04,
TYPE_ITER = 0x05,
TYPE_STRUCT = 0x06,
+ TYPE_GENERIC = 0x07,
};
/* Types of Generics. */
diff --git a/src/compiler.cc b/src/compiler.cc
index 5b17a56c..aff10b6a 100644
--- a/src/compiler.cc
+++ b/src/compiler.cc
@@ -1007,8 +1007,10 @@ void Compiler::parsePatterns()
Tree **sp = prg->stackRoot;
for ( ConsList::Iter cons = replList; cons.lte(); cons++ ) {
- StreamImpl *in = newSourceStreamCons( "<internal>", cons );
- cons->pdaRun = parsePattern( prg, sp, cons->loc, cons->langEl->parserId, in );
+ if ( cons->langEl != 0 ) {
+ StreamImpl *in = newSourceStreamCons( "<internal>", cons );
+ cons->pdaRun = parsePattern( prg, sp, cons->loc, cons->langEl->parserId, in );
+ }
}
for ( PatList::Iter pat = patternList; pat.lte(); pat++ ) {
@@ -1040,14 +1042,16 @@ void Compiler::collectParserEls( BstSet<LangEl*> &parserEls )
}
for ( ConsList::Iter repl = replList; repl.lte(); repl++ ) {
- /* We assume the reduction action compilation phase was run before
- * replacement parsing decorated the replacement with the target type. */
- assert( repl->langEl != 0 );
-
- if ( repl->langEl->parserId < 0 ) {
- /* Make a parser for the language element. */
- parserEls.insert( repl->langEl );
- repl->langEl->parserId = nextParserId++;
+ /* FIXME: should be able to remove this test. */
+ if ( repl->langEl != 0 ) {
+ /* We need the the language element from the compilation process. */
+ assert( repl->langEl != 0 );
+
+ if ( repl->langEl->parserId < 0 ) {
+ /* Make a parser for the language element. */
+ parserEls.insert( repl->langEl );
+ repl->langEl->parserId = nextParserId++;
+ }
}
}
diff --git a/src/compiler.h b/src/compiler.h
index 5b2723c5..cd539c44 100644
--- a/src/compiler.h
+++ b/src/compiler.h
@@ -886,6 +886,7 @@ struct Compiler
UniqueType *findUniqueType( enum TYPE typeId, LangEl *langEl );
UniqueType *findUniqueType( enum TYPE typeId, IterDef *iterDef );
UniqueType *findUniqueType( enum TYPE typeId, StructEl *structEl );
+ UniqueType *findUniqueType( enum TYPE typeId, GenericType *generic );
UniqueType *uniqueTypeNil;
UniqueType *uniqueTypeVoid;
diff --git a/src/declare.cc b/src/declare.cc
index 2a7077f4..d93a2e64 100644
--- a/src/declare.cc
+++ b/src/declare.cc
@@ -284,27 +284,27 @@ void GenericType::declare( Compiler *pd, Namespace *nspace )
{
//std::cout << "generic " << g->name << std::endl;
- LangEl *langEl = declareLangEl( pd, nspace, name, LangEl::NonTerm );
-
- /* Add one empty production. */
- ProdElList *emptyList = new ProdElList;
- //addProduction( g->loc, langEl, emptyList, false, 0, 0 );
-
- {
- LangEl *prodName = langEl;
- assert( prodName->type == LangEl::NonTerm );
-
- Production *newDef = Production::cons( InputLoc(), prodName,
- emptyList, String(), false, 0,
- pd->prodList.length(), prodName->defList.length() );
-
- prodName->defList.append( newDef );
- pd->prodList.append( newDef );
- newDef->predOf = 0;
- }
-
- langEl->generic = this;
- this->langEl = langEl;
+// LangEl *langEl = declareLangEl( pd, nspace, name, LangEl::NonTerm );
+
+// /* Add one empty production. */
+// ProdElList *emptyList = new ProdElList;
+// //addProduction( g->loc, langEl, emptyList, false, 0, 0 );
+//
+// {
+// LangEl *prodName = langEl;
+// assert( prodName->type == LangEl::NonTerm );
+//
+// Production *newDef = Production::cons( InputLoc(), prodName,
+// emptyList, String(), false, 0,
+// pd->prodList.length(), prodName->defList.length() );
+//
+// prodName->defList.append( newDef );
+// pd->prodList.append( newDef );
+// newDef->predOf = 0;
+// }
+//
+// langEl->generic = this;
+// this->langEl = langEl;
utArg = typeArg->uniqueType;
@@ -334,7 +334,7 @@ void GenericType::declare( Compiler *pd, Namespace *nspace )
break;
}
- langEl->objectDef = objDef;
+// langEl->objectDef = objDef;
}
void Namespace::declare( Compiler *pd )
diff --git a/src/lookup.cc b/src/lookup.cc
index 354f497d..2ee88784 100644
--- a/src/lookup.cc
+++ b/src/lookup.cc
@@ -20,6 +20,9 @@ ObjectDef *UniqueType::objectDef()
else if ( typeId == TYPE_STRUCT ) {
return structEl->context->objectDef;
}
+ else if ( typeId == TYPE_GENERIC ) {
+ return generic->objDef;
+ }
/* This should have generated a compiler error. */
assert( false );
diff --git a/src/parsetree.cc b/src/parsetree.cc
index d514ea47..0a131b62 100644
--- a/src/parsetree.cc
+++ b/src/parsetree.cc
@@ -113,6 +113,12 @@ int CmpUniqueType::compare( const UniqueType &ut1, const UniqueType &ut2 )
else if ( ut1.structEl > ut2.structEl )
return 1;
break;
+ case TYPE_GENERIC:
+ if ( ut1.generic < ut2.generic )
+ return -1;
+ else if ( ut1.generic > ut2.generic )
+ return 1;
+ break;
}
return 0;
diff --git a/src/parsetree.h b/src/parsetree.h
index b03722fd..9a3c7f2e 100644
--- a/src/parsetree.h
+++ b/src/parsetree.h
@@ -710,7 +710,7 @@ struct GenericType
GenericType( const String &name, long typeId, long id,
TypeRef *typeArg )
:
- name(name), typeId(typeId), id(id), langEl(0),
+ name(name), typeId(typeId), id(id), /*langEl(0),*/
typeArg(typeArg), keyTypeArg(0),
utArg(0), keyUT(0), objDef(0), elOffset(0)
{}
@@ -723,7 +723,6 @@ struct GenericType
String name;
long typeId;
long id;
- LangEl *langEl;
TypeRef *typeArg;
TypeRef *keyTypeArg;
UniqueType *utArg;
@@ -1803,34 +1802,47 @@ struct UniqueType : public AvlTreeEl<UniqueType>
typeId(typeId),
langEl(0),
iterDef(0),
- structEl(0)
+ structEl(0),
+ generic(0)
{}
UniqueType( enum TYPE typeId, LangEl *langEl ) :
typeId(typeId),
langEl(langEl),
iterDef(0),
- structEl(0)
+ structEl(0),
+ generic(0)
{}
UniqueType( enum TYPE typeId, IterDef *iterDef ) :
typeId(typeId),
langEl(0),
iterDef(iterDef),
- structEl(0)
+ structEl(0),
+ generic(0)
{}
UniqueType( enum TYPE typeId, StructEl *structEl ) :
typeId(typeId),
langEl(0),
iterDef(0),
- structEl(structEl)
+ structEl(structEl),
+ generic(0)
+ {}
+
+ UniqueType( enum TYPE typeId, GenericType *generic ) :
+ typeId(typeId),
+ langEl(0),
+ iterDef(0),
+ structEl(0),
+ generic(generic)
{}
enum TYPE typeId;
LangEl *langEl;
IterDef *iterDef;
StructEl *structEl;
+ GenericType *generic;
ObjectDef *objectDef();
};
diff --git a/src/pdabuild.cc b/src/pdabuild.cc
index 51757e57..c8db886b 100644
--- a/src/pdabuild.cc
+++ b/src/pdabuild.cc
@@ -1564,7 +1564,7 @@ void Compiler::makeRuntimeData()
runtimeData->genericInfo[gen->id].keyType = gen->keyUT != 0 ?
gen->keyUT->typeId : 0;
runtimeData->genericInfo[gen->id].keyOffset = 0;
- runtimeData->genericInfo[gen->id].langElId = gen->langEl->id;
+ runtimeData->genericInfo[gen->id].langElId = -1; // gen->langEl->id;
runtimeData->genericInfo[gen->id].parserId = gen->utArg->langEl->parserId;
runtimeData->genericInfo[gen->id].elOffset = gen->elOffset;
}
@@ -1810,9 +1810,11 @@ void Compiler::fillInPatterns( Program *prg )
}
for ( ConsList::Iter repl = replList; repl.lte(); repl++ ) {
- countNodes( prg, count,
- repl->pdaRun->stackTop->next,
- repl->pdaRun->stackTop->next->shadow );
+ if ( repl->langEl != 0 ) {
+ countNodes( prg, count,
+ repl->pdaRun->stackTop->next,
+ repl->pdaRun->stackTop->next->shadow );
+ }
}
runtimeData->patReplNodes = new PatConsNode[count];
@@ -1838,19 +1840,21 @@ void Compiler::fillInPatterns( Program *prg )
}
for ( ConsList::Iter repl = replList; repl.lte(); repl++ ) {
- int ind = nextAvail++;
- runtimeData->patReplInfo[repl->patRepId].offset = ind;
+ if ( repl->langEl != 0 ) {
+ int ind = nextAvail++;
+ runtimeData->patReplInfo[repl->patRepId].offset = ind;
- /* BindIds are indexed base one. */
- runtimeData->patReplInfo[repl->patRepId].numBindings =
- repl->pdaRun->bindings->length() - 1;
+ /* BindIds are indexed base one. */
+ runtimeData->patReplInfo[repl->patRepId].numBindings =
+ repl->pdaRun->bindings->length() - 1;
- long bindId = 1;
- fillNodes( prg, nextAvail, repl->pdaRun->bindings, bindId,
- runtimeData->patReplNodes,
- repl->pdaRun->stackTop->next,
- repl->pdaRun->stackTop->next->shadow,
- ind );
+ long bindId = 1;
+ fillNodes( prg, nextAvail, repl->pdaRun->bindings, bindId,
+ runtimeData->patReplNodes,
+ repl->pdaRun->stackTop->next,
+ repl->pdaRun->stackTop->next->shadow,
+ ind );
+ }
}
assert( nextAvail == count );
diff --git a/src/resolve.cc b/src/resolve.cc
index b701a092..88a79564 100644
--- a/src/resolve.cc
+++ b/src/resolve.cc
@@ -131,7 +131,7 @@ UniqueType *TypeRef::resolveTypeList( Compiler *pd )
}
generic = inMap->generic;
- return pd->findUniqueType( TYPE_PTR, pd->findUniqueType( TYPE_TREE, inMap->generic->langEl )->langEl );
+ return pd->findUniqueType( TYPE_GENERIC, inMap->generic );
}
UniqueType *TypeRef::resolveTypeListEl( Compiler *pd )
@@ -161,7 +161,7 @@ UniqueType *TypeRef::resolveTypeListEl( Compiler *pd )
}
generic = inMap->generic;
- return pd->findUniqueType( TYPE_TREE, inMap->generic->langEl );
+ return pd->findUniqueType( TYPE_GENERIC, inMap->generic );
}
UniqueType *TypeRef::resolveTypeMap( Compiler *pd )
@@ -193,7 +193,7 @@ UniqueType *TypeRef::resolveTypeMap( Compiler *pd )
}
generic = inMap->generic;
- return pd->findUniqueType( TYPE_PTR, pd->findUniqueType( TYPE_TREE, inMap->generic->langEl )->langEl );
+ return pd->findUniqueType( TYPE_GENERIC, inMap->generic );
}
UniqueType *TypeRef::resolveTypeMapEl( Compiler *pd )
@@ -223,7 +223,7 @@ UniqueType *TypeRef::resolveTypeMapEl( Compiler *pd )
}
generic = inMap->generic;
- return pd->findUniqueType( TYPE_TREE, inMap->generic->langEl );
+ return pd->findUniqueType( TYPE_GENERIC, inMap->generic );
}
UniqueType *TypeRef::resolveTypeParser( Compiler *pd )
@@ -253,7 +253,7 @@ UniqueType *TypeRef::resolveTypeParser( Compiler *pd )
}
generic = inMap->generic;
- return pd->findUniqueType( TYPE_PTR, pd->findUniqueType( TYPE_TREE, inMap->generic->langEl )->langEl );
+ return pd->findUniqueType( TYPE_GENERIC, inMap->generic );
}
diff --git a/src/synthesis.cc b/src/synthesis.cc
index 7ebe0ca8..1e5b328c 100644
--- a/src/synthesis.cc
+++ b/src/synthesis.cc
@@ -198,6 +198,17 @@ UniqueType *Compiler::findUniqueType( enum TYPE typeId, StructEl *structEl )
return uniqueType;
}
+UniqueType *Compiler::findUniqueType( enum TYPE typeId, GenericType *generic )
+{
+ UniqueType searchKey( typeId, generic );
+ UniqueType *uniqueType = uniqeTypeMap.find( &searchKey );
+ if ( uniqueType == 0 ) {
+ uniqueType = new UniqueType( typeId, generic );
+ uniqeTypeMap.insert( uniqueType );
+ }
+ return uniqueType;
+}
+
/* 0-based. */
ObjectField *ObjectDef::findFieldNum( long offset )
{
@@ -429,12 +440,14 @@ void LangVarRef::loadQualification( Compiler *pd, CodeVect &code,
qualUT = pd->findUniqueType( TYPE_TREE, qualUT->langEl );
}
- else if ( qualUT->typeId == TYPE_STRUCT ) {
+ else if ( qualUT->typeId == TYPE_STRUCT ||
+ qualUT->typeId == TYPE_GENERIC )
+ {
/* No deref. */
-
}
else {
- error(loc) << "arrow operator cannot be used to access this type" << endp;
+ error(loc) << "arrow operator cannot be used to "
+ "access this type" << endp;
}
}
@@ -1229,7 +1242,7 @@ UniqueType *LangTerm::evaluateParse( Compiler *pd, CodeVect &code,
bool tree, bool stop ) const
{
UniqueType *parserUT = typeRef->uniqueType;
- UniqueType *targetUT = parserUT->langEl->generic->utArg;
+ UniqueType *targetUT = parserUT->generic->utArg;
/* If this is a parse stop then we need to verify that the type is
* compatible with parse stop. */
@@ -1264,7 +1277,7 @@ UniqueType *LangTerm::evaluateParse( Compiler *pd, CodeVect &code,
/* Construct the parser. */
code.append( IN_CONS_GENERIC );
- code.appendHalf( parserUT->langEl->generic->id );
+ code.appendHalf( parserUT->generic->id );
/* Dup for the finish operation. */
code.append( IN_DUP_TOP );