diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-21 06:14:00 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-21 06:14:00 +0000 |
| commit | db8c7f14d2f74c3db205782acf8222cb7d91a047 (patch) | |
| tree | 31b6e17c0cb818ba0cc700cd1e0ca896a6b9156f /include/cps | |
| parent | 25ae363250e479701ed532c55c255e043c8240da (diff) | |
feat(codegen): instantiate class templates
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'include/cps')
| -rw-r--r-- | include/cps/CodeGen.h | 11 | ||||
| -rw-r--r-- | include/cps/TypeSystem.h | 2 |
2 files changed, 13 insertions, 0 deletions
diff --git a/include/cps/CodeGen.h b/include/cps/CodeGen.h index 23487f6..4730585 100644 --- a/include/cps/CodeGen.h +++ b/include/cps/CodeGen.h @@ -26,6 +26,7 @@ class ExceptionHandler; class CastExprAST; class NewExprAST; class TemplateDeclAST; +class ClassTypeDeclAST; class CodeGen { std::unique_ptr<llvm::LLVMContext> TheContext; @@ -43,6 +44,7 @@ class CodeGen { TemplateDeclAST *Decl; std::string Arguments; std::unique_ptr<FunctionDefAST> Function; + std::unique_ptr<ClassTypeDeclAST> Class; const FuncSig *Signature; size_t OwnerUnit; size_t RequesterUnit; @@ -52,6 +54,10 @@ class CodeGen { std::map<const TemplateDeclAST *, IdentifierMap<SymbolInfo>> TemplateSymbols; size_t NextTemplateBody = 0; unsigned TemplateDepth = 0; + bool TypePrePass = false; + bool SpeculativeTemplateResolution = false; + IdentifierSet FailedTemplateTypes; + std::vector<size_t> DeferredClassPrototypes; bool hasCallable(const std::string &Name) const; bool hasFunctionTemplate(const std::string &Name) const; void validateTemplates(); @@ -59,6 +65,10 @@ class CodeGen { const FuncSig *instantiateFunction(const TemplateDefinition &Definition, const IdentifierMap<std::vector<std::string>> &Bindings); void drainTemplateBodies(); + const TypeInfo *instantiateClass(const std::string &Name); + std::optional<std::string> canonicalTemplateArgument(const std::string &Name); + void emitClassPrototypes(ClassTypeDeclAST *Class); + void emitDeferredClassPrototypes(); std::vector<IdentifierMap<SymbolInfo>> Exports; bool isVisible(size_t Owner) const; void selectUnit(size_t Unit); @@ -170,6 +180,7 @@ class CodeGen { // TYPE-system registration (Designator.cc) and operators (TypeCheckGen.cc). void runTypePrePass(const std::vector<std::unique_ptr<StmtAST>> &Statements, int Phase); + void registerClassMethods(ClassTypeDeclAST *Class); llvm::Value *emitUserKindBinaryOp(int Op, llvm::Value *L, const TypeInfo *LT, llvm::Value *R, const TypeInfo *RT, int Line); diff --git a/include/cps/TypeSystem.h b/include/cps/TypeSystem.h index e4663eb..2d885fa 100644 --- a/include/cps/TypeSystem.h +++ b/include/cps/TypeSystem.h @@ -122,6 +122,7 @@ class TypeSystem { IdentifierMap<EnumConstant> EnumConstants; std::function<bool(const std::string &)> Visible; + std::function<const TypeInfo *(const std::string &)> ResolveMiss; void registerBuiltins(); const TypeInfo *registerType(const std::string &TypeName, llvm::Type *LLVMType, @@ -131,6 +132,7 @@ public: explicit TypeSystem(llvm::LLVMContext &Ctx); void setVisibility(std::function<bool(const std::string &)> Predicate) { Visible = std::move(Predicate); } + void setResolveMiss(std::function<const TypeInfo *(const std::string &)> Hook) { ResolveMiss = std::move(Hook); } const TypeInfo *resolve(const std::string &TypeName) const; // Two-pass user-type registration (pass A then pass B, both in source |
