mirror of
https://github.com/kanaka/mal.git
synced 2024-10-05 18:08:55 +03:00
446964e734
Readability * Use implicit parameter transmission ($(_list?) instead of $(call _list?,$1), first/lastword instead of word 1/words, $1 instead of $(1). * Use an undefined $(rem) macro and some automatic stripping (if, foreach) to indent code with less calls to `strip` functions. * Name the Make macro implementing a MAL core function exactly like the function (modulo the encoding above) and simplify core_ns accordingly. * Replace empty results representing `nil` with explicit MAL values. * Implement large conditionals with a computed variable name, as already done in printer.mk. For QUASIQUOTE and EVAL, this reduces a lot the diff between steps. * Represent the reader state as an explicit global variable instead of passing the same name as argument again and again. * Merge read-atom into read-form so that the switch on first character is more visible. Encapsulation * Hide most representations into types.mk. * Implement the type as a suffix in order to avoid a conditional in _obj_type. * Implement _error with throw. * Create distinct types for keywords and macros. * Move most metadata and atom stuff from core.mk to types.mk. * Move parameter association from env to types because it hides more about the representation of functions. Representation * Encode Make special characters in all strings/keywords/symbols, so they can be used directly as spaced words and/or variable names for map keys. (The encoding adding separating characters is kept for read-string and seq). * Change representation of numbers/strings/keywords/symbols, reducing the number of Make variables. Various * Allow keyword argument for keyword core function. * Shorten time-mes,slurp,readline... * Remove obsolete stuff: * `get` and `contains?` for vectors * `count` for hash-maps * `_join` from util.mk. * `type` from core.mk. * Add a function listing env_keys for DEBUG-EVAL. * Fix some includes.
50 lines
853 B
Makefile
50 lines
853 B
Makefile
#
|
|
# mal (Make Lisp)
|
|
#
|
|
_TOP_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
|
|
include $(_TOP_DIR)readline.mk
|
|
include $(_TOP_DIR)util.mk
|
|
include $(_TOP_DIR)reader.mk
|
|
include $(_TOP_DIR)printer.mk
|
|
|
|
SHELL := /bin/bash
|
|
|
|
# READ: read and parse input
|
|
define READ
|
|
$(READ_STR)
|
|
endef
|
|
|
|
# EVAL: just return the input
|
|
define EVAL
|
|
$(if $(__ERROR)\
|
|
,,$1)
|
|
endef
|
|
|
|
|
|
# PRINT:
|
|
define PRINT
|
|
$(if $(__ERROR)\
|
|
,Error$(encoded_colon)$(_SP)$(call _pr_str,$(__ERROR),yes)$(rem \
|
|
),$(call _pr_str,$1,yes))
|
|
endef
|
|
|
|
# REPL: read, eval, print, loop
|
|
|
|
REP = $(call PRINT,$(call EVAL,$(READ)))
|
|
|
|
# The foreach does nothing when line is empty (EOF).
|
|
define REPL
|
|
$(foreach line,$(call READLINE,user>$(_SP))\
|
|
,$(eval __ERROR :=)$(rem \
|
|
)$(call print,$(call REP,$(line:ok=)))$(rem \
|
|
)$(call REPL))
|
|
endef
|
|
|
|
# repl loop
|
|
$(REPL)
|
|
|
|
# Do not complain that there is no target.
|
|
.PHONY: none
|
|
none:
|
|
@true
|