当前位置: 首页>>代码示例>>Python>>正文


Python Interpreter.eval方法代码示例

本文整理汇总了Python中interpreter.Interpreter.eval方法的典型用法代码示例。如果您正苦于以下问题:Python Interpreter.eval方法的具体用法?Python Interpreter.eval怎么用?Python Interpreter.eval使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在interpreter.Interpreter的用法示例。


在下文中一共展示了Interpreter.eval方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_override__parent__

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import eval [as 别名]
def test_override__parent__():
    ast = parse("""
k = 10
object a:
    x = 1
    y = 2
    z = k
object b:
    __parent__ = a
    y = 5
    z = y

ax = a x
ay = a y
az = a z
bx = b x
by = b y
bz = b z
""")
    interpreter = Interpreter()
    w_module = interpreter.make_module()
    interpreter.eval(ast, w_module)
    a = w_module.getvalue("a")
    assert a.getvalue('__parent__') is w_module
    assert w_module.getvalue("b").getvalue('__parent__') is a
    assert w_module.getvalue("b").getparents() == [a]
    assert w_module.getvalue("ax").value == 1
    assert w_module.getvalue("ay").value == 2
    assert w_module.getvalue("az").value == 10
    assert w_module.getvalue("bx").value == 1
    assert w_module.getvalue("by").value == 5
    assert w_module.getvalue("bz").value == 5
开发者ID:dynlang-hhu,项目名称:dynlang-hhu.github.com,代码行数:34,代码来源:test_parent.py

示例2: test_args_order

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import eval [as 别名]
def test_args_order():
    ast = parse("""
def f(a, b, c):
    if a:
        4
    else:
        if b:
            8
        else:
            if c:
                15
            else:
                16
w = f(1, 1, 1)
x = f(0, 1, 1)
y = f(0, 0, 1)
z = f(0, 0, 0)
""")

    interpreter = Interpreter()
    w_module = interpreter.make_module()
    interpreter.eval(ast, w_module)
    assert w_module.getvalue("w").value == 4
    assert w_module.getvalue("x").value == 8
    assert w_module.getvalue("y").value == 15
    assert w_module.getvalue("z").value == 16
开发者ID:stepahn,项目名称:slf,代码行数:28,代码来源:test_method_args.py

示例3: test_builtin_simple

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import eval [as 别名]
def test_builtin_simple():
    builtincode = """
x = 1
object None:
    1
def pass:
    None
"""
    # construct the builtin module by running builtincode within the context of
    # a new empty module
    interpreter = Interpreter(builtincode)
    w_module = interpreter.make_module()
    # the parent of a normal module is the builtin module
    builtins = w_module.getparents()[0]
    assert builtins.getvalue('x').value == 1

    ast = parse("""
tx = x
object a:
    pass
ax = a x
""")
    interpreter.eval(ast, w_module)
    assert w_module.getvalue("ax").value == 1
    assert w_module.getvalue("tx").value == 1
开发者ID:stepahn,项目名称:slf,代码行数:27,代码来源:test_builtin.py

示例4: test_inttrait

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import eval [as 别名]
def test_inttrait():
    builtincode = """
object inttrait:
    x = 1
    def maybe_fortytwo:
        if self:
            42
        else:
            x
"""
    interpreter = Interpreter(builtincode)
    w_module = interpreter.make_module()
    # the parent of a normal module is the builtin module
    builtins = w_module.getparents()[0]
    inttrait = builtins.getvalue("inttrait")

    ast = parse("""
x = 5 x # this returns 1, because it looks in the inttrait defined above
m0 = 0 maybe_fortytwo
m1 = x maybe_fortytwo
inttrait x = 2
m2 = 0 maybe_fortytwo
tr = inttrait
""")
    interpreter.eval(ast, w_module)
    x = w_module.getvalue("x")
    assert w_module.getvalue("tr") is inttrait
    # the inttrait is defined in the builtin module, so its __parent__ is that
    # module
    assert inttrait.getparents() == [builtins]
    assert x.value == 1
    assert x.getparents() == [inttrait]
    assert w_module.getvalue("m0").value == 1
    assert w_module.getvalue("m1").value == 42
    assert w_module.getvalue("m2").value == 2
开发者ID:stepahn,项目名称:slf,代码行数:37,代码来源:test_builtin.py

示例5: test_primitive

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import eval [as 别名]
def test_primitive():
    ast = parse("""
k = 10 $int_add(31)
""")
    interpreter = Interpreter()
    w_module = interpreter.make_module()
    interpreter.eval(ast, w_module)
    assert w_module.getvalue("k").value == 41
开发者ID:dynlang-hhu,项目名称:dynlang-hhu.github.com,代码行数:10,代码来源:test_primitive.py

示例6: test_assignment

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import eval [as 别名]
def test_assignment():
    ast = parse("""
x = 1
""")
    interpreter = Interpreter(empty_builtins)
    w_module = interpreter.make_module()
    interpreter.eval(ast, w_module)
    assert w_module.getvalue("x").value == 1
开发者ID:stepahn,项目名称:slf,代码行数:10,代码来源:test_bytecode.py

示例7: test_huge_negative_intliteral

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import eval [as 别名]
def test_huge_negative_intliteral():
    ast = parse("""
x = -10000
""")
    interpreter = Interpreter(empty_builtins)
    w_module = interpreter.make_module()
    interpreter.eval(ast, w_module)
    assert w_module.getvalue("x").value == -10000
开发者ID:stepahn,项目名称:slf,代码行数:10,代码来源:test_bytecode.py

示例8: do_the_twist

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import eval [as 别名]
def do_the_twist(code):
    from simpleparser import parse

    ast = parse(code)
    interpreter = Interpreter()
    w_module = interpreter.make_module()
    interpreter.eval(ast, w_module)
    return w_module
开发者ID:stepahn,项目名称:slf,代码行数:10,代码来源:test_more_builtins.py

示例9: test_primitive

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import eval [as 别名]
def test_primitive():
    ast = parse("""
x = 1 $int_add(2)
""")
    interpreter = Interpreter(empty_builtins)
    w_module = interpreter.make_module()
    interpreter.eval(ast, w_module)
    assert w_module.getvalue("x").value == 3
开发者ID:stepahn,项目名称:slf,代码行数:10,代码来源:test_bytecode.py

示例10: test_pop

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import eval [as 别名]
def test_pop():
    ast = parse("""
x = 1 # the result of this will be popped from the stack
x = 2
""")
    interpreter = Interpreter(empty_builtins)
    w_module = interpreter.make_module()
    interpreter.eval(ast, w_module)
    assert w_module.getvalue("x").value == 2
开发者ID:stepahn,项目名称:slf,代码行数:11,代码来源:test_bytecode.py

示例11: test_objectdefinition_simple

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import eval [as 别名]
def test_objectdefinition_simple():
    ast = parse("""
object x:
    a = 1
    b = 2
""")
    interpreter = Interpreter(empty_builtins)
    w_module = interpreter.make_module()
    interpreter.eval(ast, w_module)
    assert w_module.getvalue("x").getvalue("a").value == 1
    assert w_module.getvalue("x").getvalue("b").value == 2
开发者ID:stepahn,项目名称:slf,代码行数:13,代码来源:test_bytecode.py

示例12: test_capture

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import eval [as 别名]
def test_capture():
    ast = parse("""
k = 10
object a:
    j = k
k = 11
aj = a j
""")
    interpreter = Interpreter()
    w_module = interpreter.make_module()
    interpreter.eval(ast, w_module)
    assert w_module.getvalue("aj").value == 10
开发者ID:dynlang-hhu,项目名称:dynlang-hhu.github.com,代码行数:14,代码来源:test_parent.py

示例13: test_integer_asignment

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import eval [as 别名]
def test_integer_asignment():
    ast = parse("""
x = 42
y = x
x = 4
""")

    interpreter = Interpreter()
    w_module = interpreter.make_module()
    interpreter.eval(ast, w_module)

    assert w_module.getvalue("x").value == 4
    assert w_module.getvalue("y").value == 42
开发者ID:stepahn,项目名称:slf,代码行数:15,代码来源:test_assignment.py

示例14: test_whileloop

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import eval [as 别名]
def test_whileloop():
    ast = parse("""
def f(x):
    sum = 0
    while x:
        sum = sum $int_add(x)
        x = x $int_add(-1)
    sum
x = f(100)
""")
    interpreter = Interpreter(empty_builtins)
    w_module = interpreter.make_module()
    interpreter.eval(ast, w_module)
    assert w_module.getvalue("x").value == 5050
开发者ID:stepahn,项目名称:slf,代码行数:16,代码来源:test_bytecode.py

示例15: test_loop

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import eval [as 别名]
def test_loop():
    ast = parse("""
def f(x):
    r = 0
    while x:
        r = r $int_add(x)
        x = x $int_add(-1)
    r
y = f(100)
""")
    interpreter = Interpreter()
    w_module = interpreter.make_module()
    interpreter.eval(ast, w_module)
    assert w_module.getvalue("y").value == 5050
开发者ID:dynlang-hhu,项目名称:dynlang-hhu.github.com,代码行数:16,代码来源:test_primitive.py


注:本文中的interpreter.Interpreter.eval方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。