From 2cc3b02e643ab46f4e40bf661c4cffe807fc4187 Mon Sep 17 00:00:00 2001 From: agemogolk Date: Sun, 13 Jan 2013 17:30:33 +0000 Subject: [PATCH] Implemented final overload feature. * Overloads defined using the 'overload' keyword are final. define foo; overload foo(x) {} // foo(x:T) is final overload foo(y:Int) {} // ambiguous match error * Overloads defined using the 'default' keyword can be overridden by subsequent 'default' definitions and 'overload's. define foo; default foo(x) = false; default foo(x:Int32) = true; //OK as foo(x:T) not final overload foo(x:Float32) = true; //OK as foo(x:T) not final default foo(x:Int32) = false; //OK as foo(x:Int32) not final * Default overloads may be defined in any module. * Standalone functions are unchanged. Final overloads are off by default until the library has been modified to be compatible. A compiler flag '-final-overloads' has been added to turn final overloads on. The library has been updated with 'default' overloads to allow the bindgen tool and hello world example to compile with final overloads enabled. --- compiler/clay.cpp | 13 ++- compiler/clay.hpp | 5 +- compiler/error.cpp | 24 ++++++ compiler/error.hpp | 2 + compiler/invoketables.cpp | 45 ++++++++-- compiler/invoketables.hpp | 1 + compiler/lexer.cpp | 3 +- compiler/matchinvoke.cpp | 7 +- compiler/matchinvoke.hpp | 9 +- compiler/parser.cpp | 24 ++++-- lib-clay/core/characters/characters.clay | 2 +- lib-clay/core/coordinates/coordinates.clay | 2 +- .../backtrace/platform/platform.unix.clay | 4 +- lib-clay/core/errors/errors.clay | 4 +- lib-clay/core/exceptions/exceptions.clay | 4 +- lib-clay/core/maybe/maybe.clay | 4 +- lib-clay/core/memory/memory.clay | 2 +- lib-clay/core/numbers/numbers.clay | 60 +++++++------- lib-clay/core/numbers/overflow/overflow.clay | 2 +- lib-clay/core/operators/operators.clay | 82 +++++++++---------- lib-clay/core/operators/pod/pod.clay | 8 +- lib-clay/core/pointers/pointers.clay | 6 +- lib-clay/core/ranges/ranges.clay | 4 +- lib-clay/core/records/records.clay | 12 +-- lib-clay/core/sequences/sequences.clay | 14 ++-- lib-clay/core/statics/statics.clay | 2 +- .../stringliterals/stringliterals.clay | 6 +- lib-clay/core/system/system.clay | 2 +- lib-clay/core/tuples/tuples.clay | 2 +- lib-clay/core/values/values.clay | 6 +- lib-clay/core/variants/nested/nested.clay | 4 +- lib-clay/data/vectors/generic/generic.clay | 8 +- lib-clay/data/vectors/vectors.clay | 2 +- lib-clay/hash/hash.clay | 8 +- lib-clay/io/files/raw/raw.clay | 2 +- lib-clay/math/native/gamma.clay | 4 +- lib-clay/printer/types/types.clay | 16 ++-- tools/CMakeLists.txt | 3 +- tools/bindgen.clay | 3 +- 39 files changed, 248 insertions(+), 163 deletions(-) diff --git a/compiler/clay.cpp b/compiler/clay.cpp index 6aa0b8eee..be1f96124 100644 --- a/compiler/clay.cpp +++ b/compiler/clay.cpp @@ -3,7 +3,7 @@ #include "error.hpp" #include "codegen.hpp" #include "loader.hpp" - +#include "invoketables.hpp" // for _exit #ifdef _WIN32 @@ -468,6 +468,8 @@ static void usage(char *argv0) llvm::errs() << " -e compile and run (implies -run)\n"; llvm::errs() << " -M \"import .*;\" for -e\n"; llvm::errs() << " -version display version info\n"; + + llvm::errs() << " -final-overloads enable final overloads (temporary option)\n"; } static string sharedExtensionForTarget(llvm::Triple const &triple) { @@ -541,6 +543,8 @@ int main2(int argc, char **argv, char const* const* envp) { unsigned optLevel = 2; bool optLevelSet = false; + bool finalOverloadsEnabled = false; + #ifdef __APPLE__ genPIC = true; @@ -900,6 +904,9 @@ int main2(int argc, char **argv, char const* const* envp) { } clayFile = argv[i]; } + else if (strcmp(argv[i], "-final-overloads") == 0) { + finalOverloadsEnabled = true; + } else { llvm::errs() << "error: unrecognized option " << argv[i] << '\n'; return 1; @@ -955,7 +962,9 @@ int main2(int argc, char **argv, char const* const* envp) { setInlineEnabled(inlineEnabled); setExceptionsEnabled(exceptions); - + + setFinalOverloadsEnabled(finalOverloadsEnabled); + llvm::Triple llvmTriple(targetTriple); targetTriple = llvmTriple.str(); diff --git a/compiler/clay.hpp b/compiler/clay.hpp index b06629b8d..6ad769beb 100644 --- a/compiler/clay.hpp +++ b/compiler/clay.hpp @@ -1968,6 +1968,7 @@ struct Overload : public TopLevelItem { bool callByName:1; bool nameIsPattern:1; bool hasAsConversion:1; + bool isDefault:1; Overload(Module *module, ExprPtr target, CodePtr code, @@ -1976,7 +1977,7 @@ struct Overload : public TopLevelItem { : TopLevelItem(OVERLOAD, module), target(target), code(code), isInline(isInline), patternsInitializedState(0), callByName(callByName), nameIsPattern(false), - hasAsConversion(false) {} + hasAsConversion(false), isDefault(false) {} Overload(Module *module, ExprPtr target, CodePtr code, bool callByName, @@ -1985,7 +1986,7 @@ struct Overload : public TopLevelItem { : TopLevelItem(OVERLOAD, module), target(target), code(code), isInline(isInline), patternsInitializedState(0), callByName(callByName), nameIsPattern(false), - hasAsConversion(hasAsConversion) {} + hasAsConversion(hasAsConversion), isDefault(false) {} }; struct Procedure : public TopLevelItem { diff --git a/compiler/error.cpp b/compiler/error.cpp index 453d5487e..5e26c4495 100644 --- a/compiler/error.cpp +++ b/compiler/error.cpp @@ -305,6 +305,30 @@ void argumentError(size_t index, llvm::StringRef msg) { error(sout.str()); } +void ambiguousMatchError(MatchSuccessPtr match, MatchSuccessPtr match2) { + if (match->overload->location.ok()) { + unsigned line, column; + displayLocation(match->overload->location, line, column); + llvm::errs() << match->overload->location.source->fileName + << '(' << line+1 << ',' << column << "): " << "found matching overload\n"; + llvm::errs().flush(); + + } + if (match2->overload->location.ok()) { + unsigned line, column; + displayLocation(match2->overload->location, line, column); + llvm::errs() << match2->overload->location.source->fileName + << '(' << line+1 << ',' << column << "): " << "error: ambiguous overload\n"; + llvm::errs().flush(); + + } + string buf; + llvm::raw_string_ostream err(buf); + err << "ambiguous overloads for call-site\n"; + + error(err.str()); +} + static const char *valuesStr(size_t n) { return (n == 1) ? "value" : "values"; } diff --git a/compiler/error.hpp b/compiler/error.hpp index 0579ccbb6..20409ca46 100644 --- a/compiler/error.hpp +++ b/compiler/error.hpp @@ -2,6 +2,7 @@ #define __ERROR_HPP #include "clay.hpp" +#include "invoketables.hpp" namespace clay { @@ -11,6 +12,7 @@ extern set > logMatchSymbols; void matchBindingError(MatchResultPtr const &result); void matchFailureLog(MatchFailureError const &err); void matchFailureError(MatchFailureError const &err); +void ambiguousMatchError(MatchSuccessPtr match, MatchSuccessPtr match2); class CompilerError : std::exception { }; diff --git a/compiler/invoketables.cpp b/compiler/invoketables.cpp index 3b1ac36d7..6a2712918 100644 --- a/compiler/invoketables.cpp +++ b/compiler/invoketables.cpp @@ -12,6 +12,13 @@ namespace clay { +static bool _finalOverloadsEnabled = false; + +void setFinalOverloadsEnabled(bool enabled) +{ + _finalOverloadsEnabled = enabled; +} + // // callableOverloads @@ -314,8 +321,8 @@ static InvokeEntry* newInvokeEntry(InvokeSet* parent, MatchSuccessPtr interfaceMatch) { InvokeEntry* entry = new InvokeEntry(parent, match->callable, match->argsKey); - entry->origCode = match->code; - entry->code = clone(match->code); + entry->origCode = match->overload->code; + entry->code = clone(match->overload->code); entry->env = match->env; if (interfaceMatch != NULL) entry->interfaceEnv = interfaceMatch->env; @@ -324,8 +331,8 @@ static InvokeEntry* newInvokeEntry(InvokeSet* parent, entry->varArgName = match->varArgName; entry->varArgTypes = match->varArgTypes; entry->varArgPosition = match->varArgPosition; - entry->callByName = match->callByName; - entry->isInline = match->isInline; + entry->callByName = match->overload->callByName; + entry->isInline = match->overload->isInline; return entry; } @@ -381,9 +388,9 @@ InvokeEntry* lookupInvokeEntry(ObjectPtr callable, unsigned i = 0; while ((match = getMatch(invokeSet,i,failures)).ptr() != NULL) { - if (matchTempness(match->code, + if (matchTempness(match->overload->code, argsTempness, - match->callByName, + match->overload->callByName, tempnessKey, forwardedRValueFlags)) { @@ -407,6 +414,32 @@ InvokeEntry* lookupInvokeEntry(ObjectPtr callable, invokeSet->tempnessMap2[tempnessKey] = entry; invokeSet->tempnessMap[argsTempness] = entry; + if (_finalOverloadsEnabled) { + MatchSuccessPtr match2; + vector tempnessKey2; + vector forwardedRValueFlags2; + MatchFailureError failures2; + unsigned j = invokeSet->nextOverloadIndex; + while ((match2 = findMatchingInvoke(callableOverloads(callable), + j, + callable, + argsKey, + failures2)).ptr() != NULL) { + if (matchTempness(match2->overload->code, + argsTempness, + match2->overload->callByName, + tempnessKey2, + forwardedRValueFlags2)) + { + break; + } + ++j; + } + + if (match2 != NULL && !match2->overload->isDefault) + ambiguousMatchError(match, match2); + } + return entry; } diff --git a/compiler/invoketables.hpp b/compiler/invoketables.hpp index d4ecd3c3f..df3c32b62 100644 --- a/compiler/invoketables.hpp +++ b/compiler/invoketables.hpp @@ -125,6 +125,7 @@ InvokeEntry* lookupInvokeEntry(ObjectPtr callable, llvm::ArrayRef argsTempness, MatchFailureError &failures); +void setFinalOverloadsEnabled(bool enabled); } diff --git a/compiler/lexer.cpp b/compiler/lexer.cpp index 81986c00c..850e4d086 100644 --- a/compiler/lexer.cpp +++ b/compiler/lexer.cpp @@ -132,7 +132,8 @@ static void initKeywords() { const char *s[] = {"public", "private", "import", "as", "record", "variant", "instance", - "define", "overload", "external", "alias", + "define", "overload", "default", + "external", "alias", "rvalue", "ref", "forward", "inline", "noinline", "forceinline", "enum", "var", "and", "or", "not", diff --git a/compiler/matchinvoke.cpp b/compiler/matchinvoke.cpp index a562d9186..5745ef50e 100644 --- a/compiler/matchinvoke.cpp +++ b/compiler/matchinvoke.cpp @@ -161,12 +161,11 @@ MatchResultPtr matchInvoke(OverloadPtr overload, if (code->predicate.ptr()) if (!evaluateBool(code->predicate, staticEnv)) return new MatchPredicateError(code->predicate); - + MatchSuccessPtr result = new MatchSuccess( - overload->callByName, overload->isInline, code, staticEnv, - callable, argsKey + overload, staticEnv, callable, argsKey ); - + for (unsigned i = 0, j = 0; i < formalArgs.size(); ++i) { FormalArgPtr x = formalArgs[i]; if (x->varArg) { diff --git a/compiler/matchinvoke.hpp b/compiler/matchinvoke.hpp index e0755d945..8313dc993 100644 --- a/compiler/matchinvoke.hpp +++ b/compiler/matchinvoke.hpp @@ -27,7 +27,7 @@ struct MatchResult : public Object { }; struct MatchSuccess : public MatchResult { - CodePtr code; + OverloadPtr overload; EnvPtr env; ObjectPtr callable; @@ -42,12 +42,11 @@ struct MatchSuccess : public MatchResult { InlineAttribute isInline:3; bool callByName:1; - MatchSuccess(bool callByName, InlineAttribute isInline, CodePtr code, EnvPtr env, + MatchSuccess(OverloadPtr overload, EnvPtr env, ObjectPtr callable, llvm::ArrayRef argsKey) : MatchResult(MATCH_SUCCESS), - code(code), env(env), callable(callable), - argsKey(argsKey), varArgPosition(0), - isInline(isInline), callByName(callByName) {} + overload(overload), env(env), callable(callable), + argsKey(argsKey), varArgPosition(0) {} }; typedef Pointer MatchSuccessPtr; diff --git a/compiler/parser.cpp b/compiler/parser.cpp index 04bb152c7..7ad4d8ba5 100644 --- a/compiler/parser.cpp +++ b/compiler/parser.cpp @@ -2359,6 +2359,18 @@ static bool allReturnSpecs(vector &returnSpecs, // define, overload // +static bool isOverload(bool &isDefault) { + int p = save(); + if (keyword("overload")) + isDefault = false; + else if (restore(p), keyword("default")) + isDefault = true; + else { + return false; + } + return true; +} + static bool optInline(InlineAttribute &isInline) { unsigned p = save(); if (keyword("inline")) @@ -2553,7 +2565,8 @@ static bool overload(TopLevelItemPtr &x, Module *module, unsigned s) { if (!optInline(isInline)) return false; bool callByName; if (!optCallByName(callByName)) return false; - if (!keyword("overload")) return false; + bool isDefault; + if (!isOverload(isDefault)) return false; unsigned e = save(); restore(s); Location location = currentLocation(); @@ -2585,9 +2598,10 @@ static bool overload(TopLevelItemPtr &x, Module *module, unsigned s) { target->startLocation = targetStartLocation; target->endLocation = targetEndLocation; code->location = location; - x = new Overload(module, target, code, callByName, isInline, hasAsConversion); - x->location = location; - NameRefPtr name = (NameRef *)target.ptr(); + OverloadPtr oload = new Overload(module, target, code, callByName, isInline, hasAsConversion); + oload->location = location; + oload->isDefault = isDefault; + x = oload.ptr(); return true; } @@ -3028,7 +3042,7 @@ static bool documentationAnnotation(std::map &a ano = SectionAnnotation; } else if (key == "module") { ano = ModuleAnnotation; - } else if (key == "overload") { + } else if (key == "overload" || key == "default") { ano = OverloadAnnotation; } else if (key == "record") { ano = RecordAnnotion; diff --git a/lib-clay/core/characters/characters.clay b/lib-clay/core/characters/characters.clay index 926997728..619ba38b5 100644 --- a/lib-clay/core/characters/characters.clay +++ b/lib-clay/core/characters/characters.clay @@ -9,7 +9,7 @@ record UniChar (code:UInt32); [T] define Character?(#T) : Bool; -overload Character?(x) : Bool = false; +default Character?(x) : Bool = false; overload Character?(#Char) : Bool = true; overload Character?(#UniChar) : Bool = true; diff --git a/lib-clay/core/coordinates/coordinates.clay b/lib-clay/core/coordinates/coordinates.clay index 3d16a35e1..9b0257792 100644 --- a/lib-clay/core/coordinates/coordinates.clay +++ b/lib-clay/core/coordinates/coordinates.clay @@ -18,7 +18,7 @@ LValueCoordinate?(T) : Bool = [T] define ContiguousCoordinate?(#T) : Bool; -overload ContiguousCoordinate?(T) : Bool = false; +default ContiguousCoordinate?(T) : Bool = false; diff --git a/lib-clay/core/errors/backtrace/platform/platform.unix.clay b/lib-clay/core/errors/backtrace/platform/platform.unix.clay index 9eddec51f..a33e08142 100644 --- a/lib-clay/core/errors/backtrace/platform/platform.unix.clay +++ b/lib-clay/core/errors/backtrace/platform/platform.unix.clay @@ -15,7 +15,7 @@ define printBacktraceToStderr(backtrace: Backtrace) :; define captureBacktrace(): Backtrace; -forceinline overload captureBacktrace() --> returned: Backtrace { +forceinline default captureBacktrace() --> returned: Backtrace { returned.size = 0; } @@ -26,7 +26,7 @@ forceinline overload captureBacktrace() --> returned: Backtrace { Int(size(returned.callstack))); } -forceinline overload printBacktraceToStderr(backtrace: Backtrace) : { } +forceinline default printBacktraceToStderr(backtrace: Backtrace) : { } [when BacktraceSupported?] overload printBacktraceToStderr(bt: Backtrace) : { diff --git a/lib-clay/core/errors/errors.clay b/lib-clay/core/errors/errors.clay index 08803abb0..dbb93dc2f 100644 --- a/lib-clay/core/errors/errors.clay +++ b/lib-clay/core/errors/errors.clay @@ -55,14 +55,14 @@ record assert[..tags] (); [..tags] alias overload assert[..tags](..whatever) : {} -alias overload assert(..whatever) : {} +alias default assert(..whatever) : {} [file, line, column, cond] private assertStringLiteral(#file, #line, #column, #cond, ..etc) = strl(#file, "(", #line, ",", #column, "): assertion ", #cond, " failed", ..etc); [when AllAssertionsEnabled?()] -alias overload assert(cond:Bool) : { +alias default assert(cond:Bool) : { if (not likely(cond)) errorWithPrintfNoThrow( assertStringLiteral(__FILE__, #__LINE__, #__COLUMN__, __ARG__ cond)); diff --git a/lib-clay/core/exceptions/exceptions.clay b/lib-clay/core/exceptions/exceptions.clay index 16c6e158b..88a9273b7 100644 --- a/lib-clay/core/exceptions/exceptions.clay +++ b/lib-clay/core/exceptions/exceptions.clay @@ -58,7 +58,7 @@ private exceptionObject(exp:RawPointer) : ByRef[ExceptionData] // more sophisticated version. define printUnhandledExceptionToStderr(e) :; -overload printUnhandledExceptionToStderr(e) : { +default printUnhandledExceptionToStderr(e) : { libc.fprintf(libc.stderr, cstring("unhandled %s exception\n"), cstring(MemberTypeName(e))); } @@ -67,7 +67,7 @@ overload printUnhandledExceptionToStderr(e) : { /// @section throwValue, continueException [T when Type?(T)] -overload throwValue(x:T, ..ignored) : { +default throwValue(x:T, ..ignored) : { errorWithPrintfNoThrow(stringLiteralConcat("exception of type ", StaticName(T)," thrown with exceptions disabled")); } diff --git a/lib-clay/core/maybe/maybe.clay b/lib-clay/core/maybe/maybe.clay index 94a61e5b1..4027e7f27 100644 --- a/lib-clay/core/maybe/maybe.clay +++ b/lib-clay/core/maybe/maybe.clay @@ -38,8 +38,8 @@ forceinline overload just(m: Maybe[T], dflt: T) = maybe(m, v => v, () => dflt); /// @section maybe function private define maybeValue; -forceinline overload maybeValue(T, forward x, thenFn, ..elseFn) = forward ..thenFn(x); -forceinline overload maybeValue(T, forward n: Nothing, thenFn, elseFn) = forward ..elseFn(); +forceinline default maybeValue(T, forward x, thenFn, ..elseFn) = forward ..thenFn(x); +forceinline default maybeValue(T, forward n: Nothing, thenFn, elseFn) = forward ..elseFn(); // if the thenFn returns Maybe[T]s, have the default else case return nothing(T)s diff --git a/lib-clay/core/memory/memory.clay b/lib-clay/core/memory/memory.clay index 6b3bca8bb..ea7232f56 100644 --- a/lib-clay/core/memory/memory.clay +++ b/lib-clay/core/memory/memory.clay @@ -167,7 +167,7 @@ overload moveMemory(destBegin:Pointer[T], srcBegin:Pointer[T], srcEnd:Pointer[T] } [T when not PODType?(T)] -overload moveMemoryUnsafe(destBegin:Pointer[T], srcBegin:Pointer[T], srcEnd:Pointer[T]) : { +default moveMemoryUnsafe(destBegin:Pointer[T], srcBegin:Pointer[T], srcEnd:Pointer[T]) : { if (destBegin <= srcBegin) moveMemoryForwardsUnsafe(destBegin, srcBegin, srcEnd); else diff --git a/lib-clay/core/numbers/numbers.clay b/lib-clay/core/numbers/numbers.clay index 69f666d49..6a3a19f60 100644 --- a/lib-clay/core/numbers/numbers.clay +++ b/lib-clay/core/numbers/numbers.clay @@ -5,7 +5,7 @@ import core.platform.(OSFamily, Unix, CPU, X86_64); [T] define SignedInteger?(#T) : Bool; -overload SignedInteger?(T) : Bool = false; +default SignedInteger?(T) : Bool = false; overload SignedInteger?(#Int8) : Bool = true; overload SignedInteger?(#Int16) : Bool = true; overload SignedInteger?(#Int32) : Bool = true; @@ -15,7 +15,7 @@ overload SignedInteger?(#Int128) : Bool = true; [T] define UnsignedInteger?(#T) : Bool; -overload UnsignedInteger?(T) : Bool = false; +default UnsignedInteger?(T) : Bool = false; overload UnsignedInteger?(#UInt8) : Bool = true; overload UnsignedInteger?(#UInt16) : Bool = true; overload UnsignedInteger?(#UInt32) : Bool = true; @@ -69,12 +69,12 @@ UnsignedInteger(#I) = UnsignedIntegerOfSize(#Int(TypeSize(I))); [T] define ByteSizedInteger?(#T) : Bool; -overload ByteSizedInteger?(T) : Bool = false; +default ByteSizedInteger?(T) : Bool = false; overload ByteSizedInteger?(#Int8) : Bool = true; overload ByteSizedInteger?(#UInt8) : Bool = true; define Float?(..T) : Bool; -overload Float?(T) : Bool = false; +default Float?(T) : Bool = false; overload Float?(#Float32) : Bool = true; overload Float?(#Float64) : Bool = true; overload Float?(#Float80) : Bool = true; @@ -86,7 +86,7 @@ BuiltinFloatTypes() = Float32, Float64, Float80; define Imaginary?(..T) : Bool; -overload Imaginary?(T) : Bool = false; +default Imaginary?(T) : Bool = false; overload Imaginary?(#Imag32) : Bool = true; overload Imaginary?(#Imag64) : Bool = true; overload Imaginary?(#Imag80) : Bool = true; @@ -204,7 +204,7 @@ forceinline overload assign(ref dest:A, src:B) : { /// @section equals?, notEquals?, lesser?, lesserEquals?, greater?, greaterEquals? [A,B when Numeric?(A,B)] -forceinline overload (==)(a:A, b:B) : Bool = +forceinline default (==)(a:A, b:B) : Bool = (==)(toBiggerNumericType(A, B, a), toBiggerNumericType(A, B, b)); [A when Numeric?(A)] @@ -215,7 +215,7 @@ forceinline overload (==)(a:A, b:A) : Bool = floatOrderedEquals?(a, b); [A, B when Numeric?(A, B)] -forceinline overload (!=)(a:A, b:B) : Bool = +forceinline default (!=)(a:A, b:B) : Bool = (!=)(toBiggerNumericType(A, B, a), toBiggerNumericType(A, B, b)); [A when Numeric?(A)] @@ -226,7 +226,7 @@ forceinline overload (!=)(a:A, b:A) : Bool = floatUnorderedNotEquals?(a, b); [A,B when Numeric?(A,B)] -forceinline overload (<)(a:A, b:B) : Bool = +forceinline default (<)(a:A, b:B) : Bool = (<)(toBiggerNumericType(A, B, a), toBiggerNumericType(A, B, b)); [A when Numeric?(A)] @@ -237,7 +237,7 @@ forceinline overload (<)(a:A, b:A) : Bool = floatOrderedLesser?(a, b); [A, B when Numeric?(A, B)] -forceinline overload (<=)(a:A, b:B) : Bool = +forceinline default (<=)(a:A, b:B) : Bool = (<=)(toBiggerNumericType(A, B, a), toBiggerNumericType(A, B, b)); [A when Numeric?(A)] @@ -248,7 +248,7 @@ forceinline overload (<=)(a:A, b:A) : Bool = floatOrderedLesserEquals?(a, b); [A,B when Numeric?(A,B)] -forceinline overload (>)(a:A, b:B) : Bool = +forceinline default (>)(a:A, b:B) : Bool = (>)(toBiggerNumericType(A, B, a), toBiggerNumericType(A, B, b)); [A when Numeric?(A)] @@ -259,7 +259,7 @@ forceinline overload (>)(a:A, b:A) : Bool = floatOrderedGreater?(a, b); [A, B when Numeric?(A, B)] -forceinline overload (>=)(a:A, b:B) : Bool = +forceinline default (>=)(a:A, b:B) : Bool = (>=)(toBiggerNumericType(A, B, a), toBiggerNumericType(A, B, b)); [A when Numeric?(A)] @@ -282,49 +282,49 @@ forceinline overload zero?(x:T) : Bool = (==)(x, T(0)); /// @section binary ops [A,B when Numeric?(A,B)] -forceinline overload (+)(a:A, b:B) = +forceinline default (+)(a:A, b:B) = (+)(toBiggerNumericType(A, B, a), toBiggerNumericType(A, B, b)); [A when Numeric?(A)] -forceinline overload (+)(a:A, b:A) : A = numericAdd(a, b); +forceinline default (+)(a:A, b:A) : A = numericAdd(a, b); [A,B when Numeric?(A,B)] -forceinline overload (-)(a:A, b:B) = +forceinline default (-)(a:A, b:B) = (-)(toBiggerNumericType(A, B, a), toBiggerNumericType(A, B, b)); [A when Numeric?(A)] -forceinline overload (-)(a:A, b:A) : A = numericSubtract(a, b); +forceinline default (-)(a:A, b:A) : A = numericSubtract(a, b); [A,B when Numeric?(A,B)] -forceinline overload (*)(a:A, b:B) = +forceinline default (*)(a:A, b:B) = (*)(toBiggerNumericType(A, B, a), toBiggerNumericType(A, B, b)); [A when Numeric?(A)] -forceinline overload (*)(a:A, b:A) : A = numericMultiply(a, b); +forceinline default (*)(a:A, b:A) : A = numericMultiply(a, b); [A,B when Float?(A,B)] -forceinline overload (/)(a:A, b:B) = +forceinline default (/)(a:A, b:B) = (/)(toBiggerNumericType(A, B, a), toBiggerNumericType(A, B, b)); [A when Float?(A)] -forceinline overload (/)(a:A, b:A) : A = floatDivide(a, b); +forceinline default (/)(a:A, b:A) : A = floatDivide(a, b); [A,B when Integer?(A,B)] -forceinline overload (\)(a:A, b:B) = +forceinline default (\)(a:A, b:B) = (\)(toBiggerNumericType(A, B, a), toBiggerNumericType(A, B, b)); [A when Integer?(A)] -forceinline overload (\)(a:A, b:A) : A = integerQuotient(a, b); +forceinline default (\)(a:A, b:A) : A = integerQuotient(a, b); [A,B when Integer?(A,B)] -forceinline overload (%)(a:A, b:B) = +forceinline default (%)(a:A, b:B) = (%)(toBiggerNumericType(A, B, a), toBiggerNumericType(A, B, b)); [A when Integer?(A)] -forceinline overload (%)(a:A, b:A) : A = integerRemainder(a, b); +forceinline default (%)(a:A, b:A) : A = integerRemainder(a, b); /// @section Variadic ops @@ -380,8 +380,8 @@ forceinline overload (-)(a:A) : A = numericNegate(a); /// @section inc, dec -forceinline overload inc(ref ..a) : { eachValue(inc, ..a); } -forceinline overload dec(ref ..a) : { eachValue(dec, ..a); } +forceinline default inc(ref ..a) : { eachValue(inc, ..a); } +forceinline default dec(ref ..a) : { eachValue(dec, ..a); } [A when Numeric?(A)] forceinline overload inc(ref a:A) : { @@ -398,13 +398,13 @@ forceinline overload dec(ref a:A) : { /// @section bitwise ops [A,B when Integer?(A,B)] -forceinline overload (<<)(a:A, b:B) : A = integerShiftLeft(a, A(b)); +forceinline default (<<)(a:A, b:B) : A = integerShiftLeft(a, A(b)); [A,B when Integer?(A,B)] -forceinline overload (>>)(a:A, b:B) : A = integerShiftRight(a, A(b)); +forceinline default (>>)(a:A, b:B) : A = integerShiftRight(a, A(b)); [A,B when Integer?(A,B)] -forceinline overload (&)(a:A, b:B) = +forceinline default (&)(a:A, b:B) = integerBitwiseAnd(wrapToBiggerNumericType(A, B, a), wrapToBiggerNumericType(A, B, b)); @@ -412,7 +412,7 @@ forceinline overload (&)(a:A, b:B) = forceinline overload (&)(a:A, b:A) : A = integerBitwiseAnd(a, b); [A,B when Integer?(A,B)] -forceinline overload (|)(a:A, b:B) = +forceinline default (|)(a:A, b:B) = integerBitwiseOr(wrapToBiggerNumericType(A, B, a), wrapToBiggerNumericType(A, B, b)); @@ -420,7 +420,7 @@ forceinline overload (|)(a:A, b:B) = forceinline overload (|)(a:A, b:A) : A = integerBitwiseOr(a, b); [A,B when Integer?(A,B)] -forceinline overload (~)(a:A, b:B) = +forceinline default (~)(a:A, b:B) = integerBitwiseXor(wrapToBiggerNumericType(A, B, a), wrapToBiggerNumericType(A, B, b)); diff --git a/lib-clay/core/numbers/overflow/overflow.clay b/lib-clay/core/numbers/overflow/overflow.clay index e1fb3ad94..a1289005f 100644 --- a/lib-clay/core/numbers/overflow/overflow.clay +++ b/lib-clay/core/numbers/overflow/overflow.clay @@ -230,7 +230,7 @@ forceinline overload integerConvertWithOverflow(#A, b:B) : A, Bool // callbacks for integer*Checked primitives private define PrintfFmt; -[T] overload PrintfFmt(#T) = "%d"; +[T] default PrintfFmt(#T) = "%d"; overload PrintfFmt(#UInt32) = "%u"; overload PrintfFmt(#Int64) = "%lld"; diff --git a/lib-clay/core/operators/operators.clay b/lib-clay/core/operators/operators.clay index 8d584c641..f086fae89 100644 --- a/lib-clay/core/operators/operators.clay +++ b/lib-clay/core/operators/operators.clay @@ -93,7 +93,7 @@ Movable?(T) = CallDefined?(move, T); [T] -forceinline overload assign(ref dest:T, rvalue src:T) : { +forceinline default assign(ref dest:T, rvalue src:T) : { swap(dest, src); } @@ -119,10 +119,10 @@ forceinline overload assign(ref dest:T, ref src:T) : { } [T when CallDefined?(T) and InitializeDoesNotThrowType?(T)] -forceinline overload resetUnsafe(src:T) { src <-- T(); } +forceinline default resetUnsafe(src:T) { src <-- T(); } [F] -forceinline overload updateAssign(#F, ref dest, forward ..src) : { +forceinline default updateAssign(#F, ref dest, forward ..src) : { dest = infixOperator(dest,F, ..src); } @@ -131,16 +131,16 @@ forceinline overload prefixUpdateAssign(#F, ref dest, forward ..src) : { dest = prefixOperator(F, dest, ..src); } -forceinline overload (!=)(a, b) : Bool = not (==)(a, b); +forceinline default (!=)(a, b) : Bool = not (==)(a, b); define ordered?; forceinline overload ordered?(a, b) : Bool = (<=)(a, b) or (<=)(b, a); -forceinline overload (<=)(a, b) : Bool = not (<)(b, a); +forceinline default (<=)(a, b) : Bool = not (<)(b, a); -forceinline overload (>)(a, b) : Bool = (<)(b, a); +forceinline default (>)(a, b) : Bool = (<)(b, a); -forceinline overload (>=)(a, b) : Bool = not (<)(a, b); +forceinline default (>=)(a, b) : Bool = not (<)(a, b); forceinline overload (&)(a, b, c, ..rest) = (&)((&)(a, b), c, ..rest); @@ -241,7 +241,7 @@ private define _countIndices; private define staticEquals?(a, b) : Bool; [A, B] -forceinline overload staticEquals?(a:Static[A], b:Static[B]) : Bool = false; +forceinline default staticEquals?(a:Static[A], b:Static[B]) : Bool = false; [A] forceinline overload staticEquals?(a:Static[A], b:Static[A]) : Bool = true; @@ -250,7 +250,7 @@ BinaryOpDefined?(OP,T,U) : Bool = Symbol?(OP) and not Variant?(OP) and not Recor CompareOpDefined?(OP,T,U) : Bool = Symbol?(OP) and not Variant?(OP) and not Record?(OP) and CallDefined?(OP,T,U) and staticEquals?(CallOutputTypes(OP,T,U),Bool); -[OP] forceinline overload prefixOperator(#OP, forward ..xs) +[OP] forceinline default prefixOperator(#OP, forward ..xs) = forward OP(..prefixOperator(..xs)); [OP] forceinline overload prefixOperator(#OP, forward x) = forward ..OP(x); @@ -308,8 +308,8 @@ define operatorPrecedence(T) : Int; define operatorAssociativity(T) : Int; -[T] overload operatorPrecedence(#T) : Int = 0; -[T] overload operatorAssociativity(#T) : Int = LEFT; +[T] default operatorPrecedence(#T) : Int = 0; +[T] default operatorAssociativity(#T) : Int = LEFT; overload operatorPrecedence(#(*)) : Int = 1000; overload operatorPrecedence(#(/)) : Int = 1000; @@ -348,7 +348,7 @@ overload operatorAssociativity(#(<=)) : Int = BOOLEAN; overload operatorAssociativity(#(>=)) : Int = BOOLEAN; define Operator?(..x) : Bool; -forceinline overload Operator?(..x) : Bool = false; +forceinline default Operator?(..x) : Bool = false; [OP] forceinline overload Operator?(#OP) : Bool = Symbol?(OP) and operatorPrecedence(OP) > 0; @@ -356,9 +356,9 @@ define BoolAssoc?(..x) : Bool; define LeftAssoc?(..x) : Bool; define RightAssoc?(..x) : Bool; -forceinline overload BoolAssoc?(..x) : Bool = false; -forceinline overload LeftAssoc?(..x) : Bool = false; -forceinline overload RightAssoc?(..x) : Bool = false; +forceinline default BoolAssoc?(..x) : Bool = false; +forceinline default LeftAssoc?(..x) : Bool = false; +forceinline default RightAssoc?(..x) : Bool = false; [OP] forceinline overload BoolAssoc?(#OP) : Bool = integerEquals?(operatorAssociativity(OP),BOOLEAN); [OP1,OP2] forceinline overload BoolAssoc?(#OP1,#OP2) : Bool = BoolAssoc?(OP1) and BoolAssoc?(OP2); @@ -383,7 +383,7 @@ forceinline overload infixToPolish(#0, #s, #v, forward ..y, #p, #T) = forward ..infixToPolish(#0, #(s-1), #1, ..y), T, #(p+v); [n, s, v when n>0] -forceinline overload infixToPolish(#n, #s, #v,forward x, forward ..y) +forceinline default infixToPolish(#n, #s, #v,forward x, forward ..y) = forward ..infixToPolish(#(n-1), #s, #(v+1), ..y), x; [n, s, v, OP when n>0 and Operator?(OP)] @@ -400,17 +400,17 @@ forceinline overload infixToPolish(#n, #s, #v, #OP, forward ..y, #p, #T) private define evalPolish; forceinline overload evalPolish() = ; -forceinline overload evalPolish(x, ..y) = x, ..evalPolish(..y); +forceinline default evalPolish(x, ..y) = x, ..evalPolish(..y); [OP, v when Operator?(OP)] -forceinline overload evalPolish(#OP, #v, ..x) +forceinline default evalPolish(#OP, #v, ..x) = OP(..takeValues(#v, ..evalPolish(..x))), ..dropValues(#v, ..evalPolish(..x)); [OP, v when BoolAssoc?(OP)] forceinline overload evalPolish(#OP, #v, ..x) = OP, ..evalPolish(..x); private define evalBool; -forceinline overload evalBool(..x) = ..x; +forceinline default evalBool(..x) = ..x; [OP, OP2 when BoolAssoc?(OP, OP2)] forceinline overload evalBool(#OP, y, #OP2, z, ..x) : Bool @@ -420,12 +420,12 @@ forceinline overload evalBool(#OP, y, #OP2, z, ..x) : Bool forceinline overload evalBool(#OP, x, y) : Bool = OP(x, y); [..T] -forceinline overload infixOperator(forward ..args:T) +forceinline default infixOperator(forward ..args:T) = forward ..evalBool(..evalPolish( ..infixToPolish(#countValues(..T), #0, #0, ..reverseValues(..args)))); [OP] -forceinline overload infixOperator(forward a, #OP, forward b) +forceinline default infixOperator(forward a, #OP, forward b) = forward ..OP(a,b); @@ -433,7 +433,7 @@ forceinline overload infixOperator(forward a, #OP, forward b) define swap(a, b) :; -forceinline overload swap(a, b) : { +forceinline default swap(a, b) : { var temp = moveUnsafe(a); a <-- moveUnsafe(b); b <-- move(temp); @@ -456,7 +456,7 @@ define min(a:T, b:T) : T; define max(a:T, b:T) : T; [T] -forceinline overload min(a:T, b:T) --> c:T { +forceinline default min(a:T, b:T) --> c:T { if (a <= b) c <-- a; else @@ -472,7 +472,7 @@ forceinline overload min(ref a:T, ref b:T) : ByRef[T] { } [T] -forceinline overload max(a:T, b:T) --> c:T { +forceinline default max(a:T, b:T) --> c:T { if (a > b) c <-- a; else @@ -492,7 +492,7 @@ forceinline overload max(ref a:T, ref b:T) : ByRef[T] { /// @section ifExpression [T] -alias overload ifExpression(condition, consequent:T, alternate:T) --> ret:T { +alias default ifExpression(condition, consequent:T, alternate:T) --> ret:T { if (condition) ret <-- consequent; else @@ -522,7 +522,7 @@ alias overload ifExpression(condition, #consequent, #alternate) --> ret:StringLi /// @section asExpression [T, U] -forceinline overload asExpression(value:T, #U) : U = U(value); +forceinline default asExpression(value:T, #U) : U = U(value); [T, U when Numeric?(T,U)] forceinline overload asExpression(value:T, #U) : U = numericConvert(U, value); @@ -557,7 +557,7 @@ bitror(x:I, n:J) = (|)((>>)(x, n), wrapBitshl(x, TypeSize(I)*8 - n)); [T] define PrimitiveType?(#T) : Bool; -overload PrimitiveType?(X) : Bool = false; +default PrimitiveType?(X) : Bool = false; overload PrimitiveType?(#Bool) : Bool = true; overload PrimitiveType?(#Int8) : Bool = true; overload PrimitiveType?(#Int16) : Bool = true; @@ -594,7 +594,7 @@ overload PrimitiveType?(#Tuple[]) : Bool = true; [T] define PrimitiveCompoundType?(#T) : Bool; -overload PrimitiveCompoundType?(X) : Bool = false; +default PrimitiveCompoundType?(X) : Bool = false; [T,n] overload PrimitiveCompoundType?(#Array[T,n]) : Bool = true; [..T] overload PrimitiveCompoundType?(#Tuple[..T]) : Bool = true; @@ -614,7 +614,7 @@ overload PrimitiveCompoundMemberTypes(#V) = ..VariantMembers(V); [T] define PODType?(#T) : Bool; -overload PODType?(X) : Bool = false; +default PODType?(X) : Bool = false; [T when PrimitiveType?(T)] overload PODType?(#T) : Bool = true; @@ -645,15 +645,15 @@ define BitwiseAssignedType?(#T) : Bool; [T] define BitwiseMoveAssignedType?(#T) : Bool; -overload BitwiseCopiedType?(T) = PODType?(T); -overload BitwiseMovedType?(T) = PODType?(T); -overload DestroyDoesNothingType?(T) = PODType?(T); -overload ResetDoesNothingType?(T) = PODType?(T); -overload InitializeDoesNotThrowType?(T) = PODType?(T); -overload CopyDoesNotThrowType?(T) = PODType?(T); -overload AssignDoesNotThrowType?(T) = PODType?(T); -overload BitwiseAssignedType?(T) = BitwiseCopiedType?(T) and DestroyDoesNothingType?(T); -overload BitwiseMoveAssignedType?(T) = BitwiseMovedType?(T) and DestroyDoesNothingType?(T); +default BitwiseCopiedType?(T) = PODType?(T); +default BitwiseMovedType?(T) = PODType?(T); +default DestroyDoesNothingType?(T) = PODType?(T); +default ResetDoesNothingType?(T) = PODType?(T); +default InitializeDoesNotThrowType?(T) = PODType?(T); +default CopyDoesNotThrowType?(T) = PODType?(T); +default AssignDoesNotThrowType?(T) = PODType?(T); +default BitwiseAssignedType?(T) = BitwiseCopiedType?(T) and DestroyDoesNothingType?(T); +default BitwiseMoveAssignedType?(T) = BitwiseMovedType?(T) and DestroyDoesNothingType?(T); [T when PrimitiveCompoundType?(T)] overload BitwiseCopiedType?(#T) : Bool @@ -708,13 +708,13 @@ forceinline overload case?(x, forward ..ys) : Bool { define CallDefined?; [F] -alias overload CallDefined?(f:F, ..In) : Bool = StaticCallDefined?(call, F, ..In); +alias default CallDefined?(f:F, ..In) : Bool = StaticCallDefined?(call, F, ..In); [f] alias overload CallDefined?(#f, ..In) : Bool = Symbol?(f) and StaticCallDefined?(f, ..In); define CallOutputTypes; [F] -alias overload CallOutputTypes(f:F, ..In) = ..StaticCallOutputTypes(call, F, ..In); +alias default CallOutputTypes(f:F, ..In) = ..StaticCallOutputTypes(call, F, ..In); [f] alias overload CallOutputTypes(#f, ..In) = ..StaticCallOutputTypes(f, ..In); @@ -723,7 +723,7 @@ alias overload CallOutputTypes(#f, ..In) = ..StaticCallOutputTypes(f, ..In); define MonoInputTypes; [f when StaticMono?(f)] -alias overload MonoInputTypes(#f) = ..StaticMonoInputTypes(f); +alias default MonoInputTypes(#f) = ..StaticMonoInputTypes(f); [F when LambdaRecord?(F) and LambdaMono?(F)] alias overload MonoInputTypes(f:F) = ..LambdaMonoInputTypes(F); diff --git a/lib-clay/core/operators/pod/pod.clay b/lib-clay/core/operators/pod/pod.clay index 065bd4e38..cc35fd99d 100644 --- a/lib-clay/core/operators/pod/pod.clay +++ b/lib-clay/core/operators/pod/pod.clay @@ -15,7 +15,7 @@ forceinline overload copyNonoverlappingMemory(destBegin:Pointer[P], srcBegin:Poi copyNonovPODs(destBegin, srcBegin, srcEnd); } [P when BitwiseMovedType?(P)] -forceinline overload moveMemory(destBegin:Pointer[P], srcBegin:Pointer[P], srcEnd:Pointer[P]) : { +forceinline default moveMemory(destBegin:Pointer[P], srcBegin:Pointer[P], srcEnd:Pointer[P]) : { copyPODs(destBegin, srcBegin, srcEnd); var destEnd = destBegin + (srcEnd - srcBegin); if (destBegin <= srcBegin) @@ -32,7 +32,7 @@ forceinline overload moveMemoryUnsafe(destBegin:Pointer[P], srcBegin:Pointer[P], copyPODs(destBegin, srcBegin, srcEnd); } [P when BitwiseMovedType?(P)] -forceinline overload moveNonoverlappingMemory(destBegin:Pointer[P], srcBegin:Pointer[P], srcEnd:Pointer[P]) : { +forceinline default moveNonoverlappingMemory(destBegin:Pointer[P], srcBegin:Pointer[P], srcEnd:Pointer[P]) : { copyNonovPODs(destBegin, srcBegin, srcEnd); resetMemoryUnsafe(srcBegin, srcEnd); } @@ -67,7 +67,7 @@ forceinline overload destroyMemory(begin:Pointer[P], end:Pointer[P]) : { } define copyPOD; -[P] forceinline overload copyPOD(x: P) --> returned: P { memcpy(@returned, @x, TypeSize(P)); } +[P] forceinline default copyPOD(x: P) --> returned: P { memcpy(@returned, @x, TypeSize(P)); } forceinline overload copyPOD(x: Bool) --> returned: Bool { bitcopy(returned, x); } [N when Numeric?(N)] forceinline overload copyPOD(x: N) --> returned: N { bitcopy(returned, x); } @@ -92,5 +92,5 @@ forceinline overload resetUnsafe(x: P) : { } [P when BitwiseCopiedType?(P)] forceinline overload P(x: P) --> returned: P = copyPOD(x); [P when BitwiseAssignedType?(P)] -forceinline overload assign(ref x: P, y: P) : { x <-- copyPOD(y); } +forceinline default assign(ref x: P, y: P) : { x <-- copyPOD(y); } diff --git a/lib-clay/core/pointers/pointers.clay b/lib-clay/core/pointers/pointers.clay index adc0cf677..01fa5d49d 100644 --- a/lib-clay/core/pointers/pointers.clay +++ b/lib-clay/core/pointers/pointers.clay @@ -209,7 +209,7 @@ overload CCastable?(#F, #T) : Bool = false; overload CCastable?(#F, #T) : Bool = true; [F, T when Integer?(F) and Integer?(T) and TypeSize(T) == TypeSize(F)] -overload CCastable?(#Pointer[F], #Pointer[T]) : Bool = true; +default CCastable?(#Pointer[F], #Pointer[T]) : Bool = true; [F] overload CCastable?(#Pointer[F], #RawPointer) : Bool = true; @@ -227,7 +227,7 @@ overload cCast(s:S, #Pointer[CChar]) : Pointer[CChar] = cstring(s); overload cCast(forward from:F, #F) = forward from; [CC, ..In, ..Out, ..A when countValues(..In) == countValues(..A)] -forceinline overload call(ptr:ExternalCodePointer[CC, false, [..In], [..Out]], ..args:A) = +forceinline default call(ptr:ExternalCodePointer[CC, false, [..In], [..Out]], ..args:A) = ..callExternalCodePointer(ptr, ..mapValues2((arg, T) => cCast(arg, T), #countValues(..A), ..args, ..In)); @@ -236,7 +236,7 @@ forceinline overload call(ptr:ExternalCodePointer[CC, false, [..In], [..Out]], . ..callExternalCodePointer(ptr, ..args); [CC, ..In, ..Out, ..A when (countValues(..A) >= countValues(..In))] -forceinline overload call(ptr:ExternalCodePointer[CC, true, [..In], [..Out]], ..args:A) { +forceinline default call(ptr:ExternalCodePointer[CC, true, [..In], [..Out]], ..args:A) { alias N = #countValues(..In); return ..callExternalCodePointer(ptr, ..mapValues2((arg, T) => cCast(arg, T), N, ..takeValues(N, ..args), ..In), diff --git a/lib-clay/core/ranges/ranges.clay b/lib-clay/core/ranges/ranges.clay index 0b1601c70..b9ce18c47 100644 --- a/lib-clay/core/ranges/ranges.clay +++ b/lib-clay/core/ranges/ranges.clay @@ -94,10 +94,10 @@ forceinline overload end(a:ReverseRange[T]) : ValueReverseCoordinate[T] define range; [T] -forceinline overload range(begin:T, end:T) : Range[T] = Range(begin, end); +forceinline default range(begin:T, end:T) : Range[T] = Range(begin, end); [A,B when Integer?(A) and Integer?(B)] -forceinline overload range(begin:A, end:B) = +forceinline default range(begin:A, end:B) = Range(toBiggerNumericType(A, B, begin), toBiggerNumericType(A, B, end)); diff --git a/lib-clay/core/records/records.clay b/lib-clay/core/records/records.clay index ae0055f1f..1c6ac2081 100644 --- a/lib-clay/core/records/records.clay +++ b/lib-clay/core/records/records.clay @@ -45,10 +45,10 @@ RecordFieldNames(R) = ..mapValues( define RegularRecord?(#T) : Bool; [T] -overload RegularRecord?(#T) : Bool = false; +default RegularRecord?(#T) : Bool = false; [T when Record?(T)] -overload RegularRecord?(#T) : Bool = true; +default RegularRecord?(#T) : Bool = true; @@ -58,7 +58,7 @@ overload RegularRecord?(#T) : Bool = true; define initializeRecord(#T, ..args:A): T; [T, ..A when Record?(T) and (Tuple[..RecordFieldTypes(T)] == Tuple[..A])] -alias overload initializeRecord(#T, ..args:A) --> returned:T { +alias default initializeRecord(#T, ..args:A) --> returned:T { ..recordFields(returned) <-- ..args; } @@ -134,7 +134,7 @@ destroyRecord(a:T) : { } [T when RegularRecord?(T) and not DestroyDoesNothingType?(T)] -overload destroy(a:T) : { +default destroy(a:T) : { destroyRecord(a); } @@ -154,7 +154,7 @@ overload assign(ref dest:T, ref src:T) : { /// @section equals? [T when RegularRecord?(T)] -overload equals?(a:T, b:T) : Bool { +default equals?(a:T, b:T) : Bool { alias n = RecordFieldCount(T); ..for (i in staticIntegers(#n)) { if (not equals?(fieldRefByIndex(a, i), fieldRefByIndex(b, i))) @@ -168,7 +168,7 @@ overload equals?(a:T, b:T) : Bool { /// @section lesser? [T when RegularRecord?(T)] -overload lesser?(a:T, b:T) : Bool { +default lesser?(a:T, b:T) : Bool { alias n = RecordFieldCount(T); ..for (i in staticIntegers(#n)) { ref av = fieldRefByIndex(a, i); diff --git a/lib-clay/core/sequences/sequences.clay b/lib-clay/core/sequences/sequences.clay index 3369a3d86..abeca056b 100644 --- a/lib-clay/core/sequences/sequences.clay +++ b/lib-clay/core/sequences/sequences.clay @@ -86,14 +86,14 @@ define popFront(s:S); // default implementation using `push` -overload pushAll(s, vs) : { +default pushAll(s, vs) : { for (v in vs) { push(s, v); } } // default implementation using `insert` -overload insertAll(s, coord, vs) : { +default insertAll(s, coord, vs) : { var insertPoint = coord; for (v in vs) { insert(v, insertPoint, vs); @@ -136,26 +136,26 @@ SequenceIteratorType(T) = Type(iterator(typeToLValue(T))); [T] define ContiguousSequence?(#T) : Bool; -overload ContiguousSequence?(T) : Bool = false; +default ContiguousSequence?(T) : Bool = false; // true if copying the sequence is efficient [T] define LightweightSequence?(#T) : Bool; -overload LightweightSequence?(T) : Bool = false; +default LightweightSequence?(T) : Bool = false; // true for sequences which have value semantics. [T] define SequenceContainer?(#T) : Bool; -overload SequenceContainer?(T) : Bool = false; +default SequenceContainer?(T) : Bool = false; // true if sequence is not single-valued (0 valued sequences are included). MultiValuedSequence?(T) : Bool = Sequence?(T) and multiValued?(..Type(..getValue(nextValue(iterator(typeToLValue(T)))))); private define multiValued?(..x) : Bool; -overload multiValued?(..x) : Bool = true; +default multiValued?(..x) : Bool = true; overload multiValued?(x) : Bool = false; @@ -180,7 +180,7 @@ forceinline contains?(map, key) : Bool = not null?(lookup(map, key)); /// @section generic equals?, lesser? [A,B when Sequence?(A) and Sequence?(B) and not StringLiteralType?(A,B)] -overload equals?(a:A, b:B) : Bool { +default equals?(a:A, b:B) : Bool { var i, j = iterator(a), iterator(b); while (true) { var iv, jv = nextValue(i), nextValue(j); diff --git a/lib-clay/core/statics/statics.clay b/lib-clay/core/statics/statics.clay index 876dd4b55..1ca1a101e 100644 --- a/lib-clay/core/statics/statics.clay +++ b/lib-clay/core/statics/statics.clay @@ -30,7 +30,7 @@ forceinline overload moveUnsafe(src:Static[A]) --> returned:Static[A] { /// @section equals?, lesser? [A, B] -forceinline overload equals?(a:Static[A], b:Static[B]) : Bool = false; +forceinline default equals?(a:Static[A], b:Static[B]) : Bool = false; [A] forceinline overload equals?(a:Static[A], b:Static[A]) : Bool = true; diff --git a/lib-clay/core/strings/stringliterals/stringliterals.clay b/lib-clay/core/strings/stringliterals/stringliterals.clay index 1bdf816d3..cd4a02b16 100644 --- a/lib-clay/core/strings/stringliterals/stringliterals.clay +++ b/lib-clay/core/strings/stringliterals/stringliterals.clay @@ -80,7 +80,7 @@ forceinline overload reverseIterator(#s) = /// @section string literal concatenation private define StringLiteralStatic?(s) : Bool; -overload StringLiteralStatic?(s) : Bool = false; +default StringLiteralStatic?(s) : Bool = false; [s] overload StringLiteralStatic?(#Static[s]) : Bool = StringLiteral?(s); @@ -146,10 +146,10 @@ overload stringLiteralFind(identifier, sub) = stringLiteralFind(identifier, sub, define strl; -overload strl(..xx) = stringLiteralConcat(..mapValues(strl, ..xx)); +default strl(..xx) = stringLiteralConcat(..mapValues(strl, ..xx)); [x] -overload strl(#x) = StaticName(#x); +default strl(#x) = StaticName(#x); [i when StringLiteral?(i)] overload strl(#i) = i; diff --git a/lib-clay/core/system/system.clay b/lib-clay/core/system/system.clay index adf64c590..032dd1e9f 100644 --- a/lib-clay/core/system/system.clay +++ b/lib-clay/core/system/system.clay @@ -35,7 +35,7 @@ private alias runMain(argc_, argv_, f, ..args) : Int { } [Main] -overload __operators__.callMain(#Main, argc_:Int, argv_:Pointer[Pointer[Int8]]) : Int +default __operators__.callMain(#Main, argc_:Int, argv_:Pointer[Pointer[Int8]]) : Int = runMain(argc_, argv_, Main); [Main when CallDefined?(Main, Type(commandLine()))] diff --git a/lib-clay/core/tuples/tuples.clay b/lib-clay/core/tuples/tuples.clay index 0293a5cc6..7be25a598 100644 --- a/lib-clay/core/tuples/tuples.clay +++ b/lib-clay/core/tuples/tuples.clay @@ -37,7 +37,7 @@ forceinline unpackTupleRef(x:Tuple[..T]) = ref ..tupleElements(x); define unpackRef private overload; -forceinline overload unpackRef(x) = ref x; +forceinline default unpackRef(x) = ref x; [..T] forceinline overload unpackRef(x:Tuple[..T]) = ref ..unpackTupleRef(x); diff --git a/lib-clay/core/values/values.clay b/lib-clay/core/values/values.clay index f4a9abfc4..5ec0cfc9a 100644 --- a/lib-clay/core/values/values.clay +++ b/lib-clay/core/values/values.clay @@ -43,7 +43,7 @@ forceinline overload foldlValues(fn, forward x1, forward x2, forward ..xs) forceinline overload foldlValues(fn, forward x) = forward x; define weaveValues private overload; -forceinline overload weaveValues(between, forward x, forward ..xs) +forceinline default weaveValues(between, forward x, forward ..xs) = forward x, between, ..weaveValues(between, ..xs); forceinline overload weaveValues(between, forward x, forward y) = forward x, between, y; @@ -120,7 +120,7 @@ private record CapturedRValue[T] ( define CapturedValue?(a) : Bool private overload; -overload CapturedValue?(a) : Bool = false; +default CapturedValue?(a) : Bool = false; [T] overload CapturedValue?(#CapturedLValue[T]) : Bool = true; [T] @@ -195,7 +195,7 @@ overload mapValues2(fn, #0, forward ..xs) = ; define assocValue private overload; [key] -overload assocValue(#key, kv, forward ..kvs) = forward ..assocValue(#key, ..kvs); +default assocValue(#key, kv, forward ..kvs) = forward ..assocValue(#key, ..kvs); [key, ..T] overload assocValue(#key, forward kv: Tuple[Static[key], ..T], ..kvs) diff --git a/lib-clay/core/variants/nested/nested.clay b/lib-clay/core/variants/nested/nested.clay index 92893a573..82c238b0b 100644 --- a/lib-clay/core/variants/nested/nested.clay +++ b/lib-clay/core/variants/nested/nested.clay @@ -17,7 +17,7 @@ VariantNestingPaths(#V, #M) = private define VariantNestingPaths2; [V,M] -overload VariantNestingPaths2(#V, #M, Prefix) { +default VariantNestingPaths2(#V, #M, Prefix) { alias SubV = Tuple(..SubVariants(V)); return ..VariantNestingPaths3(SubV, M, Prefix, #0); } @@ -32,7 +32,7 @@ overload VariantNestingPaths2(#V, #M, Prefix) { private define VariantNestingPaths3; [i] -overload VariantNestingPaths3(Vs, M, Prefix, #i) { +default VariantNestingPaths3(Vs, M, Prefix, #i) { alias V = staticIndex(Vs, #i); alias NewPrefix = Tuple(..unpack(Prefix), V); return ..VariantNestingPaths2(V, M, NewPrefix), diff --git a/lib-clay/data/vectors/generic/generic.clay b/lib-clay/data/vectors/generic/generic.clay index 359753ebd..ea59152ab 100644 --- a/lib-clay/data/vectors/generic/generic.clay +++ b/lib-clay/data/vectors/generic/generic.clay @@ -4,7 +4,7 @@ /// @section generic vector requirements define Vector?; -overload Vector?(x) = false; +default Vector?(x) = false; define vectorData; define vectorSize; @@ -16,7 +16,7 @@ define vectorRequestCapacity; /// @section predicates [V when Vector?(V)] -overload ContiguousSequence?(#V) = true; +default ContiguousSequence?(#V) = true; /// @section size, index @@ -135,7 +135,7 @@ private forceinline ensureSpace(a, space:SizeT) { private define insertLocationsUnsafe; [I, J when Integer?(I) and Integer?(J)] -overload insertLocationsUnsafe(a, pos:I, n:J) { +default insertLocationsUnsafe(a, pos:I, n:J) { return ..insertLocationsUnsafe(a, SizeT(pos), SizeT(n)); } @@ -161,7 +161,7 @@ overload insertAll(a:V, i:I, seq:S) { [V,I,S when Vector?(V) and Integer?(I) and SizedSequence?(S) and (SequenceElementType(S) == SequenceElementType(V)) and LValueSequence?(S)] -overload insertAll(a:V, i:I, seq:S) { +default insertAll(a:V, i:I, seq:S) { assert(i >= 0 and i <= size(a), "invalid position for insert into ", V); var first, last = ..insertLocationsUnsafe(a, i, size(seq)); try { diff --git a/lib-clay/data/vectors/vectors.clay b/lib-clay/data/vectors/vectors.clay index 59945f34e..dd3cf1f62 100644 --- a/lib-clay/data/vectors/vectors.clay +++ b/lib-clay/data/vectors/vectors.clay @@ -122,7 +122,7 @@ overload vectorRequestCapacity(a:Vector[T], capacity:SizeT) { private define reallocVector; [T] -overload reallocVector(a:Vector[T], capacity:SizeT) { +default reallocVector(a:Vector[T], capacity:SizeT) { var data = allocateRawMemory(T, capacity); moveNonoverlappingMemoryUnsafe(data, a.data, a.data + a.size); freeRawMemory(a.data); diff --git a/lib-clay/hash/hash.clay b/lib-clay/hash/hash.clay index 4c573d5f3..bcf69817f 100644 --- a/lib-clay/hash/hash.clay +++ b/lib-clay/hash/hash.clay @@ -48,7 +48,7 @@ forceinline overload hash(z:T) = wrapAdd( [T] forceinline overload hash(x:Pointer[T]) = bitcast(SizeT, x); -forceinline overload hash(x:Char) = wrapCast(SizeT, x); +forceinline default hash(x:Char) = wrapCast(SizeT, x); @@ -63,13 +63,13 @@ forceinline overload hash(a:Array[T,n]) = hashSequence(a); define hashValues; -forceinline overload hashValues(..values) { +forceinline default hashValues(..values) { var h = SizeT(0); ..for (x in values) h = wrapAdd(wrapMultiply(SizeT(7), h), wrapMultiply(SizeT(13), hash(x))); return h; } -forceinline overload hashValues(value) = hash(value); +forceinline default hashValues(value) = hash(value); [..T] forceinline overload hash(x:Tuple[..T]) = hashValues(..tupleElements(x)); @@ -98,7 +98,7 @@ forceinline overload hash(x:SharedPointer[T]) = hash(x.ptr); /// @section strings -forceinline overload hash(a:String) = hashSequence(a); +forceinline default hash(a:String) = hashSequence(a); forceinline overload hash(a:StringLiteralRef) = hashSequence(a); diff --git a/lib-clay/io/files/raw/raw.clay b/lib-clay/io/files/raw/raw.clay index e6d35e716..7b5152355 100644 --- a/lib-clay/io/files/raw/raw.clay +++ b/lib-clay/io/files/raw/raw.clay @@ -16,7 +16,7 @@ overload fileSize (f: RawFilePointer, ..args) = ..fileSize (f.rawFile^, ..args overload seek (f: RawFilePointer, ..args) = ..seek (f.rawFile^, ..args); overload fileHandle(f: RawFilePointer, ..args) = ..fileHandle(f.rawFile^, ..args); -overload RawFilePointer(..args) = +default RawFilePointer(..args) = initializeRecord(RawFilePointer, new(RawFile(..args))); overload RawFilePointer(rvalue rawFile: RawFile) = diff --git a/lib-clay/math/native/gamma.clay b/lib-clay/math/native/gamma.clay index b520db1f4..1f911a51f 100644 --- a/lib-clay/math/native/gamma.clay +++ b/lib-clay/math/native/gamma.clay @@ -189,14 +189,14 @@ lgamma_r(xarg:Double, signgamp:Pointer[Int]) { case (5) goto case5; // FALLTHRU case (4) goto case4; // FALLTHRU case (3) goto case3; // FALLTHRU - case (2,1,0) goto default; + case (2,1,0) goto defaultCase; case7: z *: (y+6.0); // FALLTHRU case6: z *: (y+5.0); // FALLTHRU case5: z *: (y+4.0); // FALLTHRU case4: z *: (y+3.0); // FALLTHRU case3: z *: (y+2.0); // FALLTHRU -default: +defaultCase: r +: log(z); // 8.0 <= x < 2**58 } diff --git a/lib-clay/printer/types/types.clay b/lib-clay/printer/types/types.clay index 8751fd816..6e5622c92 100644 --- a/lib-clay/printer/types/types.clay +++ b/lib-clay/printer/types/types.clay @@ -41,12 +41,12 @@ overload printTo(stream, x:Bool) { /// @section printTo - integers, floats, pointers [I when SignedInteger?(I)] -overload printTo(stream, x:I) { +default printTo(stream, x:I) { printWithSprintf(stream, "%d", Int(x)); } [I when UnsignedInteger?(I)] -overload printTo(stream, x:I) { +default printTo(stream, x:I) { printWithSprintf(stream, "%u", UInt(x)); } @@ -154,7 +154,7 @@ forceinline printFloatWithSprintf(stream, nanString, formatString, ..values) { /// @section printTo - statics [X] -overload printTo(stream, x:Static[X]) { +default printTo(stream, x:Static[X]) { printTo(stream, StaticName(x)); } @@ -186,7 +186,7 @@ overload printTo(stream, x:Tuple[..T]) { } [T when Record?(T) and not LambdaRecord?(T)] -overload printTo(stream, x:T) { +default printTo(stream, x:T) { printTo(stream, T, "(", ..weaveValues(", ", ..recordFields(x)), ")"); } @@ -236,13 +236,13 @@ overload printTo(stream, x:UniChar) { } [S when String?(S) or UniString?(S)] -overload printTo(stream, x:S) { +default printTo(stream, x:S) { for (c in x) printTo(stream, c); } [S when ContiguousString?(S)] -overload printTo(stream, x:S) { +default printTo(stream, x:S) { write(stream, x); } @@ -380,13 +380,13 @@ overload printReprTo(stream, x:E) { /// @section printReprTo - statics [X] -overload printReprTo(stream, x:Static[X]) { +default printReprTo(stream, x:Static[X]) { printTo(stream, "#"); printReprTo(stream, unwrapStatic(x)); } [S when Symbol?(S)] -overload printReprTo(stream, #S) { +default printReprTo(stream, #S) { printTo(stream, StaticName(S)); } diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index b7fa9302a..47275b0f7 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -22,7 +22,8 @@ if(BUILD_BINDGEN) -I${clay_SOURCE_DIR}/tools -o ${clay_BINARY_DIR}/tools/clay-bindgen${CMAKE_EXECUTABLE_SUFFIX} ${LIBCLANG_LDFLAGS} - ${clay_SOURCE_DIR}/tools/bindgen.clay) + ${clay_SOURCE_DIR}/tools/bindgen.clay + -final-overloads) add_custom_target(clay-bindgen ALL DEPENDS ${clay_BINARY_DIR}/tools/clay-bindgen${CMAKE_EXECUTABLE_SUFFIX}) diff --git a/tools/bindgen.clay b/tools/bindgen.clay index ac4397fd1..342cc706b 100644 --- a/tools/bindgen.clay +++ b/tools/bindgen.clay @@ -12,7 +12,8 @@ import data.sequences.operators.*; var clayKeywords = array( "public", "private", "import", "as", "record", "variant", "instance", - "define", "overload", "external", "alias", + "define", "overload", "default", + "external", "alias", "static", "rvalue", "inline", "enum", "var", "ref", "forward", "and", "or", "not",