• R/O
  • SSH

Joypy: Commit

Main interpreter and library.


Commit MetaInfo

Revision8409912d2fac8bf55f93aae0762857c8c563fae7 (tree)
Time2018-07-20 04:38:19
AuthorSimon Forman <sforman@hush...>
CommiterSimon Forman

Log Message

Working to get types right.

Change Summary

Incremental Difference

diff -r fdda4281b1a8 -r 8409912d2fac joy/library.py
--- a/joy/library.py Wed Jul 18 17:47:19 2018 -0700
+++ b/joy/library.py Thu Jul 19 12:38:19 2018 -0700
@@ -53,10 +53,12 @@
5353 FloatJoyType,
5454 IntJoyType,
5555 SymbolJoyType,
56+ CombinatorJoyType,
5657 TextJoyType,
5758 _functions,
5859 FUNCTIONS,
5960 infer,
61+ infer_expression,
6062 JoyTypeError,
6163 combinator_effect,
6264 poly_combinator_effect,
@@ -375,20 +377,7 @@
375377 Add the definition to the dictionary.
376378 '''
377379 F = class_.parse_definition(definition)
378- try:
379- # print F.name, F._body
380- secs = infer(*F._body)
381- except JoyTypeError:
382- _log.error(
383- 'Failed to infer stack effect of %s == %s',
384- F.name,
385- expression_to_string(F.body),
386- )
387- if fail_fails:
388- return
389- else:
390- FUNCTIONS[F.name] = SymbolJoyType(F.name, secs, _SYM_NUMS())
391- _log.info('Setting stack effect for definition %s := %s', F.name, secs)
380+ _log.info('Adding definition %s := %s', F.name, expression_to_string(F.body))
392381 dictionary[F.name] = F
393382
394383
@@ -1529,4 +1518,68 @@
15291518
15301519 DefinitionWrapper.add_definitions(definitions, _dictionary)
15311520
1521+
1522+for name in ('''
1523+of quoted enstacken ? dinfrirst
1524+'''.split()):
1525+ of_ = _dictionary[name]
1526+ secs = infer_expression(of_.body)
1527+ assert len(secs) == 1, repr(secs)
1528+ _log.info(
1529+ 'Setting stack effect for definition %s := %s',
1530+ name,
1531+ doc_from_stack_effect(*secs[0]),
1532+ )
1533+ FUNCTIONS[name] = SymbolJoyType(name, infer_expression(of_.body), _SYM_NUMS())
1534+
1535+
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+
15321550 #sec_Ns_math(_dictionary['product'])
1551+
1552+## product == 1 swap [*] step
1553+## flatten == [] swap [concat] step
1554+## quoted == [unit] dip
1555+## unquoted == [i] dip
1556+## enstacken == stack [clear] dip
1557+## ? == dup truthy
1558+## 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
1564+## pam == [i] map
1565+## run == [] swap infra
1566+## sqr == dup mul
1567+## size == 0 swap [pop ++] step
1568+## fork == [i] app2
1569+## cleave == fork [popd] dip
1570+## average == [sum 1.0 *] [size] cleave /
1571+## gcd == 1 [tuck modulus dup 0 >] loop pop
1572+## least_fraction == dup [gcd] infra [div] concat map
1573+## *fraction == [uncons] dip uncons [swap] dip concat [*] infra [*] dip cons
1574+## *fraction0 == concat [[swap] dip * [*] dip] infra
1575+## down_to_zero == [0 >] [dup --] while
1576+## range_to_zero == unit [down_to_zero] infra
1577+## anamorphism == [pop []] swap [dip swons] genrec
1578+## range == [0 <=] [1 - dup] anamorphism
1579+## while == swap [nullary] cons dup dipd concat loop
1580+## dupdipd == dup dipd
1581+## primrec == [i] genrec
1582+## step_zero == 0 roll> step
1583+## codireco == cons dip rest cons
1584+## make_generator == [codireco] ccons
1585+## ifte == [nullary not] dipd branch
diff -r fdda4281b1a8 -r 8409912d2fac joy/utils/types.py
--- a/joy/utils/types.py Wed Jul 18 17:47:19 2018 -0700
+++ b/joy/utils/types.py Thu Jul 19 12:38:19 2018 -0700
@@ -565,7 +565,7 @@
565565 if n in FUNCTIONS:
566566 res =_infer((FUNCTIONS[n], e), F)
567567 else:
568- raise JoyTypeError
568+ raise JoyTypeError(n)
569569 # print n
570570 # func = joy.library._dictionary[n]
571571 # res = _interpret(func, F[0], F[1], e)
Show on old repository browser