@@ -37,7 +37,10 @@ public struct ConditionalStatement {
|
|||||||
self.elss = .none
|
self.elss = .none
|
||||||
}
|
}
|
||||||
|
|
||||||
public init(condition: EvaluatableExpression, withThen thenn: EvaluatableStatement, andElse elss: EvaluatableStatement) {
|
public init(
|
||||||
|
condition: EvaluatableExpression, withThen thenn: EvaluatableStatement,
|
||||||
|
andElse elss: EvaluatableStatement
|
||||||
|
) {
|
||||||
self.condition = condition
|
self.condition = condition
|
||||||
self.thenn = thenn
|
self.thenn = thenn
|
||||||
self.elss = elss
|
self.elss = elss
|
||||||
@@ -51,4 +54,4 @@ public struct BlockStatement {
|
|||||||
self.statements = statements
|
self.statements = statements
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ extension BlockStatement: EvaluatableStatement {
|
|||||||
public func evaluate(execution: ProgramExecution) -> ProgramExecution {
|
public func evaluate(execution: ProgramExecution) -> ProgramExecution {
|
||||||
var execution = execution
|
var execution = execution
|
||||||
for s in self.statements {
|
for s in self.statements {
|
||||||
execution = s.evaluate(execution: execution)
|
execution = s.evaluate(execution: execution)
|
||||||
}
|
}
|
||||||
return execution
|
return execution
|
||||||
}
|
}
|
||||||
@@ -50,19 +50,18 @@ extension ConditionalStatement: EvaluatableStatement {
|
|||||||
if initial_value.eq(rhs: P4BooleanValue.init(withValue: true)) {
|
if initial_value.eq(rhs: P4BooleanValue.init(withValue: true)) {
|
||||||
let execution = execution.enter_scope()
|
let execution = execution.enter_scope()
|
||||||
var result = self.thenn.evaluate(execution: execution)
|
var result = self.thenn.evaluate(execution: execution)
|
||||||
result = result.exit_scope()
|
result = result.exit_scope()
|
||||||
return result
|
return result
|
||||||
} else if let elss = self.elss {
|
} else if let elss = self.elss {
|
||||||
let execution = execution.enter_scope()
|
let execution = execution.enter_scope()
|
||||||
var result = elss.evaluate(execution: execution)
|
var result = elss.evaluate(execution: execution)
|
||||||
result = result.exit_scope()
|
result = result.exit_scope()
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
return execution
|
return execution
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
extension ExpressionStatement: EvaluatableStatement {
|
extension ExpressionStatement: EvaluatableStatement {
|
||||||
public func evaluate(execution: ProgramExecution) -> ProgramExecution {
|
public func evaluate(execution: ProgramExecution) -> ProgramExecution {
|
||||||
return execution
|
return execution
|
||||||
|
|||||||
Reference in New Issue
Block a user