forked from M-Labs/artiq
1
0
Fork 0

compiler/lower_time: adapt to new unit system

This commit is contained in:
Sebastien Bourdeauducq 2014-08-13 17:59:53 +08:00
parent 9cbf31153a
commit 899a034204
1 changed files with 3 additions and 2 deletions

View File

@ -1,4 +1,5 @@
import ast import ast
from artiq.compiler.tools import value_to_ast
class _TimeLowerer(ast.NodeTransformer): class _TimeLowerer(ast.NodeTransformer):
def __init__(self, ref_period): def __init__(self, ref_period):
@ -6,9 +7,9 @@ class _TimeLowerer(ast.NodeTransformer):
def visit_Call(self, node): def visit_Call(self, node):
if isinstance(node.func, ast.Name) \ if isinstance(node.func, ast.Name) \
and node.func.id == "Quantity" and node.args[1].id == "base_s_unit": and node.func.id == "Quantity" and node.args[1].id == "s_unit":
return ast.copy_location( return ast.copy_location(
ast.BinOp(left=node.args[0], op=ast.FloorDiv(), right=ast.Num(self.ref_period.amount)), ast.BinOp(left=node.args[0], op=ast.Div(), right=value_to_ast(self.ref_period.amount)),
node) node)
elif isinstance(node.func, ast.Name) and node.func.id == "now": elif isinstance(node.func, ast.Name) and node.func.id == "now":
return ast.copy_location(ast.Name("now", ast.Load()), node) return ast.copy_location(ast.Name("now", ast.Load()), node)