Implement more internal calls

This commit is contained in:
augustin64 2024-01-06 19:24:13 +01:00
parent bba2e812c4
commit 6e1e6e2838
3 changed files with 19 additions and 6 deletions

View File

@ -28,7 +28,7 @@ EvalResult execute(vector<string> 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;

View File

@ -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<string> history={});
class BreakException : public InternalError {
public:

View File

@ -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<string> history) {
if (holds_alternative<InnerNode>(ast)) {
InnerNode node = get<InnerNode>(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 {
} else {
switch (get<InternalCall>(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);