Interpreter and library.
Révision | cf32aa8f162c5ce5acfba5674f8494504e832d83 (tree) |
---|---|
l'heure | 2021-11-29 02:22:03 |
Auteur | ![]() |
Commiter | Simon Forman |
Tightening up the debug script.
@@ -13,7 +13,9 @@ from joy.utils.stack import stack_to_string | ||
13 | 13 | |
14 | 14 | |
15 | 15 | inscribe(trace) |
16 | + | |
16 | 17 | dictionary = initialize() |
18 | + | |
17 | 19 | defs = {} |
18 | 20 | default_defs(defs) |
19 | 21 |
@@ -23,15 +25,22 @@ expression = text_to_expression( | ||
23 | 25 | '[dup mul]' |
24 | 26 | '[dip dip infra dip infra dip infra]' |
25 | 27 | '[[] ccons] step i' |
26 | -## '[[[] ccons] step i]' | |
27 | -## 'trace' | |
28 | + | |
29 | + # to trace replace last line above with: | |
30 | + # '[[[] ccons] step i]' | |
31 | + # 'trace' | |
28 | 32 | ) |
29 | 33 | |
30 | -step_d = {d:defs[d] for d in defs if 'step' in d} | |
31 | -for name in ('?', 'dupdipd', 'popopop'): | |
32 | - step_d[name] = defs[name] | |
34 | +expected_result = '[1 [2 [3 4 625 6] 7] 8]' | |
35 | +expected_result_as_stack = text_to_expression(expected_result) | |
36 | + | |
33 | 37 | |
34 | 38 | def test_expr(ds): |
39 | + ''' | |
40 | + Run the test expression with the defs in ds. | |
41 | + Return the resulting stack as a string or the | |
42 | + exception raised if any. | |
43 | + ''' | |
35 | 44 | D = dictionary.copy() |
36 | 45 | D.update(ds) |
37 | 46 | try: |
@@ -40,17 +49,50 @@ def test_expr(ds): | ||
40 | 49 | return err |
41 | 50 | return stack_to_string(stack) |
42 | 51 | |
43 | -res = test_expr(step_d) | |
44 | -if res: | |
45 | - print(res) | |
46 | - | |
47 | -##for def_name in defs: | |
48 | -## D = dictionary.copy() | |
49 | -## D[def_name] = defs[def_name] | |
50 | -## try: | |
51 | -## stack, _, d = joy((), expression, D) | |
52 | -## except: | |
53 | -## print(def_name, 'failed!') | |
54 | -## else: | |
55 | -## print(stack_to_string(stack), def_name, 'pass') | |
56 | -## | |
52 | + | |
53 | +# The problem is that it works with the built-ins: | |
54 | + | |
55 | +print(test_expr({})) | |
56 | + | |
57 | +# Results: | |
58 | +# [1 [2 [3 4 625 6] 7] 8] | |
59 | +# | |
60 | +# But not with the definitions: | |
61 | + | |
62 | +print(test_expr(defs)) | |
63 | + | |
64 | +# Results: | |
65 | +# not enough values to unpack (expected 2, got 0) | |
66 | +# | |
67 | +# This obviously sucks and is bad. :( | |
68 | + | |
69 | +# First, because it's easy, let's try adding single defs | |
70 | +# one-at-a-time to the dictionary and see if any one of | |
71 | +# them breaks it. | |
72 | + | |
73 | +for def_name in defs: | |
74 | + stack_str = test_expr({def_name: defs[def_name]}) | |
75 | + if stack_str != expected_result: | |
76 | + print(def_name, 'failed!') | |
77 | + print(stack_str) | |
78 | + | |
79 | +# Results: | |
80 | +# step failed! | |
81 | +# _step0 | |
82 | + | |
83 | +# Ah yes, step's definition has parts (and dependencies). | |
84 | +step_defs = { | |
85 | + d: defs[d] | |
86 | + for d in defs | |
87 | + if 'step' in d | |
88 | + } | |
89 | +for name in ('?', 'dupdipd', 'popopop'): | |
90 | + step_defs[name] = defs[name] | |
91 | +print(sorted(step_defs)) | |
92 | +print(test_expr(step_defs)) | |
93 | + | |
94 | +# Results: | |
95 | +# [1 [2 [3 4 625 6] 7] 8] | |
96 | +# | |
97 | +# So it's not step by itself, it's some combination of defintions | |
98 | +# that is causing the bug. |