Log types at startup.
This commit is contained in:
parent
1e8c196c5b
commit
49941f9a33
|
|
@ -8,6 +8,9 @@ Joypy - Copyright © 2018 Simon Forman
|
|||
' 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
|
||||
|
|
@ -111,6 +114,7 @@ def grand_reset(s, e, d):
|
|||
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')
|
||||
|
|
|
|||
|
|
@ -23,6 +23,11 @@ functions. Its main export is a Python function initialize() that
|
|||
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
|
||||
|
|
@ -55,6 +60,7 @@ from .utils.types import (
|
|||
JoyTypeError,
|
||||
combinator_effect,
|
||||
poly_combinator_effect,
|
||||
doc_from_stack_effect,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -194,10 +200,7 @@ def yin_functions():
|
|||
_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 = ('''\
|
||||
|
|
@ -376,13 +379,16 @@ class DefinitionWrapper(object):
|
|||
# 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
|
||||
|
||||
|
||||
|
|
@ -1506,11 +1512,12 @@ _functions.update(YIN_STACK_EFFECTS)
|
|||
# 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))
|
||||
|
||||
|
|
|
|||
|
|
@ -435,7 +435,7 @@ def compilable(f):
|
|||
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.
|
||||
'''
|
||||
|
|
@ -670,10 +670,12 @@ def stack_effect(*inputs):
|
|||
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
|
||||
|
|
@ -688,8 +690,10 @@ def ef(*inputs):
|
|||
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
|
||||
|
||||
|
|
@ -713,13 +717,12 @@ def generate_library_code(DEFS, f=None):
|
|||
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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue