Current state of mal for Clojure West lighting talk.
[jackhill/mal.git] / make / step1_read_print.mk
1 #
2 # mal (Make Lisp)
3 #
4 _TOP_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
5 include $(_TOP_DIR)types.mk
6 include $(_TOP_DIR)reader.mk
7
8 SHELL := /bin/bash
9 INTERACTIVE ?= yes
10
11 # READ: read and parse input
12 define READ
13 $(if $(READLINE_EOF)$(__ERROR),,$(call READ_STR,$(if $(1),$(1),$(call READLINE,"user> "))))
14 endef
15
16 # EVAL: just return the input
17 define EVAL
18 $(if $(READLINE_EOF)$(__ERROR),,$(1))
19 endef
20
21 # PRINT:
22 define PRINT
23 $(if $(__ERROR),Error: $(call _pr_str,$(__ERROR),yes),$(if $(1),$(call _pr_str,$(1),yes)))$(if $(__ERROR),$(eval __ERROR :=),)
24 endef
25
26 # REPL: read, eval, print, loop
27 REP = $(call PRINT,$(strip $(call EVAL,$(strip $(call READ,$(1))),$(REPL_ENV))))
28 REPL = $(info $(call REP,$(call READLINE,"user> ")))$(if $(READLINE_EOF),,$(call REPL))
29
30 # Call the read-eval-print loop
31 $(if $(strip $(INTERACTIVE)),$(call REPL))