diff --git a/src/execute.cpp b/src/execute.cpp index 96d596b..dcb36a4 100644 --- a/src/execute.cpp +++ b/src/execute.cpp @@ -28,7 +28,7 @@ EvalResult execute(vector input, Memory& memory, int initial_line, ExecA type_mem._debug_print(); } - EvalResult res = eval(ast, memory); + EvalResult res = eval(ast, memory, input); if (args.dump_mem) { cout << BOLD YELLOW " === MEMORY ===" RESET << endl; diff --git a/src/include/interpreter.h b/src/include/interpreter.h index 3f7ca87..2ab3a42 100644 --- a/src/include/interpreter.h +++ b/src/include/interpreter.h @@ -11,7 +11,7 @@ using namespace std; /* Evaluates the AST, returning the latest calulated value */ -EvalResult eval(Node &ast, Memory& memory); +EvalResult eval(Node &ast, Memory& memory, vector history={}); class BreakException : public InternalError { public: diff --git a/src/interpreter.cpp b/src/interpreter.cpp index 0c4473d..1ee7abd 100644 --- a/src/interpreter.cpp +++ b/src/interpreter.cpp @@ -52,7 +52,7 @@ EvalResult cast_from_type(Type type, EvalResult val) { } } -EvalResult eval(Node &ast, Memory &memory) { +EvalResult eval(Node &ast, Memory &memory, vector history) { if (holds_alternative(ast)) { InnerNode node = get(ast); switch (node.type) { @@ -231,9 +231,22 @@ EvalResult eval(Node &ast, Memory &memory) { exception_ptr e = current_exception(); if (e) rethrow_exception(e); } - } - else { - memory._debug_clear(); + } else { + switch (get(fn)) { + case InternalCall::ClearMemory: + memory._debug_clear(); + break; + case InternalCall::DumpMemory: + memory._debug_print(); + break; + case InternalCall::DumpHistory: { + for (string line : history) { + cout << line << endl; + } + } break; + default: + throw InternalError(); + } } return cast_from_type(get<0>(prototype[0]), res);