Return
This commit is contained in:
@@ -89,10 +89,14 @@ Value execute(Instruction inst) {
|
||||
Value return_val;
|
||||
for (const auto& body_inst : func.body) {
|
||||
return_val = execute(body_inst);
|
||||
if (return_val.is_return) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
data::popScope();
|
||||
|
||||
return_val.is_return = false;
|
||||
return return_val;
|
||||
}
|
||||
}
|
||||
@@ -104,6 +108,16 @@ Value execute(Instruction inst) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case InstructionType::Return: {
|
||||
if (inst.args.empty()) {
|
||||
Value val;
|
||||
val.is_return = true;
|
||||
return val;
|
||||
}
|
||||
Value return_val = inst.args[0];
|
||||
return_val.is_return = true;
|
||||
return return_val;
|
||||
}
|
||||
default:
|
||||
// Note: 'If' and 'Let' are already handled.
|
||||
error("Unknown instruction");
|
||||
|
||||
Reference in New Issue
Block a user