forked from M-Labs/artiq
1
0
Fork 0

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

View File

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

View File

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

View File

@ -23,8 +23,7 @@ def _seconds_to_mu(ref_period, node):
node) node)
return ast.copy_location( return ast.copy_location(
ast.Call(func=ast.Name("round64", ast.Load()), ast.Call(func=ast.Name("round64", ast.Load()),
args=[divided], args=[divided], keywords=[]),
keywords=[], starargs=[], kwargs=[]),
divided) divided)
@ -77,12 +76,10 @@ class _TimeQuantizer(ast.NodeTransformer):
right=ast.Num(1000)) right=ast.Num(1000))
time_int = ast.Call( time_int = ast.Call(
func=ast.Name("round", ast.Load()), func=ast.Name("round", ast.Load()),
args=[time], args=[time], keywords=[])
keywords=[], starargs=None, kwargs=None)
syscall_set = ast.Call( syscall_set = ast.Call(
func=ast.Name("syscall", ast.Load()), func=ast.Name("syscall", ast.Load()),
args=[ast.Str("watchdog_set"), time_int], args=[ast.Str("watchdog_set"), time_int], keywords=[])
keywords=[], starargs=None, kwargs=None)
stmt_set = ast.copy_location( stmt_set = ast.copy_location(
ast.Assign(targets=[ast.Name(idname, ast.Store())], ast.Assign(targets=[ast.Name(idname, ast.Store())],
value=syscall_set), value=syscall_set),
@ -91,8 +88,7 @@ class _TimeQuantizer(ast.NodeTransformer):
syscall_clear = ast.Call( syscall_clear = ast.Call(
func=ast.Name("syscall", ast.Load()), func=ast.Name("syscall", ast.Load()),
args=[ast.Str("watchdog_clear"), args=[ast.Str("watchdog_clear"),
ast.Name(idname, ast.Load())], ast.Name(idname, ast.Load())], keywords=[])
keywords=[], starargs=None, kwargs=None)
stmt_clear = ast.copy_location(ast.Expr(syscall_clear), node) stmt_clear = ast.copy_location(ast.Expr(syscall_clear), node)
node.items[0] = ast.withitem( 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 if isinstance(value, core_language.int64): # must be before int
return ast.Call( return ast.Call(
func=ast.Name("int64", ast.Load()), func=ast.Name("int64", ast.Load()),
args=[ast.Num(int(value))], args=[ast.Num(int(value))], keywords=[])
keywords=[], starargs=None, kwargs=None)
elif isinstance(value, bool) or value is None: elif isinstance(value, bool) or value is None:
# must also be before int # must also be before int
# isinstance(True/False, int) == True # isinstance(True/False, int) == True
@ -51,8 +50,7 @@ def value_to_ast(value):
elif isinstance(value, Fraction): elif isinstance(value, Fraction):
return ast.Call( return ast.Call(
func=ast.Name("Fraction", ast.Load()), func=ast.Name("Fraction", ast.Load()),
args=[ast.Num(value.numerator), ast.Num(value.denominator)], args=[ast.Num(value.numerator), ast.Num(value.denominator)], keywords=[])
keywords=[], starargs=None, kwargs=None)
elif isinstance(value, str): elif isinstance(value, str):
return ast.Str(value) return ast.Str(value)
elif isinstance(value, list): elif isinstance(value, list):

View File

@ -211,20 +211,6 @@ class _Unparser:
else: else:
comma = True comma = True
self.dispatch(e) 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.write(")")
self.enter() self.enter()
@ -466,20 +452,6 @@ class _Unparser:
else: else:
comma = True comma = True
self.dispatch(e) 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.write(")")
def _Subscript(self, t): def _Subscript(self, t):
@ -571,6 +543,9 @@ class _Unparser:
self.dispatch(t.kwarg.annotation) self.dispatch(t.kwarg.annotation)
def _keyword(self, t): def _keyword(self, t):
if t.arg is None:
self.write("**")
else:
self.write(t.arg) self.write(t.arg)
self.write("=") self.write("=")
self.dispatch(t.value) self.dispatch(t.value)