Skip to content

Commit

Permalink
Use new execution_status
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Jul 10, 2020
1 parent 5987898 commit 33a7a9c
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/fizzy/execute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,16 +276,16 @@ bool invoke_function(

const auto ret = func(instance, std::move(call_args), depth + 1);
// Bubble up traps
if (ret.trapped)
if (ret.trapped())
return false;

const auto num_outputs = func_type.outputs.size();
// NOTE: we can assume these two from validation
assert(num_outputs <= 1);
assert(ret.result.has_value() == (num_outputs == 1));
assert(ret.has_value() == (num_outputs == 1));
// Push back the result
if (num_outputs != 0)
stack.push(*ret.result);
stack.push(ret.value());

return true;
}
Expand Down Expand Up @@ -564,7 +564,7 @@ std::unique_ptr<Instance> instantiate(Module module,
{
const auto funcidx = *instance->module.startfunc;
assert(funcidx < instance->imported_functions.size() + instance->module.funcsec.size());
if (execute(*instance, funcidx, {}).trapped)
if (execute(*instance, funcidx, {}).trapped())
{
// When element section modified imported table, and then start function trapped,
// modifications to the table are not rolled back.
Expand Down Expand Up @@ -604,7 +604,7 @@ execution_result execute(
{
assert(depth >= 0);
if (depth > CallStackLimit)
return {true, {}};
return {execution_result::status::Trapped, 0};

if (func_idx < instance.imported_functions.size())
return instance.imported_functions[func_idx].function(instance, std::move(args), depth);
Expand Down Expand Up @@ -1462,10 +1462,11 @@ execution_result execute(
end:
assert(pc == &code.instructions[code.instructions.size()] || trap);
if (trap)
return {execution_result::status::Trapped, 0};
if (stack.size() == 0)
return {execution, std::nullopt};
return {execution_result::status::WithoutResult, 0};
else
return {trap, stack.pop()};
return {execution_result::status::WithResult, stack.pop()};
}

std::vector<ExternalFunction> resolve_imported_functions(
Expand Down

0 comments on commit 33a7a9c

Please sign in to comment.