futurize stage1 core

This commit is contained in:
Simon Forman 2020-04-23 23:16:45 -07:00
parent 8d0d0de897
commit b0df80f3e6
4 changed files with 30 additions and 24 deletions

View File

@ -17,15 +17,16 @@
# You should have received a copy of the GNU General Public License
# along with Thun. If not see <http://www.gnu.org/licenses/>.
#
from __future__ import print_function
from .library import initialize
from .joy import repl
print '''\
print('''\
Thun - Copyright © 2017 Simon Forman
This program comes with ABSOLUTELY NO WARRANTY; for details type "warranty".
This is free software, and you are welcome to redistribute it
under certain conditions; type "sharing" for details.
Type "words" to see a list of all words, and "[<name>] help" to print the
docs for a word.
'''
''')
stack = repl(dictionary=initialize())

View File

@ -23,6 +23,7 @@ functions. Its main export is a Python function initialize() that
returns a dictionary of Joy functions suitable for use with the joy()
function.
'''
from __future__ import print_function
from logging import getLogger
_log = getLogger(__name__)

View File

@ -10,9 +10,11 @@ functions, during inference? Could I write out better code that way?
In any event, I am proceeding with this sort of ad hoc way for now.
'''
from __future__ import print_function
from joy.parser import text_to_expression, Symbol
from joy.utils.stack import concat, iter_stack, list_to_stack
from joy.library import SimpleFunctionWrapper, YIN_STACK_EFFECTS
from functools import reduce
def import_yin():
@ -29,7 +31,7 @@ class InfiniteStack(tuple):
n = n + 1 if m is None else m
_NAMES = _names()
_NAMES.next()
next(_NAMES)
names = _NAMES.next
reset = lambda _, _n=_NAMES: _n.send(-1)
@ -82,7 +84,7 @@ def code_gen(code):
def coalesce_pops(code):
code.sort(key=lambda p: p[0] != 'pop') # All pops to the front.
try: index = (i for i, t in enumerate(code) if t[0] != 'pop').next()
try: index = next((i for i, t in enumerate(code) if t[0] != 'pop'))
except StopIteration: return
code[:index] = [tuple(['pop'] + [t for _, t in code[:index][::-1]])]
@ -216,21 +218,21 @@ for name in '''
'''
for name in sorted(D):
print name,
print(name, end=' ')
## print compile_yinyang(name, name)
print '-' * 100
print('-' * 100)
print compile_yinyang('mul_', 'mul')
print compile_yinyang('pop', 'pop')
print compile_yinyang('ppm', 'popop mul')
print compile_yinyang('sqr', 'dup mul')
print compile_yinyang('foo', 'dup 23 sub mul')
print compile_yinyang('four_mul', 'mul mul mul mul')
print compile_yinyang('baz', 'mul dup sub dup')
print compile_yinyang('to_the_fifth_power', 'dup dup mul dup mul mul')
print compile_yinyang('dup3', 'dup dup dup')
print compile_yinyang('df2m', 'dup first_two mul')
print compile_yinyang('sqr_first', 'uncons swap dup mul swons')
print compile_yinyang('0BAD', 'uncons dup mul')
print compile_yinyang('uncons', 'uncons')
print(compile_yinyang('mul_', 'mul'))
print(compile_yinyang('pop', 'pop'))
print(compile_yinyang('ppm', 'popop mul'))
print(compile_yinyang('sqr', 'dup mul'))
print(compile_yinyang('foo', 'dup 23 sub mul'))
print(compile_yinyang('four_mul', 'mul mul mul mul'))
print(compile_yinyang('baz', 'mul dup sub dup'))
print(compile_yinyang('to_the_fifth_power', 'dup dup mul dup mul mul'))
print(compile_yinyang('dup3', 'dup dup dup'))
print(compile_yinyang('df2m', 'dup first_two mul'))
print(compile_yinyang('sqr_first', 'uncons swap dup mul swons'))
print(compile_yinyang('0BAD', 'uncons dup mul'))
print(compile_yinyang('uncons', 'uncons'))

View File

@ -17,7 +17,9 @@
# You should have received a copy of the GNU General Public License
# along with Thun. If not see <http://www.gnu.org/licenses/>.
#
from __future__ import print_function
from logging import getLogger, addLevelName
from functools import reduce
_log = getLogger(__name__)
addLevelName(15, 'hmm')
@ -721,20 +723,20 @@ def combinator_effect(number, *expect):
def show(DEFS):
for name, stack_effect_comment in sorted(DEFS.iteritems()):
t = ' *'[compilable(stack_effect_comment)]
print name, '=', doc_from_stack_effect(*stack_effect_comment), t
print(name, '=', doc_from_stack_effect(*stack_effect_comment), t)
def generate_library_code(DEFS, f=None):
if f is None:
import sys
f = sys.stdout
print >> f, '# GENERATED FILE. DO NOT EDIT.\n'
print('# GENERATED FILE. DO NOT EDIT.\n', file=f)
for name, stack_effect_comment in sorted(DEFS.iteritems()):
if not compilable(stack_effect_comment):
continue
print >> f
print >> f, compile_(name, stack_effect_comment)
print >> f
print(file=f)
print(compile_(name, stack_effect_comment), file=f)
print(file=f)
def poly_combinator_effect(number, effect_funcs, *expect):