nodejs WebAssembly native work is well,but webassemblyjs throw these error
{ instantiate: [Function: instantiate],
compile: [Function: compile],
validate: [Function: validate],
instantiateFromSource: [Function: instantiateFromSource],
Instance: [Function: Instance],
Module: [Function: Module],
Memory: [Function: Memory],
Table: [Function: Table],
RuntimeError: [Function: RuntimeError],
LinkError: [Function: LinkError],
CompileError: [Function: CompileError] }
(node:15096) UnhandledPromiseRejectionWarning: Unhandled promise rejection (reje
ction id: 2): Error: Validation errors:
Function does not have local 8 at func_17:8.
Function does not have local 12 at func_18:10.
Function does not have local 5 at func_19:11.
Function does not have local 3 at func_20:6.
Function does not have local 5 at func_21:7.
Function does not have local 7 at func_22:6.
Function does not have local 5 at func_23:5.
Function does not have local 6 at func_24:5.
Function does not have local 6 at func_24:0.
Function does not have local 6 at func_24:2.
Function does not have local 6 at func_24:2.
Function does not have local 10 at func_25:8.
Function does not have local 8 at func_26:8.
Function does not have local 7 at func_27:8.
Function does not have local 8 at func_28:8.
Function does not have local 9 at func_29:7.
Function does not have local 6 at func_30:4.
Function does not have local 5 at func_30:4.
Function does not have local 13 at func_32:2.
Function does not have local 10 at func_32:2.
Function does not have local 4 at func_32:4.
Function does not have local 8 at func_32:19.
Function does not have local 7 at func_33:6.
Function does not have local 7 at func_33:2.
Function does not have local 7 at func_33:5.
Function does not have local 2 at func_34:5.
Function does not have local 3 at func_34:5.
Function does not have local 2 at func_35:4.
Function does not have local 5 at func_38:2.
Function does not have local 5 at func_38:0.
Function does not have local 3 at func_38:3.
Function does not have local 4 at func_38:9.
Function does not have local 3 at func_40:7.
Function does not have local 5 at func_41:2.
i want test a wasm moudle and pass a i64 param to a function
Could you please send me the Wasm module, if you can?
[...] pass a i64 param to a function
This is not possible yet, there's ongoing work to support that in JS. But you can pass two i32 instead.
http://votetracker.eosmedi.com/code.wast
this wasm module is a smart contract running on eos platform https://github.com/eosio/eos
my goal is execute this module in javascript,but the 'apply' function only accept the 3 i64 parameters , but i found a article write by you,use bigint as i64 type, also i found this project ,i saw you used long.js, so i think maybe i can pass 3 'long' type values as the function input
Thanks, I'll investigate that during the holidays.
The article I wrote is about the native support which is not yet deployed widely. I know that we have a hack to pass i64 as Long.js objects, i'll send an example here.
With https://github.com/xtuc/webassemblyjs/pull/473 merged I'm down to two errors:
Validation errors:
Expected type i64 but got i32 at func_21:123.
Stack contains additional type i32 at func_35.
thanks a lot, merry christmas! I notice you will come to HanZhou for D2 in next month, maybe I will come too! welcome to china !
Thanks, you too and see in at D2 :smiley:
Now with #474 the module validates. I'm hitting an unimplemented operation now (i64.gt_u), would you mind contributing? I think it will trigger other unimplemented instructions.
For the i64 instructions case, we have Long.js that implements many operations already.
Also, to pass an i64 from JavaScript you can use:
const { readFileSync } = require("fs");
const WebAssemblyjs = require("./packages/webassemblyjs");
const Long = require("@xtuc/long").default;
const makeLogFn = msg => () => console.log(msg);
const _internalInstanceOptions = {
checkForI64InSignature: false
};
const imports = {
_internalInstanceOptions,
env: {
abort: makeLogFn("abort"),
action_data_size: makeLogFn("action_data_size"),
current_time: makeLogFn("current_time"),
db_get_i64: makeLogFn("db_get_i64"),
db_lowerbound_i64: makeLogFn("db_lowerbound_i64"),
eosio_assert: makeLogFn("eosio_assert"),
is_account: makeLogFn("is_account"),
memcpy: makeLogFn("memcpy"),
read_action_data: makeLogFn("read_action_data"),
require_auth: makeLogFn("require_auth"),
require_auth2: makeLogFn("require_auth2"),
send_inline: makeLogFn("send_inline")
}
};
const i64 = n => new Long.fromString(n);
WebAssemblyjs.instantiate(readFileSync("./code.wasm", null), imports)
.then(i => {
const { apply } = i.instance.exports;
apply(i64("1"), i64("2"), i64("3"));
})
.catch(err => {
throw err;
});
wow, it's really helpful for me. this file is compiled by https://github.com/EOSIO/eosio.cdt
webassembly in blockchain project are very popular.
https://github.com/EOSIO/eos/blob/master/libraries/chain/webassembly/wavm.cpp
https://github.com/EOSIO/eosio.cdt/blob/10dc7187d754ce8348f6f57c21560067456a787c/external/wabt/src/wast-lexer.cc https://github.com/EOSIO/eos/blob/905e7c85714aee4286fa180ce946f15ceb4ce73c/libraries/wasm-jit/Source/Runtime/LLVMEmitIR.cpp https://github.com/search?p=1&q=org%3AEOSIO+gt_u&type=Code
these file maybe helpful
RETURN_OPCODE(Compare, I64GtU);
I have an ongoing patch for the i64 operations https://github.com/xtuc/webassemblyjs/pull/475/files.
I encounter another error in the interpreter:
trace exec Instr(get_local)
trace exec Instr(extend_u/i32)
trace exec Instr(const)
trace exec Instr(shl)
Error: Internal failure: expected c1 value of type i64 on top of the stack, given type: i32
https://github.com/EOSIO/eosio.cdt/blob/10dc7187d754ce8348f6f57c21560067456a787c/external/wabt/src/interp.cc
https://github.com/WebAssembly/wabt/search?p=2&q=shl&unscoped_q=shl
thanks for your job!