From cf32aa8f162c5ce5acfba5674f8494504e832d83 Mon Sep 17 00:00:00 2001 From: Simon Forman Date: Sun, 28 Nov 2021 09:22:03 -0800 Subject: [PATCH] Tightening up the debug script. --- debugger.py | 78 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 60 insertions(+), 18 deletions(-) diff --git a/debugger.py b/debugger.py index 23164b4..4a478af 100644 --- a/debugger.py +++ b/debugger.py @@ -13,7 +13,9 @@ from joy.utils.stack import stack_to_string inscribe(trace) + dictionary = initialize() + defs = {} default_defs(defs) @@ -23,15 +25,22 @@ expression = text_to_expression( '[dup mul]' '[dip dip infra dip infra dip infra]' '[[] ccons] step i' -## '[[[] ccons] step i]' -## 'trace' + + # to trace replace last line above with: + # '[[[] ccons] step i]' + # 'trace' ) -step_d = {d:defs[d] for d in defs if 'step' in d} -for name in ('?', 'dupdipd', 'popopop'): - step_d[name] = defs[name] +expected_result = '[1 [2 [3 4 625 6] 7] 8]' +expected_result_as_stack = text_to_expression(expected_result) + def test_expr(ds): + ''' + Run the test expression with the defs in ds. + Return the resulting stack as a string or the + exception raised if any. + ''' D = dictionary.copy() D.update(ds) try: @@ -40,17 +49,50 @@ def test_expr(ds): return err return stack_to_string(stack) -res = test_expr(step_d) -if res: - print(res) -##for def_name in defs: -## D = dictionary.copy() -## D[def_name] = defs[def_name] -## try: -## stack, _, d = joy((), expression, D) -## except: -## print(def_name, 'failed!') -## else: -## print(stack_to_string(stack), def_name, 'pass') -## +# The problem is that it works with the built-ins: + +print(test_expr({})) + +# Results: +# [1 [2 [3 4 625 6] 7] 8] +# +# But not with the definitions: + +print(test_expr(defs)) + +# Results: +# not enough values to unpack (expected 2, got 0) +# +# This obviously sucks and is bad. :( + +# First, because it's easy, let's try adding single defs +# one-at-a-time to the dictionary and see if any one of +# them breaks it. + +for def_name in defs: + stack_str = test_expr({def_name: defs[def_name]}) + if stack_str != expected_result: + print(def_name, 'failed!') + print(stack_str) + +# Results: +# step failed! +# _step0 + +# Ah yes, step's definition has parts (and dependencies). +step_defs = { + d: defs[d] + for d in defs + if 'step' in d + } +for name in ('?', 'dupdipd', 'popopop'): + step_defs[name] = defs[name] +print(sorted(step_defs)) +print(test_expr(step_defs)) + +# Results: +# [1 [2 [3 4 625 6] 7] 8] +# +# So it's not step by itself, it's some combination of defintions +# that is causing the bug.