summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2015-11-05 21:44:00 -0500
committerAdrian Thurston <thurston@complang.org>2015-11-05 21:44:00 -0500
commit61fea2948a63f7968e2d9f6508a640afe83421ca (patch)
tree203066627df83b5dff0d60803682ae66e740e429
parent883797b32e3a4915bf81f801946cda6798e019c9 (diff)
downloadcolm-61fea2948a63f7968e2d9f6508a640afe83421ca.tar.gz
stash reduction class in program
-rw-r--r--src/colm.h3
-rw-r--r--src/program.c5
-rw-r--r--src/program.h3
-rw-r--r--src/reduce.cc8
4 files changed, 11 insertions, 8 deletions
diff --git a/src/colm.h b/src/colm.h
index 5f3c31c8..05c4c5b8 100644
--- a/src/colm.h
+++ b/src/colm.h
@@ -98,6 +98,9 @@ struct colm_tree *colm_run_func( struct colm_program *prg, int frame_id,
/* Delete a colm program. Clears all memory. */
int colm_delete_program( struct colm_program *prg );
+/* Set the pointer to the reduce struct used. */
+void colm_set_reduce_ctx( struct colm_program *prg, void *ctx );
+
#ifdef __cplusplus
}
#endif
diff --git a/src/program.c b/src/program.c
index 3958da9d..0f7396d8 100644
--- a/src/program.c
+++ b/src/program.c
@@ -226,6 +226,11 @@ static void colm_clear_heap( program_t *prg, tree_t **sp )
}
}
+void colm_set_reduce_ctx( struct colm_program *prg, void *ctx )
+{
+ prg->red_ctx = ctx;
+}
+
int colm_delete_program( program_t *prg )
{
tree_t **sp = prg->stack_root;
diff --git a/src/program.h b/src/program.h
index 9949b386..cbca509b 100644
--- a/src/program.h
+++ b/src/program.h
@@ -99,7 +99,6 @@ struct colm_sections
struct pda_run *pda_run, struct stream_impl *input_stream );
void (*init_bindings)( struct pda_run *pda_run );
void (*pop_binding)( struct pda_run *pda_run, parse_tree_t *tree );
-
};
struct heap_list
@@ -150,6 +149,8 @@ struct colm_program
/* Returned value for main program and any exported functions. */
tree_t *return_val;
+
+ void *red_ctx;
};
#endif
diff --git a/src/reduce.cc b/src/reduce.cc
index 7880c27e..cb47e94f 100644
--- a/src/reduce.cc
+++ b/src/reduce.cc
@@ -253,12 +253,6 @@ void Compiler::writeCommit()
"#include \"reducer.h\"\n"
"\n";
- for ( ReductionVect::Iter r = rootNamespace->reductions; r.lte(); r++ ) {
- Reduction *reduction = *r;
- *outStream <<
- reduction->name << "* " << reduction->var << ";\n";
- }
-
*outStream << "\n";
for ( ReductionVect::Iter r = rootNamespace->reductions; r.lte(); r++ ) {
@@ -307,7 +301,7 @@ void Compiler::writeCommit()
Reduction *reduction = *r;
*outStream <<
" case " << reduction->id << ":\n"
- " " << reduction->var << "->commit_reduce_forward( "
+ " ((" << reduction->name << "*)prg->red_ctx)->commit_reduce_forward( "
"prg, root, pda_run, pt );\n"
" break;\n";
}