compiler, language, runtime: Separate Parser Type From Instances
In P4, parsers are considered types. Those parsers are instantiated. The instantiated parsers are values. Previously, gp4 treated a parser type and a parser value as identical. This PR makes that difference clear _and_ sets the stage for the future. TODO: Make the same distinction between control and action types and values. Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
@@ -24,7 +24,7 @@ extension SelectCaseExpression: EvaluatableExpression {
|
||||
}
|
||||
|
||||
public func type() -> P4QualifiedType {
|
||||
return P4QualifiedType(ParserState())
|
||||
return P4QualifiedType(AnyParserState)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ extension SelectExpression: EvaluatableExpression {
|
||||
}
|
||||
|
||||
public func type() -> P4QualifiedType {
|
||||
return P4QualifiedType(ParserState())
|
||||
return P4QualifiedType(AnyParserState)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,18 +79,18 @@ extension TypedIdentifier: EvaluatableLValueExpression {
|
||||
}
|
||||
|
||||
public func check(
|
||||
to: any Common.EvaluatableExpression, inScopes scopes: Common.VarTypeScopes
|
||||
to: any Common.EvaluatableExpression, inScopes scopes: Common.StaticVarValueScopes
|
||||
) -> Result<()> {
|
||||
guard case .Ok(let type) = scopes.lookup(identifier: self) else {
|
||||
return .Error(Error(withMessage: "Cannot assign to identifier not in scope"))
|
||||
}
|
||||
|
||||
return switch type.assignableFromType(to.type()) {
|
||||
return switch type.0.assignableFromType(to.type()) {
|
||||
case TypeCheckResults.IncompatibleTypes:
|
||||
.Error(
|
||||
Error(
|
||||
withMessage:
|
||||
"Cannot assign value with type \(to.type()) to identifier \(self) with type \(type)"))
|
||||
"Cannot assign value with type \(to.type()) to identifier \(self) with type \(type.0)"))
|
||||
case TypeCheckResults.ReadOnly:
|
||||
.Error(
|
||||
Error(
|
||||
@@ -318,7 +318,7 @@ extension ArrayAccessExpression: EvaluatableLValueExpression {
|
||||
}
|
||||
|
||||
public func check(
|
||||
to: any Common.EvaluatableExpression, inScopes scopes: Common.VarTypeScopes
|
||||
to: any Common.EvaluatableExpression, inScopes scopes: Common.StaticVarValueScopes
|
||||
) -> Common.Result<()> {
|
||||
|
||||
return switch self.type.value_type().assignableFromType(to.type()) {
|
||||
@@ -426,7 +426,7 @@ extension FieldAccessExpression: EvaluatableLValueExpression {
|
||||
}
|
||||
|
||||
public func check(
|
||||
to: any Common.EvaluatableExpression, inScopes scopes: Common.VarTypeScopes
|
||||
to: any Common.EvaluatableExpression, inScopes scopes: Common.StaticVarValueScopes
|
||||
) -> Common.Result<()> {
|
||||
return switch self.field.type().assignableFromType(to.type()) {
|
||||
case TypeCheckResults.IncompatibleTypes:
|
||||
|
||||
Reference in New Issue
Block a user