This repo is not current. Development has moved from Hg to Git. For the latest code use the "Source Code" tab above to go to the "Thun" git repo or navigate to:
https://osdn.net/projects/joypy/scm/git/Thun
Revision | 8c97ad5f195d12b0bc5c7608af54db81572cefda (tree) |
---|---|
Time | 2018-07-19 09:06:51 |
Author | Simon Forman <sforman@hush...> |
Commiter | Simon Forman |
Log types at startup.
@@ -8,6 +8,9 @@ | ||
8 | 8 | ' right-click "sharing" for details.' |
9 | 9 | ' Right-click on these commands to see docs on UI commands: key_bindings mouse_bindings') |
10 | 10 | import logging, os, pickle, sys |
11 | + | |
12 | +_log = logging.getLogger(__name__) | |
13 | + | |
11 | 14 | from textwrap import dedent |
12 | 15 | |
13 | 16 | from joy.gui.utils import init_home, FileFaker |
@@ -111,6 +114,7 @@ | ||
111 | 114 | return stack, e, d |
112 | 115 | |
113 | 116 | |
117 | +_log.info('Starting.') | |
114 | 118 | STACK_FN = os.path.join(JOY_HOME, 'stack.pickle') |
115 | 119 | REL_STACK_FN = repo_relative_path(STACK_FN) |
116 | 120 | JOY_FN = os.path.join(JOY_HOME, 'scratch.txt') |
@@ -23,6 +23,11 @@ | ||
23 | 23 | returns a dictionary of Joy functions suitable for use with the joy() |
24 | 24 | function. |
25 | 25 | ''' |
26 | +from logging import getLogger | |
27 | + | |
28 | +_log = getLogger(__name__) | |
29 | +_log.info('Loading library.') | |
30 | + | |
26 | 31 | from inspect import getdoc |
27 | 32 | from functools import wraps |
28 | 33 | from itertools import count |
@@ -55,6 +60,7 @@ | ||
55 | 60 | JoyTypeError, |
56 | 61 | combinator_effect, |
57 | 62 | poly_combinator_effect, |
63 | + doc_from_stack_effect, | |
58 | 64 | ) |
59 | 65 | |
60 | 66 |
@@ -194,10 +200,7 @@ | ||
194 | 200 | _Tree_delete_clear_stuff = compose(rollup, popop, rest) |
195 | 201 | _Tree_delete_R0 = compose(over, first, swap, dup) |
196 | 202 | |
197 | - return { | |
198 | - name.rstrip('_'): stack_effect | |
199 | - for name, stack_effect in locals().iteritems() | |
200 | - } | |
203 | + return locals() | |
201 | 204 | |
202 | 205 | |
203 | 206 | definitions = ('''\ |
@@ -376,13 +379,16 @@ | ||
376 | 379 | # print F.name, F._body |
377 | 380 | secs = infer(*F._body) |
378 | 381 | 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 | + ) | |
381 | 387 | if fail_fails: |
382 | - print 'Function not inscribed.' | |
383 | 388 | return |
384 | 389 | else: |
385 | 390 | FUNCTIONS[F.name] = SymbolJoyType(F.name, secs, _SYM_NUMS()) |
391 | + _log.info('Setting stack effect for definition %s := %s', F.name, secs) | |
386 | 392 | dictionary[F.name] = F |
387 | 393 | |
388 | 394 |
@@ -1506,11 +1512,12 @@ | ||
1506 | 1512 | # of = compose(swap, at) |
1507 | 1513 | |
1508 | 1514 | # ''' 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)) | |
1509 | 1520 | |
1510 | -FUNCTIONS.update( | |
1511 | - (name, SymbolJoyType(name, [_functions[name]], _SYM_NUMS())) | |
1512 | - for name in sorted(_functions) | |
1513 | - ) | |
1514 | 1521 | for name, primitive in getmembers(genlib, isfunction): |
1515 | 1522 | inscribe(SimpleFunctionWrapper(primitive)) |
1516 | 1523 |
@@ -435,7 +435,7 @@ | ||
435 | 435 | return isinstance(f, tuple) and all(imap(compilable, f)) or _stacky(f) |
436 | 436 | |
437 | 437 | |
438 | -def doc_from_stack_effect(inputs, outputs): | |
438 | +def doc_from_stack_effect(inputs, outputs=('??', ())): | |
439 | 439 | ''' |
440 | 440 | Return a crude string representation of a stack effect. |
441 | 441 | ''' |
@@ -670,10 +670,12 @@ | ||
670 | 670 | def _stack_effect(*outputs): |
671 | 671 | def _apply_to(function): |
672 | 672 | i, o = _functions[function.name] = __(*inputs), __(*outputs) |
673 | + d = doc_from_stack_effect(i, o) | |
673 | 674 | function.__doc__ += ( |
674 | 675 | '\nStack effect::\n\n ' # '::' for Sphinx docs. |
675 | - + doc_from_stack_effect(i, o) | |
676 | + + d | |
676 | 677 | ) |
678 | + _log.info('Setting stack effect for %s := %s', function.name, d) | |
677 | 679 | return function |
678 | 680 | return _apply_to |
679 | 681 | return _stack_effect |
@@ -688,8 +690,10 @@ | ||
688 | 690 | def combinator_effect(number, *expect): |
689 | 691 | def _combinator_effect(c): |
690 | 692 | 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) | |
693 | 697 | return c |
694 | 698 | return _combinator_effect |
695 | 699 |
@@ -713,13 +717,12 @@ | ||
713 | 717 | print >> f |
714 | 718 | |
715 | 719 | |
716 | -##if __name__ == '__main__': | |
717 | -## show() | |
718 | - | |
719 | 720 | def poly_combinator_effect(number, effect_funcs, *expect): |
720 | 721 | def _poly_combinator_effect(c): |
721 | 722 | e = __(*expect) if expect else None |
722 | 723 | 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) | |
723 | 726 | return c |
724 | 727 | return _poly_combinator_effect |
725 | 728 |