Skip to content

Commit

Permalink
v0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
muqiuhan committed Aug 2, 2022
1 parent 453768a commit a08a6e4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ let () =
let stream =
if input_channel = stdin
then (
print_endline "MLisp v0.1.1 (main, Jul 31 2022, 10:48:46) [OCaml 5.0.0~alpha1]\n";
print_endline "MLisp v0.1.2 (main, Aug 2 2022, 9:52:17) [OCaml 5.0.0~alpha1]\n";
make_filestream input_channel)
else make_filestream input_channel ~file_name:Sys.argv.(1)
in
Expand Down
15 changes: 13 additions & 2 deletions lib/object.ml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ let rec pair_to_list pair =
;;

let string_of_char a_char = String.make 1 a_char

let spacesep ns = String.concat " " ns

let rec string_expr =
Expand Down Expand Up @@ -117,4 +116,16 @@ and string_object e =
| Primitive (name, _) -> "#<primitive:" ^ name ^ ">"
| Quote expr -> "'" ^ string_object expr
| Closure (_, _, _) -> "#<closure>"
;;
;;

let object_type = function
| Fixnum _ -> "int"
| Boolean _ -> "boolean"
| String _ -> "string"
| Symbol _ -> "symbol"
| Nil -> "nil"
| Pair _ -> "pair"
| Primitive _ -> "primitive"
| Quote _ -> "quote"
| Closure _ -> "closure"
;;
4 changes: 2 additions & 2 deletions lib/repl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ let print_prompt () =
;;

let print_result result =
Printf.printf "- : %s\n" result;
Printf.printf "- : %s = %s\n" (Object.object_type result) (Object.string_object result);
flush_all ();
;;

Expand All @@ -36,7 +36,7 @@ let rec repl a_stream env =
if a_stream.stdin then print_prompt ();
let ast = Ast.build_ast (Reader.read_sexpr a_stream) in
let result, env' = Eval.eval ast env in
if a_stream.stdin then print_result (Object.string_object result);
if a_stream.stdin then print_result result;
repl a_stream env'
with
| Stream.Failure -> if a_stream.stdin then print_newline () else ()
Expand Down

0 comments on commit a08a6e4

Please sign in to comment.