示例#1
0
文件: tools.py 项目: neuroidss/artiq
def eval_constant(node):
    if isinstance(node, ast.Num):
        return node.n
    elif isinstance(node, ast.Str):
        return node.s
    elif isinstance(node, ast.NameConstant):
        return node.value
    elif isinstance(node, ast.Call):
        funcname = node.func.id
        if funcname == "int64":
            return core_language.int64(eval_constant(node.args[0]))
        elif funcname == "Fraction":
            numerator = eval_constant(node.args[0])
            denominator = eval_constant(node.args[1])
            return Fraction(numerator, denominator)
        elif funcname == "Quantity":
            amount, unit = node.args
            amount = eval_constant(amount)
            try:
                unit = getattr(units, unit.id)
            except:
                raise NotConstant
            return units.Quantity(amount, unit)
        else:
            raise NotConstant
    else:
        raise NotConstant
示例#2
0
文件: tools.py 项目: yuyichao/artiq
def eval_constant(node):
    if isinstance(node, ast.Num):
        return node.n
    elif isinstance(node, ast.Str):
        return node.s
    elif isinstance(node, ast.NameConstant):
        return node.value
    elif isinstance(node, ast.Call):
        funcname = node.func.id
        if funcname == "int64":
            return core_language.int64(eval_constant(node.args[0]))
        elif funcname == "Fraction":
            numerator = eval_constant(node.args[0])
            denominator = eval_constant(node.args[1])
            return Fraction(numerator, denominator)
        elif funcname == "Quantity":
            amount, unit = node.args
            amount = eval_constant(amount)
            try:
                unit = getattr(units, unit.id)
            except:
                raise NotConstant
            return units.Quantity(amount, unit)
        else:
            raise NotConstant
    else:
        raise NotConstant
示例#3
0
def _base_types(choice):
    a = 2          # promoted later to int64
    b = a + 1      # initially int32, becomes int64 after a is promoted
    c = b//2       # initially int32, becomes int64 after b is promoted
    d = 4 and 5    # stays int32
    x = int64(7)
    a += x         # promotes a to int64
    foo = True | True or False
    bar = None
    myf = 4.5
    myf2 = myf + x

    if choice and foo and not bar:
        return d
    elif myf2:
        return x + c
    else:
        return int64(8)
示例#4
0
文件: py2llvm.py 项目: fallen/artiq
def _base_types(choice):
    a = 2          # promoted later to int64
    b = a + 1      # initially int32, becomes int64 after a is promoted
    c = b//2       # initially int32, becomes int64 after b is promoted
    d = 4 and 5    # stays int32
    x = int64(7)
    a += x         # promotes a to int64
    foo = True | True or False
    bar = None
    myf = 4.5
    myf2 = myf + x

    if choice and foo and not bar:
        return d
    elif myf2:
        return x + c
    else:
        return int64(8)
示例#5
0
def eval_constant(node):
    if isinstance(node, ast.Num):
        return node.n
    elif isinstance(node, ast.Str):
        return node.s
    elif isinstance(node, ast.NameConstant):
        return node.value
    elif isinstance(node, ast.Call):
        funcname = node.func.id
        if funcname == "int64":
            return core_language.int64(eval_constant(node.args[0]))
        elif funcname == "Fraction":
            numerator = eval_constant(node.args[0])
            denominator = eval_constant(node.args[1])
            return Fraction(numerator, denominator)
        else:
            raise NotConstant
    else:
        raise NotConstant
示例#6
0
def test_list_types():
    a = [0, 0, 0, 0, 0]
    for i in range(2):
        a[i] = int64(8)
    return a
示例#7
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))
示例#8
0
文件: py2llvm.py 项目: fallen/artiq
def test_list_types():
    a = [0, 0, 0, 0, 0]
    for i in range(2):
        a[i] = int64(8)
    return a
示例#9
0
文件: py2llvm.py 项目: yuyichao/artiq
def test_array_types():
    a = array(0, 5)
    for i in range(2):
        a[i] = int64(8)
    return a