• R/O
  • SSH

Joypy: Commit

Main interpreter and library.


Commit MetaInfo

Revision8c97ad5f195d12b0bc5c7608af54db81572cefda (tree)
Time2018-07-19 09:06:51
AuthorSimon Forman <sforman@hush...>
CommiterSimon Forman

Log Message

Log types at startup.

Change Summary

Incremental Difference

diff -r e479d1f39055 -r 8c97ad5f195d joy/gui/main.py
--- a/joy/gui/main.py Wed Jul 18 16:14:32 2018 -0700
+++ b/joy/gui/main.py Wed Jul 18 17:06:51 2018 -0700
@@ -8,6 +8,9 @@
88 ' right-click "sharing" for details.'
99 ' Right-click on these commands to see docs on UI commands: key_bindings mouse_bindings')
1010 import logging, os, pickle, sys
11+
12+_log = logging.getLogger(__name__)
13+
1114 from textwrap import dedent
1215
1316 from joy.gui.utils import init_home, FileFaker
@@ -111,6 +114,7 @@
111114 return stack, e, d
112115
113116
117+_log.info('Starting.')
114118 STACK_FN = os.path.join(JOY_HOME, 'stack.pickle')
115119 REL_STACK_FN = repo_relative_path(STACK_FN)
116120 JOY_FN = os.path.join(JOY_HOME, 'scratch.txt')
diff -r e479d1f39055 -r 8c97ad5f195d joy/library.py
--- a/joy/library.py Wed Jul 18 16:14:32 2018 -0700
+++ b/joy/library.py Wed Jul 18 17:06:51 2018 -0700
@@ -23,6 +23,11 @@
2323 returns a dictionary of Joy functions suitable for use with the joy()
2424 function.
2525 '''
26+from logging import getLogger
27+
28+_log = getLogger(__name__)
29+_log.info('Loading library.')
30+
2631 from inspect import getdoc
2732 from functools import wraps
2833 from itertools import count
@@ -55,6 +60,7 @@
5560 JoyTypeError,
5661 combinator_effect,
5762 poly_combinator_effect,
63+ doc_from_stack_effect,
5864 )
5965
6066
@@ -194,10 +200,7 @@
194200 _Tree_delete_clear_stuff = compose(rollup, popop, rest)
195201 _Tree_delete_R0 = compose(over, first, swap, dup)
196202
197- return {
198- name.rstrip('_'): stack_effect
199- for name, stack_effect in locals().iteritems()
200- }
203+ return locals()
201204
202205
203206 definitions = ('''\
@@ -376,13 +379,16 @@
376379 # print F.name, F._body
377380 secs = infer(*F._body)
378381 except JoyTypeError:
379- pass
380- print F.name, '==', expression_to_string(F.body), ' --failed to infer stack effect.'
382+ _log.error(
383+ 'Failed to infer stack effect of %s == %s',
384+ F.name,
385+ expression_to_string(F.body),
386+ )
381387 if fail_fails:
382- print 'Function not inscribed.'
383388 return
384389 else:
385390 FUNCTIONS[F.name] = SymbolJoyType(F.name, secs, _SYM_NUMS())
391+ _log.info('Setting stack effect for definition %s := %s', F.name, secs)
386392 dictionary[F.name] = F
387393
388394
@@ -1506,11 +1512,12 @@
15061512 # of = compose(swap, at)
15071513
15081514 # ''' in dict(compose=compose), _functions
1515+for name in sorted(_functions):
1516+ sec = _functions[name]
1517+ F = FUNCTIONS[name] = SymbolJoyType(name, [sec], _SYM_NUMS())
1518+ if name in YIN_STACK_EFFECTS:
1519+ _log.info('Setting stack effect for Yin function %s := %s', F.name, doc_from_stack_effect(*sec))
15091520
1510-FUNCTIONS.update(
1511- (name, SymbolJoyType(name, [_functions[name]], _SYM_NUMS()))
1512- for name in sorted(_functions)
1513- )
15141521 for name, primitive in getmembers(genlib, isfunction):
15151522 inscribe(SimpleFunctionWrapper(primitive))
15161523
diff -r e479d1f39055 -r 8c97ad5f195d joy/utils/types.py
--- a/joy/utils/types.py Wed Jul 18 16:14:32 2018 -0700
+++ b/joy/utils/types.py Wed Jul 18 17:06:51 2018 -0700
@@ -435,7 +435,7 @@
435435 return isinstance(f, tuple) and all(imap(compilable, f)) or _stacky(f)
436436
437437
438-def doc_from_stack_effect(inputs, outputs):
438+def doc_from_stack_effect(inputs, outputs=('??', ())):
439439 '''
440440 Return a crude string representation of a stack effect.
441441 '''
@@ -670,10 +670,12 @@
670670 def _stack_effect(*outputs):
671671 def _apply_to(function):
672672 i, o = _functions[function.name] = __(*inputs), __(*outputs)
673+ d = doc_from_stack_effect(i, o)
673674 function.__doc__ += (
674675 '\nStack effect::\n\n ' # '::' for Sphinx docs.
675- + doc_from_stack_effect(i, o)
676+ + d
676677 )
678+ _log.info('Setting stack effect for %s := %s', function.name, d)
677679 return function
678680 return _apply_to
679681 return _stack_effect
@@ -688,8 +690,10 @@
688690 def combinator_effect(number, *expect):
689691 def _combinator_effect(c):
690692 e = __(*expect) if expect else None
691- C = FUNCTIONS[c.name] = CombinatorJoyType(c.name, [c], number, e)
692- if expect: C.expect = __(*expect)
693+ FUNCTIONS[c.name] = CombinatorJoyType(c.name, [c], number, e)
694+ if e:
695+ sec = doc_from_stack_effect(e)
696+ _log.info('Setting stack EXPECT for combinator %s := %s', c.name, sec)
693697 return c
694698 return _combinator_effect
695699
@@ -713,13 +717,12 @@
713717 print >> f
714718
715719
716-##if __name__ == '__main__':
717-## show()
718-
719720 def poly_combinator_effect(number, effect_funcs, *expect):
720721 def _poly_combinator_effect(c):
721722 e = __(*expect) if expect else None
722723 FUNCTIONS[c.name] = CombinatorJoyType(c.name, effect_funcs, number, e)
724+ if e:
725+ _log.info('Setting stack EXPECT for combinator %s := %s', c.name, e)
723726 return c
724727 return _poly_combinator_effect
725728
Show on old repository browser