I am new to github so I do not know another way to contact you.
I like this shell script for test driving forth, without installing an compiled program.
Thanks for this software.
Here is a code that in my copy of the 0.59a bashforth version function well for save-system and load-system:
save_array_print() {
local i
local inext
local -n a=$1
inext=0
printf "a0\n"
for i in "${!a[@]}"; do
if [ "$inext" != "$i" ]; then
printf 'ao %s\n' "$i"
fi
printf 'a %s\n' "${a[i]}"
let "inext=++i"
done
}
# -----------------------------------------------------------------------------
# ------------------------------- save-system ---------------------------------
# -----------------------------------------------------------------------------
# ( a c -- )
code saveas saveas
saveas() {
local i
local inext
local len
pack
(
printf "version %s\n" "$version"
printf "wc %s\n" "$wc"
printf "dp %s\n" "$dp"
save_array_print m
save_array_print h
save_array_print hf
save_array_print x
) > $tos
tos=${s[sp--]}
}
# ( -- ) write image of system to file, file name taken from input stream
revealheader "save-system"
colon savesystem $bl $stream $saveas
# -----------------------------------------------------------------------------
# ------------------------------- load-system ---------------------------------
# -----------------------------------------------------------------------------
# ( a c -- )
code loadfrom loadfrom
function loadfrom {
local load_version
local cmd
local prg
local a
local ai
local linenr
pack
m=()
h=()
hf=()
x=()
ai=0
a=0
fname=$tos
tos=${s[sp--]}
linenr=0
while read -r line
do
prg=($line)
cmd=${prg[0]}
p1=${prg[1]}
p2=${prg[2]}
case $cmd in
version)
load_version=$p1
if [ "$load_version" != "$version" ]; then
echo "Not same Version : $load_version"
fi
;;
wc)
wc=$p1
;;
dp)
dp=$p1
;;
a0)
ai=0
let "a=++a"
;;
ao)
ai=$p1
;;
a)
case $a in
1)
m[ai++]=$p1
;;
2)
h[ai++]=$p1
;;
3)
hf[ai++]=$p1
;;
4)
x[ai++]=$p1
;;
esac
;;
hlt)
ai=0
break;
;;
esac
let "linenr=++linenr"
done < $fname
}
I am new to github so I do not know another way to contact you.
I like this shell script for test driving forth, without installing an compiled program.
Thanks for this software.
Here is a code that in my copy of the 0.59a bashforth version function well for save-system and load-system:
save_array_print() { local i local inext local -n a=$1 inext=0 printf "a0\n" for i in "${!a[@]}"; do if [ "$inext" != "$i" ]; then printf 'ao %s\n' "$i" fi printf 'a %s\n' "${a[i]}" let "inext=++i" done } # ----------------------------------------------------------------------------- # ------------------------------- save-system --------------------------------- # ----------------------------------------------------------------------------- # ( a c -- ) code saveas saveas saveas() { local i local inext local len pack ( printf "version %s\n" "$version" printf "wc %s\n" "$wc" printf "dp %s\n" "$dp" save_array_print m save_array_print h save_array_print hf save_array_print x ) > $tos tos=${s[sp--]} } # ( -- ) write image of system to file, file name taken from input stream revealheader "save-system" colon savesystem $bl $stream $saveas # ----------------------------------------------------------------------------- # ------------------------------- load-system --------------------------------- # ----------------------------------------------------------------------------- # ( a c -- ) code loadfrom loadfrom function loadfrom { local load_version local cmd local prg local a local ai local linenr pack m=() h=() hf=() x=() ai=0 a=0 fname=$tos tos=${s[sp--]} linenr=0 while read -r line do prg=($line) cmd=${prg[0]} p1=${prg[1]} p2=${prg[2]} case $cmd in version) load_version=$p1 if [ "$load_version" != "$version" ]; then echo "Not same Version : $load_version" fi ;; wc) wc=$p1 ;; dp) dp=$p1 ;; a0) ai=0 let "a=++a" ;; ao) ai=$p1 ;; a) case $a in 1) m[ai++]=$p1 ;; 2) h[ai++]=$p1 ;; 3) hf[ai++]=$p1 ;; 4) x[ai++]=$p1 ;; esac ;; hlt) ai=0 break; ;; esac let "linenr=++linenr" done < $fname }