Add alloc command
This commit is contained in:
parent
d806b00b3f
commit
9b90f3fa33
10
rforth.py
10
rforth.py
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/python3
|
||||
import argparse
|
||||
stack = []
|
||||
heap = [0] * 10
|
||||
heap = [0] * 20
|
||||
next_heap = 0
|
||||
compiling = False
|
||||
words = {}
|
||||
|
@ -64,6 +64,8 @@ def parse_input(input_string, say_ok=True):
|
|||
fetch()
|
||||
elif string == "heap":
|
||||
dump_heap()
|
||||
elif string == "alloc":
|
||||
alloc()
|
||||
else:
|
||||
if string == ";":
|
||||
stop_compiling()
|
||||
|
@ -76,6 +78,12 @@ def parse_input(input_string, say_ok=True):
|
|||
def dump_heap():
|
||||
print(heap)
|
||||
|
||||
def alloc():
|
||||
global next_heap
|
||||
heap[next_heap] = 0
|
||||
stack.insert(0, next_heap)
|
||||
next_heap += 1
|
||||
|
||||
def store():
|
||||
k = stack.pop(0)
|
||||
v = stack.pop(0)
|
||||
|
|
Loading…
Reference in New Issue
Block a user