diff options
author | Adrian Thurston <thurston@complang.org> | 2014-11-02 08:06:46 -0500 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2014-11-02 08:06:46 -0500 |
commit | 9f34fbd3b981118e0febf667ad5eae1b148ab776 (patch) | |
tree | f7a1701246593a4117b4fdffadc39a1de5dc8319 /src | |
parent | fae7ec95e99a519398bb3aadd4bc73fb49d8ad3b (diff) | |
download | colm-9f34fbd3b981118e0febf667ad5eae1b148ab776.tar.gz |
start on list2, the non-tree list
Diffstat (limited to 'src')
-rw-r--r-- | src/bytecode.h | 1 | ||||
-rw-r--r-- | src/colm.lm | 2 | ||||
-rw-r--r-- | src/loadcolm.cc | 5 | ||||
-rw-r--r-- | src/parsedata.h | 1 | ||||
-rw-r--r-- | src/parsetree.cc | 10 | ||||
-rw-r--r-- | src/parsetree.h | 23 | ||||
-rw-r--r-- | src/resolve.cc | 38 |
7 files changed, 80 insertions, 0 deletions
diff --git a/src/bytecode.h b/src/bytecode.h index fa628e2c..6b535cee 100644 --- a/src/bytecode.h +++ b/src/bytecode.h @@ -321,6 +321,7 @@ typedef unsigned char uchar; #define TYPE_REF 0x03 #define TYPE_PTR 0x04 #define TYPE_ITER 0x05 +#define TYPE_LIST2 0x06 /* Types of Generics. */ #define GEN_LIST 0x10 diff --git a/src/colm.lm b/src/colm.lm index ef963acf..3c8cc434 100644 --- a/src/colm.lm +++ b/src/colm.lm @@ -28,6 +28,7 @@ lex token IN / 'in' / token PARSER / 'parser' | 'accum' / token LIST / 'list' / + token LIST2 / 'list2' / token VECTOR / 'vector' / token MAP / 'map' / token PTR / 'ptr' / @@ -550,6 +551,7 @@ def type_ref | [PTR LT region_qual id opt_repeat GT] :Ptr | [MAP LT MapKeyType: type_ref MapValueType: type_ref GT] :Map | [LIST LT type_ref GT] :List +| [LIST2 LT type_ref GT] :List2 | [VECTOR LT type_ref GT] :Vector | [PARSER LT type_ref GT] :Parser diff --git a/src/loadcolm.cc b/src/loadcolm.cc index 965f1c64..4852ba8b 100644 --- a/src/loadcolm.cc +++ b/src/loadcolm.cc @@ -826,6 +826,11 @@ struct LoadColm tr = TypeRef::cons( typeRef.loc(), TypeRef::List, 0, type, 0 ); break; } + case type_ref::List2: { + TypeRef *type = walkTypeRef( typeRef._type_ref() ); + tr = TypeRef::cons( typeRef.loc(), TypeRef::List2, 0, type, 0 ); + break; + } case type_ref::Vector: { TypeRef *type = walkTypeRef( typeRef._type_ref() ); tr = TypeRef::cons( typeRef.loc(), TypeRef::Vector, 0, type, 0 ); diff --git a/src/parsedata.h b/src/parsedata.h index 8ffed34f..12d71a84 100644 --- a/src/parsedata.h +++ b/src/parsedata.h @@ -890,6 +890,7 @@ struct Compiler UniqueRepeatMap uniqeRepeatMap; UniqueMapMap uniqueMapMap; UniqueListMap uniqueListMap; + UniqueList2Map uniqueList2Map; UniqueVectorMap uniqueVectorMap; UniqueParserMap uniqueParserMap; diff --git a/src/parsetree.cc b/src/parsetree.cc index 3b749abc..43f6faa6 100644 --- a/src/parsetree.cc +++ b/src/parsetree.cc @@ -152,6 +152,16 @@ int CmpUniqueList::compare( const UniqueList &ut1, const UniqueList &ut2 ) return 0; } +int CmpUniqueList2::compare( const UniqueList2 &ut1, const UniqueList2 &ut2 ) +{ + if ( ut1.value < ut2.value ) + return -1; + else if ( ut1.value > ut2.value ) + return 1; + + return 0; +} + int CmpUniqueVector::compare( const UniqueVector &ut1, const UniqueVector &ut2 ) { if ( ut1.value < ut2.value ) diff --git a/src/parsetree.h b/src/parsetree.h index a0ce23f8..d234a020 100644 --- a/src/parsetree.h +++ b/src/parsetree.h @@ -1893,6 +1893,27 @@ struct CmpUniqueList typedef AvlBasic< UniqueList, CmpUniqueList > UniqueListMap; /* + * Unique List2 Types + */ + +struct UniqueList2 + : public AvlTreeEl<UniqueList2> +{ + UniqueList2( UniqueType *value ) : + value(value), generic(0) {} + + UniqueType *value; + GenericType *generic; +}; + +struct CmpUniqueList2 +{ + static int compare( const UniqueList2 &ut1, const UniqueList2 &ut2 ); +}; + +typedef AvlBasic< UniqueList2, CmpUniqueList2 > UniqueList2Map; + +/* * Unique Vector Types */ @@ -1953,6 +1974,7 @@ struct TypeRef Iterator, Map, List, + List2, Vector, Parser, Ref, @@ -2123,6 +2145,7 @@ struct TypeRef UniqueType *resolveTypeLiteral( Compiler *pd ); UniqueType *resolveTypeMap( Compiler *pd ); UniqueType *resolveTypeList( Compiler *pd ); + UniqueType *resolveTypeList2( Compiler *pd ); UniqueType *resolveTypeVector( Compiler *pd ); UniqueType *resolveTypeParser( Compiler *pd ); UniqueType *resolveType( Compiler *pd ); diff --git a/src/resolve.cc b/src/resolve.cc index 00dee4ef..8961fa35 100644 --- a/src/resolve.cc +++ b/src/resolve.cc @@ -151,6 +151,41 @@ UniqueType *TypeRef::resolveTypeList( Compiler *pd ) return pd->findUniqueType( TYPE_TREE, inMap->generic->langEl ); } +/* The non-tree list. */ +UniqueType *TypeRef::resolveTypeList2( Compiler *pd ) +{ + nspace = pd->rootNamespace; + + UniqueType *utValue = typeRef1->resolveType( pd ); + + UniqueList2 searchKey( utValue ); + UniqueList2 *inMap = pd->uniqueList2Map.find( &searchKey ); + + cerr << "hello dude" << endl; + + if ( inMap == 0 ) { + /* Not found. Create. */ + inMap = new UniqueList2( utValue ); + pd->uniqueList2Map.insert( inMap ); + +// /* FIXME: Need uniqe name allocator for types. */ +// static int listId = 0; +// String name( 36, "__list%d", listId++ ); +// +// GenericType *generic = new GenericType( name, GEN_LIST, +// pd->nextGenericId++, 0/*langEl*/, typeRef1 ); +// +// nspace->genericList.append( generic ); +// +// generic->declare( pd, nspace ); +// +// inMap->generic = generic; + } + + generic = inMap->generic; + return pd->findUniqueType( TYPE_LIST2 ); +} + UniqueType *TypeRef::resolveTypeVector( Compiler *pd ) { nspace = pd->rootNamespace; @@ -311,6 +346,9 @@ UniqueType *TypeRef::resolveType( Compiler *pd ) case List: uniqueType = resolveTypeList( pd ); break; + case List2: + uniqueType = resolveTypeList2( pd ); + break; case Vector: uniqueType = resolveTypeVector( pd ); break; |