From 7ef972c041345de18576be89a0d6046890a51788 Mon Sep 17 00:00:00 2001 From: Carlo Kok Date: Tue, 26 Mar 2019 12:10:38 +0100 Subject: [PATCH 01/79] 0: Make iteration use key, value --- Source/Dictionary.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Dictionary.swift b/Source/Dictionary.swift index e73954e..8246fa1 100755 --- a/Source/Dictionary.swift +++ b/Source/Dictionary.swift @@ -95,7 +95,7 @@ public struct Dictionary /*: INSFastEnumeration*/ // @Sequence - public func GetSequence() -> ISequence<(Key, Value)> { + public func GetSequence() -> ISequence<(key: Key, value: Value)> { return DictionaryHelper.Enumerate(dictionary) } From 034ff6913bb03238acd2e65a1209984e997d6713 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Wed, 27 Mar 2019 15:55:01 -0400 Subject: [PATCH 02/79] Dictionary tests (tip) --- Tests/Dictionary.swift | 25 +++++++++++++++++++++++++ Tests/Swift.Tests.elements | 1 + 2 files changed, 26 insertions(+) create mode 100644 Tests/Dictionary.swift diff --git a/Tests/Dictionary.swift b/Tests/Dictionary.swift new file mode 100644 index 0000000..440d565 --- /dev/null +++ b/Tests/Dictionary.swift @@ -0,0 +1,25 @@ +import RemObjects.Elements.EUnit + +public class DictionaryTests : Test { + + public func test82211() { + + var dict = [String: String]() + dict["test"] = "someString" + + writeLn("dict[\"test\"] \(dict["test"])") + + Check.AreEqual(dict["test"], "someString") // good + Check.IsNotNil(dict["test"]) // good + Check.IsTrue(assigned(dict["test"])) // fails + Check.IsTrue(dict["test"] != nil) // fails + writeLn("dict[\"test\"] != nil \(dict["test"] != nil)") // False + writeLn("dict[\"test\"] == nil \(dict["test"] == nil)") // True + + let hasValue: Bool = dict["test"] != nil + writeLn("hasValue \(hasValue)") + if !hasValue { + throw Exception("dict[test] is not nil!") + } + } +} \ No newline at end of file diff --git a/Tests/Swift.Tests.elements b/Tests/Swift.Tests.elements index b6c0df2..3135122 100644 --- a/Tests/Swift.Tests.elements +++ b/Tests/Swift.Tests.elements @@ -146,6 +146,7 @@ + From 2ef1d5b4932f4eaf8e1127f580183f1e44a784ab Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Tue, 9 Apr 2019 09:43:16 -0400 Subject: [PATCH 03/79] Make `fatalError` @noreturn --- Source/Functions.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Functions.swift b/Source/Functions.swift index e0164d3..e3175ba 100644 --- a/Source/Functions.swift +++ b/Source/Functions.swift @@ -67,7 +67,7 @@ public func debugPrint(_ objects: Object?..., separator: String = " ", terminato return value } -public func fatalError(_ message: @autoclosure () -> String, file: String = #file, line: UInt32 = #line) -> Never { +@noreturn public func fatalError(_ message: @autoclosure () -> String, file: String = #file, line: UInt32 = #line) -> Never { if let message = message { __throw Exception(message()+", file "+file+", line "+line) } else { From 129f48fd7f6bd447535710fe9e04d45367d80a31 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Thu, 11 Apr 2019 15:07:01 -0400 Subject: [PATCH 04/79] Make Swift.Tests compile for all targets (except Was, as we don't ship EUnit/Wasm yet) --- Tests/Program.swift | 5 ++-- Tests/Swift.Tests.elements | 59 +++++++++++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/Tests/Program.swift b/Tests/Program.swift index bbad872..d22a04b 100644 --- a/Tests/Program.swift +++ b/Tests/Program.swift @@ -1,4 +1,5 @@ -import RemObjects.Elements.EUnit +import RemObjects.Elements.EUnit let lTests = Discovery.DiscoverTests() -Runner.RunTests(lTests, withListener: Runner.DefaultListener) \ No newline at end of file +Runner.RunTests(lTests, withListener: Runner.DefaultListener) +return 0 \ No newline at end of file diff --git a/Tests/Swift.Tests.elements b/Tests/Swift.Tests.elements index 3135122..2dcf58f 100644 --- a/Tests/Swift.Tests.elements +++ b/Tests/Swift.Tests.elements @@ -8,6 +8,7 @@ Release True Entitlements.entitlements + True False @@ -22,6 +23,7 @@ Cooper Plain + java.util,com.remobjects.elements.linq Echoes @@ -72,10 +74,16 @@ Cooper + True Cooper - + + Cooper + True + + Cooper + True Echoes @@ -94,6 +102,10 @@ Echoes True + + Echoes + True + Island.Darwin.macOS @@ -142,6 +154,51 @@ Island.Darwin.watchOS + + Island.Windows + + + Island.Windows + + + Island.Windows + + + Island.Windows + + + Island.Linux + + + Island.Linux + + + Island.Linux + + + Island.Linux + + + Island.WebAssembly + + + Island.WebAssembly + + + Island.WebAssembly + + + Island.Android + + + Island.Android + + + Island.Android + + + Island.Android + From 823d4863846a030177afbcb63e46e76862242d86 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Fri, 12 Apr 2019 11:09:30 -0400 Subject: [PATCH 05/79] fatalError overload w/o string param --- Source/Functions.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Source/Functions.swift b/Source/Functions.swift index e3175ba..23f9e26 100644 --- a/Source/Functions.swift +++ b/Source/Functions.swift @@ -67,6 +67,10 @@ public func debugPrint(_ objects: Object?..., separator: String = " ", terminato return value } +@noreturn public func fatalError(file: String = #file, line: UInt32 = #line) -> Never { + __throw Exception("Fatal Error, file "+file+", line "+line) +} + @noreturn public func fatalError(_ message: @autoclosure () -> String, file: String = #file, line: UInt32 = #line) -> Never { if let message = message { __throw Exception(message()+", file "+file+", line "+line) @@ -74,6 +78,7 @@ public func debugPrint(_ objects: Object?..., separator: String = " ", terminato __throw Exception("Fatal Error, file "+file+", line "+line) } } + @Conditional("DEBUG") public func precondition(_ condition: @autoclosure () -> Bool, _ message: @autoclosure () -> String, file: String = #file, line: UWord = #line) { if (!condition()) { fatalError(message, file: file, line: line) From bf05f11070181cd6722f734b66cb2d35bc5a08ef Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Fri, 19 Apr 2019 10:05:10 -0400 Subject: [PATCH 06/79] String: tweaks/clanup to character view --- Source/String.Views.swift | 36 +++++++----- Source/String.swift | 7 +-- Source/String_Extensions.swift | 56 +------------------ ...s.swift => UnicodeScalar_Extensions.swift} | 0 4 files changed, 27 insertions(+), 72 deletions(-) rename Source/{Char_Extensions.swift => UnicodeScalar_Extensions.swift} (100%) diff --git a/Source/String.Views.swift b/Source/String.Views.swift index 0839783..d9a6ab2 100644 --- a/Source/String.Views.swift +++ b/Source/String.Views.swift @@ -40,20 +40,23 @@ public extension SwiftString { while te.MoveNext() { stringData.append(Character(nativeStringValue: te.Current as! NativeString)) } - #elseif COCOA + #elseif DARWIN var i = 0 while i < length(string) { - let sequenceLength = string.rangeOfComposedCharacterSequenceAtIndex(i).length + let sequenceLength = (string as! NSString).rangeOfComposedCharacterSequenceAtIndex(i).length //76192: Silver: can't use range as subscript? (SBL) let ch: NativeString = string.__substring(range: i ..< i+sequenceLength) stringData.append(Character(nativeStringValue: ch)) i += sequenceLength } + #elseif ISLAND + #hint Not implemented yet #endif - /* old logic to detect surrogate pairs; not needed right now + /* old logic to detect surrogate pairs; not needed right now + { let c = string[i] let c2 = Int(c) /*switch Int(c) { @@ -99,8 +102,8 @@ public extension SwiftString { addCharacter() i += 1 - }*/ - //addCharacter() + } + //addCharacter()*/ } public override var count: Int { return stringData.count } @@ -178,6 +181,13 @@ public extension SwiftString { return stringData[index] } + @Sequence + public func GetSequence() -> ISequence { + for i in startIndex ..< endIndex { + __yield self[i] + } + } + @ToString public func description() -> NativeString { var result = "UTF16CharacterView(" for i in startIndex..*/ { + public class UTF32View: BaseCharacterView { private let stringData: Byte[] private init(stringData: Byte[]) { @@ -207,7 +216,7 @@ public extension SwiftString { #elseif CLR stringData = System.Text.UTF32Encoding(/*bigendian:*/false, /*BOM:*/false).GetBytes(string) // todo check order #elseif ISLAND - stringData = Encoding.UTF32LE.GetBytes(aValue, /*BOM:*/false) // todo check order + stringData = System.Encoding.UTF32LE.GetBytes(string, /*BOM:*/false) // todo check order #elseif COCOA if let utf32 = string.dataUsingEncoding(.NSUTF32LittleEndianStringEncoding) { // todo check order stringData = Byte[](capacity: utf32.length); @@ -263,9 +272,7 @@ public extension SwiftString { return result } } - #endif - #if !ISLAND public class UTF8View: BaseCharacterView { internal let stringData: UTF8Char[] @@ -279,7 +286,7 @@ public extension SwiftString { #elseif CLR stringData = System.Text.UTF8Encoding(/*BOM:*/false).GetBytes(string) #elseif ISLAND - stringData = Encoding.UTF8.GetBytes(aValue, /*BOM:*/false) + stringData = System.Encoding.UTF8.GetBytes(string, /*BOM:*/false) as! UTF8Char[] #elseif COCOA if let utf8 = string.dataUsingEncoding(.NSUTF8StringEncoding) { stringData = UTF8Char[](capacity: utf8.length); @@ -316,6 +323,11 @@ public extension SwiftString { return stringData[index] } + @Sequence + public func GetSequence() -> ISequence { + return stringData + } + @ToString public func description() -> NativeString { var result = "UTF8CharacterView(" for i in startIndex.. NativeString { return nativeStringValue @@ -226,11 +228,9 @@ public struct SwiftString /*: Streamable*/ { #endif } - #if !ISLAND public var utf8: SwiftString.UTF8View { return SwiftString.UTF8View(string: nativeStringValue) } - #endif #if COCOA public var utf8CString: UTF8Char[] { @@ -246,11 +246,9 @@ public struct SwiftString /*: Streamable*/ { return SwiftString.UTF16View(string: nativeStringValue) } - #if !ISLAND public var unicodeScalars: SwiftString.UnicodeScalarView { return SwiftString.UnicodeScalarView(string: nativeStringValue) } - #endif // // Methods @@ -432,5 +430,4 @@ public struct SwiftString /*: Streamable*/ { return nil #endif } - } \ No newline at end of file diff --git a/Source/String_Extensions.swift b/Source/String_Extensions.swift index 66a903e..243187c 100644 --- a/Source/String_Extensions.swift +++ b/Source/String_Extensions.swift @@ -76,9 +76,11 @@ // Properties // + #if DARWIN || !ISLAND public var characters: SwiftString.CharacterView { return SwiftString.CharacterView(string: self) } + #endif #if !COCOA public var debugDescription: NativeString { @@ -184,21 +186,17 @@ #endif } - #if !ISLAND public var utf8: SwiftString.UTF8View { return SwiftString.UTF8View(string: self) } - #endif public var utf16: SwiftString.UTF16View { return SwiftString.UTF16View(string: self) } - #if !ISLAND public var unicodeScalars: SwiftString.UnicodeScalarView { return SwiftString.UnicodeScalarView(string: self) } - #endif // // Methods @@ -335,54 +333,4 @@ return nil #endif } - - public __abstract class CharacterView { - /*fileprivate*/internal init(string: NativeString) { - } - - public var startIndex: NativeString.Index { return 0 } - public __abstract var endIndex: NativeString.Index { get } - - } - - public class UTF16CharacterView: CharacterView, ICustomDebugStringConvertible { - private let string: NativeString - - /*fileprivate*/internal init(string: NativeString) { - self.string = string - } - - public override var endIndex: NativeString.Index { return length(string) } - - public subscript(index: Int) -> UTF16Char { - return string[index] - } - - #if COCOA - override var debugDescription: NativeString! { - var result = "UTF16CharacterView(" - for i in startIndex.. startIndex { - result += " " - } - result += UInt64(self[i]).toHexString(length: 4) - } - result += ")" - return result - } - #else - public var debugDescription: NativeString { - var result = "UTF16CharacterView(" - for i in startIndex.. startIndex { - result += " " - } - result += UInt64(self[i]).toHexString(length: 4) - } - result += ")" - return result - } - #endif - } - } \ No newline at end of file diff --git a/Source/Char_Extensions.swift b/Source/UnicodeScalar_Extensions.swift similarity index 100% rename from Source/Char_Extensions.swift rename to Source/UnicodeScalar_Extensions.swift From 0731208064d501ebfd81e56782c3e759009a652f Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Fri, 19 Apr 2019 10:05:18 -0400 Subject: [PATCH 07/79] Warning fix --- Source/Aliases.swift | 4 +--- Source/Array.swift | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Source/Aliases.swift b/Source/Aliases.swift index 1f8be1f..6b7418e 100644 --- a/Source/Aliases.swift +++ b/Source/Aliases.swift @@ -32,11 +32,9 @@ public typealias UTF16Char = Char // UInt16 public typealias UTF32Char = UInt32 #if !COCOA && !ISLAND public typealias AnsiChar = Byte -public typealias UTF8Char = Byte -#else // Cocoa and Island already have AnsiChar -public typealias UTF8Char = AnsiChar #endif +public typealias UTF8Char = Byte public typealias StaticString = NativeString diff --git a/Source/Array.swift b/Source/Array.swift index 96940e8..791d424 100755 --- a/Source/Array.swift +++ b/Source/Array.swift @@ -336,7 +336,7 @@ public struct Array public subscript (range: Range) -> [T] { #if COCOA - return [T](list.Skip(range.lowerBound).Take(range.length).array()) + return [T](list.Skip(range.lowerBound).Take(range.length).ToNSArray()) #else return [T](list.Skip(range.lowerBound).Take(range.length).ToList()) #endif From 84403f4fef16255bf9c7cb62634824483bdd7886 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Fri, 19 Apr 2019 10:05:58 -0400 Subject: [PATCH 08/79] Swift/Echoes doesn't actually need Echoes.dll; allows us to keep supporting .NET Standard 1.3 --- Source/Swift.Echoes.Standard.elements | 6 +----- Source/Swift.Echoes.elements | 3 --- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/Source/Swift.Echoes.Standard.elements b/Source/Swift.Echoes.Standard.elements index affc79f..d0ab6c4 100644 --- a/Source/Swift.Echoes.Standard.elements +++ b/Source/Swift.Echoes.Standard.elements @@ -51,11 +51,7 @@ True SIGN - - - True - - + diff --git a/Source/Swift.Echoes.elements b/Source/Swift.Echoes.elements index 2dee2a7..3abadcb 100644 --- a/Source/Swift.Echoes.elements +++ b/Source/Swift.Echoes.elements @@ -57,9 +57,6 @@ - - True - From 7230408a87d5ef27c5b0f247d62f9f1bc0c46387 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Fri, 19 Apr 2019 10:06:03 -0400 Subject: [PATCH 09/79] String: tweaks/clanup to character view --- Source/Swift.Shared.projitems | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Swift.Shared.projitems b/Source/Swift.Shared.projitems index d8a6e5b..b0f8bd7 100644 --- a/Source/Swift.Shared.projitems +++ b/Source/Swift.Shared.projitems @@ -65,7 +65,7 @@ - + String From 20b1e88ba18a2d091f57481c5a8c13c1e19feede Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Wed, 24 Apr 2019 14:53:05 -0400 Subject: [PATCH 10/79] More pointer aliases; `Unmanaged` class (Cocoa) --- Source/Aliases.swift | 9 ++++ Source/Swift.Island.Darwin.iOS.elements | 1 + Source/Swift.Island.Darwin.macOS.elements | 1 + Source/Swift.Island.Darwin.tvOS.elements | 1 + Source/Swift.Island.Darwin.watchOS.elements | 1 + Source/Swift.Shared.projitems | 1 + Source/Unmanaged.swift | 54 +++++++++++++++++++++ 7 files changed, 68 insertions(+) create mode 100644 Source/Unmanaged.swift diff --git a/Source/Aliases.swift b/Source/Aliases.swift index 6b7418e..d844106 100644 --- a/Source/Aliases.swift +++ b/Source/Aliases.swift @@ -69,6 +69,15 @@ public typealias CInt = Int32 public typealias CLong = Int public typealias CLongLong = Int64 #if COCOA || ISLAND +//UnsafeMutablePointer +//UnsafePointer +public typealias UnsafeMutableBufferPointer = UnsafeMutablePointer +public typealias UnsafeBufferPointer = UnsafePointer +public typealias UnsafeMutableRawPointer = UnsafeMutablePointer +public typealias UnsafeRawPointer = UnsafePointer +public typealias UnsafeMutableRawBufferPointer = UnsafeMutablePointer +public typealias UnsafeRawBufferPointer = UnsafePointer + public typealias OpaquePointer = UnsafePointer #endif public typealias CShort = Int16 diff --git a/Source/Swift.Island.Darwin.iOS.elements b/Source/Swift.Island.Darwin.iOS.elements index d2e4f71..2ec3cd4 100644 --- a/Source/Swift.Island.Darwin.iOS.elements +++ b/Source/Swift.Island.Darwin.iOS.elements @@ -53,6 +53,7 @@ + diff --git a/Source/Swift.Island.Darwin.macOS.elements b/Source/Swift.Island.Darwin.macOS.elements index 32d1274..32d9b3e 100644 --- a/Source/Swift.Island.Darwin.macOS.elements +++ b/Source/Swift.Island.Darwin.macOS.elements @@ -54,6 +54,7 @@ + diff --git a/Source/Swift.Island.Darwin.tvOS.elements b/Source/Swift.Island.Darwin.tvOS.elements index 99a61bc..5f1fad6 100644 --- a/Source/Swift.Island.Darwin.tvOS.elements +++ b/Source/Swift.Island.Darwin.tvOS.elements @@ -53,6 +53,7 @@ + diff --git a/Source/Swift.Island.Darwin.watchOS.elements b/Source/Swift.Island.Darwin.watchOS.elements index f02b615..469a238 100644 --- a/Source/Swift.Island.Darwin.watchOS.elements +++ b/Source/Swift.Island.Darwin.watchOS.elements @@ -53,6 +53,7 @@ + diff --git a/Source/Swift.Shared.projitems b/Source/Swift.Shared.projitems index b0f8bd7..96d1ff0 100644 --- a/Source/Swift.Shared.projitems +++ b/Source/Swift.Shared.projitems @@ -94,6 +94,7 @@ + diff --git a/Source/Unmanaged.swift b/Source/Unmanaged.swift new file mode 100644 index 0000000..a6f8bd0 --- /dev/null +++ b/Source/Unmanaged.swift @@ -0,0 +1,54 @@ +#if DARWIN +public struct Unmanaged where Instance : AnyObject { + + #if ISLAND + func autorelease() -> Unmanaged { + CFAutorelease(opaque) + return self + } + func release() { + CFRelease(opaque) + } + func retain() -> Unmanaged { + CFRetain(opaque) + return self + } + #endif + + func takeRetainedValue() -> Instance { + return bridge(opaque, BridgeMode.Bridge) + } + + func takeUnretainedValue() -> Instance { + return bridge(opaque, BridgeMode.Transfer) + } + + func toOpaque() -> OpaquePointer { + return opaque + } + + static func fromOpaque(_ value: OpaquePointer) -> Unmanaged { + Unmanaged(with: value) + } + static func passRetained(_ value: Instance) -> Unmanaged { + Unmanaged(retained: value) + } + static func passUnretained(_ value: Instance) -> Unmanaged { + Unmanaged(unretained: value) + } + + private let opaque: OpaquePointer + + private init(with value: OpaquePointer) { + opaque = value + } + + private init(withRetained value: Instance) { + opaque = bridge(value, BridgeMode.Retained) + } + + private init(withUnretained value: Instance) { + opaque = bridge(value, BridgeMode.Bridge) + } +} +#endif \ No newline at end of file From e55b9c14eaab4c46799d777d25a261f3527ab87a Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Thu, 25 Apr 2019 09:39:57 -0400 Subject: [PATCH 11/79] Infinite Recursion in implicit array cast --- Source/Array.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Source/Array.swift b/Source/Array.swift index 791d424..7dcd360 100755 --- a/Source/Array.swift +++ b/Source/Array.swift @@ -188,14 +188,13 @@ public struct Array // Cast from/to platform type - public static func __implicit(_ list: PlatformList) -> [T] { + public static func __implicit(_ list: PlatformImmutableList) -> [T] { return [T](list) } public static func __implicit(_ array: [T]) -> PlatformList { return array.platformList } - // Darwin only: cast from/to Cocoa type #if DARWIN From e6b3781e47cbae8e0811108fb5758bfb0a50259c Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Mon, 29 Apr 2019 08:23:01 -0400 Subject: [PATCH 12/79] public typealias NSObjectProtocol = INSObject --- Source/Aliases.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Source/Aliases.swift b/Source/Aliases.swift index d844106..54c9876 100644 --- a/Source/Aliases.swift +++ b/Source/Aliases.swift @@ -52,8 +52,10 @@ public typealias AnyClass = rtl.Class public typealias AnyClass = java.lang.Class #endif -#if COCOA +#if DARWIN public typealias Selector = SEL +public typealias NSObjectProtocol = INSObject +public typealias INSObjectProtocol = INSObject #endif /* more obscure aliases */ From da66a1a18906a713afe7dc10e1c2eac58b316cf0 Mon Sep 17 00:00:00 2001 From: Carlo Kok Date: Wed, 8 May 2019 07:17:35 +0200 Subject: [PATCH 13/79] 82532: Unexpected cast error: java.lang.Object[] cannot be cast to uk.innerfuse.androidapplication.TreeNode[] --- Source/Array.Java.swift | 6 ++++-- Source/Array.swift | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Source/Array.Java.swift b/Source/Array.Java.swift index 16a368c..e31a6d3 100644 --- a/Source/Array.Java.swift +++ b/Source/Array.Java.swift @@ -9,11 +9,13 @@ public extension Swift.Array : java.util.List { public func contains(_ arg1: Object!) -> Bool { return list.contains(arg1) } + @inline(__always) public func toArray(_ arg1: T![]) -> T![] { - return list.toArray(arg1) + return platformList.toArray(arg1) } + @inline(__always) public func toArray() -> Object![] { - return list.toArray() + return platformList.toArray() } mutating func add(_ arg1: Int32, _ arg2: T!) { makeUnique() diff --git a/Source/Array.swift b/Source/Array.swift index 7dcd360..c16b451 100755 --- a/Source/Array.swift +++ b/Source/Array.swift @@ -92,7 +92,7 @@ public struct Array public init(repeating value: T, count: Int) { if count == 0 { list = PlatformList() - } else { + } else{ #if JAVA list = PlatformList(count) for i in 0 ..< count { @@ -181,10 +181,12 @@ public struct Array public static func __implicit(_ array: T[]) -> [T] { return [T](arrayLiteral: array) } - + // In Coope + #if !COOPER public static func __implicit(_ array: [T]) -> T[] { return array.nativeArray } + #endif // Cast from/to platform type From e6562088d84c70e87528adbfa856562691d83268 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Fri, 10 May 2019 09:54:26 -0400 Subject: [PATCH 14/79] Pointers --- Source/Aliases.swift | 16 ++++++------ Source/MemoryLayout.swift | 7 ++++++ Source/Pointers.swift | 46 +++++++++++++++++++++++++++++++++++ Source/Swift.Shared.projitems | 13 +++++++++- 4 files changed, 73 insertions(+), 9 deletions(-) create mode 100644 Source/MemoryLayout.swift create mode 100644 Source/Pointers.swift diff --git a/Source/Aliases.swift b/Source/Aliases.swift index 54c9876..05a0c69 100644 --- a/Source/Aliases.swift +++ b/Source/Aliases.swift @@ -70,18 +70,18 @@ public typealias CFloat = Float public typealias CInt = Int32 public typealias CLong = Int public typealias CLongLong = Int64 -#if COCOA || ISLAND -//UnsafeMutablePointer -//UnsafePointer + +#if !JAVA +// UnsafeMutablePointer and UnsafePointer are defined by the compiler public typealias UnsafeMutableBufferPointer = UnsafeMutablePointer public typealias UnsafeBufferPointer = UnsafePointer -public typealias UnsafeMutableRawPointer = UnsafeMutablePointer -public typealias UnsafeRawPointer = UnsafePointer -public typealias UnsafeMutableRawBufferPointer = UnsafeMutablePointer -public typealias UnsafeRawBufferPointer = UnsafePointer - +public typealias UnsafeMutableRawPointer = UnsafeMutablePointer +public typealias UnsafeRawPointer = UnsafePointer +public typealias UnsafeMutableRawBufferPointer = UnsafeMutablePointer +public typealias UnsafeRawBufferPointer = UnsafePointer public typealias OpaquePointer = UnsafePointer #endif + public typealias CShort = Int16 public typealias CSignedChar = Int8 public typealias CUnsignedChar = UInt8 diff --git a/Source/MemoryLayout.swift b/Source/MemoryLayout.swift new file mode 100644 index 0000000..b439c12 --- /dev/null +++ b/Source/MemoryLayout.swift @@ -0,0 +1,7 @@ +//public struct MemoryLayout { + + //var size: Byte { sizeOf } + //var alignment: Byte { sizeOf } + //var stride: Byte { sizeOf } + +//} \ No newline at end of file diff --git a/Source/Pointers.swift b/Source/Pointers.swift new file mode 100644 index 0000000..06936b0 --- /dev/null +++ b/Source/Pointers.swift @@ -0,0 +1,46 @@ +#if !JAVA +public extension OpaquePointer { + + //init(_ pointer: UnsafePointer) { + + //} + //init(_ pointer: UnsafeMutablePointer) { + + //} + //init?(_ pointer: UnsafePointer?) { + + //} + //init?(_ pointer: UnsafeMutablePointer?) { + + //} + init(_ pointer: UnsafeRawPointer?) { + return pointer + } + init?(bitPattern: Int) { + return bitPattern as! OpaquePointer + } + init?(bitPattern: UInt) { + return bitPattern as! OpaquePointer + } + + //@ToString // E201 Attributes of type "ToStringAspect!" are not allowed on this member + var description: String { + return "0x"+(self as! UInt).toHexString() + } + + var debugDescription: String { + return "0x"+(self as! UInt).toHexString() + } + + //func hash(into: inout Hasher) { + + //} + //static func != (_ rhs: OpaquePointer, _lhs: OpaquePointer) -> Bool { + // handled by compiler + //} + //static func == (OpaquePointer, OpaquePointer) -> Bool { + // handled by compiler + //} +} + +#endif \ No newline at end of file diff --git a/Source/Swift.Shared.projitems b/Source/Swift.Shared.projitems index 96d1ff0..8e408e4 100644 --- a/Source/Swift.Shared.projitems +++ b/Source/Swift.Shared.projitems @@ -94,7 +94,15 @@ - + + Memory + + + Memory + + + Memory + @@ -112,5 +120,8 @@ True + + True + \ No newline at end of file From fde9550668ca5c6a274fc93d7c1b96125920570e Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Fri, 10 May 2019 10:05:09 -0400 Subject: [PATCH 15/79] Test project fix --- Tests/Program.swift | 3 +-- Tests/Swift.Tests.elements | 12 ++++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Tests/Program.swift b/Tests/Program.swift index d22a04b..020127a 100644 --- a/Tests/Program.swift +++ b/Tests/Program.swift @@ -1,5 +1,4 @@ import RemObjects.Elements.EUnit let lTests = Discovery.DiscoverTests() -Runner.RunTests(lTests, withListener: Runner.DefaultListener) -return 0 \ No newline at end of file +return Runner.RunTests(lTests, withListener: Runner.DefaultListener) == TestState.Succeeded ? 0 : 1 \ No newline at end of file diff --git a/Tests/Swift.Tests.elements b/Tests/Swift.Tests.elements index 2dcf58f..b774752 100644 --- a/Tests/Swift.Tests.elements +++ b/Tests/Swift.Tests.elements @@ -109,6 +109,9 @@ Island.Darwin.macOS + + Island.Darwin.macOS + Island.Darwin.macOS @@ -121,6 +124,9 @@ Island.Darwin.iOS + + Island.Darwin.iOS + Island.Darwin.iOS @@ -133,6 +139,9 @@ Island.Darwin.tvOS + + Island.Darwin.tvOS + Island.Darwin.tvOS @@ -145,6 +154,9 @@ Island.Darwin.watchOS + + Island.Darwin.watchOS + Island.Darwin.watchOS From 4903c2b3417429ee278616e6a6a155c8e698d53e Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Thu, 16 May 2019 12:36:09 -0400 Subject: [PATCH 16/79] Cooper dictionary fix --- Source/Dictionary.Java.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Dictionary.Java.swift b/Source/Dictionary.Java.swift index 0c92971..e1f9d39 100644 --- a/Source/Dictionary.Java.swift +++ b/Source/Dictionary.Java.swift @@ -18,11 +18,11 @@ public extension Swift.Dictionary : java.util.Map { } public mutating func put(_ arg1: Key!, _ arg2: Value!) -> Value! { makeUnique() - return dictionary.put(arg1, arg1) + return dictionary.put(arg1, arg2) } public mutating func remove(_ arg1: Object!, _ arg2: Object!) -> Bool { makeUnique() - return dictionary.remove(arg1, arg1) + return dictionary.remove(arg1, arg2) } public mutating func remove(_ arg1: Object!) -> Value! { makeUnique() From 92e85a762943a2bc7ad4416a564247e1246e978c Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Mon, 20 May 2019 11:20:30 -0400 Subject: [PATCH 17/79] 82211: Swift dictionary nil issue (require Echoes.dll for Swift.dll, on .NET) --- Source/Swift.Echoes.Standard.elements | 6 ++++-- Source/Swift.Echoes.elements | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Source/Swift.Echoes.Standard.elements b/Source/Swift.Echoes.Standard.elements index d0ab6c4..d6b44b2 100644 --- a/Source/Swift.Echoes.Standard.elements +++ b/Source/Swift.Echoes.Standard.elements @@ -13,7 +13,7 @@ False Release System.Collections.Generic;System.Linq - .NETStandard1.3 + .NETStandard2.0 false @@ -51,10 +51,12 @@ True SIGN - + + + \ No newline at end of file diff --git a/Source/Swift.Echoes.elements b/Source/Swift.Echoes.elements index 3abadcb..08e34b2 100644 --- a/Source/Swift.Echoes.elements +++ b/Source/Swift.Echoes.elements @@ -57,6 +57,7 @@ + From 77edebecb3af4f96640cfaa583cb9154b4173654 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Tue, 21 May 2019 14:20:22 -0400 Subject: [PATCH 18/79] Cast form Sequence to array; Sequence.ToSwiftArray with cast --- Source/Array.swift | 26 ++++++++++++++++++++++---- Source/Sequence_Extensions.swift | 10 ++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/Source/Array.swift b/Source/Array.swift index c16b451..5e27073 100755 --- a/Source/Array.swift +++ b/Source/Array.swift @@ -92,7 +92,7 @@ public struct Array public init(repeating value: T, count: Int) { if count == 0 { list = PlatformList() - } else{ + } else{ #if JAVA list = PlatformList(count) for i in 0 ..< count { @@ -181,12 +181,18 @@ public struct Array public static func __implicit(_ array: T[]) -> [T] { return [T](arrayLiteral: array) } - // In Coope - #if !COOPER + + #if !COOPER public static func __implicit(_ array: [T]) -> T[] { return array.nativeArray } - #endif + #endif + + // Cast from sequence + + public static func __implicit(_ sequence: ISequence) -> [T] { + return [T](sequence: sequence) + } // Cast from/to platform type @@ -253,6 +259,18 @@ public struct Array return result } + public func +=(inout lhs: [T], rhs: [T]) { + for i in rhs { + lhs.append(i) + } + } + + public static func += (inout lhs: Array, rhs: ISequence) { + for i in rhs { + lhs.append(i) + } + } + public static func == (lhs: [T], rhs: [T]) -> Bool { if lhs.list == rhs.list { return true diff --git a/Source/Sequence_Extensions.swift b/Source/Sequence_Extensions.swift index 5a527dc..98f1522 100644 --- a/Source/Sequence_Extensions.swift +++ b/Source/Sequence_Extensions.swift @@ -35,6 +35,16 @@ public extension ISequence /*: ICustomDebugStringConvertible*/ { // 74092: Silve return result } + #if !COOPER + public func ToSwiftArray() -> [U] { + var result = [U]() + for i in self { + result.append(i as! U) + } + return result + } + #endif + public var count: Int { return self.Count() } From 66b5c3b645a839bbfa55aed5848cfcebcae266f1 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Wed, 19 Jun 2019 15:58:00 -0400 Subject: [PATCH 19/79] Support UIKit for Mac --- Source/Swift.Toffee.iOS.elements | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Swift.Toffee.iOS.elements b/Source/Swift.Toffee.iOS.elements index eeefb76..76485b5 100644 --- a/Source/Swift.Toffee.iOS.elements +++ b/Source/Swift.Toffee.iOS.elements @@ -17,6 +17,7 @@ 7.1 True NW6 + True false From e93ef9c2f8aca369c13fec12267e023f4ffc2a18 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Sun, 23 Jun 2019 10:46:50 -0400 Subject: [PATCH 20/79] Support UIKit for Mac (Island) --- Source/Swift.Island.Darwin.iOS.elements | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Swift.Island.Darwin.iOS.elements b/Source/Swift.Island.Darwin.iOS.elements index 2ec3cd4..497ba7b 100644 --- a/Source/Swift.Island.Darwin.iOS.elements +++ b/Source/Swift.Island.Darwin.iOS.elements @@ -14,6 +14,7 @@ Release Foundation;RemObjects.Elements.System;rtl iOS + True false From 40d4b2c5f4992f70715e6632897ee321464067b9 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Sun, 28 Jul 2019 14:51:14 -0400 Subject: [PATCH 21/79] DispatchQueue: implicit cast from/to dispatch_queue_t --- Source/Dispatch.swift | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Source/Dispatch.swift b/Source/Dispatch.swift index adee9db..8bc28a0 100644 --- a/Source/Dispatch.swift +++ b/Source/Dispatch.swift @@ -98,6 +98,22 @@ public class DispatchQueue : DispatchObject { #endif } + public static func __implicit(_ queue: DispatchQueue?) -> dispatch_queue_t? { + if let queue = queue { + return queue.queue + } else { + return nil + } + } + + public static func __implicit(_ queue: dispatch_queue_t?) -> DispatchQueue? { + if let queue = queue { + return DispatchQueue(queue: queue) + } else { + return nil + } + } + internal convenience init(__label: String, attr: dispatch_queue_attr_t?, queue: DispatchQueue?) { var raw: dispatch_queue_t if #defined(COCOA) { From 8ffadf8e3c197a8eb66bbf5b767b2d105db4edeb Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Fri, 16 Aug 2019 11:12:01 -0400 Subject: [PATCH 22/79] SE-0261 Identifiable Protocol --- Source/Protocols.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Source/Protocols.swift b/Source/Protocols.swift index 8cb717d..81dc8c1 100644 --- a/Source/Protocols.swift +++ b/Source/Protocols.swift @@ -35,6 +35,12 @@ public protocol IHashable /*: Equatable*/ { var hashValue: Int { get } } +typealias Identifiable = IIdentifiable +protocol IIdentifiable { + associatedtype ID: IHashable + var id: ID { get } +} + public typealias OutputStreamType = IOutputStreamType public protocol IOutputStreamType { //mutating func write(_ string: String) From f26c2f17a3649d73d04813dce3421cc3ae3a2e5c Mon Sep 17 00:00:00 2001 From: Carlo Kok Date: Mon, 4 Nov 2019 12:02:47 +0100 Subject: [PATCH 23/79] 0: Fixes for Island: Anonymous delegates are now unique. --- Source/Array.swift | 8 ++++---- Source/Dispatch.swift | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Source/Array.swift b/Source/Array.swift index 5e27073..f6e5cd3 100755 --- a/Source/Array.swift +++ b/Source/Array.swift @@ -652,9 +652,9 @@ public struct Array //} public func map(_ transform: (T) -> U) -> ISequence { // we deliberatey return a sequence, not an array, for efficiency and flexibility. - #if JAVA + #if JAVA || ISLAND return list.Select({ return transform($0) }) - #elseif CLR || ISLAND || COCOA + #elseif CLR || COCOA return list.Select(transform) #endif } @@ -664,9 +664,9 @@ public struct Array //} public func filter(_ includeElement: (T) -> Bool) -> ISequence { // we deliberatey return a sequence, not an array, for efficiency and flexibility. - #if JAVA + #if JAVA || ISLAND return list.Where({ return includeElement($0) }) - #elseif CLR || ISLAND || COCOA + #elseif CLR || COCOA return list.Where(includeElement) #endif } diff --git a/Source/Dispatch.swift b/Source/Dispatch.swift index 8bc28a0..a75bda7 100644 --- a/Source/Dispatch.swift +++ b/Source/Dispatch.swift @@ -157,31 +157,31 @@ public class DispatchQueue : DispatchObject { } public func asyncAfter(deadline: DispatchTime, execute work: () -> ()) { - dispatch_after(deadline.rawValue, self.queue, work) + dispatch_after(deadline.rawValue, self.queue, { work(); }) } public func asyncAfter(wallDeadline: DispatchWallTime, execute work: () -> ()) { - dispatch_after(wallDeadline.rawValue, self.queue, work) + dispatch_after(wallDeadline.rawValue, self.queue, { work(); }) } public func concurrentPerform(iterations: Int, execute work: (UInt) -> ()) { - dispatch_apply(iterations, self.queue, work) + dispatch_apply(iterations, self.queue, { work($0) }) } public func async(execute work: () -> ()) { - dispatch_async(self.queue, work) + dispatch_async(self.queue, { work(); }) } public func async(group: DispatchGroup?, execute work: () -> ()) { if group != nil { - dispatch_group_async(group!.group, self.queue, work) + dispatch_group_async(group!.group, self.queue, { work() }) } else { - dispatch_async(self.queue, work) + dispatch_async(self.queue, { work() }) } } public func sync(execute work: () -> ()) { - dispatch_sync(self.queue, work) + dispatch_sync(self.queue, { work() }) } #if !ISLAND From 7d43b9f96a4a84223296544a1cd9d8b783f55aba Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Tue, 5 Nov 2019 09:34:25 -0400 Subject: [PATCH 24/79] Implicit cast operator for Range/NSRange --- Source/Range.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Source/Range.swift b/Source/Range.swift index 9440e9a..2eaf869 100644 --- a/Source/Range.swift +++ b/Source/Range.swift @@ -277,7 +277,14 @@ public class Range/**/: CustomStringConve } #if COCOA - // todo: make a cast operator + public static func __implicit(_ range: Range) -> NSRange { + return range.nativeRange + } + + public static func __implicit(_ range: NSRange) -> Range { + return Range(range.location, range.location+range.length, upperBoundClosed: false) + } + public var nativeRange: NSRange { if let lowerBound = lowerBound, upperBound != nil { return NSMakeRange(lowerBound, length) From 197b3c9da9c39a6442aec95d2439712e235fe5eb Mon Sep 17 00:00:00 2001 From: Carlo Kok Date: Wed, 29 Jan 2020 16:35:27 +0100 Subject: [PATCH 25/79] 0: Disable Int/bool aliases for Island Darwin ios/osx (as we have them Island now) --- Source/Aliases.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Source/Aliases.swift b/Source/Aliases.swift index 05a0c69..ee1a8e1 100644 --- a/Source/Aliases.swift +++ b/Source/Aliases.swift @@ -4,6 +4,7 @@ public typealias Int = Int64 public typealias UInt = UInt64 #elseif ISLAND +#if !macos && !iOS #if CPU64 public typealias Int = Int64 public typealias UInt = UInt64 @@ -14,6 +15,7 @@ #hint Unexpected bitness public typealias Int = Int64 public typealias UInt = UInt64 +#endif #endif #elseif COCOA public typealias Int = NSInteger @@ -25,8 +27,9 @@ public typealias UInt8 = Byte public typealias IntMax = Int64 public typealias UIntMax = UInt64 +#if ISLAND && !macos && !iOS public typealias Bool = Boolean - +#endif public typealias UnicodeScalar = UTF32Char public typealias UTF16Char = Char // UInt16 public typealias UTF32Char = UInt32 From 09c8091215072261ca52453ea237a1c207e692c9 Mon Sep 17 00:00:00 2001 From: Carlo Kok Date: Wed, 29 Jan 2020 19:20:33 +0100 Subject: [PATCH 26/79] 0: Fix for SBL --- Source/Aliases.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Aliases.swift b/Source/Aliases.swift index ee1a8e1..89d431f 100644 --- a/Source/Aliases.swift +++ b/Source/Aliases.swift @@ -27,7 +27,7 @@ public typealias UInt8 = Byte public typealias IntMax = Int64 public typealias UIntMax = UInt64 -#if ISLAND && !macos && !iOS +#if !ISLAND || (!macos && !iOS) public typealias Bool = Boolean #endif public typealias UnicodeScalar = UTF32Char From 46ac54fc31237e0ed4ab4a4d7d192657d44c56d8 Mon Sep 17 00:00:00 2001 From: Carlo Kok Date: Wed, 29 Jan 2020 19:36:09 +0100 Subject: [PATCH 27/79] Revert "0: Disable Int/bool aliases for Island Darwin ios/osx (as we have them Island now)" This reverts commit 197b3c9da9c39a6442aec95d2439712e235fe5eb. --- Source/Aliases.swift | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Source/Aliases.swift b/Source/Aliases.swift index 89d431f..05a0c69 100644 --- a/Source/Aliases.swift +++ b/Source/Aliases.swift @@ -4,7 +4,6 @@ public typealias Int = Int64 public typealias UInt = UInt64 #elseif ISLAND -#if !macos && !iOS #if CPU64 public typealias Int = Int64 public typealias UInt = UInt64 @@ -15,7 +14,6 @@ #hint Unexpected bitness public typealias Int = Int64 public typealias UInt = UInt64 -#endif #endif #elseif COCOA public typealias Int = NSInteger @@ -27,9 +25,8 @@ public typealias UInt8 = Byte public typealias IntMax = Int64 public typealias UIntMax = UInt64 -#if !ISLAND || (!macos && !iOS) public typealias Bool = Boolean -#endif + public typealias UnicodeScalar = UTF32Char public typealias UTF16Char = Char // UInt16 public typealias UTF32Char = UInt32 From 85be0e65dd51d82e04b2d2b649928f2188445e37 Mon Sep 17 00:00:00 2001 From: Marko Havu Date: Thu, 28 May 2020 23:51:34 +0300 Subject: [PATCH 28/79] Changed String.init(count:repeatedValue:) with init(repeating:count:) and added String.utf8CString for CLR and ISLAND --- Source/String.swift | 26 +++++++++++++++----------- Source/String_Extensions.swift | 8 ++++---- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/Source/String.swift b/Source/String.swift index f3beb3c..d49a0a8 100644 --- a/Source/String.swift +++ b/Source/String.swift @@ -1,4 +1,4 @@ -#if JAVA +#if JAVA public typealias NativeString = java.lang.String public typealias NativeStringBuilder = java.lang.StringBuilder #elseif CLR @@ -24,7 +24,7 @@ public struct SwiftString /*: Streamable*/ { nativeStringValue = "" } - public init(count: Int, repeatedValue c: Char) { + public init(repeating c: Char, count: Int) { #if JAVA || ISLAND var chars = Char[](count) @@ -40,7 +40,7 @@ public struct SwiftString /*: Streamable*/ { } public convenience init(_ c: Char) { - init(count: 1, repeatedValue: c) + init(repeating: c, count: 1) } public init(_ s: NativeString) { @@ -232,16 +232,20 @@ public struct SwiftString /*: Streamable*/ { return SwiftString.UTF8View(string: nativeStringValue) } - #if COCOA - public var utf8CString: UTF8Char[] { + public var utf8CString: [UTF8Char] { + #if CLR + let result = System.Text.Encoding.UTF8.GetBytes(nativeStringValue) + #elseif ISLAND + let result = RemObjects.Elements.System.Encoding.UTF8.GetBytes(nativeStringValue, false) + #elseif COCOA let utf8 = nativeStringValue.cStringUsingEncoding(.UTF8StringEncoding) - let len = strlen(utf8)+1 - let result = UTF8Char[](len) + let len = strlen(utf8) + 1 + let result = [UTF8Char](len) memcpy(result, utf8, len) - return result + #endif + return result } - #endif - + public var utf16: SwiftString.UTF16View { return SwiftString.UTF16View(string: nativeStringValue) } @@ -430,4 +434,4 @@ public struct SwiftString /*: Streamable*/ { return nil #endif } -} \ No newline at end of file +} diff --git a/Source/String_Extensions.swift b/Source/String_Extensions.swift index 243187c..392d267 100644 --- a/Source/String_Extensions.swift +++ b/Source/String_Extensions.swift @@ -1,8 +1,8 @@ -public extension NativeString : Streamable { +public extension NativeString : Streamable { typealias Index = Int - public init(count: Int, repeatedValue c: Char) { + public init(repeating c: Char, count: Int) { #if JAVA || ISLAND var chars = Char[](count) @@ -18,7 +18,7 @@ } public init(_ c: Char) { - return NativeString(count: 1, repeatedValue: c) + return NativeString(repeating: c, count: 1) } public init(_ object: Object) { @@ -333,4 +333,4 @@ return nil #endif } -} \ No newline at end of file +} From d60b9acd4a79d5c70721327032b66cb0ef50ba8b Mon Sep 17 00:00:00 2001 From: Marko Havu Date: Fri, 29 May 2020 00:41:44 +0300 Subject: [PATCH 29/79] Change removeValueForKey(_:) to removeValue(forKey:), allow dot syntax in accessing key and value of an item, add forEach (issue #11) --- Source/Dictionary.swift | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Source/Dictionary.swift b/Source/Dictionary.swift index 8246fa1..293805b 100755 --- a/Source/Dictionary.swift +++ b/Source/Dictionary.swift @@ -309,7 +309,7 @@ public struct Dictionary /*: INSFastEnumeration*/ #endif } - public mutating func removeValueForKey(_ key: Key) -> Value? { + public mutating func removeValue(forKey key: Key) -> Value? { makeUnique() #if JAVA if dictionary.containsKey(key) { @@ -334,6 +334,12 @@ public struct Dictionary /*: INSFastEnumeration*/ dictionary = PlatformDictionary() unique = true } + + public func forEach(_ body: ((key: Key, value: Value)) throws -> Void) rethrows { + for item in self { + try body(item) + } + } public var count: Int { #if JAVA @@ -387,23 +393,23 @@ public struct Dictionary /*: INSFastEnumeration*/ public static class DictionaryHelper { #if JAVA - public static func Enumerate(_ val: PlatformDictionary) -> ISequence<(Key, Value)> { + public static func Enumerate(_ val: PlatformDictionary) -> ISequence<(Key, Value)> { for entry in val.entrySet() { - var item: (Key, Value) = (entry.Key, entry.Value) + var item: (key: Key, value: Value) = (entry.Key, entry.Value) __yield item } } #elseif CLR | ISLAND - public static func Enumerate(_ val: PlatformDictionary) -> ISequence<(Key, Value)> { + public static func Enumerate(_ val: PlatformDictionary) -> ISequence<(Key, Value)> { for entry in val { - var item: (Key, Value) = (entry.Key, entry.Value) + var item: (key: Key, value: Value) = (entry.Key, entry.Value) __yield item } } #elseif COCOA - public static func Enumerate(_ val: PlatformDictionary) -> ISequence<(Key, Value)> { + public static func Enumerate(_ val: PlatformDictionary) -> ISequence<(Key, Value)> { for entry in val { - var item: (Key, Value) = (entry, val[entry]?) + var item: (key: Key, value: Value) = (entry, val[entry]?) __yield item } } From ecd9142d3cae703ba4f3d00cd1b707a0a8463c0a Mon Sep 17 00:00:00 2001 From: Marko Havu Date: Fri, 29 May 2020 16:44:27 +0300 Subject: [PATCH 30/79] Changed [UTF8Char] back to UTF8Char[] --- Source/String.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/String.swift b/Source/String.swift index d49a0a8..a19cd68 100644 --- a/Source/String.swift +++ b/Source/String.swift @@ -232,7 +232,7 @@ public struct SwiftString /*: Streamable*/ { return SwiftString.UTF8View(string: nativeStringValue) } - public var utf8CString: [UTF8Char] { + public var utf8CString: UTF8Char[] { #if CLR let result = System.Text.Encoding.UTF8.GetBytes(nativeStringValue) #elseif ISLAND @@ -240,7 +240,7 @@ public struct SwiftString /*: Streamable*/ { #elseif COCOA let utf8 = nativeStringValue.cStringUsingEncoding(.UTF8StringEncoding) let len = strlen(utf8) + 1 - let result = [UTF8Char](len) + let result = UTF8Char[](len) memcpy(result, utf8, len) #endif return result From a3d6297f538ef7daee3333cf02441cf5b8458838 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Mon, 15 Jun 2020 08:19:49 -0400 Subject: [PATCH 31/79] Visibility fix --- Source/String_Extensions.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/String_Extensions.swift b/Source/String_Extensions.swift index 392d267..b9d1ca7 100644 --- a/Source/String_Extensions.swift +++ b/Source/String_Extensions.swift @@ -1,4 +1,4 @@ -public extension NativeString : Streamable { +public extension NativeString : Streamable { typealias Index = Int @@ -18,7 +18,7 @@ public extension NativeString : Streamable { } public init(_ c: Char) { - return NativeString(repeating: c, count: 1) + return NativeString(repeating: c, count: 1) } public init(_ object: Object) { @@ -143,7 +143,7 @@ public extension NativeString : Streamable { //func components(separatedBy separator: CharacterSet) -> [String] { //} - func components(separatedBy separator: String) -> [String] { + public func components(separatedBy separator: String) -> [String] { let separatorLength = separator.length() if separatorLength == 0 { return [self] @@ -333,4 +333,4 @@ public extension NativeString : Streamable { return nil #endif } -} +} \ No newline at end of file From 3e4e7113bd19044bec99a98aad0e62644def3e10 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Mon, 15 Jun 2020 09:10:18 -0400 Subject: [PATCH 32/79] Had to undo parts of pull request `Minor Dictionary changes #13` because forEach it did not compile. --- Source/Dictionary.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/Dictionary.swift b/Source/Dictionary.swift index 293805b..17e74ff 100755 --- a/Source/Dictionary.swift +++ b/Source/Dictionary.swift @@ -334,12 +334,12 @@ public struct Dictionary /*: INSFastEnumeration*/ dictionary = PlatformDictionary() unique = true } - - public func forEach(_ body: ((key: Key, value: Value)) throws -> Void) rethrows { - for item in self { - try body(item) - } - } + + //public func forEach(_ body: ((key: Key, value: Value)) throws -> Void) rethrows { + //for item in self { + //try body(item) + //} + //} public var count: Int { #if JAVA From 8ebb92c90977c9c6ff9204c734581f5bcd004146 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Mon, 15 Jun 2020 09:10:56 -0400 Subject: [PATCH 33/79] And `Some String changes #12` was also incomplete for Java & failed to build :( --- Source/String.swift | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/Source/String.swift b/Source/String.swift index a19cd68..7534c3b 100644 --- a/Source/String.swift +++ b/Source/String.swift @@ -1,4 +1,4 @@ -#if JAVA +#if JAVA public typealias NativeString = java.lang.String public typealias NativeStringBuilder = java.lang.StringBuilder #elseif CLR @@ -40,7 +40,7 @@ public struct SwiftString /*: Streamable*/ { } public convenience init(_ c: Char) { - init(repeating: c, count: 1) + init(repeating: c, count: 1) } public init(_ s: NativeString) { @@ -233,19 +233,24 @@ public struct SwiftString /*: Streamable*/ { } public var utf8CString: UTF8Char[] { - #if CLR - let result = System.Text.Encoding.UTF8.GetBytes(nativeStringValue) - #elseif ISLAND - let result = RemObjects.Elements.System.Encoding.UTF8.GetBytes(nativeStringValue, false) - #elseif COCOA + #if JAVA + let buffer = java.nio.charset.Charset.forName("UTF8").encode(self) + let result = Byte[](buffer.remaining()) + buffer.get(result) + return result + #elseif CLR + return System.Text.Encoding.UTF8.GetBytes(nativeStringValue) + #elseif ISLAND + return RemObjects.Elements.System.Encoding.UTF8.GetBytes(nativeStringValue, false) + #elseif COCOA let utf8 = nativeStringValue.cStringUsingEncoding(.UTF8StringEncoding) let len = strlen(utf8) + 1 let result = UTF8Char[](len) memcpy(result, utf8, len) - #endif - return result + return result + #endif } - + public var utf16: SwiftString.UTF16View { return SwiftString.UTF16View(string: nativeStringValue) } @@ -434,4 +439,4 @@ public struct SwiftString /*: Streamable*/ { return nil #endif } -} +} \ No newline at end of file From 42094617145241755f3e5a6c1d4a6590156f29e0 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Mon, 22 Jun 2020 18:45:31 -0400 Subject: [PATCH 34/79] Visibility fix --- Source/String_Extensions.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/String_Extensions.swift b/Source/String_Extensions.swift index b9d1ca7..e9a83b0 100644 --- a/Source/String_Extensions.swift +++ b/Source/String_Extensions.swift @@ -247,15 +247,15 @@ // Subscripts // - func `prefix`(through: Index) -> NativeString { + public func `prefix`(through: Index) -> NativeString { return self[...through] // E119 Cannot use the unary operator "..." on type "extension String.Index" } - func `prefix`(upTo: Index) -> NativeString { + public func `prefix`(upTo: Index) -> NativeString { return self[.. NativeString { + public func suffix(from: Index) -> NativeString { return self[from...] } From 6818214d081ac23c534cdb312c1496d4e5f9f848 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Tue, 14 Jul 2020 17:54:40 -0400 Subject: [PATCH 35/79] Fix for Cooper namespace changes --- Source/Swift.Cooper.elements | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Swift.Cooper.elements b/Source/Swift.Cooper.elements index 1e59547..59dcfae 100644 --- a/Source/Swift.Cooper.elements +++ b/Source/Swift.Cooper.elements @@ -2,14 +2,14 @@ 3.5 - 399BE68A-44C3-4357-8D11-4B64C6EC0674 + {399BE68A-44C3-4357-8D11-4B64C6EC0674} Library Release False Swift swift JW0 - java.util,com.remobjects.elements.linq + java.util,remobjects.elements.linq True From ba00fe57fdc2fe4c38e6bdd402395beed6deb817 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Wed, 16 Sep 2020 10:35:40 -0400 Subject: [PATCH 36/79] #ifdef fix for COOPER? --- Source/String.Views.swift | 18 +++++++++++++++--- Source/String.swift | 6 +++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Source/String.Views.swift b/Source/String.Views.swift index d9a6ab2..de68f78 100644 --- a/Source/String.Views.swift +++ b/Source/String.Views.swift @@ -52,7 +52,7 @@ public extension SwiftString { i += sequenceLength } #elseif ISLAND - #hint Not implemented yet + #hint Not implemented yet #endif /* old logic to detect surrogate pairs; not needed right now @@ -229,7 +229,13 @@ public extension SwiftString { public override var count: Int { return length(stringData) } - public override var endIndex: SwiftString.Index { return RemObjects.Elements.System.length(stringData)/4 } + public override var endIndex: SwiftString.Index { + #if COOPER + return remobjects.elements.system.length(stringData)/4 + #else + return RemObjects.Elements.System.length(stringData)/4 + #endif + } var first: UTF32Char? { return count > 0 ? self[0] : nil } @@ -299,7 +305,13 @@ public extension SwiftString { public override var count: Int { return length(stringData) } - public override var endIndex: SwiftString.Index { return RemObjects.Elements.System.length(stringData) } + public override var endIndex: SwiftString.Index { + #if COOPER + return remobjects.elements.system.length(stringData) + #else + return RemObjects.Elements.System.length(stringData) + #endif + } var first: UTF8Char? { return count > 0 ? self[0] : nil } diff --git a/Source/String.swift b/Source/String.swift index 7534c3b..5b22913 100644 --- a/Source/String.swift +++ b/Source/String.swift @@ -179,7 +179,11 @@ public struct SwiftString /*: Streamable*/ { } public var endIndex: SwiftString.Index { - return RemObjects.Elements.System.length(nativeStringValue) // for now? + #if COOPER + return remobjects.elements.system.length(nativeStringValue) // for now? + #else + return RemObjects.Elements.System.length(stringData) + #endif } var fastestEncoding: SwiftString.Encoding { return SwiftString.Encoding.utf16 } From e109a13fed0c1988d6ea11c02cb83c71ade3ba1e Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Wed, 16 Sep 2020 11:02:37 -0400 Subject: [PATCH 37/79] #ifdef fix for COOPER? --- Source/String.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/String.swift b/Source/String.swift index 5b22913..0e94aab 100644 --- a/Source/String.swift +++ b/Source/String.swift @@ -182,7 +182,7 @@ public struct SwiftString /*: Streamable*/ { #if COOPER return remobjects.elements.system.length(nativeStringValue) // for now? #else - return RemObjects.Elements.System.length(stringData) + return RemObjects.Elements.System.length(nativeStringValue) #endif } From af60ac87b9cee01c2616b1d42e55a5cb23532f37 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Sat, 26 Sep 2020 08:10:44 -0400 Subject: [PATCH 38/79] Fix for Cooper namespace changes (Test project) --- Tests/Swift.Tests.elements | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Swift.Tests.elements b/Tests/Swift.Tests.elements index b774752..a6cdce8 100644 --- a/Tests/Swift.Tests.elements +++ b/Tests/Swift.Tests.elements @@ -23,7 +23,7 @@ Cooper Plain - java.util,com.remobjects.elements.linq + java.util,remobjects.elements.linq Echoes From c0b79344542046879bfc53bc22fd43e785eb1a58 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Tue, 26 Jan 2021 14:43:35 -0400 Subject: [PATCH 39/79] Semicolon cleanup --- Source/Integer_Extensions.swift | 34 ++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Source/Integer_Extensions.swift b/Source/Integer_Extensions.swift index 717c977..e82761a 100644 --- a/Source/Integer_Extensions.swift +++ b/Source/Integer_Extensions.swift @@ -162,18 +162,18 @@ public extension Int32 /*: AbsoluteValuable*/ { public extension Int32 /*: Strideable*/ { func advancedBy(_ n: Int32) -> Int32 { - return self + n; + return self + n } func distanceTo(_ other: Int32) -> Int32 { - return other - self; + return other - self } public func stride(# through: Int32, by: Int32) -> ISequence { precondition(by > 0, "'by' must be larger than zero") var i = self while i <= through { - __yield i; + __yield i i += by } } @@ -184,7 +184,7 @@ public extension Int32 /*: Strideable*/ { precondition(by > 0, "'by' must be larger than zero") var i = self while i < to { - __yield i; + __yield i i += by } } @@ -242,18 +242,18 @@ public extension Int64 {//: Equatable, Comparable, ForwardIndexType { // Strideable func advancedBy(_ n: Int64) -> Int64 { - return self + n; + return self + n } func distanceTo(_ other: Int64) -> Int64 { - return other - self; + return other - self } public func stride(# through: Int64, by: Int64) -> ISequence { precondition(by > 0, "'by' must be larger than zero") var i = self while i <= through { - __yield i; + __yield i i += by } } @@ -264,7 +264,7 @@ public extension Int64 {//: Equatable, Comparable, ForwardIndexType { precondition(by > 0, "'by' must be larger than zero") var i = self while i < to { - __yield i; + __yield i i += by } } @@ -276,18 +276,18 @@ public extension Float { // Strideable func advancedBy(_ n: Float) -> Float { - return self + n; + return self + n } func distanceTo(_ other: Float) -> Float { - return other - self; + return other - self } public func stride(# through: Float, by: Float) -> ISequence { precondition(by > 0, "'by' must be larger than zero") var i = self while i <= through { - __yield i; + __yield i i += by } } @@ -298,7 +298,7 @@ public extension Float { precondition(by > 0, "'by' must be larger than zero") var i = self while i < to { - __yield i; + __yield i i += by } } @@ -310,18 +310,18 @@ public extension Double { // Strideable func advancedBy(_ n: Double) -> Double { - return self + n; + return self + n } func distanceTo(_ other: Double) -> Double { - return other - self; + return other - self } public func stride(# through: Double, by: Double) -> ISequence { precondition(by > 0, "'by' must be larger than zero") - var i = self + let i = self while i <= through { - __yield i; + __yield i i += by } } @@ -332,7 +332,7 @@ public extension Double { precondition(by > 0, "'by' must be larger than zero") var i = self while i < to { - __yield i; + __yield i i += by } } From 2ff932a6dad50233d98728f5eaea97dadfc6215e Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Fri, 7 May 2021 08:50:59 -0400 Subject: [PATCH 40/79] Added `stride(from: through: by:)` --- Source/Functions.swift | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Source/Functions.swift b/Source/Functions.swift index 23f9e26..8fe1fdd 100644 --- a/Source/Functions.swift +++ b/Source/Functions.swift @@ -177,15 +177,14 @@ public func stride(from start: Int, to end: Int, by stride: Int) -> ISequence ISequence { +public func stride(from start: Int, through end: Int, by stride: Int) -> ISequence { precondition(stride > 0, "'by' must be larger than zero") var i = start while i <= end { __yield i; i += stride } -}*/ +} public func stride(from start: Double, to end: Double, by stride: Double) -> ISequence { precondition(stride > 0, "'by' must be larger than zero") @@ -197,14 +196,14 @@ public func stride(from start: Double, to end: Double, by stride: Double) -> ISe } //75284: Silver: can't overload global func on parameter names? -/*public func stride(from start: Double, through end: Double, by stride: Double) -> ISequence { +public func stride(from start: Double, through end: Double, by stride: Double) -> ISequence { precondition(stride > 0, "'by' must be larger than zero") var i = start while i <= end { __yield i; i += stride } -}*/ +} #if TOFFEE From 4cc6241c381ab33e93d0a9f1a8771776202ec817 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Fri, 7 May 2021 08:57:17 -0400 Subject: [PATCH 41/79] Added `stride(from: through: by:)` (except the double variant, on Toffee) --- Source/Functions.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/Functions.swift b/Source/Functions.swift index 8fe1fdd..2b4fd92 100644 --- a/Source/Functions.swift +++ b/Source/Functions.swift @@ -195,6 +195,7 @@ public func stride(from start: Double, to end: Double, by stride: Double) -> ISe } } +#if !TOFFEE //75284: Silver: can't overload global func on parameter names? public func stride(from start: Double, through end: Double, by stride: Double) -> ISequence { precondition(stride > 0, "'by' must be larger than zero") @@ -204,6 +205,7 @@ public func stride(from start: Double, through end: Double, by stride: Double) - i += stride } } +#endif #if TOFFEE From 298f1ac0b8fe2cf7a92312cd094af4a82ce1dab7 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Fri, 7 May 2021 09:03:21 -0400 Subject: [PATCH 42/79] Support negative strides in `stride(from: to: by:)` --- Source/Functions.swift | 57 +++++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/Source/Functions.swift b/Source/Functions.swift index 2b4fd92..8af5816 100644 --- a/Source/Functions.swift +++ b/Source/Functions.swift @@ -169,40 +169,63 @@ public func readLine(# stripNewline: Bool = true) -> String { } public func stride(from start: Int, to end: Int, by stride: Int) -> ISequence { - precondition(stride > 0, "'by' must be larger than zero") var i = start - while i < end { - __yield i; - i += stride + if stride > 0 { + while i < end { + __yield i; + i += stride + } + } else if stride < 0 { + while i > end { + __yield i; + i += stride + } } } public func stride(from start: Int, through end: Int, by stride: Int) -> ISequence { - precondition(stride > 0, "'by' must be larger than zero") var i = start - while i <= end { - __yield i; - i += stride + if stride > 0 { + while i <= end { + __yield i; + i += stride + } + } else if stride < 0 { + while i >= end { + __yield i; + i += stride + } } } public func stride(from start: Double, to end: Double, by stride: Double) -> ISequence { - precondition(stride > 0, "'by' must be larger than zero") var i = start - while i < end { - __yield i; - i += stride + if stride > 0 { + while i < end { + __yield i; + i += stride + } + } else if stride < 0 { + while i > end { + __yield i; + i += stride + } } } #if !TOFFEE -//75284: Silver: can't overload global func on parameter names? public func stride(from start: Double, through end: Double, by stride: Double) -> ISequence { - precondition(stride > 0, "'by' must be larger than zero") var i = start - while i <= end { - __yield i; - i += stride + if stride > 0 { + while i <= end { + __yield i; + i += stride + } + } else if stride < 0 { + while i >= end { + __yield i; + i += stride + } } } #endif From 85530588cdaf80f47f07b6abb4af1285a59473cd Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Fri, 7 May 2021 09:06:32 -0400 Subject: [PATCH 43/79] Double .ctor (not active) --- Source/Integer_Extensions.swift | 77 +++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/Source/Integer_Extensions.swift b/Source/Integer_Extensions.swift index e82761a..0c6ad93 100644 --- a/Source/Integer_Extensions.swift +++ b/Source/Integer_Extensions.swift @@ -307,6 +307,83 @@ public extension Float { public extension Double { + /*init?(_ stringValue: String?) { + + var stringValue = stringValue//?.Trim() + if length(stringValue) == 0 { + throw Exception("Invalud Double value") + } + + if #defined(COOPER) { + let DecFormat = java.text.DecimalFormat.getInstance(java.util.Locale.Default) as! java.text.DecimalFormat + let Position = java.text.ParsePosition(0) + stringValue = stringValue!.Trim().toUpperCase() + // E+ is not accepted, just E or E- + stringValue = stringValue!.Replace("E+", "E") + if #defined(ANDROID) { + if stringValue.Length > 1 { + let DecimalIndex = stringValue.IndexOf(".") + if DecimalIndex = -1 { + DecimalIndex = stringValue.Length + } + stringValue = stringValue[0] + stringValue.Substring(1, DecimalIndex - 1).Replace(",", "") + stringValue.Substring(DecimalIndex) + } + } + + if stringValue!.StartsWith("+") { + stringValue = stringValue!.Substring(1) + } + let result = DecFormat.parse(stringValue, Position)?.doubleValue() + if Position.Index < stringValue!.Length() { + throw Exception("Invalud Double value") + } + if Double.isInfinite(result) || Double.isNaN(result) { + throw Exception("Invalud Double value") + } + return result + } else if #defined(TOFFEE) { + let Number = TryParseNumber(stringValue, Foundation.NSLocale.systemLocale) + if Number == nil { + throw Exception("Invalud Double value") + } + return Number?.doubleValue + } else if #defined(ECHOES) { + let result: Double + if !Double.TryParse(stringValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, &result) { + throw Exception("Invalud Double value") + } + return valueOrDefault(result) + } else if #defined(ISLAND) { + let result: Double + if !Double.TryParse(stringValue, RemObjects.Elements.System.Locale.Invariant, &result) { + throw Exception("Invalud Double value") + } + return valueOrDefault(result) + } + }*/ + + #if TOFFEE + private static func TryParseNumber(_ stringValue: String?, _ aLocale: Foundation.NSLocale? = nil) -> NSNumber? { + + var stringValue = stringValue//?.Trim() + if length(stringValue) == 0 { + return nil + } + + let Formatter = NSNumberFormatter() + Formatter.numberStyle = NSNumberFormatterStyle.NSNumberFormatterDecimalStyle + Formatter.locale = aLocale + if (stringValue as! NSString).rangeOfCharacterFromSet(NSCharacterSet.whitespaceAndNewlineCharacterSet).location != NSNotFound { + return nil + } + if stringValue!.hasPrefix("+") && !stringValue!.contains("-") { + stringValue = stringValue!.substring(fromIndex: 1) + return Formatter.numberFromString(stringValue) + } + return nil + } + #endif + // Strideable func advancedBy(_ n: Double) -> Double { From 003a6858de51b1c38cce6c3ee72d1149f6927ac4 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Mon, 10 May 2021 17:11:24 -0400 Subject: [PATCH 44/79] type(of:) --- Source/Functions.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Source/Functions.swift b/Source/Functions.swift index 8af5816..a234544 100644 --- a/Source/Functions.swift +++ b/Source/Functions.swift @@ -230,6 +230,17 @@ public func stride(from start: Double, through end: Double, by stride: Double) - } #endif +#if COOPER || TOFFEE +@inline(always) public func type(of value: Any) -> Class { + return typeOf(value) +} +#elseif ECHOES || ISLAND +@inline(always) public func type(of value: Any) -> Type { + return typeOf(value) +} +#endif + + #if TOFFEE public func autoreleasepool(_ act: () throws -> (T)) -> T throws { From e885ea70eeb573b61546b60e1c77371186ead2db Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Wed, 26 May 2021 12:24:31 -0400 Subject: [PATCH 45/79] SE-0220 count(where:) --- Source/Sequence_Extensions.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Source/Sequence_Extensions.swift b/Source/Sequence_Extensions.swift index 98f1522..e7dd20c 100644 --- a/Source/Sequence_Extensions.swift +++ b/Source/Sequence_Extensions.swift @@ -85,6 +85,16 @@ public extension ISequence /*: ICustomDebugStringConvertible*/ { // 74092: Silve return self.Where() { return try! includeElement($0) } } + public func count(`where` countElement: (T) throws -> Bool) rethrows -> Int { + var result = 0; + for i in self { + if try countElement(i) { + result++ + } + } + return result + } + public var first: T? { return self.FirstOrDefault() } From 043e354a5fb27970381db676c4c23858dfe947c8 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Thu, 24 Jun 2021 11:30:29 -0400 Subject: [PATCH 46/79] Actor and Sendable protocols --- Source/Protocols.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Source/Protocols.swift b/Source/Protocols.swift index 81dc8c1..0e13c42 100644 --- a/Source/Protocols.swift +++ b/Source/Protocols.swift @@ -74,4 +74,12 @@ public protocol IStringProtocol : ITextOutputStream { /*public protocol GeneratorType { typealias Element mutating func next() -> Element? -}*/ \ No newline at end of file +}*/ + +public typealias Actor = IActor +protocol IActor : AnyObject, Sendable { +} + +public typealias Sendable = ISendable +protocol ISendable { +} \ No newline at end of file From e2ba660edb760f322e7db94150e06d7c2a0932d4 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Tue, 29 Jun 2021 10:37:09 -0400 Subject: [PATCH 47/79] Tweak for missing Island implementation --- Source/String.Views.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/String.Views.swift b/Source/String.Views.swift index de68f78..0014d43 100644 --- a/Source/String.Views.swift +++ b/Source/String.Views.swift @@ -52,7 +52,8 @@ public extension SwiftString { i += sequenceLength } #elseif ISLAND - #hint Not implemented yet + throw NotImplementedException("CharacterView is not fully implemented for Island yet.") + #hint Not implemented yet #endif /* old logic to detect surrogate pairs; not needed right now From da8ebb47b4aea69809f157d731b58b7c0cb025ac Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Tue, 29 Jun 2021 10:37:36 -0400 Subject: [PATCH 48/79] New multi-target project (wip) --- Source/Silver.elements | 119 +++++++++++++++++++++++++++++++++++++++++ Source/Silver.sln | 22 ++++++++ 2 files changed, 141 insertions(+) create mode 100644 Source/Silver.elements create mode 100644 Source/Silver.sln diff --git a/Source/Silver.elements b/Source/Silver.elements new file mode 100644 index 0000000..c4a1db1 --- /dev/null +++ b/Source/Silver.elements @@ -0,0 +1,119 @@ + + + + {9E7A4B59-8176-4CAE-B966-7E299171B148} + StaticLibrary + Swift + Release + True + True + True + True + True + + + .\Bin\Debug + True + False + True + DEBUG;TRACE; + + + .\Bin\Release + + + Echoes + .NETFramework4.0 + Library + System.Collections.Generic;System.Linq + + + Echoes + .NETStandard2.0 + NETSTANDARD + Library + System.Collections.Generic;System.Linq + + + Cooper + Java + Library + java.util,remobjects.elements.linq + + + Island + Windows + + + Island + Linux + + + Island + Darwin + macOS + Foundation;RemObjects.Elements.System;rtl + + + Island + Darwin + iOS + True + Foundation;RemObjects.Elements.System;rtl + + + Island + Darwin + tvOS + Foundation;RemObjects.Elements.System;rtl + + + Island + Darwin + watchOS + Foundation;RemObjects.Elements.System;rtl + + + Island + Android + + + Island + WebAssembly + + + Toffee + iOS + True + Foundation;RemObjects.Elements.Linq + + + Toffee + macOS + Foundation;RemObjects.Elements.Linq + + + Toffee + tvOS + Foundation;RemObjects.Elements.Linq + + + Toffee + watchOS + Foundation;RemObjects.Elements.Linq + + + + + + + + + + + True + + + + + \ No newline at end of file diff --git a/Source/Silver.sln b/Source/Silver.sln new file mode 100644 index 0000000..b3f07cb --- /dev/null +++ b/Source/Silver.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# RemObjects Fire +Project("{656346D9-4656-40DA-A068-22D5425D4639}") = "Silver", "Silver.elements", "{9E7A4B59-8176-4CAE-B966-7E299171B148}" +EndProject +Project("{656346D9-4656-40DA-A068-22D5425D4639}") = "Swift.Shared", "Swift.Shared.elements", "{7952073B-795C-4074-954D-212FE780D7D3}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|AnyCPU = Debug|AnyCPU + Release|AnyCPU = Release|AnyCPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9E7A4B59-8176-4CAE-B966-7E299171B148}.Debug|AnyCPU.ActiveCfg = Debug|AnyCPU + {9E7A4B59-8176-4CAE-B966-7E299171B148}.Debug|AnyCPU.Build.0 = Debug|AnyCPU + {9E7A4B59-8176-4CAE-B966-7E299171B148}.Release|AnyCPU.ActiveCfg = Release|AnyCPU + {9E7A4B59-8176-4CAE-B966-7E299171B148}.Release|AnyCPU.Build.0 = Release|AnyCPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal \ No newline at end of file From 1937b8871bf12aafe8ea8827ddea095f355ab000 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Tue, 29 Jun 2021 10:47:50 -0400 Subject: [PATCH 49/79] Obsolete warning fixes --- Source/Array.swift | 4 ++-- Source/Sequence_Extensions.swift | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Array.swift b/Source/Array.swift index f6e5cd3..1c22940 100755 --- a/Source/Array.swift +++ b/Source/Array.swift @@ -127,7 +127,7 @@ public struct Array #elseif CLR | ISLAND list = sequence.ToList() #elseif COCOA - list = sequence.array().mutableCopy() + list = sequence.ToNSArray().mutableCopy() #endif } @@ -455,7 +455,7 @@ public struct Array #elseif CLR | ISLAND list.AddRange(sequence.ToList()) #elseif COCOA - list.addObjectsFromArray(sequence.array()) + list.addObjectsFromArray(sequence.ToNSArray()) #endif } diff --git a/Source/Sequence_Extensions.swift b/Source/Sequence_Extensions.swift index e7dd20c..f195e1b 100644 --- a/Source/Sequence_Extensions.swift +++ b/Source/Sequence_Extensions.swift @@ -235,7 +235,7 @@ public extension ISequence /*: ICustomDebugStringConvertible*/ { // 74092: Silve } return result #elseif COCOA - return self.array().sortedArrayWithOptions(0, usingComparator: { (a: id!, b: id!) -> NSComparisonResult in // ToDo: check if this is the right order + return self.ToNSArray().sortedArrayWithOptions(0, usingComparator: { (a: id!, b: id!) -> NSComparisonResult in // ToDo: check if this is the right order if isOrderedBefore(a == NSNull.null ? nil : a, b == NSNull.null ? nil : b) { return .NSOrderedDescending } else { @@ -388,7 +388,7 @@ public extension ISequence /*: ICustomDebugStringConvertible*/ { // 74092: Silve #elseif CLR || ISLAND return [T](self.ToList()) #elseif COCOA - return [T](self.array()) + return [T](self.ToNSArray()) #endif } From dd4c3421acf208bbd49ebc27901036eb22a0f4dd Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Tue, 29 Jun 2021 16:25:14 -0400 Subject: [PATCH 50/79] Changed output name for Island to Silver --- Source/Swift.Island.Darwin.iOS.elements | 4 ++-- Source/Swift.Island.Darwin.macOS.elements | 5 ++--- Source/Swift.Island.Darwin.tvOS.elements | 4 ++-- Source/Swift.Island.Darwin.watchOS.elements | 4 ++-- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Source/Swift.Island.Darwin.iOS.elements b/Source/Swift.Island.Darwin.iOS.elements index 497ba7b..d28d739 100644 --- a/Source/Swift.Island.Darwin.iOS.elements +++ b/Source/Swift.Island.Darwin.iOS.elements @@ -3,9 +3,8 @@ 3.5 Swift - {6f87c50f-069a-4e56-9b2e-044cbb68cc83} + {6F87C50F-069A-4E56-9B2E-044CBB68CC83} StaticLibrary - Swift False False False @@ -15,6 +14,7 @@ Foundation;RemObjects.Elements.System;rtl iOS True + Silver false diff --git a/Source/Swift.Island.Darwin.macOS.elements b/Source/Swift.Island.Darwin.macOS.elements index 32d9b3e..74d87fa 100644 --- a/Source/Swift.Island.Darwin.macOS.elements +++ b/Source/Swift.Island.Darwin.macOS.elements @@ -3,9 +3,8 @@ 3.5 Swift - {792e19d0-3f6b-4ef5-a113-87c76eb0ce5e} + {792E19D0-3F6B-4EF5-A113-87C76EB0CE5E} StaticLibrary - Swift False False False @@ -14,6 +13,7 @@ Release Foundation;RemObjects.Elements.System;rtl macOS + Silver false @@ -48,7 +48,6 @@ False True SIGN - x86_64 diff --git a/Source/Swift.Island.Darwin.tvOS.elements b/Source/Swift.Island.Darwin.tvOS.elements index 5f1fad6..703d8e9 100644 --- a/Source/Swift.Island.Darwin.tvOS.elements +++ b/Source/Swift.Island.Darwin.tvOS.elements @@ -3,9 +3,8 @@ 3.5 Swift - {a037c663-4495-4630-a9ef-39079ba1ec07} + {A037C663-4495-4630-A9EF-39079BA1EC07} StaticLibrary - Swift False False False @@ -14,6 +13,7 @@ Release Foundation;RemObjects.Elements.System;rtl tvOS + Silver false diff --git a/Source/Swift.Island.Darwin.watchOS.elements b/Source/Swift.Island.Darwin.watchOS.elements index 469a238..809ccdb 100644 --- a/Source/Swift.Island.Darwin.watchOS.elements +++ b/Source/Swift.Island.Darwin.watchOS.elements @@ -3,9 +3,8 @@ 3.5 Swift - {b9065575-47d6-4740-8d96-d8f5a1a30b0b} + {B9065575-47D6-4740-8D96-D8F5A1A30B0B} StaticLibrary - Swift False False False @@ -14,6 +13,7 @@ Release Foundation;RemObjects.Elements.System;rtl watchOS + Silver false From 091bf61310770acd78758c5616e0de29f0c33134 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Wed, 30 Jun 2021 10:44:27 -0400 Subject: [PATCH 51/79] Missing deployment targets --- Source/Silver.elements | 5 +++++ Source/Swift.Island.Darwin.iOS.elements | 1 + Source/Swift.Island.Darwin.macOS.elements | 1 + Source/Swift.Island.Darwin.tvOS.elements | 1 + Source/Swift.Island.Darwin.watchOS.elements | 1 + Source/Swift.Toffee.iOS.elements | 4 ++-- Source/Swift.Toffee.macOS.elements | 5 ++--- Source/Swift.Toffee.tvOS.elements | 4 ++-- Source/Swift.Toffee.watchOS.elements | 4 ++-- 9 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Source/Silver.elements b/Source/Silver.elements index c4a1db1..cf7a334 100644 --- a/Source/Silver.elements +++ b/Source/Silver.elements @@ -52,12 +52,14 @@ Island Darwin macOS + 10.12 Foundation;RemObjects.Elements.System;rtl Island Darwin iOS + 9.0 True Foundation;RemObjects.Elements.System;rtl @@ -65,12 +67,14 @@ Island Darwin tvOS + 9.0 Foundation;RemObjects.Elements.System;rtl Island Darwin watchOS + 3.0 Foundation;RemObjects.Elements.System;rtl @@ -90,6 +94,7 @@ Toffee macOS + 10.9 Foundation;RemObjects.Elements.Linq diff --git a/Source/Swift.Island.Darwin.iOS.elements b/Source/Swift.Island.Darwin.iOS.elements index d28d739..56c1288 100644 --- a/Source/Swift.Island.Darwin.iOS.elements +++ b/Source/Swift.Island.Darwin.iOS.elements @@ -15,6 +15,7 @@ iOS True Silver + 9.0 false diff --git a/Source/Swift.Island.Darwin.macOS.elements b/Source/Swift.Island.Darwin.macOS.elements index 74d87fa..acfcfa1 100644 --- a/Source/Swift.Island.Darwin.macOS.elements +++ b/Source/Swift.Island.Darwin.macOS.elements @@ -14,6 +14,7 @@ Foundation;RemObjects.Elements.System;rtl macOS Silver + 10.12 false diff --git a/Source/Swift.Island.Darwin.tvOS.elements b/Source/Swift.Island.Darwin.tvOS.elements index 703d8e9..74458eb 100644 --- a/Source/Swift.Island.Darwin.tvOS.elements +++ b/Source/Swift.Island.Darwin.tvOS.elements @@ -14,6 +14,7 @@ Foundation;RemObjects.Elements.System;rtl tvOS Silver + 9.0 false diff --git a/Source/Swift.Island.Darwin.watchOS.elements b/Source/Swift.Island.Darwin.watchOS.elements index 809ccdb..1bbbcaa 100644 --- a/Source/Swift.Island.Darwin.watchOS.elements +++ b/Source/Swift.Island.Darwin.watchOS.elements @@ -14,6 +14,7 @@ Foundation;RemObjects.Elements.System;rtl watchOS Silver + 3.0 false diff --git a/Source/Swift.Toffee.iOS.elements b/Source/Swift.Toffee.iOS.elements index 76485b5..cefbf20 100644 --- a/Source/Swift.Toffee.iOS.elements +++ b/Source/Swift.Toffee.iOS.elements @@ -2,7 +2,7 @@ Swift - 95F9545C-39BE-4A02-8673-8382ECB3F7AD + {95F9545C-39BE-4A02-8673-8382ECB3F7AD} StaticLibrary Swift False @@ -14,7 +14,7 @@ iOS True Foundation,RemObjects.Elements.Linq - 7.1 + 9.0 True NW6 True diff --git a/Source/Swift.Toffee.macOS.elements b/Source/Swift.Toffee.macOS.elements index 3e3fdcb..8cf86eb 100644 --- a/Source/Swift.Toffee.macOS.elements +++ b/Source/Swift.Toffee.macOS.elements @@ -2,7 +2,7 @@ Swift - 8F87CCEF-C142-49A8-8828-32211B2CBFBE + {8F87CCEF-C142-49A8-8828-32211B2CBFBE} StaticLibrary Swift False @@ -14,7 +14,7 @@ macOS True Foundation,RemObjects.Elements.Linq - 10.9 + 10.12 True DEBUG;OLD_DEPLOYMENT_TARGET;TRACE NW6 @@ -37,7 +37,6 @@ False False True - diff --git a/Source/Swift.Toffee.tvOS.elements b/Source/Swift.Toffee.tvOS.elements index 2f0cc79..20eb46f 100644 --- a/Source/Swift.Toffee.tvOS.elements +++ b/Source/Swift.Toffee.tvOS.elements @@ -2,7 +2,7 @@ Swift - EA152C1C-C6DD-48F8-9415-8B7FDA4653D9 + {EA152C1C-C6DD-48F8-9415-8B7FDA4653D9} StaticLibrary Swift False @@ -14,7 +14,7 @@ tvOS True Foundation,RemObjects.Elements.Linq - 9.2 + 9.0 True NW6 diff --git a/Source/Swift.Toffee.watchOS.elements b/Source/Swift.Toffee.watchOS.elements index da8e109..591e5c4 100644 --- a/Source/Swift.Toffee.watchOS.elements +++ b/Source/Swift.Toffee.watchOS.elements @@ -2,7 +2,7 @@ Swift - E0C9DDDB-B83F-4164-ADE4-577FB6611F3F + {E0C9DDDB-B83F-4164-ADE4-577FB6611F3F} StaticLibrary Swift False @@ -14,7 +14,7 @@ watchOS True Foundation,RemObjects.Elements.Linq - 2.2 + 3.0 True NW6 From 3c0527b305be5c4f06296f7582a0ae676cc6fc9d Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Wed, 14 Jul 2021 10:09:49 -0400 Subject: [PATCH 52/79] Changed output name for all platforms to Silver --- Source/Swift.Cooper.elements | 2 +- Source/Swift.Echoes.Standard.elements | 2 +- Source/Swift.Echoes.elements | 4 ++-- Source/Swift.Island.Android.elements | 4 ++-- Source/Swift.Island.Linux.elements | 4 ++-- Source/Swift.Island.WebAssembly.elements | 4 ++-- Source/Swift.Island.Windows.elements | 4 ++-- Source/Swift.Shared.projitems | 3 +-- Source/Swift.Toffee.iOS.elements | 2 +- Source/Swift.Toffee.macOS.elements | 2 +- Source/Swift.Toffee.tvOS.elements | 2 +- Source/Swift.Toffee.watchOS.elements | 2 +- Tests/Swift.Tests.sln | 20 ++++++++++++++++++++ 13 files changed, 37 insertions(+), 18 deletions(-) create mode 100644 Tests/Swift.Tests.sln diff --git a/Source/Swift.Cooper.elements b/Source/Swift.Cooper.elements index 59dcfae..6ec8049 100644 --- a/Source/Swift.Cooper.elements +++ b/Source/Swift.Cooper.elements @@ -7,10 +7,10 @@ Release False Swift - swift JW0 java.util,remobjects.elements.linq True + silver .\bin\Debug diff --git a/Source/Swift.Echoes.Standard.elements b/Source/Swift.Echoes.Standard.elements index d6b44b2..3edd132 100644 --- a/Source/Swift.Echoes.Standard.elements +++ b/Source/Swift.Echoes.Standard.elements @@ -5,7 +5,6 @@ Swift {CDDEBE6E-6B6B-4EF7-B2E1-57239C443426} Library - Swift False False False @@ -14,6 +13,7 @@ Release System.Collections.Generic;System.Linq .NETStandard2.0 + Silver false diff --git a/Source/Swift.Echoes.elements b/Source/Swift.Echoes.elements index 08e34b2..b0ea242 100644 --- a/Source/Swift.Echoes.elements +++ b/Source/Swift.Echoes.elements @@ -3,9 +3,8 @@ 3.5 Swift - BAE82ECC-39A5-4A18-9CE1-EAC0653F6E0F + {BAE82ECC-39A5-4A18-9CE1-EAC0653F6E0F} Library - Swift False False False @@ -14,6 +13,7 @@ Release v4.0 System.Collections.Generic;System.Linq + Silver false diff --git a/Source/Swift.Island.Android.elements b/Source/Swift.Island.Android.elements index 4a28550..1f76656 100644 --- a/Source/Swift.Island.Android.elements +++ b/Source/Swift.Island.Android.elements @@ -3,15 +3,15 @@ 3.5 Swift - {fa456b74-3e30-45ed-91b2-6bb7a104f836} + {FA456B74-3E30-45ED-91B2-6BB7A104F836} StaticLibrary - Swift False False False False False Release + Silver false diff --git a/Source/Swift.Island.Linux.elements b/Source/Swift.Island.Linux.elements index 1c86cd7..194addb 100644 --- a/Source/Swift.Island.Linux.elements +++ b/Source/Swift.Island.Linux.elements @@ -3,15 +3,15 @@ 3.5 Swift - {a764b9ef-be23-43ae-aceb-43f24f45eae9} + {A764B9EF-BE23-43AE-ACEB-43F24F45EAE9} StaticLibrary - Swift False False False False False Release + Silver false diff --git a/Source/Swift.Island.WebAssembly.elements b/Source/Swift.Island.WebAssembly.elements index 4ac3b41..4000898 100644 --- a/Source/Swift.Island.WebAssembly.elements +++ b/Source/Swift.Island.WebAssembly.elements @@ -3,15 +3,15 @@ 3.5 Swift - {d38b4354-35c8-4bc9-9415-4d72a1f77ca1} + {D38B4354-35C8-4BC9-9415-4D72A1F77CA1} StaticLibrary - Swift False False False False False Release + Silver false diff --git a/Source/Swift.Island.Windows.elements b/Source/Swift.Island.Windows.elements index 4539b9b..2307df3 100644 --- a/Source/Swift.Island.Windows.elements +++ b/Source/Swift.Island.Windows.elements @@ -3,15 +3,15 @@ 3.5 Swift - {d32e206a-1255-4da9-8287-64e5e988aba4} + {D32E206A-1255-4DA9-8287-64E5E988ABA4} StaticLibrary - Swift False False False False False Release + Silver false diff --git a/Source/Swift.Shared.projitems b/Source/Swift.Shared.projitems index 8e408e4..ea4132f 100644 --- a/Source/Swift.Shared.projitems +++ b/Source/Swift.Shared.projitems @@ -4,9 +4,8 @@ $(MSBuildAllProjects);$(MSBuildThisFileFullPath) true 7952073B-795C-4074-954D-212FE780D7D3 - - Swift.Shared + {7952073B-795C-4074-954D-212FE780D7D3} diff --git a/Source/Swift.Toffee.iOS.elements b/Source/Swift.Toffee.iOS.elements index cefbf20..5932029 100644 --- a/Source/Swift.Toffee.iOS.elements +++ b/Source/Swift.Toffee.iOS.elements @@ -4,7 +4,6 @@ Swift {95F9545C-39BE-4A02-8673-8382ECB3F7AD} StaticLibrary - Swift False False False @@ -18,6 +17,7 @@ True NW6 True + Silver false diff --git a/Source/Swift.Toffee.macOS.elements b/Source/Swift.Toffee.macOS.elements index 8cf86eb..f6fef88 100644 --- a/Source/Swift.Toffee.macOS.elements +++ b/Source/Swift.Toffee.macOS.elements @@ -4,7 +4,6 @@ Swift {8F87CCEF-C142-49A8-8828-32211B2CBFBE} StaticLibrary - Swift False False False @@ -18,6 +17,7 @@ True DEBUG;OLD_DEPLOYMENT_TARGET;TRACE NW6 + Silver false diff --git a/Source/Swift.Toffee.tvOS.elements b/Source/Swift.Toffee.tvOS.elements index 20eb46f..f01f909 100644 --- a/Source/Swift.Toffee.tvOS.elements +++ b/Source/Swift.Toffee.tvOS.elements @@ -4,7 +4,6 @@ Swift {EA152C1C-C6DD-48F8-9415-8B7FDA4653D9} StaticLibrary - Swift False False False @@ -17,6 +16,7 @@ 9.0 True NW6 + Silver false diff --git a/Source/Swift.Toffee.watchOS.elements b/Source/Swift.Toffee.watchOS.elements index 591e5c4..8d4954b 100644 --- a/Source/Swift.Toffee.watchOS.elements +++ b/Source/Swift.Toffee.watchOS.elements @@ -4,7 +4,6 @@ Swift {E0C9DDDB-B83F-4164-ADE4-577FB6611F3F} StaticLibrary - Swift False False False @@ -17,6 +16,7 @@ 3.0 True NW6 + Silver false diff --git a/Tests/Swift.Tests.sln b/Tests/Swift.Tests.sln new file mode 100644 index 0000000..4a4915d --- /dev/null +++ b/Tests/Swift.Tests.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# RemObjects Fire +Project("{656346D9-4656-40DA-A068-22D5425D4639}") = "Swift.Tests", "Swift.Tests.elements", "{F22ABF38-8775-4118-8590-30756523030D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|AnyCPU = Debug|AnyCPU + Release|AnyCPU = Release|AnyCPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F22ABF38-8775-4118-8590-30756523030D}.Debug|AnyCPU.ActiveCfg = Debug|AnyCPU + {F22ABF38-8775-4118-8590-30756523030D}.Debug|AnyCPU.Build.0 = Debug|AnyCPU + {F22ABF38-8775-4118-8590-30756523030D}.Release|AnyCPU.ActiveCfg = Release|AnyCPU + {F22ABF38-8775-4118-8590-30756523030D}.Release|AnyCPU.Build.0 = Release|AnyCPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal \ No newline at end of file From 64cb42958c324910e33789b38179f0b19f1ffbd2 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Wed, 14 Jul 2021 11:36:59 -0400 Subject: [PATCH 53/79] =?UTF-8?q?Workaround=20for=20E25229:=20Regression:?= =?UTF-8?q?=20SBL/Toffee:=20Recursion=20detected=20in=20inheritance=20tree?= =?UTF-8?q?=20for=20type=20=E2=80=9CStreamable=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/String_Extensions.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/String_Extensions.swift b/Source/String_Extensions.swift index e9a83b0..6702ab8 100644 --- a/Source/String_Extensions.swift +++ b/Source/String_Extensions.swift @@ -1,4 +1,4 @@ -public extension NativeString : Streamable { +public extension NativeString /*: Streamable*/ { typealias Index = Int From 9011ce41d57160aaf69d6b4a0aae99e67d22cdf4 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Fri, 19 Nov 2021 10:06:37 -0400 Subject: [PATCH 54/79] Extension for NSArray (pending fix for E25528) --- Source/NSArray_Extensions.swift | 415 +++++++++++++++++++++++++++++++ Source/Sequence_Extensions.swift | 3 +- Source/Swift.Shared.projitems | 3 + 3 files changed, 419 insertions(+), 2 deletions(-) create mode 100644 Source/NSArray_Extensions.swift diff --git a/Source/NSArray_Extensions.swift b/Source/NSArray_Extensions.swift new file mode 100644 index 0000000..23ee64b --- /dev/null +++ b/Source/NSArray_Extensions.swift @@ -0,0 +1,415 @@ +#if DARWIN +public extension NSArray { + + init(nativeArray: ObjectType[]) { + let result = NSMutableArray(capacity: length(nativeArray)) + for e in nativeArray { + result.addObject(e) + } + return result + } + + init(array: [ObjectType]) { + return array as! ISequence // 74041: Silver: warning for "as" cast that should be known safe + } + + public func ToSwiftArray() -> [ObjectType] { + if let array = self as? [ObjectType] { + return array.platformList + } + var result = [ObjectType]() + for i in self { + result.append(i) + } + return result + } + + #if !COOPER + public func ToSwiftArray() -> [U] { + var result = [U]() + for i in self { + result.append(i as! U) + } + return result + } + #endif + + public func dropFirst() -> ISequence { + return self.Skip(1) + } + + public func dropFirst(_ n: Int) -> ISequence { + return self.Skip(n) + } + + public func dropLast() -> ISequence { + fatalError("dropLast() is not implemented yet.") + } + + public func dropLast(_ n: Int) -> ISequence { + fatalError("dropLast() is not implemented yet.") + } + + public func enumerated() -> ISequence<(Int, ObjectType)> { + var index = 0 + for element in self { + __yield (index++, element) + } + } + + public func indexOf(@noescape _ predicate: (ObjectType) -> Bool) -> Int? { + for (i, element) in self.enumerated() { + if (predicate(element) == true){ + return i + } + } + return nil + } + + public func filter(_ includeElement: (ObjectType) throws -> Bool) rethrows -> ISequence { + return self.Where() { return try! includeElement($0) } + } + + public func count(`where` countElement: (ObjectType) throws -> Bool) rethrows -> Int { + var result = 0; + for i in self { + if try countElement(i) { + result++ + } + } + return result + } + + public var first: ObjectType? { + return self.FirstOrDefault() + } + + func flatMap(@noescape _ transform: (ObjectType) throws -> ObjectType?) rethrows -> ISequence { + for e in self { + if let e = try! transform(e) { + __yield e + } + } + } + + public func flatten() -> ISequence { // no-op in Silver? i dont get what this does. + return self + } + + public func forEach(@noescape body: (ObjectType) throws -> ()) rethrows { + for e in self { + try! body(e) + } + } + + @Obsolete("generate() is not supported in Silver.", true) public func generate() -> ISequence { // no-op in Silver? i dont get what this does. + fatalError("generate() is not supported in Silver.") + } + + public var isEmpty: Bool { + return !self.Any() + } + + // E25528 + #if !ISLAND + public func joined(separator: String) -> String { + var first = true + var result = "" + for e in self { + if !first { + result += separator + } else { + first = false + } + result += e.description + } + return result + } + #endif + + public func joined(separator: ISequence) -> ISequence { + var first = true + for e in self { + if !first { + for i in separator { + __yield i + } + } else { + first = false + } + __yield e + } + } + + public func joined(separator: ObjectType[]) -> ISequence { + var first = true + for e in self { + if !first { + for i in separator { + __yield i + } + } else { + first = false + } + __yield e + } + } + + public var lazy: ISequence { // sequences are always lazy in Silver + return self + } + + public func map(_ transform: (ObjectType) -> U) -> ISequence { + return self.Select() { return transform($0) } + } + + //74101: Silver: still two issues with try! + public func maxElement(_ isOrderedBefore: (ObjectType, ObjectType) /*throws*/ -> Bool) -> ObjectType? { + var m: ObjectType? = nil + for e in self { + if m == nil || /*try!*/ !isOrderedBefore(m!, e) { // ToDo: check if this is the right order + m = e + } + } + return m + } + + public func minElement(_ isOrderedBefore: (ObjectType, ObjectType) /*throws*/ -> Bool) -> ObjectType? { + var m: ObjectType? = nil + for e in self { + if m == nil || /*try!*/ isOrderedBefore(m!, e) { // ToDo: check if this is the right order + m = e + } + } + return m + } + + public func `prefix`(_ maxLength: Int) -> ISequence { + return self.Take(maxLength) + } + + public func reduce(_ initial: U, _ combine: (U, ObjectType) -> U) -> U { + var value = initial + for i in self { + value = combine(value, i) + } + return value + } + + public func reverse() -> ISequence { + return self.Reverse() + } + + public func sorted(by isOrderedBefore: (ObjectType, ObjectType) -> Bool) -> ISequence { + //todo: make more lazy? + #if JAVA + let result = self.ToList() + java.util.Collections.sort(result, class java.util.Comparator { func compare(a: ObjectType, b: ObjectType) -> Int32 { // ToDo: check if this is the right order + if isOrderedBefore(a,b) { + return 1 + } else { + return -1 + } + }}) + return result + #elseif CLR || ISLAND + let result = self.ToList() + result.Sort() { (a: ObjectType, b: ObjectType) -> Integer in // ToDo: check if this is the right order + if isOrderedBefore(a,b) { + return -1 + } else { + return 1 + } + } + return result + #elseif COCOA + return self.ToNSArray().sortedArrayWithOptions(0, usingComparator: { (a: id!, b: id!) -> NSComparisonResult in // ToDo: check if this is the right order + if isOrderedBefore(a == NSNull.null ? nil : a, b == NSNull.null ? nil : b) { + return .NSOrderedDescending + } else { + return .NSOrderedAscending + } + })! + #endif + } + + /*public func split(_ isSeparator: (ObjectType) -> Bool, maxSplit: Int = 0, allowEmptySlices: Bool = false) -> ISequence> { + + let result = [String]() + var currentString = "" + + func appendCurrent() -> Bool { + if maxSplit > 0 && result.count >= maxSplit { + return false + } + if allowEmptySlices || currentString.length() > 0 { + result.append(currentString) + } + return true + } + + for var i = 0; i < elements.length(); i++ { + let ch = elements[i] + if isSeparator(ch) { + if !appendCurrent() { + break + } + currentString = "" + } else { + currentString += ch + } + } + + if currentString.length() > 0 { + appendCurrent() + } + + return result + }*/ + + public func startsWith(`prefix` p: ISequence) -> Bool { + #if JAVA + let sEnum = self.iterator() + let pEnum = p.iterator() + while true { + if pEnum.hasNext() { + let pVal = pEnum.next() + if sEnum.hasNext() { + let sVal = sEnum.next() + if (pVal == nil && sVal == nil) { + // both nil is oke + } else if pVal != nil && sVal != nil && pVal.equals(sVal) { + // Neither nil and equals true is oke + } else { + return false // Different values + } + } else { + return false // reached end of s + } + + } else { + return true // reached end of prefix + } + } + #elseif CLR || ISLAND + let pEnum = p.GetEnumerator() + for c in self { + if pEnum.MoveNext() { + #if CLR + if !EqualityComparer.Default.Equals(c, pEnum.Current) { + return false // cound mismatch + } + #elseif ISLAND + if c == nil && pEnum.Current == nil { + } else if c != nil && pEnum.Current != nil && c.Equals(pEnum.Current) { + } else { + return false + } + #endif + } else { + return true // reached end of prefix + } + } + return true // reached end of s + #elseif COCOA + let LOOP_SIZE = 16 + let sState: NSFastEnumerationState = `default`(NSFastEnumerationState) + let pState: NSFastEnumerationState = `default`(NSFastEnumerationState) + var sObjects = ObjectType[](count: LOOP_SIZE) + var pObjects = ObjectType[](count: LOOP_SIZE) + + while true { + let sCount = self.countByEnumeratingWithState(&sState, objects: sObjects, count: LOOP_SIZE) + let pCount = p.countByEnumeratingWithState(&pState, objects: pObjects, count: LOOP_SIZE) + if pCount > sCount { + return false // s is shorter than prefix + } + if pCount == 0 { + return true // reached end of prefix + } + for i in 0 ..< sCount { + if i > pCount { + return true // reached end of prefix + } + if !(sState.itemsPtr[i] as! Any).isEqual(pState.itemsPtr[i]) { + return false // found mismatch + } + } + } + #endif + } + + public func suffix(_ maxLength: Int) -> ISequence { + fatalError("suffix() is not implemented yet.") + } + + public func underestimateCount() -> Int { // we just return the accurate count here + return self.Count() + } + + // + // Silver-specific extensions not defined in standard Swift.Array: + // + + /*public func nativeArray() -> ObjectType[] { + #if JAVA + //return self.toArray()//ObjectType[]()) + #elseif CLR + return self.ToArray() + #elseif COCOA + //return self.array() + #endif + }*/ + + public func toSwiftArray() -> [ObjectType] { + #if JAVA + let result = ArrayList() + for e in self { + result.add(e); + } + return [ObjectType](result) + #elseif CLR || ISLAND + return [ObjectType](self.ToList()) + #elseif COCOA + return [ObjectType](self.ToNSArray()) + #endif + } + + public func contains(_ item: ObjectType) -> Bool { + return self.Contains(item) + } + + #if COCOA + override var debugDescription: String! { + var result = "Sequence(" + var first = true + for e in self { + if !first { + result += ", " + } else { + first = false + } + result += String(reflecting: e) + } + result += ")" + return result + } + #else + public var debugDescription: String { + var result = "Sequence(" + var first = true + for e in self { + if !first { + result += ", " + } else { + first = false + } + result += String(reflecting: e) + } + result += ")" + return result + } + #endif +} + +#endif \ No newline at end of file diff --git a/Source/Sequence_Extensions.swift b/Source/Sequence_Extensions.swift index f195e1b..62b3a83 100644 --- a/Source/Sequence_Extensions.swift +++ b/Source/Sequence_Extensions.swift @@ -1,5 +1,4 @@ - -public extension ISequence /*: ICustomDebugStringConvertible*/ { // 74092: Silver: interface on class extension fails on not finding the matching method +public extension ISequence : ICustomDebugStringConvertible { // 74092: Silver: interface on class extension fails on not finding the matching method init(nativeArray: T[]) { // 74043: Silver: wrong/confusing error when implementing iterator in nested function diff --git a/Source/Swift.Shared.projitems b/Source/Swift.Shared.projitems index ea4132f..2b48220 100644 --- a/Source/Swift.Shared.projitems +++ b/Source/Swift.Shared.projitems @@ -102,6 +102,9 @@ Memory + + Sequences + From 36fbc960c76307fd1cdf76e414d384fa264fc452 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Fri, 19 Nov 2021 10:06:43 -0400 Subject: [PATCH 55/79] Cleanup --- Source/Dispatch.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Dispatch.swift b/Source/Dispatch.swift index a75bda7..15530b2 100644 --- a/Source/Dispatch.swift +++ b/Source/Dispatch.swift @@ -157,11 +157,11 @@ public class DispatchQueue : DispatchObject { } public func asyncAfter(deadline: DispatchTime, execute work: () -> ()) { - dispatch_after(deadline.rawValue, self.queue, { work(); }) + dispatch_after(deadline.rawValue, self.queue, work) } public func asyncAfter(wallDeadline: DispatchWallTime, execute work: () -> ()) { - dispatch_after(wallDeadline.rawValue, self.queue, { work(); }) + dispatch_after(wallDeadline.rawValue, self.queue, work) } public func concurrentPerform(iterations: Int, execute work: (UInt) -> ()) { @@ -169,7 +169,7 @@ public class DispatchQueue : DispatchObject { } public func async(execute work: () -> ()) { - dispatch_async(self.queue, { work(); }) + dispatch_async(self.queue, work) } public func async(group: DispatchGroup?, execute work: () -> ()) { From f856e43eb8e6e7a2319d648e8bf1b0fe90adf5da Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Tue, 7 Dec 2021 16:10:36 -0400 Subject: [PATCH 56/79] Implicit cast from String to Character --- Source/Character.swift | 11 +++++++++++ Source/String_Extensions.swift | 2 -- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Source/Character.swift b/Source/Character.swift index 0d6c26d..9bfbb0d 100644 --- a/Source/Character.swift +++ b/Source/Character.swift @@ -6,6 +6,17 @@ return nativeStringValue } + public static func __implicit(_ char: Char) -> Character { + return Character(nativeStringValue: char) + } + + public static func __implicit(_ string: String) -> Character { + if string.characters.count != 1 { // not super efficient + throw Exception("Cannot cast string '\(string)' to Character") + } + return Character(nativeStringValue: string) + } + internal func toHexString() -> NativeString { if length(nativeStringValue) == 1 { return UInt32(nativeStringValue[0]).toHexString(length: 4) diff --git a/Source/String_Extensions.swift b/Source/String_Extensions.swift index 6702ab8..b9516f0 100644 --- a/Source/String_Extensions.swift +++ b/Source/String_Extensions.swift @@ -76,11 +76,9 @@ // Properties // - #if DARWIN || !ISLAND public var characters: SwiftString.CharacterView { return SwiftString.CharacterView(string: self) } - #endif #if !COCOA public var debugDescription: NativeString { From 45d78b0db489042057f740fc458eab75b9a413a4 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Fri, 10 Dec 2021 09:56:26 -0400 Subject: [PATCH 57/79] Dropped ifdef for E25528 --- Source/NSArray_Extensions.swift | 3 --- 1 file changed, 3 deletions(-) diff --git a/Source/NSArray_Extensions.swift b/Source/NSArray_Extensions.swift index 23ee64b..720c018 100644 --- a/Source/NSArray_Extensions.swift +++ b/Source/NSArray_Extensions.swift @@ -110,8 +110,6 @@ public extension NSArray { return !self.Any() } - // E25528 - #if !ISLAND public func joined(separator: String) -> String { var first = true var result = "" @@ -125,7 +123,6 @@ public extension NSArray { } return result } - #endif public func joined(separator: ISequence) -> ISequence { var first = true From b8d1d71cd14cd135ed30bec710846cadbd3e84f5 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Thu, 20 Jan 2022 10:57:44 -0400 Subject: [PATCH 58/79] Workaround for E25642: Island/Darwin: can't use generic params with Cocoa collection even if consrained to NSObject (DO NOT SHIP) --- Source/Array.swift | 60 +++++++++++++++++++++-------------------- Source/Dictionary.swift | 60 +++++++++++++++++++++-------------------- 2 files changed, 62 insertions(+), 58 deletions(-) diff --git a/Source/Array.swift b/Source/Array.swift index 1c22940..bd4a3cc 100755 --- a/Source/Array.swift +++ b/Source/Array.swift @@ -205,40 +205,12 @@ public struct Array } // Darwin only: cast from/to Cocoa type - #if DARWIN - #if ISLAND - public static func __implicit(_ array: NSArray) -> [T] { - return List(array) - } - - public static func __implicit(_ array: [T]) -> NSArray { - return array.list.ToNSArray() - } - - public static func __implicit(_ list: [T]) -> NSMutableArray { - return list.list.ToNSMutableArray() - } - #else + #if DARWIN && !ISLAND public static func __implicit(_ array: [T]) -> PlatformImmutableList { return array.platformList } #endif - // Cocoa only: cast from/to different generic Cocoa type - - public static func __explicit(_ array: NSArray) -> [T] { - return (array as! NSArray) as! [T] - } - - public static func __explicit(_ array: [T]) -> NSArray { - return (array as! NSArray) as! NSArray - } - - public static func __explicit(_ array: [T]) -> NSMutableArray { - return (array as! NSMutableArray) as! NSMutableArray - } - #endif - // // Operators // @@ -728,6 +700,36 @@ public struct Array } } +#if DARWIN && ISLAND +//public extension Array where T: NSObject { + //public static func __implicit(_ array: NSArray) -> [T] { + //return List(array) + //} + + //public static func __implicit(_ array: [T]) -> NSArray { + //return array.list.ToNSArray() + //} + + //public static func __implicit(_ list: [T]) -> NSMutableArray { + //return list.list.ToNSMutableArray() + //} + + //// Cocoa only: cast from/to different generic Cocoa type + + //public static func __explicit(_ array: NSArray) -> [T] { + //return (array as! NSArray) as! [T] + //} + + //public static func __explicit(_ array: [T]) -> NSArray { + //return (array as! NSArray) as! NSArray + //} + + //public static func __explicit(_ array: [T]) -> NSMutableArray { + //return (array as! NSMutableArray) as! NSMutableArray + //} +//} +#endif + //#if !COCOA //public extension Swift.Array : ISequence { diff --git a/Source/Dictionary.swift b/Source/Dictionary.swift index 17e74ff..ff2fa85 100755 --- a/Source/Dictionary.swift +++ b/Source/Dictionary.swift @@ -115,40 +115,12 @@ public struct Dictionary /*: INSFastEnumeration*/ // Darwin only: cast from/to Cocoa type - #if DARWIN - #if ISLAND - public static func __implicit(_ dictionary: NSDictionary) -> [Key:Value] { - return PlatformDictionary(dictionary) - } - - public static func __implicit(_ dictionary: [Key:Value]) -> NSDictionary { - return dictionary.dictionary.ToNSDictionary() - } - - public static func __implicit(_ dictionary: [Key:Value]) -> NSMutableDictionary { - return dictionary.dictionary.ToNSMutableDictionary() - } - #else + #if DARWIN && !ISLAND public static func __implicit(_ dictionary: [Key:Value]) -> PlatformImmutableDictionary { return dictionary.platformDictionary } #endif - // Cocoa only: cast from/to different generic Cocoa type - - public static func __explicit(_ dictionary: NSDictionary) -> [Key:Value] { - return (dictionary as! NSDictionary) as! [Key:Value] - } - - public static func __explicit(_ dictionary: [Key:Value]) -> NSDictionary { - return (dictionary as! NSDictionary) as! NSDictionary - } - - public static func __explicit(_ dictionary: [Key:Value]) -> NSMutableDictionary { - return (dictionary as! NSMutableDictionary) as! NSMutableDictionary - } - #endif - // // Operators // @@ -391,6 +363,36 @@ public struct Dictionary /*: INSFastEnumeration*/ } } +#if DARWIN && ISLAND +//public extension Dictionary where Key: NSObject, Value: NSObject { + //public static func __implicit(_ dictionary: NSDictionary) -> [Key:Value] { + //return PlatformDictionary(dictionary) + //} + + //public static func __implicit(_ dictionary: [Key:Value]) -> NSDictionary { + //return dictionary.dictionary.ToNSDictionary() + //} + + //public static func __implicit(_ dictionary: [Key:Value]) -> NSMutableDictionary { + //return dictionary.dictionary.ToNSMutableDictionary() + //} + + //// Cocoa only: cast from/to different generic Cocoa type + + //public static func __explicit(_ dictionary: NSDictionary) -> [Key:Value] { + //return (dictionary as! NSDictionary) as! [Key:Value] + //} + + //public static func __explicit(_ dictionary: [Key:Value]) -> NSDictionary { + //return (dictionary as! NSDictionary) as! NSDictionary + //} + + //public static func __explicit(_ dictionary: [Key:Value]) -> NSMutableDictionary { + //return (dictionary as! NSMutableDictionary) as! NSMutableDictionary + //} +//} +#endif + public static class DictionaryHelper { #if JAVA public static func Enumerate(_ val: PlatformDictionary) -> ISequence<(Key, Value)> { From 460029a670a64832ab6083b74d13467de72d769b Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Thu, 20 Jan 2022 10:59:04 -0400 Subject: [PATCH 59/79] Workaround for E25642: Island/Darwin: can't use generic params with Cocoa collection even if consrained to NSObject (DO NOT SHIP) --- Source/NSArray_Extensions.swift | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Source/NSArray_Extensions.swift b/Source/NSArray_Extensions.swift index 720c018..5581df4 100644 --- a/Source/NSArray_Extensions.swift +++ b/Source/NSArray_Extensions.swift @@ -14,9 +14,10 @@ public extension NSArray { } public func ToSwiftArray() -> [ObjectType] { - if let array = self as? [ObjectType] { - return array.platformList - } + //workaround for E25642: Island/Darwin: can't use generic params with Cocoa collection even if consrained to NSObject + //if let array = self as? [ObjectType] { + //return array.platformList + //} var result = [ObjectType]() for i in self { result.append(i) From 4c14adb8b93c0f5cbaaf36b541fadc6aec63acb1 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Thu, 20 Jan 2022 11:05:32 -0400 Subject: [PATCH 60/79] Workaround for E25643: Island: ambiguous call to "description" --- Source/NSArray_Extensions.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/NSArray_Extensions.swift b/Source/NSArray_Extensions.swift index 5581df4..1db1638 100644 --- a/Source/NSArray_Extensions.swift +++ b/Source/NSArray_Extensions.swift @@ -120,7 +120,8 @@ public extension NSArray { } else { first = false } - result += e.description + //workaround for E25643: Island: ambiguous call to "description" + result += (e as! NSObject).description } return result } From 3c8259d7fd7bb9ac1b759f398322ead024a9e46e Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Thu, 20 Jan 2022 17:45:26 -0400 Subject: [PATCH 61/79] Dropped workarounds for E25642 and E25643 --- Source/Array.swift | 42 ++++++++++++++++----------------- Source/Dictionary.swift | 42 ++++++++++++++++----------------- Source/NSArray_Extensions.swift | 3 +-- 3 files changed, 43 insertions(+), 44 deletions(-) diff --git a/Source/Array.swift b/Source/Array.swift index bd4a3cc..369c19a 100755 --- a/Source/Array.swift +++ b/Source/Array.swift @@ -701,33 +701,33 @@ public struct Array } #if DARWIN && ISLAND -//public extension Array where T: NSObject { - //public static func __implicit(_ array: NSArray) -> [T] { - //return List(array) - //} +public extension Array where T: NSObject { + public static func __implicit(_ array: NSArray) -> [T] { + return List(array) + } - //public static func __implicit(_ array: [T]) -> NSArray { - //return array.list.ToNSArray() - //} + public static func __implicit(_ array: [T]) -> NSArray { + return array.list.ToNSArray() + } - //public static func __implicit(_ list: [T]) -> NSMutableArray { - //return list.list.ToNSMutableArray() - //} + public static func __implicit(_ list: [T]) -> NSMutableArray { + return list.list.ToNSMutableArray() + } - //// Cocoa only: cast from/to different generic Cocoa type + // Cocoa only: cast from/to different generic Cocoa type - //public static func __explicit(_ array: NSArray) -> [T] { - //return (array as! NSArray) as! [T] - //} + public static func __explicit(_ array: NSArray) -> [T] { + return (array as! NSArray) as! [T] + } - //public static func __explicit(_ array: [T]) -> NSArray { - //return (array as! NSArray) as! NSArray - //} + public static func __explicit(_ array: [T]) -> NSArray { + return (array as! NSArray) as! NSArray + } - //public static func __explicit(_ array: [T]) -> NSMutableArray { - //return (array as! NSMutableArray) as! NSMutableArray - //} -//} + public static func __explicit(_ array: [T]) -> NSMutableArray { + return (array as! NSMutableArray) as! NSMutableArray + } +} #endif //#if !COCOA diff --git a/Source/Dictionary.swift b/Source/Dictionary.swift index ff2fa85..648f02c 100755 --- a/Source/Dictionary.swift +++ b/Source/Dictionary.swift @@ -364,33 +364,33 @@ public struct Dictionary /*: INSFastEnumeration*/ } #if DARWIN && ISLAND -//public extension Dictionary where Key: NSObject, Value: NSObject { - //public static func __implicit(_ dictionary: NSDictionary) -> [Key:Value] { - //return PlatformDictionary(dictionary) - //} +public extension Dictionary where Key: NSObject, Value: NSObject { + public static func __implicit(_ dictionary: NSDictionary) -> [Key:Value] { + return PlatformDictionary(dictionary) + } - //public static func __implicit(_ dictionary: [Key:Value]) -> NSDictionary { - //return dictionary.dictionary.ToNSDictionary() - //} + public static func __implicit(_ dictionary: [Key:Value]) -> NSDictionary { + return dictionary.dictionary.ToNSDictionary() + } - //public static func __implicit(_ dictionary: [Key:Value]) -> NSMutableDictionary { - //return dictionary.dictionary.ToNSMutableDictionary() - //} + public static func __implicit(_ dictionary: [Key:Value]) -> NSMutableDictionary { + return dictionary.dictionary.ToNSMutableDictionary() + } - //// Cocoa only: cast from/to different generic Cocoa type + // Cocoa only: cast from/to different generic Cocoa type - //public static func __explicit(_ dictionary: NSDictionary) -> [Key:Value] { - //return (dictionary as! NSDictionary) as! [Key:Value] - //} + public static func __explicit(_ dictionary: NSDictionary) -> [Key:Value] { + return (dictionary as! NSDictionary) as! [Key:Value] + } - //public static func __explicit(_ dictionary: [Key:Value]) -> NSDictionary { - //return (dictionary as! NSDictionary) as! NSDictionary - //} + public static func __explicit(_ dictionary: [Key:Value]) -> NSDictionary { + return (dictionary as! NSDictionary) as! NSDictionary + } - //public static func __explicit(_ dictionary: [Key:Value]) -> NSMutableDictionary { - //return (dictionary as! NSMutableDictionary) as! NSMutableDictionary - //} -//} + public static func __explicit(_ dictionary: [Key:Value]) -> NSMutableDictionary { + return (dictionary as! NSMutableDictionary) as! NSMutableDictionary + } +} #endif public static class DictionaryHelper { diff --git a/Source/NSArray_Extensions.swift b/Source/NSArray_Extensions.swift index 1db1638..5581df4 100644 --- a/Source/NSArray_Extensions.swift +++ b/Source/NSArray_Extensions.swift @@ -120,8 +120,7 @@ public extension NSArray { } else { first = false } - //workaround for E25643: Island: ambiguous call to "description" - result += (e as! NSObject).description + result += e.description } return result } From a68d75da69881b2fe2ccdacacef2af8d7442833f Mon Sep 17 00:00:00 2001 From: Carlo Kok Date: Mon, 24 Jan 2022 20:32:12 +0100 Subject: [PATCH 62/79] Tweak for new ToffeeV2 --- Source/NSArray_Extensions.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/NSArray_Extensions.swift b/Source/NSArray_Extensions.swift index 5581df4..306c3a6 100644 --- a/Source/NSArray_Extensions.swift +++ b/Source/NSArray_Extensions.swift @@ -1,4 +1,4 @@ -#if DARWIN +#if TOFFEE public extension NSArray { init(nativeArray: ObjectType[]) { From b5d6a0e0f4f2eea20b30acc06112aa858b7b5e18 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Wed, 9 Feb 2022 08:41:09 -0400 Subject: [PATCH 63/79] Internal: nullability fixes for Array and Dictionary --- Source/Array.swift | 2 +- Source/Dictionary.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Array.swift b/Source/Array.swift index 369c19a..83e11cd 100755 --- a/Source/Array.swift +++ b/Source/Array.swift @@ -675,7 +675,7 @@ public struct Array #endif } - private static func compareElements(_ r: T, _ l: T) -> Bool { + private static func compareElements(_ r: T?, _ l: T?) -> Bool { if l == nil { return r == nil } diff --git a/Source/Dictionary.swift b/Source/Dictionary.swift index 648f02c..e810e49 100755 --- a/Source/Dictionary.swift +++ b/Source/Dictionary.swift @@ -165,7 +165,7 @@ public struct Dictionary /*: INSFastEnumeration*/ } } for k in rhs.keys { - let l = lhs[k]! + let l = lhs[k] if l == nil { return false } From 162ab68ab7132d505e48b330c91ccebb3e9c1090 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Wed, 9 Feb 2022 09:03:03 -0400 Subject: [PATCH 64/79] Internal: nullability fixes for Array and Dictionary --- Source/Array.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Array.swift b/Source/Array.swift index 83e11cd..90f5cea 100755 --- a/Source/Array.swift +++ b/Source/Array.swift @@ -683,13 +683,13 @@ public struct Array return false } #if COOPER - return l.equals(r) + return l!.equals(r) #elseif ECHOES return System.Collections.Generic.EqualityComparer.Default.Equals(l, r) #elseif ISLAND return RemObjects.Elements.System.EqualityComparer.Equals(l, r) #elseif COCOA - return l.isEqual(r) + return l!.isEqual(r) #endif return true } From 1a638f1b6a2c9fc392df373383cb0e7bae46cf5e Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Wed, 9 Feb 2022 16:24:34 -0400 Subject: [PATCH 65/79] Tweaks for unconstrained generics --- Source/Array.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Array.swift b/Source/Array.swift index 90f5cea..3225260 100755 --- a/Source/Array.swift +++ b/Source/Array.swift @@ -701,7 +701,7 @@ public struct Array } #if DARWIN && ISLAND -public extension Array where T: NSObject { +public extension Array where T: CocoaObject { public static func __implicit(_ array: NSArray) -> [T] { return List(array) } From 4fc46b565dca1183c3732fe14b84f431561c7bce Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Thu, 10 Feb 2022 09:15:30 -0400 Subject: [PATCH 66/79] Tweaks for unconstrained generics --- Source/Functions.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Source/Functions.swift b/Source/Functions.swift index a234544..2bad358 100644 --- a/Source/Functions.swift +++ b/Source/Functions.swift @@ -63,7 +63,15 @@ public func debugPrint(_ objects: Object?..., separator: String = " ", terminato @discardableResult func dump(_ value: T, name: String? = nil, indent: Int = 2, maxDepth: Int = -1, maxItems: Int = -1) -> T { - debugPrint(value) + switch modelOf(T) { + case "Island": debugPrint((value as? IslandObject)?.ToString()) + case "Cocoa": debugPrint((value as? CocoaObject)?.description) + case "Swift": debugPrint((value as? SwiftObject)?.description) + case "Delphi": throw Exception("This feature is not supported for Delphi Objects (yet)"); + case "COM": throw Exception("This feature is not supported for COM Objects"); + case "JNI": throw Exception("This feature is not supported for JNI Objects"); + default: throw Exception("Unexpected object model \(modelOf(T))") + } return value } From 7418c932e869a2ed245843dbea35c7eef333b2e7 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Thu, 10 Feb 2022 09:25:41 -0400 Subject: [PATCH 67/79] Dropped bad NSObject alias on Island/Darwin --- Source/Aliases.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Source/Aliases.swift b/Source/Aliases.swift index 05a0c69..7eb7553 100644 --- a/Source/Aliases.swift +++ b/Source/Aliases.swift @@ -1,4 +1,8 @@ -public typealias NSObject = Object +#if DARWIN + public typealias NSObject = Foundation.Object +#else + public typealias NSObject = Object +#endif #if CLR || JAVA public typealias Int = Int64 From 30a4af357707f846e15654e5debfa90647e3b589 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Thu, 10 Feb 2022 10:49:21 -0400 Subject: [PATCH 68/79] Tweaks for unconstrained generics --- Source/Functions.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Source/Functions.swift b/Source/Functions.swift index 2bad358..37fd2c6 100644 --- a/Source/Functions.swift +++ b/Source/Functions.swift @@ -63,6 +63,7 @@ public func debugPrint(_ objects: Object?..., separator: String = " ", terminato @discardableResult func dump(_ value: T, name: String? = nil, indent: Int = 2, maxDepth: Int = -1, maxItems: Int = -1) -> T { + #if ISLAND switch modelOf(T) { case "Island": debugPrint((value as? IslandObject)?.ToString()) case "Cocoa": debugPrint((value as? CocoaObject)?.description) @@ -72,6 +73,9 @@ public func debugPrint(_ objects: Object?..., separator: String = " ", terminato case "JNI": throw Exception("This feature is not supported for JNI Objects"); default: throw Exception("Unexpected object model \(modelOf(T))") } + #else + debugPrint(value as? Object) + #endif return value } From 77a4f01804cad35f4a6090760f37b9ba17667411 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Thu, 10 Feb 2022 11:47:51 -0400 Subject: [PATCH 69/79] Tweaks for unconstrained generics --- Source/Functions.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Functions.swift b/Source/Functions.swift index 37fd2c6..73b8880 100644 --- a/Source/Functions.swift +++ b/Source/Functions.swift @@ -63,7 +63,7 @@ public func debugPrint(_ objects: Object?..., separator: String = " ", terminato @discardableResult func dump(_ value: T, name: String? = nil, indent: Int = 2, maxDepth: Int = -1, maxItems: Int = -1) -> T { - #if ISLAND + #if ISLAND && DARWIN switch modelOf(T) { case "Island": debugPrint((value as? IslandObject)?.ToString()) case "Cocoa": debugPrint((value as? CocoaObject)?.description) From 6e7a437ea25703659f96dfbc490283483b3f1791 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Thu, 10 Feb 2022 16:30:16 -0400 Subject: [PATCH 70/79] Tweaks for unconstrained generics (stropped extension for now, DONT SHIP!) --- Source/Array.swift | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/Source/Array.swift b/Source/Array.swift index 3225260..8fa1fe0 100755 --- a/Source/Array.swift +++ b/Source/Array.swift @@ -700,35 +700,35 @@ public struct Array } } -#if DARWIN && ISLAND -public extension Array where T: CocoaObject { - public static func __implicit(_ array: NSArray) -> [T] { - return List(array) - } +//#if DARWIN && ISLAND +//public extension Array where T: NSObject { + //public static func __implicit(_ array: NSArray) -> [T] { + //return List(array) + //} - public static func __implicit(_ array: [T]) -> NSArray { - return array.list.ToNSArray() - } + //public static func __implicit(_ array: [T]) -> NSArray { + //return array.list.ToNSArray() + //} - public static func __implicit(_ list: [T]) -> NSMutableArray { - return list.list.ToNSMutableArray() - } + //public static func __implicit(_ list: [T]) -> NSMutableArray { + //return list.list.ToNSMutableArray() + //} - // Cocoa only: cast from/to different generic Cocoa type + //// Cocoa only: cast from/to different generic Cocoa type - public static func __explicit(_ array: NSArray) -> [T] { - return (array as! NSArray) as! [T] - } + //public static func __explicit(_ array: NSArray) -> [T] { + //return (array as! NSArray) as! [T] + //} - public static func __explicit(_ array: [T]) -> NSArray { - return (array as! NSArray) as! NSArray - } + //public static func __explicit(_ array: [T]) -> NSArray { + //return (array as! NSArray) as! NSArray + //} - public static func __explicit(_ array: [T]) -> NSMutableArray { - return (array as! NSMutableArray) as! NSMutableArray - } -} -#endif + //public static func __explicit(_ array: [T]) -> NSMutableArray { + //return (array as! NSMutableArray) as! NSMutableArray + //} +//} +//#endif //#if !COCOA //public extension Swift.Array : ISequence { From 8b3e34d5ddf34d1b401867bb9d8833e84fbf8190 Mon Sep 17 00:00:00 2001 From: Carlo Kok Date: Wed, 16 Feb 2022 15:22:21 +0100 Subject: [PATCH 71/79] E25684: Swift: constrained extension for an unconstrained class makes whole class constrained (retry) --- Source/Array.swift | 12 ++++++++---- Source/Dictionary.swift | 6 +++--- Source/Functions.swift | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Source/Array.swift b/Source/Array.swift index 369c19a..95b6b70 100755 --- a/Source/Array.swift +++ b/Source/Array.swift @@ -152,8 +152,8 @@ public struct Array // Storage // - private var list: PlatformList - private var unique: Boolean = true + internal var list: PlatformList + internal var unique: Boolean = true private mutating func makeUnique() { @@ -701,9 +701,13 @@ public struct Array } #if DARWIN && ISLAND -public extension Array where T: NSObject { +public extension Swift.Array where T: NSObject { public static func __implicit(_ array: NSArray) -> [T] { - return List(array) + var result = [T](capacity: array.count) + for i in 0 ... array.count { + result.append(array[i]) + } + return result } public static func __implicit(_ array: [T]) -> NSArray { diff --git a/Source/Dictionary.swift b/Source/Dictionary.swift index 648f02c..7afc930 100755 --- a/Source/Dictionary.swift +++ b/Source/Dictionary.swift @@ -79,8 +79,8 @@ public struct Dictionary /*: INSFastEnumeration*/ // Storage // - private var dictionary: PlatformDictionary - private var unique: Boolean = true + internal var dictionary: PlatformDictionary + internal var unique: Boolean = true private mutating func makeUnique() { @@ -364,7 +364,7 @@ public struct Dictionary /*: INSFastEnumeration*/ } #if DARWIN && ISLAND -public extension Dictionary where Key: NSObject, Value: NSObject { +public extension Swift.Dictionary where Key: NSObject, Value: NSObject { public static func __implicit(_ dictionary: NSDictionary) -> [Key:Value] { return PlatformDictionary(dictionary) } diff --git a/Source/Functions.swift b/Source/Functions.swift index a234544..01e2a4a 100644 --- a/Source/Functions.swift +++ b/Source/Functions.swift @@ -63,7 +63,7 @@ public func debugPrint(_ objects: Object?..., separator: String = " ", terminato @discardableResult func dump(_ value: T, name: String? = nil, indent: Int = 2, maxDepth: Int = -1, maxItems: Int = -1) -> T { - debugPrint(value) + debugPrint(value as! Object) return value } From 097204d24da290e4bd0f4aad7d054870e2d751c9 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Thu, 17 Feb 2022 16:02:00 -0400 Subject: [PATCH 72/79] Fix for Arreay.joined --- Source/Array.swift | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Source/Array.swift b/Source/Array.swift index 8fa1fe0..60d5d8d 100755 --- a/Source/Array.swift +++ b/Source/Array.swift @@ -612,7 +612,19 @@ public struct Array if i != 0, let separator = separator { result.Append(separator) } + #if ISLAND + switch modelOf(T) { + case "Island": result.Append((self[i] as? IslandObject)?.ToString()) + case "Cocoa": result.Append(self[i]?.description) + case "Swift": result.Append(self[i]?.description) + case "Delphi": throw Exception("This feature is not supported for Delphi Objects (yet)"); + case "COM": throw Exception("This feature is not supported for COM Objects"); + case "JNI": throw Exception("This feature is not supported for JNI Objects"); + default: throw Exception("Unexpected object model \(modelOf(T))") + } + #else result.Append(self[i]?.ToString()) + #endif } return result.ToString()! #elseif COCOA From a48324a44325b49b6f99444bf544b8efce5b4039 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Fri, 18 Feb 2022 09:12:27 -0400 Subject: [PATCH 73/79] Added back extensions for Swift.Array on Darwin --- Source/Array.swift | 56 +++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/Source/Array.swift b/Source/Array.swift index 063bae2..d4c61d6 100755 --- a/Source/Array.swift +++ b/Source/Array.swift @@ -712,39 +712,39 @@ public struct Array } } - //#if DARWIN && ISLAND - //public extension Swift.Array where T: NSObject { - // public static func __implicit(_ array: NSArray) -> [T] { - // var result = [T](capacity: array.count) - // for i in 0 ... array.count { - // result.append(array[i]) - // } - // return result - // } - - //public static func __implicit(_ array: [T]) -> NSArray { - //return array.list.ToNSArray() - //} +#if DARWIN && ISLAND +public extension Swift.Array where T: NSObject { + public static func __implicit(_ array: NSArray) -> [T] { + var result = [T](capacity: array.count) + for i in 0 ... array.count { + result.append(array[i]) + } + return result + } - //public static func __implicit(_ list: [T]) -> NSMutableArray { - //return list.list.ToNSMutableArray() - //} + public static func __implicit(_ array: [T]) -> NSArray { + return array.list.ToNSArray() + } - //// Cocoa only: cast from/to different generic Cocoa type + public static func __implicit(_ list: [T]) -> NSMutableArray { + return list.list.ToNSMutableArray() + } - //public static func __explicit(_ array: NSArray) -> [T] { - //return (array as! NSArray) as! [T] - //} + // Cocoa only: cast from/to different generic Cocoa type - //public static func __explicit(_ array: [T]) -> NSArray { - //return (array as! NSArray) as! NSArray - //} + public static func __explicit(_ array: NSArray) -> [T] { + return (array as! NSArray) as! [T] + } - //public static func __explicit(_ array: [T]) -> NSMutableArray { - //return (array as! NSMutableArray) as! NSMutableArray - //} -//} -//#endif + public static func __explicit(_ array: [T]) -> NSArray { + return (array as! NSArray) as! NSArray + } + + public static func __explicit(_ array: [T]) -> NSMutableArray { + return (array as! NSMutableArray) as! NSMutableArray + } +} +#endif //#if !COCOA //public extension Swift.Array : ISequence { From 28b370378644c64c27e95141d140e41330aa95cd Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Fri, 18 Feb 2022 09:12:54 -0400 Subject: [PATCH 74/79] Project fix --- Source/Swift.Island.Android.elements | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/Swift.Island.Android.elements b/Source/Swift.Island.Android.elements index 1f76656..e09d403 100644 --- a/Source/Swift.Island.Android.elements +++ b/Source/Swift.Island.Android.elements @@ -50,7 +50,6 @@ - From 45824e25c8a3fa3a40885527de8f6f3c1bc7be47 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Wed, 20 Jul 2022 11:49:43 -0400 Subject: [PATCH 75/79] SwiftString.Hashable --- Source/String.swift | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/Source/String.swift b/Source/String.swift index 0e94aab..7a072fe 100644 --- a/Source/String.swift +++ b/Source/String.swift @@ -14,7 +14,7 @@ public typealias NativeString = Foundation.NSString //public typealias String = SwiftString //@assembly:DefaultStringType("Swift", typeOf(Swift.SwiftString)) -public struct SwiftString /*: Streamable*/ { +public struct SwiftString : Hashable /*, Equatable: Streamable*/ { typealias Index = Int @@ -164,6 +164,24 @@ public struct SwiftString /*: Streamable*/ { return stringA.nativeStringValue+stringB.nativeStringValue } + // + // Protoools + // + + var hashValue: Int { + #if JAVA + return nativeStringValue.hashCode() + #elseif CLR || ISLAND + return nativeStringValue.GetHashCode() + #elseif COCOA + return nativeStringValue.hashValue() + #endif + } + + func ==(lhs: Self, rhs: Self) -> Bool { + return lhs.nativeStringValue == lhs.nativeStringValue + } + // // Properties // @@ -188,16 +206,6 @@ public struct SwiftString /*: Streamable*/ { var fastestEncoding: SwiftString.Encoding { return SwiftString.Encoding.utf16 } - public var hashValue: Int { - #if JAVA - return nativeStringValue.hashCode() - #elseif CLR || ISLAND - return nativeStringValue.GetHashCode() - #elseif COCOA - return nativeStringValue.hashValue() - #endif - } - public var isEmpty : Bool { #if JAVA return nativeStringValue.isEmpty() From 1e930321022cb01b7e0789786d59d44e8db1aa68 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Wed, 20 Jul 2022 12:18:04 -0400 Subject: [PATCH 76/79] Prepwork for enabling SwiftString --- Source/Array.swift | 9 +++++++- Source/Dictionary.swift | 2 +- Source/Set.swift | 2 +- Source/String.swift | 42 +++++++++++++++------------------- Source/String_Extensions.swift | 2 +- 5 files changed, 30 insertions(+), 27 deletions(-) diff --git a/Source/Array.swift b/Source/Array.swift index d4c61d6..43c4d7d 100755 --- a/Source/Array.swift +++ b/Source/Array.swift @@ -707,11 +707,18 @@ public struct Array } @ToString - public override func description() -> String { + public override func description() -> NativeString { return list.description } } +//public extension Swift.Array where T: String { + //public convenience init(_ items: [NativeString]) { + //self.list = items.map({ $0 as! String }).ToList() + //self.unique = true + //} +//} + #if DARWIN && ISLAND public extension Swift.Array where T: NSObject { public static func __implicit(_ array: NSArray) -> [T] { diff --git a/Source/Dictionary.swift b/Source/Dictionary.swift index 15bb71e..903d76c 100755 --- a/Source/Dictionary.swift +++ b/Source/Dictionary.swift @@ -358,7 +358,7 @@ public struct Dictionary /*: INSFastEnumeration*/ } @ToString - public override func description() -> String { + public override func description() -> NativeString { return dictionary.description } } diff --git a/Source/Set.swift b/Source/Set.swift index 50dd292..6a16154 100644 --- a/Source/Set.swift +++ b/Source/Set.swift @@ -475,7 +475,7 @@ public struct Set //: //var hashValue: Int { get } /// A textual representation of `self`. - @ToString public func description() -> String { + @ToString public func description() -> NativeString { #if JAVA return _set.toString() #elseif CLR || ISLAND diff --git a/Source/String.swift b/Source/String.swift index 7a072fe..6917327 100644 --- a/Source/String.swift +++ b/Source/String.swift @@ -71,29 +71,9 @@ public struct SwiftString : Hashable /*, Equatable: Streamable*/ { } } - //76037: Silver: compiler gets confused with overloaded ctors - #if !ECHOES - /*public convenience init(reflecting subject: Object) { - var subject = subject - if let o = subject as? ICustomDebugStringConvertible { - subject = o.debugDescription - } else { - #if JAVA - // ToDo: fall back to reflection to call debugDescription? - // ToDo: fall back to checking for extension methods - #elseif CLR - // ToDo: fall back to reflection to call debugDescription? - // ToDo: fall back to checking for extension methods - #elseif COCOA - if subject.respondsToSelector(#selector(debugDescription)) { - subject = subject.debugDescription - } - // ToDo: fall back to checking for extension methods - #endif - } - init(subject) - }*/ - #endif + public convenience init(reflecting subject: Object) { + nativeStringValue = NativeString(reflecting: subject) + } #if COCOA init/*?*/ (cString: UnsafePointer, encoding: SwiftString.Encoding) { @@ -160,6 +140,18 @@ public struct SwiftString : Hashable /*, Equatable: Streamable*/ { return string.nativeStringValue } + public static func __implicit(_ char: Char) -> SwiftString { + return SwiftString(char.ToString()) + } + + public static class func __implicit(_ string: SwiftString) -> Char { + if length(string.nativeStringValue) == 1 { + return string.nativeStringValue[0] + } else { + throw InvalidCastException("Cannto cast non-single-character string '\(string.nativeStringValue)' to Char") + } + } + public class func + (_ stringA: SwiftString, _ stringB: SwiftString) -> NativeString { return stringA.nativeStringValue+stringB.nativeStringValue } @@ -357,6 +349,10 @@ public struct SwiftString : Hashable /*, Equatable: Streamable*/ { //public subscript(range: SwiftString.Index) -> Character // implicitly provided by the compiler, already + public subscript(index: Int) -> Char { + return nativeStringValue[index] + } + public subscript(range: Range/**/) -> SwiftString { if range.upperBound != nil { #if JAVA diff --git a/Source/String_Extensions.swift b/Source/String_Extensions.swift index b9516f0..7e20dec 100644 --- a/Source/String_Extensions.swift +++ b/Source/String_Extensions.swift @@ -108,7 +108,7 @@ #if JAVA return self.isEmpty() #elseif CLR || ISLAND - return String.IsNullOrEmpty(self) + return NativeString.IsNullOrEmpty(self) #elseif COCOA return length == 0 #endif From 2d169210db6c214c4e3674bde4c9fef279f0108f Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Wed, 20 Jul 2022 12:23:59 -0400 Subject: [PATCH 77/79] Prepwork for enabling SwiftString --- Source/String.swift | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Source/String.swift b/Source/String.swift index 6917327..45ef189 100644 --- a/Source/String.swift +++ b/Source/String.swift @@ -141,14 +141,24 @@ public struct SwiftString : Hashable /*, Equatable: Streamable*/ { } public static func __implicit(_ char: Char) -> SwiftString { + #if TOFFEE + return NSString.string(format: "%c", char) + #else return SwiftString(char.ToString()) + #endif } public static class func __implicit(_ string: SwiftString) -> Char { if length(string.nativeStringValue) == 1 { return string.nativeStringValue[0] } else { - throw InvalidCastException("Cannto cast non-single-character string '\(string.nativeStringValue)' to Char") + #if ECHOES || ISLAND + throw InvalidCastException("Cannot cast non-single-character string '\(string.nativeStringValue)' to Char") + #elseif COOPER + throw ClassCastException("Cannto cast non-single-character string '\(string.nativeStringValue)' to Char") + #else + throw Exception("Cannto cast non-single-character string '\(string.nativeStringValue)' to Char") + #endif } } From 213f2290c11f3f7a103a58525c8fffec27c0fb2a Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Mon, 26 Jun 2023 15:07:56 -0400 Subject: [PATCH 78/79] visionOS Support --- Source/Silver.elements | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Source/Silver.elements b/Source/Silver.elements index cf7a334..68efbeb 100644 --- a/Source/Silver.elements +++ b/Source/Silver.elements @@ -70,6 +70,13 @@ 9.0 Foundation;RemObjects.Elements.System;rtl + + Island + Darwin + visionOS + 1.0 + Foundation;RemObjects.Elements.System;rtl + Island Darwin @@ -102,6 +109,11 @@ tvOS Foundation;RemObjects.Elements.Linq + + Toffee + visionOS + Foundation;RemObjects.Elements.Linq + Toffee watchOS From b52b882dd115eb6298ecaf4a161a03083280f4b5 Mon Sep 17 00:00:00 2001 From: marc hoffman Date: Mon, 26 Jun 2023 15:10:37 -0400 Subject: [PATCH 79/79] visionOS Support --- Source/Silver.elements | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/Silver.elements b/Source/Silver.elements index 68efbeb..7932957 100644 --- a/Source/Silver.elements +++ b/Source/Silver.elements @@ -107,11 +107,13 @@ Toffee tvOS + 9.0 Foundation;RemObjects.Elements.Linq Toffee visionOS + 1.0 Foundation;RemObjects.Elements.Linq