Fixes and functions
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include "../modules/while/while.h"
|
||||
#include "../modules/compare/compare.h"
|
||||
#include "../modules/input/input.h"
|
||||
#include "../modules/function/function.h"
|
||||
|
||||
Value execute(Instruction inst) {
|
||||
// Special cases that need to manage their own argument evaluation
|
||||
@@ -24,6 +25,9 @@ Value execute(Instruction inst) {
|
||||
if (inst.instruction == InstructionType::While) {
|
||||
return modules::whiles(inst.args);
|
||||
}
|
||||
if (inst.instruction == InstructionType::Function) {
|
||||
return modules::fndef(inst.args);
|
||||
}
|
||||
|
||||
// For all other instructions, evaluate the arguments first
|
||||
size_t i = 0;
|
||||
@@ -64,7 +68,17 @@ Value execute(Instruction inst) {
|
||||
case InstructionType::Exit:
|
||||
return modules::exit(inst.args);
|
||||
break;
|
||||
case InstructionType::Variable:
|
||||
case InstructionType::Variable: {
|
||||
if (!inst.args.empty()) {
|
||||
const std::string& name = inst.args[0].real;
|
||||
if (data::functions.count(name)) {
|
||||
Value return_val;
|
||||
for (const auto& body_inst : data::functions.at(name)) {
|
||||
return_val = execute(body_inst);
|
||||
}
|
||||
return return_val;
|
||||
}
|
||||
}
|
||||
if (inst.args.size() > 2 && inst.args[1].valtype == ValueType::Real && inst.args[1].real == "=") {
|
||||
return varmod(inst.args);
|
||||
} else {
|
||||
@@ -72,6 +86,7 @@ Value execute(Instruction inst) {
|
||||
return Value("");
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// Note: 'If' and 'Let' are already handled.
|
||||
error("Unknown instruction");
|
||||
|
||||
Reference in New Issue
Block a user