def evaluate(self, expr, args, assignments, lets, binding, statementTerm): exprAsFunction = expr.toFunction() args = [ exprAsFunction.implVal_, ForaValue.FORAValue.symbol_Call.implVal_ ] + args res = Evaluator.evaluator().evaluate(*args) # res is a ComputationResult instance, defined in ufora/FORA/Core/ComputationResult.hppml #@type ComputationResult = # Exception of ImplValContainer exception # -| Result of ImplValContainer result # -| Failure of ErrorState error resVal = None if res.isResult(): resVal = res.asResult.result elif res.isException(): resVal = res.asException.exception elif res.isFailure(): raise ForaValue.FORAFailure(res.asFailure.error) # At this point, resVal is an ImplValContainer resVal = ForaValue.FORAValue(resVal).implVal_ boundValues = {} if res.isException(): #the exception it a tuple ((exception, (a1, a2, ...)), stacktrace) #we want to propagate (exception, stacktrace) exceptionAndVariables, stacktrace = resVal exception, variableAssignments = exceptionAndVariables #iterate through the binding and update the original for ix, a in enumerate(assignments): boundValues[a] = binding[a] = variableAssignments[ix] boundValues['result'] = ForaValue.FORAException( (exception, ForaValue.FORAValue(stacktrace))) else: #packAssignedVarsIntoTuple puts the result in the first tuple element #and the assigned variables in the second actualResult, boundSymbolValues, assignedOutputs = resVal #iterate through the binding and update the original for ix, a in enumerate(lets): boundValues[a] = binding[a] = boundSymbolValues[ix] for ix, a in enumerate(assignments): boundValues[a] = binding[a] = assignedOutputs[ix] boundValues['result'] = actualResult return boundValues
def evaluate(self, expr, args, assignments, lets, binding, statementTerm): exprAsFunction = expr.toFunction() args = [exprAsFunction.implVal_, ForaValue.FORAValue.symbol_Call.implVal_] + args res = Evaluator.evaluator().evaluate(*args) # res is a ComputationResult instance, defined in ufora/FORA/Core/ComputationResult.hppml #@type ComputationResult = # Exception of ImplValContainer exception, ImplValContainer computationLog # -| Result of ImplValContainer result, ImplValContainer computationLog # -| Failure of ErrorState error resVal = None logs = None if res.isResult(): resVal = res.asResult.result logs = res.asResult.computationLog elif res.isException(): resVal = res.asException.exception logs = res.asException.computationLog elif res.isFailure(): raise ForaValue.FORAFailure(res.asFailure.error) # At this point, resVal and logs are both ImplValContainers. resVal = ForaValue.FORAValue(resVal).implVal_ if logs is not None and logs.isVector() and logs.getVectorSize() > 0: if logs.getVectorSize() > 50: for ix in range(50): print "log> " + ForaValue.FORAValue(logs)[ix] print " and", logs.getVectorSize() - 50, "additional log messages..." else: print "log> " + ForaValue.FORAValue("\nlog> ").join(ForaValue.FORAValue(logs)) boundValues = {} if res.isException(): #the exception it a tuple ((exception, (a1, a2, ...)), stacktrace) #we want to propagate (exception, stacktrace) exceptionAndVariables, stacktrace = resVal exception, variableAssignments = exceptionAndVariables #iterate through the binding and update the original for ix, a in enumerate(assignments): boundValues[a] = binding[a] = variableAssignments[ix] boundValues['result'] = ForaValue.FORAException((exception, ForaValue.FORAValue(stacktrace))) else: #packAssignedVarsIntoTuple puts the result in the first tuple element #and the assigned variables in the second actualResult, boundSymbolValues, assignedOutputs = resVal #iterate through the binding and update the original for ix, a in enumerate(lets): boundValues[a] = binding[a] = boundSymbolValues[ix] for ix, a in enumerate(assignments): boundValues[a] = binding[a] = assignedOutputs[ix] boundValues['result'] = actualResult return boundValues