SPPCompiler.SemanticAnalysis.Utils.CompilerStages module

class SPPCompiler.SemanticAnalysis.Utils.CompilerStages.CompilerStages

Bases: object

pre_process(ctx)

The preprocessor stage performs mutations on ASTs, introduces new ASTs, and removes some ASTs. This allows for single-method processing of multiple ASTs, such as functions vs types with function classes superimposed over them. This stage directly affects what symbols are generated. :type ctx: TypeAliasType :param ctx: The pre-processing context that owns the AST being pre-processed.

Return type:

None

generate_top_level_scopes(sm)

! The generate top-level scopes stage generates all module and superimposition level scopes and symbols. This includes classes, attributes, functions, sup-methods, aliases and global constants. No generation is done for symbols inside functions. The symbols are generated here so that they can be used in any module, allowing for circular imports. :param sm The scope manager.

Return type:

None

generate_top_level_aliases(sm, **kwargs)

! The generate top-level aliases stage generates all aliases at the module/sup level. This must come after the symbol generation stage, as it requires symbol knowledge to attach the correct “old types”. It must also come before the load sup scopes stage, because superimposing over aliases requires the alias to exist beforehand, in any order of compilation. :param sm The scope manager. :param kwargs Additional keyword arguments.

Return type:

None

qualify_types(sm, **kwargs)

… :type sm: ScopeManager :param sm: :type kwargs: :param kwargs: :rtype: None :return:

load_super_scopes(sm, **kwargs)
Return type:

None

pre_analyse_semantics(sm, **kwargs)
Return type:

None

analyse_semantics(sm, **kwargs)

The semantic analysis stage is the most complex, and final analysis, stage of the semantic pipeline. This stage performs all the semantic checks, type inference, and type checking. This stage requires all symbols to be generated, and all types to be aliased, loaded, and post-processed. All functions scopes are inspected. :param sm The scope manager. :param kwargs Additional keyword arguments.

Return type:

None

check_memory(sm, **kwargs)

The check memory stage is the final stage of the semantic pipeline. This stage performs all the memory checks, and has to happen after, and not during semantic analysis, because sometimes the ASTs are analysed out of order to allow for type-inference. This messes up the strict order of memory checks, so the additional stage enforces the order of memory checks. :type sm: ScopeManager :param sm: The scope manager. :type kwargs: :param kwargs: Additional keyword arguments.

Return type:

None

code_gen_pass_1(sm, llvm_module, **kwargs)

The first pass of the code generation handles declarations. This includes type declarations (no memory layout set), and function declarations (no body set). This is because for class attributes, the types need to have already been created :type sm: ScopeManager :param sm: The scope manager. :type llvm_module: Module :param llvm_module: The LLVM module to generate code for. :type kwargs: :param kwargs: Additional keyword arguments.

Return type:

None

code_gen_pass_2(sm, llvm_module, **kwargs)

The second pass of the code generation handles definitions. This includes type definitions (memory layout set), and function definitions (body set). :type sm: ScopeManager :param sm: The scope manager. :type llvm_module: Module :param llvm_module: The LLVM module to generate code for. :type kwargs: :param kwargs: Additional keyword arguments.

Return type:

None