-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
3top1a
committed
Feb 8, 2025
1 parent
2fade2b
commit db88d1e
Showing
17 changed files
with
452 additions
and
803 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,4 @@ jobs: | |
- uses: actions/checkout@v4 | ||
- uses: extractions/setup-just@v2 | ||
- name: Test | ||
run: just test | ||
run: just ci |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Alkoholiq design document | ||
|
||
Features: | ||
- Expression oriented, e.g. the return value(s) of a block can be used to assign a variable | ||
- Use S-Expression syntax | ||
- Optimizing for size and speed | ||
|
||
|
||
Limitations: | ||
- The size of all variables must be known at compile time as there is no heap | ||
|
||
Let's start from the bottom and work up to a usable language | ||
|
||
|
||
## Brainfuck | ||
|
||
It is imperative that both the generated brainfuck code and LIR code leave the stack size determenistic. | ||
|
||
Function calls can be implemented as a flag and switch case statement. | ||
See [os.bf](https://github.com/bf-enterprise-solutions/os.bf/blob/master/os.bf). | ||
|
||
|
||
For control structure design, see [bf.style](https://github.com/bf-enterprise-solutions/bf.style). | ||
For if statements, see [bottom of this gist](https://gist.github.com/roachhd/dce54bec8ba55fb17d3a). | ||
|
||
|
||
## Lower IR | ||
|
||
Brainfuck forces you to think about the memory layout before any code is written. The code gen is no different. | ||
Before any code can be generated, the LIR needs to be analyzed and a concrete memory layout generated. | ||
This step will also ensure that brainfuck can be generated. | ||
|
||
The LIR does not have a concept of functions, instead a function switch like in os.bf is implemented in LIR form. | ||
A function can be viewed as a set of instructions that has a side effect on the stack, just like a single instruction. | ||
|
||
|
||
If, else and while are implemented with `match` `case` instructions. | ||
?? Is this optimal? Might make implementation easier but runtime slower. | ||
|
||
Most operations should consume the top of the stack. | ||
Inefficiencies caused by this should be optimized in the next step. | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,5 @@ lint: | |
test: build | ||
cargo test | ||
for x in examples/*; do cargo run --release -- $x; done | ||
|
||
ci: test |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
pub mod optim; | ||
|
||
pub fn add_header(s: String) -> String { | ||
let header = format!( | ||
"[Generated by alkoholiq v{}. See https://github.com/3top1a/alkoholiq]", | ||
env!("CARGO_PKG_VERSION") | ||
); | ||
format!("{}\n{}", header, s) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/// Optimizes series of instructions that have no effect, e.g. <><> or +-+- | ||
/// TODO | ||
pub fn optimize_no_effect() {} | ||
|
||
pub fn remove_comments(bf: String) -> String { | ||
bf.chars().filter(|&c| "+-><[].,".contains(c)).collect() | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.