Tightening up the debug script.
This commit is contained in:
parent
d420f572df
commit
cf32aa8f16
78
debugger.py
78
debugger.py
|
|
@ -13,7 +13,9 @@ from joy.utils.stack import stack_to_string
|
||||||
|
|
||||||
|
|
||||||
inscribe(trace)
|
inscribe(trace)
|
||||||
|
|
||||||
dictionary = initialize()
|
dictionary = initialize()
|
||||||
|
|
||||||
defs = {}
|
defs = {}
|
||||||
default_defs(defs)
|
default_defs(defs)
|
||||||
|
|
||||||
|
|
@ -23,15 +25,22 @@ expression = text_to_expression(
|
||||||
'[dup mul]'
|
'[dup mul]'
|
||||||
'[dip dip infra dip infra dip infra]'
|
'[dip dip infra dip infra dip infra]'
|
||||||
'[[] ccons] step i'
|
'[[] 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}
|
expected_result = '[1 [2 [3 4 625 6] 7] 8]'
|
||||||
for name in ('?', 'dupdipd', 'popopop'):
|
expected_result_as_stack = text_to_expression(expected_result)
|
||||||
step_d[name] = defs[name]
|
|
||||||
|
|
||||||
def test_expr(ds):
|
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 = dictionary.copy()
|
||||||
D.update(ds)
|
D.update(ds)
|
||||||
try:
|
try:
|
||||||
|
|
@ -40,17 +49,50 @@ def test_expr(ds):
|
||||||
return err
|
return err
|
||||||
return stack_to_string(stack)
|
return stack_to_string(stack)
|
||||||
|
|
||||||
res = test_expr(step_d)
|
|
||||||
if res:
|
|
||||||
print(res)
|
|
||||||
|
|
||||||
##for def_name in defs:
|
# The problem is that it works with the built-ins:
|
||||||
## D = dictionary.copy()
|
|
||||||
## D[def_name] = defs[def_name]
|
print(test_expr({}))
|
||||||
## try:
|
|
||||||
## stack, _, d = joy((), expression, D)
|
# Results:
|
||||||
## except:
|
# [1 [2 [3 4 625 6] 7] 8]
|
||||||
## print(def_name, 'failed!')
|
#
|
||||||
## else:
|
# But not with the definitions:
|
||||||
## print(stack_to_string(stack), def_name, 'pass')
|
|
||||||
##
|
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.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue