From 68b8916d63530c83ef673d68bb3351941507a64c Mon Sep 17 00:00:00 2001 From: Emin Arslan Date: Sun, 17 May 2026 20:03:38 +0300 Subject: [PATCH] repl: added a repl. currently compiles every program as a new one however. this needs to be fixed with incremental compilation --- bin/comp.ml | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/bin/comp.ml b/bin/comp.ml index 35abe85..f2690ba 100644 --- a/bin/comp.ml +++ b/bin/comp.ml @@ -2,23 +2,15 @@ let ( let* ) = Result.bind;; -(* Try to interpret some test source code. *) -let some_source = "(define (print-three a b c) - (print a) - (print b) - (print c)) - (print-three 'hello 'world 'there) - (print 'fuck)";; (* I don't have any built-in functions at all rn, so we just use a dummy function *) -let bruh = - let* vm = Compiler.Emit.compile_src some_source in + +let rec interpret_loop () = + let l = read_line () in + let* vm = Compiler.Emit.compile_src l in print_endline "=== PROGRAM DISASSEMBLY"; Vm.Types.print_instrs vm.instrs; print_endline "=== PROGRAM OUTPUT"; Vm.interpret vm; - Ok () - -let _ = match bruh with - | Ok _ -> () - | Error s -> print_endline s + interpret_loop () +let _ = interpret_loop ()