-
Notifications
You must be signed in to change notification settings - Fork 456
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
Interpreter: Inconsistencies in s-expression format #437
Comments
Yes, the s-expression format can be "folded" or unfolded. Many have found that the folded format (pre-order) is easier to read than the unfolded format (post-order). Ultimately, the binary format is expressed as a stack machine, so the folded format is just sugar. If you look at the grammar for the spec or wabt parsers, you'll see that for "plain instructions", the behavior is just to swap the order of the instruction with all the following child expressions. In other words, So for example, All of these:
Are sugar for:
Even though |
@binji I see and understand that this is syntactical sugar and boils down to instructions for the stack machine, but i don't really see how the 2nd and 3th would be correct and produce the result 6. Anyways, can you think of anything that could cause a problem when I would convert the "plain instructions" to "real" s-expression instructions and interpret these, as opposed to directly interpreting the binary format (besides the unnecessary step)? |
Sorry, I wasn't clear. None of these will produce the output 6 in isolation, in fact the function:
Is not valid because it leaves two values on the stack: 1 and 5. You'd have to have an additional
You can convert from the "flat" format (no folding) to a folded format in most cases, and in fact this is what binaryen does, AFAIK. The stack machine is more expressive, though, as something like this:
Cannot be folded into a two operand
|
@jonas-db, in addition to @binji's explanation also note that we want to generalise Wasm to multiple return values soon. Once we do, the type of an operator does no longer coincide with the syntactic arity of its application. For example, imagine a function $f that returns two i32 values. Then
is an expression you want to be able to write. |
Closing this, since question has been answered / working as intended. There now is PR #471 for specifying the text format. |
[test] Add JS API tests for I31 refs
In the example 'simple' (https://cdn.rawgit.com/WebAssembly/wabt/e528a622caa77702209bf0c3654ca78456c41a52/demo/index.html) there is a prefix notation of operators:
However, when i convert a .wasm to a .wast with
wasm -d module.wasm -o module.wast
, i see code snippets where this is not the case:This makes parsing such s-based expressions hard since i32.add is expected to have 2 operands. This is also the case with other operators.
The text was updated successfully, but these errors were encountered: