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
|
#!/usr/bin/python3
|
||||||
import argparse
|
import argparse
|
||||||
stack = []
|
stack = []
|
||||||
heap = [0] * 10
|
heap = [0] * 20
|
||||||
next_heap = 0
|
next_heap = 0
|
||||||
compiling = False
|
compiling = False
|
||||||
words = {}
|
words = {}
|
||||||
|
@ -64,6 +64,8 @@ def parse_input(input_string, say_ok=True):
|
||||||
fetch()
|
fetch()
|
||||||
elif string == "heap":
|
elif string == "heap":
|
||||||
dump_heap()
|
dump_heap()
|
||||||
|
elif string == "alloc":
|
||||||
|
alloc()
|
||||||
else:
|
else:
|
||||||
if string == ";":
|
if string == ";":
|
||||||
stop_compiling()
|
stop_compiling()
|
||||||
|
@ -76,6 +78,12 @@ def parse_input(input_string, say_ok=True):
|
||||||
def dump_heap():
|
def dump_heap():
|
||||||
print(heap)
|
print(heap)
|
||||||
|
|
||||||
|
def alloc():
|
||||||
|
global next_heap
|
||||||
|
heap[next_heap] = 0
|
||||||
|
stack.insert(0, next_heap)
|
||||||
|
next_heap += 1
|
||||||
|
|
||||||
def store():
|
def store():
|
||||||
k = stack.pop(0)
|
k = stack.pop(0)
|
||||||
v = stack.pop(0)
|
v = stack.pop(0)
|
||||||
|
|
Loading…
Reference in New Issue