aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ocaml/Makefile14
-rw-r--r--ocaml/step2_eval.ml4
2 files changed, 10 insertions, 8 deletions
diff --git a/ocaml/Makefile b/ocaml/Makefile
index a526ecf..c905b2e 100644
--- a/ocaml/Makefile
+++ b/ocaml/Makefile
@@ -2,18 +2,20 @@ STEPS = step0_repl.ml step1_read_print.ml step2_eval.ml
MODULES = types.ml reader.ml printer.ml
LIBS = str.cma
-BINS = $(STEPS:%.ml=%)
+STEP_BINS = $(STEPS:%.ml=%)
+LAST_STEP_BIN = $(word $(words $(STEP_BINS)),$(STEP_BINS))
+MODULE_BINS = $(MODULES:%.ml=%.cmo)
-all: $(BINS) mal
+all: $(STEP_BINS) mal
-mal: $(word $(words $(BINS)),$(BINS))
+mal: $(LAST_STEP_BIN)
cp $< $@
repl: $(MODULES)
- rlwrap ocaml $(LIBS) $(MODULES:%.ml=%.cmo)
+ rlwrap ocaml $(LIBS) $(MODULE_BINS)
-$(BINS): %: %.ml $(MODULES)
+$(STEP_BINS): %: %.ml $(MODULES)
ocamlc $(LIBS) $(MODULES) $< -o $@
clean:
- rm -f $(BINS) mal *.cmi *.cmo
+ rm -f $(STEP_BINS) mal *.cmi *.cmo
diff --git a/ocaml/step2_eval.ml b/ocaml/step2_eval.ml
index 4337a11..02866eb 100644
--- a/ocaml/step2_eval.ml
+++ b/ocaml/step2_eval.ml
@@ -12,7 +12,7 @@ let num_fun f = Types.Fn
| [(Types.Int a); (Types.Int b)] -> Types.Int (f a b)
| _ -> raise (Invalid_argument "Numeric args required for this Mal builtin"))
-let env = ref (List.fold_left (fun a b -> b a) Env.empty
+let repl_env = ref (List.fold_left (fun a b -> b a) Env.empty
[ Env.add "+" (num_fun ( + ));
Env.add "-" (num_fun ( - ));
Env.add "*" (num_fun ( * ));
@@ -41,7 +41,7 @@ let rec main =
print_string "user> ";
let line = read_line () in
try
- print_endline (rep line env);
+ print_endline (rep line repl_env);
with End_of_file -> ()
| Invalid_argument x ->
output_string stderr ("Invalid_argument exception: " ^ x ^ "\n");