compiler, runtime, common: Support (in)out Parameters
When a function is called, if there is an (in)out parameter, make sure that updated values are propogated to the calling function. Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
@@ -87,6 +87,12 @@ open class ProgramExecution: CustomStringConvertible {
|
||||
return new_pe
|
||||
}
|
||||
|
||||
public func replaceScopes(_ new_scopes: VarValueScopes) -> ProgramExecution {
|
||||
let new_pe = ProgramExecution(copy: self)
|
||||
new_pe.scopes = new_scopes
|
||||
return new_pe
|
||||
}
|
||||
|
||||
public func declare(identifier: Identifier, withValue value: P4Value) -> ProgramExecution {
|
||||
let new_pe = ProgramExecution(copy: self)
|
||||
let new_scopes = new_pe.scopes.declare(identifier: identifier, withValue: value)
|
||||
|
||||
@@ -15,6 +15,13 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
public enum TypeCheckResults: Equatable {
|
||||
case Ok
|
||||
case ReadOnly
|
||||
case WrongDirection
|
||||
case IncompatibleTypes
|
||||
}
|
||||
|
||||
public enum Direction: Equatable, CustomStringConvertible {
|
||||
case In
|
||||
case Out
|
||||
@@ -115,11 +122,11 @@ public struct P4Type: CustomStringConvertible {
|
||||
}
|
||||
|
||||
public func update(removeAttribute attribute: P4TypeAttribute) -> P4Type {
|
||||
return P4Type(self._data_type, self._attributes.update(addAttribute: attribute))
|
||||
return P4Type(self._data_type, self._attributes.update(removeAttribute: attribute))
|
||||
}
|
||||
|
||||
public func update(addAttribute attribute: P4TypeAttribute) -> P4Type {
|
||||
return P4Type(self._data_type, self._attributes.update(removeAttribute: attribute))
|
||||
return P4Type(self._data_type, self._attributes.update(addAttribute: attribute))
|
||||
}
|
||||
|
||||
public func direction() -> Direction? {
|
||||
@@ -143,6 +150,37 @@ public struct P4Type: CustomStringConvertible {
|
||||
&& self.dataType().eq(rhs: rhs.dataType())
|
||||
}
|
||||
|
||||
public func assignable() -> TypeCheckResults {
|
||||
if self.readOnly() {
|
||||
return TypeCheckResults.ReadOnly
|
||||
}
|
||||
|
||||
if let direction = direction(),
|
||||
direction == Direction.In
|
||||
{
|
||||
return TypeCheckResults.WrongDirection
|
||||
}
|
||||
return TypeCheckResults.Ok
|
||||
}
|
||||
|
||||
public func assignableFromType(_ rhs: P4Type) -> TypeCheckResults {
|
||||
if !self.dataType().eq(rhs: rhs.dataType()) {
|
||||
return TypeCheckResults.IncompatibleTypes
|
||||
}
|
||||
|
||||
if self.readOnly() {
|
||||
return TypeCheckResults.ReadOnly
|
||||
}
|
||||
|
||||
if let direction = direction(),
|
||||
direction == Direction.In
|
||||
{
|
||||
return TypeCheckResults.WrongDirection
|
||||
}
|
||||
|
||||
return TypeCheckResults.Ok
|
||||
}
|
||||
|
||||
public static func ReadOnly(_ type: P4DataType) -> P4Type {
|
||||
return P4Type(type, P4TypeAttributes.ReadOnly())
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public protocol EvaluatableExpression {
|
||||
/// - Parameters
|
||||
/// - execution: The execution context in which to evaluate the expression
|
||||
/// - Returns: The value of expression
|
||||
func evaluate(execution: ProgramExecution) -> Result<P4Value>
|
||||
func evaluate(execution: ProgramExecution) -> (Result<P4Value>, ProgramExecution)
|
||||
func type() -> P4Type
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user