Commit graph

139 commits

Author SHA1 Message Date
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
304e9c904f Formatting 2021-09-30 17:28:02 +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
79ac2f04b8 Improve stack allocation code 2021-09-30 17:04:16 +01:00
Brian Carroll
f1b14c14e3 Refactor SymbolStorage to emphasise stack/non-stack params
We don't have much (any) code that cares about the difference between
heap pointers and other primitives, but we have a _lot_ of code that cares
if it's stack memory. So let's encode it that way.
2021-09-30 17:04:16 +01:00
Brian Carroll
7ea59ad9d4 PR tidy-ups 2021-09-29 06:15:58 +01:00
Brian Carroll
45c9dc8617 update gen_wasm README 2021-09-28 19:06:47 +01:00
Brian Carroll
02bb9028ef Returning records on the stack from Wasm dev backend! 2021-09-28 08:06:59 +01:00
Brian Carroll
39fda3e675 Add more information to SymbolStorage
SymbolStorage is function-specific, whereas WasmLayout is function-independent.

SymbolStorage used to be a single-variant enum with a LocalId and a WasmLayout,
but now we need more variants, so we can handle stack memory allocation..

- For values in stack memory, the storage needs to include an offset within the
  stack frame, but we don't need that for primitive values.

- For function parameters, the allocated stack memory is in the caller's frame
  rather than the current frame, so we don't want size or offset.

We could have kept a WasmLayout inside of SymbolStorage but that would have made
possible a lot of invalid combinations. It seemed better to copy the fields we need.
2021-09-26 20:52:17 +01:00
Brian Carroll
ecece45a83 Add a helper method local_id_from_symbol 2021-09-26 20:52:17 +01:00
Brian Carroll
286ca680e0 Tidy up load_literal 2021-09-26 20:52:16 +01:00
Brian Carroll
92b1d73bd6 Refactor build_proc into smaller helpers 2021-09-26 20:52:10 +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
52a56bfa27 Optimise away a memory copy for returned structs in simple cases 2021-09-17 21:50:00 +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
3d18d34135 Insert extra argument when returning on stack 2021-09-15 18:45:20 +02:00
Brian Carroll
866d9f47a0 Move WasmLayout to its own module 2021-09-14 08:31:32 +02:00
Brian Carroll
258513a57c reset join/jump data 2021-09-14 08:18:33 +02:00
Brian Carroll
672aa14f7c Cosmetic: reorganise WasmLayout match statment 2021-09-14 08:00:00 +02:00
Brian Carroll
c47c3ccf58 Clippy fix 2021-09-13 17:30:13 +02:00
Brian Carroll
408c31ebcc Tests for different bitwidth integers 2021-09-13 17:01:06 +02:00
Brian Carroll
b21155f60b Move some constants from backend to lib 2021-09-11 10:20:32 +01:00
Brian Carroll
042b175d89 More comprehensive WasmLayout 2021-09-11 10:20:27 +01:00
Folkert
3750b154ca cleanup 2021-09-10 13:52:33 +02:00
Folkert
7290ef7f98 rename 2021-09-10 13:19:18 +02:00
Folkert
e802da5f54 implement factorial example 2021-09-08 20:05:05 +02:00
Folkert
4e5b677426 basic join point 2021-09-08 15:54:00 +02:00
Folkert
1da32f18e5 implement switch for the gen wasm backend 2021-09-08 00:00:36 +02:00
Folkert
c888baccff rename layout -> return_layout 2021-09-07 20:55:05 +02:00
Folkert
afd7553e7a enable F64 2021-09-07 17:42:31 +02:00
Brian Carroll
b445cea964 Fix generation of params & locals 2021-09-04 21:35:23 +01:00
Brian Carroll
bf7b1cdc63 Don't double-count args as locals 2021-09-04 13:34:04 +01: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
Folkert
08e242967a function must end with an End instruction 2021-09-01 22:36:34 +02:00
Brian Carroll
0770bb242e Reset after each procedure, and reserve space in vecs 2021-09-01 20:12:01 +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
Renamed from compiler/gen_wasm/src/function.rs (Browse further)