2023-12-02 18:50:24 +00:00
|
|
|
module Ast = 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
|
|
|
|
|
2023-12-02 22:02:40 +00:00
|
|
|
let failf f =
|
|
|
|
Fmt.kstr (fun s -> raise (Error s)) f
|
2023-11-24 04:06:13 +00:00
|
|
|
|
|
|
|
let parse input =
|
2023-12-02 22:02:40 +00:00
|
|
|
let open Spice_syntax in
|
2023-11-24 04:06:13 +00:00
|
|
|
let lexbuf = Lexing.from_string input ~with_positions:true in
|
2023-12-02 22:02:40 +00:00
|
|
|
try
|
|
|
|
Parser.modl Lexer.read lexbuf
|
|
|
|
with
|
|
|
|
| Parser.Error -> failf "syntax error"
|
|
|
|
| Lexer.Error msg -> failf "syntax error: %s" msg
|
2023-11-29 18:43:14 +00:00
|
|
|
|
2023-11-30 03:24:51 +00:00
|
|
|
let compile ast = Spice_compile.Bcc.compile ast
|
2023-11-29 21:50:26 +00:00
|
|
|
|
|
|
|
let run prog =
|
2023-12-02 22:02:40 +00:00
|
|
|
let open Spice_runtime in
|
2023-12-02 21:06:57 +00:00
|
|
|
try
|
|
|
|
let stdlib = Value.native_lib Interp.stdlib in
|
|
|
|
Interp.run prog stdlib
|
2023-12-02 22:02:40 +00:00
|
|
|
with
|
|
|
|
| Interp.Runtime_error msg -> failf "runtime error: %s" msg
|