Nearly there maybe, maybe not.
This commit is contained in:
parent
73d19b1f3d
commit
c9f405fbe9
|
|
@ -54,6 +54,7 @@ from .utils.types import (
|
||||||
infer,
|
infer,
|
||||||
JoyTypeError,
|
JoyTypeError,
|
||||||
combinator_effect,
|
combinator_effect,
|
||||||
|
poly_combinator_effect,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -926,7 +927,7 @@ def x(stack, expression, dictionary):
|
||||||
|
|
||||||
|
|
||||||
@inscribe
|
@inscribe
|
||||||
#@combinator_effect(_COMB_NUMS(), s7, s6)
|
@combinator_effect(_COMB_NUMS(), s7, s6)
|
||||||
@FunctionWrapper
|
@FunctionWrapper
|
||||||
def b(stack, expression, dictionary):
|
def b(stack, expression, dictionary):
|
||||||
'''
|
'''
|
||||||
|
|
@ -943,6 +944,7 @@ def b(stack, expression, dictionary):
|
||||||
|
|
||||||
|
|
||||||
@inscribe
|
@inscribe
|
||||||
|
@combinator_effect(_COMB_NUMS(), a1, s1)
|
||||||
@FunctionWrapper
|
@FunctionWrapper
|
||||||
def dupdip(stack, expression, dictionary):
|
def dupdip(stack, expression, dictionary):
|
||||||
'''
|
'''
|
||||||
|
|
@ -962,7 +964,7 @@ def dupdip(stack, expression, dictionary):
|
||||||
|
|
||||||
|
|
||||||
@inscribe
|
@inscribe
|
||||||
#@combinator_effect(_COMB_NUMS(), s7, s6)
|
@combinator_effect(_COMB_NUMS(), s7, s6)
|
||||||
@FunctionWrapper
|
@FunctionWrapper
|
||||||
def infra(stack, expression, dictionary):
|
def infra(stack, expression, dictionary):
|
||||||
'''
|
'''
|
||||||
|
|
@ -980,6 +982,7 @@ def infra(stack, expression, dictionary):
|
||||||
|
|
||||||
|
|
||||||
@inscribe
|
@inscribe
|
||||||
|
@combinator_effect(_COMB_NUMS(), s7, s6, s5, s4)
|
||||||
@FunctionWrapper
|
@FunctionWrapper
|
||||||
def genrec(stack, expression, dictionary):
|
def genrec(stack, expression, dictionary):
|
||||||
'''
|
'''
|
||||||
|
|
@ -1041,6 +1044,7 @@ def genrec(stack, expression, dictionary):
|
||||||
|
|
||||||
|
|
||||||
@inscribe
|
@inscribe
|
||||||
|
@combinator_effect(_COMB_NUMS(), s7, s6)
|
||||||
@FunctionWrapper
|
@FunctionWrapper
|
||||||
def map_(S, expression, dictionary):
|
def map_(S, expression, dictionary):
|
||||||
'''
|
'''
|
||||||
|
|
@ -1078,7 +1082,18 @@ def map_(S, expression, dictionary):
|
||||||
# return (q, (p, stack)), expression, dictionary
|
# return (q, (p, stack)), expression, dictionary
|
||||||
|
|
||||||
|
|
||||||
|
def branch_true(stack, expression, dictionary):
|
||||||
|
(then, (else_, (flag, stack))) = stack
|
||||||
|
return stack, concat(then, expression), dictionary
|
||||||
|
|
||||||
|
|
||||||
|
def branch_false(stack, expression, dictionary):
|
||||||
|
(then, (else_, (flag, stack))) = stack
|
||||||
|
return stack, concat(else_, expression), dictionary
|
||||||
|
|
||||||
|
|
||||||
@inscribe
|
@inscribe
|
||||||
|
@poly_combinator_effect(_COMB_NUMS(), [branch_true, branch_false], b1, s7, s6)
|
||||||
@FunctionWrapper
|
@FunctionWrapper
|
||||||
def branch(stack, expression, dictionary):
|
def branch(stack, expression, dictionary):
|
||||||
'''
|
'''
|
||||||
|
|
@ -1103,6 +1118,9 @@ def branch(stack, expression, dictionary):
|
||||||
return stack, concat(then if flag else else_, expression), dictionary
|
return stack, concat(then if flag else else_, expression), dictionary
|
||||||
|
|
||||||
|
|
||||||
|
#FUNCTIONS['branch'] = CombinatorJoyType('branch', [branch_true, branch_false], 100)
|
||||||
|
|
||||||
|
|
||||||
##@inscribe
|
##@inscribe
|
||||||
##@FunctionWrapper
|
##@FunctionWrapper
|
||||||
##def ifte(stack, expression, dictionary):
|
##def ifte(stack, expression, dictionary):
|
||||||
|
|
@ -1192,6 +1210,7 @@ def dip(stack, expression, dictionary):
|
||||||
|
|
||||||
|
|
||||||
@inscribe
|
@inscribe
|
||||||
|
@combinator_effect(_COMB_NUMS(), a2, a1, s1)
|
||||||
@FunctionWrapper
|
@FunctionWrapper
|
||||||
def dipd(S, expression, dictionary):
|
def dipd(S, expression, dictionary):
|
||||||
'''
|
'''
|
||||||
|
|
@ -1209,6 +1228,7 @@ def dipd(S, expression, dictionary):
|
||||||
|
|
||||||
|
|
||||||
@inscribe
|
@inscribe
|
||||||
|
@combinator_effect(_COMB_NUMS(), a3, a2, a1, s1)
|
||||||
@FunctionWrapper
|
@FunctionWrapper
|
||||||
def dipdd(S, expression, dictionary):
|
def dipdd(S, expression, dictionary):
|
||||||
'''
|
'''
|
||||||
|
|
@ -1226,6 +1246,7 @@ def dipdd(S, expression, dictionary):
|
||||||
|
|
||||||
|
|
||||||
@inscribe
|
@inscribe
|
||||||
|
@combinator_effect(_COMB_NUMS(), a1, s1)
|
||||||
@FunctionWrapper
|
@FunctionWrapper
|
||||||
def app1(S, expression, dictionary):
|
def app1(S, expression, dictionary):
|
||||||
'''
|
'''
|
||||||
|
|
@ -1245,6 +1266,7 @@ def app1(S, expression, dictionary):
|
||||||
|
|
||||||
|
|
||||||
@inscribe
|
@inscribe
|
||||||
|
@combinator_effect(_COMB_NUMS(), a2, a1, s1)
|
||||||
@FunctionWrapper
|
@FunctionWrapper
|
||||||
def app2(S, expression, dictionary):
|
def app2(S, expression, dictionary):
|
||||||
'''Like app1 with two items.
|
'''Like app1 with two items.
|
||||||
|
|
@ -1265,6 +1287,7 @@ def app2(S, expression, dictionary):
|
||||||
|
|
||||||
|
|
||||||
@inscribe
|
@inscribe
|
||||||
|
@combinator_effect(_COMB_NUMS(), a3, a2, a1, s1)
|
||||||
@FunctionWrapper
|
@FunctionWrapper
|
||||||
def app3(S, expression, dictionary):
|
def app3(S, expression, dictionary):
|
||||||
'''Like app1 with three items.
|
'''Like app1 with three items.
|
||||||
|
|
@ -1287,6 +1310,7 @@ def app3(S, expression, dictionary):
|
||||||
|
|
||||||
|
|
||||||
@inscribe
|
@inscribe
|
||||||
|
@combinator_effect(_COMB_NUMS(), s7, s6)
|
||||||
@FunctionWrapper
|
@FunctionWrapper
|
||||||
def step(S, expression, dictionary):
|
def step(S, expression, dictionary):
|
||||||
'''
|
'''
|
||||||
|
|
@ -1322,6 +1346,7 @@ def step(S, expression, dictionary):
|
||||||
|
|
||||||
|
|
||||||
@inscribe
|
@inscribe
|
||||||
|
@combinator_effect(_COMB_NUMS(), i1, s6)
|
||||||
@FunctionWrapper
|
@FunctionWrapper
|
||||||
def times(stack, expression, dictionary):
|
def times(stack, expression, dictionary):
|
||||||
'''
|
'''
|
||||||
|
|
@ -1371,6 +1396,7 @@ def times(stack, expression, dictionary):
|
||||||
|
|
||||||
|
|
||||||
@inscribe
|
@inscribe
|
||||||
|
@combinator_effect(_COMB_NUMS(), b1, s6)
|
||||||
@FunctionWrapper
|
@FunctionWrapper
|
||||||
def loop(stack, expression, dictionary):
|
def loop(stack, expression, dictionary):
|
||||||
'''
|
'''
|
||||||
|
|
@ -1393,6 +1419,7 @@ def loop(stack, expression, dictionary):
|
||||||
|
|
||||||
|
|
||||||
@inscribe
|
@inscribe
|
||||||
|
@combinator_effect(_COMB_NUMS(), a1, a2, s6, s7, s8)
|
||||||
@FunctionWrapper
|
@FunctionWrapper
|
||||||
def cmp_(stack, expression, dictionary):
|
def cmp_(stack, expression, dictionary):
|
||||||
'''
|
'''
|
||||||
|
|
|
||||||
|
|
@ -17,32 +17,12 @@ from joy.utils.stack import (
|
||||||
expression_to_string,
|
expression_to_string,
|
||||||
list_to_stack,
|
list_to_stack,
|
||||||
)
|
)
|
||||||
# from joy.utils.types import (
|
|
||||||
# AnyJoyType, A,
|
|
||||||
# BooleanJoyType, B,
|
|
||||||
# DEFS,
|
|
||||||
# doc_from_stack_effect,
|
|
||||||
# FloatJoyType, F,
|
|
||||||
# JoyTypeError,
|
|
||||||
# NumberJoyType, N,
|
|
||||||
# StackJoyType, S,
|
|
||||||
# _stacky,
|
|
||||||
# _R,
|
|
||||||
# relabel, delabel,
|
|
||||||
# reify,
|
|
||||||
# )
|
|
||||||
|
|
||||||
|
average =
|
||||||
'''Docstring for functions in Sphinx?'''
|
# sum_ =
|
||||||
|
# product =
|
||||||
|
# min_ = max_ = [(((Ns[1], s1), s0), (n0, s0))]
|
||||||
def defs():
|
# flatten = [(((Ss[1], s1), s0), (s2, s0))]
|
||||||
'''
|
|
||||||
Return a dict of FunctionJoyType instances to be used with ``infer()``.
|
|
||||||
'''
|
|
||||||
|
|
||||||
average = sum_ = product = min_ = max_ = [(((Ns[1], s1), s0), (n0, s0))]
|
|
||||||
flatten = [(((Ss[1], s1), s0), (s2, s0))]
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name.rstrip('_'): stack_effect
|
name.rstrip('_'): stack_effect
|
||||||
|
|
@ -57,21 +37,7 @@ FUNCTIONS.update({
|
||||||
FUNCTIONS.update({
|
FUNCTIONS.update({
|
||||||
combo.__name__: CombinatorJoyType(combo.__name__, [combo], i)
|
combo.__name__: CombinatorJoyType(combo.__name__, [combo], i)
|
||||||
for i, combo in enumerate((
|
for i, combo in enumerate((
|
||||||
joy.library.b,
|
|
||||||
joy.library.concat_,
|
joy.library.concat_,
|
||||||
joy.library.dip,
|
|
||||||
joy.library.dipd,
|
|
||||||
joy.library.dipdd,
|
|
||||||
joy.library.dupdip,
|
|
||||||
joy.library.i,
|
|
||||||
joy.library.infra,
|
|
||||||
joy.library._dictionary['nullary'],
|
|
||||||
joy.library._dictionary['unary'],
|
|
||||||
joy.library._dictionary['binary'],
|
|
||||||
joy.library._dictionary['ternary'],
|
|
||||||
joy.library._dictionary['quoted'],
|
|
||||||
joy.library._dictionary['unquoted'],
|
|
||||||
joy.library._dictionary['enstacken'],
|
|
||||||
joy.library._dictionary['disenstacken'],
|
joy.library._dictionary['disenstacken'],
|
||||||
joy.library.x,
|
joy.library.x,
|
||||||
))
|
))
|
||||||
|
|
@ -121,19 +87,20 @@ def set_expectations_of_definition(cjt):
|
||||||
|
|
||||||
|
|
||||||
def set_expectations():
|
def set_expectations():
|
||||||
branch.expect = s7, (s6, (b1, s5))
|
|
||||||
loop.expect = s6, (b1, s5)
|
loop.expect = s6, (b1, s5)
|
||||||
i.expect = nullary.expect = x.expect = s7, s6
|
# i.expect = nullary.expect = x.expect = s7, s6
|
||||||
dip.expect = dupdip.expect = s8, (a8, s7)
|
# dip.expect = dupdip.expect = s8, (a8, s7)
|
||||||
dipd.expect = s8, (a8, (a7, s7))
|
# dipd.expect = s8, (a8, (a7, s7))
|
||||||
dipdd.expect = s8, (a8, (a7, (a6, s7)))
|
# dipdd.expect = s8, (a8, (a7, (a6, s7)))
|
||||||
b.expect = concat_.expect = infra.expect = s8, (s7, s6)
|
concat_.expect = s8, (s7, s6)
|
||||||
set_expectations_of_definition(unary)
|
# b.expect = infra.expect = s8, (s7, s6)
|
||||||
set_expectations_of_definition(binary)
|
# set_expectations_of_definition(unary)
|
||||||
set_expectations_of_definition(ternary)
|
# set_expectations_of_definition(binary)
|
||||||
set_expectations_of_definition(quoted)
|
# set_expectations_of_definition(ternary)
|
||||||
set_expectations_of_definition(unquoted)
|
# set_expectations_of_definition(quoted)
|
||||||
set_expectations_of_definition(enstacken)
|
# set_expectations_of_definition(unquoted)
|
||||||
|
# set_expectations_of_definition(enstacken)
|
||||||
disenstacken.expect = (As[1], s1), s0
|
disenstacken.expect = (As[1], s1), s0
|
||||||
scope = globals().copy()
|
scope = globals().copy()
|
||||||
scope.update(FUNCTIONS)
|
scope.update(FUNCTIONS)
|
||||||
|
|
|
||||||
|
|
@ -665,11 +665,12 @@ def ef(*inputs):
|
||||||
|
|
||||||
|
|
||||||
def combinator_effect(number, *expect):
|
def combinator_effect(number, *expect):
|
||||||
def _combinator_effect(c):
|
def _combinator_effect(c):
|
||||||
C = FUNCTIONS[c.name] = CombinatorJoyType(c.name, [c], number)
|
e = __(*expect) if expect else None
|
||||||
if expect: C.expect = __(*expect)
|
C = FUNCTIONS[c.name] = CombinatorJoyType(c.name, [c], number, e)
|
||||||
return c
|
if expect: C.expect = __(*expect)
|
||||||
return _combinator_effect
|
return c
|
||||||
|
return _combinator_effect
|
||||||
|
|
||||||
|
|
||||||
def show(DEFS):
|
def show(DEFS):
|
||||||
|
|
@ -693,3 +694,13 @@ def generate_library_code(DEFS, f=None):
|
||||||
|
|
||||||
##if __name__ == '__main__':
|
##if __name__ == '__main__':
|
||||||
## show()
|
## 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)
|
||||||
|
return c
|
||||||
|
return _poly_combinator_effect
|
||||||
|
|
||||||
|
#FUNCTIONS['branch'].expect = s7, (s6, (b1, s5))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue