Simple rust compiler with a backend targeting WebAssembly.
scanner: Converts source code into tokens.syntax: Contains language constructs.parser: Builds an abstract syntax tree (AST) from tokens.typecheck: Ensures type correctness of the AST.codegen: Generates WebAssembly code from on the AST.
- wasm-tools (by Bytecode Alliance)
- wasm-encoder for code generation.
- wasmi for the interpreter.
- helper functions.
- pretty_assertions (for colored test diffs)
- Compile and run a
.lgfile:
cargo run -- filename.lg- Run all the tests (nocapture is used for scanner test):
cargo test -- --nocapture- Every programs must have a
mainentry point function, returning anint. - Numeric types are 32-bit integers, booleans are compiled as
0or1. - Types:
intandbool. letand=body are defined by the next underneath line, at least one line break.- Everything except functions are expressions.
- Returns
3ifis_nullis true, otherwise returns3:
int main()
let is_null = true
let var = (foo(is_null, 5*2, 0-10) + 1) * 2
var = var + 2 / 2
var
end
int foo(bool null, int res1, int res2)
if null then
0
else
let boolean = if fee() then res1 else res2 end
boolean
end
end
bool fee()
(1 < 2 & 4-2 > 3) == false & true
end