• R/O
  • SSH

Joypy: Commit

Main interpreter and library.


Commit MetaInfo

Revision8ea49c3dec9fc78c16619088f4fce2523c9cba71 (tree)
Time2018-07-21 04:33:06
AuthorSimon Forman <sforman@hush...>
CommiterSimon Forman

Log Message

Loop and while combinators.

Change Summary

Incremental Difference

diff -r eb366be1cff7 -r 8ea49c3dec9f joy/library.py
--- a/joy/library.py Thu Jul 19 15:37:35 2018 -0700
+++ b/joy/library.py Fri Jul 20 12:33:06 2018 -0700
@@ -703,6 +703,7 @@
703703
704704
705705 @inscribe
706+@sec_unary_math
706707 @SimpleFunctionWrapper
707708 def succ(S):
708709 '''Increment TOS.'''
@@ -711,6 +712,7 @@
711712
712713
713714 @inscribe
715+@sec_unary_math
714716 @SimpleFunctionWrapper
715717 def pred(S):
716718 '''Decrement TOS.'''
@@ -885,6 +887,7 @@
885887 S_i = Symbol('i')
886888 S_ifte = Symbol('ifte')
887889 S_infra = Symbol('infra')
890+S_pop = Symbol('pop')
888891 S_step = Symbol('step')
889892 S_times = Symbol('times')
890893 S_swaack = Symbol('swaack')
@@ -1398,8 +1401,21 @@
13981401 # return stack, expression, dictionary
13991402
14001403
1404+def loop_true(stack, expression, dictionary):
1405+ quote, (flag, stack) = stack # pylint: disable=unused-variable
1406+ return stack, concat(quote, (S_pop, expression)), dictionary
1407+
1408+def loop_two_true(stack, expression, dictionary):
1409+ quote, (flag, stack) = stack # pylint: disable=unused-variable
1410+ return stack, concat(quote, (S_pop, concat(quote, (S_pop, expression)))), dictionary
1411+
1412+def loop_false(stack, expression, dictionary):
1413+ quote, (flag, stack) = stack # pylint: disable=unused-variable
1414+ return stack, expression, dictionary
1415+
1416+
14011417 @inscribe
1402-#@combinator_effect(_COMB_NUMS(), b1, s6)
1418+@poly_combinator_effect(_COMB_NUMS(), [loop_two_true, loop_true, loop_false], b1, s6)
14031419 @FunctionWrapper
14041420 def loop(stack, expression, dictionary):
14051421 '''
@@ -1523,8 +1539,8 @@
15231539 ifte=(s7, (s6, (s5, s4))),
15241540 nullary=(s7, s6),
15251541 run=(s7, s6),
1526-
15271542 )
1543+EXPECTATIONS['while'] = (s7, (s6, s5))
15281544
15291545
15301546 for name in '''
@@ -1533,6 +1549,7 @@
15331549 ifte
15341550 run
15351551 dupdipd codireco
1552+ while
15361553 '''.split():
15371554 C = _dictionary[name]
15381555 expect = EXPECTATIONS.get(name)
diff -r eb366be1cff7 -r 8ea49c3dec9f joy/utils/types.py
--- a/joy/utils/types.py Thu Jul 19 15:37:35 2018 -0700
+++ b/joy/utils/types.py Fri Jul 20 12:33:06 2018 -0700
@@ -1,7 +1,8 @@
11 # -*- coding: utf_8
2-from logging import getLogger
2+from logging import getLogger, addLevelName
33
44 _log = getLogger(__name__)
5+addLevelName(15, 'hmm')
56
67 from collections import Counter
78 from itertools import imap, chain, product
@@ -585,12 +586,13 @@
585586
586587
587588 def _log_it(e, F):
588- _log.debug(
589- u'%3i %s ∘ %s',
590- len(inspect_stack()),
591- doc_from_stack_effect(*F),
592- expression_to_string(e),
593- )
589+ _log.log(
590+ 15,
591+ u'%3i %s ∘ %s',
592+ len(inspect_stack()),
593+ doc_from_stack_effect(*F),
594+ expression_to_string(e),
595+ )
594596
595597
596598 def infer(*expression):
Show on old repository browser