diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-18 06:05:53 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-18 06:05:53 +0000 |
| commit | 16231050058131860f710073c17d3bca7c6637eb (patch) | |
| tree | 1da2ca606f1d513822ccd04b3053d5eee69ac19d /lib/CodeGen/ExpressionGen.cc | |
| parent | 1b0b287629e6e3b6d8eb6182db72b28fd0510574 (diff) | |
feat(operators): support global binary operator overloads
Resolve exact operand types and preserve declared operator return types.
Reject implicit STRING to BOOLEAN conversion at typed expression boundaries.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'lib/CodeGen/ExpressionGen.cc')
| -rw-r--r-- | lib/CodeGen/ExpressionGen.cc | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/CodeGen/ExpressionGen.cc b/lib/CodeGen/ExpressionGen.cc index 79c5fb0..8fb13c9 100644 --- a/lib/CodeGen/ExpressionGen.cc +++ b/lib/CodeGen/ExpressionGen.cc @@ -4,6 +4,7 @@ #include "cps/MemoryHandler.h" #include "cps/Lexer.h" #include "cps/TypeAST.h" +#include "cps/Operator.h" #include "Builtins.h" #include <climits> #include <cstddef> @@ -155,6 +156,16 @@ Value *CodeGen::emitBinaryOp(int Op, Value *L, const TypeInfo *LT, Value *R, const TypeInfo *RT, int Line) { SaveAndRestore<int> Location(DiagnosticLine, Line ? Line : DiagnosticLine); if (!L || !R) return nullptr; + if (!LT || !RT) { + reportError("Cannot determine operand types for %s", operatorName(Op).c_str()); + return nullptr; + } + auto Overload = resolveOperator(Op, LT, RT); + if (Overload.Ambiguous) { + reportError("Ambiguous overload for %s(%s, %s)", operatorName(Op).c_str(), LT->Name.c_str(), RT->Name.c_str()); + return nullptr; + } + if (Overload.Signature) return FuncGen->emitCall(*Overload.Signature, {L, R}); if ((LT && LT->isC()) || (RT && RT->isC())) return emitCBinaryOp(Op, L, LT, R, RT, Line); if ((LT && LT->isUserKind()) || (RT && RT->isUserKind())) |
