Commit graph

57 commits

Author SHA1 Message Date
Brian Carroll
c950f6d834 Merge branch 'trunk' of github.com:rtfeldman/roc into wasm-linking-zig9 2022-04-11 18:34:43 +01:00
Brian Carroll
249925cb23 wasm: Work around Zig returning small structs as integers 2022-04-11 11:28:40 +01:00
Brian Carroll
5db3ae0227 wasm: code gen for higher order wrapper function 2022-04-05 00:02:05 +01:00
Brian Carroll
83cae16a60 wasm: Generate code for List.map call (incomplete) 2022-04-05 00:02:05 +01:00
Brian Carroll
ff9bbfab63 wasm: generate code for ZigCC wrapper function 2022-04-05 00:01:11 +01:00
Mats Sigge
71f359fbdc Move macros from roc_reporting to new roc_error_macros module
The `internal_error!` and `user_error!´ macros can't be used everywhere
when they live in `roc_reporting` due to circular dependencies.
2022-01-23 18:40:04 +01:00
ayazhafiz
4631ff96f5 Initialize stack pointer when it doesn't exist
I'm not sure this is right, but we have to do it somewhere.. and here
seems reasonable?
2021-12-26 17:46:06 -06:00
Folkert de Vries
2f1c648602
Merge pull request #2253 from rtfeldman/wasm-no-block-results
Wasm: fix nested conditionals
2021-12-21 16:35:22 +01:00
Brian Carroll
17dc6668ec Make all Wasm blocks NoResult and always put return value in a local var. 2021-12-21 13:16:15 +00:00
Brian Carroll
51119c8142 Emit less code for ensure_value_has_local 2021-12-21 13:16:15 +00:00
Brian Carroll
6480a720ae Move symbol_layouts to storage.rs 2021-12-20 16:06:39 +00:00
Brian Carroll
ece28f1975 Fix loading code for Zig calling convention 2021-12-19 21:20:06 +00:00
Brian Carroll
f3ca3be507 Add Wasm support for recursive tags, along with GetTagId and UnionAtIndex 2021-12-11 20:33:11 +00:00
Brian Carroll
3f7b3bef87 Merge branch 'trunk' of github.com:rtfeldman/roc into wasm-tags 2021-12-09 09:28:11 +00:00
Brian Carroll
1dda8859c4 Update gen_wasm's error handling to remove Result and use macros consistently 2021-12-09 00:11:44 +00:00
Brian Carroll
1ba654c5b2 Change round_up_to_alignment to a macro to work on more Rust types 2021-12-08 21:11:10 +00:00
Brian Carroll
a08633fd36 Debugging improvements 2021-11-30 10:58:03 +00:00
Brian Carroll
079a8311ec Delete HeapMemory variant of WasmLayout, just treat pointers as Primitive
When I created this (at the very beginning of the Wasm backend),
I didn't really have a clear reason for it. I just thought it might end up
making sense treat heap pointers differently from numbers, somehow.

But the semantic differences between pointers and other numbers is not relevant
to WasmLayout. The semantics are clear from where the Symbol appears in the IR.

Also we were storing heap pointers in locals, for no real reason.
And the fact that it's *different* meant a lot of new cases in match expressions,
to do the exact same thing as Primitives but with a pointless difference.

Until now, we haven't really used this variant in any of our tests.
But the refcount pointer needed it... and everything broke!
2021-11-30 09:57:00 +00:00
Brian Carroll
1f747e971f Clippy & fmt 2021-11-29 01:09:31 +00:00
Brian Carroll
dcd4914ac1 Fix and enable tests involving empty records 2021-11-29 00:57:28 +00:00
Brian Carroll
88bf6bf1b7 Clean up Wasm calling convention code 2021-11-29 00:17:45 +00:00
Folkert
4e6568016d fix comment: rust thought it was code it should execute 2021-11-23 11:56:33 +01:00
Folkert
44fdf8df18 remove unreachable cases 2021-11-22 21:40:44 +01:00
Folkert
78c26c6096 fix returning an aggregate value with ccc 2021-11-22 10:17:17 +01:00
Brian Carroll
5a8c3d4f0f Fix it again, properly this time 2021-11-21 23:49:26 +00:00
Brian Carroll
bd2813f36c Fix loading of 128-bit numbers 2021-11-21 23:46:04 +00:00
Brian Carroll
2e31350010 Logic to load 128-bit numbers 2021-11-21 20:44:16 +00:00
Brian Carroll
03c19b727a String concatenation working in gen_wasm! 2021-11-17 13:38:50 +00:00
Brian Carroll
af896e5d33 Comments 2021-11-17 09:39:16 +00:00
Brian Carroll
e9f920827e Add support for Zig/LLVM "fast calling convention" 2021-11-15 19:20:55 +00:00
Brian Carroll
29d355c4d6 Implement Expr::StructAtIndex for wasm dev backend 2021-11-14 19:06:04 +00:00
Brian Carroll
39263b0ab1 Shorter name: VmSymbolState 2021-11-14 10:57:19 +00:00
Brian Carroll
1b5740cd5d Tidy up lowlevel calls and implement a few more 2021-11-09 14:28:15 +00:00
Brian Carroll
ad9b761fce Move wasm file format code into a submodule 2021-11-03 11:20:16 +00:00
Brian Carroll
973626fe2d Rename FunctionBuilder back to CodeBuilder 2021-10-23 13:48:20 +02:00
Brian Carroll
dbe6d195f7 Delete CodeBuilder 2021-10-23 13:40:10 +02:00
Brian Carroll
74e3239a1c Switch over to function_builder 2021-10-23 13:39:54 +02:00
Brian Carroll
5ea313f256 update gen_wasm to use bumpalo::collections::Vec where possible 2021-10-21 21:14:15 +02:00
Brian Carroll
401f2ececd rename some methods 2021-10-18 21:35:16 +02:00
Brian Carroll
1b97675f1f Refactor the optimisation for immediately-returned Let statements
The original intention was to avoid creating a local when we define
and immediately return a primitive value. But now our default path
does avoids unnecessary locals anyway!

For StackMemory values we do need an optimised path but it's nicer
to just pass a flag to Storage::allocate.
2021-10-18 13:18:10 +02:00
Brian Carroll
6206418b67 Fix clippy warnings 2021-10-14 00:13:47 +02:00
Brian Carroll
5c42455ca7 Rename some values & improve comments 2021-10-13 10:52:51 +02:00
Brian Carroll
472943a068 Refactoring: extract Storage out of WasmBackend 2021-10-12 10:22:38 +01:00
Brian Carroll
d2e01bd10a rename SymbolStorage -> StoredValue 2021-10-12 10:20:17 +01:00
Brian Carroll
3aaafdefe1 Get Join/Jump working with VM storage 2021-10-09 16:46:59 +01:00
Brian Carroll
d81999045a Get Switch statements working with VM storage 2021-10-07 09:14:35 +01:00
Brian Carroll
d6bba482ee Treat the Virtual Machine stack as a form of SymbolStorage
Simulate the behaviour of the stack machine, mark where Symbol values
are created, and track where they are in the stack as we emit instructions.

This will allow us to be smarter with setting and getting locals.
However that's not actually implemented yet! At the moment,
we're still generating the same code as before but in a fancier way.

What's happening:

Let's say we have a function call that takes two arguments [A,B]
and that we are lucky and just happen to have a VM stack of [A,B]
That's great, we _should_ not have to do anything, just emit 'Call'

BUT what we are doing is "load A to the top" and then "load B to the top".
This sounds good but it's actually stupid
We are saying we want A at the top of the stack when we don't!!
We want it right where it is, just beneath the top!

So we are emitting code to bring it from 2nd position to the top.
How do we do that? By inserting a local.set instruction to save it,
and a local.get instruction to load it to the top!

What should be happening:

Check the entire VM stack at once for all the symbols we are trying to load.
If they happen to be there (which is likely given the IR structure) do nothing.
If it's not quite perfect... then emit lots of local.set and local.get. Whatever.

What would be the way to solve this properly?

Build the Wasm instructions as a tree, then serialise it depth-first.
The tree encodes all of the information about what needs to be on the
stack at what point in the program. If a tree node has two children,
it consumes two items from the stack. If you do it this way, all
of the instructions get executed just at the right time.
2021-10-05 21:39:19 +01:00
Brian Carroll
32f79b5ee2 Create CodeBuilder to track Wasm VM stack as we accumulate instructions 2021-10-03 22:50:11 +01:00
Brian Carroll
cc6f83f284 Clearer variant names for StackMemoryLocation 2021-10-03 21:53:18 +01:00
Brian Carroll
2756425eb9 Assert storage matches when copying 2021-10-03 21:52:27 +01:00