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:
@@ -46,7 +46,7 @@ public func ConfigureP4Parser() -> Result<SwiftTreeSitter.Parser> {
|
||||
/// knowledge of an expected type. For instance, when compiling a return statement, the
|
||||
/// compiler must know the return type of the function to type check.
|
||||
public struct CompilerContext {
|
||||
let instances: VarTypeScopes
|
||||
let instances: StaticVarValueScopes
|
||||
let types: TypeTypeScopes
|
||||
let externs: TypeTypeScopes
|
||||
let ffis: [P4FFI]
|
||||
@@ -54,7 +54,7 @@ public struct CompilerContext {
|
||||
let extern_context: Bool
|
||||
|
||||
public init() {
|
||||
instances = VarTypeScopes().enter()
|
||||
instances = StaticVarValueScopes().enter()
|
||||
types = TypeTypeScopes().enter()
|
||||
externs = TypeTypeScopes().enter()
|
||||
expected_type = .none
|
||||
@@ -62,7 +62,7 @@ public struct CompilerContext {
|
||||
ffis = Array()
|
||||
}
|
||||
|
||||
public init(withInstances _instances: VarTypeScopes, withTypes _types: TypeTypeScopes) {
|
||||
public init(withInstances _instances: StaticVarValueScopes, withTypes _types: TypeTypeScopes) {
|
||||
instances = _instances
|
||||
types = _types
|
||||
externs = TypeTypeScopes().enter()
|
||||
@@ -72,7 +72,7 @@ public struct CompilerContext {
|
||||
}
|
||||
|
||||
public init(
|
||||
withInstances _instances: VarTypeScopes, withTypes _types: TypeTypeScopes,
|
||||
withInstances _instances: StaticVarValueScopes, withTypes _types: TypeTypeScopes,
|
||||
withExpectation expectation: P4QualifiedType?, withExtern extern: Bool,
|
||||
withExterns externs: TypeTypeScopes, withFFIs foreigns: [P4FFI]
|
||||
) {
|
||||
@@ -90,7 +90,7 @@ public struct CompilerContext {
|
||||
///
|
||||
/// - Parameter instances: a ``VarTypeScopes`` with the updated instances for the newly created compiler context.
|
||||
/// - Returns: A new compiler context based on the current but new instances.
|
||||
public func update(newInstances instances: VarTypeScopes) -> CompilerContext {
|
||||
public func update(newInstances instances: StaticVarValueScopes) -> CompilerContext {
|
||||
return CompilerContext(
|
||||
withInstances: instances, withTypes: self.types, withExpectation: self.expected_type,
|
||||
withExtern: self.extern_context, withExterns: self.externs, withFFIs: self.ffis)
|
||||
|
||||
Reference in New Issue
Block a user