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
Revision | 8ea49c3dec9fc78c16619088f4fce2523c9cba71 (tree) |
---|---|
Time | 2018-07-21 04:33:06 |
Author | Simon Forman <sforman@hush...> |
Commiter | Simon Forman |
Loop and while combinators.
@@ -703,6 +703,7 @@ | ||
703 | 703 | |
704 | 704 | |
705 | 705 | @inscribe |
706 | +@sec_unary_math | |
706 | 707 | @SimpleFunctionWrapper |
707 | 708 | def succ(S): |
708 | 709 | '''Increment TOS.''' |
@@ -711,6 +712,7 @@ | ||
711 | 712 | |
712 | 713 | |
713 | 714 | @inscribe |
715 | +@sec_unary_math | |
714 | 716 | @SimpleFunctionWrapper |
715 | 717 | def pred(S): |
716 | 718 | '''Decrement TOS.''' |
@@ -885,6 +887,7 @@ | ||
885 | 887 | S_i = Symbol('i') |
886 | 888 | S_ifte = Symbol('ifte') |
887 | 889 | S_infra = Symbol('infra') |
890 | +S_pop = Symbol('pop') | |
888 | 891 | S_step = Symbol('step') |
889 | 892 | S_times = Symbol('times') |
890 | 893 | S_swaack = Symbol('swaack') |
@@ -1398,8 +1401,21 @@ | ||
1398 | 1401 | # return stack, expression, dictionary |
1399 | 1402 | |
1400 | 1403 | |
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 | + | |
1401 | 1417 | @inscribe |
1402 | -#@combinator_effect(_COMB_NUMS(), b1, s6) | |
1418 | +@poly_combinator_effect(_COMB_NUMS(), [loop_two_true, loop_true, loop_false], b1, s6) | |
1403 | 1419 | @FunctionWrapper |
1404 | 1420 | def loop(stack, expression, dictionary): |
1405 | 1421 | ''' |
@@ -1523,8 +1539,8 @@ | ||
1523 | 1539 | ifte=(s7, (s6, (s5, s4))), |
1524 | 1540 | nullary=(s7, s6), |
1525 | 1541 | run=(s7, s6), |
1526 | - | |
1527 | 1542 | ) |
1543 | +EXPECTATIONS['while'] = (s7, (s6, s5)) | |
1528 | 1544 | |
1529 | 1545 | |
1530 | 1546 | for name in ''' |
@@ -1533,6 +1549,7 @@ | ||
1533 | 1549 | ifte |
1534 | 1550 | run |
1535 | 1551 | dupdipd codireco |
1552 | + while | |
1536 | 1553 | '''.split(): |
1537 | 1554 | C = _dictionary[name] |
1538 | 1555 | expect = EXPECTATIONS.get(name) |
@@ -1,7 +1,8 @@ | ||
1 | 1 | # -*- coding: utf_8 |
2 | -from logging import getLogger | |
2 | +from logging import getLogger, addLevelName | |
3 | 3 | |
4 | 4 | _log = getLogger(__name__) |
5 | +addLevelName(15, 'hmm') | |
5 | 6 | |
6 | 7 | from collections import Counter |
7 | 8 | from itertools import imap, chain, product |
@@ -585,12 +586,13 @@ | ||
585 | 586 | |
586 | 587 | |
587 | 588 | 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 | + ) | |
594 | 596 | |
595 | 597 | |
596 | 598 | def infer(*expression): |