• R/O
  • SSH

Joypy: Commit

Main interpreter and library.


Commit MetaInfo

Revisionedea873c334cc360787c1116bbdfbd96aeb20272 (tree)
Time2018-07-18 12:09:17
AuthorSimon Forman <sforman@hush...>
CommiterSimon Forman

Log Message

Nearly there maybe, maybe not.

Change Summary

Incremental Difference

diff -r 150ba0008881 -r edea873c334c joy/library.py
--- a/joy/library.py Tue Jul 17 17:12:27 2018 -0700
+++ b/joy/library.py Tue Jul 17 20:09:17 2018 -0700
@@ -54,6 +54,7 @@
5454 infer,
5555 JoyTypeError,
5656 combinator_effect,
57+ poly_combinator_effect,
5758 )
5859
5960
@@ -926,7 +927,7 @@
926927
927928
928929 @inscribe
929-#@combinator_effect(_COMB_NUMS(), s7, s6)
930+@combinator_effect(_COMB_NUMS(), s7, s6)
930931 @FunctionWrapper
931932 def b(stack, expression, dictionary):
932933 '''
@@ -943,6 +944,7 @@
943944
944945
945946 @inscribe
947+@combinator_effect(_COMB_NUMS(), a1, s1)
946948 @FunctionWrapper
947949 def dupdip(stack, expression, dictionary):
948950 '''
@@ -962,7 +964,7 @@
962964
963965
964966 @inscribe
965-#@combinator_effect(_COMB_NUMS(), s7, s6)
967+@combinator_effect(_COMB_NUMS(), s7, s6)
966968 @FunctionWrapper
967969 def infra(stack, expression, dictionary):
968970 '''
@@ -980,6 +982,7 @@
980982
981983
982984 @inscribe
985+@combinator_effect(_COMB_NUMS(), s7, s6, s5, s4)
983986 @FunctionWrapper
984987 def genrec(stack, expression, dictionary):
985988 '''
@@ -1041,6 +1044,7 @@
10411044
10421045
10431046 @inscribe
1047+@combinator_effect(_COMB_NUMS(), s7, s6)
10441048 @FunctionWrapper
10451049 def map_(S, expression, dictionary):
10461050 '''
@@ -1078,7 +1082,18 @@
10781082 # return (q, (p, stack)), expression, dictionary
10791083
10801084
1085+def branch_true(stack, expression, dictionary):
1086+ (then, (else_, (flag, stack))) = stack
1087+ return stack, concat(then, expression), dictionary
1088+
1089+
1090+def branch_false(stack, expression, dictionary):
1091+ (then, (else_, (flag, stack))) = stack
1092+ return stack, concat(else_, expression), dictionary
1093+
1094+
10811095 @inscribe
1096+@poly_combinator_effect(_COMB_NUMS(), [branch_true, branch_false], b1, s7, s6)
10821097 @FunctionWrapper
10831098 def branch(stack, expression, dictionary):
10841099 '''
@@ -1103,6 +1118,9 @@
11031118 return stack, concat(then if flag else else_, expression), dictionary
11041119
11051120
1121+#FUNCTIONS['branch'] = CombinatorJoyType('branch', [branch_true, branch_false], 100)
1122+
1123+
11061124 ##@inscribe
11071125 ##@FunctionWrapper
11081126 ##def ifte(stack, expression, dictionary):
@@ -1192,6 +1210,7 @@
11921210
11931211
11941212 @inscribe
1213+@combinator_effect(_COMB_NUMS(), a2, a1, s1)
11951214 @FunctionWrapper
11961215 def dipd(S, expression, dictionary):
11971216 '''
@@ -1209,6 +1228,7 @@
12091228
12101229
12111230 @inscribe
1231+@combinator_effect(_COMB_NUMS(), a3, a2, a1, s1)
12121232 @FunctionWrapper
12131233 def dipdd(S, expression, dictionary):
12141234 '''
@@ -1226,6 +1246,7 @@
12261246
12271247
12281248 @inscribe
1249+@combinator_effect(_COMB_NUMS(), a1, s1)
12291250 @FunctionWrapper
12301251 def app1(S, expression, dictionary):
12311252 '''
@@ -1245,6 +1266,7 @@
12451266
12461267
12471268 @inscribe
1269+@combinator_effect(_COMB_NUMS(), a2, a1, s1)
12481270 @FunctionWrapper
12491271 def app2(S, expression, dictionary):
12501272 '''Like app1 with two items.
@@ -1265,6 +1287,7 @@
12651287
12661288
12671289 @inscribe
1290+@combinator_effect(_COMB_NUMS(), a3, a2, a1, s1)
12681291 @FunctionWrapper
12691292 def app3(S, expression, dictionary):
12701293 '''Like app1 with three items.
@@ -1287,6 +1310,7 @@
12871310
12881311
12891312 @inscribe
1313+@combinator_effect(_COMB_NUMS(), s7, s6)
12901314 @FunctionWrapper
12911315 def step(S, expression, dictionary):
12921316 '''
@@ -1322,6 +1346,7 @@
13221346
13231347
13241348 @inscribe
1349+@combinator_effect(_COMB_NUMS(), i1, s6)
13251350 @FunctionWrapper
13261351 def times(stack, expression, dictionary):
13271352 '''
@@ -1371,6 +1396,7 @@
13711396
13721397
13731398 @inscribe
1399+@combinator_effect(_COMB_NUMS(), b1, s6)
13741400 @FunctionWrapper
13751401 def loop(stack, expression, dictionary):
13761402 '''
@@ -1393,6 +1419,7 @@
13931419
13941420
13951421 @inscribe
1422+@combinator_effect(_COMB_NUMS(), a1, a2, s6, s7, s8)
13961423 @FunctionWrapper
13971424 def cmp_(stack, expression, dictionary):
13981425 '''
diff -r 150ba0008881 -r edea873c334c joy/utils/polytypes.py
--- a/joy/utils/polytypes.py Tue Jul 17 17:12:27 2018 -0700
+++ b/joy/utils/polytypes.py Tue Jul 17 20:09:17 2018 -0700
@@ -17,32 +17,12 @@
1717 expression_to_string,
1818 list_to_stack,
1919 )
20-# from joy.utils.types import (
21-# AnyJoyType, A,
22-# BooleanJoyType, B,
23-# DEFS,
24-# doc_from_stack_effect,
25-# FloatJoyType, F,
26-# JoyTypeError,
27-# NumberJoyType, N,
28-# StackJoyType, S,
29-# _stacky,
30-# _R,
31-# relabel, delabel,
32-# reify,
33-# )
3420
35-
36-'''Docstring for functions in Sphinx?'''
37-
38-
39-def defs():
40- '''
41- Return a dict of FunctionJoyType instances to be used with ``infer()``.
42- '''
43-
44- average = sum_ = product = min_ = max_ = [(((Ns[1], s1), s0), (n0, s0))]
45- flatten = [(((Ss[1], s1), s0), (s2, s0))]
21+ average =
22+ # sum_ =
23+ # product =
24+ # min_ = max_ = [(((Ns[1], s1), s0), (n0, s0))]
25+ # flatten = [(((Ss[1], s1), s0), (s2, s0))]
4626
4727 return {
4828 name.rstrip('_'): stack_effect
@@ -57,21 +37,7 @@
5737 FUNCTIONS.update({
5838 combo.__name__: CombinatorJoyType(combo.__name__, [combo], i)
5939 for i, combo in enumerate((
60- joy.library.b,
6140 joy.library.concat_,
62- joy.library.dip,
63- joy.library.dipd,
64- joy.library.dipdd,
65- joy.library.dupdip,
66- joy.library.i,
67- joy.library.infra,
68- joy.library._dictionary['nullary'],
69- joy.library._dictionary['unary'],
70- joy.library._dictionary['binary'],
71- joy.library._dictionary['ternary'],
72- joy.library._dictionary['quoted'],
73- joy.library._dictionary['unquoted'],
74- joy.library._dictionary['enstacken'],
7541 joy.library._dictionary['disenstacken'],
7642 joy.library.x,
7743 ))
@@ -121,19 +87,20 @@
12187
12288
12389 def set_expectations():
124- branch.expect = s7, (s6, (b1, s5))
90+
12591 loop.expect = s6, (b1, s5)
126- i.expect = nullary.expect = x.expect = s7, s6
127- dip.expect = dupdip.expect = s8, (a8, s7)
128- dipd.expect = s8, (a8, (a7, s7))
129- dipdd.expect = s8, (a8, (a7, (a6, s7)))
130- b.expect = concat_.expect = infra.expect = s8, (s7, s6)
131- set_expectations_of_definition(unary)
132- set_expectations_of_definition(binary)
133- set_expectations_of_definition(ternary)
134- set_expectations_of_definition(quoted)
135- set_expectations_of_definition(unquoted)
136- set_expectations_of_definition(enstacken)
92+# i.expect = nullary.expect = x.expect = s7, s6
93+# dip.expect = dupdip.expect = s8, (a8, s7)
94+# dipd.expect = s8, (a8, (a7, s7))
95+# dipdd.expect = s8, (a8, (a7, (a6, s7)))
96+ concat_.expect = s8, (s7, s6)
97+# b.expect = infra.expect = s8, (s7, s6)
98+ # set_expectations_of_definition(unary)
99+ # set_expectations_of_definition(binary)
100+ # set_expectations_of_definition(ternary)
101+ # set_expectations_of_definition(quoted)
102+ # set_expectations_of_definition(unquoted)
103+ # set_expectations_of_definition(enstacken)
137104 disenstacken.expect = (As[1], s1), s0
138105 scope = globals().copy()
139106 scope.update(FUNCTIONS)
diff -r 150ba0008881 -r edea873c334c joy/utils/types.py
--- a/joy/utils/types.py Tue Jul 17 17:12:27 2018 -0700
+++ b/joy/utils/types.py Tue Jul 17 20:09:17 2018 -0700
@@ -665,11 +665,12 @@
665665
666666
667667 def combinator_effect(number, *expect):
668- def _combinator_effect(c):
669- C = FUNCTIONS[c.name] = CombinatorJoyType(c.name, [c], number)
670- if expect: C.expect = __(*expect)
671- return c
672- return _combinator_effect
668+ def _combinator_effect(c):
669+ e = __(*expect) if expect else None
670+ C = FUNCTIONS[c.name] = CombinatorJoyType(c.name, [c], number, e)
671+ if expect: C.expect = __(*expect)
672+ return c
673+ return _combinator_effect
673674
674675
675676 def show(DEFS):
@@ -693,3 +694,13 @@
693694
694695 ##if __name__ == '__main__':
695696 ## show()
697+
698+def poly_combinator_effect(number, effect_funcs, *expect):
699+ def _poly_combinator_effect(c):
700+ e = __(*expect) if expect else None
701+ FUNCTIONS[c.name] = CombinatorJoyType(c.name, effect_funcs, number, e)
702+ return c
703+ return _poly_combinator_effect
704+
705+#FUNCTIONS['branch'].expect = s7, (s6, (b1, s5))
706+
Show on old repository browser