Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
binji committed May 21, 2020
1 parent bfd1690 commit 962344d
Show file tree
Hide file tree
Showing 20 changed files with 93 additions and 90 deletions.
5 changes: 3 additions & 2 deletions docs/wast2json.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,14 @@ types are supported, with the given JSON format:
| "f32" | `{"type": "f32", "value": <string>}` |
| "f64" | `{"type": "f64", "value": <string>}` |

The `reference-types` proposal adds three more valid types:
The `reference-types` proposal adds three more valid types. In each case the
value can either be an integer or `"null"`:

| type | JSON format |
| - | - |
| "externref" | `{"type": "externref", "value": <string>}` |
| "funcref" | `{"type": "funcref", "value": <string>}` |

| "exnref" | `{"type": "exnref", "value": <string>}` |

The `simd` proposal adds another type, with a slightly different syntax.

Expand Down
10 changes: 5 additions & 5 deletions src/binary-reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -410,11 +410,11 @@ bool BinaryReader::IsConcreteType(Type type) {
case Type::V128:
return options_.features.simd_enabled();

case Type::Funcref:
case Type::Externref:
case Type::FuncRef:
case Type::ExternRef:
return options_.features.reference_types_enabled();

case Type::Exnref:
case Type::ExnRef:
return options_.features.exceptions_enabled();

default:
Expand Down Expand Up @@ -2197,7 +2197,7 @@ Result BinaryReader::ReadElemSection(Offset section_size) {
if ((flags & (SegPassive | SegExplicitIndex)) == SegExplicitIndex) {
CHECK_RESULT(ReadIndex(&table_index, "elem segment table index"));
}
Type elem_type = Type::Funcref;
Type elem_type = Type::FuncRef;

CALLBACK(BeginElemSegment, i, table_index, flags);

Expand All @@ -2217,7 +2217,7 @@ Result BinaryReader::ReadElemSection(Offset section_size) {
ERROR_UNLESS(kind == ExternalKind::Func,
"segment elem type must be func (%s)",
elem_type.GetName());
elem_type = Type::Funcref;
elem_type = Type::FuncRef;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/binary-writer-spec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,15 @@ void BinaryWriterSpec::WriteConst(const Const& const_) {
WriteF64(const_.f64_bits(), const_.expected_nan());
break;

case Type::Funcref: {
case Type::FuncRef: {
WriteString("funcref");
WriteSeparator();
WriteKey("value");
WriteRefBits(const_.ref_bits());
break;
}

case Type::Externref: {
case Type::ExternRef: {
WriteString("externref");
WriteSeparator();
WriteKey("value");
Expand Down
6 changes: 3 additions & 3 deletions src/decompiler-ls.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ inline const char *GetDecompTypeName(Type t) {
case Type::F64: return "double";
case Type::V128: return "simd";
case Type::Func: return "func";
case Type::Funcref: return "funcref";
case Type::Externref: return "externref";
case Type::Exnref: return "exnref";
case Type::FuncRef: return "funcref";
case Type::ExternRef: return "externref";
case Type::ExnRef: return "exnref";
case Type::Void: return "void";
default: return "ILLEGAL";
}
Expand Down
2 changes: 2 additions & 0 deletions src/interp/interp-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ template <typename T> void RequireType(ValueType type) {
}

inline bool TypesMatch(ValueType expected, ValueType actual) {
// Currently there is no subtyping, so expected and actual must match
// exactly. In the future this may be expanded.
return expected == actual;
}

Expand Down
6 changes: 3 additions & 3 deletions src/interp/interp-util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ std::string TypedValueToString(const TypedValue& tv) {
case Type::I16: // For SIMD lane.
return StringPrintf("i16:%u", tv.value.Get<u32>() & 0xffff);

case Type::Funcref:
case Type::FuncRef:
return StringPrintf("funcref:%" PRIzd, tv.value.Get<Ref>().index);

case Type::Externref:
case Type::ExternRef:
return StringPrintf("externref:%" PRIzd, tv.value.Get<Ref>().index);

case Type::Exnref:
case Type::ExnRef:
return StringPrintf("exnref:%" PRIzd, tv.value.Get<Ref>().index);

case Type::Func:
Expand Down
12 changes: 6 additions & 6 deletions src/interp/interp-wasm-c-api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,9 @@ static ValueType ToWabtValueType(wasm_valkind_t kind) {
case WASM_F64:
return ValueType::F64;
case WASM_ANYREF:
return ValueType::Externref;
return ValueType::ExternRef;
case WASM_FUNCREF:
return ValueType::Funcref;
return ValueType::FuncRef;
default:
TRACE("unexpected wasm_valkind_t: %d", kind);
WABT_UNREACHABLE;
Expand All @@ -330,9 +330,9 @@ static wasm_valkind_t FromWabtValueType(ValueType type) {
return WASM_F32;
case ValueType::F64:
return WASM_F64;
case ValueType::Externref:
case ValueType::ExternRef:
return WASM_ANYREF;
case ValueType::Funcref:
case ValueType::FuncRef:
return WASM_FUNCREF;
default:
WABT_UNREACHABLE;
Expand Down Expand Up @@ -429,13 +429,13 @@ static wasm_val_t FromWabtValue(Store& store, const TypedValue& tv) {
out_value.kind = WASM_F64;
out_value.of.f64 = tv.value.Get<f64>();
break;
case Type::Funcref: {
case Type::FuncRef: {
Ref ref = tv.value.Get<Ref>();
out_value.kind = WASM_FUNCREF;
out_value.of.ref = new wasm_func_t(store.UnsafeGet<Func>(ref));
break;
}
case Type::Externref: {
case Type::ExternRef: {
Ref ref = tv.value.Get<Ref>();
out_value.kind = WASM_ANYREF;
out_value.of.ref = new wasm_foreign_t(store.UnsafeGet<Foreign>(ref));
Expand Down
12 changes: 6 additions & 6 deletions src/interp/interp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ bool Store::HasValueType(Ref ref, ValueType type) const {
if (!IsValid(ref)) {
return false;
}
if (type == ValueType::Externref) {
if (type == ValueType::ExternRef) {
return true;
}
if (ref == Ref::Null) {
Expand All @@ -213,10 +213,10 @@ bool Store::HasValueType(Ref ref, ValueType type) const {

Object* obj = objects_.Get(ref.index).get();
switch (type) {
case ValueType::Funcref:
case ValueType::FuncRef:
return obj->kind() == ObjectKind::DefinedFunc ||
obj->kind() == ObjectKind::HostFunc;
case ValueType::Exnref: // TODO
case ValueType::ExnRef: // TODO
return false;
default:
return false;
Expand Down Expand Up @@ -2197,9 +2197,9 @@ std::string Thread::TraceSource::Pick(Index index, Instr instr) {
v.u32(2), v.u32(3));
}

case ValueType::Funcref: reftype = "funcref"; break;
case ValueType::Externref: reftype = "externref"; break;
case ValueType::Exnref: reftype = "exnref"; break;
case ValueType::FuncRef: reftype = "funcref"; break;
case ValueType::ExternRef: reftype = "externref"; break;
case ValueType::ExnRef: reftype = "exnref"; break;

default:
WABT_UNREACHABLE;
Expand Down
2 changes: 1 addition & 1 deletion src/ir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ void Var::Destroy() {
uint8_t ElemSegment::GetFlags(const Module* module) const {
uint8_t flags = 0;

bool all_ref_func = elem_type == Type::Funcref;
bool all_ref_func = elem_type == Type::FuncRef;

switch (kind) {
case SegmentKind::Active: {
Expand Down
8 changes: 4 additions & 4 deletions src/ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ struct Const {
// Only used for expectations. (e.g. wast assertions)
void set_f32(ExpectedNan nan) { set_f32(0); set_expected_nan(0, nan); }
void set_f64(ExpectedNan nan) { set_f64(0); set_expected_nan(0, nan); }
void set_funcref() { From<uintptr_t>(Type::Funcref, 0); }
void set_externref(uintptr_t x) { From(Type::Externref, x); }
void set_funcref() { From<uintptr_t>(Type::FuncRef, 0); }
void set_externref(uintptr_t x) { From(Type::ExternRef, x); }
void set_null(Type type) { From<uintptr_t>(type, kRefNullBits); }

bool is_expected_nan(int lane = 0) const {
Expand Down Expand Up @@ -719,7 +719,7 @@ struct Global {

struct Table {
explicit Table(string_view name)
: name(name.to_string()), elem_type(Type::Funcref) {}
: name(name.to_string()), elem_type(Type::FuncRef) {}

std::string name;
Limits elem_limits;
Expand All @@ -732,7 +732,7 @@ enum class ElemExprKind {
};

struct ElemExpr {
ElemExpr() : kind(ElemExprKind::RefNull), type(Type::Funcref) {}
ElemExpr() : kind(ElemExprKind::RefNull), type(Type::FuncRef) {}
explicit ElemExpr(Var var) : kind(ElemExprKind::RefFunc), var(var) {}
explicit ElemExpr(Type type) : kind(ElemExprKind::RefNull), type(type) {}

Expand Down
14 changes: 7 additions & 7 deletions src/lexer-keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ elem, TokenType::Elem
else, TokenType::Else, Opcode::Else
end, TokenType::End, Opcode::End
event, TokenType::Event
exn, Type::Exnref, TokenType::Exn
exnref, Type::Exnref
extern, Type::Externref, TokenType::Extern
externref, Type::Externref
exn, Type::ExnRef, TokenType::Exn
exnref, Type::ExnRef
extern, Type::ExternRef, TokenType::Extern
externref, Type::ExternRef
export, TokenType::Export
f32.abs, TokenType::Unary, Opcode::F32Abs
f32.add, TokenType::Binary, Opcode::F32Add
Expand Down Expand Up @@ -152,8 +152,8 @@ f64x2.sqrt, TokenType::Unary, Opcode::F64X2Sqrt
f64x2.sub, TokenType::Binary, Opcode::F64X2Sub
f64x2, TokenType::F64X2
field, TokenType::Field
funcref, Type::Funcref
func, Type::Funcref, TokenType::Func
funcref, Type::FuncRef
func, Type::FuncRef, TokenType::Func
get, TokenType::Get
global.get, TokenType::GlobalGet, Opcode::GlobalGet
global.set, TokenType::GlobalSet, Opcode::GlobalSet
Expand Down Expand Up @@ -524,7 +524,7 @@ v8x16.load_splat, TokenType::Load, Opcode::V8X16LoadSplat
v8x16.shuffle, TokenType::SimdShuffleOp, Opcode::V8X16Shuffle
v8x16.swizzle, TokenType::Binary, Opcode::V8X16Swizzle
# Deprecated names.
anyfunc, Type::Funcref
anyfunc, Type::FuncRef
f32.convert_s/i32, TokenType::Convert, Opcode::F32ConvertI32S
f32.convert_s/i64, TokenType::Convert, Opcode::F32ConvertI64S
f32.convert_u/i32, TokenType::Convert, Opcode::F32ConvertI32U
Expand Down
14 changes: 7 additions & 7 deletions src/prebuilt/lexer-keywords.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ Perfect_Hash::InWordSet (const char *str, size_t len)
{"mut", TokenType::Mut},
{""}, {""},
#line 49 "src/lexer-keywords.txt"
{"exn", Type::Exnref, TokenType::Exn},
{"exn", Type::ExnRef, TokenType::Exn},
#line 127 "src/lexer-keywords.txt"
{"f64.ne", TokenType::Compare, Opcode::F64Ne},
#line 77 "src/lexer-keywords.txt"
Expand All @@ -216,7 +216,7 @@ Perfect_Hash::InWordSet (const char *str, size_t len)
{"event", TokenType::Event},
{""},
#line 50 "src/lexer-keywords.txt"
{"exnref", Type::Exnref},
{"exnref", Type::ExnRef},
{""},
#line 119 "src/lexer-keywords.txt"
{"f64.le", TokenType::Compare, Opcode::F64Le},
Expand All @@ -233,10 +233,10 @@ Perfect_Hash::InWordSet (const char *str, size_t len)
#line 488 "src/lexer-keywords.txt"
{"result", TokenType::Result},
#line 155 "src/lexer-keywords.txt"
{"funcref", Type::Funcref},
{"funcref", Type::FuncRef},
{""}, {""}, {""},
#line 51 "src/lexer-keywords.txt"
{"extern", Type::Externref, TokenType::Extern},
{"extern", Type::ExternRef, TokenType::Extern},
#line 492 "src/lexer-keywords.txt"
{"return", TokenType::Return, Opcode::Return},
#line 504 "src/lexer-keywords.txt"
Expand Down Expand Up @@ -266,7 +266,7 @@ Perfect_Hash::InWordSet (const char *str, size_t len)
#line 73 "src/lexer-keywords.txt"
{"f32.min", TokenType::Binary, Opcode::F32Min},
#line 52 "src/lexer-keywords.txt"
{"externref", Type::Externref},
{"externref", Type::ExternRef},
{""}, {""}, {""}, {""}, {""}, {""},
#line 398 "src/lexer-keywords.txt"
{"i64.store32", TokenType::Store, Opcode::I64Store32},
Expand Down Expand Up @@ -297,7 +297,7 @@ Perfect_Hash::InWordSet (const char *str, size_t len)
#line 205 "src/lexer-keywords.txt"
{"i32.and", TokenType::Binary, Opcode::I32And},
#line 156 "src/lexer-keywords.txt"
{"func", Type::Funcref, TokenType::Func},
{"func", Type::FuncRef, TokenType::Func},
{""}, {""},
#line 153 "src/lexer-keywords.txt"
{"f64x2", TokenType::F64X2},
Expand Down Expand Up @@ -977,7 +977,7 @@ Perfect_Hash::InWordSet (const char *str, size_t len)
{"i32.atomic.rmw8.cmpxchg_u", TokenType::AtomicRmwCmpxchg, Opcode::I32AtomicRmw8CmpxchgU},
{""}, {""},
#line 527 "src/lexer-keywords.txt"
{"anyfunc", Type::Funcref},
{"anyfunc", Type::FuncRef},
{""}, {""}, {""}, {""}, {""},
#line 474 "src/lexer-keywords.txt"
{"memory", TokenType::Memory},
Expand Down
4 changes: 2 additions & 2 deletions src/shared-validator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Result SharedValidator::OnTable(const Location& loc,
if (limits.is_shared) {
result |= PrintError(loc, "tables may not be shared");
}
if (elem_type != Type::Funcref &&
if (elem_type != Type::FuncRef &&
!options_.features.reference_types_enabled()) {
result |= PrintError(loc, "tables must have funcref type");
}
Expand Down Expand Up @@ -220,7 +220,7 @@ Result SharedValidator::OnGlobalInitExpr_RefFunc(const Location& loc,
Result result = Result::Ok;
result |= CheckFuncIndex(func_var);
init_expr_funcs_.push_back(func_var);
result |= CheckType(loc, Type::Funcref, globals_.back().type,
result |= CheckType(loc, Type::FuncRef, globals_.back().type,
"global initializer expression");
return result;
}
Expand Down
6 changes: 3 additions & 3 deletions src/test-interp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ TEST_F(InterpGCTest, Collect_Basic) {
}

TEST_F(InterpGCTest, Collect_GlobalCycle) {
auto gt = GlobalType{ValueType::Externref, Mutability::Var};
auto gt = GlobalType{ValueType::ExternRef, Mutability::Var};
auto g1 = Global::New(store_, gt, Value::Make(Ref::Null));
auto g2 = Global::New(store_, gt, Value::Make(g1->self()));
g1->Set(store_, g2->self());
Expand All @@ -593,7 +593,7 @@ TEST_F(InterpGCTest, Collect_GlobalCycle) {
}

TEST_F(InterpGCTest, Collect_TableCycle) {
auto tt = TableType{ValueType::Externref, Limits{2}};
auto tt = TableType{ValueType::ExternRef, Limits{2}};
auto t1 = Table::New(store_, tt);
auto t2 = Table::New(store_, tt);
auto t3 = Table::New(store_, tt);
Expand Down Expand Up @@ -645,7 +645,7 @@ TEST_F(InterpGCTest, Collect_InstanceImport) {
auto f = HostFunc::New(store_, FuncType{{}, {}},
[](Thread& thread, const Values&, Values&,
Trap::Ptr*) -> Result { return Result::Ok; });
auto t = Table::New(store_, TableType{ValueType::Funcref, Limits{0}});
auto t = Table::New(store_, TableType{ValueType::FuncRef, Limits{0}});
auto m = Memory::New(store_, MemoryType{Limits{0}});
auto g = Global::New(store_, GlobalType{ValueType::I32, Mutability::Const},
Value::Make(5));
Expand Down
6 changes: 3 additions & 3 deletions src/token.def
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

/* Tokens with no additional data (i.e. bare). */
WABT_TOKEN(Invalid, "Invalid")
WABT_TOKEN(Array, "array")
WABT_TOKEN(AssertExhaustion, "assert_exhaustion")
WABT_TOKEN(AssertInvalid, "assert_invalid")
WABT_TOKEN(AssertMalformed, "assert_malformed")
Expand Down Expand Up @@ -55,6 +56,7 @@ WABT_TOKEN(Result, "result")
WABT_TOKEN(Rpar, ")")
WABT_TOKEN(Shared, "shared")
WABT_TOKEN(Start, "start")
WABT_TOKEN(Struct, "struct")
WABT_TOKEN(Table, "table")
WABT_TOKEN(Then, "then")
WABT_TOKEN(Type, "type")
Expand Down Expand Up @@ -160,7 +162,5 @@ WABT_TOKEN_LAST(Type, ValueType)
WABT_TOKEN(Func, "func")
WABT_TOKEN(Extern, "extern")
WABT_TOKEN(Exn, "exn")
WABT_TOKEN(Struct, "struct")
WABT_TOKEN(Array, "array")
WABT_TOKEN_FIRST(RefKind, Func)
WABT_TOKEN_LAST(RefKind, Array)
WABT_TOKEN_LAST(RefKind, Exn)
Loading

0 comments on commit 962344d

Please sign in to comment.