Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nodejs WebAssembly native work is well,but webassemblyjs throw these error #472

Open
lljxx1 opened this issue Dec 21, 2018 · 17 comments
Open

Comments

@lljxx1
Copy link

lljxx1 commented Dec 21, 2018

{ 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.

@lljxx1
Copy link
Author

lljxx1 commented Dec 21, 2018

i want test a wasm moudle and pass a i64 param to a function

@xtuc
Copy link
Owner

xtuc commented Dec 21, 2018

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.

@lljxx1
Copy link
Author

lljxx1 commented Dec 22, 2018

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

@xtuc
Copy link
Owner

xtuc commented Dec 24, 2018

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.

@xtuc
Copy link
Owner

xtuc commented Dec 24, 2018

With #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.

@lljxx1
Copy link
Author

lljxx1 commented Dec 25, 2018

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 !

@xtuc
Copy link
Owner

xtuc commented Dec 27, 2018

Thanks, you too and see in at D2 😃

@xtuc
Copy link
Owner

xtuc commented Dec 27, 2018

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;
  });

@lljxx1
Copy link
Author

lljxx1 commented Dec 28, 2018

wow, it's really helpful for me.
this file is compiled by https://github.com/EOSIO/eosio.cdt

@lljxx1
Copy link
Author

lljxx1 commented Dec 28, 2018

webassembly in blockchain project are very popular.

@lljxx1
Copy link
Author

lljxx1 commented Dec 28, 2018

@lljxx1
Copy link
Author

lljxx1 commented Dec 28, 2018

RETURN_OPCODE(Compare, I64GtU);

@xtuc
Copy link
Owner

xtuc commented Jan 8, 2019

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

@lljxx1
Copy link
Author

lljxx1 commented Jan 14, 2019

@lljxx1
Copy link
Author

lljxx1 commented Jan 14, 2019

thanks for your job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants