Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
79b01a2
feat: OpCode and VM struct
TogarashiPepper Jul 23, 2024
a9d47e9
feat: add if and else to syntax highlighting
TogarashiPepper Jul 22, 2024
d888c14
chore: increase test file size
TogarashiPepper Jul 23, 2024
7107b81
fix: lex π correctly
TogarashiPepper Jul 24, 2024
cf403ea
refactor: generate Into<KoanErrorType> with a macro
TogarashiPepper Jul 24, 2024
7ec2e5a
chore: remove unused imports
TogarashiPepper Jul 24, 2024
b1c7f60
feat: add basic ops to the vm
TogarashiPepper Jul 24, 2024
3c75c64
feat: remove hacky iter and switch to CharIndices
TogarashiPepper Jul 26, 2024
2914c63
feat(inference): add skeleton for inference architecture
TogarashiPepper Jul 27, 2024
e918ae9
feat(inference): infer binary ops and prefix ops
TogarashiPepper Jul 27, 2024
4504322
feat: state simulator struct
TogarashiPepper Jul 27, 2024
519589c
feat: rudimentary ast type inference
TogarashiPepper Jul 28, 2024
d15f85b
feat: type inference for blocks
TogarashiPepper Jul 28, 2024
e760f31
fix: undo debug print
TogarashiPepper Jul 28, 2024
4edfa50
feat: simple intrinsic call
TogarashiPepper Jul 30, 2024
17fb9bd
feat: implement most of expr's evaluation
TogarashiPepper Jul 30, 2024
608c2db
style: run formatter
TogarashiPepper Jul 30, 2024
2046408
feat: implement 'print' func
TogarashiPepper Jul 30, 2024
ce9e30a
feat: absolute value in llvm
TogarashiPepper Jul 31, 2024
18f229a
style: run rustfmt with new rules
TogarashiPepper Aug 1, 2024
d6bccae
feat: stdlib array in C and link it as module
TogarashiPepper Aug 3, 2024
9dcb3e7
feat: assert ptr nonnull in stdlib.c
TogarashiPepper Aug 3, 2024
cb4151c
feat(stdlib.c) make assert static inline
TogarashiPepper Aug 3, 2024
3ffff6c
feat(stdlib.c): static analysis
TogarashiPepper Aug 3, 2024
80de312
feat(stdlib.c): make KoanArray refcounted
TogarashiPepper Aug 3, 2024
9098283
chore: delete IR file
TogarashiPepper Aug 3, 2024
1b3a5f4
feat(stdlib.c): switch to malloc over calloc
TogarashiPepper Aug 3, 2024
2f53752
chore: typo fix
TogarashiPepper Aug 6, 2024
5587e1d
feat: array init in builder
TogarashiPepper Aug 7, 2024
7626e27
i do not know
TogarashiPepper Aug 7, 2024
1ea3057
docs: design planning in todo comment
TogarashiPepper Aug 7, 2024
f854400
ffff
TogarashiPepper Aug 10, 2024
d36633e
e
TogarashiPepper Oct 12, 2024
1d37369
feat: basic cranelift impl
TogarashiPepper Nov 24, 2024
20569f0
fix: correct linkage for stdlibf fns
TogarashiPepper Nov 24, 2024
428df97
feat: impl || and &&
TogarashiPepper Nov 24, 2024
b0fe582
feat: ban shadowing and fix typo
TogarashiPepper Dec 1, 2024
b85eaf3
big progress
TogarashiPepper Dec 27, 2024
fe9a746
feat: simple tests for type checker
TogarashiPepper Dec 28, 2024
8e26401
feat: basic compiler and vm
TogarashiPepper Feb 17, 2025
eeac8e9
feat: add and or for vm
TogarashiPepper Feb 22, 2025
4dd6ded
features :)
TogarashiPepper Feb 22, 2025
6563289
fix: correct TryFrom impl
TogarashiPepper Feb 27, 2025
ed83b5c
feat: add GetGlobal
TogarashiPepper Feb 27, 2025
ce40912
fix: correct error msg for GetGlobal
TogarashiPepper Feb 28, 2025
a30c9eb
e
TogarashiPepper Mar 14, 2025
3354b7b
block
TogarashiPepper Mar 15, 2025
cede38e
local
TogarashiPepper Mar 16, 2025
6e80424
feat: finish locals impl
TogarashiPepper Mar 17, 2025
9486d6f
remove old
TogarashiPepper Mar 17, 2025
9d69e9a
e
TogarashiPepper Mar 26, 2025
5895b12
commit
TogarashiPepper Jul 8, 2025
a14fc25
feat: function struct
TogarashiPepper Jul 10, 2025
2703498
minor function additions
TogarashiPepper Jul 12, 2025
1017857
fix: reserve slot 1 for vm use
TogarashiPepper Jul 13, 2025
de159ef
feat: test for inference
TogarashiPepper Jul 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
# Uncomment following lines if rustc isn't taking full advantage of your processor
# Commented by default for CI purposes
# [build]
# rustflags = ["-C", "target-cpu=native"]

[build]
rustflags = ["-C", "target-cpu=native"]
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
**/.DS_Store
stdlib/stdlib.ll
101 changes: 98 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[package]
name = "koan"
version = "0.1.0"
edition = "2021"
edition = "2024"

[dependencies]
rand = "0.9.1"
rustyline = { version = "14.0.0", features = ["derive"], optional = true }
syntect = { version = "5.2.0", optional = true }
thiserror = "1.0.62"
Expand All @@ -18,9 +19,14 @@ harness = false
[features]
default = ["repl"]
repl = ["dep:rustyline", "dep:syntect"]
track_clones = []

[profile.release]
codegen-units = 1
opt-level = 3
lto = "fat"
debug = 1

[build]
rustflags = ["-Z", "threads=8"]

100 changes: 85 additions & 15 deletions benches/ast.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
use criterion::{
black_box, criterion_group, criterion_main, BatchSize, Criterion,
use std::rc::Rc;

use criterion::{BatchSize, Criterion, black_box, criterion_group, criterion_main};
use koan::{
compiler::Compiler,
interpreter::IntrpCtx,
lexer::lex,
parser::{Ast, parse},
pool::ExprPool,
state::State,
value::Value,
vm::{OpCode, VM},
};
use koan::{interpreter::IntrpCtx, lexer::lex, parser::parse, state::State};
use rand::Rng;

fn twalk_initrun((ast, mut state): ((Vec<Ast>, ExprPool), State)) {
let mut ctx = IntrpCtx {
writer: vec![],
state: &mut state,
pool: &ast.1,
};

for s in ast.0 {
black_box(ctx.eval_ast(s).unwrap());
}
}

fn criterion_benchmark(c: &mut Criterion) {
let toks = lex(include_str!("../foo.koan")).unwrap();
let ast = parse(toks.clone()).unwrap();
let inp = include_str!("lexerdata.txt");

c.bench_function("ast", |b| {
b.iter_batched(
Expand All @@ -15,20 +37,68 @@ fn criterion_benchmark(c: &mut Criterion) {
)
});

c.bench_function("tree-walk interpreter", |b| {
c.bench_function("lexer", |b| {
b.iter(|| {
lex(black_box(inp)).unwrap();
});
});

c.bench_function("VM 5000x array mul", |b| {
b.iter_batched(
|| (ast.clone(), State::new()),
|(ast, mut state)| {
let mut ctx = IntrpCtx {
writer: vec![],
state: &mut state,
pool: &ast.1,
};

for s in ast.0 {
black_box(ctx.eval_ast(s).unwrap());
|| {
let mut vm = VM::new();
let mut rng = rand::rng();

let mut a1: Vec<u32> = vec![];
let mut a2: Vec<u32> = vec![];
for _ in 0..5000 {
a1.push(rng.random());
a2.push(rng.random());
}

vm.stack.push(Value::Array(Rc::new(
a1.into_iter().map(|n| Value::Num(n as f64)).collect(),
)));

vm.stack.push(Value::Array(Rc::new(
a2.into_iter().map(|n| Value::Num(n as f64)).collect(),
)));

vm.chunk.push(OpCode::Mul as u8);

vm
},
|mut vm| {
vm.run().unwrap();
},
BatchSize::SmallInput,
);
});

c.bench_function("tree-walk interpreter 1000x array mul", |b| {
b.iter_batched(
|| {
(
lex(include_str!("thousandmul.koan"))
.and_then(parse)
.unwrap(),
State::new(),
)
},
twalk_initrun,
BatchSize::SmallInput,
);
});

c.bench_function("tree-walk interpreter fib.koan", |b| {
b.iter_batched(
|| {
(
lex(include_str!("../fib.koan")).and_then(parse).unwrap(),
State::new(),
)
},
twalk_initrun,
BatchSize::SmallInput,
)
});
Expand Down
1 change: 1 addition & 0 deletions benches/lexerdata.txt

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions benches/thousandmul.koan

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion fib.koan
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fun fib(n) { if n <= 1 { n } else { fib(n - 1) + fib(n - 2) } }

print(fib(10))
print(fib(25))
Loading