• R/O
  • SSH

Joypy: Commit

Main interpreter and library.


Commit MetaInfo

Revision747e86657f67dc170fae4fb95ee98101e197f1d1 (tree)
Time2018-07-20 07:18:42
AuthorSimon Forman <sforman@hush...>
CommiterSimon Forman

Log Message

Getting back to parity after jumble.

Polytypes module folded into types module, with all the actual type
information done when you load the library module. Some definitions can
be inferred from their body expression, others need to be
CombinatorJoyType wrapped. Still to do: loop.

Change Summary

Incremental Difference

diff -r 8409912d2fac -r 747e86657f67 joy/library.py
--- a/joy/library.py Thu Jul 19 12:38:19 2018 -0700
+++ b/joy/library.py Thu Jul 19 15:18:42 2018 -0700
@@ -1519,8 +1519,29 @@
15191519 DefinitionWrapper.add_definitions(definitions, _dictionary)
15201520
15211521
1522+EXPECTATIONS = dict(
1523+ nullary=(s7, s6),
1524+)
1525+
1526+
1527+for name in '''
1528+ dinfrirst
1529+ nullary
1530+ '''.split():
1531+ C = _dictionary[name]
1532+ expect = EXPECTATIONS.get(name)
1533+ if expect:
1534+ sec = doc_from_stack_effect(expect)
1535+ _log.info('Setting stack EXPECT for combinator %s := %s', C.name, sec)
1536+ else:
1537+ _log.info('combinator %s', C.name)
1538+ FUNCTIONS[name] = CombinatorJoyType(name, [C], _COMB_NUMS(), expect)
1539+
1540+
15221541 for name in ('''
1523-of quoted enstacken ? dinfrirst
1542+of quoted enstacken ?
1543+unary binary ternary
1544+sqr codireco unquoted
15241545 '''.split()):
15251546 of_ = _dictionary[name]
15261547 secs = infer_expression(of_.body)
@@ -1533,20 +1554,6 @@
15331554 FUNCTIONS[name] = SymbolJoyType(name, infer_expression(of_.body), _SYM_NUMS())
15341555
15351556
1536-for name in ('''
1537-of quoted enstacken ? dinfrirst
1538-'''.split()):
1539- of_ = _dictionary[name]
1540-
1541- assert len(secs) == 1, repr(secs)
1542- _log.info(
1543- 'Setting stack effect for definition %s := %s',
1544- name,
1545- doc_from_stack_effect(*secs[0]),
1546- )
1547- FUNCTIONS[name] = SymbolJoyType(name, infer_expression(of_.body), _SYM_NUMS())
1548-
1549-
15501557 #sec_Ns_math(_dictionary['product'])
15511558
15521559 ## product == 1 swap [*] step
@@ -1556,14 +1563,8 @@
15561563 ## enstacken == stack [clear] dip
15571564 ## ? == dup truthy
15581565 ## disenstacken == ? [uncons ?] loop pop
1559-## dinfrirst == dip infra first
1560-## nullary == [stack] dinfrirst
1561-## unary == nullary popd
1562-## binary == nullary [popop] dip
1563-## ternary == unary [popop] dip
15641566 ## pam == [i] map
15651567 ## run == [] swap infra
1566-## sqr == dup mul
15671568 ## size == 0 swap [pop ++] step
15681569 ## fork == [i] app2
15691570 ## cleave == fork [popd] dip
diff -r 8409912d2fac -r 747e86657f67 test/test_type_inference.py
--- a/test/test_type_inference.py Thu Jul 19 12:38:19 2018 -0700
+++ b/test/test_type_inference.py Thu Jul 19 15:18:42 2018 -0700
@@ -1,12 +1,26 @@
11 #!/usr/bin/env python
2-import unittest
2+import logging, sys, unittest
33
4-from joy.utils.polytypes import *
4+from joy.utils.types import *
55 from joy.utils.stack import list_to_stack as __
6-
6+from joy.library import (
7+ a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, As,
8+ b0, b1, b2, b3, b4, b5, b6, b7, b8, b9,
9+ n0, n1, n2, n3, n4, n5, n6, n7, n8, n9, Ns,
10+ s0, s1, s2, s3, s4, s5, s6, s7, s8, s9,
11+ f0, f1, f2, f3, f4, f5, f6, f7, f8, f9,
12+ i0, i1, i2, i3, i4, i5, i6, i7, i8, i9,
13+ t0, t1, t2, t3, t4, t5, t6, t7, t8, t9,
14+ )
715
816 globals().update(FUNCTIONS)
917
18+logging.basicConfig(
19+ format='%(message)s',
20+ stream=sys.stdout,
21+ level=logging.INFO,
22+ )
23+
1024
1125 class TestMixin(object):
1226
@@ -52,7 +66,7 @@
5266 self.assertEqualTypeStructure(infer(*expression), f)
5367
5468 def test_concat(self):
55- expression = (swons, s3), (a4, s1), concat_
69+ expression = (swons, s3), (a4, s1), concat
5670 f = (s1, ((swons, (a1, s2)), s1)) # (-- [swons a1 ...2])
5771 self.assertEqualTypeStructure(infer(*expression), [f])
5872
@@ -90,18 +104,14 @@
90104 infra
91105 ]
92106 f = [
93- (s1, ((f1, (n1, s2)), s3)), # (-- [f1 n1 ...2])
94- (s1, ((i1, (n1, s2)), s3)), # (-- [i1 n1 ...2])
107+ (s1, ((n1, (n2, s2)), s1)), # (-- [n1 n2 ...2])
95108 ]
96109 self.assertEqualTypeStructure(infer(*expression), f)
97110
98111 def test_nullary(self):
99112 expression = n1, n2, (mul, s2), (stack, s3), dip, infra, first
100113 f = [
101- (s1, (f1, (f2, (f3, s1)))), # (-- f3 f2 f1)
102- (s1, (f1, (f2, (i1, s1)))), # (-- i1 f2 f1)
103- (s1, (f1, (i1, (f2, s1)))), # (-- f2 i1 f1)
104- (s1, (i1, (i2, (i3, s1)))), # (-- i3 i2 i1)
114+ (s1, (n1, (n2, (n3, s1)))), # (-- n3 n2 n1)
105115 ]
106116 self.assertEqualTypeStructure(infer(*expression), f)
107117
Show on old repository browser