From db8c7f14d2f74c3db205782acf8222cb7d91a047 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Wed, 21 Oct 2026 06:14:00 +0000 Subject: feat(codegen): instantiate class templates Co-Authored-By: Claude Opus 5.5 --- include/cps/CodeGen.h | 11 +++++++++++ include/cps/TypeSystem.h | 2 ++ 2 files changed, 13 insertions(+) (limited to 'include') 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 TheContext; @@ -43,6 +44,7 @@ class CodeGen { TemplateDeclAST *Decl; std::string Arguments; std::unique_ptr Function; + std::unique_ptr Class; const FuncSig *Signature; size_t OwnerUnit; size_t RequesterUnit; @@ -52,6 +54,10 @@ class CodeGen { std::map> TemplateSymbols; size_t NextTemplateBody = 0; unsigned TemplateDepth = 0; + bool TypePrePass = false; + bool SpeculativeTemplateResolution = false; + IdentifierSet FailedTemplateTypes; + std::vector 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> &Bindings); void drainTemplateBodies(); + const TypeInfo *instantiateClass(const std::string &Name); + std::optional canonicalTemplateArgument(const std::string &Name); + void emitClassPrototypes(ClassTypeDeclAST *Class); + void emitDeferredClassPrototypes(); std::vector> 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> &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 EnumConstants; std::function Visible; + std::function 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 Predicate) { Visible = std::move(Predicate); } + void setResolveMiss(std::function 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 -- cgit v1.3.1-4-g156e