46 lines
671 B
Io
46 lines
671 B
Io
add_fn := method(name, action,
|
|
fns atPut(name, action)
|
|
)
|
|
|
|
add_fn("quit", block(
|
|
should_quit = true
|
|
))
|
|
|
|
add_fn("clear", block(
|
|
stack empty
|
|
))
|
|
|
|
add_fn("exec", block(
|
|
doword(pop)
|
|
))
|
|
add_fn("quote", block(
|
|
word := pop
|
|
word = "'#{word}" interpolate
|
|
push(word)
|
|
))
|
|
|
|
add_fn("exec_if_0", block(
|
|
value := pop
|
|
action := pop
|
|
if(value == 0, doword(action))
|
|
))
|
|
|
|
add_fn("peek", block(
|
|
depth := pop
|
|
push(stack at(stack size - 1 - depth))
|
|
))
|
|
add_fn("deref", block(
|
|
index := pop
|
|
push(stack at(index))
|
|
))
|
|
add_fn("write", block(
|
|
index := pop
|
|
stack atPut(index, pop)
|
|
))
|
|
add_fn("size", block(
|
|
push(stack size)
|
|
))
|
|
|
|
add_fn("read_word", block(
|
|
push(action_queue removeAt(0))
|
|
))
|