diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-30 14:23:32 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-30 14:23:32 +0000 |
| commit | 4cb0d9b196008bc55dbfcdac1f9211dbbc879895 (patch) | |
| tree | 0d95a2682ef26455483c4bb9222e1dff0d5c8e69 /include | |
| parent | 63109537383fa58c6a1db95f275d6b5de63b0015 (diff) | |
feat(types): support implicit single-argument constructors
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'include')
| -rw-r--r-- | include/cps/CodeGen.h | 7 | ||||
| -rw-r--r-- | include/cps/FunctionAST.h | 3 | ||||
| -rw-r--r-- | include/cps/FunctionGen.h | 1 | ||||
| -rw-r--r-- | include/cps/Lexer.h | 1 | ||||
| -rw-r--r-- | include/cps/Parser.h | 2 |
5 files changed, 12 insertions, 2 deletions
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<size_t> &Transfers = {}); std::unique_ptr<TypeSystem> Types; std::unique_ptr<ArrayHandler> 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<ParamDecl> &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<RecordFieldDecl> &Out, bool IsPublic); std::unique_ptr<FunctionDefAST> ParseFunction(const std::string &OwnerClass = {}, bool IsPublic = true, bool IsOverload = false); - std::unique_ptr<FunctionDefAST> ParseProcedure(const std::string &OwnerClass = {}, bool IsPublic = true, bool IsOverload = false); + std::unique_ptr<FunctionDefAST> ParseProcedure(const std::string &OwnerClass = {}, bool IsPublic = true, bool IsOverload = false, bool IsImplicit = false); std::unique_ptr<FunctionDefAST> ParseFunctionBody( std::unique_ptr<PrototypeAST> Proto, int EndToken, const char *EndMessage, int Line); std::unique_ptr<StmtAST> ParseExternDecl(); |
