summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2015-06-07 16:03:23 -0400
committerAdrian Thurston <thurston@complang.org>2015-06-07 16:03:23 -0400
commit158cd89b0b45b68155dfce173f40a18f64a0b5cc (patch)
treee89f1f943ba95017b5da63f324dacf88a09c26b2
parent9ed46192f42837b4c066b5e1ebf859c9f5070106 (diff)
downloadcolm-158cd89b0b45b68155dfce173f40a18f64a0b5cc.tar.gz
giving list and map the original (non-vlist) funcs and fields
This change allows us to iterate list and maps using next/prev pointers.
-rw-r--r--src/declare.cc39
-rw-r--r--test/accum3.lm2
-rw-r--r--test/argv1.lm2
-rw-r--r--test/argv2.lm2
-rw-r--r--test/factor5.lm2
-rw-r--r--test/list2.lm2
-rw-r--r--test/map1.lm2
-rw-r--r--test/map6.lm47
8 files changed, 88 insertions, 10 deletions
diff --git a/src/declare.cc b/src/declare.cc
index 725930f1..52b8396a 100644
--- a/src/declare.cc
+++ b/src/declare.cc
@@ -1132,6 +1132,15 @@ void Compiler::initValueMapFunctions( GenericType *gen )
initFunction( gen->elUt, gen->objDef, "remove",
IN_VMAP_REMOVE_WV, IN_VMAP_REMOVE_WC, gen->keyUt, false, true, gen );
+
+ initFunction( gen->elUt, gen->objDef, "find_el",
+ IN_MAP_FIND, IN_MAP_FIND, gen->keyUt, true, true, gen );
+
+ initFunction( uniqueTypeInt, gen->objDef, "insert_el",
+ IN_MAP_INSERT_WV, IN_MAP_INSERT_WC, gen->elUt, false, true, gen );
+
+ initFunction( gen->elUt, gen->objDef, "detach_el",
+ IN_MAP_DETACH_WV, IN_MAP_DETACH_WC, gen->elUt, false, true, gen );
}
void Compiler::initMapField( GenericType *gen, const char *name, int offset )
@@ -1163,16 +1172,16 @@ void Compiler::initMapFields( GenericType *gen )
{
addLengthField( gen->objDef, IN_MAP_LENGTH );
- initMapField( gen, "head", 0 );
- initMapField( gen, "tail", 1 );
+ initMapField( gen, "head_el", 0 );
+ initMapField( gen, "tail_el", 1 );
}
void Compiler::initValueMapFields( GenericType *gen )
{
addLengthField( gen->objDef, IN_MAP_LENGTH );
- initMapField( gen, "head", 0 );
- initMapField( gen, "tail", 1 );
+ initMapField( gen, "head_el", 0 );
+ initMapField( gen, "tail_el", 1 );
}
void Compiler::initMapElKey( GenericType *gen, const char *name, int offset )
@@ -1259,6 +1268,24 @@ void Compiler::initValueListFunctions( GenericType *gen )
initFunction( gen->valueUt, gen->objDef, "pop",
IN_VLIST_POP_HEAD_WV, IN_VLIST_POP_HEAD_WC, false, true, gen );
+
+ initFunction( uniqueTypeInt, gen->objDef, "push_head_el",
+ IN_LIST_PUSH_HEAD_WV, IN_LIST_PUSH_HEAD_WC, gen->elUt, false, true, gen );
+
+ initFunction( uniqueTypeInt, gen->objDef, "push_tail_el",
+ IN_LIST_PUSH_TAIL_WV, IN_LIST_PUSH_TAIL_WC, gen->elUt, false, true, gen );
+
+ initFunction( uniqueTypeInt, gen->objDef, "push_el",
+ IN_LIST_PUSH_HEAD_WV, IN_LIST_PUSH_HEAD_WC, gen->elUt, false, true, gen );
+
+ initFunction( gen->elUt, gen->objDef, "pop_head_el",
+ IN_LIST_POP_HEAD_WV, IN_LIST_POP_HEAD_WC, false, true, gen );
+
+ initFunction( gen->elUt, gen->objDef, "pop_tail_el",
+ IN_LIST_POP_TAIL_WV, IN_LIST_POP_TAIL_WC, false, true, gen );
+
+ initFunction( gen->elUt, gen->objDef, "pop_el",
+ IN_LIST_POP_HEAD_WV, IN_LIST_POP_HEAD_WC, false, true, gen );
}
void Compiler::initListElField( GenericType *gen, const char *name, int offset )
@@ -1353,6 +1380,10 @@ void Compiler::initValueListFields( GenericType *gen )
initValueListField( gen, "head", 0 );
initValueListField( gen, "tail", 1 );
initValueListField( gen, "top", 0 );
+
+ initListField( gen, "head_el", 0 );
+ initListField( gen, "tail_el", 1 );
+ initListField( gen, "top_el", 0 );
}
void Compiler::initParserFunctions( GenericType *gen )
diff --git a/test/accum3.lm b/test/accum3.lm
index 45d664ec..0106871b 100644
--- a/test/accum3.lm
+++ b/test/accum3.lm
@@ -21,7 +21,7 @@ def args
ArgParser: parser<args> = new parser<args>()
-A: argv_el = argv->head
+A: list_el<str> = argv->head_el
while ( A ) {
send ArgParser [A->value '\0']
A = A->next
diff --git a/test/argv1.lm b/test/argv1.lm
index 0318756c..1b079155 100644
--- a/test/argv1.lm
+++ b/test/argv1.lm
@@ -1,6 +1,6 @@
print_xml( arg0 )
-A: argv_el = argv->head
+A: list_el<str> = argv->head_el
while ( A ) {
print_xml( A->value )
A = A->next
diff --git a/test/argv2.lm b/test/argv2.lm
index fdcaa714..024ed487 100644
--- a/test/argv2.lm
+++ b/test/argv2.lm
@@ -40,7 +40,7 @@ def args
ArgParser: parser<args> = new parser<args>()
# Parse the args and extract the result into Args.
-A: argv_el = argv->head
+A: list_el<str> = argv->head_el
while ( A ) {
send ArgParser [A->value '\0']
A = A->next
diff --git a/test/factor5.lm b/test/factor5.lm
index 87d1a9e3..8c52f54b 100644
--- a/test/factor5.lm
+++ b/test/factor5.lm
@@ -1,4 +1,4 @@
-A: argv_el = argv->pop()
+A: list_el<str> = argv->pop_el()
print( A->value, '\n' )
##### ARGS #####
a
diff --git a/test/list2.lm b/test/list2.lm
index f5c7654b..9f5a12cd 100644
--- a/test/list2.lm
+++ b/test/list2.lm
@@ -1,7 +1,7 @@
new M: map<str, str>()
-for AE: argv_el in argv {
+for AE: list_el<str> in argv {
print "[AE->value]
}
diff --git a/test/map1.lm b/test/map1.lm
index 8d3b111b..65c4f595 100644
--- a/test/map1.lm
+++ b/test/map1.lm
@@ -1,7 +1,7 @@
new M: map<str, str>()
-AE: argv_el = argv->head
+AE: list_el<str> = argv->head_el
while AE {
M->insert( AE->value, AE->value )
AE = AE->next
diff --git a/test/map6.lm b/test/map6.lm
new file mode 100644
index 00000000..97f0c223
--- /dev/null
+++ b/test/map6.lm
@@ -0,0 +1,47 @@
+new M: map<str, str>()
+
+AE: list_el<str> = argv->head_el
+while AE {
+ M->insert( AE->value, toupper(AE->value) )
+ AE = AE->next
+}
+
+for A: str in argv {
+ new El: map_el<str, str>()
+
+ El->key = toupper(A)
+ El->value = A
+
+ M->insert_el( El )
+}
+
+
+for El: map_el<str, str> in M {
+ print "[El->key] [El->value]
+}
+
+El: map_el<str, str> = M->head_el
+while ( El ) {
+ print "[El->key] [El->value]
+ El = El->next
+}
+
+###### ARGS ######
+a b c done
+###### EXP ######
+A a
+B b
+C c
+a A
+b B
+c C
+DONE done
+done DONE
+A a
+B b
+C c
+a A
+b B
+c C
+DONE done
+done DONE