39 lines
887 B
Text
39 lines
887 B
Text
make "memory (array 32 0)
|
|
|
|
to load_subleq
|
|
local "i make "i 0
|
|
local "line
|
|
make "line readlist
|
|
while [or (not empty? :line) (not list? :line)] [
|
|
foreach :line [
|
|
setitem :i :memory ?
|
|
make "i sum :i 1
|
|
]
|
|
make "line readlist
|
|
]
|
|
end
|
|
|
|
to run_subleq
|
|
make "ip 0
|
|
while [greaterequal? :ip 0] [
|
|
local "a make "a item :ip :memory
|
|
make "ip sum :ip 1
|
|
local "b make "b item :ip :memory
|
|
make "ip sum :ip 1
|
|
local "c make "c item :ip :memory
|
|
make "ip sum :ip 1
|
|
cond [
|
|
[[less? :a 0] setitem :b :memory ascii readchar ]
|
|
[[less? :b 0] type char item :a :memory ]
|
|
[else
|
|
local "av make "av item :a :memory
|
|
local "bv make "bv item :b :memory
|
|
local "diff make "diff difference :bv :av
|
|
setitem :b :memory :diff
|
|
if [lessequal? :diff 0] [make "ip :c]]]
|
|
]
|
|
end
|
|
|
|
load_subleq
|
|
run_subleq
|
|
bye
|