spice/bin/main.ml

24 lines
658 B
OCaml

open Spice
let () =
Logs.set_reporter (Logs.format_reporter ());
Logs.set_level (Some Logs.Debug);
try
let ast = parse "
val two = 2
val one = 1
fun twice(x) {
fun f(x) (x - one) * two
fun g() x + one
f(g())
}
println(twice(4))
" in
Logs.debug (fun m -> m "[AST] %a" Ast.pp_modl ast);
let prog = compile ast in
Logs.debug (fun m -> Code.dump (m "[BC] %s") prog.main);
let modl = run prog in
Logs.debug (fun m -> m "[RET] %a" Value.pp modl)
with Error msg -> Logs.err (fun m -> m "%s" msg)