Compare commits

...

1 Commits

Author SHA1 Message Date
4792a296d3 interpreter: minor fixes, changes to the main binary to actually interpret some source code
All checks were successful
ci/woodpecker/push/debian Pipeline was successful
ci/woodpecker/push/nix Pipeline was successful
ci/woodpecker/push/fedora Pipeline was successful
ci/woodpecker/push/publish Pipeline was successful
ci/woodpecker/cron/debian Pipeline was successful
ci/woodpecker/cron/nix Pipeline was successful
ci/woodpecker/cron/fedora Pipeline was successful
ci/woodpecker/cron/publish Pipeline was successful
2026-03-22 17:23:49 +03:00
4 changed files with 16 additions and 22 deletions

View File

@@ -1,22 +1,16 @@
let def = Parser.parse_str "(define (f)
(let ((x 5))
(if t (set! x (+ x 1)))))
(define (f)
(define (g y) (* y 2))
(or (g 5) (g 6)))
(cond
((> 1 2) 0)
((> 3 2) 3)
(t -1))";;
let ( let* ) = Result.bind;; let ( let* ) = Result.bind;;
let e =
(*let def = Parser.parse_str "(lambda () (+ x 1) (+ x 1))" in
*)
let* top = Compiler.Syntactic_ast.make (List.hd def) in
Ok (Printf.printf "%s\n" (Compiler.Syntactic_ast.print top))
let _ = match e with (* Try to interpret some test source code. *)
| Error s -> Printf.printf "%s\n" s let some_source = "(define (+ a b) b)
(+ 1 2)";;
(* I don't have any built-in functions at all rn, so we just use a dummy function *)
let bruh =
let* res = Interpreter.Main.interpret_src some_source in
match res with
| Int x -> Printf.printf "got %d as result\n" x; Ok ()
| _ -> Printf.printf "got something else\n" ; Ok ()
let _ =
match bruh with
| Error s -> Printf.printf "%s" s
| _ -> () | _ -> ()

View File

@@ -1,4 +1,4 @@
(executable (executable
(name comp) (name comp)
(public_name ollisp) (public_name ollisp)
(libraries str unix compiler)) (libraries str unix compiler interpreter))

View File

@@ -86,7 +86,7 @@ let resolve_set tbl env sym expr =
If a symbol is accessed in a lambda body, that is fine, since that computation If a symbol is accessed in a lambda body, that is fine, since that computation
is delayed, but for top-level forms that are directly executed we must be strict. is delayed, but for top-level forms that are directly executed we must be strict.
The analyze function is strict by default, until it encounters a lambda, at which This function is strict by default, until it encounters a lambda, at which
point it switches to resolving against all symbols. point it switches to resolving against all symbols.
global_tbl is a table that contains ALL defined symbols, global_tbl is a table that contains ALL defined symbols,
tbl is a table that contains symbols defined only until this point. tbl is a table that contains symbols defined only until this point.

View File

@@ -66,7 +66,7 @@ let interpret program global_syms =
let count = Compiler.Scope_analysis.SymbolTable.cardinal global_syms in let count = Compiler.Scope_analysis.SymbolTable.cardinal global_syms in
let globals : runtime_value array = Array.make count Nil in let globals : runtime_value array = Array.make count Nil in
Ok (interpret_one (Begin program) [] globals) interpret_one (Begin program) [] globals