diff options
| author | Joel Martin <github@martintribe.org> | 2014-04-16 23:57:50 -0500 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2014-04-16 23:57:50 -0500 |
| commit | 8cb5cda46cf3aef847ae3926dc53a5e5f87fe261 (patch) | |
| tree | 13e5b2878f19ee24272ead8a92a9cb84b33ad0e5 /bash/step3_env.sh | |
| parent | a05f7822b10ed4cdd61ed8384299a003baf1c1c6 (diff) | |
| download | mal-8cb5cda46cf3aef847ae3926dc53a5e5f87fe261.tar.gz mal-8cb5cda46cf3aef847ae3926dc53a5e5f87fe261.zip | |
All: move some fns to core. Major cleanup.
- Don't import/require core until step4.
- Define cond/or macros from step8
Diffstat (limited to 'bash/step3_env.sh')
| -rwxr-xr-x | bash/step3_env.sh | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/bash/step3_env.sh b/bash/step3_env.sh index 28106ee..f7a9e42 100755 --- a/bash/step3_env.sh +++ b/bash/step3_env.sh @@ -4,12 +4,11 @@ INTERACTIVE=${INTERACTIVE-yes} source $(dirname $0)/reader.sh source $(dirname $0)/printer.sh -source $(dirname $0)/core.sh source $(dirname $0)/env.sh # READ: read and parse input READ () { - READLINE + [ "${1}" ] && r="${1}" || READLINE READ_STR "${r}" } @@ -77,8 +76,8 @@ EVAL () { *) EVAL_AST "${ast}" "${env}" [[ "${__ERROR}" ]] && r= && return 1 local el="${r}" - first "${el}"; local f="${r}" - rest "${el}"; local args="${ANON["${r}"]}" + _first "${el}"; local f="${r}" + _rest "${el}"; local args="${ANON["${r}"]}" #echo "invoke: ${f} ${args}" eval ${f} ${args} return ;; @@ -100,16 +99,20 @@ PRINT () { ENV; REPL_ENV="${r}" REP () { r= - READ_STR "${1}" - EVAL "${r}" ${REPL_ENV} + READ "${1}" || return 1 + EVAL "${r}" "${REPL_ENV}" PRINT "${r}" } -_ref () { ENV_SET "${REPL_ENV}" "${1}" "${2}"; } -_ref "+" num_plus -_ref "-" num_minus -_ref "__STAR__" num_multiply -_ref "/" num_divide +plus () { r=$(( ${ANON["${1}"]} + ${ANON["${2}"]} )); _number "${r}"; } +minus () { r=$(( ${ANON["${1}"]} - ${ANON["${2}"]} )); _number "${r}"; } +multiply () { r=$(( ${ANON["${1}"]} * ${ANON["${2}"]} )); _number "${r}"; } +divide () { r=$(( ${ANON["${1}"]} / ${ANON["${2}"]} )); _number "${r}"; } + +ENV_SET "${REPL_ENV}" "+" plus +ENV_SET "${REPL_ENV}" "-" minus +ENV_SET "${REPL_ENV}" "__STAR__" multiply +ENV_SET "${REPL_ENV}" "/" divide if [[ -n "${INTERACTIVE}" ]]; then while true; do |
