Merge pull request #519 from dubek/fix-ruby-keyword
[jackhill/mal.git] / impls / 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 include $(_TOP_DIR)printer.mk
8
9 SHELL := /bin/bash
10 INTERACTIVE ?= yes
11
12 # READ: read and parse input
13 define READ
14 $(if $(READLINE_EOF)$(__ERROR),,$(call READ_STR,$(if $(1),$(1),$(call READLINE,"user> "))))
15 endef
16
17 # EVAL: just return the input
18 define EVAL
19 $(if $(READLINE_EOF)$(__ERROR),,$(1))
20 endef
21
22 # PRINT:
23 define PRINT
24 $(if $(__ERROR),Error: $(call _pr_str,$(__ERROR),yes),$(if $(1),$(call _pr_str,$(1),yes)))$(if $(__ERROR),$(eval __ERROR :=),)
25 endef
26
27 # REPL: read, eval, print, loop
28 REP = $(call PRINT,$(strip $(call EVAL,$(strip $(call READ,$(1))),$(REPL_ENV))))
29 REPL = $(info $(call REP,$(call READLINE,"user> ")))$(if $(READLINE_EOF),,$(call REPL))
30
31 # repl loop
32 $(if $(strip $(INTERACTIVE)),$(call REPL))