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
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
This commit is contained in:
32
bin/comp.ml
32
bin/comp.ml
@@ -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
|
||||||
| _ -> ()
|
| _ -> ()
|
||||||
|
|||||||
2
bin/dune
2
bin/dune
@@ -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))
|
||||||
|
|||||||
@@ -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.
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user