From d806b00b3f508161a168ec061c452bc7904110de Mon Sep 17 00:00:00 2001 From: rmgr Date: Tue, 19 Apr 2022 08:06:02 +0930 Subject: [PATCH] Implement heap --- TODO | 4 ++++ rforth.py | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 TODO diff --git a/TODO b/TODO new file mode 100644 index 0000000..106f59a --- /dev/null +++ b/TODO @@ -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 diff --git a/rforth.py b/rforth.py index 4715475..ebab4ee 100755 --- a/rforth.py +++ b/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)