I noticed a lack of an operator module, so I decided to write a basic
one...
def add(a, b):
return a + b
def sub(a, b):
return a - b
def mul(a, b):
return a * b
def div(a, b):
return a / b
def floordiv(a, b):
return int(a / b)
def truediv(a, b):
# no easy way to implement truediv in 2.6.
return a.__truediv__(b)
def and_(a, b):
return a and b
def or_(a, b):
return a or b
def not_(a):
return not a
def inv_(a, b):
return ~a
__add__ = add
__sub__ = sub
__mul__ = mul
__div__ = div
__floordiv__ = floordiv
__truediv__ = truediv
__and__ = and_
__or__ = or_
__not__ = not_
__inv__ = inv_
I got an error while trying to compile it though.
thomas@kamikaze:~/shedskin/lib$ python ../ss.py operator.py
*** SHED SKIN Python-to-C++ Compiler 0.2 ***
Copyright 2005-2009 Mark Dufour; License GNU GPL version 3 (See LICENSE)
Traceback (most recent call last):
File "../ss.py", line 433, in <module>
main()
File "../ss.py", line 428, in main
analysis(name)
File "../ss.py", line 51, in analysis
getgx().main_module = parse_module(getgx().main_mod, ast)
File "/home/thomas/shedskin/graph.py", line 1428, in parse_module
mv.dispatch(mod.ast)
File "/home/thomas/shedskin/graph.py", line 54, in dispatch
ASTVisitor.dispatch(self, node, *args)
File "/usr/lib/python2.6/compiler/visitor.py", line 57, in dispatch
return meth(node, *args)
File "/home/thomas/shedskin/graph.py", line 248, in visitModule
self.visit(n)
File "/home/thomas/shedskin/graph.py", line 54, in dispatch
ASTVisitor.dispatch(self, node, *args)
File "/usr/lib/python2.6/compiler/visitor.py", line 57, in dispatch
return meth(node, *args)
File "/home/thomas/shedskin/graph.py", line 384, in visitFrom
mod = self.importmodules(node.modname, node, True)
File "/home/thomas/shedskin/graph.py", line 360, in importmodules
mod = self.importmodule(subname, subname, node, fake)
File "/home/thomas/shedskin/graph.py", line 367, in importmodule
mod = self.analyzeModule(name, pseudonym, node, fake)
File "/home/thomas/shedskin/graph.py", line 421, in analyzeModule
mod = parse_module(name, None, getmv().module, node)
File "/home/thomas/shedskin/graph.py", line 1428, in parse_module
mv.dispatch(mod.ast)
File "/home/thomas/shedskin/graph.py", line 54, in dispatch
ASTVisitor.dispatch(self, node, *args)
File "/usr/lib/python2.6/compiler/visitor.py", line 57, in dispatch
return meth(node, *args)
File "/home/thomas/shedskin/graph.py", line 242, in visitModule
self.visit(Class(dummy, [], None, Pass()))
File "/home/thomas/shedskin/graph.py", line 54, in dispatch
ASTVisitor.dispatch(self, node, *args)
File "/usr/lib/python2.6/compiler/visitor.py", line 57, in dispatch
return meth(node, *args)
File "/home/thomas/shedskin/graph.py", line 1166, in visitClass
if not getmv().module.builtin and not node in getmv().classnodes:
AttributeError: moduleVisitor instance has no attribute 'classnodes'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python2.6/dist-packages/apport_python_hook.py", line 39,
in apport_excepthook
from apport.packaging_impl import impl as packaging
File "/usr/lib/python2.6/dist-packages/apport/__init__.py", line 1, in
<module>
from apport.report import Report
File "/usr/lib/python2.6/dist-packages/apport/report.py", line 14, in
<module>
import subprocess, tempfile, os.path, urllib, re, pwd, grp, os, sys
File "/usr/lib/python2.6/subprocess.py", line 430, in <module>
import pickle
File "/usr/lib/python2.6/pickle.py", line 827, in <module>
class Unpickler:
File "/usr/lib/python2.6/pickle.py", line 957, in Unpickler
def load_binfloat(self, unpack=struct.unpack):
AttributeError: 'module' object has no attribute 'unpack'
Original exception was:
Traceback (most recent call last):
File "../ss.py", line 433, in <module>
main()
File "../ss.py", line 428, in main
analysis(name)
File "../ss.py", line 51, in analysis
getgx().main_module = parse_module(getgx().main_mod, ast)
File "/home/thomas/shedskin/graph.py", line 1428, in parse_module
mv.dispatch(mod.ast)
File "/home/thomas/shedskin/graph.py", line 54, in dispatch
ASTVisitor.dispatch(self, node, *args)
File "/usr/lib/python2.6/compiler/visitor.py", line 57, in dispatch
return meth(node, *args)
File "/home/thomas/shedskin/graph.py", line 248, in visitModule
self.visit(n)
File "/home/thomas/shedskin/graph.py", line 54, in dispatch
ASTVisitor.dispatch(self, node, *args)
File "/usr/lib/python2.6/compiler/visitor.py", line 57, in dispatch
return meth(node, *args)
File "/home/thomas/shedskin/graph.py", line 384, in visitFrom
mod = self.importmodules(node.modname, node, True)
File "/home/thomas/shedskin/graph.py", line 360, in importmodules
mod = self.importmodule(subname, subname, node, fake)
File "/home/thomas/shedskin/graph.py", line 367, in importmodule
mod = self.analyzeModule(name, pseudonym, node, fake)
File "/home/thomas/shedskin/graph.py", line 421, in analyzeModule
mod = parse_module(name, None, getmv().module, node)
File "/home/thomas/shedskin/graph.py", line 1428, in parse_module
mv.dispatch(mod.ast)
File "/home/thomas/shedskin/graph.py", line 54, in dispatch
ASTVisitor.dispatch(self, node, *args)
File "/usr/lib/python2.6/compiler/visitor.py", line 57, in dispatch
return meth(node, *args)
File "/home/thomas/shedskin/graph.py", line 242, in visitModule
self.visit(Class(dummy, [], None, Pass()))
File "/home/thomas/shedskin/graph.py", line 54, in dispatch
ASTVisitor.dispatch(self, node, *args)
File "/usr/lib/python2.6/compiler/visitor.py", line 57, in dispatch
return meth(node, *args)
File "/home/thomas/shedskin/graph.py", line 1166, in visitClass
if not getmv().module.builtin and not node in getmv().classnodes:
AttributeError: moduleVisitor instance has no attribute 'classnodes'