Skip to content

Commit

Permalink
Upgrade to Python3. (#8)
Browse files Browse the repository at this point in the history
90% of changes is getting eager results of map(), which is otherwise lazy
in Python3 (represented by adhoc "map" object). Beyond that, there're
removals of types which are no longer in Python3 (long, unicode), and
literally the only noticeable change is to account for different AST
structure to encode function parameters.
  • Loading branch information
pfalcon authored and sdiehl committed Mar 28, 2019
1 parent 353280b commit 73c0dad
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions numpile.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def visit_Fun(self, node):
for (arg, ty) in zip(node.args, self.argtys):
arg.type = ty
self.env[arg.id] = ty
map(self.visit, node.body)
list(map(self.visit, node.body))
return TFun(self.argtys, self.retty)

def visit_Noop(self, node):
Expand Down Expand Up @@ -291,7 +291,7 @@ def visit_Loop(self, node):
end = self.visit(node.end)
self.constraints += [(varty, int32), (
begin, int64), (end, int32)]
map(self.visit, node.body)
list(map(self.visit, node.body))

def generic_visit(self, node):
raise NotImplementedError
Expand Down Expand Up @@ -397,7 +397,7 @@ def __call__(self, source):
source = dedent(inspect.getsource(source))
if isinstance(source, types.LambdaType):
source = dedent(inspect.getsource(source))
elif isinstance(source, (str, unicode)):
elif isinstance(source, str):
source = dedent(source)
else:
raise NotImplementedError
Expand All @@ -407,7 +407,7 @@ def __call__(self, source):
return self.visit(self._ast)

def visit_Module(self, node):
body = map(self.visit, node.body)
body = list(map(self.visit, node.body))
return body[0]

def visit_Name(self, node):
Expand All @@ -424,8 +424,8 @@ def visit_Bool(self, node):

def visit_Call(self, node):
name = self.visit(node.func)
args = map(self.visit, node.args)
keywords = map(self.visit, node.keywords)
args = list(map(self.visit, node.args))
keywords = list(map(self.visit, node.keywords))
return App(name, args)

def visit_BinOp(self, node):
Expand All @@ -445,8 +445,8 @@ def visit_Assign(self, node):

def visit_FunctionDef(self, node):
stmts = list(node.body)
stmts = map(self.visit, stmts)
args = map(self.visit, node.args.args)
stmts = list(map(self.visit, stmts))
args = [Var(a.arg) for a in node.args.args]
res = Fun(node.name, args, stmts)
return res

Expand Down Expand Up @@ -475,9 +475,9 @@ def visit_Subscript(self, node):

def visit_For(self, node):
target = self.visit(node.target)
stmts = map(self.visit, node.body)
stmts = list(map(self.visit, node.body))
if node.iter.func.id in {"xrange", "range"}:
args = map(self.visit, node.iter.args)
args = list(map(self.visit, node.iter.args))
else:
raise Exception("Loop must be over range")

Expand Down Expand Up @@ -624,7 +624,7 @@ def specialize(self, val):
return val.type

def const(self, val):
if isinstance(val, (int, long)):
if isinstance(val, int):
return ir.Constant(int_type, val)
elif isinstance(val, float):
return ir.Constant(double_type, val)
Expand Down Expand Up @@ -655,7 +655,7 @@ def visit_Noop(self, node):

def visit_Fun(self, node):
rettype = to_lltype(self.retty)
argtypes = map(to_lltype, self.argtys)
argtypes = list(map(to_lltype, self.argtys))
# Create a unique specialized name
func_name = mangler(node.fname, self.argtys)
self.start_function(func_name, module, rettype, argtypes)
Expand Down Expand Up @@ -689,7 +689,7 @@ def visit_Fun(self, node):
if rettype is not void_type:
self.locals['retval'] = self.builder.alloca(rettype, name="retval")

map(self.visit, node.body)
list(map(self.visit, node.body))
self.end_function()

def visit_Index(self, node):
Expand Down Expand Up @@ -741,7 +741,7 @@ def visit_Loop(self, node):

# Generate the loop body
self.set_block(body_block)
map(self.visit, node.body)
list(map(self.visit, node.body))

# Increment the counter
succ = self.builder.add(self.const(step), self.builder.load(inc))
Expand Down Expand Up @@ -822,7 +822,7 @@ def wrap_function(func, engine):
args = func.type.pointee.args
ret_type = func.type.pointee.return_type
ret_ctype = wrap_type(ret_type)
args_ctypes = map(wrap_type, args)
args_ctypes = list(map(wrap_type, args))

functype = ctypes.CFUNCTYPE(ret_ctype, *args_ctypes)
fptr = engine.get_function_address(func.name)
Expand Down Expand Up @@ -895,7 +895,7 @@ def dispatcher(fn):
def _call_closure(*args):
cargs = list(fn._argtypes_)
pargs = list(args)
rargs = map(wrap_arg, cargs, pargs)
rargs = list(map(wrap_arg, cargs, pargs))
return fn(*rargs)
_call_closure.__name__ = fn.__name__
return _call_closure
Expand Down Expand Up @@ -941,7 +941,7 @@ def arg_pytype(arg):

def specialize(ast, infer_ty, mgu):
def _wrapper(*args):
types = map(arg_pytype, list(args))
types = list(map(arg_pytype, list(args)))
spec_ty = TFun(argtys=types, retty=TVar("$retty"))
unifier = unify(infer_ty, spec_ty)
specializer = compose(unifier, mgu)
Expand Down

0 comments on commit 73c0dad

Please sign in to comment.