μscheme: added a heap (not used for now)
This commit is contained in:
parent
1866822890
commit
d5b3158ded
|
@ -1,14 +1,63 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
heap_init() {
|
||||||
|
heap_max=0
|
||||||
|
}
|
||||||
|
|
||||||
|
alloc_cons_ptr_ptr_unit() {
|
||||||
|
# args: $1 must be an heap pointer (non-negative integer)
|
||||||
|
# $2 must be an heap pointer (non-negative integer)
|
||||||
|
# input: heap_max
|
||||||
|
# output: heap_max++ heap_type_$heap_max heap_car_$heap_max heap_cdr_$heap_max
|
||||||
|
# clobbers: none
|
||||||
|
# warning: does no attempt to escape ", \, $, space and so on in any of the inputs or outputs.
|
||||||
|
|
||||||
|
# heap_max++
|
||||||
|
heap_max=$((heap_max+1))
|
||||||
|
# heap_type[heap_max] = C
|
||||||
|
eval heap_type_$heap_max=C
|
||||||
|
# heap_car[heap_max] = $1
|
||||||
|
eval heap_car_$heap_max='"'$1'"'
|
||||||
|
# heap_cdr[heap_max] = $2
|
||||||
|
eval heap_cdr_$heap_max='"'$2'"'
|
||||||
|
}
|
||||||
|
|
||||||
|
alloc_primitive_hex_unit() {
|
||||||
|
# args: $1 must be a hexadecimal string
|
||||||
|
# input: heap_max
|
||||||
|
# output: heap_max++ heap_type_$heap_max heap_value_$heap_max
|
||||||
|
# clobbers: none
|
||||||
|
# warning: does no attempt to escape ", \, $, space and so on in any of the inputs or outputs.
|
||||||
|
|
||||||
|
# heap_max++
|
||||||
|
heap_max=$((heap_max+1))
|
||||||
|
# heap_type[heap_max] = P
|
||||||
|
eval heap_type_$heap_max=P
|
||||||
|
# heap_value[heap_max] = $1
|
||||||
|
eval heap_value_$heap_max='"'$1'"'
|
||||||
|
}
|
||||||
|
|
||||||
|
car() {
|
||||||
|
eval 'printf %s "$heap_car_'$1'"'
|
||||||
|
}
|
||||||
|
|
||||||
|
cdr() {
|
||||||
|
eval 'printf %s "$heap_cdr_'$1'"'
|
||||||
|
}
|
||||||
|
|
||||||
|
value() {
|
||||||
|
eval 'printf %s "$heap_value_'$1'"'
|
||||||
|
}
|
||||||
|
|
||||||
stack_init_name_unit() {
|
stack_init_name_unit() {
|
||||||
eval "stacklast_${1}="
|
eval "stacklast_${1}=0"
|
||||||
}
|
}
|
||||||
|
|
||||||
stack_push_name_hex_unit() {
|
stack_push_name_hex_unit() {
|
||||||
# args: $1 must be an [a-z]+ name
|
# args: $1 must be an [a-z]+ name
|
||||||
# $2 must be a hexadecimal string
|
# $2 must be a hexadecimal string
|
||||||
# input: stacklast_$1
|
# input: stacklast_$1
|
||||||
# output: stacklast_$1 stack_$1_${!stacklast_$1}
|
# output: stacklast_$1 stack_$1_${!stacklast_$1+1}
|
||||||
# clobbers: stacklast
|
# clobbers: stacklast
|
||||||
# warning: does no attempt to escape ", \, $, space and so on in any of the inputs or outputs.
|
# warning: does no attempt to escape ", \, $, space and so on in any of the inputs or outputs.
|
||||||
eval stacklast='${'stacklast_${1}'}'
|
eval stacklast='${'stacklast_${1}'}'
|
||||||
|
@ -52,6 +101,11 @@ stack_peek_name_hex() {
|
||||||
stack_init_name_unit parse_stack
|
stack_init_name_unit parse_stack
|
||||||
stack_push_name_hex_unit parse ''
|
stack_push_name_hex_unit parse ''
|
||||||
|
|
||||||
|
heap_init
|
||||||
|
alloc_primitive_hex_unit "Int 42"
|
||||||
|
alloc_primitive_hex_unit "Sym toto"
|
||||||
|
alloc_cons_ptr_ptr_unit 1 $heap_max
|
||||||
|
|
||||||
printf '(+ 1 ( + 22 345 ))' | \
|
printf '(+ 1 ( + 22 345 ))' | \
|
||||||
od -v -A n -t x1 | sed -e 's/^ //' | tr ' ' \\n | (while read c; do
|
od -v -A n -t x1 | sed -e 's/^ //' | tr ' ' \\n | (while read c; do
|
||||||
case "$c" in
|
case "$c" in
|
||||||
|
@ -76,8 +130,18 @@ od -v -A n -t x1 | sed -e 's/^ //' | tr ' ' \\n | (while read c; do
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
echo stack:
|
||||||
|
|
||||||
while test "x$(stack_len_name_int parse)" != 'x0'; do
|
while test "x$(stack_len_name_int parse)" != 'x0'; do
|
||||||
stack_pop_name_result_unit parse tmp
|
stack_pop_name_result_unit parse tmp
|
||||||
echo "$tmp 0a"
|
echo "$tmp 0a"
|
||||||
done | tac | xxd -ps -r
|
done | tac | xxd -ps -r
|
||||||
|
|
||||||
|
echo heap:
|
||||||
|
|
||||||
|
for i in `seq $heap_max`; do
|
||||||
|
eval "echo $i \$heap_type_$i \$heap_car_$i \$heap_cdr_$i \$heap_value_$i"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo $(value $(cdr $heap_max))
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user