• R/O
  • SSH

Joypy: Commit

Main interpreter and library.


Commit MetaInfo

Revisione479d1f390553df2dbdd82ae969e6d50bea4f428 (tree)
Time2018-07-19 08:14:32
AuthorSimon Forman <sforman@hush...>
CommiterSimon Forman

Log Message

Add some logging.

Change Summary

Incremental Difference

diff -r 4e07e6751eba -r e479d1f39055 joy/gui/main.py
--- a/joy/gui/main.py Wed Jul 18 16:13:57 2018 -0700
+++ b/joy/gui/main.py Wed Jul 18 16:14:32 2018 -0700
@@ -7,11 +7,21 @@
77 ' This is free software, and you are welcome to redistribute it under certain conditions;'
88 ' right-click "sharing" for details.'
99 ' Right-click on these commands to see docs on UI commands: key_bindings mouse_bindings')
10-import os, pickle, sys
10+import logging, os, pickle, sys
1111 from textwrap import dedent
1212
13+from joy.gui.utils import init_home, FileFaker
14+
15+JOY_HOME, repo = init_home()
16+
17+logging.basicConfig(
18+ format='%(asctime)-15s %(levelname)s %(name)s %(message)s',
19+ filename=os.path.join(JOY_HOME, 'thun.log'),
20+ level=logging.INFO,
21+ )
22+
23+
1324 from joy.gui.textwidget import TextViewerWidget, tk, get_font, TEXT_BINDINGS
14-from joy.gui.utils import init_home, FileFaker
1525 from joy.gui.world import StackDisplayWorld
1626 from joy.library import initialize
1727 from joy.utils.stack import stack_to_string
@@ -101,7 +111,6 @@
101111 return stack, e, d
102112
103113
104-JOY_HOME, repo = init_home()
105114 STACK_FN = os.path.join(JOY_HOME, 'stack.pickle')
106115 REL_STACK_FN = repo_relative_path(STACK_FN)
107116 JOY_FN = os.path.join(JOY_HOME, 'scratch.txt')
diff -r 4e07e6751eba -r e479d1f39055 joy/utils/types.py
--- a/joy/utils/types.py Wed Jul 18 16:13:57 2018 -0700
+++ b/joy/utils/types.py Wed Jul 18 16:14:32 2018 -0700
@@ -6,7 +6,12 @@
66 from collections import Counter
77 from itertools import imap, chain, product
88 from inspect import stack as inspect_stack
9-from joy.utils.stack import concat, expression_to_string, list_to_stack
9+from joy.utils.stack import (
10+ concat,
11+ expression_to_string,
12+ list_to_stack,
13+ stack_to_string,
14+ )
1015 from joy.parser import Symbol, text_to_expression
1116
1217
@@ -222,6 +227,8 @@
222227
223228
224229 def _1000(right):
230+ if isinstance(right, Symbol):
231+ return right
225232 if not isinstance(right, tuple):
226233 return 1000 + right
227234 return tuple(_1000(n) for n in right)
@@ -539,7 +546,8 @@
539546
540547
541548 def _infer(e, F=ID):
542- _log_it(e, F)
549+ if __debug__:
550+ _log_it(e, F)
543551 if not e:
544552 return [F]
545553
@@ -577,7 +585,7 @@
577585
578586
579587 def _log_it(e, F):
580- _log.info(
588+ _log.debug(
581589 u'%3i %s ∘ %s',
582590 len(inspect_stack()),
583591 doc_from_stack_effect(*F),
@@ -614,25 +622,38 @@
614622
615623
616624 def type_check(name, stack):
617- '''
618- Trinary predicate. True if named function type-checks, False if it
619- fails, None if it's indeterminate (because I haven't entered it into
620- the FUNCTIONS dict yet.)
621- '''
625+ '''
626+ Trinary predicate. True if named function type-checks, False if it
627+ fails, None if it's indeterminate (because I haven't entered it into
628+ the FUNCTIONS dict yet.)
629+ '''
630+ try:
631+ func = FUNCTIONS[name]
632+ except KeyError:
633+ return # None, indicating unknown
634+ if isinstance(func, SymbolJoyType):
635+ secs = func.stack_effects
636+ elif isinstance(func, CombinatorJoyType):
637+ if func.expect is None:
638+ return # None, indicating unknown
639+ secs = [(func.expect, ())]
640+ else:
641+ raise TypeError(repr(func)) # wtf?
642+ for fi, fo in secs:
622643 try:
623- func = FUNCTIONS[name]
624- except KeyError:
625- return # None, indicating unknown
626-
627- for fi, fo in infer(func):
628- try:
629- U = unify(fi, stack)
630- except (JoyTypeError, ValueError), e:
631- #print >> sys.stderr, name, e, stack
632- continue
633- #print U
634- return True
635- return False
644+ unify(fi, stack)
645+ except (JoyTypeError, ValueError):
646+ continue
647+ except:
648+ _log.exception(
649+ 'Type-checking %s %s against %s',
650+ name,
651+ doc_from_stack_effect(fi, fo),
652+ stack_to_string(stack),
653+ )
654+ continue
655+ return True
656+ return False
636657
637658
638659 FUNCTIONS = {} # Polytypes (lists of stack effects.)
Show on old repository browser