diff --git a/CMakeLists.txt b/CMakeLists.txt index 16e2add800f..6ac28935a4f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -528,8 +528,10 @@ endif() # Note that we can't emit binaryen.js directly, as there is libbinaryen already # declared earlier, so we create binaryen_wasm/js.js, which must then be copied. if(EMSCRIPTEN) + add_compile_flag("-DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0") + # binaryen.js WebAssembly variant - add_executable(binaryen_wasm ${binaryen_SOURCES}) + add_executable(binaryen_wasm src/binaryen-embind.cpp) target_link_libraries(binaryen_wasm PRIVATE binaryen) target_link_libraries(binaryen_wasm PRIVATE "-sFILESYSTEM") target_link_libraries(binaryen_wasm PRIVATE "-sEXPORT_NAME=Binaryen") @@ -542,12 +544,10 @@ if(EMSCRIPTEN) target_link_libraries(binaryen_wasm PRIVATE "-sSINGLE_FILE") endif() target_link_libraries(binaryen_wasm PRIVATE "-sEXPORT_ES6") - target_link_libraries(binaryen_wasm PRIVATE "-sEXPORTED_RUNTIME_METHODS=stringToUTF8OnStack,stringToAscii") - target_link_libraries(binaryen_wasm PRIVATE "-sEXPORTED_FUNCTIONS=_malloc,_free") - target_link_libraries(binaryen_wasm PRIVATE "--post-js=${CMAKE_CURRENT_SOURCE_DIR}/src/js/binaryen.js-post.js") + target_link_libraries(binaryen_wasm PRIVATE "-lembind") + target_link_libraries(binaryen_wasm PRIVATE "--emit-tsd binaryen.d.ts") target_link_libraries(binaryen_wasm PRIVATE "-msign-ext") target_link_libraries(binaryen_wasm PRIVATE "-mbulk-memory") - target_link_libraries(binaryen_wasm PRIVATE optimized "--closure=1") # TODO: Fix closure warnings! (#5062) target_link_libraries(binaryen_wasm PRIVATE optimized "-Wno-error=closure") if (BYN_ENABLE_LTO) @@ -560,7 +560,7 @@ if(EMSCRIPTEN) install(TARGETS binaryen_wasm DESTINATION ${CMAKE_INSTALL_BINDIR}) # binaryen.js JavaScript variant - add_executable(binaryen_js ${binaryen_SOURCES}) + add_executable(binaryen_js src/binaryen-embind.cpp) target_link_libraries(binaryen_js PRIVATE binaryen) target_link_libraries(binaryen_js PRIVATE "-sWASM=0") target_link_libraries(binaryen_js PRIVATE "-sWASM_ASYNC_COMPILATION=0") @@ -590,14 +590,12 @@ if(EMSCRIPTEN) else() target_link_libraries(binaryen_js PRIVATE "-sEXPORT_ES6=1") endif() - target_link_libraries(binaryen_js PRIVATE "-sEXPORTED_RUNTIME_METHODS=stringToUTF8OnStack,stringToAscii") - target_link_libraries(binaryen_js PRIVATE "-sEXPORTED_FUNCTIONS=_malloc,_free") - target_link_libraries(binaryen_js PRIVATE "--post-js=${CMAKE_CURRENT_SOURCE_DIR}/src/js/binaryen.js-post.js") + target_link_libraries(binaryen_js PRIVATE "-lembind") + target_link_libraries(binaryen_js PRIVATE "--emit-tsd binaryen.d.ts") # js_of_ocaml needs a specified variable with special comment to provide the library to consumers if(JS_OF_OCAML) target_link_libraries(binaryen_js PRIVATE "--extern-pre-js=${CMAKE_CURRENT_SOURCE_DIR}/src/js/binaryen.jsoo-extern-pre.js") endif() - target_link_libraries(binaryen_js PRIVATE optimized "--closure=1") # Currently, js_of_ocaml can only process ES5 code if(JS_OF_OCAML) target_link_libraries(binaryen_js PRIVATE optimized "--closure-args=\"--language_out=ECMASCRIPT5\"") diff --git a/src/binaryen-embind.cpp b/src/binaryen-embind.cpp new file mode 100644 index 00000000000..56ddd755c2f --- /dev/null +++ b/src/binaryen-embind.cpp @@ -0,0 +1,1304 @@ +#include "binaryen-embind.h" +#include "parser/wat-parser.h" +#include "wasm-binary.h" +#include "wasm-builder.h" +#include "wasm-stack.h" +#include "wasm2js.h" +#include +#include + +using namespace emscripten; +using namespace std::string_literals; + +namespace binaryen { +static wasm::PassOptions passOptions = + wasm::PassOptions::getWithDefaultOptimizationOptions(); + +Module::Module() : Module(new wasm::Module()) {} + +Module::Module(wasm::Module* module) : module(module) {} + +const uintptr_t& Module::ptr() const { + return reinterpret_cast(module); +} + +wasm::Block* Module::block(OptionalString name, + ExpressionList children, + std::optional type) const { + return wasm::Builder(*module).makeBlock( + name.isNull() ? nullptr : name.as(), + vecFromJSArray(children, allow_raw_pointers()), + (std::optional)type); +} +wasm::If* Module::if_(wasm::Expression* condition, + wasm::Expression* ifTrue, + wasm::Expression* ifFalse) const { + return wasm::Builder(*module).makeIf(condition, ifTrue, ifFalse); +} +wasm::Loop* Module::loop(OptionalString label, wasm::Expression* body) const { + return wasm::Builder(*module).makeLoop( + label.isNull() || label.isUndefined() ? nullptr : label.as(), + body); +} +wasm::Break* Module::br(const std::string& label, + wasm::Expression* condition, + wasm::Expression* value) const { + return wasm::Builder(*module).makeBreak(label, condition, value); +} +wasm::Switch* Module::switch_(NameList names, + const std::string& defaultName, + wasm::Expression* condition, + wasm::Expression* value) const { + auto strVec = vecFromJSArray(names); + std::vector namesVec(strVec.begin(), strVec.end()); + return wasm::Builder(*module).makeSwitch( + namesVec, defaultName, condition, value); +} +wasm::Call* Module::call(const std::string& name, + ExpressionList operands, + TypeID type) const { + return wasm::Builder(*module).makeCall( + name, + vecFromJSArray(operands, allow_raw_pointers()), + wasm::Type(type)); +} +wasm::CallIndirect* Module::call_indirect(const std::string& table, + wasm::Expression* target, + ExpressionList operands, + TypeID params, + TypeID results) const { + return wasm::Builder(*module).makeCallIndirect( + table, + target, + vecFromJSArray(operands, allow_raw_pointers()), + wasm::Signature(wasm::Type(params), wasm::Type(results))); +} +wasm::Call* Module::return_call(const std::string& name, + ExpressionList operands, + TypeID type) const { + return wasm::Builder(*module).makeCall( + name, + vecFromJSArray(operands, allow_raw_pointers()), + wasm::Type(type), + true); +} +wasm::CallIndirect* Module::return_call_indirect(const std::string& table, + wasm::Expression* target, + ExpressionList operands, + TypeID params, + TypeID results) const { + return wasm::Builder(*module).makeCallIndirect( + table, + target, + vecFromJSArray(operands, allow_raw_pointers()), + wasm::Signature(wasm::Type(params), wasm::Type(results)), + true); +} +wasm::LocalGet* Module::Local::get(uint32_t index, TypeID type) const { + return wasm::Builder(*module).makeLocalGet(index, wasm::Type(type)); +} +wasm::LocalSet* Module::Local::set(uint32_t index, + wasm::Expression* value) const { + return wasm::Builder(*module).makeLocalSet(index, value); +} +wasm::LocalSet* +Module::Local::tee(uint32_t index, wasm::Expression* value, TypeID type) const { + return wasm::Builder(*module).makeLocalTee(index, value, wasm::Type(type)); +} +wasm::GlobalGet* Module::Global::get(const std::string& name, + TypeID type) const { + return wasm::Builder(*module).makeGlobalGet(name, wasm::Type(type)); +} +wasm::GlobalSet* Module::Global::set(const std::string& name, + wasm::Expression* value) const { + return wasm::Builder(*module).makeGlobalSet(name, value); +} +wasm::TableGet* Module::Table::get(const std::string& name, + wasm::Expression* index, + TypeID type) const { + return wasm::Builder(*module).makeTableGet(name, index, wasm::Type(type)); +} +wasm::TableSet* Module::Table::set(const std::string& name, + wasm::Expression* index, + wasm::Expression* value) const { + return wasm::Builder(*module).makeTableSet(name, index, value); +} +wasm::TableSize* Module::Table::size(const std::string& name) const { + return wasm::Builder(*module).makeTableSize(name); +} +wasm::TableGrow* Module::Table::grow(const std::string& name, + wasm::Expression* value, + wasm::Expression* delta) const { + return wasm::Builder(*module).makeTableGrow(name, value, delta); +} +wasm::MemorySize* Module::Memory::size(const std::string& name, + bool memory64) const { + return wasm::Builder(*module).makeMemorySize( + name, + memory64 ? wasm::Builder::MemoryInfo::Memory64 + : wasm::Builder::MemoryInfo::Memory32); +} +wasm::MemoryGrow* Module::Memory::grow(wasm::Expression* value, + const std::string& name, + bool memory64) const { + return wasm::Builder(*module).makeMemoryGrow( + value, + name, + memory64 ? wasm::Builder::MemoryInfo::Memory64 + : wasm::Builder::MemoryInfo::Memory32); +} +wasm::MemoryInit* Module::Memory::init(const std::string& segment, + wasm::Expression* dest, + wasm::Expression* offset, + wasm::Expression* size, + const std::string& name) const { + return wasm::Builder(*module).makeMemoryInit( + segment, dest, offset, size, name); +} +wasm::MemoryCopy* Module::Memory::copy(wasm::Expression* dest, + wasm::Expression* source, + wasm::Expression* size, + const std::string& destMemory, + const std::string& sourceMemory) const { + return wasm::Builder(*module).makeMemoryCopy( + dest, source, size, destMemory, sourceMemory); +} +wasm::MemoryFill* Module::Memory::fill(wasm::Expression* dest, + wasm::Expression* value, + wasm::Expression* size, + const std::string& name) const { + return wasm::Builder(*module).makeMemoryFill(dest, value, size, name); +} +wasm::AtomicNotify* +Module::Memory::Atomic::notify(wasm::Expression* ptr, + wasm::Expression* notifyCount, + const std::string& name) const { + return wasm::Builder(*module).makeAtomicNotify(ptr, notifyCount, 0, name); +} +wasm::AtomicWait* +Module::Memory::Atomic::wait32(wasm::Expression* ptr, + wasm::Expression* expected, + wasm::Expression* timeout, + const std::string& name) const { + return wasm::Builder(*module).makeAtomicWait( + ptr, expected, timeout, wasm::Type(wasm::Type::i32), 0, name); +} +wasm::AtomicWait* +Module::Memory::Atomic::wait64(wasm::Expression* ptr, + wasm::Expression* expected, + wasm::Expression* timeout, + const std::string& name) const { + return wasm::Builder(*module).makeAtomicWait( + ptr, expected, timeout, wasm::Type(wasm::Type::i64), 0, name); +} +wasm::DataDrop* Module::Data::drop(const std::string& segment) const { + return wasm::Builder(*module).makeDataDrop(segment); +} +wasm::Load* Module::I32::load(uint32_t offset, + uint32_t align, + wasm::Expression* ptr, + const std::string& name) const { + return wasm::Builder(*module).makeLoad( + 4, true, offset, align, ptr, wasm::Type(wasm::Type::i32), name); +} +wasm::Load* Module::I32::load8_s(uint32_t offset, + uint32_t align, + wasm::Expression* ptr, + const std::string& name) const { + return wasm::Builder(*module).makeLoad( + 1, true, offset, align, ptr, wasm::Type(wasm::Type::i32), name); +} +wasm::Load* Module::I32::load8_u(uint32_t offset, + uint32_t align, + wasm::Expression* ptr, + const std::string& name) const { + return wasm::Builder(*module).makeLoad( + 1, false, offset, align, ptr, wasm::Type(wasm::Type::i32), name); +} +wasm::Load* Module::I32::load16_s(uint32_t offset, + uint32_t align, + wasm::Expression* ptr, + const std::string& name) const { + return wasm::Builder(*module).makeLoad( + 2, true, offset, align, ptr, wasm::Type(wasm::Type::i32), name); +} +wasm::Load* Module::I32::load16_u(uint32_t offset, + uint32_t align, + wasm::Expression* ptr, + const std::string& name) const { + return wasm::Builder(*module).makeLoad( + 2, false, offset, align, ptr, wasm::Type(wasm::Type::i32), name); +} +wasm::Store* Module::I32::store(uint32_t offset, + uint32_t align, + wasm::Expression* ptr, + wasm::Expression* value, + const std::string& name) const { + return wasm::Builder(*module).makeStore( + 4, offset, align, ptr, value, wasm::Type(wasm::Type::i32), name); +} +wasm::Store* Module::I32::store8(uint32_t offset, + uint32_t align, + wasm::Expression* ptr, + wasm::Expression* value, + const std::string& name) const { + return wasm::Builder(*module).makeStore( + 1, offset, align, ptr, value, wasm::Type(wasm::Type::i32), name); +} +wasm::Store* Module::I32::store16(uint32_t offset, + uint32_t align, + wasm::Expression* ptr, + wasm::Expression* value, + const std::string& name) const { + return wasm::Builder(*module).makeStore( + 2, offset, align, ptr, value, wasm::Type(wasm::Type::i32), name); +} +wasm::Const* Module::I32::const_(uint32_t x) const { + return wasm::Builder(*module).makeConst(x); +} +wasm::Binary* Module::I32::add(wasm::Expression* left, + wasm::Expression* right) const { + return wasm::Builder(*module).makeBinary( + wasm::BinaryOp::AddInt32, left, right); +} +wasm::Drop* Module::drop(wasm::Expression* value) { + return wasm::Builder(*module).makeDrop(value); +} +wasm::Return* Module::return_(wasm::Expression* value) { + return wasm::Builder(*module).makeReturn(value); +} +wasm::Nop* Module::nop() { return wasm::Builder(*module).makeNop(); } +wasm::Unreachable* Module::unreachable() { + return wasm::Builder(*module).makeUnreachable(); +} + +static std::mutex ModuleAddFunctionMutex; + +wasm::Function* Module::addFunction(const std::string& name, + TypeID params, + TypeID results, + TypeList varTypes, + wasm::Expression* body) { + auto* ret = new wasm::Function; + ret->setExplicitName(name); + ret->type = wasm::Signature(wasm::Type(params), wasm::Type(results)); + ret->vars = vecFromJSArray(varTypes); + ret->body = body; + + // Lock. This can be called from multiple threads at once, and is a + // point where they all access and modify the module. + { + std::lock_guard lock(ModuleAddFunctionMutex); + module->addFunction(ret); + } + + return ret; +} +wasm::Export* Module::addFunctionExport(const std::string& internalName, + const std::string& externalName) { + auto* ret = + new wasm::Export(externalName, wasm::ExternalKind::Function, internalName); + module->addExport(ret); + return ret; +} + +Binary Module::emitBinary() { + wasm::BufferWithRandomAccess buffer; + wasm::WasmBinaryWriter writer(module, buffer, passOptions); + writer.setNamesSection(passOptions.debugInfo); + std::ostringstream os; + // TODO: Source map + writer.write(); + return val::global("Uint8Array") + .call("from", val(typed_memory_view(buffer.size(), buffer.data()))); +} +std::string Module::emitText() { + std::ostringstream os; + bool colors = Colors::isEnabled(); + Colors::setEnabled(false); // do not use colors for writing + os << *module; + Colors::setEnabled(colors); // restore colors state + return os.str(); +} +std::string Module::emitStackIR() { + std::ostringstream os; + bool colors = Colors::isEnabled(); + Colors::setEnabled(false); // do not use colors for writing + wasm::printStackIR(os, module, passOptions); + Colors::setEnabled(colors); // restore colors state + auto str = os.str(); + const size_t len = str.length() + 1; + char* output = (char*)malloc(len); + std::copy_n(str.c_str(), len, output); + return output; +} +std::string Module::emitAsmjs() { + wasm::Wasm2JSBuilder::Flags flags; + wasm::Wasm2JSBuilder wasm2js(flags, passOptions); + auto asmjs = wasm2js.processWasm(module); + wasm::JSPrinter jser(true, true, asmjs); + wasm::Output out("", wasm::Flags::Text); // stdout + wasm::Wasm2JSGlue glue(*module, out, flags, "asmFunc"); + glue.emitPre(); + jser.printAst(); + std::string text(jser.buffer); + glue.emitPost(); + return text; +} + +bool Module::validate() { return wasm::WasmValidator().validate(*module); } +void Module::optimize() { + wasm::PassRunner passRunner(module); + passRunner.options = passOptions; + passRunner.addDefaultOptimizationPasses(); + passRunner.run(); +} +void Module::optimizeFunction(wasm::Function* func) { + wasm::PassRunner passRunner(module); + passRunner.options = passOptions; + passRunner.addDefaultFunctionOptimizationPasses(); + passRunner.runOnFunction(func); +} + +void Module::dispose() { delete this; } + +Module* parseText(const std::string& text) { + auto* wasm = new wasm::Module; + auto parsed = wasm::WATParser::parseModule(*wasm, text); + if (auto* err = parsed.getErr()) { + wasm::Fatal() << err->msg << "\n"; + } + return new Module(wasm); +} + +TypeID createType(TypeList types) { + auto typeIdsVec = vecFromJSArray(types); + std::vector typesVec(typeIdsVec.begin(), typeIdsVec.end()); + return wasm::Type(typesVec).getID(); +} + +val getExpressionInfo(wasm::Expression* expr) { + using namespace wasm; + + val info = val::object(); + info.set("id", val(expr->_id)); + info.set("type", (binaryen::TypeID)expr->type.getID()); + +#define DELEGATE_ID expr->_id + +#define DELEGATE_START(id) [[maybe_unused]] auto* cast = expr->cast(); + +#define DELEGATE_FIELD_CHILD(id, field) info.set(#field, cast->field); +#define DELEGATE_FIELD_OPTIONAL_CHILD(id, field) info.set(#field, cast->field); +#define DELEGATE_FIELD_CHILD_VECTOR(id, field) \ + info.set(#field, \ + val::array(std::vector(cast->field.begin(), \ + cast->field.end()))); +#define DELEGATE_FIELD_INT(id, field) info.set(#field, cast->field); +#define DELEGATE_FIELD_INT_ARRAY(id, field) +#define DELEGATE_FIELD_INT_VECTOR(id, field) +#define DELEGATE_FIELD_BOOL(id, field) info.set(#field, cast->field); +#define DELEGATE_FIELD_BOOL_VECTOR(id, field) +#define DELEGATE_FIELD_ENUM(id, field, type) +#define DELEGATE_FIELD_LITERAL(id, field) +#define DELEGATE_FIELD_NAME(id, field) info.set(#field, cast->field.toString()); +#define DELEGATE_FIELD_NAME_VECTOR(id, field) \ + { \ + std::vector vec; \ + vec.reserve(cast->field.size()); \ + std::transform(cast->field.begin(), \ + cast->field.end(), \ + std::back_inserter(vec), \ + [](wasm::Name name) { return name.toString(); }); \ + info.set(#field, val::array(vec)); \ + } +#define DELEGATE_FIELD_SCOPE_NAME_DEF(id, field) \ + info.set(#field, \ + cast->field.size() ? val(cast->field.toString()) : val::null()); +#define DELEGATE_FIELD_SCOPE_NAME_USE(id, field) DELEGATE_FIELD_NAME(id, field) +#define DELEGATE_FIELD_SCOPE_NAME_USE_VECTOR(id, field) \ + DELEGATE_FIELD_NAME_VECTOR(id, field) +#define DELEGATE_FIELD_TYPE(id, field) +#define DELEGATE_FIELD_TYPE_VECTOR(id, field) +#define DELEGATE_FIELD_HEAPTYPE(id, field) +#define DELEGATE_FIELD_ADDRESS(id, field) + +#include "wasm-delegations-fields.def" + + switch (expr->_id) { + case Expression::Id::BlockId: { + auto* cast = expr->cast(); + info.set("children", + val::array(std::vector(cast->list.begin(), + cast->list.end()))); + break; + } + case Expression::Id::SwitchId: { + auto* cast = expr->cast(); + + info.set("defaultName", cast->default_.toString()); + + std::vector vec; + vec.reserve(cast->targets.size()); + std::transform(cast->targets.begin(), + cast->targets.end(), + std::back_inserter(vec), + [](wasm::Name name) { return name.toString(); }); + info.set("names", val::array(vec)); + break; + } + case Expression::Id::CallIndirectId: { + auto* cast = expr->cast(); + wasm::Signature signature = cast->heapType.getSignature(); + info.set("params", binaryen::TypeID(signature.params.getID())); + info.set("results", binaryen::TypeID(signature.results.getID())); + break; + } + case Expression::Id::LocalSetId: { + auto* cast = expr->cast(); + info.set("isTee", cast->isTee()); + break; + } + default: + break; + } + + return info; +} + +std::string toText(wasm::Expression* expr) { + std::ostringstream os; + bool colors = Colors::isEnabled(); + Colors::setEnabled(false); // do not use colors for writing + os << *expr << '\n'; + Colors::setEnabled(colors); // restore colors state + return os.str(); +} + +void finalize(wasm::Expression* expr) { wasm::ReFinalizeNode().visit(expr); } +} // namespace binaryen + +namespace { +static std::string uncapitalize(std::string str, int i) { + str[i] = std::tolower(str[i]); + return str; +} + +static std::string capitalize(std::string str, int i) { + str[i] = std::toupper(str[i]); + return str; +} + +static std::string normalize(std::string str) { + if (str.back() == '_') + str.pop_back(); + return str; +} + +static std::string unboolenize(std::string str) { + if (str.substr(0, 2) == "is") + str = uncapitalize(str, 2).substr(2); + return str; +} + +static std::string unpluralize(std::string str) { + if (str == "children") + str = str.substr(0, 5); + else if (str.back() == 's') { + str.pop_back(); + if (str.substr(str.size() - 2, 2) == "ie") + str = str.substr(0, str.size() - 2) + "y"; + } + return str; +} + +#define GETTER_NAME(field) capitalize("get"s + field, 3) +#define BOOL_GETTER_NAME(field) capitalize("is"s + field, 2) +#define SETTER_NAME(field) capitalize("set"s + field, 3) + +#define ACCESSOR(target, name, accessor, ...) \ + target.class_function(name, +accessor, ##__VA_ARGS__) \ + .function(name, +accessor, ##__VA_ARGS__); + +#define FIELD_G(target, id, field, name, getterName, type, cppToJs, ...) \ + { \ + auto getter = [](const wasm::id& expr) { return cppToJs(expr.field); }; \ + ACCESSOR(target, getterName, getter, ##__VA_ARGS__); \ + target.property(name, +getter, ##__VA_ARGS__); \ + } + +#define FIELD_CONST(target, id, field, name, type, cppToJs, ...) \ + { \ + std::string propName = normalize(name); \ + std::string getterName = GETTER_NAME(propName); \ + FIELD_G(target, \ + id, \ + field, \ + propName.c_str(), \ + getterName.c_str(), \ + type, \ + jsToCpp, \ + ##__VA_ARGS__); \ + } + +#define FIELD_GS(target, \ + id, \ + field, \ + name, \ + getterName, \ + setterName, \ + type, \ + jsToCpp, \ + cppToJs, \ + ...) \ + { \ + auto getter = [](const wasm::id& expr) { \ + return (type)(cppToJs(expr.field)); \ + }; \ + auto setter = [](wasm::id& expr, type value) { \ + expr.field = jsToCpp(value); \ + }; \ + ACCESSOR(target, getterName, getter, ##__VA_ARGS__); \ + ACCESSOR(target, setterName, setter, ##__VA_ARGS__); \ + target.property(name, +getter, +setter, ##__VA_ARGS__); \ + } + +#define FIELD(target, id, field, name, type, jsToCpp, cppToJs, ...) \ + { \ + std::string propName = normalize(name); \ + std::string getterName = GETTER_NAME(propName); \ + std::string setterName = SETTER_NAME(propName); \ + FIELD_GS(target, \ + id, \ + field, \ + propName.c_str(), \ + getterName.c_str(), \ + setterName.c_str(), \ + type, \ + jsToCpp, \ + cppToJs, \ + ##__VA_ARGS__); \ + } + +#define FIELD_PROP_G(target, id, field, name, getterName, type, ...) \ + { \ + auto getter = [](const wasm::id& expr) { return expr.field; }; \ + ACCESSOR(target, getterName, getter, ##__VA_ARGS__); \ + target.property(name, &wasm::id::field, ##__VA_ARGS__); \ + } + +#define FIELD_PROP_CONST(target, id, field, name, type, ...) \ + { \ + std::string propName = normalize(name); \ + std::string getterName = GETTER_NAME(propName); \ + FIELD_PROP_G(target, \ + id, \ + field, \ + propName.c_str(), \ + getterName.c_str(), \ + type, \ + ##__VA_ARGS__); \ + } + +#define FIELD_PROP_GS( \ + target, id, field, name, getterName, setterName, type, ...) \ + { \ + auto getter = [](const wasm::id& expr) { return (type)(expr.field); }; \ + auto setter = [](wasm::id& expr, type value) { expr.field = value; }; \ + ACCESSOR(target, getterName, getter, ##__VA_ARGS__); \ + ACCESSOR(target, setterName, setter, ##__VA_ARGS__); \ + target.property(name, &wasm::id::field, ##__VA_ARGS__); \ + } + +#define FIELD_PROP(target, id, field, name, type, ...) \ + { \ + std::string propName = normalize(name); \ + std::string getterName = GETTER_NAME(propName); \ + std::string setterName = SETTER_NAME(propName); \ + FIELD_PROP_GS(target, \ + id, \ + field, \ + propName.c_str(), \ + getterName.c_str(), \ + setterName.c_str(), \ + type, \ + ##__VA_ARGS__); \ + } + +#define FIELD_PROP_BOOL(target, id, field, name, ...) \ + { \ + std::string propName = unboolenize(normalize(name)); \ + std::string getterName = BOOL_GETTER_NAME(propName); \ + std::string setterName = SETTER_NAME(propName); \ + FIELD_PROP_GS(target, \ + id, \ + field, \ + propName.c_str(), \ + getterName.c_str(), \ + setterName.c_str(), \ + bool, \ + ##__VA_ARGS__); \ + } + +#define FIELD_VEC( \ + target, id, field, name, listType, elemType, jsToCpp, cppToJs, ...) \ + { \ + std::string listName = normalize(name); \ + std::string elemName = unpluralize(listName); \ + { \ + std::string getterName = GETTER_NAME(listName); \ + std::string setterName = SETTER_NAME(listName); \ + auto getter = [](const wasm::id& expr) { \ + std::vector valVec; \ + valVec.reserve(expr.field.size()); \ + std::transform(expr.field.begin(), \ + expr.field.end(), \ + std::back_inserter(valVec), \ + cppToJs); \ + return listType(val::array(valVec)); \ + }; \ + auto setter = [](wasm::id& expr, listType value) { \ + std::vector valVec = \ + vecFromJSArray(value, ##__VA_ARGS__); \ + expr.field.resize(valVec.size()); \ + std::transform( \ + valVec.begin(), valVec.end(), expr.field.begin(), jsToCpp); \ + }; \ + ACCESSOR(target, getterName.c_str(), getter, ##__VA_ARGS__); \ + ACCESSOR(target, setterName.c_str(), setter, ##__VA_ARGS__); \ + target.property(listName.c_str(), +getter, +setter, ##__VA_ARGS__); \ + } \ + { \ + std::string propName = capitalize("num" + listName, 3); \ + std::string getterName = GETTER_NAME(propName); \ + auto getter = [](const wasm::id& expr) { \ + return uint32_t(expr.field.size()); \ + }; \ + ACCESSOR(target, getterName.c_str(), getter, ##__VA_ARGS__); \ + target.property(propName.c_str(), +getter, ##__VA_ARGS__); \ + } \ + { \ + std::string funcName = capitalize("get" + elemName + "At", 3); \ + auto func = [](const wasm::id& expr, uint32_t index) { \ + assert(index < expr.field.size()); \ + return (elemType)cppToJs(expr.field[index]); \ + }; \ + target.class_function(funcName.c_str(), +func, ##__VA_ARGS__) \ + .function(funcName.c_str(), +func, ##__VA_ARGS__); \ + } \ + { \ + std::string funcName = capitalize("set" + elemName + "At", 3); \ + auto func = [](wasm::id& expr, uint32_t index, elemType elem) { \ + assert(index < expr.field.size()); \ + expr.field[index] = jsToCpp(elem); \ + }; \ + target.class_function(funcName.c_str(), +func, ##__VA_ARGS__) \ + .function(funcName.c_str(), +func, ##__VA_ARGS__); \ + } \ + { \ + std::string funcName = capitalize("append" + elemName, 6); \ + auto func = [](wasm::id& expr, elemType elem) { \ + auto index = expr.field.size(); \ + expr.field.push_back(jsToCpp(elem)); \ + return index; \ + }; \ + target.class_function(funcName.c_str(), +func, ##__VA_ARGS__) \ + .function(funcName.c_str(), +func, ##__VA_ARGS__); \ + } \ + { \ + std::string funcName = capitalize("insert" + elemName + "At", 6); \ + auto func = [](wasm::id& expr, uint32_t index, elemType elem) { \ + expr.field.insertAt(index, jsToCpp(elem)); \ + }; \ + target.class_function(funcName.c_str(), +func, ##__VA_ARGS__) \ + .function(funcName.c_str(), +func, ##__VA_ARGS__); \ + } \ + { \ + std::string funcName = capitalize("remove" + elemName + "At", 6); \ + auto func = [](wasm::id& expr, uint32_t index) { \ + return (elemType)cppToJs(expr.field.removeAt(index)); \ + }; \ + target.class_function(funcName.c_str(), +func, ##__VA_ARGS__) \ + .function(funcName.c_str(), +func, ##__VA_ARGS__); \ + } \ + } +} // namespace + +EMSCRIPTEN_BINDINGS(Binaryen) { + register_type("Uint8Array"); + + register_type("string | null"); + + register_optional(); + + constant("none", wasm::Type(wasm::Type::none).getID()); + constant("i32", wasm::Type(wasm::Type::i32).getID()); + constant("i64", wasm::Type(wasm::Type::i64).getID()); + constant("f32", wasm::Type(wasm::Type::f32).getID()); + constant("f64", wasm::Type(wasm::Type::f64).getID()); + constant("v128", wasm::Type(wasm::Type::v128).getID()); + constant( + "funcref", wasm::Type(wasm::HeapType::func, wasm::Nullable).getID()); + constant( + "externref", wasm::Type(wasm::HeapType::ext, wasm::Nullable).getID()); + constant( + "anyref", wasm::Type(wasm::HeapType::any, wasm::Nullable).getID()); + constant( + "eqref", wasm::Type(wasm::HeapType::eq, wasm::Nullable).getID()); + constant( + "i31ref", wasm::Type(wasm::HeapType::i31, wasm::Nullable).getID()); + constant( + "structref", wasm::Type(wasm::HeapType::struct_, wasm::Nullable).getID()); + constant( + "stringref", wasm::Type(wasm::HeapType::string, wasm::Nullable).getID()); + constant( + "nullref", wasm::Type(wasm::HeapType::none, wasm::Nullable).getID()); + constant( + "nullexternref", wasm::Type(wasm::HeapType::noext, wasm::Nullable).getID()); + constant( + "nullfuncref", wasm::Type(wasm::HeapType::nofunc, wasm::Nullable).getID()); + constant("unreachable", + wasm::Type(wasm::Type::unreachable).getID()); + constant("auto", val::undefined()); + + register_type("number[]"); + + constant("notPacked", wasm::Field::PackedType::not_packed); + constant("i8", wasm::Field::PackedType::i8); + constant("i16", wasm::Field::PackedType::i16); + + auto expressionIds = enum_("ExpressionIds"); + expressionIds.value("Invalid", wasm::Expression::Id::InvalidId); +#define DELEGATE(CLASS_TO_VISIT) \ + expressionIds.value(#CLASS_TO_VISIT, wasm::Expression::Id::CLASS_TO_VISIT##Id) +#include "wasm-delegations.def" + + constant("InvalidId", wasm::Expression::Id::InvalidId); +#define DELEGATE(CLASS_TO_VISIT) \ + constant(#CLASS_TO_VISIT "Id", wasm::Expression::Id::CLASS_TO_VISIT##Id); +#include "wasm-delegations.def" + + class_("Function"); + + class_("Export"); + + class_("Module_Local") // TODO: factory class + .function("get", + &binaryen::Module::Local::get, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()) + .function("set", + &binaryen::Module::Local::set, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()) + .function("get", + &binaryen::Module::Local::tee, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()); + + class_("Module_Global") + .function("get", + &binaryen::Module::Global::get, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()) + .function("set", + &binaryen::Module::Global::set, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()); + + class_("Module_Table") + .function("get", + &binaryen::Module::Table::get, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()) + .function("set", + &binaryen::Module::Table::set, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()) + .function("size", + &binaryen::Module::Table::size, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()) + .function("grow", + &binaryen::Module::Table::grow, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()); + + class_("Module_Memory") + .function("size", + &binaryen::Module::Memory::size, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()) + .function("grow", + &binaryen::Module::Memory::grow, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()) + .function("init", + &binaryen::Module::Memory::init, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()) + .function("copy", + &binaryen::Module::Memory::copy, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()) + .function("fill", + &binaryen::Module::Memory::fill, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()) + .property("atomic", + &binaryen::Module::Memory::atomic, + allow_raw_pointers(), + return_value_policy::reference()); + + class_("Module_Memory_Atomic") + .function("notify", + &binaryen::Module::Memory::Atomic::notify, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()) + .function("wait32", + &binaryen::Module::Memory::Atomic::wait32, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()) + .function("wait64", + &binaryen::Module::Memory::Atomic::wait64, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()); + + class_("Module_Data") + .function("drop", + &binaryen::Module::Data::drop, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()); + + class_("Module_I32") + .function("load", + &binaryen::Module::I32::load, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()) + .function("load8_s", + &binaryen::Module::I32::load8_s, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()) + .function("load8_u", + &binaryen::Module::I32::load8_u, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()) + .function("load16_s", + &binaryen::Module::I32::load16_s, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()) + .function("load16_u", + &binaryen::Module::I32::load16_u, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()) + .function("store", + &binaryen::Module::I32::store, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()) + .function("store8", + &binaryen::Module::I32::store16, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()) + .function("const", + &binaryen::Module::I32::const_, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()) + .function("add", + &binaryen::Module::I32::add, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()); + + class_("Module") + .constructor() + .property("ptr", &binaryen::Module::ptr) + + .function("block", + &binaryen::Module::block, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()) + .function("if", + &binaryen::Module::if_, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()) + .function("loop", + &binaryen::Module::loop, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()) + .function("br", + &binaryen::Module::br, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()) + .function("break", + &binaryen::Module::br, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()) + .function("br_if", + &binaryen::Module::br, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()) + .function("switch", + &binaryen::Module::switch_, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()) + .function( + "call", &binaryen::Module::call, allow_raw_pointers(), nonnull()) + .function("call_indirect", + &binaryen::Module::call_indirect, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()) + .function("return_call", + &binaryen::Module::return_call, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()) + .function("return_call_indirect", + &binaryen::Module::return_call_indirect, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()) + .property("local", + &binaryen::Module::local, + allow_raw_pointers(), + return_value_policy::reference()) + .property("global", + &binaryen::Module::global, + allow_raw_pointers(), + return_value_policy::reference()) + .property("table", + &binaryen::Module::table, + allow_raw_pointers(), + return_value_policy::reference()) + .property("memory", + &binaryen::Module::memory, + allow_raw_pointers(), + return_value_policy::reference()) + .property("data", + &binaryen::Module::data, + allow_raw_pointers(), + return_value_policy::reference()) + .property("i32", + &binaryen::Module::i32, + allow_raw_pointers(), + return_value_policy::reference()) + .function("drop", + &binaryen::Module::drop, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()) + .function("return", + &binaryen::Module::return_, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()) + .function("nop", + &binaryen::Module::nop, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()) + .function("unreachable", + &binaryen::Module::unreachable, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()) + + .function("addFunction", + &binaryen::Module::addFunction, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()) + .function("addFunctionExport", + &binaryen::Module::addFunctionExport, + allow_raw_pointers(), + return_value_policy::reference(), + nonnull()) + + .function("emitBinary", &binaryen::Module::emitBinary) + .function("emitText", &binaryen::Module::emitText) + .function("emitStackIR", &binaryen::Module::emitStackIR) + .function("emitAsmjs", &binaryen::Module::emitAsmjs) + + .function("validate", &binaryen::Module::validate) + .function("optimize", &binaryen::Module::optimize) + .function("optimizeFunction", + &binaryen::Module::optimizeFunction, + allow_raw_pointers()) + + .function( + "dispose", + &binaryen::Module::dispose) // for compatibility, should be removed later + // in favor of Module.delete() + ; + + function( + "parseText", binaryen::parseText, allow_raw_pointers(), nonnull()); + + function("createType", binaryen::createType); + + function( + "getExpressionInfo", binaryen::getExpressionInfo, allow_raw_pointers()); + + auto ExpressionWrapper = + class_("Expression") + .class_function("finalize", &binaryen::finalize, allow_raw_pointers()) + .function("finalize", &binaryen::finalize, allow_raw_pointers()) + .class_function("toText", &binaryen::toText, allow_raw_pointers()) + .function("toText", &binaryen::toText, allow_raw_pointers()); + FIELD_PROP_CONST( + ExpressionWrapper, Expression, _id, "id", wasm::Expression::Id); + FIELD( + ExpressionWrapper, + Expression, + type, + "type", + binaryen::TypeID, + [](binaryen::TypeID value) { return wasm::Type(value); }, + [](wasm::Type value) { return value.getID(); }); + ExpressionWrapper.function( + "valueOf", +[](const wasm::Expression& expr) { + return reinterpret_cast(&expr); + }); + + register_type("Expression[]"); + + register_type("string[]"); + +#define DELEGATE_FIELD_MAIN_START + +#define DELEGATE_FIELD_CASE_START(id) \ + [[maybe_unused]] auto id##Wrapper = \ + class_>(#id).constructor( \ + +[](wasm::Expression* expr) { \ + assert(expr->is()); \ + return static_cast(expr); \ + }, \ + allow_raw_pointers()); \ + { \ + auto getter = [](const wasm::Expression& expr) { return expr._id; }; \ + id##Wrapper.class_function("getId", +getter); \ + }; \ + { \ + auto getter = [](const wasm::Expression& expr) { \ + return binaryen::TypeID(expr.type.getID()); \ + }; \ + auto setter = [](wasm::Expression& expr, binaryen::TypeID value) { \ + expr.type = wasm::Type(value); \ + }; \ + id##Wrapper.class_function("getType", +getter) \ + .class_function("setType", +setter); \ + }; + +#define DELEGATE_FIELD_CASE_END(id) + +#define DELEGATE_FIELD_MAIN_END + +#define DELEGATE_FIELD_CHILD(id, field) \ + FIELD_PROP(id##Wrapper, \ + id, \ + field, \ + #field, \ + wasm::Expression*, \ + allow_raw_pointers(), \ + return_value_policy::reference(), \ + nonnull()); +#define DELEGATE_FIELD_OPTIONAL_CHILD(id, field) \ + FIELD_PROP(id##Wrapper, \ + id, \ + field, \ + #field, \ + wasm::Expression*, \ + allow_raw_pointers(), \ + return_value_policy::reference()); +#define DELEGATE_FIELD_CHILD_VECTOR(id, field) \ + FIELD_VEC( \ + id##Wrapper, \ + id, \ + field, \ + #field, \ + binaryen::ExpressionList, \ + wasm::Expression*, \ + [](wasm::Expression* value) { return value; }, \ + [](wasm::Expression* value) { return value; }, \ + allow_raw_pointers(), \ + return_value_policy::reference()); +#define DELEGATE_FIELD_INT(id, field) \ + FIELD_PROP(id##Wrapper, id, field, #field, uint32_t); +#define DELEGATE_FIELD_INT_ARRAY(id, field) +#define DELEGATE_FIELD_INT_VECTOR(id, field) +#define DELEGATE_FIELD_BOOL(id, field) \ + FIELD_PROP_BOOL(id##Wrapper, id, field, #field); +#define DELEGATE_FIELD_BOOL_VECTOR(id, field) +#define DELEGATE_FIELD_ENUM(id, field, type) +#define DELEGATE_FIELD_LITERAL(id, field) +#define DELEGATE_FIELD_NAME(id, field) \ + FIELD( \ + id##Wrapper, \ + id, \ + field, \ + #field, \ + const std::string&, \ + [](const std::string& value) { return value; }, \ + [](wasm::Name value) { return value.toString(); }); +#define DELEGATE_FIELD_NAME_VECTOR(id, field) \ + FIELD_VEC( \ + id##Wrapper, \ + id, \ + field, \ + #field, \ + binaryen::NameList, \ + std::string, \ + [](const std::string& value) { return value; }, \ + [](wasm::Name value) { return value.toString(); }); +#define DELEGATE_FIELD_SCOPE_NAME_DEF(id, field) \ + FIELD( \ + id##Wrapper, \ + id, \ + field, \ + #field, \ + binaryen::OptionalString, \ + [](binaryen::OptionalString value) { \ + return value.isNull() ? nullptr : value.as(); \ + }, \ + [](wasm::Name value) { \ + return binaryen::OptionalString(value.size() ? val(value.toString()) \ + : val::null()); \ + }); +#define DELEGATE_FIELD_SCOPE_NAME_USE(id, field) DELEGATE_FIELD_NAME(id, field) +#define DELEGATE_FIELD_SCOPE_NAME_USE_VECTOR(id, field) \ + DELEGATE_FIELD_NAME_VECTOR(id, field) +#define DELEGATE_FIELD_TYPE(id, field) \ + FIELD( \ + id##Wrapper, \ + id, \ + field, \ + #field, \ + binaryen::TypeID, \ + [](binaryen::TypeID value) { return wasm::Type(value); }, \ + [](wasm::Type value) { return value.getID(); }); +#define DELEGATE_FIELD_TYPE_VECTOR(id, field) \ + FIELD_VEC( \ + id##Wrapper, \ + id, \ + field, \ + #field, \ + binaryen::TypeList, \ + binaryen::TypeID, \ + [](binaryen::TypeID value) { return wasm::Type(value); }, \ + [](wasm::Type value) { return value.getID(); }); +#define DELEGATE_FIELD_HEAPTYPE(id, field) +#define DELEGATE_FIELD_ADDRESS(id, field) + +#include "wasm-delegations-fields.def" + + // Extensions + { // Block + FIELD_VEC( + BlockWrapper, + Block, + list, + "children", + binaryen::ExpressionList, + wasm::Expression*, + [](wasm::Expression* value) { return value; }, + [](wasm::Expression* value) { return value; }, + allow_raw_pointers(), + return_value_policy::reference()); + } + + { // Switch + FIELD( + SwitchWrapper, + Switch, + default_, + "defaultName", + const std::string&, + [](const std::string& value) { return value; }, + [](wasm::Name value) { return value.toString(); }); + FIELD_VEC( + SwitchWrapper, + Switch, + targets, + "names", + binaryen::NameList, + std::string, + [](const std::string& value) { return value; }, + [](wasm::Name value) { return value.toString(); }); + } + + { // CallIndirect + { + std::string propName = "params"; + std::string getterName = GETTER_NAME(propName); + std::string setterName = SETTER_NAME(propName); + auto getter = [](const wasm::CallIndirect& expr) { + return binaryen::TypeID(expr.heapType.getSignature().params.getID()); + }; + auto setter = [](wasm::CallIndirect& expr, binaryen::TypeID value) { + expr.heapType = wasm::Signature(wasm::Type(value), + expr.heapType.getSignature().results); + }; + ACCESSOR(CallIndirectWrapper, getterName.c_str(), +getter); + ACCESSOR(CallIndirectWrapper, setterName.c_str(), +setter); + CallIndirectWrapper.property(propName.c_str(), +getter, +setter); + } + { + std::string propName = "results"; + std::string getterName = GETTER_NAME(propName); + std::string setterName = SETTER_NAME(propName); + auto getter = [](const wasm::CallIndirect& expr) { + return binaryen::TypeID(expr.heapType.getSignature().results.getID()); + }; + auto setter = [](wasm::CallIndirect& expr, binaryen::TypeID value) { + expr.heapType = wasm::Signature(expr.heapType.getSignature().params, + wasm::Type(value)); + }; + ACCESSOR(CallIndirectWrapper, getterName.c_str(), getter); + ACCESSOR(CallIndirectWrapper, setterName.c_str(), setter); + CallIndirectWrapper.property(propName.c_str(), +getter, +setter); + } + } + + { // LocalSet + { + std::string propName = "tee"; + std::string getterName = BOOL_GETTER_NAME(propName); + auto getter = [](const wasm::LocalSet& expr) { return expr.isTee(); }; + ACCESSOR(LocalSetWrapper, getterName.c_str(), getter); + LocalSetWrapper.property(propName.c_str(), +getter); + } + } +} \ No newline at end of file diff --git a/src/binaryen-embind.h b/src/binaryen-embind.h new file mode 100644 index 00000000000..7d98e1ae906 --- /dev/null +++ b/src/binaryen-embind.h @@ -0,0 +1,193 @@ +#include "wasm.h" +#include + +namespace binaryen { + +EMSCRIPTEN_DECLARE_VAL_TYPE(Binary); + +// https://github.com/emscripten-core/emscripten/issues/24211 +EMSCRIPTEN_DECLARE_VAL_TYPE(OptionalString); + +EMSCRIPTEN_DECLARE_VAL_TYPE(ExpressionList); + +EMSCRIPTEN_DECLARE_VAL_TYPE(NameList); + +using TypeID = uint32_t; + +EMSCRIPTEN_DECLARE_VAL_TYPE(TypeList); + +struct ExpressionFactory { + wasm::Module* module; +}; + +class Module { +private: + wasm::Module* module; + +public: + Module(); + + Module(wasm::Module* module); + + const uintptr_t& ptr() const; + + wasm::Block* block(OptionalString name, + ExpressionList children, + std::optional type) const; + wasm::If* if_(wasm::Expression* condition, + wasm::Expression* ifTrue, + wasm::Expression* ifFalse) const; + wasm::Loop* loop(OptionalString label, wasm::Expression* body) const; + wasm::Break* br(const std::string& label, + wasm::Expression* condition, + wasm::Expression* value) const; + wasm::Switch* switch_(NameList names, + const std::string& defaultName, + wasm::Expression* condition, + wasm::Expression* value) const; + wasm::Call* + call(const std::string&, ExpressionList operands, TypeID type) const; + wasm::CallIndirect* call_indirect(const std::string& table, + wasm::Expression* target, + ExpressionList operands, + TypeID params, + TypeID results) const; + wasm::Call* + return_call(const std::string&, ExpressionList operands, TypeID type) const; + wasm::CallIndirect* return_call_indirect(const std::string& table, + wasm::Expression* target, + ExpressionList operands, + TypeID params, + TypeID results) const; + const struct Local : ExpressionFactory { + wasm::LocalGet* get(uint32_t index, TypeID type) const; + wasm::LocalSet* set(uint32_t index, wasm::Expression* value) const; + wasm::LocalSet* + tee(uint32_t index, wasm::Expression* value, TypeID type) const; + }* local = new Local{module}; + const struct Global : ExpressionFactory { + wasm::GlobalGet* get(const std::string& name, TypeID type) const; + wasm::GlobalSet* set(const std::string& name, + wasm::Expression* value) const; + }* global = new Global{module}; + const struct Table : ExpressionFactory { + wasm::TableGet* + get(const std::string& name, wasm::Expression* index, TypeID type) const; + wasm::TableSet* set(const std::string& name, + wasm::Expression* index, + wasm::Expression* value) const; + wasm::TableSize* size(const std::string& name) const; + wasm::TableGrow* grow(const std::string& name, + wasm::Expression* value, + wasm::Expression* delta) const; + }* table = new Table{module}; + const struct Memory : ExpressionFactory { + wasm::MemorySize* size(const std::string& name, + bool memory64 = false) const; + wasm::MemoryGrow* grow(wasm::Expression* value, + const std::string& name, + bool memory64 = false) const; + wasm::MemoryInit* init(const std::string& segment, + wasm::Expression* dest, + wasm::Expression* offset, + wasm::Expression* size, + const std::string& name) const; + wasm::MemoryCopy* copy(wasm::Expression* dest, + wasm::Expression* source, + wasm::Expression* size, + const std::string& destMemory, + const std::string& sourceMemory) const; + wasm::MemoryFill* fill(wasm::Expression* dest, + wasm::Expression* value, + wasm::Expression* size, + const std::string& name) const; + const struct Atomic : ExpressionFactory { + wasm::AtomicNotify* notify(wasm::Expression* ptr, + wasm::Expression* notifyCount, + const std::string& name) const; + wasm::AtomicWait* wait32(wasm::Expression* ptr, + wasm::Expression* expected, + wasm::Expression* timeout, + const std::string& name) const; + wasm::AtomicWait* wait64(wasm::Expression* ptr, + wasm::Expression* expected, + wasm::Expression* timeout, + const std::string& name) const; + }* atomic = new Atomic{module}; + }* memory = new Memory{{module}}; + const struct Data : ExpressionFactory { + wasm::DataDrop* drop(const std::string& segment) const; + }* data = new Data{module}; + struct I32 : ExpressionFactory { + wasm::Load* load(uint32_t offset, + uint32_t align, + wasm::Expression* ptr, + const std::string& name) const; + wasm::Load* load8_s(uint32_t offset, + uint32_t align, + wasm::Expression* ptr, + const std::string& name) const; + wasm::Load* load8_u(uint32_t offset, + uint32_t align, + wasm::Expression* ptr, + const std::string& name) const; + wasm::Load* load16_s(uint32_t offset, + uint32_t align, + wasm::Expression* ptr, + const std::string& name) const; + wasm::Load* load16_u(uint32_t offset, + uint32_t align, + wasm::Expression* ptr, + const std::string& name) const; + wasm::Store* store(uint32_t offset, + uint32_t align, + wasm::Expression* ptr, + wasm::Expression* value, + const std::string& name) const; + wasm::Store* store8(uint32_t offset, + uint32_t align, + wasm::Expression* ptr, + wasm::Expression* value, + const std::string& name) const; + wasm::Store* store16(uint32_t offset, + uint32_t align, + wasm::Expression* ptr, + wasm::Expression* value, + const std::string& name) const; + wasm::Const* const_(uint32_t x) const; + wasm::Binary* add(wasm::Expression* left, wasm::Expression* right) const; + }* i32 = new I32{module}; + wasm::Drop* drop(wasm::Expression* value); + wasm::Return* return_(wasm::Expression* value); + wasm::Nop* nop(); + wasm::Unreachable* unreachable(); + + wasm::Function* addFunction(const std::string& name, + TypeID params, + TypeID results, + TypeList varTypes, + wasm::Expression* body); + wasm::Export* addFunctionExport(const std::string& internalName, + const std::string& externalName); + + Binary emitBinary(); + std::string emitText(); + std::string emitStackIR(); + std::string emitAsmjs(); + + bool validate(); + void optimize(); + void optimizeFunction(wasm::Function* func); + + void dispose(); +}; + +Module* parseText(const std::string& text); + +TypeID createType(TypeList types); + +emscripten::val getExpressionInfo(wasm::Expression* expr); + +std::string toText(wasm::Expression* expr); +void finalize(wasm::Expression* expr); +}; // namespace binaryen \ No newline at end of file diff --git a/src/wasm-delegations-fields.def b/src/wasm-delegations-fields.def index e40f7a06f02..a43bd267e84 100644 --- a/src/wasm-delegations-fields.def +++ b/src/wasm-delegations-fields.def @@ -46,17 +46,27 @@ // of child pointers. If this is not defined, and DELEGATE_GET_FIELD is, then // DELEGATE_FIELD_CHILD is called on them. // -// DELEGATE_FIELD_INT(id, field) - called for an integer field (bool, enum, -// Index, int32, or int64). +// DELEGATE_FIELD_INT(id, field) - called for an integer field (enum, Index, +// int32, or int64). // // DELEGATE_FIELD_INT_ARRAY(id, field) - called for a std::array of fixed size // of integer values (like a SIMD mask). If this is not defined, and // DELEGATE_GET_FIELD is, then DELEGATE_FIELD_INT is called on them. - +// // DELEGATE_FIELD_INT_VECTOR(id, field) - called for a variable-sized vector // of integer values. If this is not defined, and DELEGATE_GET_FIELD is, then // DELEGATE_FIELD_INT is called on them. // +// DELEGATE_FIELD_ENUM(id, field, type) - called for an enum field. If this is +// not defined, then DELEGATE_FIELD_INT is used as fallback. +// +// DELEGATE_FIELD_BOOL(id, field) - called for a boolean field. If this is not +// defined, then DELEGATE_FIELD_INT is used as fallback. +// +// DELEGATE_FIELD_BOOL_VECTOR(id, field) - called for a variable-sized vector +// of boolean values. If this is not defined, then DELEGATE_FIELD_INT_VECTOR +// is used as fallback. +// // DELEGATE_FIELD_LITERAL(id, field) - called for a Literal. // // DELEGATE_FIELD_NAME(id, field) - called for a Name. @@ -150,6 +160,19 @@ #endif #endif +#ifndef DELEGATE_FIELD_ENUM +#define DELEGATE_FIELD_ENUM(id, field, type) DELEGATE_FIELD_INT(id, field) +#endif + +#ifndef DELEGATE_FIELD_BOOL +#define DELEGATE_FIELD_BOOL(id, field) DELEGATE_FIELD_INT(id, field) +#endif + +#ifndef DELEGATE_FIELD_BOOL_VECTOR +#define DELEGATE_FIELD_BOOL_VECTOR(id, field) \ + DELEGATE_FIELD_INT_VECTOR(id, field) +#endif + #ifndef DELEGATE_FIELD_LITERAL #error please define DELEGATE_FIELD_LITERAL(id, field) #endif @@ -290,7 +313,7 @@ DELEGATE_FIELD_CASE_END(Switch) DELEGATE_FIELD_CASE_START(Call) DELEGATE_FIELD_CHILD_VECTOR(Call, operands) DELEGATE_FIELD_NAME_KIND(Call, target, ModuleItemKind::Function) -DELEGATE_FIELD_INT(Call, isReturn) +DELEGATE_FIELD_BOOL(Call, isReturn) DELEGATE_FIELD_CASE_END(Call) DELEGATE_FIELD_CASE_START(CallIndirect) @@ -298,7 +321,7 @@ DELEGATE_FIELD_CHILD(CallIndirect, target) DELEGATE_FIELD_NAME_KIND(CallIndirect, table, ModuleItemKind::Table) DELEGATE_FIELD_CHILD_VECTOR(CallIndirect, operands) DELEGATE_FIELD_HEAPTYPE(CallIndirect, heapType) -DELEGATE_FIELD_INT(CallIndirect, isReturn) +DELEGATE_FIELD_BOOL(CallIndirect, isReturn) DELEGATE_FIELD_CASE_END(CallIndirect) DELEGATE_FIELD_CASE_START(LocalGet) @@ -322,10 +345,10 @@ DELEGATE_FIELD_CASE_END(GlobalSet) DELEGATE_FIELD_CASE_START(Load) DELEGATE_FIELD_CHILD(Load, ptr) DELEGATE_FIELD_INT(Load, bytes) -DELEGATE_FIELD_INT(Load, signed_) +DELEGATE_FIELD_BOOL(Load, signed_) DELEGATE_FIELD_ADDRESS(Load, offset) DELEGATE_FIELD_ADDRESS(Load, align) -DELEGATE_FIELD_INT(Load, isAtomic) +DELEGATE_FIELD_BOOL(Load, isAtomic) DELEGATE_FIELD_NAME_KIND(Load, memory, ModuleItemKind::Memory) DELEGATE_FIELD_CASE_END(Load) @@ -335,7 +358,7 @@ DELEGATE_FIELD_CHILD(Store, ptr) DELEGATE_FIELD_INT(Store, bytes) DELEGATE_FIELD_ADDRESS(Store, offset) DELEGATE_FIELD_ADDRESS(Store, align) -DELEGATE_FIELD_INT(Store, isAtomic) +DELEGATE_FIELD_BOOL(Store, isAtomic) DELEGATE_FIELD_TYPE(Store, valueType) DELEGATE_FIELD_NAME_KIND(Store, memory, ModuleItemKind::Memory) DELEGATE_FIELD_CASE_END(Store) @@ -343,7 +366,7 @@ DELEGATE_FIELD_CASE_END(Store) DELEGATE_FIELD_CASE_START(AtomicRMW) DELEGATE_FIELD_CHILD(AtomicRMW, value) DELEGATE_FIELD_CHILD(AtomicRMW, ptr) -DELEGATE_FIELD_INT(AtomicRMW, op) +DELEGATE_FIELD_ENUM(AtomicRMW, op, AtomicRMWOp) DELEGATE_FIELD_INT(AtomicRMW, bytes) DELEGATE_FIELD_ADDRESS(AtomicRMW, offset) DELEGATE_FIELD_NAME_KIND(AtomicRMW, memory, ModuleItemKind::Memory) @@ -380,14 +403,14 @@ DELEGATE_FIELD_CASE_END(AtomicFence) DELEGATE_FIELD_CASE_START(SIMDExtract) DELEGATE_FIELD_CHILD(SIMDExtract, vec) -DELEGATE_FIELD_INT(SIMDExtract, op) +DELEGATE_FIELD_ENUM(SIMDExtract, op, SIMDExtractOp) DELEGATE_FIELD_INT(SIMDExtract, index) DELEGATE_FIELD_CASE_END(SIMDExtract) DELEGATE_FIELD_CASE_START(SIMDReplace) DELEGATE_FIELD_CHILD(SIMDReplace, value) DELEGATE_FIELD_CHILD(SIMDReplace, vec) -DELEGATE_FIELD_INT(SIMDReplace, op) +DELEGATE_FIELD_ENUM(SIMDReplace, op, SIMDReplaceOp) DELEGATE_FIELD_INT(SIMDReplace, index) DELEGATE_FIELD_CASE_END(SIMDReplace) @@ -401,18 +424,18 @@ DELEGATE_FIELD_CASE_START(SIMDTernary) DELEGATE_FIELD_CHILD(SIMDTernary, c) DELEGATE_FIELD_CHILD(SIMDTernary, b) DELEGATE_FIELD_CHILD(SIMDTernary, a) -DELEGATE_FIELD_INT(SIMDTernary, op) +DELEGATE_FIELD_ENUM(SIMDTernary, op, SIMDTernaryOp) DELEGATE_FIELD_CASE_END(SIMDTernary) DELEGATE_FIELD_CASE_START(SIMDShift) DELEGATE_FIELD_CHILD(SIMDShift, shift) DELEGATE_FIELD_CHILD(SIMDShift, vec) -DELEGATE_FIELD_INT(SIMDShift, op) +DELEGATE_FIELD_ENUM(SIMDShift, op, SIMDShiftOp) DELEGATE_FIELD_CASE_END(SIMDShift) DELEGATE_FIELD_CASE_START(SIMDLoad) DELEGATE_FIELD_CHILD(SIMDLoad, ptr) -DELEGATE_FIELD_INT(SIMDLoad, op) +DELEGATE_FIELD_ENUM(SIMDLoad, op, SIMDLoadOp) DELEGATE_FIELD_ADDRESS(SIMDLoad, offset) DELEGATE_FIELD_ADDRESS(SIMDLoad, align) DELEGATE_FIELD_NAME_KIND(SIMDLoad, memory, ModuleItemKind::Memory) @@ -421,7 +444,7 @@ DELEGATE_FIELD_CASE_END(SIMDLoad) DELEGATE_FIELD_CASE_START(SIMDLoadStoreLane) DELEGATE_FIELD_CHILD(SIMDLoadStoreLane, vec) DELEGATE_FIELD_CHILD(SIMDLoadStoreLane, ptr) -DELEGATE_FIELD_INT(SIMDLoadStoreLane, op) +DELEGATE_FIELD_ENUM(SIMDLoadStoreLane, op, SIMDLoadStoreLaneOp) DELEGATE_FIELD_ADDRESS(SIMDLoadStoreLane, offset) DELEGATE_FIELD_ADDRESS(SIMDLoadStoreLane, align) DELEGATE_FIELD_INT(SIMDLoadStoreLane, index) @@ -461,13 +484,13 @@ DELEGATE_FIELD_CASE_END(Const) DELEGATE_FIELD_CASE_START(Unary) DELEGATE_FIELD_CHILD(Unary, value) -DELEGATE_FIELD_INT(Unary, op) +DELEGATE_FIELD_ENUM(Unary, op, UnaryOp) DELEGATE_FIELD_CASE_END(Unary) DELEGATE_FIELD_CASE_START(Binary) DELEGATE_FIELD_CHILD(Binary, right) DELEGATE_FIELD_CHILD(Binary, left) -DELEGATE_FIELD_INT(Binary, op) +DELEGATE_FIELD_ENUM(Binary, op, BinaryOp) DELEGATE_FIELD_CASE_END(Binary) DELEGATE_FIELD_CASE_START(Select) @@ -563,7 +586,7 @@ DELEGATE_FIELD_CASE_END(Try) DELEGATE_FIELD_CASE_START(TryTable) DELEGATE_FIELD_TYPE_VECTOR(TryTable, sentTypes) -DELEGATE_FIELD_INT_VECTOR(TryTable, catchRefs) +DELEGATE_FIELD_BOOL_VECTOR(TryTable, catchRefs) DELEGATE_FIELD_SCOPE_NAME_USE_VECTOR(TryTable, catchDests) DELEGATE_FIELD_NAME_KIND_VECTOR(TryTable, catchTags, ModuleItemKind::Tag) DELEGATE_FIELD_CHILD(TryTable, body) @@ -592,7 +615,7 @@ DELEGATE_FIELD_CASE_START(Pop) DELEGATE_FIELD_CASE_END(Pop) DELEGATE_FIELD_CASE_START(TupleMake) -DELEGATE_FIELD_CHILD_VECTOR(Tuple, operands) +DELEGATE_FIELD_CHILD_VECTOR(TupleMake, operands) DELEGATE_FIELD_CASE_END(TupleMake) DELEGATE_FIELD_CASE_START(TupleExtract) @@ -606,13 +629,13 @@ DELEGATE_FIELD_CASE_END(RefI31) DELEGATE_FIELD_CASE_START(I31Get) DELEGATE_FIELD_CHILD(I31Get, i31) -DELEGATE_FIELD_INT(I31Get, signed_) +DELEGATE_FIELD_BOOL(I31Get, signed_) DELEGATE_FIELD_CASE_END(I31Get) DELEGATE_FIELD_CASE_START(CallRef) DELEGATE_FIELD_CHILD(CallRef, target) DELEGATE_FIELD_CHILD_VECTOR(CallRef, operands) -DELEGATE_FIELD_INT(CallRef, isReturn) +DELEGATE_FIELD_BOOL(CallRef, isReturn) DELEGATE_FIELD_CASE_END(CallRef) DELEGATE_FIELD_CASE_START(RefTest) @@ -625,7 +648,7 @@ DELEGATE_FIELD_CHILD(RefCast, ref) DELEGATE_FIELD_CASE_END(RefCast) DELEGATE_FIELD_CASE_START(BrOn) -DELEGATE_FIELD_INT(BrOn, op) +DELEGATE_FIELD_ENUM(BrOn, op, BrOnOp) DELEGATE_FIELD_SCOPE_NAME_USE(BrOn, name) DELEGATE_FIELD_TYPE(BrOn, castType) DELEGATE_FIELD_CHILD(BrOn, ref) @@ -638,23 +661,23 @@ DELEGATE_FIELD_CASE_END(StructNew) DELEGATE_FIELD_CASE_START(StructGet) DELEGATE_FIELD_INT(StructGet, index) DELEGATE_FIELD_CHILD(StructGet, ref) -DELEGATE_FIELD_INT(StructGet, signed_) -DELEGATE_FIELD_INT(StructGet, order) +DELEGATE_FIELD_BOOL(StructGet, signed_) +DELEGATE_FIELD_ENUM(StructGet, order, MemoryOrder) DELEGATE_FIELD_CASE_END(StructGet) DELEGATE_FIELD_CASE_START(StructSet) DELEGATE_FIELD_INT(StructSet, index) DELEGATE_FIELD_CHILD(StructSet, value) DELEGATE_FIELD_CHILD(StructSet, ref) -DELEGATE_FIELD_INT(StructSet, order) +DELEGATE_FIELD_ENUM(StructSet, order, MemoryOrder) DELEGATE_FIELD_CASE_END(StructSet) DELEGATE_FIELD_CASE_START(StructRMW) -DELEGATE_FIELD_INT(StructRMW, op) +DELEGATE_FIELD_ENUM(StructRMW, op, StructRMWOp) DELEGATE_FIELD_INT(StructRMW, index) DELEGATE_FIELD_CHILD(StructRMW, value) DELEGATE_FIELD_CHILD(StructRMW, ref) -DELEGATE_FIELD_INT(StructRMW, order) +DELEGATE_FIELD_ENUM(StructRMW, order, MemoryOrder) DELEGATE_FIELD_CASE_END(StructRMW) DELEGATE_FIELD_CASE_START(StructCmpxchg) @@ -662,7 +685,7 @@ DELEGATE_FIELD_INT(StructCmpxchg, index) DELEGATE_FIELD_CHILD(StructCmpxchg, replacement) DELEGATE_FIELD_CHILD(StructCmpxchg, expected) DELEGATE_FIELD_CHILD(StructCmpxchg, ref) -DELEGATE_FIELD_INT(StructCmpxchg, order) +DELEGATE_FIELD_ENUM(StructCmpxchg, order, MemoryOrder) DELEGATE_FIELD_CASE_END(StructCmpxchg) DELEGATE_FIELD_CASE_START(ArrayNew) @@ -689,7 +712,7 @@ DELEGATE_FIELD_CASE_END(ArrayNewFixed) DELEGATE_FIELD_CASE_START(ArrayGet) DELEGATE_FIELD_CHILD(ArrayGet, index) DELEGATE_FIELD_CHILD(ArrayGet, ref) -DELEGATE_FIELD_INT(ArrayGet, signed_) +DELEGATE_FIELD_BOOL(ArrayGet, signed_) DELEGATE_FIELD_CASE_END(ArrayGet) DELEGATE_FIELD_CASE_START(ArraySet) @@ -734,12 +757,12 @@ DELEGATE_FIELD_CHILD(ArrayInitElem, ref) DELEGATE_FIELD_CASE_END(ArrayInitElem) DELEGATE_FIELD_CASE_START(RefAs) -DELEGATE_FIELD_INT(RefAs, op) +DELEGATE_FIELD_ENUM(RefAs, op, RefAsOp) DELEGATE_FIELD_CHILD(RefAs, value) DELEGATE_FIELD_CASE_END(RefAs) DELEGATE_FIELD_CASE_START(StringNew) -DELEGATE_FIELD_INT(StringNew, op) +DELEGATE_FIELD_ENUM(StringNew, op, StringNewOp) DELEGATE_FIELD_OPTIONAL_CHILD(StringNew, end) DELEGATE_FIELD_OPTIONAL_CHILD(StringNew, start) DELEGATE_FIELD_CHILD(StringNew, ref) @@ -750,12 +773,12 @@ DELEGATE_FIELD_NAME(StringConst, string) DELEGATE_FIELD_CASE_END(StringConst) DELEGATE_FIELD_CASE_START(StringMeasure) -DELEGATE_FIELD_INT(StringMeasure, op) +DELEGATE_FIELD_ENUM(StringMeasure, op, StringMeasureOp) DELEGATE_FIELD_CHILD(StringMeasure, ref) DELEGATE_FIELD_CASE_END(StringMeasure) DELEGATE_FIELD_CASE_START(StringEncode) -DELEGATE_FIELD_INT(StringEncode, op) +DELEGATE_FIELD_ENUM(StringEncode, op, StringEncodeOp) DELEGATE_FIELD_OPTIONAL_CHILD(StringEncode, start) DELEGATE_FIELD_CHILD(StringEncode, array) DELEGATE_FIELD_CHILD(StringEncode, str) @@ -767,7 +790,7 @@ DELEGATE_FIELD_CHILD(StringConcat, left) DELEGATE_FIELD_CASE_END(StringConcat) DELEGATE_FIELD_CASE_START(StringEq) -DELEGATE_FIELD_INT(StringEq, op) +DELEGATE_FIELD_ENUM(StringEq, op, StringEqOp) DELEGATE_FIELD_CHILD(StringEq, right) DELEGATE_FIELD_CHILD(StringEq, left) DELEGATE_FIELD_CASE_END(StringEq) @@ -820,7 +843,6 @@ DELEGATE_FIELD_CHILD_VECTOR(StackSwitch, operands) DELEGATE_FIELD_NAME_KIND(StackSwitch, tag, ModuleItemKind::Tag) DELEGATE_FIELD_CASE_END(StackSwitch) - DELEGATE_FIELD_MAIN_END #undef DELEGATE_ID @@ -832,6 +854,9 @@ DELEGATE_FIELD_MAIN_END #undef DELEGATE_FIELD_INT #undef DELEGATE_FIELD_INT_ARRAY #undef DELEGATE_FIELD_INT_VECTOR +#undef DELEGATE_FIELD_ENUM +#undef DELEGATE_FIELD_BOOL +#undef DELEGATE_FIELD_BOOL_VECTOR #undef DELEGATE_FIELD_LITERAL #undef DELEGATE_FIELD_NAME #undef DELEGATE_FIELD_NAME_VECTOR diff --git a/test/binaryen.js/expressions.js b/test/binaryen.js/expressions.js index f249f95493c..a177e12ca5b 100644 --- a/test/binaryen.js/expressions.js +++ b/test/binaryen.js/expressions.js @@ -1,7 +1,9 @@ -function assertDeepEqual(x, y) { +function assertEq(x, y) { if (typeof x === "object") { - for (let i in x) assertDeepEqual(x[i], y[i]); - for (let i in y) assertDeepEqual(x[i], y[i]); + if (x instanceof binaryen.Expression) + return +x === +y; + for (let i in x) assertEq(x[i], y[i]); + for (let i in y) assertEq(x[i], y[i]); } else { assert(x === y); } @@ -13,7 +15,7 @@ console.log("# Expression"); const ptr = module.block(null, []); - var theExpression = binaryen.Expression(ptr); // works without new + var theExpression = ptr; assert(theExpression instanceof binaryen.Block); assert(theExpression instanceof binaryen.Expression); assert(theExpression.constructor === binaryen.Block); @@ -21,7 +23,6 @@ console.log("# Expression"); assert(typeof binaryen.Block.getName === "function"); // own assert(typeof theExpression.getId === "function"); // proto assert(typeof theExpression.getName === "function"); // own - assert((theExpression | 0) === ptr); // via valueOf module.dispose(); })(); @@ -30,60 +31,60 @@ console.log("# Block"); (function testBlock() { const module = new binaryen.Module(); - const theBlock = binaryen.Block(module.block(null, [])); + const theBlock = module.block(null, []); assert(theBlock instanceof binaryen.Block); assert(theBlock instanceof binaryen.Expression); - assert(theBlock.id === binaryen.BlockId); - assert(theBlock.name === null); - assert(theBlock.type === binaryen.none); + assertEq(theBlock.id, binaryen.BlockId); + assertEq(theBlock.name, null); + assertEq(theBlock.type, binaryen.none); var info = binaryen.getExpressionInfo(theBlock); - assert(info.id === theBlock.id); - assert(info.type === theBlock.type); - assert(info.name === theBlock.name); - assertDeepEqual(info.children, theBlock.children); + assertEq(info.id, theBlock.id); + assertEq(info.type, theBlock.type); + assertEq(info.name, theBlock.name); + assertEq(info.children, theBlock.children); theBlock.name ="theName"; - assert(theBlock.name === "theName"); + assertEq(theBlock.name, "theName"); theBlock.type = binaryen.i32; - assert(theBlock.type === binaryen.i32); - assert(theBlock.numChildren === 0); - assertDeepEqual(theBlock.children, []); - assertDeepEqual(theBlock.getChildren(), []); + assertEq(theBlock.type, binaryen.i32); + assertEq(theBlock.numChildren, 0); + assertEq(theBlock.children, []); + assertEq(theBlock.getChildren(), []); var child1 = module.i32.const(1); theBlock.appendChild(child1); - assert(theBlock.numChildren === 1); - assert(theBlock.getChildAt(0) === child1); + assertEq(theBlock.numChildren, 1); + assertEq(theBlock.getChildAt(0), child1); var child2 = module.i32.const(2); theBlock.insertChildAt(1, child2); - assert(theBlock.numChildren === 2); - assert(theBlock.getChildAt(0) === child1); - assert(theBlock.getChildAt(1) === child2); + assertEq(theBlock.numChildren, 2); + assertEq(theBlock.getChildAt(0), child1); + assertEq(theBlock.getChildAt(1), child2); var child0 = module.i32.const(0); theBlock.insertChildAt(0, child0); - assert(theBlock.numChildren === 3); - assert(theBlock.getChildAt(0) === child0); - assert(theBlock.getChildAt(1) === child1); - assert(theBlock.getChildAt(2) === child2); + assertEq(theBlock.numChildren, 3); + assertEq(theBlock.getChildAt(0), child0); + assertEq(theBlock.getChildAt(1), child1); + assertEq(theBlock.getChildAt(2), child2); var newChild1 = module.i32.const(11); theBlock.setChildAt(1, newChild1); - assert(theBlock.numChildren === 3); - assert(theBlock.getChildAt(0) === child0); - assert(theBlock.getChildAt(1) === newChild1); - assert(theBlock.getChildAt(2) === child2); + assertEq(theBlock.numChildren, 3); + assertEq(theBlock.getChildAt(0), child0); + assertEq(theBlock.getChildAt(1), newChild1); + assertEq(theBlock.getChildAt(2), child2); theBlock.removeChildAt(1); - assert(theBlock.numChildren === 2); - assert(theBlock.getChildAt(0) === child0); - assert(theBlock.getChildAt(1) === child2); + assertEq(theBlock.numChildren, 2); + assertEq(theBlock.getChildAt(0), child0); + assertEq(theBlock.getChildAt(1), child2); theBlock.removeChildAt(1); - assert(theBlock.numChildren === 1); - assert(theBlock.getChildAt(0) === child0); + assertEq(theBlock.numChildren, 1); + assertEq(theBlock.getChildAt(0), child0); theBlock.finalize(); info = binaryen.getExpressionInfo(theBlock); - assert(info.name === theBlock.name); - assertDeepEqual(info.children, theBlock.children); + assertEq(info.name, theBlock.name); + assertEq(info.children, theBlock.children); console.log(theBlock.toText()); assert( @@ -92,7 +93,7 @@ console.log("# Block"); "(block $theName (result i32)\n (i32.const 0)\n)\n" ); theBlock.removeChildAt(0); - assert(theBlock.numChildren === 0); + assertEq(theBlock.numChildren, 0); module.dispose(); })(); @@ -104,34 +105,34 @@ console.log("# If"); var condition = module.i32.const(1); var ifTrue = module.i32.const(2); var ifFalse = module.i32.const(3); - const theIf = binaryen.If(module.if(condition, ifTrue, ifFalse)); + const theIf = module.if(condition, ifTrue, ifFalse); assert(theIf instanceof binaryen.If); assert(theIf instanceof binaryen.Expression); - assert(theIf.id === binaryen.IfId); - assert(theIf.condition === condition); - assert(theIf.ifTrue === ifTrue); - assert(theIf.ifFalse === ifFalse); + assertEq(theIf.id, binaryen.IfId); + assertEq(theIf.condition, condition); + assertEq(theIf.ifTrue, ifTrue); + assertEq(theIf.ifFalse, ifFalse); assert(theIf.type == binaryen.i32); var info = binaryen.getExpressionInfo(theIf); - assert(info.id === theIf.id); - assert(info.type === theIf.type); - assert(info.condition === theIf.condition); - assert(info.ifTrue === theIf.ifTrue); - assert(info.ifFalse === theIf.ifFalse); + assertEq(info.id, theIf.id); + assertEq(info.type, theIf.type); + assertEq(info.condition, theIf.condition); + assertEq(info.ifTrue, theIf.ifTrue); + assertEq(info.ifFalse, theIf.ifFalse); theIf.condition = condition = module.i32.const(4); - assert(theIf.condition === condition); + assertEq(theIf.condition, condition); theIf.ifTrue = ifTrue = module.i32.const(5); - assert(theIf.ifTrue === ifTrue); + assertEq(theIf.ifTrue, ifTrue); theIf.ifFalse = ifFalse = module.i32.const(6); - assert(theIf.ifFalse === ifFalse); + assertEq(theIf.ifFalse, ifFalse); theIf.finalize(); info = binaryen.getExpressionInfo(theIf); - assert(info.condition === theIf.condition); - assert(info.ifTrue === theIf.ifTrue); - assert(info.ifFalse === theIf.ifFalse); + assertEq(info.condition, theIf.condition); + assertEq(info.ifTrue, theIf.ifTrue); + assertEq(info.ifFalse, theIf.ifFalse); console.log(theIf.toText()); assert( @@ -144,7 +145,7 @@ console.log("# If"); assert(!theIf.ifFalse); info = binaryen.getExpressionInfo(theIf); - assert(info.ifFalse === theIf.ifFalse); + assertEq(info.ifFalse, theIf.ifFalse); console.log(theIf.toText()); assert( @@ -162,31 +163,31 @@ console.log("# Loop"); var name = null; var body = module.i32.const(1); - const theLoop = binaryen.Loop(module.loop(name, body)); + const theLoop = module.loop(name, body); assert(theLoop instanceof binaryen.Loop); assert(theLoop instanceof binaryen.Expression); - assert(theLoop.id === binaryen.LoopId); - assert(theLoop.name === name); - assert(theLoop.body === body); - assert(theLoop.type === binaryen.i32); + assertEq(theLoop.id, binaryen.LoopId); + assertEq(theLoop.name, name); + assertEq(theLoop.body, body); + assertEq(theLoop.type, binaryen.i32); var info = binaryen.getExpressionInfo(theLoop); - assert(info.id === theLoop.id); - assert(info.type === theLoop.type); - assert(info.name === theLoop.name); - assert(info.body === theLoop.body); + assertEq(info.id, theLoop.id); + assertEq(info.type, theLoop.type); + assertEq(info.name, theLoop.name); + assertEq(info.body, theLoop.body); theLoop.name = name = "theName"; - assert(theLoop.name === name); + assertEq(theLoop.name, name); theLoop.body = body = module.drop(body); - assert(theLoop.body === body); + assertEq(theLoop.body, body); theLoop.finalize(); - assert(theLoop.type === binaryen.none); + assertEq(theLoop.type, binaryen.none); info = binaryen.getExpressionInfo(theLoop); - assert(info.type === theLoop.type); - assert(info.name === theLoop.name); - assert(info.body === theLoop.body); + assertEq(info.type, theLoop.type); + assertEq(info.name, theLoop.name); + assertEq(info.body, theLoop.body); console.log(theLoop.toText()); assert( @@ -205,33 +206,33 @@ console.log("# Break"); var name = "theName"; var condition = module.i32.const(1); var value = module.i32.const(2); - const theBreak = binaryen.Break(module.br(name, condition, value)); + const theBreak = module.br(name, condition, value); assert(theBreak instanceof binaryen.Break); assert(theBreak instanceof binaryen.Expression); - assert(theBreak.name === name); - assert(theBreak.condition === condition); - assert(theBreak.value === value); - assert(theBreak.type === binaryen.i32); + assertEq(theBreak.name, name); + assertEq(theBreak.condition, condition); + assertEq(theBreak.value, value); + assertEq(theBreak.type, binaryen.i32); var info = binaryen.getExpressionInfo(theBreak); - assert(info.id === theBreak.id); - assert(info.type === theBreak.type); - assert(info.name === theBreak.name); - assert(info.condition === theBreak.condition); - assert(info.value === theBreak.value); + assertEq(info.id, theBreak.id); + assertEq(info.type, theBreak.type); + assertEq(info.name, theBreak.name); + assertEq(info.condition, theBreak.condition); + assertEq(info.value, theBreak.value); theBreak.name = name = "theNewName"; - assert(theBreak.name === "theNewName"); + assertEq(theBreak.name, "theNewName"); theBreak.condition = condition = module.i32.const(3); - assert(theBreak.condition === condition); + assertEq(theBreak.condition, condition); theBreak.value = value = module.i32.const(4); - assert(theBreak.value === value); + assertEq(theBreak.value, value); theBreak.finalize(); info = binaryen.getExpressionInfo(theBreak); - assert(info.name === theBreak.name); - assert(info.condition === theBreak.condition); - assert(info.value === theBreak.value); + assertEq(info.name, theBreak.name); + assertEq(info.condition, theBreak.condition); + assertEq(info.value, theBreak.value); console.log(theBreak.toText()); assert( @@ -251,23 +252,23 @@ console.log("# Switch"); var defaultName = "c"; var condition = module.i32.const(1); var value = module.i32.const(2); - const theSwitch = binaryen.Switch(module.switch(names, defaultName, condition, value)); + const theSwitch = module.switch(names, defaultName, condition, value); assert(theSwitch instanceof binaryen.Switch); assert(theSwitch instanceof binaryen.Expression); - assert(theSwitch.numNames === 2); - assertDeepEqual(theSwitch.names, names); - assert(theSwitch.defaultName === defaultName); - assert(theSwitch.condition === condition); - assert(theSwitch.value === value); - assert(theSwitch.type === binaryen.unreachable); + assertEq(theSwitch.numNames, 2); + assertEq(theSwitch.names, names); + assertEq(theSwitch.defaultName, defaultName); + assertEq(theSwitch.condition, condition); + assertEq(theSwitch.value, value); + assertEq(theSwitch.type, binaryen.unreachable); var info = binaryen.getExpressionInfo(theSwitch); - assert(info.id === theSwitch.id); - assert(info.type === theSwitch.type); - assertDeepEqual(info.names, theSwitch.names); - assert(info.defaultName === theSwitch.defaultName); - assert(info.condition === theSwitch.condition); - assert(info.value === theSwitch.value); + assertEq(info.id, theSwitch.id); + assertEq(info.type, theSwitch.type); + assertEq(info.names, theSwitch.names); + assertEq(info.defaultName, theSwitch.defaultName); + assertEq(info.condition, theSwitch.condition); + assertEq(info.value, theSwitch.value); names = [ "1", // set @@ -275,26 +276,26 @@ console.log("# Switch"); "3" // append ] theSwitch.setNames(names); - assertDeepEqual(theSwitch.names, names); + assertEq(theSwitch.names, names); theSwitch.names = names = [ "x", // set // remove // remove ]; - assertDeepEqual(theSwitch.names, names); - assertDeepEqual(theSwitch.getNames(), names); + assertEq(theSwitch.names, names); + assertEq(theSwitch.getNames(), names); theSwitch.insertNameAt(1, "y"); theSwitch.condition = condition = module.i32.const(3); - assert(theSwitch.condition === condition); + assertEq(theSwitch.condition, condition); theSwitch.value = value = module.i32.const(4); - assert(theSwitch.value === value); + assertEq(theSwitch.value, value); theSwitch.finalize(); info = binaryen.getExpressionInfo(theSwitch); - assertDeepEqual(info.names, theSwitch.names); - assert(info.defaultName === theSwitch.defaultName); - assert(info.condition === theSwitch.condition); - assert(info.value === theSwitch.value); + assertEq(info.names, theSwitch.names); + assertEq(info.defaultName, theSwitch.defaultName); + assertEq(info.condition, theSwitch.condition); + assertEq(info.value, theSwitch.value); console.log(theSwitch.toText()); assert( @@ -315,57 +316,57 @@ console.log("# Call"); module.i32.const(1), module.i32.const(2) ]; - const theCall = binaryen.Call(module.call(target, operands, binaryen.i32)); + const theCall = module.call(target, operands, binaryen.i32); assert(theCall instanceof binaryen.Call); assert(theCall instanceof binaryen.Expression); - assert(theCall.target === target); - assertDeepEqual(theCall.operands, operands); - assertDeepEqual(theCall.getOperands(), operands); - assert(theCall.return === false); - assert(theCall.type === binaryen.i32); + assertEq(theCall.target, target); + assertEq(theCall.operands, operands); + assertEq(theCall.getOperands(), operands); + assertEq(theCall.return, false); + assertEq(theCall.type, binaryen.i32); var info = binaryen.getExpressionInfo(theCall); - assert(info.id === theCall.id); - assert(info.type === theCall.type); - assert(info.target === theCall.target); - assertDeepEqual(info.operands, theCall.operands); - assert(info.isReturn === theCall.return); + assertEq(info.id, theCall.id); + assertEq(info.type, theCall.type); + assertEq(info.target, theCall.target); + assertEq(info.operands, theCall.operands); + assertEq(info.isReturn, theCall.return); theCall.target = "bar"; - assert(theCall.target === "bar"); + assertEq(theCall.target, "bar"); theCall.operands = operands = [ module.i32.const(3), // set module.i32.const(4), // set module.i32.const(5) // append ]; - assertDeepEqual(theCall.operands, operands); + assertEq(theCall.operands, operands); operands = [ module.i32.const(6) // set // remove // remove ]; theCall.setOperands(operands); - assertDeepEqual(theCall.operands, operands); + assertEq(theCall.operands, operands); theCall.insertOperandAt(0, module.i32.const(7)); theCall.return = true; - assert(theCall.return === true); + assertEq(theCall.return, true); theCall.finalize(); - assert(theCall.type === binaryen.unreachable); // finalized tail call + assertEq(theCall.type, binaryen.unreachable); // finalized tail call info = binaryen.getExpressionInfo(theCall); - assert(info.type === theCall.type); - assert(info.target === theCall.target); - assertDeepEqual(info.operands, theCall.operands); - assert(info.isReturn === theCall.return); + assertEq(info.type, theCall.type); + assertEq(info.target, theCall.target); + assertEq(info.operands, theCall.operands); + assertEq(info.isReturn, theCall.return); theCall.return = false; theCall.type = binaryen.i32; theCall.finalize(); - assert(theCall.type === binaryen.i32); // finalized call + assertEq(theCall.type, binaryen.i32); // finalized call info = binaryen.getExpressionInfo(theCall); - assert(info.type === theCall.type); - assert(info.isReturn === theCall.return); + assertEq(info.type, theCall.type); + assertEq(info.isReturn, theCall.return); console.log(theCall.toText()); assert( @@ -389,67 +390,67 @@ console.log("# CallIndirect"); module.i32.const(1), module.i32.const(2) ]; - const theCallIndirect = binaryen.CallIndirect(module.call_indirect(table, target, operands, params, results)); + const theCallIndirect = module.call_indirect(table, target, operands, params, results); assert(theCallIndirect instanceof binaryen.CallIndirect); assert(theCallIndirect instanceof binaryen.Expression); - assert(theCallIndirect.table === table); - assert(theCallIndirect.target === target); - assertDeepEqual(theCallIndirect.operands, operands); - assert(theCallIndirect.params === params); - assert(theCallIndirect.results === results); - assert(theCallIndirect.return === false); - assert(theCallIndirect.type === theCallIndirect.results); + assertEq(theCallIndirect.table, table); + assertEq(theCallIndirect.target, target); + assertEq(theCallIndirect.operands, operands); + assertEq(theCallIndirect.params, params); + assertEq(theCallIndirect.results, results); + assertEq(theCallIndirect.return, false); + assertEq(theCallIndirect.type, theCallIndirect.results); var info = binaryen.getExpressionInfo(theCallIndirect); - assert(info.id === theCallIndirect.id); - assert(info.type === theCallIndirect.type); - assert(info.table === theCallIndirect.table); - assert(info.target === theCallIndirect.target); - assertDeepEqual(info.operands, theCallIndirect.operands); - assert(info.params === theCallIndirect.params); - assert(info.results === theCallIndirect.results); - assert(info.isReturn === theCallIndirect.return); + assertEq(info.id, theCallIndirect.id); + assertEq(info.type, theCallIndirect.type); + assertEq(info.table, theCallIndirect.table); + assertEq(info.target, theCallIndirect.target); + assertEq(info.operands, theCallIndirect.operands); + assertEq(info.params, theCallIndirect.params); + assertEq(info.results, theCallIndirect.results); + assertEq(info.isReturn, theCallIndirect.return); theCallIndirect.target = target = module.i32.const(9000); - assert(theCallIndirect.target === target); + assertEq(theCallIndirect.target, target); theCallIndirect.operands = operands = [ module.i32.const(3), // set module.i32.const(4), // set module.i32.const(5) // append ]; - assertDeepEqual(theCallIndirect.operands, operands); + assertEq(theCallIndirect.operands, operands); operands = [ module.i32.const(6) // set // remove // remove ]; theCallIndirect.setOperands(operands); - assertDeepEqual(theCallIndirect.operands, operands); - assertDeepEqual(theCallIndirect.getOperands(), operands); + assertEq(theCallIndirect.operands, operands); + assertEq(theCallIndirect.getOperands(), operands); theCallIndirect.insertOperandAt(0, module.i32.const(7)); theCallIndirect.return = true; - assert(theCallIndirect.return === true); + assertEq(theCallIndirect.return, true); theCallIndirect.params = params = binaryen.createType([ binaryen.i32, binaryen.i32 ]); - assert(theCallIndirect.params === params); + assertEq(theCallIndirect.params, params); theCallIndirect.results = results = binaryen.i32; - assert(theCallIndirect.results === results); + assertEq(theCallIndirect.results, results); theCallIndirect.finalize(); - assert(theCallIndirect.type === binaryen.unreachable); // finalized tail call + assertEq(theCallIndirect.type, binaryen.unreachable); // finalized tail call info = binaryen.getExpressionInfo(theCallIndirect); - assert(info.type === theCallIndirect.type); - assert(info.target === theCallIndirect.target); - assertDeepEqual(info.operands, theCallIndirect.operands); - assert(info.params === theCallIndirect.params); - assert(info.results === theCallIndirect.results); - assert(info.isReturn === theCallIndirect.return); + assertEq(info.type, theCallIndirect.type); + assertEq(info.target, theCallIndirect.target); + assertEq(info.operands, theCallIndirect.operands); + assertEq(info.params, theCallIndirect.params); + assertEq(info.results, theCallIndirect.results); + assertEq(info.isReturn, theCallIndirect.return); theCallIndirect.return = false; theCallIndirect.finalize(); - assert(theCallIndirect.type === results); // finalized call + assertEq(theCallIndirect.type, results); // finalized call info = binaryen.getExpressionInfo(theCallIndirect); - assert(info.isReturn === theCallIndirect.return); + assertEq(info.isReturn, theCallIndirect.return); console.log(theCallIndirect.toText()); assert( @@ -467,26 +468,26 @@ console.log("# LocalGet"); var index = 1; var type = binaryen.i32; - const theLocalGet = binaryen.LocalGet(module.local.get(index, type)); + const theLocalGet = module.local.get(index, type); assert(theLocalGet instanceof binaryen.LocalGet); assert(theLocalGet instanceof binaryen.Expression); - assert(theLocalGet.index === index); - assert(theLocalGet.type === type); + assertEq(theLocalGet.index, index); + assertEq(theLocalGet.type, type); var info = binaryen.getExpressionInfo(theLocalGet); - assert(info.id === theLocalGet.id); - assert(info.type === theLocalGet.type); - assert(info.index === theLocalGet.index); + assertEq(info.id, theLocalGet.id); + assertEq(info.type, theLocalGet.type); + assertEq(info.index, theLocalGet.index); theLocalGet.index = index = 2; - assert(theLocalGet.index === index); + assertEq(theLocalGet.index, index); theLocalGet.type = type = binaryen.f64; - assert(theLocalGet.type === type); + assertEq(theLocalGet.type, type); theLocalGet.finalize(); info = binaryen.getExpressionInfo(theLocalGet); - assert(info.type === theLocalGet.type); - assert(info.index === theLocalGet.index); + assertEq(info.type, theLocalGet.type); + assertEq(info.index, theLocalGet.index); console.log(theLocalGet.toText()); assert( @@ -504,36 +505,36 @@ console.log("# LocalSet"); var index = 1; var value = module.i32.const(1); - const theLocalSet = binaryen.LocalSet(module.local.set(index, value)); + const theLocalSet = module.local.set(index, value); assert(theLocalSet instanceof binaryen.LocalSet); assert(theLocalSet instanceof binaryen.Expression); - assert(theLocalSet.index === index); - assert(theLocalSet.value === value); - assert(theLocalSet.tee === false); + assertEq(theLocalSet.index, index); + assertEq(theLocalSet.value, value); + assertEq(theLocalSet.tee, false); assert(theLocalSet.type == binaryen.none); var info = binaryen.getExpressionInfo(theLocalSet); - assert(info.id === theLocalSet.id); - assert(info.type === theLocalSet.type); - assert(info.index === theLocalSet.index); - assert(info.value === theLocalSet.value); - assert(info.isTee === theLocalSet.tee) + assertEq(info.id, theLocalSet.id); + assertEq(info.type, theLocalSet.type); + assertEq(info.index, theLocalSet.index); + assertEq(info.value, theLocalSet.value); + assertEq(info.isTee, theLocalSet.tee) theLocalSet.index = index = 2; - assert(theLocalSet.index === index); + assertEq(theLocalSet.index, index); theLocalSet.value = value = module.i32.const(3); - assert(theLocalSet.value === value); + assertEq(theLocalSet.value, value); theLocalSet.type = binaryen.i32; - assert(theLocalSet.type === binaryen.i32); - assert(theLocalSet.tee === true); + assertEq(theLocalSet.type, binaryen.i32); + assertEq(theLocalSet.tee, true); theLocalSet.type = binaryen.none; theLocalSet.finalize(); info = binaryen.getExpressionInfo(theLocalSet); - assert(info.type === theLocalSet.type); - assert(info.index === theLocalSet.index); - assert(info.value === theLocalSet.value); - assert(info.isTee === theLocalSet.tee) + assertEq(info.type, theLocalSet.type); + assertEq(info.index, theLocalSet.index); + assertEq(info.value, theLocalSet.value); + assertEq(info.isTee, theLocalSet.tee) console.log(theLocalSet.toText()); assert( @@ -551,26 +552,26 @@ console.log("# GlobalGet"); var name = "a"; var type = binaryen.i32; - const theGlobalGet = binaryen.GlobalGet(module.global.get(name, type)); + const theGlobalGet = module.global.get(name, type); assert(theGlobalGet instanceof binaryen.GlobalGet); assert(theGlobalGet instanceof binaryen.Expression); - assert(theGlobalGet.name === name); - assert(theGlobalGet.type === type); + assertEq(theGlobalGet.name, name); + assertEq(theGlobalGet.type, type); var info = binaryen.getExpressionInfo(theGlobalGet); - assert(info.id === theGlobalGet.id); - assert(info.type === theGlobalGet.type); - assert(info.name === theGlobalGet.name); + assertEq(info.id, theGlobalGet.id); + assertEq(info.type, theGlobalGet.type); + assertEq(info.name, theGlobalGet.name); theGlobalGet.name = name = "b"; - assert(theGlobalGet.name === name); + assertEq(theGlobalGet.name, name); theGlobalGet.type = type = binaryen.f64; - assert(theGlobalGet.type === type); + assertEq(theGlobalGet.type, type); theGlobalGet.finalize(); info = binaryen.getExpressionInfo(theGlobalGet); - assert(info.type === theGlobalGet.type); - assert(info.name === theGlobalGet.name); + assertEq(info.type, theGlobalGet.type); + assertEq(info.name, theGlobalGet.name); console.log(theGlobalGet.toText()); assert( @@ -588,28 +589,28 @@ console.log("# GlobalSet"); var name = "a"; var value = module.i32.const(1); - const theGlobalSet = binaryen.GlobalSet(module.global.set(name, value)); + const theGlobalSet = module.global.set(name, value); assert(theGlobalSet instanceof binaryen.GlobalSet); assert(theGlobalSet instanceof binaryen.Expression); - assert(theGlobalSet.name === name); - assert(theGlobalSet.value === value); + assertEq(theGlobalSet.name, name); + assertEq(theGlobalSet.value, value); assert(theGlobalSet.type == binaryen.none); var info = binaryen.getExpressionInfo(theGlobalSet); - assert(info.id === theGlobalSet.id); - assert(info.type === theGlobalSet.type); - assert(info.name === theGlobalSet.name); - assert(info.value === theGlobalSet.value); + assertEq(info.id, theGlobalSet.id); + assertEq(info.type, theGlobalSet.type); + assertEq(info.name, theGlobalSet.name); + assertEq(info.value, theGlobalSet.value); theGlobalSet.name = name = "b"; - assert(theGlobalSet.name === name); + assertEq(theGlobalSet.name, name); theGlobalSet.value = value = module.f64.const(3); - assert(theGlobalSet.value === value); + assertEq(theGlobalSet.value, value); theGlobalSet.finalize(); info = binaryen.getExpressionInfo(theGlobalSet); - assert(info.name === theGlobalSet.name); - assert(info.value === theGlobalSet.value); + assertEq(info.name, theGlobalSet.name); + assertEq(info.value, theGlobalSet.value); console.log(theGlobalSet.toText()); assert( @@ -626,15 +627,15 @@ console.log("# MemorySize"); const module = new binaryen.Module(); module.setMemory(1, 1, null); var type = binaryen.i32; - const theMemorySize = binaryen.MemorySize(module.memory.size()); + const theMemorySize = module.memory.size(); assert(theMemorySize instanceof binaryen.MemorySize); assert(theMemorySize instanceof binaryen.Expression); - assert(theMemorySize.type === type); + assertEq(theMemorySize.type, type); theMemorySize.finalize(); var info = binaryen.getExpressionInfo(theMemorySize); - assert(info.id === theMemorySize.id); - assert(info.type === theMemorySize.type); + assertEq(info.id, theMemorySize.id); + assertEq(info.type, theMemorySize.type); console.log(theMemorySize.toText()); assert( @@ -653,23 +654,23 @@ console.log("# MemoryGrow"); var type = binaryen.i32; var delta = module.i32.const(1); - const theMemoryGrow = binaryen.MemoryGrow(module.memory.grow(delta)); + const theMemoryGrow = module.memory.grow(delta); assert(theMemoryGrow instanceof binaryen.MemoryGrow); assert(theMemoryGrow instanceof binaryen.Expression); - assert(theMemoryGrow.delta === delta); - assert(theMemoryGrow.type === type); + assertEq(theMemoryGrow.delta, delta); + assertEq(theMemoryGrow.type, type); var info = binaryen.getExpressionInfo(theMemoryGrow); - assert(info.id === theMemoryGrow.id); - assert(info.type === theMemoryGrow.type); - assert(info.delta === theMemoryGrow.delta); + assertEq(info.id, theMemoryGrow.id); + assertEq(info.type, theMemoryGrow.type); + assertEq(info.delta, theMemoryGrow.delta); theMemoryGrow.delta = delta = module.i32.const(2); - assert(theMemoryGrow.delta === delta); + assertEq(theMemoryGrow.delta, delta); theMemoryGrow.finalize(); info = binaryen.getExpressionInfo(theMemoryGrow); - assert(info.delta === theMemoryGrow.delta); + assertEq(info.delta, theMemoryGrow.delta); console.log(theMemoryGrow.toText()); assert( @@ -689,51 +690,51 @@ console.log("# Load"); var offset = 16; var align = 2; var ptr = module.i32.const(64); - const theLoad = binaryen.Load(module.i32.load(offset, align, ptr)); + const theLoad = module.i32.load(offset, align, ptr); assert(theLoad instanceof binaryen.Load); assert(theLoad instanceof binaryen.Expression); - assert(theLoad.offset === offset); - assert(theLoad.align === align); - assert(theLoad.ptr === ptr); - assert(theLoad.bytes === 4); - assert(theLoad.signed === true); - assert(theLoad.atomic === false); + assertEq(theLoad.offset, offset); + assertEq(theLoad.align, align); + assertEq(theLoad.ptr, ptr); + assertEq(theLoad.bytes, 4); + assertEq(theLoad.signed, true); + assertEq(theLoad.atomic, false); assert(theLoad.type == binaryen.i32); var info = binaryen.getExpressionInfo(theLoad); - assert(info.id === theLoad.id); - assert(info.type === theLoad.type); - assert(info.offset === theLoad.offset); - assert(info.align === theLoad.align); - assert(info.ptr === theLoad.ptr); - assert(info.bytes === theLoad.bytes); - assert(info.isSigned === theLoad.signed); - assert(info.isAtomic === theLoad.atomic); + assertEq(info.id, theLoad.id); + assertEq(info.type, theLoad.type); + assertEq(info.offset, theLoad.offset); + assertEq(info.align, theLoad.align); + assertEq(info.ptr, theLoad.ptr); + assertEq(info.bytes, theLoad.bytes); + assertEq(info.isSigned, theLoad.signed); + assertEq(info.isAtomic, theLoad.atomic); theLoad.offset = offset = 32; - assert(theLoad.offset === offset); + assertEq(theLoad.offset, offset); theLoad.align = align = 4; - assert(theLoad.align === align); + assertEq(theLoad.align, align); theLoad.ptr = ptr = module.i32.const(128); - assert(theLoad.ptr === ptr); + assertEq(theLoad.ptr, ptr); theLoad.type = binaryen.i64; - assert(theLoad.type === binaryen.i64); + assertEq(theLoad.type, binaryen.i64); theLoad.signed = false; - assert(theLoad.signed === false); + assertEq(theLoad.signed, false); theLoad.bytes = 8; - assert(theLoad.bytes === 8); + assertEq(theLoad.bytes, 8); theLoad.atomic = true; - assert(theLoad.atomic === true); + assertEq(theLoad.atomic, true); theLoad.finalize(); - assert(theLoad.align === 4); + assertEq(theLoad.align, 4); info = binaryen.getExpressionInfo(theLoad); - assert(info.offset === theLoad.offset); - assert(info.align === theLoad.align); - assert(info.ptr === theLoad.ptr); - assert(info.bytes === theLoad.bytes); - assert(info.isSigned === theLoad.signed); - assert(info.isAtomic === theLoad.atomic); + assertEq(info.offset, theLoad.offset); + assertEq(info.align, theLoad.align); + assertEq(info.ptr, theLoad.ptr); + assertEq(info.bytes, theLoad.bytes); + assertEq(info.isSigned, theLoad.signed); + assertEq(info.isAtomic, theLoad.atomic); console.log(theLoad.toText()); assert( @@ -754,56 +755,56 @@ console.log("# Store"); var align = 2; var ptr = module.i32.const(64); var value = module.i32.const(1); - const theStore = binaryen.Store(module.i32.store(offset, align, ptr, value)); + const theStore = module.i32.store(offset, align, ptr, value); assert(theStore instanceof binaryen.Store); assert(theStore instanceof binaryen.Expression); - assert(theStore.offset === offset); - assert(theStore.align === align); - assert(theStore.ptr === ptr); - assert(theStore.value === value); - assert(theStore.bytes === 4); - assert(theStore.atomic === false); - assert(theStore.valueType === binaryen.i32); - assert(theStore.type === binaryen.none); + assertEq(theStore.offset, offset); + assertEq(theStore.align, align); + assertEq(theStore.ptr, ptr); + assertEq(theStore.value, value); + assertEq(theStore.bytes, 4); + assertEq(theStore.atomic, false); + assertEq(theStore.valueType, binaryen.i32); + assertEq(theStore.type, binaryen.none); var info = binaryen.getExpressionInfo(theStore); - assert(info.id === theStore.id); - assert(info.type === theStore.type); - assert(info.offset === theStore.offset); - assert(info.align === theStore.align); - assert(info.ptr === theStore.ptr); - assert(info.value === theStore.value); - assert(info.bytes === theStore.bytes); - assert(info.isAtomic === theStore.atomic); - assert(info.valueType === theStore.valueType); + assertEq(info.id, theStore.id); + assertEq(info.type, theStore.type); + assertEq(info.offset, theStore.offset); + assertEq(info.align, theStore.align); + assertEq(info.ptr, theStore.ptr); + assertEq(info.value, theStore.value); + assertEq(info.bytes, theStore.bytes); + assertEq(info.isAtomic, theStore.atomic); + assertEq(info.valueType, theStore.valueType); theStore.offset = offset = 32; - assert(theStore.offset === offset); + assertEq(theStore.offset, offset); theStore.align = align = 4; - assert(theStore.align === align); + assertEq(theStore.align, align); theStore.ptr = ptr = module.i32.const(128); - assert(theStore.ptr === ptr); + assertEq(theStore.ptr, ptr); theStore.value = value = module.i32.const(2); - assert(theStore.value === value); + assertEq(theStore.value, value); theStore.signed = false; - assert(theStore.signed === false); + assertEq(theStore.signed, false); theStore.valueType = binaryen.i64; - assert(theStore.valueType === binaryen.i64); + assertEq(theStore.valueType, binaryen.i64); theStore.bytes = 8; - assert(theStore.bytes === 8); + assertEq(theStore.bytes, 8); theStore.atomic = true; - assert(theStore.atomic === true); + assertEq(theStore.atomic, true); theStore.finalize(); - assert(theStore.align === 4); + assertEq(theStore.align, 4); info = binaryen.getExpressionInfo(theStore); - assert(info.offset === theStore.offset); - assert(info.align === theStore.align); - assert(info.ptr === theStore.ptr); - assert(info.value === theStore.value); - assert(info.bytes === theStore.bytes); - assert(info.isAtomic === theStore.atomic); - assert(info.valueType === theStore.valueType); + assertEq(info.offset, theStore.offset); + assertEq(info.align, theStore.align); + assertEq(info.ptr, theStore.ptr); + assertEq(info.value, theStore.value); + assertEq(info.bytes, theStore.bytes); + assertEq(info.isAtomic, theStore.atomic); + assertEq(info.valueType, theStore.valueType); console.log(theStore.toText()); assert( @@ -819,57 +820,57 @@ console.log("# Const"); (function testConst() { const module = new binaryen.Module(); - const theConst = binaryen.Const(module.i32.const(1)); + const theConst = module.i32.const(1); assert(theConst instanceof binaryen.Const); assert(theConst instanceof binaryen.Expression); - assert(theConst.valueI32 === 1); + assertEq(theConst.valueI32, 1); theConst.valueI32 = 2; - assert(theConst.valueI32 === 2); - assert(theConst.type === binaryen.i32); + assertEq(theConst.valueI32, 2); + assertEq(theConst.type, binaryen.i32); var info = binaryen.getExpressionInfo(theConst); - assert(info.id === theConst.id); - assert(info.type === theConst.type); - assert(info.value === theConst.valueI32); + assertEq(info.id, theConst.id); + assertEq(info.type, theConst.type); + assertEq(info.value, theConst.valueI32); theConst.valueI64Low = 3; - assert(theConst.valueI64Low === 3); + assertEq(theConst.valueI64Low, 3); theConst.valueI64High = 4; - assert(theConst.valueI64High === 4); + assertEq(theConst.valueI64High, 4); theConst.finalize(); assert(theConst.type == binaryen.i64); info = binaryen.getExpressionInfo(theConst); - assert(info.type === theConst.type); - assert(info.value.low === theConst.valueI64Low); - assert(info.value.high === theConst.valueI64High); + assertEq(info.type, theConst.type); + assertEq(info.value.low, theConst.valueI64Low); + assertEq(info.value.high, theConst.valueI64High); theConst.valueF32 = 5; - assert(theConst.valueF32 === 5); + assertEq(theConst.valueF32, 5); theConst.finalize(); - assert(theConst.type === binaryen.f32); + assertEq(theConst.type, binaryen.f32); info = binaryen.getExpressionInfo(theConst); - assert(info.type === theConst.type); - assert(info.value === theConst.valueF32); + assertEq(info.type, theConst.type); + assertEq(info.value, theConst.valueF32); theConst.valueF64 = 6; - assert(theConst.valueF64 === 6); + assertEq(theConst.valueF64, 6); theConst.finalize(); - assert(theConst.type === binaryen.f64); + assertEq(theConst.type, binaryen.f64); info = binaryen.getExpressionInfo(theConst); - assert(info.type === theConst.type); - assert(info.value === theConst.valueF64); + assertEq(info.type, theConst.type); + assertEq(info.value, theConst.valueF64); theConst.valueV128 = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]; - assertDeepEqual(theConst.valueV128, [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]); + assertEq(theConst.valueV128, [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]); theConst.finalize(); - assert(theConst.type === binaryen.v128); + assertEq(theConst.type, binaryen.v128); info = binaryen.getExpressionInfo(theConst); - assert(info.type === theConst.type); - assertDeepEqual(info.value, theConst.valueV128); + assertEq(info.type, theConst.type); + assertEq(info.value, theConst.valueV128); console.log(theConst.toText()); assert( @@ -887,31 +888,31 @@ console.log("# Unary"); var op = binaryen.Operations.EqZInt32; var value = module.i32.const(1); - const theUnary = binaryen.Unary(module.i32.eqz(value)); + const theUnary = module.i32.eqz(value); assert(theUnary instanceof binaryen.Unary); assert(theUnary instanceof binaryen.Expression); - assert(theUnary.op === op); - assert(theUnary.value === value); - assert(theUnary.type === binaryen.i32); + assertEq(theUnary.op, op); + assertEq(theUnary.value, value); + assertEq(theUnary.type, binaryen.i32); var info = binaryen.getExpressionInfo(theUnary); - assert(info.id === theUnary.id); - assert(info.type === theUnary.type); - assert(info.op === theUnary.op); - assert(info.value === theUnary.value); + assertEq(info.id, theUnary.id); + assertEq(info.type, theUnary.type); + assertEq(info.op, theUnary.op); + assertEq(info.value, theUnary.value); theUnary.op = op = binaryen.Operations.EqZInt64; - assert(theUnary.op === op); + assertEq(theUnary.op, op); theUnary.value = value = module.i64.const(2); - assert(theUnary.value === value); + assertEq(theUnary.value, value); theUnary.type = binaryen.f32; theUnary.finalize(); - assert(theUnary.type === binaryen.i32); + assertEq(theUnary.type, binaryen.i32); info = binaryen.getExpressionInfo(theUnary); - assert(info.type === theUnary.type); - assert(info.op === theUnary.op); - assert(info.value === theUnary.value); + assertEq(info.type, theUnary.type); + assertEq(info.op, theUnary.op); + assertEq(info.value, theUnary.value); console.log(theUnary.toText()); assert( @@ -930,36 +931,36 @@ console.log("# Binary"); var op = binaryen.Operations.AddInt32; var left = module.i32.const(1); var right = module.i32.const(2); - const theBinary = binaryen.Binary(module.i32.add(left, right)); + const theBinary = module.i32.add(left, right); assert(theBinary instanceof binaryen.Binary); assert(theBinary instanceof binaryen.Expression); - assert(theBinary.op === op); - assert(theBinary.left === left); - assert(theBinary.right === right); - assert(theBinary.type === binaryen.i32) + assertEq(theBinary.op, op); + assertEq(theBinary.left, left); + assertEq(theBinary.right, right); + assertEq(theBinary.type, binaryen.i32) var info = binaryen.getExpressionInfo(theBinary); - assert(info.id === theBinary.id); - assert(info.type === theBinary.type); - assert(info.op === theBinary.op); - assert(info.left === theBinary.left); - assert(info.right === theBinary.right); + assertEq(info.id, theBinary.id); + assertEq(info.type, theBinary.type); + assertEq(info.op, theBinary.op); + assertEq(info.left, theBinary.left); + assertEq(info.right, theBinary.right); theBinary.op = op = binaryen.Operations.AddInt64; - assert(theBinary.op === op); + assertEq(theBinary.op, op); theBinary.left = left = module.i64.const(3); - assert(theBinary.left === left); + assertEq(theBinary.left, left); theBinary.right = right = module.i64.const(4); - assert(theBinary.right === right); + assertEq(theBinary.right, right); theBinary.type = binaryen.f32; theBinary.finalize(); - assert(theBinary.type === binaryen.i64); + assertEq(theBinary.type, binaryen.i64); info = binaryen.getExpressionInfo(theBinary); - assert(info.type === theBinary.type); - assert(info.op === theBinary.op); - assert(info.left === theBinary.left); - assert(info.right === theBinary.right); + assertEq(info.type, theBinary.type); + assertEq(info.op, theBinary.op); + assertEq(info.left, theBinary.left); + assertEq(info.right, theBinary.right); console.log(theBinary.toText()); assert( @@ -978,35 +979,35 @@ console.log("# Select"); var condition = module.i32.const(1); var ifTrue = module.i32.const(2); var ifFalse = module.i32.const(3); - const theSelect = binaryen.Select(module.select(condition, ifTrue, ifFalse)); assert(theSelect.ifTrue === ifTrue); + const theSelect = module.select(condition, ifTrue, ifFalse); assert(theSelect instanceof binaryen.Select); assert(theSelect instanceof binaryen.Expression); - assert(theSelect.condition === condition); - assert(theSelect.ifTrue === ifTrue); - assert(theSelect.ifFalse === ifFalse); - assert(theSelect.type === binaryen.i32); + assertEq(theSelect.condition, condition); + assertEq(theSelect.ifTrue, ifTrue); + assertEq(theSelect.ifFalse, ifFalse); + assertEq(theSelect.type, binaryen.i32); var info = binaryen.getExpressionInfo(theSelect); - assert(info.id === theSelect.id); - assert(info.type === theSelect.type); - assert(info.condition === theSelect.condition); - assert(info.ifTrue === theSelect.ifTrue); - assert(info.ifFalse === theSelect.ifFalse); + assertEq(info.id, theSelect.id); + assertEq(info.type, theSelect.type); + assertEq(info.condition, theSelect.condition); + assertEq(info.ifTrue, theSelect.ifTrue); + assertEq(info.ifFalse, theSelect.ifFalse); theSelect.condition = condition = module.i32.const(4); - assert(theSelect.condition === condition); + assertEq(theSelect.condition, condition); theSelect.ifTrue = ifTrue = module.i64.const(5); - assert(theSelect.ifTrue === ifTrue); + assertEq(theSelect.ifTrue, ifTrue); theSelect.ifFalse = ifFalse = module.i64.const(6); - assert(theSelect.ifFalse === ifFalse); + assertEq(theSelect.ifFalse, ifFalse); theSelect.finalize(); - assert(theSelect.type === binaryen.i64); + assertEq(theSelect.type, binaryen.i64); info = binaryen.getExpressionInfo(theSelect); - assert(info.type === theSelect.type); - assert(info.condition === theSelect.condition); - assert(info.ifTrue === theSelect.ifTrue); - assert(info.ifFalse === theSelect.ifFalse); + assertEq(info.type, theSelect.type); + assertEq(info.condition, theSelect.condition); + assertEq(info.ifTrue, theSelect.ifTrue); + assertEq(info.ifFalse, theSelect.ifFalse); console.log(theSelect.toText()); assert( @@ -1023,26 +1024,26 @@ console.log("# Drop"); const module = new binaryen.Module(); var value = module.i32.const(1); - const theDrop = binaryen.Drop(module.drop(value)); + const theDrop = module.drop(value); assert(theDrop instanceof binaryen.Drop); assert(theDrop instanceof binaryen.Expression); - assert(theDrop.value === value); - assert(theDrop.type === binaryen.none); + assertEq(theDrop.value, value); + assertEq(theDrop.type, binaryen.none); var info = binaryen.getExpressionInfo(theDrop); - assert(info.id === theDrop.id); - assert(info.type === theDrop.type); - assert(info.value === theDrop.value); + assertEq(info.id, theDrop.id); + assertEq(info.type, theDrop.type); + assertEq(info.value, theDrop.value); theDrop.value = value = module.i32.const(2); - assert(theDrop.value === value); + assertEq(theDrop.value, value); theDrop.finalize(); - assert(theDrop.type === binaryen.none); + assertEq(theDrop.type, binaryen.none); info = binaryen.getExpressionInfo(theDrop); - assert(info.type === theDrop.type); - assert(info.value === theDrop.value); + assertEq(info.type, theDrop.type); + assertEq(info.value, theDrop.value); console.log(theDrop.toText()); assert( @@ -1059,26 +1060,26 @@ console.log("# Return"); const module = new binaryen.Module(); var value = module.i32.const(1); - const theReturn = binaryen.Return(module.return(value)); + const theReturn = module.return(value); assert(theReturn instanceof binaryen.Return); assert(theReturn instanceof binaryen.Expression); - assert(theReturn.value === value); - assert(theReturn.type === binaryen.unreachable); + assertEq(theReturn.value, value); + assertEq(theReturn.type, binaryen.unreachable); var info = binaryen.getExpressionInfo(theReturn); - assert(info.id === theReturn.id); - assert(info.type === theReturn.type); - assert(info.value === theReturn.value); + assertEq(info.id, theReturn.id); + assertEq(info.type, theReturn.type); + assertEq(info.value, theReturn.value); theReturn.value = value = module.i32.const(2); - assert(theReturn.value === value); + assertEq(theReturn.value, value); theReturn.finalize(); - assert(theReturn.type === binaryen.unreachable); + assertEq(theReturn.type, binaryen.unreachable); info = binaryen.getExpressionInfo(theReturn); - assert(info.type === theReturn.type); - assert(info.value === theReturn.value); + assertEq(info.type, theReturn.type); + assertEq(info.value, theReturn.value); console.log(theReturn.toText()); assert( @@ -1099,46 +1100,46 @@ console.log("# AtomicRMW"); var offset = 8; var ptr = module.i32.const(2); var value = module.i32.const(3); - const theAtomicRMW = binaryen.AtomicRMW(module.i32.atomic.rmw.add(offset, ptr, value)); + const theAtomicRMW = module.i32.atomic.rmw.add(offset, ptr, value); assert(theAtomicRMW instanceof binaryen.AtomicRMW); assert(theAtomicRMW instanceof binaryen.Expression); - assert(theAtomicRMW.op === op); - assert(theAtomicRMW.bytes === 4); - assert(theAtomicRMW.offset === offset); - assert(theAtomicRMW.ptr === ptr); - assert(theAtomicRMW.value === value); - assert(theAtomicRMW.type === binaryen.i32); + assertEq(theAtomicRMW.op, op); + assertEq(theAtomicRMW.bytes, 4); + assertEq(theAtomicRMW.offset, offset); + assertEq(theAtomicRMW.ptr, ptr); + assertEq(theAtomicRMW.value, value); + assertEq(theAtomicRMW.type, binaryen.i32); var info = binaryen.getExpressionInfo(theAtomicRMW); - assert(info.id === theAtomicRMW.id); - assert(info.type === theAtomicRMW.type); - assert(info.op === theAtomicRMW.op); - assert(info.bytes === theAtomicRMW.bytes); - assert(info.offset === theAtomicRMW.offset); - assert(info.ptr === theAtomicRMW.ptr); - assert(info.value === theAtomicRMW.value); + assertEq(info.id, theAtomicRMW.id); + assertEq(info.type, theAtomicRMW.type); + assertEq(info.op, theAtomicRMW.op); + assertEq(info.bytes, theAtomicRMW.bytes); + assertEq(info.offset, theAtomicRMW.offset); + assertEq(info.ptr, theAtomicRMW.ptr); + assertEq(info.value, theAtomicRMW.value); theAtomicRMW.op = op = binaryen.Operations.AtomicRMWSub; - assert(theAtomicRMW.op === op); + assertEq(theAtomicRMW.op, op); theAtomicRMW.bytes = 2; - assert(theAtomicRMW.bytes === 2); + assertEq(theAtomicRMW.bytes, 2); theAtomicRMW.offset = offset = 16; - assert(theAtomicRMW.offset === offset); + assertEq(theAtomicRMW.offset, offset); theAtomicRMW.ptr = ptr = module.i32.const(4); - assert(theAtomicRMW.ptr === ptr); + assertEq(theAtomicRMW.ptr, ptr); theAtomicRMW.value = value = module.i64.const(5); - assert(theAtomicRMW.value === value); + assertEq(theAtomicRMW.value, value); theAtomicRMW.type = binaryen.i64; theAtomicRMW.finalize(); - assert(theAtomicRMW.type === binaryen.i64); + assertEq(theAtomicRMW.type, binaryen.i64); info = binaryen.getExpressionInfo(theAtomicRMW); - assert(info.type === theAtomicRMW.type); - assert(info.op === theAtomicRMW.op); - assert(info.bytes === theAtomicRMW.bytes); - assert(info.offset === theAtomicRMW.offset); - assert(info.ptr === theAtomicRMW.ptr); - assert(info.value === theAtomicRMW.value); + assertEq(info.type, theAtomicRMW.type); + assertEq(info.op, theAtomicRMW.op); + assertEq(info.bytes, theAtomicRMW.bytes); + assertEq(info.offset, theAtomicRMW.offset); + assertEq(info.ptr, theAtomicRMW.ptr); + assertEq(info.value, theAtomicRMW.value); console.log(theAtomicRMW.toText()); assert( @@ -1159,46 +1160,46 @@ console.log("# AtomicCmpxchg"); var ptr = module.i32.const(2); var expected = module.i32.const(3); var replacement = module.i32.const(4); - const theAtomicCmpxchg = binaryen.AtomicCmpxchg(module.i32.atomic.rmw.cmpxchg(offset, ptr, expected, replacement)); + const theAtomicCmpxchg = module.i32.atomic.rmw.cmpxchg(offset, ptr, expected, replacement); assert(theAtomicCmpxchg instanceof binaryen.AtomicCmpxchg); assert(theAtomicCmpxchg instanceof binaryen.Expression); - assert(theAtomicCmpxchg.bytes === 4); - assert(theAtomicCmpxchg.offset === offset); - assert(theAtomicCmpxchg.ptr === ptr); - assert(theAtomicCmpxchg.expected === expected); - assert(theAtomicCmpxchg.replacement === replacement); - assert(theAtomicCmpxchg.type === binaryen.i32); + assertEq(theAtomicCmpxchg.bytes, 4); + assertEq(theAtomicCmpxchg.offset, offset); + assertEq(theAtomicCmpxchg.ptr, ptr); + assertEq(theAtomicCmpxchg.expected, expected); + assertEq(theAtomicCmpxchg.replacement, replacement); + assertEq(theAtomicCmpxchg.type, binaryen.i32); var info = binaryen.getExpressionInfo(theAtomicCmpxchg); - assert(info.id === theAtomicCmpxchg.id); - assert(info.type === theAtomicCmpxchg.type); - assert(info.bytes === theAtomicCmpxchg.bytes); - assert(info.offset === theAtomicCmpxchg.offset); - assert(info.ptr === theAtomicCmpxchg.ptr); - assert(info.expected === theAtomicCmpxchg.expected); - assert(info.replacement === theAtomicCmpxchg.replacement); + assertEq(info.id, theAtomicCmpxchg.id); + assertEq(info.type, theAtomicCmpxchg.type); + assertEq(info.bytes, theAtomicCmpxchg.bytes); + assertEq(info.offset, theAtomicCmpxchg.offset); + assertEq(info.ptr, theAtomicCmpxchg.ptr); + assertEq(info.expected, theAtomicCmpxchg.expected); + assertEq(info.replacement, theAtomicCmpxchg.replacement); theAtomicCmpxchg.bytes = 2; - assert(theAtomicCmpxchg.bytes === 2); + assertEq(theAtomicCmpxchg.bytes, 2); theAtomicCmpxchg.offset = offset = 16; - assert(theAtomicCmpxchg.offset === offset); + assertEq(theAtomicCmpxchg.offset, offset); theAtomicCmpxchg.ptr = ptr = module.i32.const(5); - assert(theAtomicCmpxchg.ptr === ptr); + assertEq(theAtomicCmpxchg.ptr, ptr); theAtomicCmpxchg.expected = expected = module.i64.const(6); - assert(theAtomicCmpxchg.expected === expected); + assertEq(theAtomicCmpxchg.expected, expected); theAtomicCmpxchg.replacement = replacement = module.i64.const(7); - assert(theAtomicCmpxchg.replacement === replacement); + assertEq(theAtomicCmpxchg.replacement, replacement); theAtomicCmpxchg.type = binaryen.i64; theAtomicCmpxchg.finalize(); - assert(theAtomicCmpxchg.type === binaryen.i64); + assertEq(theAtomicCmpxchg.type, binaryen.i64); info = binaryen.getExpressionInfo(theAtomicCmpxchg); - assert(info.type === theAtomicCmpxchg.type); - assert(info.bytes === theAtomicCmpxchg.bytes); - assert(info.offset === theAtomicCmpxchg.offset); - assert(info.ptr === theAtomicCmpxchg.ptr); - assert(info.expected === theAtomicCmpxchg.expected); - assert(info.replacement === theAtomicCmpxchg.replacement); + assertEq(info.type, theAtomicCmpxchg.type); + assertEq(info.bytes, theAtomicCmpxchg.bytes); + assertEq(info.offset, theAtomicCmpxchg.offset); + assertEq(info.ptr, theAtomicCmpxchg.ptr); + assertEq(info.expected, theAtomicCmpxchg.expected); + assertEq(info.replacement, theAtomicCmpxchg.replacement); console.log(theAtomicCmpxchg.toText()); assert( @@ -1218,41 +1219,41 @@ console.log("# AtomicWait"); var ptr = module.i32.const(2); var expected = module.i32.const(3); var timeout = module.i64.const(4); - const theAtomicWait = binaryen.AtomicWait(module.memory.atomic.wait32(ptr, expected, timeout)); + const theAtomicWait = module.memory.atomic.wait32(ptr, expected, timeout); assert(theAtomicWait instanceof binaryen.AtomicWait); assert(theAtomicWait instanceof binaryen.Expression); - assert(theAtomicWait.ptr === ptr); - assert(theAtomicWait.expected === expected); - assert(theAtomicWait.expectedType === binaryen.i32); - assert(theAtomicWait.timeout === timeout); - assert(theAtomicWait.type === binaryen.i32); + assertEq(theAtomicWait.ptr, ptr); + assertEq(theAtomicWait.expected, expected); + assertEq(theAtomicWait.expectedType, binaryen.i32); + assertEq(theAtomicWait.timeout, timeout); + assertEq(theAtomicWait.type, binaryen.i32); var info = binaryen.getExpressionInfo(theAtomicWait); - assert(info.id === theAtomicWait.id); - assert(info.type === theAtomicWait.type); - assert(info.ptr === theAtomicWait.ptr); - assert(info.expected === theAtomicWait.expected); - assert(info.expectedType === theAtomicWait.expectedType); - assert(info.timeout === theAtomicWait.timeout); + assertEq(info.id, theAtomicWait.id); + assertEq(info.type, theAtomicWait.type); + assertEq(info.ptr, theAtomicWait.ptr); + assertEq(info.expected, theAtomicWait.expected); + assertEq(info.expectedType, theAtomicWait.expectedType); + assertEq(info.timeout, theAtomicWait.timeout); theAtomicWait.ptr = ptr = module.i32.const(5); - assert(theAtomicWait.ptr === ptr); + assertEq(theAtomicWait.ptr, ptr); theAtomicWait.expected = expected = module.i32.const(6); - assert(theAtomicWait.expected === expected); + assertEq(theAtomicWait.expected, expected); theAtomicWait.expectedType = binaryen.i64; - assert(theAtomicWait.expectedType === binaryen.i64); + assertEq(theAtomicWait.expectedType, binaryen.i64); theAtomicWait.timeout = timeout = module.i64.const(7); - assert(theAtomicWait.timeout === timeout); + assertEq(theAtomicWait.timeout, timeout); theAtomicWait.type = binaryen.f64; theAtomicWait.finalize(); - assert(theAtomicWait.type === binaryen.i32); + assertEq(theAtomicWait.type, binaryen.i32); info = binaryen.getExpressionInfo(theAtomicWait); - assert(info.type === theAtomicWait.type); - assert(info.ptr === theAtomicWait.ptr); - assert(info.expected === theAtomicWait.expected); - assert(info.expectedType === theAtomicWait.expectedType); - assert(info.timeout === theAtomicWait.timeout); + assertEq(info.type, theAtomicWait.type); + assertEq(info.ptr, theAtomicWait.ptr); + assertEq(info.expected, theAtomicWait.expected); + assertEq(info.expectedType, theAtomicWait.expectedType); + assertEq(info.timeout, theAtomicWait.timeout); console.log(theAtomicWait.toText()); assert( @@ -1271,31 +1272,31 @@ console.log("# AtomicNotify"); var ptr = module.i32.const(1); var notifyCount = module.i32.const(2); - const theAtomicNotify = binaryen.AtomicNotify(module.memory.atomic.notify(ptr, notifyCount)); + const theAtomicNotify = module.memory.atomic.notify(ptr, notifyCount); assert(theAtomicNotify instanceof binaryen.AtomicNotify); assert(theAtomicNotify instanceof binaryen.Expression); - assert(theAtomicNotify.ptr === ptr); - assert(theAtomicNotify.notifyCount === notifyCount); - assert(theAtomicNotify.type === binaryen.i32); + assertEq(theAtomicNotify.ptr, ptr); + assertEq(theAtomicNotify.notifyCount, notifyCount); + assertEq(theAtomicNotify.type, binaryen.i32); var info = binaryen.getExpressionInfo(theAtomicNotify); - assert(info.id === theAtomicNotify.id); - assert(info.type === theAtomicNotify.type); - assert(info.ptr === theAtomicNotify.ptr); - assert(info.notifyCount === theAtomicNotify.notifyCount); + assertEq(info.id, theAtomicNotify.id); + assertEq(info.type, theAtomicNotify.type); + assertEq(info.ptr, theAtomicNotify.ptr); + assertEq(info.notifyCount, theAtomicNotify.notifyCount); theAtomicNotify.ptr = ptr = module.i32.const(3); - assert(theAtomicNotify.ptr === ptr); + assertEq(theAtomicNotify.ptr, ptr); theAtomicNotify.notifyCount = notifyCount = module.i32.const(4); - assert(theAtomicNotify.notifyCount === notifyCount); + assertEq(theAtomicNotify.notifyCount, notifyCount); theAtomicNotify.type = binaryen.f64; theAtomicNotify.finalize(); - assert(theAtomicNotify.type === binaryen.i32); + assertEq(theAtomicNotify.type, binaryen.i32); info = binaryen.getExpressionInfo(theAtomicNotify); - assert(info.type === theAtomicNotify.type); - assert(info.ptr === theAtomicNotify.ptr); - assert(info.notifyCount === theAtomicNotify.notifyCount); + assertEq(info.type, theAtomicNotify.type); + assertEq(info.ptr, theAtomicNotify.ptr); + assertEq(info.notifyCount, theAtomicNotify.notifyCount); console.log(theAtomicNotify.toText()); assert( @@ -1311,26 +1312,26 @@ console.log("# AtomicFence"); (function testAtomicFence() { const module = new binaryen.Module(); - const theAtomicFence = binaryen.AtomicFence(module.atomic.fence()); + const theAtomicFence = module.atomic.fence(); assert(theAtomicFence instanceof binaryen.AtomicFence); assert(theAtomicFence instanceof binaryen.Expression); - assert(theAtomicFence.order === 0); // reserved, not yet used - assert(theAtomicFence.type === binaryen.none); + assertEq(theAtomicFence.order, 0); // reserved, not yet used + assertEq(theAtomicFence.type, binaryen.none); var info = binaryen.getExpressionInfo(theAtomicFence); - assert(info.id === theAtomicFence.id); - assert(info.type === theAtomicFence.type); - assert(info.order === theAtomicFence.order); + assertEq(info.id, theAtomicFence.id); + assertEq(info.type, theAtomicFence.type); + assertEq(info.order, theAtomicFence.order); theAtomicFence.order = 1; - assert(theAtomicFence.order === 1); + assertEq(theAtomicFence.order, 1); theAtomicFence.type = binaryen.f64; theAtomicFence.finalize(); - assert(theAtomicFence.type === binaryen.none); + assertEq(theAtomicFence.type, binaryen.none); info = binaryen.getExpressionInfo(theAtomicFence); - assert(info.type === theAtomicFence.type); - assert(info.order === theAtomicFence.order); + assertEq(info.type, theAtomicFence.type); + assertEq(info.order, theAtomicFence.order); console.log(theAtomicFence.toText()); assert( @@ -1349,36 +1350,36 @@ console.log("# SIMDExtract"); var op = binaryen.Operations.ExtractLaneSVecI8x16; var vec = module.v128.const([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]); var index = 0; - const theSIMDExtract = binaryen.SIMDExtract(module.i8x16.extract_lane_s(vec, index)); + const theSIMDExtract = module.i8x16.extract_lane_s(vec, index); assert(theSIMDExtract instanceof binaryen.SIMDExtract); assert(theSIMDExtract instanceof binaryen.Expression); - assert(theSIMDExtract.op === op); - assert(theSIMDExtract.vec === vec); - assert(theSIMDExtract.index === index); - assert(theSIMDExtract.type === binaryen.i32); + assertEq(theSIMDExtract.op, op); + assertEq(theSIMDExtract.vec, vec); + assertEq(theSIMDExtract.index, index); + assertEq(theSIMDExtract.type, binaryen.i32); var info = binaryen.getExpressionInfo(theSIMDExtract); - assert(info.id === theSIMDExtract.id); - assert(info.type === theSIMDExtract.type); - assert(info.op === theSIMDExtract.op); - assert(info.vec === theSIMDExtract.vec); - assert(info.index === theSIMDExtract.index); + assertEq(info.id, theSIMDExtract.id); + assertEq(info.type, theSIMDExtract.type); + assertEq(info.op, theSIMDExtract.op); + assertEq(info.vec, theSIMDExtract.vec); + assertEq(info.index, theSIMDExtract.index); theSIMDExtract.op = op = binaryen.Operations.ExtractLaneSVecI16x8; - assert(theSIMDExtract.op === op); + assertEq(theSIMDExtract.op, op); theSIMDExtract.vec = vec = module.v128.const([1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]); - assert(theSIMDExtract.vec === vec); + assertEq(theSIMDExtract.vec, vec); theSIMDExtract.index = index = 1; - assert(theSIMDExtract.index === index); + assertEq(theSIMDExtract.index, index); theSIMDExtract.type = binaryen.f64; theSIMDExtract.finalize(); - assert(theSIMDExtract.type === binaryen.i32); + assertEq(theSIMDExtract.type, binaryen.i32); info = binaryen.getExpressionInfo(theSIMDExtract); - assert(info.type === theSIMDExtract.type); - assert(info.op === theSIMDExtract.op); - assert(info.vec === theSIMDExtract.vec); - assert(info.index === theSIMDExtract.index); + assertEq(info.type, theSIMDExtract.type); + assertEq(info.op, theSIMDExtract.op); + assertEq(info.vec, theSIMDExtract.vec); + assertEq(info.index, theSIMDExtract.index); console.log(theSIMDExtract.toText()); assert( @@ -1398,41 +1399,41 @@ console.log("# SIMDReplace"); var vec = module.v128.const([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]); var index = 0; var value = module.i32.const(1); - const theSIMDReplace = binaryen.SIMDReplace(module.i8x16.replace_lane(vec, index, value)); + const theSIMDReplace = module.i8x16.replace_lane(vec, index, value); assert(theSIMDReplace instanceof binaryen.SIMDReplace); assert(theSIMDReplace instanceof binaryen.Expression); - assert(theSIMDReplace.op === op); - assert(theSIMDReplace.vec === vec); - assert(theSIMDReplace.index === index); - assert(theSIMDReplace.value === value); - assert(theSIMDReplace.type === binaryen.v128); + assertEq(theSIMDReplace.op, op); + assertEq(theSIMDReplace.vec, vec); + assertEq(theSIMDReplace.index, index); + assertEq(theSIMDReplace.value, value); + assertEq(theSIMDReplace.type, binaryen.v128); var info = binaryen.getExpressionInfo(theSIMDReplace); - assert(info.id === theSIMDReplace.id); - assert(info.type === theSIMDReplace.type); - assert(info.op === theSIMDReplace.op); - assert(info.vec === theSIMDReplace.vec); - assert(info.index === theSIMDReplace.index); - assert(info.value === theSIMDReplace.value); + assertEq(info.id, theSIMDReplace.id); + assertEq(info.type, theSIMDReplace.type); + assertEq(info.op, theSIMDReplace.op); + assertEq(info.vec, theSIMDReplace.vec); + assertEq(info.index, theSIMDReplace.index); + assertEq(info.value, theSIMDReplace.value); theSIMDReplace.op = op = binaryen.Operations.ReplaceLaneVecI16x8; - assert(theSIMDReplace.op === op); + assertEq(theSIMDReplace.op, op); theSIMDReplace.vec = vec = module.v128.const([1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]); - assert(theSIMDReplace.vec === vec); + assertEq(theSIMDReplace.vec, vec); theSIMDReplace.index = index = 1; - assert(theSIMDReplace.index === index); + assertEq(theSIMDReplace.index, index); theSIMDReplace.value = value = module.i32.const(2); - assert(theSIMDReplace.value === value); + assertEq(theSIMDReplace.value, value); theSIMDReplace.type = binaryen.f64; theSIMDReplace.finalize(); - assert(theSIMDReplace.type === binaryen.v128); + assertEq(theSIMDReplace.type, binaryen.v128); info = binaryen.getExpressionInfo(theSIMDReplace); - assert(info.type === theSIMDReplace.type); - assert(info.op === theSIMDReplace.op); - assert(info.vec === theSIMDReplace.vec); - assert(info.index === theSIMDReplace.index); - assert(info.value === theSIMDReplace.value); + assertEq(info.type, theSIMDReplace.type); + assertEq(info.op, theSIMDReplace.op); + assertEq(info.vec, theSIMDReplace.vec); + assertEq(info.index, theSIMDReplace.index); + assertEq(info.value, theSIMDReplace.value); console.log(theSIMDReplace.toText()); assert( @@ -1451,36 +1452,36 @@ console.log("# SIMDShuffle"); var left = module.v128.const([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]); var right = module.v128.const([2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17]); var mask = [3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18]; - const theSIMDShuffle = binaryen.SIMDShuffle(module.i8x16.shuffle(left, right, mask)); + const theSIMDShuffle = module.i8x16.shuffle(left, right, mask); assert(theSIMDShuffle instanceof binaryen.SIMDShuffle); assert(theSIMDShuffle instanceof binaryen.Expression); - assert(theSIMDShuffle.left === left); - assert(theSIMDShuffle.right === right); - assertDeepEqual(theSIMDShuffle.mask, mask); - assert(theSIMDShuffle.type === binaryen.v128); + assertEq(theSIMDShuffle.left, left); + assertEq(theSIMDShuffle.right, right); + assertEq(theSIMDShuffle.mask, mask); + assertEq(theSIMDShuffle.type, binaryen.v128); var info = binaryen.getExpressionInfo(theSIMDShuffle); - assert(info.id === theSIMDShuffle.id); - assert(info.type === theSIMDShuffle.type); - assert(info.left === theSIMDShuffle.left); - assert(info.right === theSIMDShuffle.right); - assertDeepEqual(info.mask, theSIMDShuffle.mask); + assertEq(info.id, theSIMDShuffle.id); + assertEq(info.type, theSIMDShuffle.type); + assertEq(info.left, theSIMDShuffle.left); + assertEq(info.right, theSIMDShuffle.right); + assertEq(info.mask, theSIMDShuffle.mask); theSIMDShuffle.left = left = module.v128.const([1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]); - assert(theSIMDShuffle.left === left); + assertEq(theSIMDShuffle.left, left); theSIMDShuffle.right = right = module.v128.const([2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2]); - assert(theSIMDShuffle.right === right); + assertEq(theSIMDShuffle.right, right); theSIMDShuffle.mask = mask = [3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3]; - assertDeepEqual(theSIMDShuffle.mask, mask); + assertEq(theSIMDShuffle.mask, mask); theSIMDShuffle.type = binaryen.f64; theSIMDShuffle.finalize(); - assert(theSIMDShuffle.type === binaryen.v128); + assertEq(theSIMDShuffle.type, binaryen.v128); info = binaryen.getExpressionInfo(theSIMDShuffle); - assert(info.type === theSIMDShuffle.type); - assert(info.left === theSIMDShuffle.left); - assert(info.right === theSIMDShuffle.right); - assertDeepEqual(info.mask, theSIMDShuffle.mask); + assertEq(info.type, theSIMDShuffle.type); + assertEq(info.left, theSIMDShuffle.left); + assertEq(info.right, theSIMDShuffle.right); + assertEq(info.mask, theSIMDShuffle.mask); console.log(theSIMDShuffle.toText()); assert( @@ -1500,22 +1501,22 @@ console.log("# SIMDTernary"); var a = module.v128.const([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]); var b = module.v128.const([2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17]); var c = module.v128.const([3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18]); - const theSIMDTernary = binaryen.SIMDTernary(module.v128.bitselect(a, b, c)); + const theSIMDTernary = module.v128.bitselect(a, b, c); assert(theSIMDTernary instanceof binaryen.SIMDTernary); assert(theSIMDTernary instanceof binaryen.Expression); - assert(theSIMDTernary.op === op); - assert(theSIMDTernary.a === a); - assert(theSIMDTernary.b === b); - assert(theSIMDTernary.c === c); - assert(theSIMDTernary.type === binaryen.v128); + assertEq(theSIMDTernary.op, op); + assertEq(theSIMDTernary.a, a); + assertEq(theSIMDTernary.b, b); + assertEq(theSIMDTernary.c, c); + assertEq(theSIMDTernary.type, binaryen.v128); var info = binaryen.getExpressionInfo(theSIMDTernary); - assert(info.id === theSIMDTernary.id); - assert(info.type === theSIMDTernary.type); - assert(info.op === theSIMDTernary.op); - assert(info.a === theSIMDTernary.a); - assert(info.b === theSIMDTernary.b); - assert(info.c === theSIMDTernary.c); + assertEq(info.id, theSIMDTernary.id); + assertEq(info.type, theSIMDTernary.type); + assertEq(info.op, theSIMDTernary.op); + assertEq(info.a, theSIMDTernary.a); + assertEq(info.b, theSIMDTernary.b); + assertEq(info.c, theSIMDTernary.c); console.log(theSIMDTernary.toText() + "\n"); assert( @@ -1534,36 +1535,36 @@ console.log("# SIMDShift"); var op = binaryen.Operations.BitselectVec128; var vec = module.v128.const([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]); var shift = module.i32.const(1); - const theSIMDShift = binaryen.SIMDShift(module.i8x16.shl(vec, shift)); + const theSIMDShift = module.i8x16.shl(vec, shift); assert(theSIMDShift instanceof binaryen.SIMDShift); assert(theSIMDShift instanceof binaryen.Expression); - assert(theSIMDShift.op === op); - assert(theSIMDShift.vec === vec); - assert(theSIMDShift.shift === shift); - assert(theSIMDShift.type === binaryen.v128); + assertEq(theSIMDShift.op, op); + assertEq(theSIMDShift.vec, vec); + assertEq(theSIMDShift.shift, shift); + assertEq(theSIMDShift.type, binaryen.v128); var info = binaryen.getExpressionInfo(theSIMDShift); - assert(info.id === theSIMDShift.id); - assert(info.type === theSIMDShift.type); - assert(info.op === theSIMDShift.op); - assert(info.vec === theSIMDShift.vec); - assert(info.shift === theSIMDShift.shift); + assertEq(info.id, theSIMDShift.id); + assertEq(info.type, theSIMDShift.type); + assertEq(info.op, theSIMDShift.op); + assertEq(info.vec, theSIMDShift.vec); + assertEq(info.shift, theSIMDShift.shift); theSIMDShift.op = op = binaryen.Operations.ShrSVecI8x16; - assert(theSIMDShift.op === op); + assertEq(theSIMDShift.op, op); theSIMDShift.vec = vec = module.v128.const([1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]); - assert(theSIMDShift.vec === vec); + assertEq(theSIMDShift.vec, vec); theSIMDShift.shift = shift = module.i32.const(2); - assert(theSIMDShift.shift === shift); + assertEq(theSIMDShift.shift, shift); theSIMDShift.type = binaryen.f64; theSIMDShift.finalize(); - assert(theSIMDShift.type === binaryen.v128); + assertEq(theSIMDShift.type, binaryen.v128); info = binaryen.getExpressionInfo(theSIMDShift); - assert(info.type === theSIMDShift.type); - assert(info.op === theSIMDShift.op); - assert(info.vec === theSIMDShift.vec); - assert(info.shift === theSIMDShift.shift); + assertEq(info.type, theSIMDShift.type); + assertEq(info.op, theSIMDShift.op); + assertEq(info.vec, theSIMDShift.vec); + assertEq(info.shift, theSIMDShift.shift); console.log(theSIMDShift.toText()); assert( @@ -1584,38 +1585,38 @@ console.log("# SIMDLoad"); var offset = 16; var align = 2; var ptr = module.i32.const(1); - const theSIMDLoad = binaryen.SIMDLoad(module.v128.load8x8_s(offset, align, ptr)); + const theSIMDLoad = module.v128.load8x8_s(offset, align, ptr); assert(theSIMDLoad instanceof binaryen.SIMDLoad); assert(theSIMDLoad instanceof binaryen.Expression); - assert(theSIMDLoad.offset === offset); - assert(theSIMDLoad.align === align); - assert(theSIMDLoad.ptr === ptr); - assert(theSIMDLoad.type === binaryen.v128); + assertEq(theSIMDLoad.offset, offset); + assertEq(theSIMDLoad.align, align); + assertEq(theSIMDLoad.ptr, ptr); + assertEq(theSIMDLoad.type, binaryen.v128); var info = binaryen.getExpressionInfo(theSIMDLoad); - assert(info.id === theSIMDLoad.id); - assert(info.type === theSIMDLoad.type); - assert(info.offset === theSIMDLoad.offset); - assert(info.align === theSIMDLoad.align); - assert(info.ptr === theSIMDLoad.ptr); + assertEq(info.id, theSIMDLoad.id); + assertEq(info.type, theSIMDLoad.type); + assertEq(info.offset, theSIMDLoad.offset); + assertEq(info.align, theSIMDLoad.align); + assertEq(info.ptr, theSIMDLoad.ptr); theSIMDLoad.op = op = binaryen.Operations.Load8SplatVec128; - assert(theSIMDLoad.op === op); + assertEq(theSIMDLoad.op, op); theSIMDLoad.offset = offset = 32; - assert(theSIMDLoad.offset === offset); + assertEq(theSIMDLoad.offset, offset); theSIMDLoad.align = align = 4; - assert(theSIMDLoad.align === align); + assertEq(theSIMDLoad.align, align); theSIMDLoad.ptr = ptr = module.i32.const(2); - assert(theSIMDLoad.ptr === ptr); + assertEq(theSIMDLoad.ptr, ptr); theSIMDLoad.type = binaryen.f64; theSIMDLoad.finalize(); - assert(theSIMDLoad.type === binaryen.v128); + assertEq(theSIMDLoad.type, binaryen.v128); info = binaryen.getExpressionInfo(theSIMDLoad); - assert(info.type === theSIMDLoad.type); - assert(info.offset === theSIMDLoad.offset); - assert(info.align === theSIMDLoad.align); - assert(info.ptr === theSIMDLoad.ptr); + assertEq(info.type, theSIMDLoad.type); + assertEq(info.offset, theSIMDLoad.offset); + assertEq(info.align, theSIMDLoad.align); + assertEq(info.ptr, theSIMDLoad.ptr); console.log(theSIMDLoad.toText()); assert( @@ -1638,53 +1639,53 @@ console.log("# SIMDLoadStoreLane"); var align = 1; var ptr = module.i32.const(1); var vec = module.v128.const([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]); - const theSIMDLoadStoreLane = binaryen.SIMDLoadStoreLane(module.v128.load8_lane(offset, align, index, ptr, vec)); + const theSIMDLoadStoreLane = module.v128.load8_lane(offset, align, index, ptr, vec); assert(theSIMDLoadStoreLane instanceof binaryen.SIMDLoadStoreLane); assert(theSIMDLoadStoreLane instanceof binaryen.Expression); - assert(theSIMDLoadStoreLane.op === op); - assert(theSIMDLoadStoreLane.offset === offset); - assert(theSIMDLoadStoreLane.align === align); - assert(theSIMDLoadStoreLane.index === index); - assert(theSIMDLoadStoreLane.ptr === ptr); - assert(theSIMDLoadStoreLane.vec === vec); - assert(theSIMDLoadStoreLane.type === binaryen.v128); - assert(theSIMDLoadStoreLane.store === false); + assertEq(theSIMDLoadStoreLane.op, op); + assertEq(theSIMDLoadStoreLane.offset, offset); + assertEq(theSIMDLoadStoreLane.align, align); + assertEq(theSIMDLoadStoreLane.index, index); + assertEq(theSIMDLoadStoreLane.ptr, ptr); + assertEq(theSIMDLoadStoreLane.vec, vec); + assertEq(theSIMDLoadStoreLane.type, binaryen.v128); + assertEq(theSIMDLoadStoreLane.store, false); var info = binaryen.getExpressionInfo(theSIMDLoadStoreLane); - assert(info.id === theSIMDLoadStoreLane.id); - assert(info.type === theSIMDLoadStoreLane.type); - assert(info.op === theSIMDLoadStoreLane.op); - assert(info.offset === theSIMDLoadStoreLane.offset); - assert(info.align === theSIMDLoadStoreLane.align); - assert(info.index === theSIMDLoadStoreLane.index); - assert(info.ptr === theSIMDLoadStoreLane.ptr); - assert(info.vec === theSIMDLoadStoreLane.vec); - assert(info.isStore === theSIMDLoadStoreLane.store); + assertEq(info.id, theSIMDLoadStoreLane.id); + assertEq(info.type, theSIMDLoadStoreLane.type); + assertEq(info.op, theSIMDLoadStoreLane.op); + assertEq(info.offset, theSIMDLoadStoreLane.offset); + assertEq(info.align, theSIMDLoadStoreLane.align); + assertEq(info.index, theSIMDLoadStoreLane.index); + assertEq(info.ptr, theSIMDLoadStoreLane.ptr); + assertEq(info.vec, theSIMDLoadStoreLane.vec); + assertEq(info.isStore, theSIMDLoadStoreLane.store); theSIMDLoadStoreLane.op = op = binaryen.Operations.Load16LaneVec128; - assert(theSIMDLoadStoreLane.op === op); + assertEq(theSIMDLoadStoreLane.op, op); theSIMDLoadStoreLane.offset = offset = 32; - assert(theSIMDLoadStoreLane.offset === offset); + assertEq(theSIMDLoadStoreLane.offset, offset); theSIMDLoadStoreLane.align = align = 2; - assert(theSIMDLoadStoreLane.align === align); + assertEq(theSIMDLoadStoreLane.align, align); theSIMDLoadStoreLane.index = index = 2; - assert(theSIMDLoadStoreLane.index === index); + assertEq(theSIMDLoadStoreLane.index, index); theSIMDLoadStoreLane.ptr = ptr = module.i32.const(2); - assert(theSIMDLoadStoreLane.ptr === ptr); + assertEq(theSIMDLoadStoreLane.ptr, ptr); theSIMDLoadStoreLane.vec = vec = module.v128.const([1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]); - assert(theSIMDLoadStoreLane.vec === vec); + assertEq(theSIMDLoadStoreLane.vec, vec); theSIMDLoadStoreLane.type = binaryen.f64; theSIMDLoadStoreLane.finalize(); - assert(theSIMDLoadStoreLane.type === binaryen.v128); + assertEq(theSIMDLoadStoreLane.type, binaryen.v128); info = binaryen.getExpressionInfo(theSIMDLoadStoreLane); - assert(info.type === theSIMDLoadStoreLane.type); - assert(info.op === theSIMDLoadStoreLane.op); - assert(info.offset === theSIMDLoadStoreLane.offset); - assert(info.align === theSIMDLoadStoreLane.align); - assert(info.index === theSIMDLoadStoreLane.index); - assert(info.ptr === theSIMDLoadStoreLane.ptr); - assert(info.vec === theSIMDLoadStoreLane.vec); + assertEq(info.type, theSIMDLoadStoreLane.type); + assertEq(info.op, theSIMDLoadStoreLane.op); + assertEq(info.offset, theSIMDLoadStoreLane.offset); + assertEq(info.align, theSIMDLoadStoreLane.align); + assertEq(info.index, theSIMDLoadStoreLane.index); + assertEq(info.ptr, theSIMDLoadStoreLane.ptr); + assertEq(info.vec, theSIMDLoadStoreLane.vec); console.log(theSIMDLoadStoreLane.toText()); assert( @@ -1694,16 +1695,16 @@ console.log("# SIMDLoadStoreLane"); ); theSIMDLoadStoreLane.op = op = binaryen.Operations.Store16LaneVec128; - assert(theSIMDLoadStoreLane.op === op); + assertEq(theSIMDLoadStoreLane.op, op); theSIMDLoadStoreLane.type = binaryen.f64; - assert(theSIMDLoadStoreLane.store === true); + assertEq(theSIMDLoadStoreLane.store, true); theSIMDLoadStoreLane.finalize(); - assert(theSIMDLoadStoreLane.type === binaryen.none); + assertEq(theSIMDLoadStoreLane.type, binaryen.none); info = binaryen.getExpressionInfo(theSIMDLoadStoreLane); - assert(info.type === theSIMDLoadStoreLane.type); - assert(info.op === theSIMDLoadStoreLane.op); - assert(info.isStore === theSIMDLoadStoreLane.store); + assertEq(info.type, theSIMDLoadStoreLane.type); + assertEq(info.op, theSIMDLoadStoreLane.op); + assertEq(info.isStore, theSIMDLoadStoreLane.store); console.log(theSIMDLoadStoreLane.toText()); assert( @@ -1724,41 +1725,41 @@ console.log("# MemoryInit"); var dest = module.i32.const(2); var offset = module.i32.const(3); var size = module.i32.const(4); - const theMemoryInit = binaryen.MemoryInit(module.memory.init(segment, dest, offset, size)); + const theMemoryInit = module.memory.init(segment, dest, offset, size); assert(theMemoryInit instanceof binaryen.MemoryInit); assert(theMemoryInit instanceof binaryen.Expression); - assert(theMemoryInit.segment === segment); - assert(theMemoryInit.dest === dest); - assert(theMemoryInit.offset === offset); - assert(theMemoryInit.size === size); - assert(theMemoryInit.type === binaryen.none); + assertEq(theMemoryInit.segment, segment); + assertEq(theMemoryInit.dest, dest); + assertEq(theMemoryInit.offset, offset); + assertEq(theMemoryInit.size, size); + assertEq(theMemoryInit.type, binaryen.none); var info = binaryen.getExpressionInfo(theMemoryInit); - assert(info.id === theMemoryInit.id); - assert(info.type === theMemoryInit.type); - assert(info.segment === theMemoryInit.segment); - assert(info.dest === theMemoryInit.dest); - assert(info.offset === theMemoryInit.offset); - assert(info.size === theMemoryInit.size); + assertEq(info.id, theMemoryInit.id); + assertEq(info.type, theMemoryInit.type); + assertEq(info.segment, theMemoryInit.segment); + assertEq(info.dest, theMemoryInit.dest); + assertEq(info.offset, theMemoryInit.offset); + assertEq(info.size, theMemoryInit.size); theMemoryInit.segment = segment = "5"; - assert(theMemoryInit.segment === "5"); + assertEq(theMemoryInit.segment, "5"); theMemoryInit.dest = dest = module.i32.const(6); - assert(theMemoryInit.dest === dest); + assertEq(theMemoryInit.dest, dest); theMemoryInit.offset = offset = module.i32.const(7); - assert(theMemoryInit.offset === offset); + assertEq(theMemoryInit.offset, offset); theMemoryInit.size = size = module.i32.const(8); - assert(theMemoryInit.size === size); + assertEq(theMemoryInit.size, size); theMemoryInit.type = binaryen.f64; theMemoryInit.finalize(); - assert(theMemoryInit.type === binaryen.none); + assertEq(theMemoryInit.type, binaryen.none); info = binaryen.getExpressionInfo(theMemoryInit); - assert(info.type === theMemoryInit.type); - assert(info.segment === theMemoryInit.segment); - assert(info.dest === theMemoryInit.dest); - assert(info.offset === theMemoryInit.offset); - assert(info.size === theMemoryInit.size); + assertEq(info.type, theMemoryInit.type); + assertEq(info.segment, theMemoryInit.segment); + assertEq(info.dest, theMemoryInit.dest); + assertEq(info.offset, theMemoryInit.offset); + assertEq(info.size, theMemoryInit.size); console.log(theMemoryInit.toText()); assert( @@ -1775,26 +1776,26 @@ console.log("# DataDrop"); const module = new binaryen.Module(); var segment = "1"; - const theDataDrop = binaryen.DataDrop(module.data.drop(segment)); + const theDataDrop = module.data.drop(segment); assert(theDataDrop instanceof binaryen.DataDrop); assert(theDataDrop instanceof binaryen.Expression); - assert(theDataDrop.segment === segment); - assert(theDataDrop.type === binaryen.none); + assertEq(theDataDrop.segment, segment); + assertEq(theDataDrop.type, binaryen.none); var info = binaryen.getExpressionInfo(theDataDrop); - assert(info.id === theDataDrop.id); - assert(info.type === theDataDrop.type); - assert(info.segment === theDataDrop.segment); + assertEq(info.id, theDataDrop.id); + assertEq(info.type, theDataDrop.type); + assertEq(info.segment, theDataDrop.segment); theDataDrop.segment = segment = "2"; - assert(theDataDrop.segment === "2"); + assertEq(theDataDrop.segment, "2"); theDataDrop.type = binaryen.f64; theDataDrop.finalize(); - assert(theDataDrop.type === binaryen.none); + assertEq(theDataDrop.type, binaryen.none); info = binaryen.getExpressionInfo(theDataDrop); - assert(info.type === theDataDrop.type); - assert(info.segment === theDataDrop.segment); + assertEq(info.type, theDataDrop.type); + assertEq(info.segment, theDataDrop.segment); console.log(theDataDrop.toText()); assert( @@ -1814,36 +1815,36 @@ console.log("# MemoryCopy"); var dest = module.i32.const(1); var source = module.i32.const(2); var size = module.i32.const(3); - const theMemoryCopy = binaryen.MemoryCopy(module.memory.copy(dest, source, size)); + const theMemoryCopy = module.memory.copy(dest, source, size); assert(theMemoryCopy instanceof binaryen.MemoryCopy); assert(theMemoryCopy instanceof binaryen.Expression); - assert(theMemoryCopy.dest === dest); - assert(theMemoryCopy.source === source); - assert(theMemoryCopy.size === size); - assert(theMemoryCopy.type === binaryen.none); + assertEq(theMemoryCopy.dest, dest); + assertEq(theMemoryCopy.source, source); + assertEq(theMemoryCopy.size, size); + assertEq(theMemoryCopy.type, binaryen.none); var info = binaryen.getExpressionInfo(theMemoryCopy); - assert(info.id === theMemoryCopy.id); - assert(info.type === theMemoryCopy.type); - assert(info.dest === theMemoryCopy.dest); - assert(info.source === theMemoryCopy.source); - assert(info.size === theMemoryCopy.size); + assertEq(info.id, theMemoryCopy.id); + assertEq(info.type, theMemoryCopy.type); + assertEq(info.dest, theMemoryCopy.dest); + assertEq(info.source, theMemoryCopy.source); + assertEq(info.size, theMemoryCopy.size); theMemoryCopy.dest = dest = module.i32.const(4); - assert(theMemoryCopy.dest === dest); + assertEq(theMemoryCopy.dest, dest); theMemoryCopy.source = source = module.i32.const(5); - assert(theMemoryCopy.source === source); + assertEq(theMemoryCopy.source, source); theMemoryCopy.size = size = module.i32.const(6); - assert(theMemoryCopy.size === size); + assertEq(theMemoryCopy.size, size); theMemoryCopy.type = binaryen.f64; theMemoryCopy.finalize(); - assert(theMemoryCopy.type === binaryen.none); + assertEq(theMemoryCopy.type, binaryen.none); info = binaryen.getExpressionInfo(theMemoryCopy); - assert(info.type === theMemoryCopy.type); - assert(info.dest === theMemoryCopy.dest); - assert(info.source === theMemoryCopy.source); - assert(info.size === theMemoryCopy.size); + assertEq(info.type, theMemoryCopy.type); + assertEq(info.dest, theMemoryCopy.dest); + assertEq(info.source, theMemoryCopy.source); + assertEq(info.size, theMemoryCopy.size); console.log(theMemoryCopy.toText()); assert( @@ -1863,36 +1864,36 @@ console.log("# MemoryFill"); var dest = module.i32.const(1); var value = module.i32.const(2); var size = module.i32.const(3); - const theMemoryFill = binaryen.MemoryFill(module.memory.fill(dest, value, size)); + const theMemoryFill = module.memory.fill(dest, value, size); assert(theMemoryFill instanceof binaryen.MemoryFill); assert(theMemoryFill instanceof binaryen.Expression); - assert(theMemoryFill.dest === dest); - assert(theMemoryFill.value === value); - assert(theMemoryFill.size === size); - assert(theMemoryFill.type === binaryen.none); + assertEq(theMemoryFill.dest, dest); + assertEq(theMemoryFill.value, value); + assertEq(theMemoryFill.size, size); + assertEq(theMemoryFill.type, binaryen.none); var info = binaryen.getExpressionInfo(theMemoryFill); - assert(info.id === theMemoryFill.id); - assert(info.type === theMemoryFill.type); - assert(info.dest === theMemoryFill.dest); - assert(info.value === theMemoryFill.value); - assert(info.size === theMemoryFill.size); + assertEq(info.id, theMemoryFill.id); + assertEq(info.type, theMemoryFill.type); + assertEq(info.dest, theMemoryFill.dest); + assertEq(info.value, theMemoryFill.value); + assertEq(info.size, theMemoryFill.size); theMemoryFill.dest = dest = module.i32.const(4); - assert(theMemoryFill.dest === dest); + assertEq(theMemoryFill.dest, dest); theMemoryFill.value = value = module.i32.const(5); - assert(theMemoryFill.value === value); + assertEq(theMemoryFill.value, value); theMemoryFill.size = size = module.i32.const(6); - assert(theMemoryFill.size === size); + assertEq(theMemoryFill.size, size); theMemoryFill.type = binaryen.f64; theMemoryFill.finalize(); - assert(theMemoryFill.type === binaryen.none); + assertEq(theMemoryFill.type, binaryen.none); info = binaryen.getExpressionInfo(theMemoryFill); - assert(info.type === theMemoryFill.type); - assert(info.dest === theMemoryFill.dest); - assert(info.value === theMemoryFill.value); - assert(info.size === theMemoryFill.size); + assertEq(info.type, theMemoryFill.type); + assertEq(info.dest, theMemoryFill.dest); + assertEq(info.value, theMemoryFill.value); + assertEq(info.size, theMemoryFill.size); console.log(theMemoryFill.toText()); assert( @@ -1909,26 +1910,26 @@ console.log("# RefIsNull"); const module = new binaryen.Module(); var value = module.local.get(1, binaryen.externref); - const theRefIsNull = binaryen.RefIsNull(module.ref.is_null(value)); + const theRefIsNull = module.ref.is_null(value); assert(theRefIsNull instanceof binaryen.RefIsNull); assert(theRefIsNull instanceof binaryen.Expression); - assert(theRefIsNull.value === value); - assert(theRefIsNull.type === binaryen.i32); + assertEq(theRefIsNull.value, value); + assertEq(theRefIsNull.type, binaryen.i32); var info = binaryen.getExpressionInfo(theRefIsNull); - assert(info.id === theRefIsNull.id); - assert(info.type === theRefIsNull.type); - assert(info.value === theRefIsNull.value); + assertEq(info.id, theRefIsNull.id); + assertEq(info.type, theRefIsNull.type); + assertEq(info.value, theRefIsNull.value); theRefIsNull.value = value = module.local.get(2, binaryen.externref); - assert(theRefIsNull.value === value); + assertEq(theRefIsNull.value, value); theRefIsNull.type = binaryen.f64; theRefIsNull.finalize(); - assert(theRefIsNull.type === binaryen.i32); + assertEq(theRefIsNull.type, binaryen.i32); info = binaryen.getExpressionInfo(theRefIsNull); - assert(info.type === theRefIsNull.type); - assert(info.value === theRefIsNull.value); + assertEq(info.type, theRefIsNull.type); + assertEq(info.value, theRefIsNull.value); console.log(theRefIsNull.toText()); assert( @@ -1947,32 +1948,32 @@ console.log("# RefAs"); var op = binaryen.Operations.RefAsNonNull; var value = module.local.get(1, binaryen.anyref); var externref = module.local.get(3, binaryen.externref); - const theRefAs = binaryen.RefAs(module.ref.as_non_null(value)); + const theRefAs = module.ref.as_non_null(value); assert(theRefAs instanceof binaryen.RefAs); assert(theRefAs instanceof binaryen.Expression); - assert(theRefAs.op === op); - assert(theRefAs.value === value); + assertEq(theRefAs.op, op); + assertEq(theRefAs.value, value); assert(theRefAs.type !== binaryen.i32); // TODO: === (ref any) var info = binaryen.getExpressionInfo(theRefAs); - assert(info.id === theRefAs.id); - assert(info.type === theRefAs.type); - assert(info.op === theRefAs.op); - assert(info.value === theRefAs.value); + assertEq(info.id, theRefAs.id); + assertEq(info.type, theRefAs.type); + assertEq(info.op, theRefAs.op); + assertEq(info.value, theRefAs.value); theRefAs.op = op = binaryen.Operations.RefAsExternConvertAny; - assert(theRefAs.op === op); + assertEq(theRefAs.op, op); theRefAs.op = op = binaryen.Operations.RefAsNonNull; theRefAs.value = value = module.local.get(2, binaryen.anyref); - assert(theRefAs.value === value); + assertEq(theRefAs.value, value); theRefAs.type = binaryen.f64; theRefAs.finalize(); assert(theRefAs.type !== binaryen.f64); // TODO: === (ref any) info = binaryen.getExpressionInfo(theRefAs); - assert(info.type === theRefAs.type); - assert(info.op === theRefAs.op); - assert(info.value === theRefAs.value); + assertEq(info.type, theRefAs.type); + assertEq(info.op, theRefAs.op); + assertEq(info.value, theRefAs.value); console.log(theRefAs.toText()); assert( @@ -1993,25 +1994,25 @@ console.log("# RefFunc"); var type = binaryen.Function(module.getFunction("a")).type; var func = "a"; - const theRefFunc = binaryen.RefFunc(module.ref.func(func, type)); + const theRefFunc = module.ref.func(func, type); assert(theRefFunc instanceof binaryen.RefFunc); assert(theRefFunc instanceof binaryen.Expression); - assert(theRefFunc.func === func); - assert(theRefFunc.type === type); + assertEq(theRefFunc.func, func); + assertEq(theRefFunc.type, type); var info = binaryen.getExpressionInfo(theRefFunc); - assert(info.id === theRefFunc.id); - assert(info.type === theRefFunc.type); - assert(info.func === theRefFunc.func); + assertEq(info.id, theRefFunc.id); + assertEq(info.type, theRefFunc.type); + assertEq(info.func, theRefFunc.func); theRefFunc.func = func = "b"; - assert(theRefFunc.func === func); + assertEq(theRefFunc.func, func); theRefFunc.finalize(); - assert(theRefFunc.type === type); + assertEq(theRefFunc.type, type); info = binaryen.getExpressionInfo(theRefFunc); - assert(info.type === theRefFunc.type); - assert(info.func === theRefFunc.func); + assertEq(info.type, theRefFunc.type); + assertEq(info.func, theRefFunc.func); console.log(theRefFunc.toText()); assert( @@ -2029,31 +2030,31 @@ console.log("# RefEq"); var left = module.local.get(0, binaryen.eqref); var right = module.local.get(1, binaryen.eqref); - const theRefEq = binaryen.RefEq(module.ref.eq(left, right)); + const theRefEq = module.ref.eq(left, right); assert(theRefEq instanceof binaryen.RefEq); assert(theRefEq instanceof binaryen.Expression); - assert(theRefEq.left === left); - assert(theRefEq.right === right); - assert(theRefEq.type === binaryen.i32); + assertEq(theRefEq.left, left); + assertEq(theRefEq.right, right); + assertEq(theRefEq.type, binaryen.i32); var info = binaryen.getExpressionInfo(theRefEq); - assert(info.id === theRefEq.id); - assert(info.type === theRefEq.type); - assert(info.left === theRefEq.left); - assert(info.right === theRefEq.right); + assertEq(info.id, theRefEq.id); + assertEq(info.type, theRefEq.type); + assertEq(info.left, theRefEq.left); + assertEq(info.right, theRefEq.right); theRefEq.left = left = module.local.get(2, binaryen.eqref); - assert(theRefEq.left === left); + assertEq(theRefEq.left, left); theRefEq.right = right = module.local.get(3, binaryen.eqref); - assert(theRefEq.right === right); + assertEq(theRefEq.right, right); theRefEq.type = binaryen.f64; theRefEq.finalize(); - assert(theRefEq.type === binaryen.i32); + assertEq(theRefEq.type, binaryen.i32); info = binaryen.getExpressionInfo(theRefEq); - assert(info.type === theRefEq.type); - assert(info.left === theRefEq.left); - assert(info.right === theRefEq.right); + assertEq(info.type, theRefEq.type); + assertEq(info.left, theRefEq.left); + assertEq(info.right, theRefEq.right); console.log(theRefEq.toText()); assert( @@ -2071,31 +2072,31 @@ console.log("# RefTest"); var ref = module.local.get(0, binaryen.anyref); var castType = binaryen.anyref; - const theRefTest = binaryen.RefTest(module.ref.test(ref, castType)); + const theRefTest = module.ref.test(ref, castType); assert(theRefTest instanceof binaryen.RefTest); assert(theRefTest instanceof binaryen.Expression); - assert(theRefTest.ref === ref); - assert(theRefTest.castType === castType); - assert(theRefTest.type === binaryen.i32); + assertEq(theRefTest.ref, ref); + assertEq(theRefTest.castType, castType); + assertEq(theRefTest.type, binaryen.i32); var info = binaryen.getExpressionInfo(theRefTest); - assert(info.id === theRefTest.id); - assert(info.type === theRefTest.type); - assert(info.ref === theRefTest.ref); - assert(info.castType === theRefTest.castType); + assertEq(info.id, theRefTest.id); + assertEq(info.type, theRefTest.type); + assertEq(info.ref, theRefTest.ref); + assertEq(info.castType, theRefTest.castType); theRefTest.ref = ref = module.local.get(2, binaryen.externref); - assert(theRefTest.ref === ref); + assertEq(theRefTest.ref, ref); theRefTest.castType = castType = binaryen.externref; - assert(theRefTest.castType === castType); + assertEq(theRefTest.castType, castType); theRefTest.type = binaryen.f64; theRefTest.finalize(); - assert(theRefTest.type === binaryen.i32); + assertEq(theRefTest.type, binaryen.i32); info = binaryen.getExpressionInfo(theRefTest); - assert(info.type === theRefTest.type); - assert(info.ref === theRefTest.ref); - assert(info.castType === theRefTest.castType); + assertEq(info.type, theRefTest.type); + assertEq(info.ref, theRefTest.ref); + assertEq(info.castType, theRefTest.castType); console.log(theRefTest.toText()); assert( @@ -2113,26 +2114,26 @@ console.log("# RefCast"); var ref = module.local.get(0, binaryen.anyref); var type = binaryen.anyref; - const theRefCast = binaryen.RefCast(module.ref.cast(ref, type)); + const theRefCast = module.ref.cast(ref, type); assert(theRefCast instanceof binaryen.RefCast); assert(theRefCast instanceof binaryen.Expression); - assert(theRefCast.ref === ref); - assert(theRefCast.type === type); + assertEq(theRefCast.ref, ref); + assertEq(theRefCast.type, type); var info = binaryen.getExpressionInfo(theRefCast); - assert(info.id === theRefCast.id); - assert(info.type === theRefCast.type); - assert(info.ref === theRefCast.ref); + assertEq(info.id, theRefCast.id); + assertEq(info.type, theRefCast.type); + assertEq(info.ref, theRefCast.ref); theRefCast.ref = ref = module.local.get(2, binaryen.externref); - assert(theRefCast.ref === ref); + assertEq(theRefCast.ref, ref); theRefCast.type = type = binaryen.externref; theRefCast.finalize(); - assert(theRefCast.type === type); + assertEq(theRefCast.type, type); info = binaryen.getExpressionInfo(theRefCast); - assert(info.type === theRefCast.type); - assert(info.ref === theRefCast.ref); + assertEq(info.type, theRefCast.type); + assertEq(info.ref, theRefCast.ref); console.log(theRefCast.toText()); assert( @@ -2152,39 +2153,39 @@ console.log("# BrOn"); var ref = module.local.get(0, binaryen.externref); var op = binaryen.Operations.BrOnNull; var castType = binaryen.unreachable; - const theBrOn = binaryen.BrOn(module.br_on_null(name, ref)); + const theBrOn = module.br_on_null(name, ref); assert(theBrOn instanceof binaryen.BrOn); assert(theBrOn instanceof binaryen.Expression); - assert(theBrOn.name === name); - assert(theBrOn.ref === ref); - assert(theBrOn.op === op); - assert(theBrOn.castType === castType); + assertEq(theBrOn.name, name); + assertEq(theBrOn.ref, ref); + assertEq(theBrOn.op, op); + assertEq(theBrOn.castType, castType); // TODO: What should theBrOn.type be equal to? var info = binaryen.getExpressionInfo(theBrOn); - assert(info.id === theBrOn.id); - assert(info.type === theBrOn.type); - assert(info.name === theBrOn.name); - assert(info.ref === theBrOn.ref); - assert(info.op === theBrOn.op); - assert(info.castType === theBrOn.castType); + assertEq(info.id, theBrOn.id); + assertEq(info.type, theBrOn.type); + assertEq(info.name, theBrOn.name); + assertEq(info.ref, theBrOn.ref); + assertEq(info.op, theBrOn.op); + assertEq(info.castType, theBrOn.castType); theBrOn.name = name = "br2"; - assert(theBrOn.name === name); + assertEq(theBrOn.name, name); theBrOn.ref = ref = module.local.get(1, binaryen.anyref); - assert(theBrOn.ref === ref); + assertEq(theBrOn.ref, ref); theBrOn.op = op = binaryen.Operations.BrOnCast; - assert(theBrOn.op === op); + assertEq(theBrOn.op, op); theBrOn.castType = castType = binaryen.i31ref; - assert(theBrOn.castType === castType); + assertEq(theBrOn.castType, castType); theBrOn.finalize(); info = binaryen.getExpressionInfo(theBrOn); - assert(info.name === theBrOn.name); - assert(info.ref === theBrOn.ref); - assert(info.op === theBrOn.op); - assert(info.castType === theBrOn.castType); + assertEq(info.name, theBrOn.name); + assertEq(info.ref, theBrOn.ref); + assertEq(info.op, theBrOn.op); + assertEq(info.castType, theBrOn.castType); console.log(theBrOn.toText()); assert( @@ -2218,39 +2219,39 @@ console.log("# StructNew"); module.i32.const(2) ]; var type = struct0Type; - const theStructNew = binaryen.StructNew(module.struct.new(operands, type)); + const theStructNew = module.struct.new(operands, type); assert(theStructNew instanceof binaryen.StructNew); assert(theStructNew instanceof binaryen.Expression); - assertDeepEqual(theStructNew.operands, operands); - assertDeepEqual(theStructNew.getOperands(), operands); - assert(theStructNew.type === type); + assertEq(theStructNew.operands, operands); + assertEq(theStructNew.getOperands(), operands); + assertEq(theStructNew.type, type); var info = binaryen.getExpressionInfo(theStructNew); - assert(info.id === theStructNew.id); - assert(info.type === theStructNew.type); - assertDeepEqual(info.operands, theStructNew.operands); + assertEq(info.id, theStructNew.id); + assertEq(info.type, theStructNew.type); + assertEq(info.operands, theStructNew.operands); theStructNew.operands = operands = [ module.i32.const(3), // set module.i32.const(4), // set module.i32.const(5) // append ]; - assertDeepEqual(theStructNew.operands, operands); + assertEq(theStructNew.operands, operands); operands = [ module.i32.const(6) // set // remove // remove ]; theStructNew.setOperands(operands); - assertDeepEqual(theStructNew.operands, operands); + assertEq(theStructNew.operands, operands); theStructNew.insertOperandAt(0, module.i32.const(7)); theStructNew.type = type = struct1Type; theStructNew.finalize(); - assert(theStructNew.type === type); + assertEq(theStructNew.type, type); info = binaryen.getExpressionInfo(theStructNew); - assert(info.type === theStructNew.type); - assertDeepEqual(info.operands, theStructNew.operands); + assertEq(info.type, theStructNew.type); + assertEq(info.operands, theStructNew.operands); console.log(theStructNew.toText()); assert( @@ -2283,36 +2284,36 @@ console.log("# StructGet"); var ref = module.local.get(0, struct0Type); var type = binaryen.i32; var signed = false; - const theStructGet = binaryen.StructGet(module.struct.get(index, ref, type, signed)); + const theStructGet = module.struct.get(index, ref, type, signed); assert(theStructGet instanceof binaryen.StructGet); assert(theStructGet instanceof binaryen.Expression); - assert(theStructGet.index === index); - assert(theStructGet.ref === ref); - assert(theStructGet.signed === signed); - assert(theStructGet.type === type); + assertEq(theStructGet.index, index); + assertEq(theStructGet.ref, ref); + assertEq(theStructGet.signed, signed); + assertEq(theStructGet.type, type); var info = binaryen.getExpressionInfo(theStructGet); - assert(info.id === theStructGet.id); - assert(info.type === theStructGet.type); - assert(info.index === theStructGet.index); - assert(info.ref === theStructGet.ref); - assert(info.isSigned === theStructGet.signed); + assertEq(info.id, theStructGet.id); + assertEq(info.type, theStructGet.type); + assertEq(info.index, theStructGet.index); + assertEq(info.ref, theStructGet.ref); + assertEq(info.isSigned, theStructGet.signed); theStructGet.index = index = 1; - assert(theStructGet.index === index); + assertEq(theStructGet.index, index); theStructGet.ref = ref = module.local.get(1, struct1Type); - assert(theStructGet.ref === ref); + assertEq(theStructGet.ref, ref); theStructGet.signed = signed = true; - assert(theStructGet.signed === signed); + assertEq(theStructGet.signed, signed); theStructGet.type = type = binaryen.i64; theStructGet.finalize(); - assert(theStructGet.type === type); + assertEq(theStructGet.type, type); info = binaryen.getExpressionInfo(theStructGet); - assert(info.type === theStructGet.type); - assert(info.index === theStructGet.index); - assert(info.ref === theStructGet.ref); - assert(info.isSigned === theStructGet.signed); + assertEq(info.type, theStructGet.type); + assertEq(info.index, theStructGet.index); + assertEq(info.ref, theStructGet.ref); + assertEq(info.isSigned, theStructGet.signed); console.log(theStructGet.toText()); assert( @@ -2344,36 +2345,36 @@ console.log("# StructSet"); var index = 0; var ref = module.local.get(0, struct0Type); var value = module.local.get(1, binaryen.i32); - const theStructSet = binaryen.StructSet(module.struct.set(index, ref, value)); + const theStructSet = module.struct.set(index, ref, value); assert(theStructSet instanceof binaryen.StructSet); assert(theStructSet instanceof binaryen.Expression); - assert(theStructSet.index === index); - assert(theStructSet.ref === ref); - assert(theStructSet.value === value); - assert(theStructSet.type === binaryen.none); + assertEq(theStructSet.index, index); + assertEq(theStructSet.ref, ref); + assertEq(theStructSet.value, value); + assertEq(theStructSet.type, binaryen.none); var info = binaryen.getExpressionInfo(theStructSet); - assert(info.id === theStructSet.id); - assert(info.type === theStructSet.type); - assert(info.index === theStructSet.index); - assert(info.ref === theStructSet.ref); - assert(info.value === theStructSet.value); + assertEq(info.id, theStructSet.id); + assertEq(info.type, theStructSet.type); + assertEq(info.index, theStructSet.index); + assertEq(info.ref, theStructSet.ref); + assertEq(info.value, theStructSet.value); theStructSet.index = index = 1; - assert(theStructSet.index === index); + assertEq(theStructSet.index, index); theStructSet.ref = ref = module.local.get(2, struct1Type); - assert(theStructSet.ref === ref); + assertEq(theStructSet.ref, ref); theStructSet.value = value = module.local.get(3, binaryen.i64); - assert(theStructSet.value === value); + assertEq(theStructSet.value, value); theStructSet.type = binaryen.f64; theStructSet.finalize(); - assert(theStructSet.type === binaryen.none); + assertEq(theStructSet.type, binaryen.none); info = binaryen.getExpressionInfo(theStructSet); - assert(info.type === theStructSet.type); - assert(info.index === theStructSet.index); - assert(info.ref === theStructSet.ref); - assert(info.value === theStructSet.value); + assertEq(info.type, theStructSet.type); + assertEq(info.index, theStructSet.index); + assertEq(info.ref, theStructSet.ref); + assertEq(info.value, theStructSet.value); console.log(theStructSet.toText()); assert( @@ -2400,31 +2401,31 @@ console.log("# ArrayNew"); var type = array0Type; var size = module.i32.const(2); var init = module.i32.const(1); - const theArrayNew = binaryen.ArrayNew(module.array.new(type, size, init)); + const theArrayNew = module.array.new(type, size, init); assert(theArrayNew instanceof binaryen.ArrayNew); assert(theArrayNew instanceof binaryen.Expression); - assert(theArrayNew.size === size); - assert(theArrayNew.init === init); - assert(theArrayNew.type === type); + assertEq(theArrayNew.size, size); + assertEq(theArrayNew.init, init); + assertEq(theArrayNew.type, type); var info = binaryen.getExpressionInfo(theArrayNew); - assert(info.id === theArrayNew.id); - assert(info.type === theArrayNew.type); - assert(info.size === theArrayNew.size); - assert(info.init === theArrayNew.init); + assertEq(info.id, theArrayNew.id); + assertEq(info.type, theArrayNew.type); + assertEq(info.size, theArrayNew.size); + assertEq(info.init, theArrayNew.init); theArrayNew.size = size = module.i32.const(4); - assert(theArrayNew.size === size); + assertEq(theArrayNew.size, size); theArrayNew.init = init = module.i32.const(3); - assert(theArrayNew.init === init); + assertEq(theArrayNew.init, init); theArrayNew.type = type = array1Type; theArrayNew.finalize(); - assert(theArrayNew.type === type); + assertEq(theArrayNew.type, type); info = binaryen.getExpressionInfo(theArrayNew); - assert(info.type === theArrayNew.type); - assert(info.size === theArrayNew.size); - assert(info.init === theArrayNew.init); + assertEq(info.type, theArrayNew.type); + assertEq(info.size, theArrayNew.size); + assertEq(info.init, theArrayNew.init); console.log(theArrayNew.toText()); assert( @@ -2453,39 +2454,39 @@ console.log("# ArrayNewFixed"); module.i32.const(1), module.i32.const(2) ]; - const theArrayNewFixed = binaryen.ArrayNewFixed(module.array.new_fixed(type, values)); + const theArrayNewFixed = module.array.new_fixed(type, values); assert(theArrayNewFixed instanceof binaryen.ArrayNewFixed); assert(theArrayNewFixed instanceof binaryen.Expression); - assertDeepEqual(theArrayNewFixed.values, values); - assertDeepEqual(theArrayNewFixed.getValues(), values); - assert(theArrayNewFixed.type === type); + assertEq(theArrayNewFixed.values, values); + assertEq(theArrayNewFixed.getValues(), values); + assertEq(theArrayNewFixed.type, type); var info = binaryen.getExpressionInfo(theArrayNewFixed); - assert(info.id === theArrayNewFixed.id); - assert(info.type === theArrayNewFixed.type); - assertDeepEqual(info.values, theArrayNewFixed.values); + assertEq(info.id, theArrayNewFixed.id); + assertEq(info.type, theArrayNewFixed.type); + assertEq(info.values, theArrayNewFixed.values); theArrayNewFixed.values = values = [ module.i32.const(3), // set module.i32.const(4), // set module.i32.const(5) // append ]; - assertDeepEqual(theArrayNewFixed.values, values); + assertEq(theArrayNewFixed.values, values); values = [ module.i32.const(6) // set // remove // remove ]; theArrayNewFixed.setValues(values); - assertDeepEqual(theArrayNewFixed.values, values); + assertEq(theArrayNewFixed.values, values); theArrayNewFixed.insertValueAt(0, module.i32.const(7)); theArrayNewFixed.type = type = array1Type; theArrayNewFixed.finalize(); - assert(theArrayNewFixed.type === type); + assertEq(theArrayNewFixed.type, type); info = binaryen.getExpressionInfo(theArrayNewFixed); - assert(info.type === theArrayNewFixed.type); - assertDeepEqual(info.values, theArrayNewFixed.values); + assertEq(info.type, theArrayNewFixed.type); + assertEq(info.values, theArrayNewFixed.values); console.log(theArrayNewFixed.toText()); assert( @@ -2513,36 +2514,36 @@ console.log("# ArrayNewData"); var segment = "0"; var offset = module.i32.const(1); var size = module.i32.const(2); - const theArrayNewData = binaryen.ArrayNewData(module.array.new_data(type, segment, offset, size)); + const theArrayNewData = module.array.new_data(type, segment, offset, size); assert(theArrayNewData instanceof binaryen.ArrayNewData); assert(theArrayNewData instanceof binaryen.Expression); - assert(theArrayNewData.segment === segment); - assert(theArrayNewData.offset === offset); - assert(theArrayNewData.size === size); - assert(theArrayNewData.type === type); + assertEq(theArrayNewData.segment, segment); + assertEq(theArrayNewData.offset, offset); + assertEq(theArrayNewData.size, size); + assertEq(theArrayNewData.type, type); var info = binaryen.getExpressionInfo(theArrayNewData); - assert(info.id === theArrayNewData.id); - assert(info.type === theArrayNewData.type); - assert(info.segment === theArrayNewData.segment); - assert(info.offset === theArrayNewData.offset); - assert(info.size === theArrayNewData.size); + assertEq(info.id, theArrayNewData.id); + assertEq(info.type, theArrayNewData.type); + assertEq(info.segment, theArrayNewData.segment); + assertEq(info.offset, theArrayNewData.offset); + assertEq(info.size, theArrayNewData.size); theArrayNewData.segment = segment = "3"; - assert(theArrayNewData.segment === segment); + assertEq(theArrayNewData.segment, segment); theArrayNewData.offset = offset = module.i32.const(4); - assert(theArrayNewData.offset === offset); + assertEq(theArrayNewData.offset, offset); theArrayNewData.size = size = module.i32.const(5); - assert(theArrayNewData.size === size); + assertEq(theArrayNewData.size, size); theArrayNewData.type = type = array1Type; theArrayNewData.finalize(); - assert(theArrayNewData.type === type); + assertEq(theArrayNewData.type, type); info = binaryen.getExpressionInfo(theArrayNewData); - assert(info.type === theArrayNewData.type); - assert(info.segment === theArrayNewData.segment); - assert(info.offset === theArrayNewData.offset); - assert(info.size === theArrayNewData.size); + assertEq(info.type, theArrayNewData.type); + assertEq(info.segment, theArrayNewData.segment); + assertEq(info.offset, theArrayNewData.offset); + assertEq(info.size, theArrayNewData.size); console.log(theArrayNewData.toText()); assert( @@ -2570,37 +2571,37 @@ console.log("# ArrayNewElem"); var segment = "0"; var offset = module.i32.const(1); var size = module.i32.const(2); - const theArrayNewElem = binaryen.ArrayNewElem(module.array.new_elem(type, segment, offset, size)); + const theArrayNewElem = module.array.new_elem(type, segment, offset, size); assert(theArrayNewElem instanceof binaryen.ArrayNewElem); assert(theArrayNewElem instanceof binaryen.Expression); - assert(theArrayNewElem.segment === segment); - assert(theArrayNewElem.offset === offset); - assert(theArrayNewElem.size === size); - assert(theArrayNewElem.type === type); + assertEq(theArrayNewElem.segment, segment); + assertEq(theArrayNewElem.offset, offset); + assertEq(theArrayNewElem.size, size); + assertEq(theArrayNewElem.type, type); var info = binaryen.getExpressionInfo(theArrayNewElem); - assert(info.id === theArrayNewElem.id); - assert(info.type === theArrayNewElem.type); - assert(info.segment === theArrayNewElem.segment); - assert(info.offset === theArrayNewElem.offset); - assert(info.size === theArrayNewElem.size); + assertEq(info.id, theArrayNewElem.id); + assertEq(info.type, theArrayNewElem.type); + assertEq(info.segment, theArrayNewElem.segment); + assertEq(info.offset, theArrayNewElem.offset); + assertEq(info.size, theArrayNewElem.size); theArrayNewElem.segment = segment = "3"; - assert(theArrayNewElem.segment === segment); + assertEq(theArrayNewElem.segment, segment); theArrayNewElem.offset = offset = module.i32.const(4); - assert(theArrayNewElem.offset === offset); + assertEq(theArrayNewElem.offset, offset); theArrayNewElem.size = size = module.i32.const(5); - assert(theArrayNewElem.size === size); + assertEq(theArrayNewElem.size, size); theArrayNewElem.type = type = array1Type; theArrayNewElem.finalize(); - assert(theArrayNewElem.type === type); + assertEq(theArrayNewElem.type, type); info = binaryen.getExpressionInfo(theArrayNewElem); - assert(info.id === theArrayNewElem.id); - assert(info.type === theArrayNewElem.type); - assert(info.segment === theArrayNewElem.segment); - assert(info.offset === theArrayNewElem.offset); - assert(info.size === theArrayNewElem.size); + assertEq(info.id, theArrayNewElem.id); + assertEq(info.type, theArrayNewElem.type); + assertEq(info.segment, theArrayNewElem.segment); + assertEq(info.offset, theArrayNewElem.offset); + assertEq(info.size, theArrayNewElem.size); console.log(theArrayNewElem.toText()); assert( @@ -2628,36 +2629,36 @@ console.log("# ArrayGet"); var index = module.i32.const(0); var type = binaryen.i32; var signed = false; - const theArrayGet = binaryen.ArrayGet(module.array.get(ref, index, type, signed)); + const theArrayGet = module.array.get(ref, index, type, signed); assert(theArrayGet instanceof binaryen.ArrayGet); assert(theArrayGet instanceof binaryen.Expression); - assert(theArrayGet.ref === ref); - assert(theArrayGet.index === index); - assert(theArrayGet.signed === signed); - assert(theArrayGet.type === type); + assertEq(theArrayGet.ref, ref); + assertEq(theArrayGet.index, index); + assertEq(theArrayGet.signed, signed); + assertEq(theArrayGet.type, type); var info = binaryen.getExpressionInfo(theArrayGet); - assert(info.id === theArrayGet.id); - assert(info.type === theArrayGet.type); - assert(info.ref === theArrayGet.ref); - assert(info.index === theArrayGet.index); - assert(info.isSigned === theArrayGet.signed); + assertEq(info.id, theArrayGet.id); + assertEq(info.type, theArrayGet.type); + assertEq(info.ref, theArrayGet.ref); + assertEq(info.index, theArrayGet.index); + assertEq(info.isSigned, theArrayGet.signed); theArrayGet.ref = ref = module.local.get(1, array1Type); - assert(theArrayGet.ref === ref); + assertEq(theArrayGet.ref, ref); theArrayGet.index = index = module.i32.const(1); - assert(theArrayGet.index === index); + assertEq(theArrayGet.index, index); theArrayGet.signed = signed = true; - assert(theArrayGet.signed === signed); + assertEq(theArrayGet.signed, signed); theArrayGet.type = type = binaryen.i64; theArrayGet.finalize(); - assert(theArrayGet.type === type); + assertEq(theArrayGet.type, type); info = binaryen.getExpressionInfo(theArrayGet); - assert(info.type === theArrayGet.type); - assert(info.ref === theArrayGet.ref); - assert(info.index === theArrayGet.index); - assert(info.isSigned === theArrayGet.signed); + assertEq(info.type, theArrayGet.type); + assertEq(info.ref, theArrayGet.ref); + assertEq(info.index, theArrayGet.index); + assertEq(info.isSigned, theArrayGet.signed); console.log(theArrayGet.toText()); assert( @@ -2684,36 +2685,36 @@ console.log("# ArraySet"); var ref = module.local.get(0, array0Type); var index = module.i32.const(0); var value = module.local.get(1, binaryen.i32); - const theArraySet = binaryen.ArraySet(module.array.set(ref, index, value)); + const theArraySet = module.array.set(ref, index, value); assert(theArraySet instanceof binaryen.ArraySet); assert(theArraySet instanceof binaryen.Expression); - assert(theArraySet.ref === ref); - assert(theArraySet.index === index); - assert(theArraySet.value === value); - assert(theArraySet.type === binaryen.none); + assertEq(theArraySet.ref, ref); + assertEq(theArraySet.index, index); + assertEq(theArraySet.value, value); + assertEq(theArraySet.type, binaryen.none); var info = binaryen.getExpressionInfo(theArraySet); - assert(info.id === theArraySet.id); - assert(info.type === theArraySet.type); - assert(info.ref === theArraySet.ref); - assert(info.index === theArraySet.index); - assert(info.value === theArraySet.value); + assertEq(info.id, theArraySet.id); + assertEq(info.type, theArraySet.type); + assertEq(info.ref, theArraySet.ref); + assertEq(info.index, theArraySet.index); + assertEq(info.value, theArraySet.value); theArraySet.ref = ref = module.local.get(2, array1Type); - assert(theArraySet.ref === ref); + assertEq(theArraySet.ref, ref); theArraySet.index = index = module.i32.const(1); - assert(theArraySet.index === index); + assertEq(theArraySet.index, index); theArraySet.value = value = module.local.get(3, binaryen.i64); - assert(theArraySet.value === value); + assertEq(theArraySet.value, value); theArraySet.type = binaryen.i64; theArraySet.finalize(); - assert(theArraySet.type === binaryen.none); + assertEq(theArraySet.type, binaryen.none); info = binaryen.getExpressionInfo(theArraySet); - assert(info.type === theArraySet.type); - assert(info.ref === theArraySet.ref); - assert(info.index === theArraySet.index); - assert(info.value === theArraySet.value); + assertEq(info.type, theArraySet.type); + assertEq(info.ref, theArraySet.ref); + assertEq(info.index, theArraySet.index); + assertEq(info.value, theArraySet.value); console.log(theArraySet.toText()); assert( @@ -2738,26 +2739,26 @@ console.log("# ArrayLen"); const module = new binaryen.Module(); var ref = module.local.get(0, array0Type); - const theArrayLen = binaryen.ArrayLen(module.array.len(ref)); + const theArrayLen = module.array.len(ref); assert(theArrayLen instanceof binaryen.ArrayLen); assert(theArrayLen instanceof binaryen.Expression); - assert(theArrayLen.ref === ref); - assert(theArrayLen.type === binaryen.i32); + assertEq(theArrayLen.ref, ref); + assertEq(theArrayLen.type, binaryen.i32); var info = binaryen.getExpressionInfo(theArrayLen); - assert(info.id === theArrayLen.id); - assert(info.type === theArrayLen.type); - assert(info.ref === theArrayLen.ref); + assertEq(info.id, theArrayLen.id); + assertEq(info.type, theArrayLen.type); + assertEq(info.ref, theArrayLen.ref); theArrayLen.ref = ref = module.local.get(1, array1Type); - assert(theArrayLen.ref === ref); + assertEq(theArrayLen.ref, ref); theArrayLen.type = binaryen.i64; theArrayLen.finalize(); - assert(theArrayLen.type === binaryen.i32); + assertEq(theArrayLen.type, binaryen.i32); info = binaryen.getExpressionInfo(theArrayLen); - assert(info.type === theArrayLen.type); - assert(info.ref === theArrayLen.ref); + assertEq(info.type, theArrayLen.type); + assertEq(info.ref, theArrayLen.ref); console.log(theArrayLen.toText()); assert( @@ -2785,41 +2786,41 @@ console.log("# ArrayFill"); var index = module.i32.const(0); var value = module.local.get(1, binaryen.i32); var size = module.i32.const(1); - const theArrayFill = binaryen.ArrayFill(module.array.fill(ref, index, value, size)); + const theArrayFill = module.array.fill(ref, index, value, size); assert(theArrayFill instanceof binaryen.ArrayFill); assert(theArrayFill instanceof binaryen.Expression); - assert(theArrayFill.ref === ref); - assert(theArrayFill.index === index); - assert(theArrayFill.value === value); - assert(theArrayFill.size === size); - assert(theArrayFill.type === binaryen.none); + assertEq(theArrayFill.ref, ref); + assertEq(theArrayFill.index, index); + assertEq(theArrayFill.value, value); + assertEq(theArrayFill.size, size); + assertEq(theArrayFill.type, binaryen.none); var info = binaryen.getExpressionInfo(theArrayFill); - assert(info.id === theArrayFill.id); - assert(info.type === theArrayFill.type); - assert(info.ref === theArrayFill.ref); - assert(info.index === theArrayFill.index); - assert(info.value === theArrayFill.value); - assert(info.size === theArrayFill.size); + assertEq(info.id, theArrayFill.id); + assertEq(info.type, theArrayFill.type); + assertEq(info.ref, theArrayFill.ref); + assertEq(info.index, theArrayFill.index); + assertEq(info.value, theArrayFill.value); + assertEq(info.size, theArrayFill.size); theArrayFill.ref = ref = module.local.get(2, array1Type); - assert(theArrayFill.ref === ref); + assertEq(theArrayFill.ref, ref); theArrayFill.index = index = module.i32.const(2); - assert(theArrayFill.index === index); + assertEq(theArrayFill.index, index); theArrayFill.value = value = module.local.get(3, binaryen.i64); assert(theArrayFill.value = value); theArrayFill.size = size = module.i32.const(3); - assert(theArrayFill.size === size); + assertEq(theArrayFill.size, size); theArrayFill.type = binaryen.i64; theArrayFill.finalize(); - assert(theArrayFill.type === binaryen.none); + assertEq(theArrayFill.type, binaryen.none); info = binaryen.getExpressionInfo(theArrayFill); - assert(info.type === theArrayFill.type); - assert(info.ref === theArrayFill.ref); - assert(info.index === theArrayFill.index); - assert(info.value === theArrayFill.value); - assert(info.size === theArrayFill.size); + assertEq(info.type, theArrayFill.type); + assertEq(info.ref, theArrayFill.ref); + assertEq(info.index, theArrayFill.index); + assertEq(info.value, theArrayFill.value); + assertEq(info.size, theArrayFill.size); console.log(theArrayFill.toText()); assert( @@ -2848,46 +2849,46 @@ console.log("# ArrayCopy"); var srcRef = module.local.get(1, array0Type); var srcIndex = module.i32.const(1); var length = module.i32.const(1); - const theArrayCopy = binaryen.ArrayCopy(module.array.copy(destRef, destIndex, srcRef, srcIndex, length)); + const theArrayCopy = module.array.copy(destRef, destIndex, srcRef, srcIndex, length); assert(theArrayCopy instanceof binaryen.ArrayCopy); assert(theArrayCopy instanceof binaryen.Expression); - assert(theArrayCopy.destRef === destRef); - assert(theArrayCopy.destIndex === destIndex); - assert(theArrayCopy.srcRef === srcRef); - assert(theArrayCopy.srcIndex === srcIndex); - assert(theArrayCopy.length === length); - assert(theArrayCopy.type === binaryen.none); + assertEq(theArrayCopy.destRef, destRef); + assertEq(theArrayCopy.destIndex, destIndex); + assertEq(theArrayCopy.srcRef, srcRef); + assertEq(theArrayCopy.srcIndex, srcIndex); + assertEq(theArrayCopy.length, length); + assertEq(theArrayCopy.type, binaryen.none); var info = binaryen.getExpressionInfo(theArrayCopy); - assert(info.id === theArrayCopy.id); - assert(info.type === theArrayCopy.type); - assert(info.destRef === theArrayCopy.destRef); - assert(info.destIndex === theArrayCopy.destIndex); - assert(info.srcRef === theArrayCopy.srcRef); - assert(info.srcIndex === theArrayCopy.srcIndex); - assert(info.length === theArrayCopy.length); + assertEq(info.id, theArrayCopy.id); + assertEq(info.type, theArrayCopy.type); + assertEq(info.destRef, theArrayCopy.destRef); + assertEq(info.destIndex, theArrayCopy.destIndex); + assertEq(info.srcRef, theArrayCopy.srcRef); + assertEq(info.srcIndex, theArrayCopy.srcIndex); + assertEq(info.length, theArrayCopy.length); theArrayCopy.destRef = destRef = module.local.get(2, array1Type); - assert(theArrayCopy.destRef === destRef); + assertEq(theArrayCopy.destRef, destRef); theArrayCopy.destIndex = destIndex = module.i32.const(2); - assert(theArrayCopy.destIndex === destIndex); + assertEq(theArrayCopy.destIndex, destIndex); theArrayCopy.srcRef = srcRef = module.local.get(3, array1Type); - assert(theArrayCopy.srcRef === srcRef); + assertEq(theArrayCopy.srcRef, srcRef); theArrayCopy.srcIndex = srcIndex = module.i32.const(3); - assert(theArrayCopy.srcIndex === srcIndex); + assertEq(theArrayCopy.srcIndex, srcIndex); theArrayCopy.length = length = module.i32.const(2); - assert(theArrayCopy.length === length); + assertEq(theArrayCopy.length, length); theArrayCopy.type = binaryen.i64; theArrayCopy.finalize(); - assert(theArrayCopy.type === binaryen.none); + assertEq(theArrayCopy.type, binaryen.none); info = binaryen.getExpressionInfo(theArrayCopy); - assert(info.type === theArrayCopy.type); - assert(info.destRef === theArrayCopy.destRef); - assert(info.destIndex === theArrayCopy.destIndex); - assert(info.srcRef === theArrayCopy.srcRef); - assert(info.srcIndex === theArrayCopy.srcIndex); - assert(info.length === theArrayCopy.length); + assertEq(info.type, theArrayCopy.type); + assertEq(info.destRef, theArrayCopy.destRef); + assertEq(info.destIndex, theArrayCopy.destIndex); + assertEq(info.srcRef, theArrayCopy.srcRef); + assertEq(info.srcIndex, theArrayCopy.srcIndex); + assertEq(info.length, theArrayCopy.length); console.log(theArrayCopy.toText()); assert( @@ -2916,46 +2917,46 @@ console.log("# ArrayInitData"); var index = module.i32.const(0); var offset = module.i32.const(1); var size = module.i32.const(2); - const theArrayInitData = binaryen.ArrayInitData(module.array.init_data(segment, ref, index, offset, size)); + const theArrayInitData = module.array.init_data(segment, ref, index, offset, size); assert(theArrayInitData instanceof binaryen.ArrayInitData); assert(theArrayInitData instanceof binaryen.Expression); - assert(theArrayInitData.segment === segment); - assert(theArrayInitData.ref === ref); - assert(theArrayInitData.index === index); - assert(theArrayInitData.offset === offset); - assert(theArrayInitData.size === size); - assert(theArrayInitData.type === binaryen.none); + assertEq(theArrayInitData.segment, segment); + assertEq(theArrayInitData.ref, ref); + assertEq(theArrayInitData.index, index); + assertEq(theArrayInitData.offset, offset); + assertEq(theArrayInitData.size, size); + assertEq(theArrayInitData.type, binaryen.none); var info = binaryen.getExpressionInfo(theArrayInitData); - assert(info.id === theArrayInitData.id); - assert(info.type === theArrayInitData.type); - assert(info.segment === theArrayInitData.segment); - assert(info.ref === theArrayInitData.ref); - assert(info.index === theArrayInitData.index); - assert(info.offset === theArrayInitData.offset); - assert(info.size === theArrayInitData.size); + assertEq(info.id, theArrayInitData.id); + assertEq(info.type, theArrayInitData.type); + assertEq(info.segment, theArrayInitData.segment); + assertEq(info.ref, theArrayInitData.ref); + assertEq(info.index, theArrayInitData.index); + assertEq(info.offset, theArrayInitData.offset); + assertEq(info.size, theArrayInitData.size); theArrayInitData.segment = segment = "1"; - assert(theArrayInitData.segment === segment); + assertEq(theArrayInitData.segment, segment); theArrayInitData.ref = ref = module.local.get(1, array1Type); - assert(theArrayInitData.ref === ref); + assertEq(theArrayInitData.ref, ref); theArrayInitData.index = index = module.i32.const(3); - assert(theArrayInitData.index === index); + assertEq(theArrayInitData.index, index); theArrayInitData.offset = offset = module.i32.const(4); - assert(theArrayInitData.offset === offset); + assertEq(theArrayInitData.offset, offset); theArrayInitData.size = size = module.i32.const(5); - assert(theArrayInitData.size === size); + assertEq(theArrayInitData.size, size); theArrayInitData.type = binaryen.i64; theArrayInitData.finalize(); - assert(theArrayInitData.type === binaryen.none); + assertEq(theArrayInitData.type, binaryen.none); info = binaryen.getExpressionInfo(theArrayInitData); - assert(info.type === theArrayInitData.type); - assert(info.segment === theArrayInitData.segment); - assert(info.ref === theArrayInitData.ref); - assert(info.index === theArrayInitData.index); - assert(info.offset === theArrayInitData.offset); - assert(info.size === theArrayInitData.size); + assertEq(info.type, theArrayInitData.type); + assertEq(info.segment, theArrayInitData.segment); + assertEq(info.ref, theArrayInitData.ref); + assertEq(info.index, theArrayInitData.index); + assertEq(info.offset, theArrayInitData.offset); + assertEq(info.size, theArrayInitData.size); console.log(theArrayInitData.toText()); assert( @@ -2984,46 +2985,46 @@ console.log("# ArrayInitElem"); var index = module.i32.const(0); var offset = module.i32.const(1); var size = module.i32.const(2); - const theArrayInitElem = binaryen.ArrayInitElem(module.array.init_elem(segment, ref, index, offset, size)); + const theArrayInitElem = module.array.init_elem(segment, ref, index, offset, size); assert(theArrayInitElem instanceof binaryen.ArrayInitElem); assert(theArrayInitElem instanceof binaryen.Expression); - assert(theArrayInitElem.segment === segment); - assert(theArrayInitElem.ref === ref); - assert(theArrayInitElem.index === index); - assert(theArrayInitElem.offset === offset); - assert(theArrayInitElem.size === size); - assert(theArrayInitElem.type === binaryen.none); + assertEq(theArrayInitElem.segment, segment); + assertEq(theArrayInitElem.ref, ref); + assertEq(theArrayInitElem.index, index); + assertEq(theArrayInitElem.offset, offset); + assertEq(theArrayInitElem.size, size); + assertEq(theArrayInitElem.type, binaryen.none); var info = binaryen.getExpressionInfo(theArrayInitElem); - assert(info.id === theArrayInitElem.id); - assert(info.type === theArrayInitElem.type); - assert(info.segment === theArrayInitElem.segment); - assert(info.ref === theArrayInitElem.ref); - assert(info.index === theArrayInitElem.index); - assert(info.offset === theArrayInitElem.offset); - assert(info.size === theArrayInitElem.size); + assertEq(info.id, theArrayInitElem.id); + assertEq(info.type, theArrayInitElem.type); + assertEq(info.segment, theArrayInitElem.segment); + assertEq(info.ref, theArrayInitElem.ref); + assertEq(info.index, theArrayInitElem.index); + assertEq(info.offset, theArrayInitElem.offset); + assertEq(info.size, theArrayInitElem.size); theArrayInitElem.segment = segment = "1"; - assert(theArrayInitElem.segment === segment); + assertEq(theArrayInitElem.segment, segment); theArrayInitElem.ref = ref = module.local.get(1, array1Type); - assert(theArrayInitElem.ref === ref); + assertEq(theArrayInitElem.ref, ref); theArrayInitElem.index = index = module.i32.const(3); - assert(theArrayInitElem.index === index); + assertEq(theArrayInitElem.index, index); theArrayInitElem.offset = offset = module.i32.const(4); - assert(theArrayInitElem.offset === offset); + assertEq(theArrayInitElem.offset, offset); theArrayInitElem.size = size = module.i32.const(5); - assert(theArrayInitElem.size === size); + assertEq(theArrayInitElem.size, size); theArrayInitElem.type = binaryen.i64; theArrayInitElem.finalize(); - assert(theArrayInitElem.type === binaryen.none); + assertEq(theArrayInitElem.type, binaryen.none); info = binaryen.getExpressionInfo(theArrayInitElem); - assert(info.type === theArrayInitElem.type); - assert(info.segment === theArrayInitElem.segment); - assert(info.ref === theArrayInitElem.ref); - assert(info.index === theArrayInitElem.index); - assert(info.offset === theArrayInitElem.offset); - assert(info.size === theArrayInitElem.size); + assertEq(info.type, theArrayInitElem.type); + assertEq(info.segment, theArrayInitElem.segment); + assertEq(info.ref, theArrayInitElem.ref); + assertEq(info.index, theArrayInitElem.index); + assertEq(info.offset, theArrayInitElem.offset); + assertEq(info.size, theArrayInitElem.size); console.log(theArrayInitElem.toText()); assert( @@ -3047,37 +3048,37 @@ console.log("# Try"); module.i32.const(2), module.i32.const(3) ]; - const theTry = binaryen.Try(module.try('', body, ["tag1"], catchBodies, '')); + const theTry = module.try('', body, ["tag1"], catchBodies, ''); assert(theTry instanceof binaryen.Try); assert(theTry instanceof binaryen.Expression); - assert(theTry.body === body); - assertDeepEqual(theTry.catchBodies, catchBodies); - assert(theTry.type === binaryen.i32); + assertEq(theTry.body, body); + assertEq(theTry.catchBodies, catchBodies); + assertEq(theTry.type, binaryen.i32); assert(theTry.getNumCatchTags() == 1); assert(theTry.getNumCatchBodies() == 2); assert(theTry.hasCatchAll() == 1); console.log(theTry.toText()); var info = binaryen.getExpressionInfo(theTry); - assert(info.id === theTry.id); - assert(info.type === theTry.type); - assert(info.name === theTry.name); - assert(info.body === theTry.body); - assertDeepEqual(info.catchTags, theTry.catchTags); - assertDeepEqual(info.catchBodies, theTry.catchBodies); - assert(info.hasCatchAll === theTry.hasCatchAll()); - assert(info.delegateTarget === theTry.delegateTarget); - assert(info.isDelegate === theTry.delegate); + assertEq(info.id, theTry.id); + assertEq(info.type, theTry.type); + assertEq(info.name, theTry.name); + assertEq(info.body, theTry.body); + assertEq(info.catchTags, theTry.catchTags); + assertEq(info.catchBodies, theTry.catchBodies); + assertEq(info.hasCatchAll, theTry.hasCatchAll()); + assertEq(info.delegateTarget, theTry.delegateTarget); + assertEq(info.isDelegate, theTry.delegate); theTry.body = body = module.i32.const(4); - assert(theTry.body === body); + assertEq(theTry.body, body); catchBodies = [ module.i32.const(5) // set //remove ]; theTry.setCatchBodies(catchBodies); - assertDeepEqual(theTry.catchBodies, catchBodies); - assertDeepEqual(theTry.getCatchBodies(), catchBodies); + assertEq(theTry.catchBodies, catchBodies); + assertEq(theTry.getCatchBodies(), catchBodies); console.log(theTry.toText()); theTry.insertCatchTagAt(1, "tag2"); @@ -3098,7 +3099,7 @@ console.log("# Try"); assert(theTry.getCatchTagAt(0) == "tag1"); assert(theTry.getCatchTagAt(1) == "tag3"); theTry.setCatchTags(["tag2", "tag3"]); - assertDeepEqual(theTry.getCatchTags(), ["tag2", "tag3"]); + assertEq(theTry.getCatchTags(), ["tag2", "tag3"]); theTry.setCatchBodies([module.i32.const(8), module.i32.const(9)]); assert(theTry.getCatchTagAt(0) == "tag2"); assert(theTry.getCatchTagAt(1) == "tag3"); @@ -3109,30 +3110,30 @@ console.log("# Try"); theTry.type = binaryen.f64; theTry.finalize(); - assert(theTry.type === binaryen.i32); + assertEq(theTry.type, binaryen.i32); info = binaryen.getExpressionInfo(theTry); - assert(info.id === theTry.id); - assert(info.type === theTry.type); - assert(info.name === theTry.name); - assert(info.body === theTry.body); - assertDeepEqual(info.catchTags, theTry.catchTags); - assertDeepEqual(info.catchBodies, theTry.catchBodies); - assert(info.hasCatchAll === theTry.hasCatchAll()); - assert(info.delegateTarget === theTry.delegateTarget); - assert(info.isDelegate === theTry.delegate); + assertEq(info.id, theTry.id); + assertEq(info.type, theTry.type); + assertEq(info.name, theTry.name); + assertEq(info.body, theTry.body); + assertEq(info.catchTags, theTry.catchTags); + assertEq(info.catchBodies, theTry.catchBodies); + assertEq(info.hasCatchAll, theTry.hasCatchAll()); + assertEq(info.delegateTarget, theTry.delegateTarget); + assertEq(info.isDelegate, theTry.delegate); console.log(theTry.toText()); - const tryDelegate = binaryen.Try(module.try('', body, [], [], "try_blah")); + const tryDelegate = module.try('', body, [], [], "try_blah"); assert(tryDelegate.isDelegate() == 1); assert(tryDelegate.getDelegateTarget() == "try_blah"); tryDelegate.setDelegateTarget("try_outer"); assert(tryDelegate.getDelegateTarget() == "try_outer"); info = binaryen.getExpressionInfo(tryDelegate); - assert(info.delegateTarget === tryDelegate.delegateTarget); - assert(info.isDelegate === tryDelegate.delegate); + assertEq(info.delegateTarget, tryDelegate.delegateTarget); + assertEq(info.isDelegate, tryDelegate.delegate); console.log(tryDelegate.toText()); @@ -3148,44 +3149,44 @@ console.log("# Throw"); module.i32.const(1), module.i32.const(2) ]; - const theThrow = binaryen.Throw(module.throw(tag, operands)); + const theThrow = module.throw(tag, operands); assert(theThrow instanceof binaryen.Throw); assert(theThrow instanceof binaryen.Expression); - assert(theThrow.tag === tag); - assertDeepEqual(theThrow.operands, operands); - assert(theThrow.type === binaryen.unreachable); + assertEq(theThrow.tag, tag); + assertEq(theThrow.operands, operands); + assertEq(theThrow.type, binaryen.unreachable); var info = binaryen.getExpressionInfo(theThrow); - assert(info.id === theThrow.id); - assert(info.type === theThrow.type); - assert(info.tag === theThrow.tag); - assertDeepEqual(info.operands, theThrow.operands); + assertEq(info.id, theThrow.id); + assertEq(info.type, theThrow.type); + assertEq(info.tag, theThrow.tag); + assertEq(info.operands, theThrow.operands); theThrow.tag = "bar"; - assert(theThrow.tag === "bar"); + assertEq(theThrow.tag, "bar"); theThrow.operands = operands = [ module.i32.const(3), // set module.i32.const(4), // set module.i32.const(5) // append ]; - assertDeepEqual(theThrow.operands, operands); - assertDeepEqual(theThrow.getOperands(), operands); + assertEq(theThrow.operands, operands); + assertEq(theThrow.getOperands(), operands); operands = [ module.i32.const(6) // set // remove // remove ]; theThrow.setOperands(operands); - assertDeepEqual(theThrow.operands, operands); + assertEq(theThrow.operands, operands); theThrow.insertOperandAt(1, module.i32.const(7)); theThrow.type = binaryen.f64; theThrow.finalize(); - assert(theThrow.type === binaryen.unreachable); + assertEq(theThrow.type, binaryen.unreachable); info = binaryen.getExpressionInfo(theThrow); - assert(info.type === theThrow.type); - assert(info.tag === theThrow.tag); - assertDeepEqual(info.operands, theThrow.operands); + assertEq(info.type, theThrow.type); + assertEq(info.tag, theThrow.tag); + assertEq(info.operands, theThrow.operands); console.log(theThrow.toText()); assert( @@ -3201,26 +3202,26 @@ console.log("# Rethrow"); (function testRethrow() { const module = new binaryen.Module(); - const theRethrow = binaryen.Rethrow(module.rethrow("l0")); + const theRethrow = module.rethrow("l0"); assert(theRethrow instanceof binaryen.Rethrow); assert(theRethrow instanceof binaryen.Expression); - assert(theRethrow.target === "l0"); - assert(theRethrow.type === binaryen.unreachable); + assertEq(theRethrow.target, "l0"); + assertEq(theRethrow.type, binaryen.unreachable); var info = binaryen.getExpressionInfo(theRethrow); - assert(info.id === theRethrow.id); - assert(info.type === theRethrow.type); - assert(info.target === theRethrow.target); + assertEq(info.id, theRethrow.id); + assertEq(info.type, theRethrow.type); + assertEq(info.target, theRethrow.target); theRethrow.target = "l1"; - assert(theRethrow.target === "l1"); + assertEq(theRethrow.target, "l1"); theRethrow.type = binaryen.f64; theRethrow.finalize(); - assert(theRethrow.type === binaryen.unreachable); + assertEq(theRethrow.type, binaryen.unreachable); info = binaryen.getExpressionInfo(theRethrow); - assert(info.type === theRethrow.type); - assert(info.target === theRethrow.target); + assertEq(info.type, theRethrow.type); + assertEq(info.target, theRethrow.target); console.log(theRethrow.toText()); assert( @@ -3241,39 +3242,39 @@ console.log("# TupleMake"); module.i32.const(2) ]; var type = binaryen.createType([ binaryen.i32, binaryen.i32 ]); - const theTupleMake = binaryen.TupleMake(module.tuple.make(operands)); + const theTupleMake = module.tuple.make(operands); assert(theTupleMake instanceof binaryen.TupleMake); assert(theTupleMake instanceof binaryen.Expression); - assertDeepEqual(theTupleMake.operands, operands); - assert(theTupleMake.type === type); + assertEq(theTupleMake.operands, operands); + assertEq(theTupleMake.type, type); var info = binaryen.getExpressionInfo(theTupleMake); - assert(info.id === theTupleMake.id); - assert(info.type === theTupleMake.type); - assertDeepEqual(info.operands, theTupleMake.operands); + assertEq(info.id, theTupleMake.id); + assertEq(info.type, theTupleMake.type); + assertEq(info.operands, theTupleMake.operands); theTupleMake.operands = operands = [ module.i32.const(3), // set module.i32.const(4), // set module.i32.const(5) // append ]; - assertDeepEqual(theTupleMake.operands, operands); + assertEq(theTupleMake.operands, operands); operands = [ module.i32.const(6) // set // remove // remove ]; theTupleMake.setOperands(operands); - assertDeepEqual(theTupleMake.operands, operands); - assertDeepEqual(theTupleMake.getOperands(), operands); + assertEq(theTupleMake.operands, operands); + assertEq(theTupleMake.getOperands(), operands); theTupleMake.insertOperandAt(1, module.i32.const(7)); theTupleMake.type = binaryen.f64; theTupleMake.finalize(); - assert(theTupleMake.type === type); + assertEq(theTupleMake.type, type); info = binaryen.getExpressionInfo(theTupleMake); - assert(info.type === theTupleMake.type); - assertDeepEqual(info.operands, theTupleMake.operands); + assertEq(info.type, theTupleMake.type); + assertEq(info.operands, theTupleMake.operands); console.log(theTupleMake.toText()); assert( @@ -3294,34 +3295,34 @@ console.log("# TupleExtract"); module.i32.const(2) ]); var index = 1; - const theTupleExtract = binaryen.TupleExtract(module.tuple.extract(tuple, index)); + const theTupleExtract = module.tuple.extract(tuple, index); assert(theTupleExtract instanceof binaryen.TupleExtract); assert(theTupleExtract instanceof binaryen.Expression); - assert(theTupleExtract.tuple === tuple); - assert(theTupleExtract.index === index); - assert(theTupleExtract.type === binaryen.i32); + assertEq(theTupleExtract.tuple, tuple); + assertEq(theTupleExtract.index, index); + assertEq(theTupleExtract.type, binaryen.i32); var info = binaryen.getExpressionInfo(theTupleExtract); - assert(info.id === theTupleExtract.id); - assert(info.type === theTupleExtract.type); - assert(info.tuple === theTupleExtract.tuple); - assert(info.index === theTupleExtract.index); + assertEq(info.id, theTupleExtract.id); + assertEq(info.type, theTupleExtract.type); + assertEq(info.tuple, theTupleExtract.tuple); + assertEq(info.index, theTupleExtract.index); theTupleExtract.tuple = tuple = module.tuple.make([ module.f64.const(3), module.f64.const(4) ]); - assert(theTupleExtract.tuple === tuple); + assertEq(theTupleExtract.tuple, tuple); theTupleExtract.index = index = 0; - assert(theTupleExtract.index === index); + assertEq(theTupleExtract.index, index); theTupleExtract.type = binaryen.i32; theTupleExtract.finalize(); - assert(theTupleExtract.type === binaryen.f64); + assertEq(theTupleExtract.type, binaryen.f64); info = binaryen.getExpressionInfo(theTupleExtract); - assert(info.type === theTupleExtract.type); - assert(info.tuple === theTupleExtract.tuple); - assert(info.index === theTupleExtract.index); + assertEq(info.type, theTupleExtract.type); + assertEq(info.tuple, theTupleExtract.tuple); + assertEq(info.index, theTupleExtract.index); console.log(theTupleExtract.toText()); assert( @@ -3338,22 +3339,22 @@ console.log("# RefI31"); const module = new binaryen.Module(); var value = module.local.get(1, binaryen.i32); - const theRefI31 = binaryen.RefI31(module.ref.i31(value)); + const theRefI31 = module.ref.i31(value); assert(theRefI31 instanceof binaryen.RefI31); assert(theRefI31 instanceof binaryen.Expression); - assert(theRefI31.value === value); - // assert(theRefI31.type === binaryen.?); // TODO: (ref i31) + assertEq(theRefI31.value, value); + // assertEq(theRefI31.type, binaryen.?); // TODO: (ref i31) var info = binaryen.getExpressionInfo(theRefI31); - assert(info.id === theRefI31.id); - assert(info.type === theRefI31.type); - assert(info.value === theRefI31.value); + assertEq(info.id, theRefI31.id); + assertEq(info.type, theRefI31.type); + assertEq(info.value, theRefI31.value); theRefI31.value = value = module.local.get(2, binaryen.i32); - assert(theRefI31.value === value); + assertEq(theRefI31.value, value); info = binaryen.getExpressionInfo(theRefI31); - assert(info.value === theRefI31.value); + assertEq(info.value, theRefI31.value); console.log(theRefI31.toText()); assert( @@ -3370,31 +3371,31 @@ console.log("# I31Get"); const module = new binaryen.Module(); var i31 = module.local.get(1, binaryen.i31ref); - const theI31Get = binaryen.I31Get(module.i31.get_s(i31)); + const theI31Get = module.i31.get_s(i31); assert(theI31Get instanceof binaryen.I31Get); assert(theI31Get instanceof binaryen.Expression); - assert(theI31Get.i31 === i31); - assert(theI31Get.signed === true); - assert(theI31Get.type === binaryen.i32); + assertEq(theI31Get.i31, i31); + assertEq(theI31Get.signed, true); + assertEq(theI31Get.type, binaryen.i32); var info = binaryen.getExpressionInfo(theI31Get); - assert(info.id === theI31Get.id); - assert(info.type === theI31Get.type); - assert(info.i31 === theI31Get.i31); - assert(info.isSigned === theI31Get.signed); + assertEq(info.id, theI31Get.id); + assertEq(info.type, theI31Get.type); + assertEq(info.i31, theI31Get.i31); + assertEq(info.isSigned, theI31Get.signed); theI31Get.i31 = i31 = module.local.get(2, binaryen.i31ref); - assert(theI31Get.i31 === i31); + assertEq(theI31Get.i31, i31); theI31Get.signed = false; - assert(theI31Get.signed === false); + assertEq(theI31Get.signed, false); theI31Get.type = binaryen.f64; theI31Get.finalize(); - assert(theI31Get.type === binaryen.i32); + assertEq(theI31Get.type, binaryen.i32); info = binaryen.getExpressionInfo(theI31Get); - assert(info.type === theI31Get.type); - assert(info.i31 === theI31Get.i31); - assert(info.isSigned === theI31Get.signed); + assertEq(info.type, theI31Get.type); + assertEq(info.i31, theI31Get.i31); + assertEq(info.isSigned, theI31Get.signed); console.log(theI31Get.toText()); assert(