Implement heap
This commit is contained in:
parent
c648adedd5
commit
d806b00b3f
|
@ -0,0 +1,4 @@
|
|||
Implement control stack
|
||||
On if add if to control stack, every subsequent word gets added to a string until a then or an end. On then or end, execute teh string
|
||||
|
||||
Implement BEGIN..UNTIL loops
|
21
rforth.py
21
rforth.py
|
@ -1,6 +1,8 @@
|
|||
#!/usr/bin/python3
|
||||
import argparse
|
||||
stack = []
|
||||
heap = [0] * 10
|
||||
next_heap = 0
|
||||
compiling = False
|
||||
words = {}
|
||||
word_name = ""
|
||||
|
@ -56,6 +58,12 @@ def parse_input(input_string, say_ok=True):
|
|||
_and()
|
||||
elif string == "or":
|
||||
_or()
|
||||
elif string == "!":
|
||||
store()
|
||||
elif string == "@":
|
||||
fetch()
|
||||
elif string == "heap":
|
||||
dump_heap()
|
||||
else:
|
||||
if string == ";":
|
||||
stop_compiling()
|
||||
|
@ -65,6 +73,19 @@ def parse_input(input_string, say_ok=True):
|
|||
if say_ok:
|
||||
print("ok.")
|
||||
|
||||
def dump_heap():
|
||||
print(heap)
|
||||
|
||||
def store():
|
||||
k = stack.pop(0)
|
||||
v = stack.pop(0)
|
||||
heap[k] = v
|
||||
|
||||
def fetch():
|
||||
k = stack.pop(0)
|
||||
v = heap[k]
|
||||
stack.insert(0, v)
|
||||
|
||||
def rot():
|
||||
a = stack.pop(0)
|
||||
b = stack.pop(0)
|
||||
|
|
Loading…
Reference in New Issue