summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2015-01-11 11:56:37 -0500
committerAdrian Thurston <thurston@complang.org>2015-01-11 11:56:37 -0500
commita5ad06e3fbbda39cbd894906e93a775c511f1f05 (patch)
treead71cf7b11cc6357d6a12d6897e779d43eea3a46
parent5ede67bfe812f2407244fafc0b830728213f2110 (diff)
downloadcolm-a5ad06e3fbbda39cbd894906e93a775c511f1f05.tar.gz
improvements to list object semantics
-rw-r--r--src/bytecode.c31
-rw-r--r--src/compiler.h1
-rw-r--r--src/fsmcodegen.cc4
-rw-r--r--src/internal.h1
-rw-r--r--src/iter.c1
-rw-r--r--src/map.h2
-rw-r--r--src/program.h4
-rw-r--r--src/struct.c2
8 files changed, 27 insertions, 19 deletions
diff --git a/src/bytecode.c b/src/bytecode.c
index b1c65db8..992754e4 100644
--- a/src/bytecode.c
+++ b/src/bytecode.c
@@ -460,7 +460,7 @@ static List *construct_argv( Program *prg, int argc, const char **argv )
Tree *arg = constructString( prg, head );
treeUpref( arg );
- Struct *s = colm_struct_new_size( prg, 3 );
+ Struct *s = colm_struct_new_size( prg, 16 );
colm_struct_set_field( s, Tree*, 0, arg );
ListEl *listEl = colm_struct_get_addr( s, ListEl*, 1 );
colm_list_append( list, listEl );
@@ -3036,7 +3036,7 @@ again:
case IN_LIST_LENGTH: {
debug( prg, REALM_BYTECODE, "IN_LIST_LENGTH\n" );
- List *list = (List*) vm_pop();
+ List *list = vm_pop_type( List* );
long len = colm_list_length( list );
Tree *res = constructInteger( prg, len );
treeDownref( prg, sp, (Tree*)list );
@@ -3152,32 +3152,35 @@ again:
short genId;
read_half( genId );
- debug( prg, REALM_BYTECODE, "IN_LIST_POP_TAIL_WC\n" );
+ debug( prg, REALM_BYTECODE, "IN_LIST_POP_HEAD_WC\n" );
- Tree *obj = vm_pop();
- treeDownref( prg, sp, obj );
+ List *list = vm_pop_type(List*);
- Tree *end = listRemoveEnd( prg, (List*)obj );
- vm_push( end );
+ ListEl *head = list->head;
+ colm_list_detach_tail( list );
+ GenericInfo *gi = &prg->rtd->genericInfo[genId];
+ Struct *s = colm_struct_container( head, gi->elOffset );
+ vm_push_type( Struct *, s );
break;
}
case IN_LIST_POP_TAIL_WV: {
short genId;
read_half( genId );
- debug( prg, REALM_BYTECODE, "IN_LIST_POP_TAIL_WV\n" );
+ debug( prg, REALM_BYTECODE, "IN_LIST_POP_HEAD_WV\n" );
- Tree *obj = vm_pop();
- treeDownref( prg, sp, obj );
+ List *list = vm_pop_type(List*);
- Tree *end = listRemoveEnd( prg, (List*)obj );
- vm_push( end );
+ ListEl *head = list->head;
+ colm_list_detach_tail( list );
+ GenericInfo *gi = &prg->rtd->genericInfo[genId];
+ Struct *s = colm_struct_container( head, gi->elOffset );
+ vm_push_type( Struct *, s );
/* Set up reverse. The result comes off the list downrefed.
* Need it up referenced for the reverse code too. */
- treeUpref( end );
rcodeCode( exec, IN_LIST_POP_TAIL_BKT );
- rcodeWord( exec, (Word)end );
+ rcodeWord( exec, (Word)s );
rcodeUnitTerm( exec );
break;
}
diff --git a/src/compiler.h b/src/compiler.h
index a545355d..a4ee828f 100644
--- a/src/compiler.h
+++ b/src/compiler.h
@@ -26,6 +26,7 @@
#include "pdarun.h"
#include "bytecode.h"
#include "program.h"
+#include "internal.h"
using std::ostream;
diff --git a/src/fsmcodegen.cc b/src/fsmcodegen.cc
index 5d85831b..fb2b3f5e 100644
--- a/src/fsmcodegen.cc
+++ b/src/fsmcodegen.cc
@@ -903,8 +903,8 @@ void FsmCodeGen::writeCode()
/* Referenced in the runtime lib, but used only in the compiler. Probably
* should use the preprocessor to make these go away. */
out <<
- "static void sendNamedLangEl( Program *prg, Tree **tree, PdaRun *pdaRun,\n"
- " FsmRun *fsmRun, StreamImpl *inputStream ) { }\n"
+ "static void sendNamedLangEl( struct colm_program *prg, Tree **tree,\n"
+ " PdaRun *pdaRun, FsmRun *fsmRun, StreamImpl *inputStream ) { }\n"
"static void initBindings( PdaRun *pdaRun ) {}\n"
"static void popBinding( PdaRun *pdaRun, ParseTree *tree ) {}\n"
"\n"
diff --git a/src/internal.h b/src/internal.h
index 7b3b1a75..fc12fd68 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -2,5 +2,6 @@
#define _COLM_INTERNAL
typedef struct colm_struct Struct;
+typedef struct colm_program Program;
#endif
diff --git a/src/iter.c b/src/iter.c
index aded50ad..8f4b343e 100644
--- a/src/iter.c
+++ b/src/iter.c
@@ -6,6 +6,7 @@
#include <colm/bytecode.h>
#include <colm/program.h>
#include <assert.h>
+#include "internal.h"
#define true 1
#define false 0
diff --git a/src/map.h b/src/map.h
index 1cbc2d74..b59c16b5 100644
--- a/src/map.h
+++ b/src/map.h
@@ -11,7 +11,7 @@ extern "C" {
#include <colm/program.h>
#include <colm/struct.h>
-
+#include "internal.h"
void mapListAbandon( Map *map );
diff --git a/src/program.h b/src/program.h
index 9fdd9255..0d915d42 100644
--- a/src/program.h
+++ b/src/program.h
@@ -90,7 +90,7 @@ typedef struct colm_heap_list
struct colm_struct *tail;
} HeapList;
-typedef struct colm_program
+struct colm_program
{
long activeRealm;
@@ -137,6 +137,6 @@ typedef struct colm_program
/* Returned value for main program and any exported functions. */
Tree *returnVal;
-} Program;
+};
#endif
diff --git a/src/struct.c b/src/struct.c
index b2f8dbc7..827adc77 100644
--- a/src/struct.c
+++ b/src/struct.c
@@ -1,6 +1,8 @@
#include <colm/program.h>
#include <colm/struct.h>
+#include "internal.h"
+
#include <stdlib.h>
#include <string.h>
#include <assert.h>