diff options
Diffstat (limited to 'make')
| -rw-r--r-- | make/core.mk | 12 | ||||
| -rw-r--r-- | make/step3_env.mk | 9 | ||||
| -rw-r--r-- | make/step4_if_fn_do.mk | 6 | ||||
| -rw-r--r-- | make/step6_file.mk | 14 | ||||
| -rw-r--r-- | make/step7_quote.mk | 14 | ||||
| -rw-r--r-- | make/step8_macros.mk | 16 | ||||
| -rw-r--r-- | make/step9_interop.mk | 16 | ||||
| -rw-r--r-- | make/stepA_more.mk | 17 |
8 files changed, 37 insertions, 67 deletions
diff --git a/make/core.mk b/make/core.mk index fbea5ea..80f51ac 100644 --- a/make/core.mk +++ b/make/core.mk @@ -8,6 +8,8 @@ __mal_core_included := true _TOP_DIR := $(dir $(lastword $(MAKEFILE_LIST))) include $(_TOP_DIR)util.mk include $(_TOP_DIR)types.mk +include $(_TOP_DIR)readline.mk +include $(_TOP_DIR)reader.mk include $(_TOP_DIR)printer.mk @@ -49,12 +51,16 @@ number_divide = $(call _pnumber,$(call int_divide,$($(word 1,$(1))_value),$($(wo # String functions +string? = $(if $(call _string?,$(1)),$(__true),$(__false)) + pr_str = $(call _string,$(call _pr_str_mult,$(1),yes, )) str = $(call _string,$(call _pr_str_mult,$(1),,)) prn = $(info $(call _pr_str_mult,$(1),yes, )) println = $(info $(subst \n,$(NEWLINE),$(call _pr_str_mult,$(1),, ))) -string? = $(if $(call _string?,$(1)),$(__true),$(__false)) +readline= $(foreach res,$(call _string,$(call READLINE,"$(call str_decode,$($(1)_value))")),$(if $(READLINE_EOF),$(__nil),$(res))) +read_str= $(call READ_STR,$(1)) +slurp = $(call _string,$(call _read_file,$(call str_decode,$($(1)_value)))) subs = $(strip \ $(foreach start,$(call gmsl_plus,1,$(call int_decode,$($(word 2,$(1))_value))),\ @@ -205,10 +211,14 @@ core_ns = type obj_type \ symbol? symbol? \ function? function? \ string? string? \ + \ pr-str pr_str \ str str \ prn prn \ println println \ + readline readline \ + read-string read_str \ + slurp slurp \ subs subs \ number? number? \ < number_lt \ diff --git a/make/step3_env.mk b/make/step3_env.mk index 7c505cf..acc038d 100644 --- a/make/step3_env.mk +++ b/make/step3_env.mk @@ -86,11 +86,10 @@ REP = $(call PRINT,$(strip $(call EVAL,$(strip $(call READ,$(1))),$(REPL_ENV)))) REPL = $(info $(call REP,$(call READLINE,"user> ")))$(if $(READLINE_EOF),,$(call REPL)) # Setup the environment -_ref = $(eval REPL_ENV := $(call ENV_SET,$(REPL_ENV),$(1),$(if $(2),$(2),$(1)))) -$(call _ref,+,number_plus) -$(call _ref,-,number_subtract) -$(call _ref,*,number_multiply) -$(call _ref,/,number_divide) +REPL_ENV := $(call ENV_SET,$(REPL_ENV),+,number_plus) +REPL_ENV := $(call ENV_SET,$(REPL_ENV),-,number_subtract) +REPL_ENV := $(call ENV_SET,$(REPL_ENV),*,number_multiply) +REPL_ENV := $(call ENV_SET,$(REPL_ENV),/,number_divide) # Call the read-eval-print loop $(if $(strip $(INTERACTIVE)),$(call REPL)) diff --git a/make/step4_if_fn_do.mk b/make/step4_if_fn_do.mk index f45cfa9..13dcf1c 100644 --- a/make/step4_if_fn_do.mk +++ b/make/step4_if_fn_do.mk @@ -101,14 +101,12 @@ REPL_ENV := $(call ENV) REP = $(call PRINT,$(strip $(call EVAL,$(strip $(call READ,$(1))),$(REPL_ENV)))) REPL = $(info $(call REP,$(call READLINE,"user> ")))$(if $(READLINE_EOF),,$(call REPL)) -# Setup the environment +# core.mk: defined using Make _fref = $(eval REPL_ENV := $(call ENV_SET,$(REPL_ENV),$(1),$(call _function,$$(call $(2),$$1)))) - -# Import core namespace _import_core = $(if $(strip $(1)),$(call _fref,$(word 1,$(1)),$(word 2,$(1)))$(call _import_core,$(wordlist 3,$(words $(1)),$(1))),) $(call _import_core,$(core_ns)) -# Defined in terms of the language itself +# core.mal: defined in terms of the language itself $(call do,$(call REP, (def! not (fn* (a) (if a false true))) )) # Call the read-eval-print loop diff --git a/make/step6_file.mk b/make/step6_file.mk index c791b33..494cbb2 100644 --- a/make/step6_file.mk +++ b/make/step6_file.mk @@ -101,21 +101,13 @@ REPL_ENV := $(call ENV) REP = $(call PRINT,$(strip $(call EVAL,$(strip $(call READ,$(1))),$(REPL_ENV)))) REPL = $(info $(call REP,$(call READLINE,"user> ")))$(if $(READLINE_EOF),,$(call REPL)) -# Setup the environment -_ref = $(eval REPL_ENV := $(call ENV_SET,$(REPL_ENV),$(1),$(if $(2),$(2),$(1)))) +# core.mk: defined using Make _fref = $(eval REPL_ENV := $(call ENV_SET,$(REPL_ENV),$(1),$(call _function,$$(call $(2),$$1)))) - -# Import core namespace _import_core = $(if $(strip $(1)),$(call _fref,$(word 1,$(1)),$(word 2,$(1)))$(call _import_core,$(wordlist 3,$(words $(1)),$(1))),) $(call _import_core,$(core_ns)) +REPL_ENV := $(call ENV_SET,$(REPL_ENV),eval,$(call _function,$$(call EVAL,$$(1),$$(REPL_ENV)))) -$(call _ref,read-string,$(call _function,$$(call READ_STR,$$(1)))) -$(call _ref,eval,$(call _function,$$(call EVAL,$$(1),$$(REPL_ENV)))) - -_slurp = $(call _string,$(call _read_file,$(1))) -$(call _ref,slurp,$(call _function,$$(call _slurp,$$(call str_decode,$$($$(1)_value))))) - -# Defined in terms of the language itself +# core.mal: defined in terms of the language itself $(call do,$(call REP, (def! not (fn* (a) (if a false true))) )) $(call do,$(call REP, (def! load-file (fn* (f) (eval (read-string (str "(do " (slurp f) ")"))))) )) diff --git a/make/step7_quote.mk b/make/step7_quote.mk index 46e5130..af14e85 100644 --- a/make/step7_quote.mk +++ b/make/step7_quote.mk @@ -118,21 +118,13 @@ REPL_ENV := $(call ENV) REP = $(call PRINT,$(strip $(call EVAL,$(strip $(call READ,$(1))),$(REPL_ENV)))) REPL = $(info $(call REP,$(call READLINE,"user> ")))$(if $(READLINE_EOF),,$(call REPL)) -# Setup the environment -_ref = $(eval REPL_ENV := $(call ENV_SET,$(REPL_ENV),$(1),$(if $(2),$(2),$(1)))) +# core.mk: defined using Make _fref = $(eval REPL_ENV := $(call ENV_SET,$(REPL_ENV),$(1),$(call _function,$$(call $(2),$$1)))) - -# Import core namespace _import_core = $(if $(strip $(1)),$(call _fref,$(word 1,$(1)),$(word 2,$(1)))$(call _import_core,$(wordlist 3,$(words $(1)),$(1))),) $(call _import_core,$(core_ns)) +REPL_ENV := $(call ENV_SET,$(REPL_ENV),eval,$(call _function,$$(call EVAL,$$(1),$$(REPL_ENV)))) -$(call _ref,read-string,$(call _function,$$(call READ_STR,$$(1)))) -$(call _ref,eval,$(call _function,$$(call EVAL,$$(1),$$(REPL_ENV)))) - -_slurp = $(call _string,$(call _read_file,$(1))) -$(call _ref,slurp,$(call _function,$$(call _slurp,$$(call str_decode,$$($$(1)_value))))) - -# Defined in terms of the language itself +# core.mal: defined in terms of the language itself $(call do,$(call REP, (def! not (fn* (a) (if a false true))) )) $(call do,$(call REP, (def! load-file (fn* (f) (eval (read-string (str "(do " (slurp f) ")"))))) )) diff --git a/make/step8_macros.mk b/make/step8_macros.mk index fee4bb0..8ed5df8 100644 --- a/make/step8_macros.mk +++ b/make/step8_macros.mk @@ -141,23 +141,17 @@ REPL_ENV := $(call ENV) REP = $(call PRINT,$(strip $(call EVAL,$(strip $(call READ,$(1))),$(REPL_ENV)))) REPL = $(info $(call REP,$(call READLINE,"user> ")))$(if $(READLINE_EOF),,$(call REPL)) -# Setup the environment -_ref = $(eval REPL_ENV := $(call ENV_SET,$(REPL_ENV),$(1),$(if $(2),$(2),$(1)))) +# core.mk: defined using Make _fref = $(eval REPL_ENV := $(call ENV_SET,$(REPL_ENV),$(1),$(call _function,$$(call $(2),$$1)))) - -# Import core namespace _import_core = $(if $(strip $(1)),$(call _fref,$(word 1,$(1)),$(word 2,$(1)))$(call _import_core,$(wordlist 3,$(words $(1)),$(1))),) $(call _import_core,$(core_ns)) +REPL_ENV := $(call ENV_SET,$(REPL_ENV),eval,$(call _function,$$(call EVAL,$$(1),$$(REPL_ENV)))) -$(call _ref,read-string,$(call _function,$$(call READ_STR,$$(1)))) -$(call _ref,eval,$(call _function,$$(call EVAL,$$(1),$$(REPL_ENV)))) - -_slurp = $(call _string,$(call _read_file,$(1))) -$(call _ref,slurp,$(call _function,$$(call _slurp,$$(call str_decode,$$($$(1)_value))))) - -# Defined in terms of the language itself +# core.mal: defined in terms of the language itself $(call do,$(call REP, (def! not (fn* (a) (if a false true))) )) $(call do,$(call REP, (def! load-file (fn* (f) (eval (read-string (str "(do " (slurp f) ")"))))) )) +$(call do,$(call REP, (defmacro! cond (fn* (& xs) (if (> (count xs) 0) (list 'if (first xs) (if (> (count xs) 1) (nth xs 1) (throw "odd number of forms to cond")) (cons 'cond (rest (rest xs))))))) )) +$(call do,$(call REP, (defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs)))))))) )) # Load and eval any files specified on the command line $(if $(MAKECMDGOALS),\ diff --git a/make/step9_interop.mk b/make/step9_interop.mk index 4b7eaff..8c9220c 100644 --- a/make/step9_interop.mk +++ b/make/step9_interop.mk @@ -145,23 +145,17 @@ REPL_ENV := $(call ENV) REP = $(call PRINT,$(strip $(call EVAL,$(strip $(call READ,$(1))),$(REPL_ENV)))) REPL = $(info $(call REP,$(call READLINE,"user> ")))$(if $(READLINE_EOF),,$(call REPL)) -# Setup the environment -_ref = $(eval REPL_ENV := $(call ENV_SET,$(REPL_ENV),$(1),$(if $(2),$(2),$(1)))) +# core.mk: defined using Make _fref = $(eval REPL_ENV := $(call ENV_SET,$(REPL_ENV),$(1),$(call _function,$$(call $(2),$$1)))) - -# Import core namespace _import_core = $(if $(strip $(1)),$(call _fref,$(word 1,$(1)),$(word 2,$(1)))$(call _import_core,$(wordlist 3,$(words $(1)),$(1))),) $(call _import_core,$(core_ns)) +REPL_ENV := $(call ENV_SET,$(REPL_ENV),eval,$(call _function,$$(call EVAL,$$(1),$$(REPL_ENV)))) -$(call _ref,read-string,$(call _function,$$(call READ_STR,$$(1)))) -$(call _ref,eval,$(call _function,$$(call EVAL,$$(1),$$(REPL_ENV)))) - -_slurp = $(call _string,$(call _read_file,$(1))) -$(call _ref,slurp,$(call _function,$$(call _slurp,$$(call str_decode,$$($$(1)_value))))) - -# Defined in terms of the language itself +# core.mal: defined in terms of the language itself $(call do,$(call REP, (def! not (fn* (a) (if a false true))) )) $(call do,$(call REP, (def! load-file (fn* (f) (eval (read-string (str "(do " (slurp f) ")"))))) )) +$(call do,$(call REP, (defmacro! cond (fn* (& xs) (if (> (count xs) 0) (list 'if (first xs) (if (> (count xs) 1) (nth xs 1) (throw "odd number of forms to cond")) (cons 'cond (rest (rest xs))))))) )) +$(call do,$(call REP, (defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs)))))))) )) # Load and eval any files specified on the command line $(if $(MAKECMDGOALS),\ diff --git a/make/stepA_more.mk b/make/stepA_more.mk index 3cd0d2a..00ae252 100644 --- a/make/stepA_more.mk +++ b/make/stepA_more.mk @@ -160,26 +160,17 @@ REPL_ENV := $(call ENV) REP = $(call PRINT,$(strip $(call EVAL,$(strip $(call READ,$(1))),$(REPL_ENV)))) REPL = $(info $(call REP,$(call READLINE,"user> ")))$(if $(READLINE_EOF),,$(call REPL)) -# Setup the environment -_ref = $(eval REPL_ENV := $(call ENV_SET,$(REPL_ENV),$(1),$(if $(2),$(2),$(1)))) +# core.mk: defined using Make _fref = $(eval REPL_ENV := $(call ENV_SET,$(REPL_ENV),$(1),$(call _function,$$(call $(2),$$1)))) - -# Import core namespace _import_core = $(if $(strip $(1)),$(call _fref,$(word 1,$(1)),$(word 2,$(1)))$(call _import_core,$(wordlist 3,$(words $(1)),$(1))),) $(call _import_core,$(core_ns)) +REPL_ENV := $(call ENV_SET,$(REPL_ENV),eval,$(call _function,$$(call EVAL,$$(1),$$(REPL_ENV)))) -$(call _ref,readline,$(call _function,$$(foreach res,$$(call _string,$$(call READLINE,"$$(call str_decode,$$($$(1)_value))")),$$(if $$(READLINE_EOF),$$(__nil),$$(res))))) -$(call _ref,read-string,$(call _function,$$(call READ_STR,$$(1)))) -$(call _ref,eval,$(call _function,$$(call EVAL,$$(1),$$(REPL_ENV)))) - -_slurp = $(call _string,$(call _read_file,$(1))) -$(call _ref,slurp,$(call _function,$$(call _slurp,$$(call str_decode,$$($$(1)_value))))) - -# Defined in terms of the language itself +# core.mal: defined in terms of the language itself $(call do,$(call REP, (def! not (fn* (a) (if a false true))) )) +$(call do,$(call REP, (def! load-file (fn* (f) (eval (read-string (str "(do " (slurp f) ")"))))) )) $(call do,$(call REP, (defmacro! cond (fn* (& xs) (if (> (count xs) 0) (list 'if (first xs) (if (> (count xs) 1) (nth xs 1) (throw "odd number of forms to cond")) (cons 'cond (rest (rest xs))))))) )) $(call do,$(call REP, (defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs)))))))) )) -$(call do,$(call REP, (def! load-file (fn* (f) (eval (read-string (str "(do " (slurp f) ")"))))) )) # Load and eval any files specified on the command line $(if $(MAKECMDGOALS),\ |
