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

Confused about text format #1042

Closed
ljulliar opened this issue Jul 5, 2019 · 9 comments
Closed

Confused about text format #1042

ljulliar opened this issue Jul 5, 2019 · 9 comments

Comments

@ljulliar
Copy link

ljulliar commented Jul 5, 2019

I started writing some wasm code (well actually WAT code) and I'm confused as to what the correct syntax is like I'm seeing wat sample using get_local although the WASM 1.0 spec says local.get. Same for set_local. I have noticed other discrepancies too here and thare

Is it that the WAT samples I'm looking at are outdated or is it that the various WAT -> WASM compilers available right now are not yet compliant with the WASM 1.0 specification ?

Side question: is there a forum for SW development in WASM somewhere ?

Thank you everyone ! (and congrats for making WASM. It's a great initiative)

@rossberg
Copy link
Member

rossberg commented Jul 5, 2019

Yes, there was a change in naming scheme from get_local to local.get -- and other renamings -- late in the game, so many sources might still use the old syntax.

@ljulliar
Copy link
Author

Thank you for that. And for another quick question about text format again. When writing wat code am I supposed to use the S expression style like

(i32.add
(get_local $1)
(i32.const 5)
)

or the stack-based postfix style :
local.get $1
i32.const 5
i32.add

Thanks!

@rossberg
Copy link
Member

You use the style you prefer. ;)

@ljulliar
Copy link
Author

Ah nice!
Except for the block / loop instructions where you have to use the S-expression style anyway, right ?

@binji
Copy link
Member

binji commented Jul 10, 2019

No, there are different formats for those too:

;; "flat" format
block
  nop
  i32.const 1
  i32.const 2
  i32.add
  drop
end

;; sexpr format
(block
  (nop)
  (drop
    (i32.add (i32.const 1) (i32.const 2)))
)

Same with if and loop too. if has a bit more syntax though:

;; flat format
i32.const 1 ;; condition
if
  nop
else
  nop
end

;; sexpr format
(if
  (i32.const 1)  ;; condition
  (nop)
  (nop)
)

;; alternate sexpr format
(if
  (i32.const 1)
  (then (nop))
  (else (nop))
)

These all produce identical binary output.

@rossberg
Copy link
Member

@binji:

;; sexpr format
(if
  (i32.const 1)  ;; condition
  (nop)
  (nop)
)

Actually, we dropped this short form on the way to standardisation.

@binji
Copy link
Member

binji commented Jul 10, 2019

Interesting, I must have missed that change. :)

@ljulliar
Copy link
Author

@binji Thanks a lot. That was very helpful. Reading the WASM Standard it isn't obvious that you can use so many different style writing WAT code.

@rossberg
Copy link
Member

rossberg commented Aug 4, 2022

This has been answered.

@rossberg rossberg closed this as completed Aug 4, 2022
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