Skip to content

Commit

Permalink
make: trivial
Browse files Browse the repository at this point in the history
  • Loading branch information
asarhaddon authored and kanaka committed Aug 8, 2024
1 parent 446964e commit c64f6f2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 56 deletions.
4 changes: 0 additions & 4 deletions impls/make/gmsl.mk
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,4 @@ gmsl_characters += 0 1 2 3 4 5 6 7 8 9
gmsl_characters += ` ~ ! @ \# $$ % ^ & * ( ) - _ = +
gmsl_characters += { } [ ] \ : ; ' " < > , . / ? |
gmsl_pairmap = $(strip \
$(if $2$3,$(call $1,$(word 1,$2),$(word 1,$3)) \
$(call gmsl_pairmap,$1,$(wordlist 2,$(words $2),$2),$(wordlist 2,$(words $3),$3))))
endif
4 changes: 2 additions & 2 deletions impls/make/printer.mk
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ symbol_pr_str = $(_symbol_val)
keyword_pr_str = $(encoded_colon)$(_keyword_val)

string_pr_str = $(if $2\
,"$(subst $(_NL),$(ESC_N),$(rem \
)$(subst $(DQUOTE),$(ESC_DQUOTE),$(rem \
,"$(subst $(_NL),$(encoded_slash)n,$(rem \
)$(subst ",$(encoded_slash)",$(rem \
)$(subst $(encoded_slash),$(encoded_slash)$(encoded_slash),$(rem \
)$(_string_val))))"$(rem \
else \
Expand Down
56 changes: 28 additions & 28 deletions impls/make/reader.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ include $(_TOP_DIR)types.mk

READER_DEBUG ?=

_TOKEN_DELIMS := $(SEMI) $(COMMA) $(DQUOTE) $(QQUOTE) $(_SP) $(_NL) { } $(_LP) $(_RP) $(LBRACKET) $(RBRACKET)
_TOKEN_DELIMS := ; , " ` $(_SP) $(_NL) { } $(_LP) $(_RP) [ ] #`"
reader_init = $(eval __reader_temp := $(str_encode))
reader_next = $(firstword $(__reader_temp))
Expand All @@ -20,21 +20,21 @@ reader_log = $(if $(READER_DEBUG),$(info READER: $1 from $(__reader_temp)))
define READ_NUMBER
$(call reader_log,number)$(rem \
)$(if $(filter $(NUMBERS),$(reader_next))\
)$(if $(filter 0 1 2 3 4 5 6 7 8 9,$(reader_next))\
,$(reader_next)$(reader_drop)$(call READ_NUMBER))
endef
define READ_STRING
$(call reader_log,string)$(rem \
)$(if $(filter $(DQUOTE),$(reader_next))\
,$(reader_drop)$(rem \
)$(if $(filter ",$(reader_next))\
,$(reader_drop)$(rem "\
),$(if $(filter $(encoded_slash),$(reader_next))\
,$(reader_drop)$(rem \
)$(if $(filter n,$(reader_next)),$(_NL),$(reader_next))$(rem \
)$(reader_drop)$(call READ_STRING)$(rem \
),$(if $(reader_next)\
,$(reader_next)$(reader_drop)$(call READ_STRING)$(rem \
),$(call _error,Expected '$(DQUOTE)'$(COMMA) got EOF))))
),$(call _error,Expected '"'$(COMMA) got EOF))))
endef
define READ_SYMBOL
Expand All @@ -56,16 +56,16 @@ $(call reader_log,until $1)$(rem \
endef
define READ_COMMENT
$(call reader_log,read comment)$(rem \
$(call reader_log,comment)$(rem \
)$(if $(filter-out $(_NL),$(reader_next))\
,$(reader_drop)$(call READ_COMMENT))
endef
define READ_SPACES
$(call reader_log,spaces)$(rem \
)$(if $(filter $(_SP) $(_NL) $(COMMA),$(reader_next))\
,$(reader_drop)$(call READ_SPACES),$(rem \
)$(if $(filter $(SEMI),$(reader_next))\
,$(reader_drop)$(call READ_SPACES)$(rem \
),$(if $(filter ;,$(reader_next))\
,$(READ_COMMENT)))
endef
Expand All @@ -74,39 +74,39 @@ $(call reader_log,form)$(rem \
)$(READ_SPACES)$(rem \
)$(if $(filter-out undefined,$(flavor READ_FORM_$(reader_next)))\
,$(call READ_FORM_$(reader_next)$(reader_drop))$(rem \
),$(if $(reader_next)\
,$(foreach sym,$(READ_SYMBOL)\
),$(foreach sym,$(READ_SYMBOL)\
,$(if $(filter false nil true,$(sym))\
,$(__$(sym))$(rem \
),$(call _symbol,$(sym))))$(rem \
),$(call _error,expected a form, found EOF)))
),$(call _symbol,$(sym)))))
endef
READ_FORM_ = $(call _error,expected a form$(COMMA) found EOF)
# Reader macros
READ_FORM_$(ATSIGN) = $(call list,$(call _symbol,deref) $(call READ_FORM))
READ_FORM_$(SQUOTE) = $(call list,$(call _symbol,quote) $(call READ_FORM))
READ_FORM_$(QQUOTE) = $(call list,$(call _symbol,quasiquote) $(call READ_FORM))
READ_FORM_$(CARET) = $(call list,$(call _symbol,with-meta) $(foreach m,\
READ_FORM_@ = $(call list,$(call _symbol,deref) $(call READ_FORM))
READ_FORM_' = $(call list,$(call _symbol,quote) $(call READ_FORM))#'
READ_FORM_` = $(call list,$(call _symbol,quasiquote) $(call READ_FORM))#`
READ_FORM_^ = $(call list,$(call _symbol,with-meta) $(foreach m,\
$(call READ_FORM),$(call READ_FORM) $m))
READ_FORM_$(UNQUOTE) = $(call list,$(if $(filter $(ATSIGN),$(reader_next))\
READ_FORM_~ = $(call list,$(if $(filter @,$(reader_next))\
,$(reader_drop)$(call _symbol,splice-unquote)$(rem \
),$(call _symbol,unquote)) $(call READ_FORM))
# Lists, vectors and maps
# _map_new accepts a leading space, list and vector require )strip.
READ_FORM_$(LCURLY) = $(call _map_new,,$(strip $(call READ_UNTIL,$(RCURLY))))
READ_FORM_$(_LP) = $(call list,$(strip $(call READ_UNTIL,$(_RP))))
READ_FORM_$(LBRACKET) = $(call vector,$(strip $(call READ_UNTIL,$(RBRACKET))))
READ_FORM_$(RCURLY) = $(call _error,Unexpected '$(RCURLY)')
READ_FORM_$(_RP) = $(call _error,Unexpected '$(_RP)')
READ_FORM_$(RBRACKET) = $(call _error,Unexpected '$(RBRACKET)')
READ_FORM_{ = $(call _map_new,,$(strip $(call READ_UNTIL,})))
READ_FORM_$(_LP) = $(call list,$(strip $(call READ_UNTIL,$(_RP))))
READ_FORM_[ = $(call vector,$(strip $(call READ_UNTIL,])))
READ_FORM_} = $(call _error,Unexpected '}')
READ_FORM_$(_RP) = $(call _error,Unexpected '$(_RP)')
READ_FORM_] = $(call _error,Unexpected ']')
# Numbers
define READ_FORM_$(MINUS)
$(if $(filter $(NUMBERS),$(reader_next))\
,$(call _number,$(MINUS)$(READ_NUMBER))$(rem \
),$(call _symbol,$(MINUS)$(READ_SYMBOL)))
define READ_FORM_-
$(if $(filter 0 1 2 3 4 5 6 7 8 9,$(reader_next))\
,$(call _number,-$(READ_NUMBER))$(rem \
),$(call _symbol,-$(READ_SYMBOL)))
endef
READ_FORM_0 = $(call _number,0$(READ_NUMBER))
READ_FORM_1 = $(call _number,1$(READ_NUMBER))
Expand All @@ -120,7 +120,7 @@ READ_FORM_8 = $(call _number,8$(READ_NUMBER))
READ_FORM_9 = $(call _number,9$(READ_NUMBER))
# Strings
READ_FORM_$(DQUOTE) = $(call _string,$(call str_decode,$(READ_STRING)))
READ_FORM_" = $(call _string,$(call str_decode,$(READ_STRING)))#"
# Keywords
READ_FORM_$(encoded_colon) = $(call _keyword,$(READ_SYMBOL))
Expand Down
25 changes: 3 additions & 22 deletions impls/make/util.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,17 @@ encoded_slash := λ
raw_hash := \#
encoded_hash := η

SEMI := ;
COMMA := ,
COLON := :
LCURLY := {
RCURLY := }
LPAREN := (
RPAREN := )
LBRACKET := [
RBRACKET := ]
DQUOTE := "# "
SLASH := $(strip \ )
ESC_DQUOTE := $(encoded_slash)$(DQUOTE)
ESC_N := $(encoded_slash)n
SQUOTE := '# '
QQUOTE := `# `
SPACE :=
SPACE := $(SPACE) $(SPACE)
MINUS := -
NUMBERS := 0 1 2 3 4 5 6 7 8 9
UNQUOTE := ~
define NEWLINE


endef
CARET := ^
ATSIGN := @

# \u00ab
_LP := «
Expand All @@ -51,8 +36,6 @@ _SP := §
_DOL := Ş
## \u00b6
_NL := ¶
## \u00a8
###_EDQ := ¨


#
Expand Down Expand Up @@ -117,13 +100,11 @@ print = $(info $(str_decode_nospace))
_rest = $(wordlist 2,$(words $1),$1)
_rest2 = $(wordlist 3,$(words $1),$1)

# Evaluate $3 repeatedly with $k and $v set to key/value pairs from $1.
# Evaluate $2 repeatedly with $k and $v set to key/value pairs from $1.
define _foreach2
$(if $1\
,$(foreach k,$(firstword $1)\
$(foreach k,$(firstword $1)\
,$(foreach v,$(word 2,$1)\
,$(eval $2)))$(rem \
)$(call _foreach2,$(_rest2),$2))
,$(eval $2)$(call _foreach2,$(_rest2),$2)))
endef

endif

0 comments on commit c64f6f2

Please sign in to comment.