Skip to content

Commit

Permalink
git reset --hard
Browse files Browse the repository at this point in the history
  • Loading branch information
3top1a committed Feb 8, 2025
1 parent 2fade2b commit db88d1e
Show file tree
Hide file tree
Showing 17 changed files with 452 additions and 803 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ jobs:
- uses: actions/checkout@v4
- uses: extractions/setup-just@v2
- name: Test
run: just test
run: just ci
44 changes: 44 additions & 0 deletions DESIGN.md
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.



2 changes: 2 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ lint:
test: build
cargo test
for x in examples/*; do cargo run --release -- $x; done

ci: test
138 changes: 0 additions & 138 deletions src/ast.rs

This file was deleted.

9 changes: 9 additions & 0 deletions src/bf/mod.rs
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)
}
7 changes: 7 additions & 0 deletions src/bf/optim.rs
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()
}
13 changes: 0 additions & 13 deletions src/codegen.rs

This file was deleted.

129 changes: 0 additions & 129 deletions src/ir.rs

This file was deleted.

Loading

0 comments on commit db88d1e

Please sign in to comment.