aboutsummaryrefslogtreecommitdiff
path: root/bash
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-10-09 23:48:47 -0500
committerJoel Martin <github@martintribe.org>2015-01-06 21:57:24 -0600
commit01c9731649a7ed97fad0bdeac9cb75b7323c0ad6 (patch)
treed6d00e574c489b206ddf78adc12c3d535bab7440 /bash
parent1771ab50b87c745181e4e30f94b63e3f23d33dac (diff)
downloadmal-01c9731649a7ed97fad0bdeac9cb75b7323c0ad6.tar.gz
mal-01c9731649a7ed97fad0bdeac9cb75b7323c0ad6.zip
All: swap step9,A. Fixes for bash, C, perl.
step9_interop -> stepA_interop stepA_more -> step9_try C: fix glib headers bash: behavior change of declare -A and pattern replacement. perl: squelch new 5.18 warnings related to switch/given statement. Also, include some in-progress interop related files.
Diffstat (limited to 'bash')
-rw-r--r--bash/Makefile2
-rwxr-xr-xbash/step9_try.sh (renamed from bash/step9_interop.sh)22
-rwxr-xr-xbash/stepA_interop.sh (renamed from bash/stepA_more.sh)0
-rw-r--r--bash/tests/stepA_interop.mal (renamed from bash/tests/step9_interop.mal)0
-rw-r--r--bash/types.sh6
5 files changed, 19 insertions, 11 deletions
diff --git a/bash/Makefile b/bash/Makefile
index e171f69..df663b5 100644
--- a/bash/Makefile
+++ b/bash/Makefile
@@ -1,5 +1,5 @@
SOURCES_BASE = types.sh reader.sh printer.sh
-SOURCES_LISP = env.sh core.sh stepA_more.sh
+SOURCES_LISP = env.sh core.sh stepA_interop.sh
SOURCES = $(SOURCES_BASE) $(SOURCES_LISP)
all: mal.sh
diff --git a/bash/step9_interop.sh b/bash/step9_try.sh
index ec8d6eb..db0b5a7 100755
--- a/bash/step9_interop.sh
+++ b/bash/step9_try.sh
@@ -157,14 +157,20 @@ EVAL () {
macroexpand)
MACROEXPAND "${a1}" "${env}"
return ;;
- sh*) MACROEXPAND "${a1}" "${env}"
+ try*) MACROEXPAND "${a1}" "${env}"
EVAL "${r}" "${env}"
- local output=""
- local line=""
- while read line; do
- output="${output}${line}\n"
- done < <(eval ${ANON["${r}"]})
- _string "${output%\\n}"
+ [[ -z "${__ERROR}" ]] && return
+ _nth "${a2}" 0; local a20="${r}"
+ if [ "${ANON["${a20}"]}" == "catch__STAR__" ]; then
+ _nth "${a2}" 1; local a21="${r}"
+ _nth "${a2}" 2; local a22="${r}"
+ _list "${a21}"; local binds="${r}"
+ ENV "${env}" "${binds}" "${__ERROR}"
+ local try_env="${r}"
+ __ERROR=
+ MACROEXPAND "${a22}" "${try_env}"
+ EVAL "${r}" "${try_env}"
+ fi # if no catch* clause, just propagate __ERROR
return ;;
do) _count "${ast}"
_slice "${ast}" 1 $(( ${r} - 2 ))
@@ -245,6 +251,7 @@ for _arg in "${@:2}"; do _string "${_arg}"; _conj! "${argv}" "${r}"; done
ENV_SET "${REPL_ENV}" "__STAR__ARGV__STAR__" "${argv}";
# core.mal: defined using the language itself
+REP "(def! *host-language* \"bash\")"
REP "(def! not (fn* (a) (if a false true)))"
REP "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))"
REP "(defmacro! cond (fn* (& xs) (if (> (count xs) 0) (list 'if (first xs) (if (> (count xs) 1) (nth xs 1) (throw \"odd number of forms to cond\")) (cons 'cond (rest (rest xs)))))))"
@@ -257,6 +264,7 @@ if [[ "${1}" ]]; then
fi
# repl loop
+REP "(println (str \"Mal [\" *host-language* \"]\"))"
while true; do
READLINE "user> " || exit "$?"
[[ "${r}" ]] && REP "${r}" && echo "${r}"
diff --git a/bash/stepA_more.sh b/bash/stepA_interop.sh
index 2422643..2422643 100755
--- a/bash/stepA_more.sh
+++ b/bash/stepA_interop.sh
diff --git a/bash/tests/step9_interop.mal b/bash/tests/stepA_interop.mal
index bf3eabd..bf3eabd 100644
--- a/bash/tests/step9_interop.mal
+++ b/bash/tests/stepA_interop.mal
diff --git a/bash/types.sh b/bash/types.sh
index 6781492..5cdc14a 100644
--- a/bash/types.sh
+++ b/bash/types.sh
@@ -104,7 +104,7 @@ _false? () { [[ ${1} =~ ^fals_ ]]; }
_symbol () {
__new_obj_hash_code
r="symb_${r}"
- ANON["${r}"]="${1//$'\*'/__STAR__}"
+ ANON["${r}"]="${1//\*/__STAR__}"
}
_symbol? () { [[ ${1} =~ ^symb_ ]]; }
@@ -124,7 +124,7 @@ _number? () { [[ ${1} =~ ^numb_ ]]; }
_string () {
__new_obj_hash_code
r="strn_${r}"
- ANON["${r}"]="${1//$'\*'/__STAR__}"
+ ANON["${r}"]="${1//\*/__STAR__}"
}
_string? () { [[ ${1} =~ ^strn_ ]]; }
@@ -173,7 +173,7 @@ _hash_map () {
__new_obj_hash_code
local name="hmap_${r}"
local obj="${__obj_magic}_${name}"
- declare -A -g ${obj}
+ declare -A -g ${obj}; eval "${obj}=()"
ANON["${name}"]="${obj}"
while [[ "${1}" ]]; do