Wap: an Oberon-level language on shrubbery notation, compiled through the Wax AST
Dependencies
module sieve
type flags = [bool]
export "count_primes" fn count(n :: u32) -> u32:
if n < 2:
return 0
var marked = flags[false ** (n + 1)]
var total = 0
for i in 2 .. n:
if marked[i]:
continue
total += 1
var j = i * i
while j <= n:
marked[j] = true
j += i
totalfn a(x :: i32, y :: i32) -> i32: x / y // i32.div_s
fn b(x :: u32, y :: u32) -> u32: x / y // i32.div_ufn c(x :: i64) -> f64: x as f64_s // f64.convert_i64_s
fn d(x :: f64) -> i32: x as i32_s // i32.trunc_sat_f64_smodule app
import geometry
import collections.hashing
export "run" fn run() -> i32:
let p = geometry.make(3, 4) // `geometry.make` must be `pub`
geometry.dot(p, p)All names use pv_/pvt_ prefixes because Wax has no source namespaces.
moon add marianoguerra/wap@wap.compile_string(src) // -> Result[Bytes, Diagnostics]
@wap.compile_string_to_wat(src) // the same lowering, printed
@wap.to_wax(src) // stop at the Wax ASTlet loader = @resolve.MapLoader::new(entries=[("collections.hashing", src)])
@wap.compile_program("app", entry_src, loader)struct Files {
root : String
}
impl @resolve.Loader for Files with load(self, path) {
read_file(self.root + "/" + path.replace_all(old=".", new="/") + ".wap")
}let m : @wap_ast.Module = {
name: "gen",
decls: [
Fn({
name: "mul",
receiver: None,
params: [
{ name: "x", typ: I32, span: @wap_ast.nowhere },
{ name: "y", typ: I32, span: @wap_ast.nowhere },
],
results: [I32],
body: Some([{ it: Bin(Mul, x, y), span: @wap_ast.nowhere }]),
export_name: Some("mul"),
import_name: None,
is_start: false,
span: @wap_ast.nowhere,
}),
],
}
let fields = @lower.lower_module(m).fields() // Wax AST, ready to check| package | what |
|---|---|
| marianoguerra/wap | the facade: source to Wax AST, wasm or wat |
| marianoguerra/wap/ast | the AST. Depends on error-report and nothing else |
| marianoguerra/wap/parse | shrubbery notation to wap AST |
| marianoguerra/wap/lower | wap AST to Wax AST |
| marianoguerra/wap/resolve | Loader, and the import walk over it |
moon check --deny-warn
moon test
moon info --target all # regenerate .mbti
moon fmtfn check_string(src : String, fname? : String, features? : Set, policy? : Policy) -> Result[(Checked, Module), Diagnostics]fn compile_program(path : String, src : String, loader : &Loader, features? : Set, policy? : Policy) -> Result[Bytes, Diagnostics] raise CompileErrorfn compile_program_to_wat(path : String, src : String, loader : &Loader, features? : Set, policy? : Policy) -> Result[String, Diagnostics] raise CompileErrorfn compile_string(src : String, fname? : String, features? : Set, policy? : Policy) -> Result[Bytes, Diagnostics] raise CompileErrorfn compile_string_to_wat(src : String, fname? : String, features? : Set, policy? : Policy) -> Result[String, Diagnostics] raise CompileErrorInstall
Download zipWap: an Oberon-level language on shrubbery notation, compiled through the Wax AST
Dependencies