From 45ce13ae9960a22ed46d94a6cf9d8a612e622b7e Mon Sep 17 00:00:00 2001 From: Antoine Viallon Date: Tue, 23 May 2023 00:48:52 +0200 Subject: [PATCH] semantic+main: add the BuiltinContext and use it as semantic root --- compiler/__main__.py | 2 +- compiler/semantic.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/compiler/__main__.py b/compiler/__main__.py index bf52687..52ced6c 100644 --- a/compiler/__main__.py +++ b/compiler/__main__.py @@ -43,7 +43,7 @@ def main(): ast = parser.parse() ast.pprint(depth=10) - context = semantic.Context("root") + context = semantic.BuiltinContext() ast.semantic_analysis(context) intermediate_representation = ast.intermediate_representation() diff --git a/compiler/semantic.py b/compiler/semantic.py index 710f954..2c43be2 100644 --- a/compiler/semantic.py +++ b/compiler/semantic.py @@ -131,3 +131,12 @@ class Context: def __repr__(self) -> str: return self._pprint() + + +class BuiltinContext(Context): + def __init__(self): + super().__init__(name="builtins", parent=None) + self.types = { + "__unknown": Type(self, "__unknown", "builtin"), + "uint32": Type(self, "uint32", "builtin") + }