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

Add grammar to execute raw WAT in Text Format #1581

Open
guest271314 opened this issue Jan 23, 2023 · 1 comment
Open

Add grammar to execute raw WAT in Text Format #1581

guest271314 opened this issue Jan 23, 2023 · 1 comment

Comments

@guest271314
Copy link

Currently the Text Format specification does not define a means to call a WASM executable from within the WAT file, see bytecodealliance/wasmtime#3715.

Reading the specification(s) https://github.com/WebAssembly/spec/blob/4c249c5a575e2b0e252e747af261bbb82f448dd4/interpreter/README.md, https://webassembly.github.io/spec/core/text/conventions.html#grammar this sounds reasonable

file.wat

;;#!wasmtime
(module
;; ...
)

Prospective specification text:

Comment ;; at position 0 and 1 in WAT followed by #! 1 invokes the following until end of line as WAT executable, optionally followed by arguments to WAT executable where lines 1-N are interpreted as WAT for WASM executable to execute.

The above change should not affect existing WAT usage, where it is highly unlikely WAT files in existence contain that precise sequence of characters at positions 0-3 in the file.

I found this limitation when using wasmtime to execute WASM as a Native Messaging host.

This is the current workaround I'm using to use WAT in a Bash sheel script, call wasmtime (which does not exit when the parent exits) using WAT Text Format in the same file, then terminate wasmtime in a separate script when the Native Messaging host exits.

nm_c_wat.sh

#!/bin/bash
# https://www.reddit.com/r/bash/comments/10i09se/comment/j5blsrw/

script='
(module
;; ...
)
'

./kill_wasmtime.sh &
./wasmtime <(printf '%s' "$script")

kill_wasmtime.sh

#!/bin/bash
while pgrep -f nm_c_wat.sh > /dev/null
do
  sleep 1
done
killall -9 wasmtime
exit 0

Pros, cons, discussion. I cannot champion this because W3C banned me. So either one of you champion this or it doesn't happen.

1. The #! magic, details about the shebang/hash-bang mechanism on various Unix flavours

@bjorn3
Copy link

bjorn3 commented Jan 23, 2023

I would rather specify the following:

If the WAT file starts with a # followed by an ! everything from the start of the file until the first newline shall be interpreted as comment.

;;#! is not something that any OS will interpret. It can only be interpreted once a program that supports reading WAT files has already started at which point I don't think there should be a possibility to run another program instead. UNIX systems only interpret #! at the start of the file without anything before it to determine which program to run.

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

3 participants
@guest271314 @bjorn3 and others