spice/lib/spice.ml

20 lines
635 B
OCaml
Raw Normal View History

2023-11-29 18:52:16 +00:00
module Syn = Spice_syntax.Ast
2023-11-29 21:21:35 +00:00
module Code = Spice_runtime.Code
2023-11-29 21:48:24 +00:00
module Value = Spice_runtime.Value
2023-11-29 18:43:14 +00:00
exception Error of string
let failf f = Fmt.kstr (fun s -> raise (Error s)) f
2023-11-24 04:06:13 +00:00
let parse input =
let lexbuf = Lexing.from_string input ~with_positions:true in
2023-11-29 18:52:16 +00:00
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
2023-11-29 18:43:14 +00:00
let compile ast = Spice_compile.Bcc.compile ast
2023-11-29 21:50:26 +00:00
let run prog =
try Spice_runtime.Interp.run_program prog
with Spice_runtime.Interp.Runtime_error msg -> failf "runtime error: %s" msg