' right-click "sharing" for details.'
' Right-click on these commands to see docs on UI commands: key_bindings mouse_bindings')
import logging, os, pickle, sys
+
+_log = logging.getLogger(__name__)
+
from textwrap import dedent
from joy.gui.utils import init_home, FileFaker
return stack, e, d
+_log.info('Starting.')
STACK_FN = os.path.join(JOY_HOME, 'stack.pickle')
REL_STACK_FN = repo_relative_path(STACK_FN)
JOY_FN = os.path.join(JOY_HOME, 'scratch.txt')
returns a dictionary of Joy functions suitable for use with the joy()
function.
'''
+from logging import getLogger
+
+_log = getLogger(__name__)
+_log.info('Loading library.')
+
from inspect import getdoc
from functools import wraps
from itertools import count
JoyTypeError,
combinator_effect,
poly_combinator_effect,
+ doc_from_stack_effect,
)
_Tree_delete_clear_stuff = compose(rollup, popop, rest)
_Tree_delete_R0 = compose(over, first, swap, dup)
- return {
- name.rstrip('_'): stack_effect
- for name, stack_effect in locals().iteritems()
- }
+ return locals()
definitions = ('''\
# print F.name, F._body
secs = infer(*F._body)
except JoyTypeError:
- pass
- print F.name, '==', expression_to_string(F.body), ' --failed to infer stack effect.'
+ _log.error(
+ 'Failed to infer stack effect of %s == %s',
+ F.name,
+ expression_to_string(F.body),
+ )
if fail_fails:
- print 'Function not inscribed.'
return
else:
FUNCTIONS[F.name] = SymbolJoyType(F.name, secs, _SYM_NUMS())
+ _log.info('Setting stack effect for definition %s := %s', F.name, secs)
dictionary[F.name] = F
# of = compose(swap, at)
# ''' in dict(compose=compose), _functions
+for name in sorted(_functions):
+ sec = _functions[name]
+ F = FUNCTIONS[name] = SymbolJoyType(name, [sec], _SYM_NUMS())
+ if name in YIN_STACK_EFFECTS:
+ _log.info('Setting stack effect for Yin function %s := %s', F.name, doc_from_stack_effect(*sec))
-FUNCTIONS.update(
- (name, SymbolJoyType(name, [_functions[name]], _SYM_NUMS()))
- for name in sorted(_functions)
- )
for name, primitive in getmembers(genlib, isfunction):
inscribe(SimpleFunctionWrapper(primitive))
return isinstance(f, tuple) and all(imap(compilable, f)) or _stacky(f)
-def doc_from_stack_effect(inputs, outputs):
+def doc_from_stack_effect(inputs, outputs=('??', ())):
'''
Return a crude string representation of a stack effect.
'''
def _stack_effect(*outputs):
def _apply_to(function):
i, o = _functions[function.name] = __(*inputs), __(*outputs)
+ d = doc_from_stack_effect(i, o)
function.__doc__ += (
'\nStack effect::\n\n ' # '::' for Sphinx docs.
- + doc_from_stack_effect(i, o)
+ + d
)
+ _log.info('Setting stack effect for %s := %s', function.name, d)
return function
return _apply_to
return _stack_effect
def combinator_effect(number, *expect):
def _combinator_effect(c):
e = __(*expect) if expect else None
- C = FUNCTIONS[c.name] = CombinatorJoyType(c.name, [c], number, e)
- if expect: C.expect = __(*expect)
+ FUNCTIONS[c.name] = CombinatorJoyType(c.name, [c], number, e)
+ if e:
+ sec = doc_from_stack_effect(e)
+ _log.info('Setting stack EXPECT for combinator %s := %s', c.name, sec)
return c
return _combinator_effect
print >> f
-##if __name__ == '__main__':
-## show()
-
def poly_combinator_effect(number, effect_funcs, *expect):
def _poly_combinator_effect(c):
e = __(*expect) if expect else None
FUNCTIONS[c.name] = CombinatorJoyType(c.name, effect_funcs, number, e)
+ if e:
+ _log.info('Setting stack EXPECT for combinator %s := %s', c.name, e)
return c
return _poly_combinator_effect