spice/lib/spice.ml

18 lines
555 B
OCaml

module Syn = Spice_syntax.Ast
module Lir = Spice_lower.Lir
module Code = Spice_runtime.Code
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