Add some logging.
This commit is contained in:
parent
3c27fab071
commit
1e8c196c5b
|
|
@ -7,11 +7,21 @@ Joypy - Copyright © 2018 Simon Forman
|
||||||
' This is free software, and you are welcome to redistribute it under certain conditions;'
|
' This is free software, and you are welcome to redistribute it under certain conditions;'
|
||||||
' right-click "sharing" for details.'
|
' right-click "sharing" for details.'
|
||||||
' Right-click on these commands to see docs on UI commands: key_bindings mouse_bindings')
|
' Right-click on these commands to see docs on UI commands: key_bindings mouse_bindings')
|
||||||
import os, pickle, sys
|
import logging, os, pickle, sys
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
|
|
||||||
from joy.gui.textwidget import TextViewerWidget, tk, get_font, TEXT_BINDINGS
|
|
||||||
from joy.gui.utils import init_home, FileFaker
|
from joy.gui.utils import init_home, FileFaker
|
||||||
|
|
||||||
|
JOY_HOME, repo = init_home()
|
||||||
|
|
||||||
|
logging.basicConfig(
|
||||||
|
format='%(asctime)-15s %(levelname)s %(name)s %(message)s',
|
||||||
|
filename=os.path.join(JOY_HOME, 'thun.log'),
|
||||||
|
level=logging.INFO,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
from joy.gui.textwidget import TextViewerWidget, tk, get_font, TEXT_BINDINGS
|
||||||
from joy.gui.world import StackDisplayWorld
|
from joy.gui.world import StackDisplayWorld
|
||||||
from joy.library import initialize
|
from joy.library import initialize
|
||||||
from joy.utils.stack import stack_to_string
|
from joy.utils.stack import stack_to_string
|
||||||
|
|
@ -101,7 +111,6 @@ def grand_reset(s, e, d):
|
||||||
return stack, e, d
|
return stack, e, d
|
||||||
|
|
||||||
|
|
||||||
JOY_HOME, repo = init_home()
|
|
||||||
STACK_FN = os.path.join(JOY_HOME, 'stack.pickle')
|
STACK_FN = os.path.join(JOY_HOME, 'stack.pickle')
|
||||||
REL_STACK_FN = repo_relative_path(STACK_FN)
|
REL_STACK_FN = repo_relative_path(STACK_FN)
|
||||||
JOY_FN = os.path.join(JOY_HOME, 'scratch.txt')
|
JOY_FN = os.path.join(JOY_HOME, 'scratch.txt')
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,12 @@ _log = getLogger(__name__)
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
from itertools import imap, chain, product
|
from itertools import imap, chain, product
|
||||||
from inspect import stack as inspect_stack
|
from inspect import stack as inspect_stack
|
||||||
from joy.utils.stack import concat, expression_to_string, list_to_stack
|
from joy.utils.stack import (
|
||||||
|
concat,
|
||||||
|
expression_to_string,
|
||||||
|
list_to_stack,
|
||||||
|
stack_to_string,
|
||||||
|
)
|
||||||
from joy.parser import Symbol, text_to_expression
|
from joy.parser import Symbol, text_to_expression
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -222,6 +227,8 @@ def relabel(left, right):
|
||||||
|
|
||||||
|
|
||||||
def _1000(right):
|
def _1000(right):
|
||||||
|
if isinstance(right, Symbol):
|
||||||
|
return right
|
||||||
if not isinstance(right, tuple):
|
if not isinstance(right, tuple):
|
||||||
return 1000 + right
|
return 1000 + right
|
||||||
return tuple(_1000(n) for n in right)
|
return tuple(_1000(n) for n in right)
|
||||||
|
|
@ -539,7 +546,8 @@ ID = _S0, _S0 # Identity function.
|
||||||
|
|
||||||
|
|
||||||
def _infer(e, F=ID):
|
def _infer(e, F=ID):
|
||||||
_log_it(e, F)
|
if __debug__:
|
||||||
|
_log_it(e, F)
|
||||||
if not e:
|
if not e:
|
||||||
return [F]
|
return [F]
|
||||||
|
|
||||||
|
|
@ -577,7 +585,7 @@ def _interpret(f, fi, fo, e):
|
||||||
|
|
||||||
|
|
||||||
def _log_it(e, F):
|
def _log_it(e, F):
|
||||||
_log.info(
|
_log.debug(
|
||||||
u'%3i %s ∘ %s',
|
u'%3i %s ∘ %s',
|
||||||
len(inspect_stack()),
|
len(inspect_stack()),
|
||||||
doc_from_stack_effect(*F),
|
doc_from_stack_effect(*F),
|
||||||
|
|
@ -614,25 +622,38 @@ def infer_expression(expression):
|
||||||
|
|
||||||
|
|
||||||
def type_check(name, stack):
|
def type_check(name, stack):
|
||||||
'''
|
'''
|
||||||
Trinary predicate. True if named function type-checks, False if it
|
Trinary predicate. True if named function type-checks, False if it
|
||||||
fails, None if it's indeterminate (because I haven't entered it into
|
fails, None if it's indeterminate (because I haven't entered it into
|
||||||
the FUNCTIONS dict yet.)
|
the FUNCTIONS dict yet.)
|
||||||
'''
|
'''
|
||||||
|
try:
|
||||||
|
func = FUNCTIONS[name]
|
||||||
|
except KeyError:
|
||||||
|
return # None, indicating unknown
|
||||||
|
if isinstance(func, SymbolJoyType):
|
||||||
|
secs = func.stack_effects
|
||||||
|
elif isinstance(func, CombinatorJoyType):
|
||||||
|
if func.expect is None:
|
||||||
|
return # None, indicating unknown
|
||||||
|
secs = [(func.expect, ())]
|
||||||
|
else:
|
||||||
|
raise TypeError(repr(func)) # wtf?
|
||||||
|
for fi, fo in secs:
|
||||||
try:
|
try:
|
||||||
func = FUNCTIONS[name]
|
unify(fi, stack)
|
||||||
except KeyError:
|
except (JoyTypeError, ValueError):
|
||||||
return # None, indicating unknown
|
continue
|
||||||
|
except:
|
||||||
for fi, fo in infer(func):
|
_log.exception(
|
||||||
try:
|
'Type-checking %s %s against %s',
|
||||||
U = unify(fi, stack)
|
name,
|
||||||
except (JoyTypeError, ValueError), e:
|
doc_from_stack_effect(fi, fo),
|
||||||
#print >> sys.stderr, name, e, stack
|
stack_to_string(stack),
|
||||||
continue
|
)
|
||||||
#print U
|
continue
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
FUNCTIONS = {} # Polytypes (lists of stack effects.)
|
FUNCTIONS = {} # Polytypes (lists of stack effects.)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue