Skip to content

Commit 695db1b

Browse files
authored
feat(backend): Implement an anf tree and anf mapper (#12)
* feat: Refactor locations out of expressions Locations and expressions were overly intertwined this would have led to issues differentiating between sets and gets when performing codegen. * chore: Update tests * feat: Implement anf mapper and tree
1 parent e45fcaa commit 695db1b

55 files changed

Lines changed: 1518 additions & 494 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Codegen.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ Statements are going to be lowered within a function to wasm instructions.
4141
### Assignments
4242
Assignments are pretty simple we need to compile the left hand side which is the location accessor to become a `global.get` if we are working on an array we are going to need to set a memory address.
4343

44-
We are then either going to use ` WasmI32.store` for arrays or `local.set` for local variables or `local.set` for global variables `global.set`
44+
We are then either going to use `WasmI32.store` for arrays or `local.set` for local variables or `local.set` for global variables `global.set`
4545

46-
### Expression Statetements
46+
### Expression Statements
4747
These compile pretty simply as we compile the expression like normal and just `(drop)` the result if there is one.
4848

4949
### If Statements
@@ -70,13 +70,13 @@ This is going to compile to a wasm call pretty cleanly
7070
This is going to compile pretty cleanly into a wasm instruction we are going to need to use the signature and operator to determine what instruction to use from a lookup table.
7171

7272
### Prefix Node
73-
This is going to be done just like binops but with different instructions. I think for not we have a few option for compiling the simplest one is probably bitwise. It's also ussually the fastest
73+
This is going to be done just like binops but with different instructions. I think for not we have a few option for compiling the simplest one is probably bitwise. It's also usually the fastest.
7474

7575
### New Class Node
7676
This isn't going to be compiled if it was we would store some sort of record in linear memory that points to everything.
7777

7878
### New Array Node
79-
This is going to probably use a very primtive bump allocator to compile some instructions that write a simple data structure to memory probably something like ```<arrayTypeID>, <size>, ...<values>````
79+
This is going to probably use a very primitive bump allocator to compile some instructions that write a simple data structure to memory probably something like `<arrayTypeID>, <size>, ...<values>`
8080

8181
### LocationNode
8282
I think we still need todo some thoughts here but it's essentially going to be come a local.get or local.set depending on the use, this is probably going to be compiled in a somewhat context aware manner.
@@ -97,14 +97,10 @@ This is going to become a `(i32.const <value>)`
9797
This is also going to become a `(i32.const <value>)` we will make no distinction between a character and an integer at runtime.
9898

9999
### String
100-
This is only going to be compiledin one place the values will go into data sections and we will copy from the data section into memory passing around the pointer.
100+
This is only going to be compiled one place the values will go into data sections and we will copy from the data section into memory passing around the pointer.
101101

102102
### BooleanNode
103103
This is going to compile to a `(i32.const <value>)` with `1` for `true` and `0` for `false`.
104104

105105
### NullNode
106-
This is going to compile to a `(i32.const 0)` most likely though I need to consider this a bit more.
107-
108-
109-
#### Other Notes
110-
* We can't modify parameters so we are going to need to not allow assignments on parameters this can be done in the typechecker.
106+
This is going to compile to a `(i32.const 0)` most likely though I need to consider this a bit more.

0 commit comments

Comments
 (0)