Permalink
Browse files

Compile Oil's stdlib dependencies with OPy.

Had to cahnge/remove some print statements.

Also compiler OPy's stdlib dependencies.  Additional dependencies:
atexit, collections, copy, dis, heapq.

Now Running into an encoding issue.
  • Loading branch information...
Andy Chu
Andy Chu committed Feb 25, 2018
1 parent 829429b commit 34c7ebc4e7b2781b3383bc06fb3f280bc2ab124e
@@ -1,3 +1,4 @@
from __future__ import print_function # for OPy compiler
"""
atexit.py - allow programmer to define multiple exit functions to be executed
upon normal program termination.
@@ -26,7 +27,7 @@ def _run_exitfuncs():
exc_info = sys.exc_info()
except:
import traceback
print >> sys.stderr, "Error in atexit._run_exitfuncs:"
print("Error in atexit._run_exitfuncs:", file=sys.stderr)
traceback.print_exc()
exc_info = sys.exc_info()
@@ -53,11 +54,11 @@ def register(func, *targs, **kargs):
if __name__ == "__main__":
def x1():
print "running x1"
print("running x1")
def x2(n):
print "running x2(%r)" % (n,)
print("running x2(%r)" % (n,))
def x3(n, kwd=None):
print "running x3(%r, kwd=%r)" % (n, kwd)
print("running x3(%r, kwd=%r)" % (n, kwd))
register(x1)
register(x2, 12)
@@ -1,3 +1,4 @@
from __future__ import print_function # for OPy compiler
'''This module implements specialized container datatypes providing
alternatives to Python's general purpose built-in containers, dict,
list, set, and tuple.
@@ -376,7 +377,7 @@ def namedtuple(typename, field_names, verbose=False, rename=False):
for index, name in enumerate(field_names))
)
if verbose:
print class_definition
print(class_definition)
# Execute the template string in a temporary namespace and support
# tracing utilities by setting a value for frame.f_globals['__name__']
@@ -723,7 +724,7 @@ def __str__(self):
return 'Point: x=%6.3f y=%6.3f hypot=%6.3f' % (self.x, self.y, self.hypot)
for p in Point(3, 4), Point(14, 5/7.):
print p
print(p)
class Point(namedtuple('Point', 'x y')):
'Point class with optimized _make() and _replace() without error-checking'
@@ -732,11 +733,11 @@ class Point(namedtuple('Point', 'x y')):
def _replace(self, _map=map, **kwds):
return self._make(_map(kwds.get, ('x', 'y'), self))
print Point(11, 22)._replace(x=100)
print(Point(11, 22)._replace(x=100))
Point3D = namedtuple('Point3D', Point._fields + ('z',))
print Point3D.__doc__
print(Point3D.__doc__)
import doctest
TestResults = namedtuple('TestResults', 'failed attempted')
print TestResults(*doctest.testmod())
print(TestResults(*doctest.testmod()))
View
@@ -1,3 +1,4 @@
from __future__ import print_function # for OPy compiler
"""Generic (shallow and deep) copying operations.
Interface summary:
@@ -370,11 +371,11 @@ def _test():
l = [None, 1, 2L, 3.14, 'xyzzy', (1, 2L), [3.14, 'abc'],
{'abc': 'ABC'}, (), [], {}]
l1 = copy(l)
print l1==l
print(l1==l)
l1 = map(copy, l)
print l1==l
print(l1==l)
l1 = deepcopy(l)
print l1==l
print(l1==l)
class C:
def __init__(self, arg=None):
self.a = 1
@@ -398,26 +399,26 @@ def __deepcopy__(self, memo=None):
c = C('argument sketch')
l.append(c)
l2 = copy(l)
print l == l2
print l
print l2
print(l == l2)
print(l)
print(l2)
l2 = deepcopy(l)
print l == l2
print l
print l2
print(l == l2)
print(l)
print(l2)
l.append({l[1]: l, 'xyz': l[2]})
l3 = copy(l)
import repr
print map(repr.repr, l)
print map(repr.repr, l1)
print map(repr.repr, l2)
print map(repr.repr, l3)
print(map(repr.repr, l))
print(map(repr.repr, l1))
print(map(repr.repr, l2))
print(map(repr.repr, l3))
l3 = deepcopy(l)
import repr
print map(repr.repr, l)
print map(repr.repr, l1)
print map(repr.repr, l2)
print map(repr.repr, l3)
print(map(repr.repr, l))
print(map(repr.repr, l1))
print(map(repr.repr, l2))
print(map(repr.repr, l3))
class odict(dict):
def __init__(self, d = {}):
self.a = 99
@@ -427,7 +428,7 @@ def __setitem__(self, k, i):
self.a
o = odict({"A" : "B"})
x = deepcopy(o)
print(o, x)
print((o, x))
if __name__ == '__main__':
_test()
View
@@ -1,3 +1,4 @@
from __future__ import print_function # for OPy compiler
"""Disassembler of Python byte code into mnemonics."""
import sys
@@ -33,12 +34,12 @@ def dis(x=None):
items.sort()
for name, x1 in items:
if isinstance(x1, _have_code):
print "Disassembly of %s:" % name
print("Disassembly of %s:" % name)
try:
dis(x1)
except TypeError, msg:
print "Sorry:", msg
print
print("Sorry:", msg)
print()
elif hasattr(x, 'co_code'):
disassemble(x)
elif isinstance(x, str):
@@ -72,40 +73,40 @@ def disassemble(co, lasti=-1):
op = ord(c)
if i in linestarts:
if i > 0:
print
print "%3d" % linestarts[i],
print()
print("%3d" % linestarts[i], end=' ')
else:
print ' ',
if i == lasti: print '-->',
else: print ' ',
if i in labels: print '>>',
else: print ' ',
print repr(i).rjust(4),
print opname[op].ljust(20),
print(' ', end=' ')
if i == lasti: print('-->', end=' ')
else: print(' ', end=' ')
if i in labels: print('>>', end=' ')
else: print(' ', end=' ')
print(repr(i).rjust(4), end=' ')
print(opname[op].ljust(20), end=' ')
i = i+1
if op >= HAVE_ARGUMENT:
oparg = ord(code[i]) + ord(code[i+1])*256 + extended_arg
extended_arg = 0
i = i+2
if op == EXTENDED_ARG:
extended_arg = oparg*65536L
print repr(oparg).rjust(5),
print(repr(oparg).rjust(5), end=' ')
if op in hasconst:
print '(' + repr(co.co_consts[oparg]) + ')',
print('(' + repr(co.co_consts[oparg]) + ')', end=' ')
elif op in hasname:
print '(' + co.co_names[oparg] + ')',
print('(' + co.co_names[oparg] + ')', end=' ')
elif op in hasjrel:
print '(to ' + repr(i + oparg) + ')',
print('(to ' + repr(i + oparg) + ')', end=' ')
elif op in haslocal:
print '(' + co.co_varnames[oparg] + ')',
print('(' + co.co_varnames[oparg] + ')', end=' ')
elif op in hascompare:
print '(' + cmp_op[oparg] + ')',
print('(' + cmp_op[oparg] + ')', end=' ')
elif op in hasfree:
if free is None:
free = co.co_cellvars + co.co_freevars
print '(' + free[oparg] + ')',
print
print('(' + free[oparg] + ')', end=' ')
print()
def disassemble_string(code, lasti=-1, varnames=None, names=None,
constants=None):
@@ -115,37 +116,37 @@ def disassemble_string(code, lasti=-1, varnames=None, names=None,
while i < n:
c = code[i]
op = ord(c)
if i == lasti: print '-->',
else: print ' ',
if i in labels: print '>>',
else: print ' ',
print repr(i).rjust(4),
print opname[op].ljust(15),
if i == lasti: print('-->', end=' ')
else: print(' ', end=' ')
if i in labels: print('>>', end=' ')
else: print(' ', end=' ')
print(repr(i).rjust(4), end=' ')
print(opname[op].ljust(15), end=' ')
i = i+1
if op >= HAVE_ARGUMENT:
oparg = ord(code[i]) + ord(code[i+1])*256
i = i+2
print repr(oparg).rjust(5),
print(repr(oparg).rjust(5), end=' ')
if op in hasconst:
if constants:
print '(' + repr(constants[oparg]) + ')',
print('(' + repr(constants[oparg]) + ')', end=' ')
else:
print '(%d)'%oparg,
print('(%d)'%oparg, end=' ')
elif op in hasname:
if names is not None:
print '(' + names[oparg] + ')',
print('(' + names[oparg] + ')', end=' ')
else:
print '(%d)'%oparg,
print('(%d)'%oparg, end=' ')
elif op in hasjrel:
print '(to ' + repr(i + oparg) + ')',
print('(to ' + repr(i + oparg) + ')', end=' ')
elif op in haslocal:
if varnames:
print '(' + varnames[oparg] + ')',
print('(' + varnames[oparg] + ')', end=' ')
else:
print '(%d)' % oparg,
print('(%d)' % oparg, end=' ')
elif op in hascompare:
print '(' + cmp_op[oparg] + ')',
print
print('(' + cmp_op[oparg] + ')', end=' ')
print()
disco = disassemble # XXX For backwards compatibility
@@ -1,3 +1,4 @@
from __future__ import print_function # for OPy compiler
# -*- coding: latin-1 -*-
"""Heap queue algorithm (a.k.a. priority queue).
@@ -479,7 +480,7 @@ def nlargest(n, iterable, key=None):
sort = []
while heap:
sort.append(heappop(heap))
print sort
print(sort)
import doctest
doctest.testmod()
@@ -1615,5 +1615,6 @@ def platform(aliased=0, terse=0):
# Default is to print the aliased verbose platform string
terse = ('terse' in sys.argv or '--terse' in sys.argv)
aliased = (not 'nonaliased' in sys.argv and not '--nonaliased' in sys.argv)
print platform(aliased,terse)
# Commented out because OPy compiler doesn't like print statements.
#print platform(aliased,terse)
sys.exit(0)
@@ -260,4 +260,5 @@ def dump(f, d, prefix):
f.write("#define SRE_INFO_CHARSET %d\n" % SRE_INFO_CHARSET)
f.close()
print "done"
# Commented out because OPy compiler doesn't like print statements.
#print "done"
@@ -1,3 +1,5 @@
from __future__ import print_function # for OPy compiler
#
# Secret Labs' Regular Expression Engine
#
@@ -98,40 +100,40 @@ def __init__(self, pattern, data=None):
def dump(self, level=0):
seqtypes = (tuple, list)
for op, av in self.data:
print level*" " + op,
print(level*" " + op, end=' ')
if op == IN:
# member sublanguage
print
print()
for op, a in av:
print (level+1)*" " + op, a
print((level+1)*" " + op, a)
elif op == BRANCH:
print
print()
for i, a in enumerate(av[1]):
if i:
print level*" " + "or"
print(level*" " + "or")
a.dump(level+1)
elif op == GROUPREF_EXISTS:
condgroup, item_yes, item_no = av
print condgroup
print(condgroup)
item_yes.dump(level+1)
if item_no:
print level*" " + "else"
print(level*" " + "else")
item_no.dump(level+1)
elif isinstance(av, seqtypes):
nl = 0
for a in av:
if isinstance(a, SubPattern):
if not nl:
print
print()
a.dump(level+1)
nl = 1
else:
print a,
print(a, end=' ')
nl = 0
if not nl:
print
print()
else:
print av
print(av)
def __repr__(self):
return repr(self.data)
def __len__(self):
View
@@ -18,7 +18,8 @@ def testModules(self):
('simplejson',
'/home/andy/dev/simplejson-2.1.5/simplejson/__init__.py')
]
app_deps.PrintManifest(pairs, sys.stdout, sys.stdout)
for mod_type, x, y in app_deps.FilterModules(pairs):
print mod_type, x, y
if __name__ == '__main__':
Oops, something went wrong.

0 comments on commit 34c7ebc

Please sign in to comment.