From 4d3ed205fc2b86180f81fea388e488f5fa96cef9 Mon Sep 17 00:00:00 2001 From: Teddy Date: Mon, 12 Aug 2013 19:37:57 +0800 Subject: basic gc --- main.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index 78515a6..a193b68 100644 --- a/main.cpp +++ b/main.cpp @@ -3,13 +3,15 @@ #include "parser.h" #include "eval.h" #include "exc.h" +#include "gc.h" #include #include -Tokenizor *tk = new Tokenizor(); -ASTGenerator *ast = new ASTGenerator(); -Evaluator *eval = new Evaluator(); +GarbageCollector gc; +Tokenizor tk; +ASTGenerator ast; +Evaluator eval; void load_file(const char *fname) { FILE *f = fopen(fname, "r"); @@ -18,14 +20,14 @@ void load_file(const char *fname) { printf("Can not open file: %s\n", fname); exit(0); } - tk->set_stream(f); + tk.set_stream(f); while (1) { try { - Pair *tree = ast->absorb(tk); + Pair *tree = ast.absorb(&tk); if (!tree) break; - eval->run_expr(tree); + eval.run_expr(tree); } catch (GeneralError &e) { @@ -79,15 +81,15 @@ int main(int argc, char **argv) { } int rcnt = 0; - tk->set_stream(stdin); // interactive mode + tk.set_stream(stdin); // interactive mode while (1) { fprintf(stderr, "Sonsi> "); try { - Pair *tree = ast->absorb(tk); + Pair *tree = ast.absorb(&tk); if (!tree) break; - string output = eval->run_expr(tree)->ext_repr(); + string output = eval.run_expr(tree)->ext_repr(); fprintf(stderr, "Ret> $%d = %s\n", rcnt++, output.c_str()); } catch (GeneralError &e) -- cgit v1.2.3