spooky/lib/spooky.ml

39 lines
1.0 KiB
OCaml
Raw Normal View History

2026-04-29 15:50:03 +00:00
module Ast = Ast
module Lexer = Lexer
module Parser = Parser
module Typechecker = Typechecker
module Generator_json = Generator_json
module Generator_c = Generator_c
2026-04-29 16:15:08 +00:00
module Module_system = Module_system
2026-04-29 15:25:15 +00:00
2026-04-29 15:50:03 +00:00
type program = Ast.program
2026-04-29 15:25:15 +00:00
2026-04-29 15:50:03 +00:00
let parse_string = Parser.parse_string
let string_of_program = Ast.string_of_program
let type_check = Typechecker.type_check
2026-04-29 16:15:08 +00:00
let load_source_with_imports = Module_system.load_source_with_imports
let parse_file path =
match load_source_with_imports path with
| Error e -> Error e
| Ok src -> parse_string src
2026-04-29 15:25:15 +00:00
let parse_and_type_check src =
match parse_string src with
2026-04-29 15:50:03 +00:00
| Error e -> Error e
2026-04-29 15:25:15 +00:00
| Ok prog ->
(match type_check prog with
2026-04-29 18:56:41 +00:00
| Ok annotated -> Ok annotated
2026-04-29 15:50:03 +00:00
| Error e -> Error ("type error: " ^ e))
2026-04-29 16:15:08 +00:00
let parse_and_type_check_file path =
match parse_file path with
| Error e -> Error e
| Ok prog ->
(match type_check prog with
2026-04-29 18:56:41 +00:00
| Ok annotated -> Ok annotated
2026-04-29 16:15:08 +00:00
| Error e -> Error ("type error: " ^ e))
2026-04-29 15:50:03 +00:00
let generate_json = Generator_json.generate
let generate_c = Generator_c.generate