summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2015-01-02 12:46:36 -0500
committerAdrian Thurston <thurston@complang.org>2015-01-02 12:46:36 -0500
commitc8bf7e7cba2b61c0b87d0192ae5a5d3868b6d857 (patch)
tree8f83d7a2474c348db8161b29df044c355c47eefa
parent0b223651fcb525374e87935c2de894b7849903c2 (diff)
downloadcolm-c8bf7e7cba2b61c0b87d0192ae5a5d3868b6d857.tar.gz
make stream and parser overlay struct
-rw-r--r--src/bytecode.c4
-rw-r--r--src/compiler.cc3
-rw-r--r--src/input.c4
-rw-r--r--src/loadinit.cc2
-rw-r--r--src/program.h7
-rw-r--r--src/struct.c27
-rw-r--r--src/struct.h58
-rw-r--r--src/tree.c44
-rw-r--r--src/tree.h30
9 files changed, 101 insertions, 78 deletions
diff --git a/src/bytecode.c b/src/bytecode.c
index 6a983037..4fa5d96b 100644
--- a/src/bytecode.c
+++ b/src/bytecode.c
@@ -2168,7 +2168,7 @@ again:
debug( prg, REALM_BYTECODE, "IN_INPUT_CLOSE_WC\n" );
Stream *stream = (Stream*) vm_pop();
- StreamImpl *si = stream->in;
+ StreamImpl *si = stream->impl;
if ( si->file != 0 ) {
fclose( si->file );
@@ -2651,7 +2651,7 @@ again:
case IN_CONSTRUCT_INPUT: {
debug( prg, REALM_BYTECODE, "IN_CONSTRUCT_INPUT\n" );
- Tree *input = constructStream( prg );
+ Tree *input = (Tree*)colm_stream_new( prg );
vm_push( input );
break;
}
diff --git a/src/compiler.cc b/src/compiler.cc
index 1d5d78f2..5b17a56c 100644
--- a/src/compiler.cc
+++ b/src/compiler.cc
@@ -21,6 +21,7 @@
#include "pdarun.h"
#include "colm.h"
#include "pool.h"
+#include "struct.h"
using std::ostringstream;
using std::cout;
@@ -970,7 +971,7 @@ PdaRun *Compiler::parsePattern( Program *prg, Tree **sp, const InputLoc &loc,
PdaRun *pdaRun = new PdaRun;
colm_pda_init( prg, pdaRun, pdaTables, parserId, 0, false, 0 );
- Tree *stream = constructStream( prg );
+ Tree *stream = (Tree*)colm_stream_new( prg );
in->funcs->appendStream( in, stream );
in->funcs->setEof( in );
diff --git a/src/input.c b/src/input.c
index eb68eeec..e4dfee4c 100644
--- a/src/input.c
+++ b/src/input.c
@@ -1056,13 +1056,13 @@ Stream *openFile( Program *prg, Tree *name, Tree *mode )
return stream;
}
-Tree *constructStream( Program *prg )
+Stream *colm_stream_new( Program *prg )
{
StreamImpl *impl = newSourceStreamGeneric( "<internal>" );
struct colm_struct *s = colm_struct_inbuilt( prg, 16, 0 );
colm_struct_set_field( s, 15, (Tree*)impl );
- return (Tree*) s;
+ return (Stream*) s;
}
StreamImpl *colm_stream_impl( struct colm_struct *s )
diff --git a/src/loadinit.cc b/src/loadinit.cc
index aba62146..07b78701 100644
--- a/src/loadinit.cc
+++ b/src/loadinit.cc
@@ -347,7 +347,7 @@ void LoadInit::go( long activeRealm )
argv[2] = 0;
colm_program *program = colm_new_program( &colm_object );
- colm_set_debug( program, 0x3 );
+ colm_set_debug( program, 0 );
colm_run_program( program, 2, argv );
/* Extract the parse tree. */
diff --git a/src/program.h b/src/program.h
index 26be6869..9fdd9255 100644
--- a/src/program.h
+++ b/src/program.h
@@ -84,13 +84,6 @@ typedef struct colm_sections
} RuntimeData;
-struct colm_struct
-{
- short id;
- struct colm_struct *prev;
- struct colm_struct *next;
-};
-
typedef struct colm_heap_list
{
struct colm_struct *head;
diff --git a/src/struct.c b/src/struct.c
index 3e1b6394..f17ce779 100644
--- a/src/struct.c
+++ b/src/struct.c
@@ -65,3 +65,30 @@ void colm_struct_delete( Program *prg, Tree **sp, struct colm_struct *el )
}
free( el );
}
+
+void colm_parser_destroy( Program *prg, Tree **sp, struct colm_struct *parser )
+{
+ /* Free the PDA run. */
+ PdaRun *pdaRun = colm_struct_get_field_type( parser, PdaRun *, 6 );
+ clearPdaRun( prg, sp, pdaRun );
+ free( pdaRun );
+
+ /* Free the result. */
+ Tree *result = colm_struct_get_field_type( parser, Tree *, 8 );
+ treeDownref( prg, sp, result );
+}
+
+Parser *colm_parser_new( Program *prg, GenericInfo *gi )
+{
+ PdaRun *pdaRun = malloc( sizeof(PdaRun) );
+
+ /* Start off the parsing process. */
+ colm_pda_init( prg, pdaRun, prg->rtd->pdaTables,
+ gi->parserId, 0, 0, 0 );
+
+ struct colm_struct *s = colm_struct_inbuilt( prg, 16, colm_parser_destroy );
+ colm_struct_set_field_type( s, PdaRun*, 6, pdaRun );
+
+ return (Parser*) s;
+}
+
diff --git a/src/struct.h b/src/struct.h
index 2e72e118..b23dbce6 100644
--- a/src/struct.h
+++ b/src/struct.h
@@ -1,12 +1,57 @@
#ifndef _COLM_STRUCT_H
+#define _COLM_STRUCT_H
-struct colm_struct *colm_struct_new( struct colm_program *prg, int id );
-void colm_struct_delete( struct colm_program *prg, struct colm_tree **sp,
- struct colm_struct *el );
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+typedef struct _StreamImpl StreamImpl;
typedef void (*colm_destructor_t)( struct colm_program *prg,
Tree **sp, struct colm_struct *s );
+struct colm_struct
+{
+ short id;
+ struct colm_struct *prev, *next;
+};
+
+/* Must overlay colm_struct. */
+struct colm_inbuilt
+{
+ short id;
+ struct colm_struct *prev, *next;
+ colm_destructor_t destructor;
+};
+
+/* Must overlay colm_inbuilt. */
+typedef struct colm_parser
+{
+ short id;
+ struct colm_struct *prev, *next;
+ colm_destructor_t destructor;
+
+ struct _PdaRun *pdaRun;
+ struct colm_stream *input;
+ Tree *result;
+} Parser;
+
+
+/* Must overlay colm_inbuilt. */
+typedef struct colm_stream
+{
+ short id;
+ struct colm_struct *prev, *next;
+ colm_destructor_t destructor;
+
+ StreamImpl *impl;
+} Stream;
+
+
+struct colm_struct *colm_struct_new( struct colm_program *prg, int id );
+void colm_struct_delete( struct colm_program *prg, struct colm_tree **sp,
+ struct colm_struct *el );
+
struct colm_struct *colm_struct_inbuilt( Program *prg, int size,
colm_destructor_t destructor );
@@ -24,4 +69,11 @@ struct colm_struct *colm_struct_inbuilt( Program *prg, int size,
((type*)(((struct colm_struct*)obj)+1))[field] = val
+Parser *colm_parser_new( struct colm_program *prg, GenericInfo *gi );
+Stream *colm_stream_new( struct colm_program *prg );
+
+#if defined(__cplusplus)
+}
+#endif
+
#endif
diff --git a/src/tree.c b/src/tree.c
index 2383925e..1dcbcf62 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -949,32 +949,6 @@ Tree *splitTree( Program *prg, Tree *tree )
return tree;
}
-void colm_parser_destroy( Program *prg, Tree **sp, struct colm_struct *parser )
-{
- /* Free the PDA run. */
- PdaRun *pdaRun = colm_struct_get_field_type( parser, PdaRun *, 6 );
- clearPdaRun( prg, sp, pdaRun );
- free( pdaRun );
-
- /* Free the result. */
- Tree *result = colm_struct_get_field_type( parser, Tree *, 8 );
- treeDownref( prg, sp, result );
-}
-
-Parser *colm_parser_construct( Program *prg, GenericInfo *gi )
-{
- PdaRun *pdaRun = malloc( sizeof(PdaRun) );
-
- /* Start off the parsing process. */
- colm_pda_init( prg, pdaRun, prg->rtd->pdaTables,
- gi->parserId, false, false, 0 );
-
- struct colm_struct *s = colm_struct_inbuilt( prg, 16, colm_parser_destroy );
- colm_struct_set_field_type( s, PdaRun*, 6, pdaRun );
-
- return (Parser*) s;
-}
-
Tree *constructGeneric( Program *prg, long genericId )
{
GenericInfo *genericInfo = &prg->rtd->genericInfo[genericId];
@@ -995,7 +969,7 @@ Tree *constructGeneric( Program *prg, long genericId )
break;
}
case GEN_PARSER: {
- Parser *parser = colm_parser_construct( prg, genericInfo );
+ Parser *parser = colm_parser_new( prg, genericInfo );
newGeneric = (Tree*) parser;
break;
}
@@ -1134,14 +1108,14 @@ free_tree:
mapElFree( prg, (MapEl*)map );
break;
}
- case GEN_PARSER: {
- Parser *parser = (Parser*)tree;
- clearPdaRun( prg, sp, parser->pdaRun );
- free( parser->pdaRun );
- treeDownref( prg, sp, (Tree*)parser->input );
- mapElFree( prg, (MapEl*)parser );
- break;
- }
+// case GEN_PARSER: {
+// Parser *parser = (Parser*)tree;
+// clearPdaRun( prg, sp, parser->pdaRun );
+// free( parser->pdaRun );
+// treeDownref( prg, sp, (Tree*)parser->input );
+// mapElFree( prg, (MapEl*)parser );
+// break;
+// }
case GEN_LIST2EL: {
break;
}
diff --git a/src/tree.h b/src/tree.h
index a2d3a6a8..e6df8f7b 100644
--- a/src/tree.h
+++ b/src/tree.h
@@ -18,6 +18,9 @@ typedef unsigned long Half;
struct Bindings;
struct _FunctionInfo;
+typedef struct colm_stream Stream;
+typedef struct colm_parser Parser;
+
typedef struct colm_location
{
const char *name;
@@ -148,32 +151,6 @@ typedef struct _List
} List;
-typedef struct _Stream
-{
- /* Must overlay Tree. */
- short id;
- unsigned short flags;
- long refs;
- Kid *child;
-
- StreamImpl *in;
-} Stream;
-
-typedef struct _Parser
-{
- /* Must overlay Tree. */
- short id;
- unsigned short flags;
- long refs;
- Kid *child;
-
- GenericInfo *genericInfo;
-
- struct _PdaRun *pdaRun;
- struct _Stream *input;
- Tree *result;
-} Parser;
-
enum IterType
{
IT_Tree = 1,
@@ -259,7 +236,6 @@ Tree *constructObject( struct colm_program *prg, Kid *kid,
Tree **bindings, long langElId );
Tree *constructGeneric( struct colm_program *prg, long genericId );
Tree *constructToken( struct colm_program *prg, Tree **args, long nargs );
-Tree *constructStream( struct colm_program *prg );
Object *newList2( struct colm_program *prg );