Skip to content

Commit 9660801

Browse files
committed
remove emdedded patches from app targets
1 parent 35001e7 commit 9660801

File tree

5 files changed

+123
-121
lines changed

5 files changed

+123
-121
lines changed

Examples/Basic/Sources/App/_thingsThatShouldNotBeNeeded.swift

Lines changed: 0 additions & 10 deletions
This file was deleted.

Examples/Swiftle/Sources/Swiftle/Game.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,11 @@ extension LetterGuess {
187187
}
188188
}
189189
}
190+
191+
extension String {
192+
// native string comparison would require unicode stuff
193+
@inline(__always)
194+
func utf8Equals(_ other: borrowing String) -> Bool {
195+
utf8.elementsEqual(other.utf8)
196+
}
197+
}

Examples/Swiftle/Sources/Swiftle/_thingsThatShouldNotBeNeeded.swift

Lines changed: 0 additions & 111 deletions
This file was deleted.

Sources/ElementaryDOM/Interop/Elementary+JavaScriptKit.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ final class JSKitDOMInteractor: DOM.Interactor {
2626

2727
init(root: JSObject) {
2828
self.root = .init(root)
29+
30+
#if hasFeature(Embedded)
31+
if __omg_this_was_annoying_I_am_false {
32+
// NOTE: this is just to force inclusion of some types that would otherwise crash the 6.2 compiler
33+
_ = JSClosure { _ in .undefined }
34+
}
35+
#endif
2936
}
3037

3138
func makeEventSink(_ handler: @escaping (String, DOM.Event) -> Void) -> DOM.EventSink {

Sources/ElementaryDOM/_embeddedTricks.swift

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,111 @@
33
#if hasFeature(Embedded)
44
internal var __omg_this_was_annoying_I_am_false: Bool = false
55
#endif
6+
7+
// FIXME: embedded - remove once https://github.com/swiftlang/swift/issues/83460 lands
8+
#if hasFeature(Embedded)
9+
@_silgen_name("swift_float64ToString")
10+
@_noAllocation
11+
public func _swift_float64ToString(
12+
_ buffer: UnsafeMutablePointer<UInt8>,
13+
_ bufferLength: UInt,
14+
_ value: Double,
15+
_ isDebug: Bool
16+
) -> UInt64 {
17+
var value = value
18+
var index = 0
19+
let maxIndex = Int(bufferLength) - 1
20+
21+
if value < 0 {
22+
if index > maxIndex { return 0 }
23+
buffer[index] = 45 // '-'
24+
index += 1
25+
value = -value
26+
}
27+
28+
let integerPart = Int(value)
29+
var temp = integerPart
30+
let start = index
31+
if temp == 0 {
32+
if index > maxIndex { return UInt64(index) }
33+
buffer[index] = 48 // '0'
34+
index += 1
35+
} else {
36+
while temp > 0 {
37+
if index > maxIndex { return UInt64(index) }
38+
let digit = UInt8(temp % 10) + 48 // ASCII '0' is 48
39+
buffer[index] = digit
40+
index += 1
41+
temp /= 10
42+
}
43+
// reverse the integer digits written in place
44+
var i = start
45+
var j = index - 1
46+
while i < j {
47+
let t = buffer[i]
48+
buffer[i] = buffer[j]
49+
buffer[j] = t
50+
i += 1
51+
j -= 1
52+
}
53+
}
54+
55+
let fractionalPart = value - Double(integerPart)
56+
if fractionalPart > 0 {
57+
if index > maxIndex { return UInt64(index) }
58+
buffer[index] = 46 // '.'
59+
index += 1
60+
61+
var remaining = fractionalPart
62+
var decimalPlaces = 0
63+
var hasNonZeroDigit = false
64+
65+
while decimalPlaces < 5 && index <= maxIndex {
66+
remaining *= 10
67+
let digit = Int(remaining)
68+
buffer[index] = UInt8(digit) + 48
69+
index += 1
70+
remaining -= Double(digit)
71+
decimalPlaces += 1
72+
if digit != 0 {
73+
hasNonZeroDigit = true
74+
}
75+
}
76+
77+
// Check if we need to round up
78+
if index <= maxIndex {
79+
remaining *= 10
80+
let nextDigit = Int(remaining)
81+
if nextDigit >= 5 {
82+
// Round up the last digit
83+
var i = index - 1
84+
while i >= 0 {
85+
if buffer[i] == 46 { // skip the decimal point
86+
i -= 1
87+
continue
88+
}
89+
if buffer[i] < 57 { // '9'
90+
buffer[i] += 1
91+
break
92+
} else {
93+
buffer[i] = 48 // '0'
94+
i -= 1
95+
}
96+
}
97+
}
98+
}
99+
100+
// Only remove trailing zeros if there are non-zero digits after the decimal point
101+
if hasNonZeroDigit {
102+
while index > 0 && buffer[index - 1] == 48 { // '0'
103+
index -= 1
104+
}
105+
if index > 0 && buffer[index - 1] == 46 { // '.'
106+
index -= 1
107+
}
108+
}
109+
}
110+
111+
return UInt64(index)
112+
}
113+
#endif

0 commit comments

Comments
 (0)