2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-25 03:08:27 +08:00

Adapt old compiler to Python 3.5 AST.

This commit is contained in:
whitequark 2015-10-12 14:45:11 +03:00
parent 36c3f022aa
commit 9e64f7dc3a
6 changed files with 16 additions and 52 deletions

View File

@ -356,8 +356,7 @@ class Function:
exception_id = self.mappers.exception.encode(exception_class)
return ast.copy_location(
ast.Call(func=ast.Name("EncodedException", ast.Load()),
args=[value_to_ast(exception_id)],
keywords=[], starargs=None, kwargs=None),
args=[value_to_ast(exception_id)], keywords=[]),
e)
def code_visit_Raise(self, node):
@ -514,8 +513,7 @@ def get_attr_writeback(attribute_namespace, rpc_mapper, loc_node):
arg3 = ast.copy_location(
ast.Name(attr_info.mangled_name, ast.Load()), loc_node)
call = ast.copy_location(
ast.Call(func=func, args=[arg1, arg2, arg3],
keywords=[], starargs=None, kwargs=None),
ast.Call(func=func, args=[arg1, arg2, arg3], keywords=[]),
loc_node)
expr = ast.copy_location(ast.Expr(call), loc_node)
attr_writeback.append(expr)

View File

@ -71,8 +71,7 @@ def _interleave_timelines(timelines):
delay_stmt = ast.copy_location(
ast.Expr(ast.Call(
func=ast.Name("delay_mu", ast.Load()),
args=[value_to_ast(dt)],
keywords=[], starargs=[], kwargs=[])),
args=[value_to_ast(dt)], keywords=[])),
ref_stmt)
r.append(delay_stmt)
else:

View File

@ -46,14 +46,12 @@ def lower_time(func_def):
_TimeLowerer().visit(func_def)
call_init = ast.Call(
func=ast.Name("syscall", ast.Load()),
args=[ast.Str("now_init")],
keywords=[], starargs=None, kwargs=None)
args=[ast.Str("now_init")], keywords=[])
stmt_init = ast.Assign(targets=[ast.Name("now", ast.Store())],
value=call_init)
call_save = ast.Call(
func=ast.Name("syscall", ast.Load()),
args=[ast.Str("now_save"), ast.Name("now", ast.Load())],
keywords=[], starargs=None, kwargs=None)
args=[ast.Str("now_save"), ast.Name("now", ast.Load())], keywords=[])
stmt_save = ast.Expr(call_save)
func_def.body = [
stmt_init,

View File

@ -23,8 +23,7 @@ def _seconds_to_mu(ref_period, node):
node)
return ast.copy_location(
ast.Call(func=ast.Name("round64", ast.Load()),
args=[divided],
keywords=[], starargs=[], kwargs=[]),
args=[divided], keywords=[]),
divided)
@ -77,12 +76,10 @@ class _TimeQuantizer(ast.NodeTransformer):
right=ast.Num(1000))
time_int = ast.Call(
func=ast.Name("round", ast.Load()),
args=[time],
keywords=[], starargs=None, kwargs=None)
args=[time], keywords=[])
syscall_set = ast.Call(
func=ast.Name("syscall", ast.Load()),
args=[ast.Str("watchdog_set"), time_int],
keywords=[], starargs=None, kwargs=None)
args=[ast.Str("watchdog_set"), time_int], keywords=[])
stmt_set = ast.copy_location(
ast.Assign(targets=[ast.Name(idname, ast.Store())],
value=syscall_set),
@ -91,8 +88,7 @@ class _TimeQuantizer(ast.NodeTransformer):
syscall_clear = ast.Call(
func=ast.Name("syscall", ast.Load()),
args=[ast.Str("watchdog_clear"),
ast.Name(idname, ast.Load())],
keywords=[], starargs=None, kwargs=None)
ast.Name(idname, ast.Load())], keywords=[])
stmt_clear = ast.copy_location(ast.Expr(syscall_clear), node)
node.items[0] = ast.withitem(

View File

@ -40,8 +40,7 @@ def value_to_ast(value):
if isinstance(value, core_language.int64): # must be before int
return ast.Call(
func=ast.Name("int64", ast.Load()),
args=[ast.Num(int(value))],
keywords=[], starargs=None, kwargs=None)
args=[ast.Num(int(value))], keywords=[])
elif isinstance(value, bool) or value is None:
# must also be before int
# isinstance(True/False, int) == True
@ -51,8 +50,7 @@ def value_to_ast(value):
elif isinstance(value, Fraction):
return ast.Call(
func=ast.Name("Fraction", ast.Load()),
args=[ast.Num(value.numerator), ast.Num(value.denominator)],
keywords=[], starargs=None, kwargs=None)
args=[ast.Num(value.numerator), ast.Num(value.denominator)], keywords=[])
elif isinstance(value, str):
return ast.Str(value)
elif isinstance(value, list):

View File

@ -211,20 +211,6 @@ class _Unparser:
else:
comma = True
self.dispatch(e)
if t.starargs:
if comma:
self.write(", ")
else:
comma = True
self.write("*")
self.dispatch(t.starargs)
if t.kwargs:
if comma:
self.write(", ")
else:
comma = True
self.write("**")
self.dispatch(t.kwargs)
self.write(")")
self.enter()
@ -466,20 +452,6 @@ class _Unparser:
else:
comma = True
self.dispatch(e)
if t.starargs:
if comma:
self.write(", ")
else:
comma = True
self.write("*")
self.dispatch(t.starargs)
if t.kwargs:
if comma:
self.write(", ")
else:
comma = True
self.write("**")
self.dispatch(t.kwargs)
self.write(")")
def _Subscript(self, t):
@ -571,8 +543,11 @@ class _Unparser:
self.dispatch(t.kwarg.annotation)
def _keyword(self, t):
self.write(t.arg)
self.write("=")
if t.arg is None:
self.write("**")
else:
self.write(t.arg)
self.write("=")
self.dispatch(t.value)
def _Lambda(self, t):