spice/lib/spice.ml

23 lines
729 B
OCaml

module Syn = Spice_syntax.Ast
module Lir = Spice_lower.Lir
module Code = Spice_runtime.Code
module Value = Spice_runtime.Value
exception Error of string
let failf f = Fmt.kstr (fun s -> raise (Error s)) f
let parse input =
let lexbuf = Lexing.from_string input ~with_positions:true in
try Spice_syntax.Parser.modl Spice_syntax.Lexer.read lexbuf with
| Spice_syntax.Parser.Error -> failf "syntax error"
| Spice_syntax.Lexer.Error msg -> failf "syntax error: %s" msg
let compile syn =
try Spice_lower.Normalize.to_anf syn
with Failure msg -> failf "compilation error: %s" msg
let run prog =
try Spice_runtime.Interp.run_program prog
with Spice_runtime.Interp.Runtime_error msg -> failf "runtime error: %s" msg