• R/O
  • SSH

Joypy: Commit

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


Commit MetaInfo

Revision0d6ddc806c69ff4021a09bbbb5d4206b8a6fdf68 (tree)
Time2018-07-18 12:52:57
AuthorSimon Forman <sforman@hush...>
CommiterSimon Forman

Log Message

Definitions infer stack effects.

At start-up defs that DON'T type check are permitted (so you can use e.g.
loop, map, etc.) in the definitions "source", but then the user-facing
inscribe command only allows you to define new commands that DO
type-check. The ideal solution here is to get inference working for the
loopy words. (In the meantime you can select and execute their
definition text directly. That's not (yet!) type-checked.)

Change Summary

Incremental Difference

diff -r edea873c334c -r 0d6ddc806c69 joy/gui/world.py
--- a/joy/gui/world.py Tue Jul 17 20:09:17 2018 -0700
+++ b/joy/gui/world.py Tue Jul 17 20:52:57 2018 -0700
@@ -23,7 +23,7 @@
2323 from joy.joy import run
2424 from joy.parser import Symbol
2525 from joy.utils.stack import stack_to_string
26-from joy.utils.polytypes import type_check
26+from joy.utils.types import type_check
2727
2828
2929 def is_numerical(s):
diff -r edea873c334c -r 0d6ddc806c69 joy/library.py
--- a/joy/library.py Tue Jul 17 20:09:17 2018 -0700
+++ b/joy/library.py Tue Jul 17 20:52:57 2018 -0700
@@ -236,6 +236,7 @@
236236 make_generator == [codireco] ccons
237237 ifte == [nullary not] dipd branch
238238 '''
239+#
239240 #
240241 # ifte == [nullary] dipd swap branch
241242 # genrec == [[genrec] cons cons cons cons] nullary swons concat ifte
@@ -365,17 +366,20 @@
365366 class_.add_def(definition, dictionary)
366367
367368 @classmethod
368- def add_def(class_, definition, dictionary):
369+ def add_def(class_, definition, dictionary, fail_fails=False):
369370 '''
370371 Add the definition to the dictionary.
371372 '''
372373 F = class_.parse_definition(definition)
373374 try:
374- #print F._body
375+ # print F.name, F._body
375376 secs = infer(*F._body)
376377 except JoyTypeError:
377378 pass
378379 print F.name, '==', expression_to_string(F.body), ' --failed to infer stack effect.'
380+ if fail_fails:
381+ print 'Function not inscribed.'
382+ return
379383 else:
380384 FUNCTIONS[F.name] = SymbolJoyType(F.name, secs, _SYM_NUMS())
381385 dictionary[F.name] = F
@@ -405,7 +409,7 @@
405409 the definitions.txt resource.
406410 '''
407411 definition, stack = stack
408- DefinitionWrapper.add_def(definition, dictionary)
412+ DefinitionWrapper.add_def(definition, dictionary, fail_fails=True)
409413 return stack, expression, dictionary
410414
411415
@@ -652,6 +656,7 @@
652656
653657
654658 @inscribe
659+@combinator_effect(_COMB_NUMS(), s7, s6)
655660 @SimpleFunctionWrapper
656661 def concat_(S):
657662 '''Concatinate the two lists on the top of the stack.
@@ -982,7 +987,7 @@
982987
983988
984989 @inscribe
985-@combinator_effect(_COMB_NUMS(), s7, s6, s5, s4)
990+#@combinator_effect(_COMB_NUMS(), s7, s6, s5, s4)
986991 @FunctionWrapper
987992 def genrec(stack, expression, dictionary):
988993 '''
@@ -1396,7 +1401,7 @@
13961401
13971402
13981403 @inscribe
1399-@combinator_effect(_COMB_NUMS(), b1, s6)
1404+#@combinator_effect(_COMB_NUMS(), b1, s6)
14001405 @FunctionWrapper
14011406 def loop(stack, expression, dictionary):
14021407 '''
diff -r edea873c334c -r 0d6ddc806c69 joy/utils/polytypes.py
--- a/joy/utils/polytypes.py Tue Jul 17 20:09:17 2018 -0700
+++ b/joy/utils/polytypes.py Tue Jul 17 20:52:57 2018 -0700
@@ -1,58 +1,15 @@
11 # -*- coding: utf_8
2-'''
3-
4-Multiple Stack Effects
5-
6-By adjusting the machinery in types.py to handles lists of stack effect comments
7-we can capture more information about the type signatures of some functions,
8-and we can introduce a kind of Kleene Star or sequence type that can stand for
9-an unbounded sequence of other types.
10-
11-'''
12-import sys
13-import joy.library
14-from joy.parser import Symbol, text_to_expression
15-from joy.utils.stack import (
16- concat as CONCAT,
17- expression_to_string,
18- list_to_stack,
19- )
20-
21- average =
22- # sum_ =
23- # product =
24- # min_ = max_ = [(((Ns[1], s1), s0), (n0, s0))]
25- # flatten = [(((Ss[1], s1), s0), (s2, s0))]
26-
27- return {
28- name.rstrip('_'): stack_effect
29- for name, stack_effect in locals().iteritems()
30- }
312
323
33-FUNCTIONS.update({
34- name: SymbolJoyType(name, stack_effect, i)
35- for i, (name, stack_effect) in enumerate(defs().iteritems())
36- })
37-FUNCTIONS.update({
38- combo.__name__: CombinatorJoyType(combo.__name__, [combo], i)
39- for i, combo in enumerate((
40- joy.library.concat_,
41- joy.library._dictionary['disenstacken'],
42- joy.library.x,
43- ))
44- })
454
465
47-def branch_true(stack, expression, dictionary):
48- (then, (else_, (flag, stack))) = stack
49- return stack, CONCAT(then, expression), dictionary
506
51-def branch_false(stack, expression, dictionary):
52- (then, (else_, (flag, stack))) = stack
53- return stack, CONCAT(else_, expression), dictionary
547
55-FUNCTIONS['branch'] = CombinatorJoyType('branch', [branch_true, branch_false], 100)
8+
9+
10+
11+
12+
5613 pop = FUNCTIONS['pop']
5714
5815 def loop_true(stack, expression, dictionary):
@@ -70,41 +27,42 @@
7027 FUNCTIONS['loop'] = CombinatorJoyType('loop', [loop_two_true, loop_true, loop_false], 101)
7128
7229
73-joy.library.add_aliases(FUNCTIONS, joy.library.ALIASES)
74-
75-
76-def set_expectations_of_definition(cjt):
77- if len(cjt.stack_effects) != 1:
78- raise ValueError
79- defi = cjt.stack_effects[0]
80- if not isinstance(defi, joy.library.DefinitionWrapper):
81- raise ValueError
82- F = infer_expression(defi.body)
83- assert len(F) == 1, repr(F)
84- fi, fo = F[0]
85- cjt.expect = fi
8630
8731
8832
89-def set_expectations():
90-
91- loop.expect = s6, (b1, s5)
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)
104- disenstacken.expect = (As[1], s1), s0
105-scope = globals().copy()
106-scope.update(FUNCTIONS)
107-eval(set_expectations.func_code, scope)
108-del scope
10933
11034
35+
36+
37+
38+
39+
40+# joy.library.add_aliases(FUNCTIONS, joy.library.ALIASES)
41+
42+
43+# def set_expectations_of_definition(cjt):
44+# if len(cjt.stack_effects) != 1:
45+# raise ValueError
46+# defi = cjt.stack_effects[0]
47+# if not isinstance(defi, joy.library.DefinitionWrapper):
48+# raise ValueError
49+# F = infer_expression(defi.body)
50+# assert len(F) == 1, repr(F)
51+# fi, fo = F[0]
52+# cjt.expect = fi
53+
54+
55+
56+
57+ average =
58+ loop.expect = s6, (b1, s5)
59+ disenstacken.expect = (As[1], s1), s0
60+ joy.library._dictionary['disenstacken'],
61+
62+
63+# scope = globals().copy()
64+# scope.update(FUNCTIONS)
65+# eval(set_expectations.func_code, scope)
66+# del scope
67+
68+
Show on old repository browser