From 4cb0d9b196008bc55dbfcdac1f9211dbbc879895 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Fri, 30 Oct 2026 14:23:32 +0000 Subject: feat(types): support implicit single-argument constructors Co-Authored-By: Claude Opus 5.5 --- include/cps/CodeGen.h | 7 ++++++- include/cps/FunctionAST.h | 3 +++ include/cps/FunctionGen.h | 1 + include/cps/Lexer.h | 1 + include/cps/Parser.h | 2 +- 5 files changed, 12 insertions(+), 2 deletions(-) (limited to 'include/cps') diff --git a/include/cps/CodeGen.h b/include/cps/CodeGen.h index c3a7b19..c0ae997 100644 --- a/include/cps/CodeGen.h +++ b/include/cps/CodeGen.h @@ -148,6 +148,11 @@ class CodeGen { llvm::Value *emitCStringExpr(ExprAST *Expr); llvm::Value *emitFileNameOperand(ExprAST *E, const char *Keyword); bool containsString(const TypeInfo *Type) const; + const FuncSig *findImplicitConstructor(const TypeInfo *Source, const TypeInfo *Target); + bool canImplicitlyConvert(const TypeInfo *Source, const TypeInfo *Target); + llvm::Value *emitImplicitConstruct(const FuncSig &Constructor, const TypeInfo *Target, + llvm::Value *Argument, + const std::vector &Transfers = {}); std::unique_ptr Types; std::unique_ptr Arrays; @@ -230,7 +235,7 @@ class CodeGen { llvm::Value *materializeOperatorReceiver(llvm::Value *Value, const TypeInfo *Type); llvm::Value *emitOperatorCall(const FuncSig &Signature, ExprAST *Left, ExprAST *Right = nullptr); llvm::Value *emitOperatorValues(const FuncSig &Signature, llvm::Value *Left, - const TypeInfo *LeftType, llvm::Value *Right); + const TypeInfo *LeftType, llvm::Value *Right, const TypeInfo *RightType); llvm::Value *emitVariadicArgument(ExprAST *Expr, const std::string &Callee, size_t Position, const TypeInfo *&Promoted); // Variadic, if given, receives the promoted type of each variadic argument. diff --git a/include/cps/FunctionAST.h b/include/cps/FunctionAST.h index 5280d58..d7fca1a 100644 --- a/include/cps/FunctionAST.h +++ b/include/cps/FunctionAST.h @@ -34,6 +34,7 @@ class PrototypeAST { bool IsOverload; std::string OwnerClass; bool IsPublic; + bool IsImplicit = false; bool IsVariadic = false; bool IsDefaultReturn = false; int Operator = 0; @@ -50,6 +51,8 @@ public: const std::vector &getParams() const { return Params; } const std::string &getReturnType() const { return ReturnType; } bool isOverload() const { return IsOverload; } + bool isImplicit() const { return IsImplicit; } + void setImplicit(bool V) { IsImplicit = V; } bool isDefaultReturn() const { return IsDefaultReturn; } void setDefaultReturn(bool V) { IsDefaultReturn = V; } int getOperator() const { return Operator; } diff --git a/include/cps/FunctionGen.h b/include/cps/FunctionGen.h index 5e895fe..741d08b 100644 --- a/include/cps/FunctionGen.h +++ b/include/cps/FunctionGen.h @@ -42,6 +42,7 @@ struct FuncSig { std::string ParamKey; std::string ReturnKey; bool IsOverload = false; + bool IsImplicit = false; bool IsDefaultReturn = false; const PrototypeAST *Prototype = nullptr; std::string ReturnTypeName; diff --git a/include/cps/Lexer.h b/include/cps/Lexer.h index 1268582..9faa09f 100644 --- a/include/cps/Lexer.h +++ b/include/cps/Lexer.h @@ -80,6 +80,7 @@ enum Token { tok_byref = -407, tok_byval = -408, tok_default = -409, + tok_implicit = -410, tok_openfile = -500, tok_readfile = -501, diff --git a/include/cps/Parser.h b/include/cps/Parser.h index e710150..aadf9a4 100644 --- a/include/cps/Parser.h +++ b/include/cps/Parser.h @@ -96,7 +96,7 @@ class Parser { bool ParseRecordField(std::vector &Out, bool IsPublic); std::unique_ptr ParseFunction(const std::string &OwnerClass = {}, bool IsPublic = true, bool IsOverload = false); - std::unique_ptr ParseProcedure(const std::string &OwnerClass = {}, bool IsPublic = true, bool IsOverload = false); + std::unique_ptr ParseProcedure(const std::string &OwnerClass = {}, bool IsPublic = true, bool IsOverload = false, bool IsImplicit = false); std::unique_ptr ParseFunctionBody( std::unique_ptr Proto, int EndToken, const char *EndMessage, int Line); std::unique_ptr ParseExternDecl(); -- cgit v1.3.1-4-g156e