From 16231050058131860f710073c17d3bca7c6637eb Mon Sep 17 00:00:00 2001 From: _ov4 Date: Sun, 18 Oct 2026 06:05:53 +0000 Subject: 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 --- lib/CodeGen/OperatorGen.cc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 lib/CodeGen/OperatorGen.cc (limited to 'lib/CodeGen/OperatorGen.cc') diff --git a/lib/CodeGen/OperatorGen.cc b/lib/CodeGen/OperatorGen.cc new file mode 100644 index 0000000..83c515b --- /dev/null +++ b/lib/CodeGen/OperatorGen.cc @@ -0,0 +1,20 @@ +#include "cps/CodeGen.h" +#include "cps/Operator.h" + +using namespace cps; + +// Probing candidates must not evaluate operands or diagnose absent overloads: +// both static typing and emission use this same selection. +CodeGen::OperatorResolution CodeGen::resolveOperator( + int Op, const TypeInfo *Left, const TypeInfo *Right) { + OperatorResolution Result; + if (!Left) return Result; + for (const FuncSig *Sig : FuncGen->getOverloads(operatorName(Op))) { + if (Sig->Prototype->getOperator() != Op || Sig->Params.size() != (Right ? 2u : 1u)) continue; + if (!Left->sameType(resolveType(Sig->Params[0].TypeName))) continue; + if (Right && !Right->sameType(resolveType(Sig->Params[1].TypeName))) continue; + if (Result.Signature) Result.Ambiguous = true; + else Result.Signature = Sig; + } + return Result; +} -- cgit v1.3.1-4-g156e