compiler, runtime, common, documentation: Refactor Type System

The type system (and the value system) now include attributes
for each type (things like direction, const-ness).

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
Will Hawkins
2026-04-13 23:53:31 -04:00
parent 35b2537754
commit 94086c8e17
34 changed files with 690 additions and 552 deletions
+4 -11
View File
@@ -19,36 +19,29 @@ import Common
public struct Parameter: CustomStringConvertible, Equatable {
public static func == (lhs: Parameter, rhs: Parameter) -> Bool {
return lhs.name == rhs.name && lhs.type.eq(rhs: rhs.type) && lhs.direction == rhs.direction
return lhs.name == rhs.name && lhs.type.eq(rhs.type)
}
public var name: Identifier
public var type: P4Type
public var direction: Direction?
public init(
identifier: Identifier, withType type: P4Type, withDirection direction: Direction? = .none
identifier: Identifier, withType type: P4Type
) {
self.name = identifier
self.type = type
self.direction = direction
}
public var description: String {
let direction = self.direction != .none ? self.direction!.description : "no"
return "Parameter: \(self.name) with type \(self.type) with \(direction) direction"
return "Parameter: \(self.name) with type \(self.type)"
}
/// Calculate whether the `argument` is compatible with this parameter.
public func compatible(_ argument: Argument) -> Bool {
let arg_type = argument.argument.type()
return arg_type.eq(rhs: self.type)
return arg_type.eq(self.type)
}
public func attributedType() -> P4TypeAttributed {
return P4TypeAttributed(
self.type, self.direction == .none ? [] : [P4TypeAttribute.Direction(self.direction!)])
}
}
public struct ParameterList: CustomStringConvertible, Equatable {