mirror of
https://github.com/MorizzG/MLox.git
synced 2025-12-06 04:22:41 +00:00
automatically include loxstd in default env
This commit is contained in:
parent
1e50140970
commit
0dc19b4fdf
1 changed files with 9 additions and 3 deletions
12
lib/lox.ml
12
lib/lox.ml
|
|
@ -4,14 +4,20 @@ module Error = Error
|
|||
module Expr = Expr
|
||||
module Interpreter = Interpreter
|
||||
module Lexer = Lexer
|
||||
module Loxstd = Loxstd
|
||||
module Parser = Parser
|
||||
module Stmt = Stmt
|
||||
|
||||
type lox_error = Error.lox_error
|
||||
|
||||
let make_env_with_std () =
|
||||
let env = Environment.Env.make () in
|
||||
Loxstd.init_std env;
|
||||
env
|
||||
|
||||
let run ?(env : Environment.environment option) ?(debug = false) (source : string) :
|
||||
(unit, lox_error) result =
|
||||
let env = Option.value env ~default:(Environment.Env.make ()) in
|
||||
let env = Option.value env ~default:(make_env_with_std ()) in
|
||||
let* tokens = Error.of_lexer_error (Lexer.tokenize source) in
|
||||
let () =
|
||||
if debug then
|
||||
|
|
@ -50,12 +56,12 @@ let run ?(env : Environment.environment option) ?(debug = false) (source : strin
|
|||
interpret_stmts stmts |> Error.of_runtimer_error
|
||||
|
||||
let runRepl ?(debug = false) () : unit =
|
||||
let env = Environment.Env.make () in
|
||||
let env = make_env_with_std () in
|
||||
try
|
||||
while true do
|
||||
print_string "> ";
|
||||
let line = read_line () in
|
||||
let result = run ~env ~debug line in
|
||||
Result.iter_error Error.print_error result
|
||||
Result.map_error Error.print_error result |> ignore
|
||||
done
|
||||
with End_of_file -> ()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue