mirror of
https://github.com/kanaka/mal.git
synced 2024-10-27 14:52:16 +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.
35 lines
781 B
Makefile
35 lines
781 B
Makefile
#
|
|
# mal (Make Lisp) Object Types and Functions
|
|
#
|
|
|
|
ifndef __mal_env_included
|
|
__mal_env_included := true
|
|
|
|
_TOP_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
|
|
include $(_TOP_DIR)types.mk
|
|
|
|
#
|
|
# ENV
|
|
#
|
|
|
|
# An ENV environment is a hash-map with an __outer__ reference to an
|
|
# outer environment
|
|
|
|
# Keys are stored as Make variables named $(env)_$(key). The outer
|
|
# environment is the content of the variable itself.
|
|
|
|
# 1: outer environment, or "" -> new environment
|
|
ENV = $(call __new_obj,env,$1)
|
|
|
|
# 1:env 2:key -> value or ""
|
|
ENV_GET = $(if $1,$(or $($1_$2),$(call ENV_GET,$($1),$2)))
|
|
|
|
# 1:env 2:key 3:value
|
|
ENV_SET = $(eval $1_$2 := $3)
|
|
|
|
# 1:env -> (encoded) keys
|
|
env_keys = $(foreach k,$(patsubst $1_%,%,$(filter $1_%,$(.VARIABLES)))\
|
|
,$(call _symbol_val,$k))
|
|
|
|
endif
|