本文整理汇总了Python中ufora.native.FORA.simulateApply方法的典型用法代码示例。如果您正苦于以下问题:Python FORA.simulateApply方法的具体用法?Python FORA.simulateApply怎么用?Python FORA.simulateApply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ufora.native.FORA
的用法示例。
在下文中一共展示了FORA.simulateApply方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_createInstance_2
# 需要导入模块: from ufora.native import FORA [as 别名]
# 或者: from ufora.native.FORA import simulateApply [as 别名]
def test_createInstance_2(self):
classIvc = FORA.eval(
"""let C = class {
member y;
member x;
};
C"""
).implVal_
x = 1
y = 2
res = ForaNative.simulateApply(
ForaNative.ImplValContainer(
(
classIvc,
makeSymbolIvc("CreateInstance"),
ForaNative.ImplValContainer(y),
ForaNative.ImplValContainer(x),
)
)
)
self.assertIsNotNone(res)
computed_x = ForaNative.simulateApply(
ForaNative.ImplValContainer((res, self.Symbol_member, makeSymbolIvc("x")))
)
self.assertEqual(computed_x, ForaNative.ImplValContainer(x))
示例2: sim
# 需要导入模块: from ufora.native import FORA [as 别名]
# 或者: from ufora.native.FORA import simulateApply [as 别名]
def sim(memberName):
return ForaNative.simulateApply(
ForaNative.ImplValContainer(
(ivc, makeSymbolIvc("Member"),
makeSymbolIvc(memberName))
)
).pyval
示例3: convertClassInstanceDescription
# 需要导入模块: from ufora.native import FORA [as 别名]
# 或者: from ufora.native.FORA import simulateApply [as 别名]
def convertClassInstanceDescription(self, objectId, classInstanceDescription, convertedValues):
classMemberNameToImplVal = {
classMemberName: convertedValues[memberId]
for classMemberName, memberId in
classInstanceDescription.classMemberNameToClassMemberId.iteritems()
}
classImplVal = convertedValues[classInstanceDescription.classId]
if classImplVal.isSymbol():
convertedValues[objectId] = classImplVal
return
memberNames = tuple(sorted(name for name in classMemberNameToImplVal.iterkeys()))
memberValues = tuple(classMemberNameToImplVal[name] for name in memberNames)
convertedValueOrNone = ForaNative.simulateApply(
ForaNative.ImplValContainer(
(classImplVal,
Symbol_CreateInstance,
ForaNative.CreateNamedTuple(memberValues, memberNames))
)
)
if convertedValueOrNone is None:
raise pyfora.PythonToForaConversionError(
("An internal error occurred: " +
"function stage 1 simulation unexpectedly returned None")
)
convertedValues[objectId] = convertedValueOrNone
示例4: __init__
# 需要导入模块: from ufora.native import FORA [as 别名]
# 或者: from ufora.native.FORA import simulateApply [as 别名]
def __init__(self, pyforaBuiltinsModule):
self.pyforaBuiltinsModule = pyforaBuiltinsModule
self.pythonNameToInstance = {}
self.instanceToPythonName = {}
self.pyExceptionClass = pyforaBuiltinsModule.getObjectMember("PyException")
self.pyAbortExceptionClass = pyforaBuiltinsModule.getObjectMember("PyAbortException")
self.pyExceptionClassInstanceName = ForaNative.simulateApply(
ForaNative.ImplValContainer(
(self.pyExceptionClass,
ForaNative.makeSymbol("CreateInstance"),
ForaNative.ImplValContainer(),
ForaNative.ImplValContainer()
)
)
).getClassName()
self.pyAbortExceptionClassInstanceName = ForaNative.simulateApply(
ForaNative.ImplValContainer(
(self.pyAbortExceptionClass,
ForaNative.makeSymbol("CreateInstance"),
ForaNative.ImplValContainer(),
ForaNative.ImplValContainer()
)
)
).getClassName()
self.pythonNameToPyforaName = {}
self.pythonNameToPyforaName.update(
NamedSingletons.pythonNameToPyforaName
)
self.pythonNameToPyforaName.update(
PyAbortSingletons.pythonNameToPyforaName
)
for pyName, pyforaName in self.pythonNameToPyforaName.iteritems():
try:
instance = FORA.ForaValue.FORAValue(pyforaBuiltinsModule).__getattr__(pyforaName).implVal_
except:
logging.error(
"Initializing PyforaSingletonAndExceptionConverter failed:"+
" couldn't find %s in the pyfora builtins", pyforaName)
raise
self.pythonNameToInstance[pyName] = instance
self.instanceToPythonName[instance] = pyName
示例5: test_simulateGetItem
# 需要导入模块: from ufora.native import FORA [as 别名]
# 或者: from ufora.native.FORA import simulateApply [as 别名]
def test_simulateGetItem(self):
n = 42
ivc = FORA.eval("object { m: %s }" % n).implVal_
res = ForaNative.simulateApply(ForaNative.ImplValContainer((ivc, self.Symbol_member, makeSymbolIvc("m"))))
self.assertEqual(res, ForaNative.ImplValContainer(n))
示例6: instantiateException
# 需要导入模块: from ufora.native import FORA [as 别名]
# 或者: from ufora.native.FORA import simulateApply [as 别名]
def instantiateException(self, exceptionTypeName, exceptionArgsAsPyTuple):
"""Return an IVC representing an exception of type given by name 'exceptionTypeName'.
Returns None if 'exceptionTypeName' isn't a singleton.
"""
exceptionTypeInstance = self.convertSingletonByName(exceptionTypeName)
if exceptionTypeInstance is None:
return None
args = (
self.pyExceptionClass,
ForaNative.makeSymbol("CreateInstance"),
exceptionTypeInstance,
exceptionArgsAsPyTuple
)
return ForaNative.simulateApply(ForaNative.ImplValContainer(args))
示例7: convertClassInstanceDescription
# 需要导入模块: from ufora.native import FORA [as 别名]
# 或者: from ufora.native.FORA import simulateApply [as 别名]
def convertClassInstanceDescription(self, objectId, classInstanceDescription):
classMemberNameToImplVal = {
classMemberName: self.convertedValues[memberId]
for classMemberName, memberId in
classInstanceDescription.classMemberNameToClassMemberId.iteritems()
}
classImplVal = self.convertedValues[classInstanceDescription.classId]
#note that we need to strip off the first character of membernames defined in the
#class implval because the object holds 'x' as '@x' so that it doesn't capture
#all references to 'x'
classMembersInForaDeclarationOrder = \
[str(val)[1:] for val in classImplVal.getDataMembers]
assert set(classMembersInForaDeclarationOrder) == \
set(classMemberNameToImplVal.keys()), "%s vs %s" % (
set(classMembersInForaDeclarationOrder),
set(classMemberNameToImplVal.keys())
)
classMemberImplVals = []
for classMemberName in classMembersInForaDeclarationOrder:
ivc = classMemberNameToImplVal[classMemberName]
classMemberImplVals.append(ivc)
applyArgs = [classImplVal, Symbol_CreateInstance] + classMemberImplVals
convertedValueOrNone = ForaNative.simulateApply(
ForaNative.ImplValContainer(
tuple(applyArgs)
)
)
if convertedValueOrNone is None:
raise pyfora.PythonToForaConversionError(
("An internal error occurred: " +
"function stage 1 simulation unexpectedly returned None")
)
self.convertedValues[objectId] = convertedValueOrNone