@@ -22,7 +22,7 @@ public func Call<T>(
|
||||
body: (ProgramExecution) -> (Result<T>, ProgramExecution), withArguments args: ArgumentList,
|
||||
withParameters params: ParameterList, inExecution execution: ProgramExecution
|
||||
) -> (Result<T>, ProgramExecution) {
|
||||
|
||||
|
||||
if case .Error(let e) = args.compatible(params) {
|
||||
return (.Error(e), execution)
|
||||
}
|
||||
@@ -53,21 +53,32 @@ public func Call<T>(
|
||||
|
||||
for (parameter, argument) in zip(params.parameters, args.arguments) {
|
||||
if let param_direction = parameter.type.direction(),
|
||||
param_direction == Direction.InOut || param_direction == Direction.Out {
|
||||
param_direction == Direction.InOut || param_direction == Direction.Out
|
||||
{
|
||||
// Let's make sure that it is an evaluatable l value!
|
||||
guard let arg_lvalue = argument.argument as? EvaluatableLValueExpression else {
|
||||
return (.Error(Error(withMessage: "(in)out parameter argument is not lvalue")), updated_execution.exit_scope())
|
||||
return (
|
||||
.Error(Error(withMessage: "(in)out parameter argument is not lvalue")),
|
||||
updated_execution.exit_scope()
|
||||
)
|
||||
}
|
||||
|
||||
guard case .Ok(let arg_new_value) = updated_execution.scopes.lookup(identifier: parameter.name) else {
|
||||
return (.Error(Error(withMessage: "Could not get (in)out parameter value from scope")), updated_execution.exit_scope())
|
||||
guard
|
||||
case .Ok(let arg_new_value) = updated_execution.scopes.lookup(identifier: parameter.name)
|
||||
else {
|
||||
return (
|
||||
.Error(Error(withMessage: "Could not get (in)out parameter value from scope")),
|
||||
updated_execution.exit_scope()
|
||||
)
|
||||
}
|
||||
|
||||
switch arg_lvalue.set(to: arg_new_value, inScopes: inout_scopes, duringExecution: updated_execution) {
|
||||
case .Ok((let updated_scopes, _)): inout_scopes = updated_scopes
|
||||
case .Error(let e): return (.Error(e), updated_execution.exit_scope())
|
||||
switch arg_lvalue.set(
|
||||
to: arg_new_value, inScopes: inout_scopes, duringExecution: updated_execution)
|
||||
{
|
||||
case .Ok((let updated_scopes, _)): inout_scopes = updated_scopes
|
||||
case .Error(let e): return (.Error(e), updated_execution.exit_scope())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return (.Ok(call_result), updated_execution.replaceScopes(inout_scopes))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user