Implement more internal calls
This commit is contained in:
parent
bba2e812c4
commit
6e1e6e2838
@ -28,7 +28,7 @@ EvalResult execute(vector<string> input, Memory& memory, int initial_line, ExecA
|
|||||||
type_mem._debug_print();
|
type_mem._debug_print();
|
||||||
}
|
}
|
||||||
|
|
||||||
EvalResult res = eval(ast, memory);
|
EvalResult res = eval(ast, memory, input);
|
||||||
|
|
||||||
if (args.dump_mem) {
|
if (args.dump_mem) {
|
||||||
cout << BOLD YELLOW " === MEMORY ===" RESET << endl;
|
cout << BOLD YELLOW " === MEMORY ===" RESET << endl;
|
||||||
|
@ -11,7 +11,7 @@ using namespace std;
|
|||||||
/*
|
/*
|
||||||
Evaluates the AST, returning the latest calulated value
|
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 {
|
class BreakException : public InternalError {
|
||||||
public:
|
public:
|
||||||
|
@ -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)) {
|
if (holds_alternative<InnerNode>(ast)) {
|
||||||
InnerNode node = get<InnerNode>(ast);
|
InnerNode node = get<InnerNode>(ast);
|
||||||
switch (node.type) {
|
switch (node.type) {
|
||||||
@ -231,9 +231,22 @@ EvalResult eval(Node &ast, Memory &memory) {
|
|||||||
exception_ptr e = current_exception();
|
exception_ptr e = current_exception();
|
||||||
if (e) rethrow_exception(e);
|
if (e) rethrow_exception(e);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
switch (get<InternalCall>(fn)) {
|
||||||
|
case InternalCall::ClearMemory:
|
||||||
memory._debug_clear();
|
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);
|
return cast_from_type(get<0>(prototype[0]), res);
|
||||||
|
Loading…
Reference in New Issue
Block a user