Esempio n. 1
0
 def visit_For(self, node):
     self.generic_visit(node)
     try:
         it = eval_ast(node.iter)
     except:
         return node
     l_it = len(it)
     if l_it:
         if (not _loop_breakable(node.body)
                 and l_it*_count_stmts(node.body) < self.limit):
             replacement = []
             for i in it:
                 if not isinstance(i, int):
                     replacement = None
                     break
                 replacement.append(ast.copy_location(
                     ast.Assign(targets=[node.target],
                                value=value_to_ast(i)),
                     node))
                 replacement += deepcopy(node.body)
             if replacement is not None:
                 return replacement
             else:
                 return node
         else:
             return node
     else:
         return node.orelse
Esempio n. 2
0
 def visit_For(self, node):
     self.generic_visit(node)
     try:
         it = eval_ast(node.iter)
     except:
         return node
     l_it = len(it)
     if l_it:
         if (not _loop_breakable(node.body)
                 and l_it * _count_stmts(node.body) < self.limit):
             replacement = []
             for i in it:
                 if not isinstance(i, int):
                     replacement = None
                     break
                 replacement.append(
                     ast.copy_location(
                         ast.Assign(targets=[node.target],
                                    value=value_to_ast(i)), node))
                 replacement += deepcopy(node.body)
             if replacement is not None:
                 return replacement
             else:
                 return node
         else:
             return node
     else:
         return node.orelse
Esempio n. 3
0
def _seconds_to_mu(ref_period, node):
    divided = ast.copy_location(
        ast.BinOp(left=node, op=ast.Div(), right=value_to_ast(ref_period)),
        node)
    return ast.copy_location(
        ast.Call(func=ast.Name("round64", ast.Load()),
                 args=[divided],
                 keywords=[]), divided)
Esempio n. 4
0
def _seconds_to_mu(ref_period, node):
    divided = ast.copy_location(
        ast.BinOp(left=node,
                  op=ast.Div(),
                  right=value_to_ast(ref_period)),
        node)
    return ast.copy_location(
        ast.Call(func=ast.Name("round64", ast.Load()),
                 args=[divided], keywords=[]),
        divided)
Esempio n. 5
0
def _mu_to_seconds(ref_period, node):
    return ast.copy_location(
        ast.BinOp(left=node,
                  op=ast.Mult(),
                  right=value_to_ast(ref_period)),
        node)
Esempio n. 6
0
def lower_time(func_def, initial_time):
    _TimeLowerer().visit(func_def)
    func_def.body.insert(0, ast.copy_location(
        ast.Assign(targets=[ast.Name("now", ast.Store())],
                   value=value_to_ast(int64(initial_time))),
        func_def))
Esempio n. 7
0
def _cycles_to_time(ref_period, node):
    return ast.copy_location(
        ast.BinOp(left=node, op=ast.Mult(), right=value_to_ast(ref_period)),
        node)
Esempio n. 8
0
def _mu_to_seconds(ref_period, node):
    return ast.copy_location(
        ast.BinOp(left=node,
                  op=ast.Mult(),
                  right=value_to_ast(ref_period)),
        node)
Esempio n. 9
0
def _cycles_to_time(ref_period, node):
    return ast.copy_location(
        ast.BinOp(left=node,
                  op=ast.Mult(),
                  right=value_to_ast(ref_period)),
        node)