From c56877035d6600b463a9cbf0e339f7548c0b46fd Mon Sep 17 00:00:00 2001 From: _ov4 Date: Wed, 21 Oct 2026 05:54:26 +0000 Subject: feat(codegen): instantiate function templates by deduction Co-Authored-By: Claude Opus 5.5 --- lib/CodeGen/TemplateClone.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 lib/CodeGen/TemplateClone.h (limited to 'lib/CodeGen/TemplateClone.h') diff --git a/lib/CodeGen/TemplateClone.h b/lib/CodeGen/TemplateClone.h new file mode 100644 index 0000000..a0f196f --- /dev/null +++ b/lib/CodeGen/TemplateClone.h @@ -0,0 +1,32 @@ +#pragma once +#include "cps/TemplateAST.h" +#include "cps/Identifier.h" +#include + +namespace cps::detail { + +using TemplateBindings = IdentifierMap>; + +// Clones own all children; source ASTs remain reusable for later instances. +class TemplateClone { + const TemplateBindings &Bindings; + IdentifierMap> PackNames; + std::function Error; + bool Failed = false; + void fail(int Line, const std::string &Message); + std::vector> arguments(const std::vector> &Args); + std::vector> body(const std::vector> &Body); + std::unique_ptr expression(ExprAST *Expr); + std::unique_ptr statement(StmtAST *Stmt); +public: + TemplateClone(const TemplateBindings &Bindings, + std::function Error) + : Bindings(Bindings), Error(std::move(Error)) {} + std::string type(const std::string &Name); + std::unique_ptr function(const FunctionDefAST *Source, + const std::string &Name, const std::string &OwnerClass = {}); + std::unique_ptr klass(const ClassTypeDeclAST *Source, + const std::string &Name); +}; + +} // namespace cps::detail -- cgit v1.3.1-4-g156e