本文整理汇总了Python中freeode.interpreter.Interpreter.environment方法的典型用法代码示例。如果您正苦于以下问题:Python Interpreter.environment方法的具体用法?Python Interpreter.environment怎么用?Python Interpreter.environment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类freeode.interpreter.Interpreter
的用法示例。
在下文中一共展示了Interpreter.environment方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_expression_evaluation_5
# 需要导入模块: from freeode.interpreter import Interpreter [as 别名]
# 或者: from freeode.interpreter.Interpreter import environment [as 别名]
def test_expression_evaluation_5(): #IGNORE:C01111
msg = \
'''
Test expression evaluation (returning of partially evaluated expression
when accessing variables)
'''
#skip_test(msg)
print msg
from freeode.ast import RoleVariable, NodeFuncCall
from freeode.interpreter import (IModule, IFloat, ExecutionEnvironment,
Interpreter, istype)
import freeode.simlparser as simlparser
from freeode.util import func #, aa_make_tree
#parse the expression
ps = simlparser.Parser()
ex = ps.parseExpressionStr('a + 2*2')
# print
# print 'AST (parser output): -----------------------------------------------------------'
# print aa_make_tree(ex)
#create module where name lives
mod = IModule()
#create attribute 'a' with no value
val_2 = IFloat()
val_2.__siml_role__ = RoleVariable
mod.a = val_2
# print
# print 'Module where variable is located: --------------------------------------------'
# print aa_make_tree(mod)
#create environment for lookup of variables (stack frame)
env = ExecutionEnvironment()
env.global_scope = mod
#interpret the expression
intp = Interpreter()
intp.environment = env
res = intp.eval(ex)
# print
# print 'Result object - should be an unevaluated expression: --------------------------------------------------------------'
# print aa_make_tree(res)
assert isinstance(res, NodeFuncCall)
assert res.function is func(IFloat.__add__)
assert istype(res, IFloat)