• R/O
  • HTTP
  • SSH
  • HTTPS

Thun: Commit

Interpreter and library.


Commit MetaInfo

Révisioncf32aa8f162c5ce5acfba5674f8494504e832d83 (tree)
l'heure2021-11-29 02:22:03
AuteurSimon Forman <sforman@hush...>
CommiterSimon Forman

Message de Log

Tightening up the debug script.

Change Summary

Modification

--- a/debugger.py
+++ b/debugger.py
@@ -13,7 +13,9 @@ from joy.utils.stack import stack_to_string
1313
1414
1515 inscribe(trace)
16+
1617 dictionary = initialize()
18+
1719 defs = {}
1820 default_defs(defs)
1921
@@ -23,15 +25,22 @@ expression = text_to_expression(
2325 '[dup mul]'
2426 '[dip dip infra dip infra dip infra]'
2527 '[[] ccons] step i'
26-## '[[[] ccons] step i]'
27-## 'trace'
28+
29+ # to trace replace last line above with:
30+ # '[[[] ccons] step i]'
31+ # 'trace'
2832 )
2933
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+
3337
3438 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+ '''
3544 D = dictionary.copy()
3645 D.update(ds)
3746 try:
@@ -40,17 +49,50 @@ def test_expr(ds):
4049 return err
4150 return stack_to_string(stack)
4251
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.
Afficher sur ancien navigateur de dépôt.