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

Demo #2

Open
arcosx opened this issue Dec 21, 2021 · 5 comments
Open

Demo #2

arcosx opened this issue Dec 21, 2021 · 5 comments

Comments

@arcosx
Copy link
Contributor

arcosx commented Dec 21, 2021

CREATE FUNCTION f1_addTwo(x INT32, y INT32, z FLOAT) RETURN FIXED_STRING(10) FROM WASM://AGFzbQEAAAABBwFgAn9/AX8DAgEABwoBBmFkZFR3bwAACgkBBwAgACABagsADgRuYW1lAgcBAAIAAAEA;
@Triple-Z
Copy link
Member

Triple-Z commented Dec 23, 2021

A greatest common divider example:

# wasmtime
CREATE FUNCTION gcd_main(x INT32, y INT32) RETURN INT32 FROM WAT://KG1vZHVsZQogIChmdW5jICRnY2QgKHBhcmFtIGkzMiBpMzIpIChyZXN1bHQgaTMyKQogICAgKGxvY2FsIGkzMikKICAgIGJsb2NrICA7OyBsYWJlbCA9IEAxCiAgICAgIGJsb2NrICA7OyBsYWJlbCA9IEAyCiAgICAgICAgbG9jYWwuZ2V0IDAKICAgICAgICBicl9pZiAwICg7QDI7KQogICAgICAgIGxvY2FsLmdldCAxCiAgICAgICAgbG9jYWwuc2V0IDIKICAgICAgICBiciAxICg7QDE7KQogICAgICBlbmQKICAgICAgbG9vcCAgOzsgbGFiZWwgPSBAMgogICAgICAgIGxvY2FsLmdldCAxCiAgICAgICAgbG9jYWwuZ2V0IDAKICAgICAgICBsb2NhbC50ZWUgMgogICAgICAgIGkzMi5yZW1fdQogICAgICAgIGxvY2FsLnNldCAwCiAgICAgICAgbG9jYWwuZ2V0IDIKICAgICAgICBsb2NhbC5zZXQgMQogICAgICAgIGxvY2FsLmdldCAwCiAgICAgICAgYnJfaWYgMCAoO0AyOykKICAgICAgZW5kCiAgICBlbmQKICAgIGxvY2FsLmdldCAyCiAgKQogIChleHBvcnQgIm1haW4iIChmdW5jICRnY2QpKSA7OyBleHBvcnQgd2l0aCBtYWluCik=;

# WasmEdge (BUG)
CREATE FUNCTION gcd_main(x INT32, y INT32) RETURN INT32 FROM WASM://AGFzbQEAAAABBwFgAn9/AX8DAgEABwcBA2djZAAACiwBKgEBfwJAAkAgAA0AIAEhAgwBCwNAIAEgACICcCEAIAIhASAADQALCyACCwAYBG5hbWUBBgEAA2djZAIJAQADAAABAAIA;

RETURN UDF("gcd", [12, 27]);
# result is 3
RETURN UDF("gcd", [12, 6]);
# result is 6
RETURN UDF("gcd", [50, 150]);
#result is 50

DROP FUNCTION gcd;

WasmEdge result always has a chance of going wrong, like this:
image

@arcosx
Copy link
Contributor Author

arcosx commented Dec 23, 2021

WASM and WAT generally do not have the same base64.
WAT pass the wat (string) base64 string.
WASM pass the xxx.wasm (file binary) to base64 string.

We should notice user how to use.

Here are website can help.

https://webassembly.github.io/wabt/demo/wasm2wat/
https://webassembly.github.io/wabt/demo/wat2wasm/

@Triple-Z
Copy link
Member

WASM and WAT generally do not have the same base64.

OK, I get it. It's my usage fault.

@Triple-Z
Copy link
Member

Triple-Z commented Dec 23, 2021

I used wat2wasm to compile the gcd.wat, and the binary base64 is AGFzbQEAAAABBwFgAn9/AX8DAgEABwcBA2djZAAACiwBKgEBfwJAAkAgAA0AIAEhAgwBCwNAIAEgACICcCEAIAIhASAADQALCyACCwAYBG5hbWUBBgEAA2djZAIJAQADAAABAAIA:

image

But it still doesn't work in nebula.

image

BTW, addTwo from wat2wasm site works well.

@Triple-Z
Copy link
Member

Triple-Z commented Dec 25, 2021

CREATE FUNCTION 语法。

CREATE FUNCTION [IF NOT EXISTS] <function_name>_<function_handler> 
(
  <param_name> <data_type>
  [{, <param_name> <data_type>} ...]
)
RETURN <return_type>
FROM [ WASM://<wasm_binary_base64> | WAT://<wat_source_base64> | PATH://<remote_source_path> ];

DROP FUNCTION 语法。

DROP FUNCTION [IF EXISTS] <function_name>;

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