Refactor Type System

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
Will Hawkins
2026-02-06 07:46:18 -05:00
parent bc700509c1
commit c3fdfb62e8
11 changed files with 395 additions and 199 deletions
+24 -1
View File
@@ -15,7 +15,30 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
import Common
public struct Program {
public var parsers: [Parser] = Array()
public var types: [P4Type] = Array()
/// Find the program's main parser
///
/// Note: For now, the main parser is expected to be named main_parser.
public func starting_parser() -> Result<Parser> {
return self.find_parser(withName: Identifier(name: "main_parser"))
}
public func find_parser(withName name: Identifier) -> Result<Parser> {
for type in self.types {
print("type: \(type)")
guard let parser = type as? Parser else {
continue
}
if parser.name == name {
return .Ok(parser)
}
}
return .Error(Error(withMessage: "Could not find parser named \(name)"))
}
public init() {}
}