Running WebAssembly from my hobby compiler!

Sdílet
Vložit
  • čas přidán 6. 07. 2024
  • Code: github.com/contextfreeinfo/rio
    0:00 Intro
    0:53 Internal & Wasm representation
    1:58 Support scripts & export example
    3:15 Wasm generation
    3:43 Stages & type representation
    5:30 Compiler internals
    6:08 Type inference strategy
    8:38 Core module
    9:02 Main function and friends
    10:12 Keep on trucking
    11:35 Running junk
    12:25 Prep for tooling
    12:56 Summary
  • Věda a technologie

Komentáře • 22

  • @dercoder015
    @dercoder015 Před 6 měsíci +4

    very cool, i was also interested to compile to wasm but getting into it seeemed daunting. Will definitely use your project as inspiration

    • @contextfree
      @contextfree  Před 6 měsíci +2

      Definitely review output from other compilers for ideas. That helps me a lot.

  • @UliTroyo
    @UliTroyo Před 6 měsíci +3

    I dig the syntax :)

  • @1vader
    @1vader Před 6 měsíci +3

    There are some wasm optimizers like binaryen which I'd assume would optimize stuff like variables that are stored and immediately loaded again and then never used again. So maybe you could just run that after your compilation to get some speedups. Although I guess it might add some annoying dependencies and performance probably isn't exactly a priority.

    • @contextfree
      @contextfree  Před 6 měsíci

      Yeah, I've used wasm-opt from binaryen, and I think that's my fallback. Worst case, people can follow up with that after a non optimizing compiler, if/when that matters to them. Maybe I should include it as part of my overall test script, though, so I can compare processing times and output sizes and contents.

  • @irubberduck
    @irubberduck Před 6 měsíci +1

    Really interesting series. A completely different perspective compared to languages trying to be mature or production-ready. Especially the wild file / program.
    Is wasm limited to a 32-bit address space? Otherwise, why do your strings get unwrapped into 32-bit address and length parameters?

    • @AtomicalYT
      @AtomicalYT Před 6 měsíci +5

      WebAssembly in its core spec uses 32-bit integers for pointers. There is a separate proposal to have 64-bit memory addresses

  • @donutloop
    @donutloop Před 6 měsíci +1

    Cool

  • @0marble8
    @0marble8 Před 6 měsíci +1

    As im writing one of those parser generator programs for my thesis, ive been wondering, do real language designers actually use them? It seems like a lot of projects i looked at, all write their parser by hand

    • @contextfree
      @contextfree  Před 6 měsíci

      I've tried antlr and others in the past, and I think they're good for some things, but yeah, sometimes easier to be flexible with hand rolled. Or maybe I'm just stubborn, even if other people have good reasons to roll their own.

  • @casperes0912
    @casperes0912 Před 6 měsíci +3

    What was the difference between print message and print(message)? (and possibly print (message))?

    • @contextfree
      @contextfree  Před 6 měsíci +1

      Nothing really. I mostly want to support `print message` so constructs like `if whatever be ...` don't need parens, and those constructs get parsed the same as any function call, even if processed differently in the compiler (effectively macros although I'm not sure yet if I plan to expose macro definition support to user code). But when nesting function calls, not needing parens at every level might also be prettier sometimes, so I'll have to think about recommended style some. And I'm also thinking more on the `print (message)` thing. I was considering allowing tuples earlier, although as I mentioned in the video, I'm leaning away from that now. If there were tuples, then `something (a, b)` would pass in a single tuple as the first argument, whereas `something(a, b)` would have two separate arguments. I didn't change that comment yet because I want to think about it a bit more. But if I really don't have tuples, the space might as well be irrelevant, unless I'm forgetting something. Sometimes I only notice details when I start implementing. Anyway, sorry for being so longwinded in my reply!

    • @contextfree
      @contextfree  Před 6 měsíci

      And yeah, I have some plans, but I'm also winging a lot.

    • @casperes0912
      @casperes0912 Před 6 měsíci +2

      @@contextfree right. Makes sense. I think each style, by association, will encourage different styles. Print message would make me write more functional as my brain would initially group the language with ML languages like OCaml. Print(message) puts me in a procedural mindset. At least initially.

    • @contextfree
      @contextfree  Před 6 měsíci

      I'm definitely aiming for functional-first attitudes in Rio, but not aiming for purity.

  • @familyshare3724
    @familyshare3724 Před 6 měsíci +2

    I imagine a statically typed language with only two primitive cardinals: non-null value and non-null list. The "nullable" value can only be a list with zero elements.

    • @contextfree
      @contextfree  Před 6 měsíci

      Any variety in the non-null value or do you imagine using Peano numbers or some such?

    • @familyshare3724
      @familyshare3724 Před 6 měsíci +1

      @@contextfree oh yes, full typing, definable class types. Just no null. Anything "nullable" is just the empty set of that type. Consider a deserialized JSON with no null. Empty string same as [] (if not predefined). Arrays and objects are simply different types of a collection.

    • @familyshare3724
      @familyshare3724 Před 6 měsíci +1

      @@contextfree i would hope it would be simpler and faster than Lua, with types, and of course 0 indexed.

    • @contextfree
      @contextfree  Před 6 měsíci

      Thanks for the further explanation! I guess now would be a bad time to say that I often flirt with 1-based indexing ...

    • @atiedebee1020
      @atiedebee1020 Před 6 měsíci +4

      So... Lisp?