Commit graph

84 commits

Author SHA1 Message Date
Brian Carroll
8164a14dfa rename module_builder 2021-10-10 20:56:20 +01:00
Brian Carroll
d796bbcc68 add a couple of assertions 2021-10-05 21:19:08 +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
79a4f2bbf7 Refactor SymbolStorage local_id code, and copy_memory
SymbolStorage had some rather ad-hoc methods for extracting pieces of data.
This change makes that more intentional and organised.

Also cleaned up the API for the related function copy_memory,
as it had lots of positional arguments with the same types.
Created a struct for this just to name them and make the code clearer.
2021-10-02 22:31:48 +01:00
Brian Carroll
ffa6ff0a62 gen_wasm: Get rid of individual locals for values in stack memory
All values in stack memory can share the stack frame pointer,
with different offsets.

This avoids having to generate initialisation code for individual
pointers we used to have. It should also make things more efficient
when the runtime compiles Wasm to machine code. It can just assign
the stack frame pointer to a single CPU register and leave it there.

The original idea was to make params and local variables work the same.
(A struct param will be passed as a pointer to caller stack memory.)
But now I don't think that's worth it. Some match expressions get more
awkward this way but we might be able to refactor that to be nicer.
2021-10-02 15:12:25 +01:00
Brian Carroll
4aa2452e01 gen_wasm: Change some compiler bugs error handling from Result to panic
Result makes sense where I have something meaningful to say to the user like
"X is not implemented yet". And also for public functions that may interface
with other parts of the project like Backend.

But for private functions internal to gen_wasm, it's just unhelpful to get a stack trace
to where the Result is unwrapped! I want a stack trace to the root cause.
I always end up temporarily rewriting Err("oops") to panic!("oops") and then waiting
for it to recompile.

This feels like a more balanced approach, using each technique where it makes sense.
2021-10-02 13:40:44 +01:00
Brian Carroll
7ac7e16f60 Ensure stack frame is always popped when procedure returns from inside a branch 2021-09-30 17:04:16 +01:00
Brian Carroll
7ea59ad9d4 PR tidy-ups 2021-09-29 06:15:58 +01:00
Brian Carroll
02bb9028ef Returning records on the stack from Wasm dev backend! 2021-09-28 08:06:59 +01:00
Brian Carroll
65446ce1e8 Remove unnecessary Option 2021-09-18 14:46:09 +01:00
Brian Carroll
c3b5ac6c82 Allocate stack memory to local variables 2021-09-18 13:39:38 +01:00
Brian Carroll
4f55b7a56e Allocate and free stack frames 2021-09-17 21:17:05 +01:00
Brian Carroll
036503c750 copy returned structs to caller stack 2021-09-17 19:42:29 +01:00
Brian Carroll
866d9f47a0 Move WasmLayout to its own module 2021-09-14 08:31:32 +02:00
Brian Carroll
cfef0f0f47 Add clarifying comments based on PR feedback 2021-09-13 22:42:04 +02:00
Brian Carroll
35c5b6bc4e Tests passing with generic native/wasm interface 2021-09-12 23:23:43 +02:00
Brian Carroll
b21155f60b Move some constants from backend to lib 2021-09-11 10:20:32 +01:00
Folkert
34a88c228f fix another typo 2021-09-10 15:49:18 +02:00
Folkert
3a83b0c415 fix typo 2021-09-10 15:44:11 +02:00
Folkert
e3b3206286 sorting comment 2021-09-10 14:15:37 +02:00
Folkert
e802da5f54 implement factorial example 2021-09-08 20:05:05 +02:00
Folkert
f4379673b4 Merge remote-tracking branch 'origin/trunk' into gen_wasm 2021-09-07 16:45:57 +02:00
Folkert
f8809a3eef rename wasm -> wasm32 2021-09-05 14:08:14 +02:00
Brian Carroll
13a969a238 Bugfixes: generate valid wasm for gen_add_i64
Still need to create test_wrapper
2021-09-03 21:54:57 +01:00
Brian Carroll
9ba7076d8e Cleanups after self-review
- Fix clippy warnings
- Improve a comment
- Delete commented-out lines in Cargo.toml
- Checkin Cargo.lock
2021-09-01 19:37:15 +01:00
Brian Carroll
3bf94e020c Beat the borrow-checker by following gen_dev structure 2021-09-01 19:26:26 +01:00
Brian Carroll
e67efaba4d Split up Wasm module and function 2021-09-01 19:26:26 +01:00
Brian Carroll
e5d5bb27fa Implement a bit more of the IR 2021-09-01 19:26:25 +01:00
Brian Carroll
6500cb3c35 Add a body to the function 2021-09-01 19:26:25 +01:00
Brian Carroll
4d76b9d15d Refactor locals 2021-09-01 19:26:25 +01:00
Brian Carroll
8d7e0471fd Get rid of return-on-stack stuff for now, focus on numbers first 2021-09-01 19:26:24 +01:00
Brian Carroll
06c0e0d815 outline of build_proc 2021-09-01 19:26:24 +01:00
Brian Carroll
a1102222dd Create a high-level structure for Wasm backend 2021-09-01 19:26:23 +01:00
Brian Carroll
863f449048 Create a library for the Wasm dev backend 2021-09-01 19:26:23 +01:00