Fixed a few final bugs

master
Mark 2022-10-27 21:06:07 -07:00
parent 0dae1afb61
commit 8d1abe2712
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
1 changed files with 6 additions and 23 deletions

View File

@ -1,3 +1,4 @@
from subprocess import call
from prompt_toolkit import PromptSession from prompt_toolkit import PromptSession
from prompt_toolkit.completion import WordCompleter from prompt_toolkit.completion import WordCompleter
from prompt_toolkit import print_formatted_text as printf from prompt_toolkit import print_formatted_text as printf
@ -200,10 +201,9 @@ class Macro(ExpandableEndNode):
def expand(self): def expand(self):
if self.name in macro_table: if self.name in macro_table:
return macro_table[self.name] return clone(macro_table[self.name])
else: else:
f = FreeVar(self.name) f = FreeVar(self.name)
f.set_parent(self.parent, self.parent_side) # type: ignore
return f return f
def clone(self): def clone(self):
@ -391,12 +391,9 @@ def clone(expr: Node):
if isinstance(expr, EndNode): if isinstance(expr, EndNode):
return out return out
print("cloning", expr) # We're not using a TreeWalker here because
# we need more control over our pointer when cloning.
while True: while True:
print("p", ptr)
print("o", out_ptr)
print("r", out)
if isinstance(ptr, EndNode): if isinstance(ptr, EndNode):
from_side, ptr = ptr.go_up() from_side, ptr = ptr.go_up()
_, out_ptr = out_ptr.go_up() _, out_ptr = out_ptr.go_up()
@ -423,15 +420,6 @@ def clone(expr: Node):
if ptr is expr.parent: if ptr is expr.parent:
break break
if out_ptr is None:
print("fail")
print(out_ptr)
print(out)
print(ptr, expr.parent)
print("<fail")
#return False
return out return out
def print_expr(expr) -> str: def print_expr(expr) -> str:
@ -445,8 +433,6 @@ def print_expr(expr) -> str:
out = "" out = ""
for s, n in expr: for s, n in expr:
print(out)
if isinstance(n, EndNode): if isinstance(n, EndNode):
out += n.print_value() out += n.print_value()
@ -533,7 +519,6 @@ def reduce(expr) -> tuple[bool, Node]:
reduced = False reduced = False
for s, n in expr: for s, n in expr:
if isinstance(n, Call): if isinstance(n, Call):
if s == Direction.UP: if s == Direction.UP:
@ -550,7 +535,6 @@ def reduce(expr) -> tuple[bool, Node]:
reduced = True reduced = True
break break
print("r")
return reduced, expr return reduced, expr
@ -581,9 +565,8 @@ for l in [
macro_table[n.label] = n.expr macro_table[n.label] = n.expr
print(print_expr(n)) print(print_expr(n))
else: else:
for i in range(10): for i in range(100):
r, n = reduce(n) r, n = reduce(n)
print(print_expr(n))
if not r: if not r:
break break
#print(print_expr(clone(n))) print(print_expr(n))