Coding raw WebAssembly Text - Dive into Wat

แชร์
ฝัง
  • เผยแพร่เมื่อ 23 พ.ย. 2024

ความคิดเห็น • 27

  • @contextfree
    @contextfree  ปีที่แล้ว +4

    And for an example of coding directly in wasm binary, check out this video from Thomas Ballinger! th-cam.com/video/pkw9USN_Tko/w-d-xo.html

  • @bensmith218
    @bensmith218 ปีที่แล้ว +8

    Thanks for the shout out!
    WebAssembly is a funny format because it looks like a stack machine, but doesn’t have traditional dup/swap/rot operators, and the text format uses s-expressions but otherwise is not at all like a lisp!
    In response to some other comments, WebAssembly is higher level than other machine code formats, primarily in the use of local variables instead of registers, and the requirement to use structured control-flow such as if and loop instead of jumps and branches. Neither of these are needed for safety, however, so it would have been possible to define it a different way.
    By the way, there is a “folded” format for the if instruction. It is written like (if (condition) (then (expr)) (else (expr))).
    Great video as always!

  • @MyCodingDiary
    @MyCodingDiary ปีที่แล้ว +7

    Your attention to detail and dedication to your craft is truly inspiring. Thank you for sharing your expertise with us!🖤❣

    • @contextfree
      @contextfree  ปีที่แล้ว

      Glad you enjoy the videos!

  • @tuffenduffen
    @tuffenduffen ปีที่แล้ว +4

    Having read the wasm spec, this video is very nice because the spec isn't very hands-on to put it lightly. Thank you very much!

    • @BenjaminAster
      @BenjaminAster ปีที่แล้ว +1

      You can look at Dan Gohman's wasm-reference-manual for a more human-readable documentation of WebAssembly.

    • @contextfree
      @contextfree  ปีที่แล้ว

      I missed this document in all my searching for help. Thanks for mentioning it! I think this is the right link? github.com/sunfishcode/wasm-reference-manual/blob/master/WebAssembly.md

    • @BenjaminAster
      @BenjaminAster ปีที่แล้ว +1

      @@contextfree yep

    • @109Rage
      @109Rage ปีที่แล้ว +3

      Yeah, I've gone through the spec before. It's written more for people implementing a WASM VM, and not people trying to write .wat files directly, so it can be rather difficult to parse through imo.

    • @spotandjake1008
      @spotandjake1008 ปีที่แล้ว +1

      @@contextfree Working between this, the wasm spec and mdn seems to be the best option for learning wasm. wat2wasm has a great online demo as well and when you run it with verbose mode on it can be very useful for learning what is what.
      I went through and made a wasm parser and builder in grain which was a fun project the spec is nice in small for wasm though so can be done in about a day or two. but the resources out there are a little lacking given how new wasm is.

  • @andrewdunbar828
    @andrewdunbar828 ปีที่แล้ว +2

    This was nice to see. I had a tiny bit of a play with WAT a year or so ago to see if it would bring back the nostalgia of doing machine code on the Z80 and assembly on the 68000.
    I didn't play with AssemblyScript though, are you thinking of having a look at that?

  • @shilangyu
    @shilangyu ปีที่แล้ว +2

    Very nice showcase. Makes me seriously consider Wat as the target for my toy language. It seems legible enough to do easy debugging on it. It can also compile to standalone executables, which is always desirable.

    • @contextfree
      @contextfree  ปีที่แล้ว +3

      I would actually like to go straight to binary wasm (ideally with some helper library) and use wasm2wat to inspect. Got to generate valid binary at each step for that, though, I suppose.

    • @spotandjake1008
      @spotandjake1008 ปีที่แล้ว +1

      Using binaryen it is rather easy to get something working once you have a front end anyways.

  • @gamerzero6085
    @gamerzero6085 ปีที่แล้ว +10

    Lol, didn't knew wasm text representation is lisp. That's kinda curious

    • @RodyDavis
      @RodyDavis ปีที่แล้ว

      Same, just now realized this

    • @adamih96
      @adamih96 ปีที่แล้ว

      WASM is different in that it is fully stack based like Forth

    • @gagagero
      @gagagero ปีที่แล้ว

      Most intermediate representation is made up of s-expressions.

  • @enirya
    @enirya ปีที่แล้ว +1

    one thing that bugged me about WAT was that the rules for parentheses arent strict like lisp and it made writing it feel weirdly inconsistent

    • @contextfree
      @contextfree  ปีที่แล้ว +1

      As it's not really lisp anyway, I wish I could add parenthesized args without parenthesizing the whole statement, but then it probably needs to worry about newlines or something. I didn't explore the corners of the grammar, but I suspect it's not aware of newlines.

  • @109Rage
    @109Rage ปีที่แล้ว +5

    2:40 - I take it you're using 0.10.1 Zig? Current way to iterate through integers is for(0..10) |n| {}

    • @contextfree
      @contextfree  ปีที่แล้ว +3

      Didn't realize they were improving that. Thanks for the info!

    • @VojtěchJavora
      @VojtěchJavora ปีที่แล้ว +1

      Oh, cool. I did not know that. Some time ago, I tried to Google how to do this but came back only with weird hacks about comptime array building or something.

  • @stevenhe3462
    @stevenhe3462 ปีที่แล้ว +1

    So, it is much higher-level than machine assembly languages, with strong inspiration from Lisp.

    • @contextfree
      @contextfree  ปีที่แล้ว +2

      I wouldn't worry the syntax so much. But yeah it's higher level than common hardware asm. I'm not sure which things are for convenience and which for safety. Haven't studied that enough.

  • @alirezakarimi8685
    @alirezakarimi8685 19 วันที่ผ่านมา

    Please help me : This browser does not support WebAssembly.
    This problem has occurred in some clients with Windows 11 and google chrome, whose browser is updated.

    • @contextfree
      @contextfree  18 วันที่ผ่านมา

      They may have disabled wasm in their browser, or maybe some extension or security settings are causing trouble? I don't know, but those sound like some possible causes from searching around.