Implement heap

This commit is contained in:
rmgr 2022-04-19 08:06:02 +09:30
parent c648adedd5
commit d806b00b3f
2 changed files with 25 additions and 0 deletions

4
TODO Normal file
View File

@ -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

View File

@ -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)