Skip to content

Commit

Permalink
Print error message
Browse files Browse the repository at this point in the history
- fix 2 typos (uint16_t to Walrus::ByteCodeStackOffset)

- fix 1 typo (because of it 3 tests failed, altough it was
  unnoticable hence the error wasn't caught)

- refactor nested if...else to switch...case

- print error message before exit

- make string() operator for Value class
  • Loading branch information
GorogPeter committed Aug 30, 2023
1 parent 89c3d0b commit 099a77a
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 43 deletions.
4 changes: 2 additions & 2 deletions src/parser/WASMParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1703,7 +1703,7 @@ class WASMBinaryReader : public wabt::WASMBinaryReaderDelegate {
ASSERT(peekVMStackValueType() == Walrus::Value::Type::I32);
auto stackPos = popVMStack();
size_t pos = m_currentFunction->currentByteCodeSize();
pushByteCode(Walrus::JumpIfFalse(stackPos), WASMOpcode::BrIfOpcode);
pushByteCode(Walrus::JumpIfFalse(stackPos, sizeof(Walrus::JumpIfFalse) + sizeof(Walrus::End) + sizeof(Walrus::ByteCodeStackOffset) * m_currentFunctionType->result().size()), WASMOpcode::BrIfOpcode);
for (size_t i = 0; i < m_currentFunctionType->result().size(); i++) {
ASSERT((m_vmStack.rbegin() + i)->valueType() == m_currentFunctionType->result()[m_currentFunctionType->result().size() - i - 1]);
}
Expand Down Expand Up @@ -1848,7 +1848,7 @@ class WASMBinaryReader : public wabt::WASMBinaryReaderDelegate {
if (tagIndex != std::numeric_limits<Index>::max()) {
auto functionType = m_result.m_functionTypes[m_result.m_tagTypes[tagIndex]->sigIndex()];
auto& param = functionType->param();
m_currentFunction->expandByteCode(sizeof(uint16_t) * param.size());
m_currentFunction->expandByteCode(sizeof(Walrus::ByteCodeStackOffset) * param.size());
Walrus::Throw* code = m_currentFunction->peekByteCode<Walrus::Throw>(pos);
for (size_t i = 0; i < param.size(); i++) {
code->dataOffsets()[param.size() - i - 1] = (m_vmStack.rbegin() + i)->position();
Expand Down
20 changes: 20 additions & 0 deletions src/runtime/Value.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,26 @@ class Value {
return false;
}

operator std::string() const
{
switch (m_type) {
case I32:
return std::to_string(asI32());
case I64:
return std::to_string(asI64());
case F32:
return std::to_string(asF32());
case F64:
return std::to_string(asF64());
case FuncRef:
case ExternRef:
return std::to_string((size_t)(asExternal()));
default:
ASSERT_NOT_REACHED();
return "";
}
}

private:
union {
int32_t m_i32;
Expand Down
Loading

0 comments on commit 099a77a

Please sign in to comment.