mirror of
https://github.com/kanaka/mal.git
synced 2024-09-21 02:27:10 +03:00
ea81a8087b
- types: low-level mapping to the implementation language. - core: functions on types that are exposed directly to mal. - printer: implementation called by pr-str, str, prn, println. - env: the environment implementation - Also, unindent all TCO while loops so that the diff of step4 and step5 are minimized.
47 lines
784 B
Bash
Executable File
47 lines
784 B
Bash
Executable File
#!/bin/bash
|
|
|
|
INTERACTIVE=${INTERACTIVE-yes}
|
|
|
|
source $(dirname $0)/reader.sh
|
|
source $(dirname $0)/printer.sh
|
|
|
|
# READ: read and parse input
|
|
READ () {
|
|
[ "${1}" ] && r="${1}" || READLINE
|
|
READ_STR "${r}"
|
|
}
|
|
|
|
# EVAL: just return the input
|
|
EVAL () {
|
|
local ast="${1}"
|
|
local env="${2}"
|
|
r=
|
|
[[ "${__ERROR}" ]] && return 1
|
|
r="${ast}"
|
|
}
|
|
|
|
# PRINT:
|
|
PRINT () {
|
|
if [[ "${__ERROR}" ]]; then
|
|
_pr_str "${__ERROR}" yes
|
|
r="Error: ${r}"
|
|
__ERROR=
|
|
else
|
|
_pr_str "${1}" yes
|
|
fi
|
|
}
|
|
|
|
# REPL: read, eval, print, loop
|
|
REP () {
|
|
READ "${1}" || return 1
|
|
EVAL "${r}"
|
|
PRINT "${r}"
|
|
}
|
|
|
|
if [[ -n "${INTERACTIVE}" ]]; then
|
|
while true; do
|
|
READLINE "user> " || exit "$?"
|
|
[[ "${r}" ]] && REP "${r}" && echo "${r}"
|
|
done
|
|
fi
|