forked from swiftwasm/JavaScriptKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStaticFunctions.swift
More file actions
210 lines (192 loc) · 6.85 KB
/
Copy pathStaticFunctions.swift
File metadata and controls
210 lines (192 loc) · 6.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
extension Calculator: _BridgedSwiftCaseEnum {
@_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 {
return bridgeJSRawValue
}
@_spi(BridgeJS) @_transparent public static func bridgeJSLiftReturn(_ value: Int32) -> Calculator {
return bridgeJSLiftParameter(value)
}
@_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter(_ value: Int32) -> Calculator {
return Calculator(bridgeJSRawValue: value)!
}
@_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() -> Int32 {
return bridgeJSLowerParameter()
}
@_spi(BridgeJS) @usableFromInline init?(bridgeJSRawValue: Int32) {
switch bridgeJSRawValue {
case 0:
self = .scientific
case 1:
self = .basic
default:
return nil
}
}
@_spi(BridgeJS) @usableFromInline var bridgeJSRawValue: Int32 {
switch self {
case .scientific:
return 0
case .basic:
return 1
}
}
}
@_expose(wasm, "bjs_Calculator_static_square")
@_cdecl("bjs_Calculator_static_square")
public func _bjs_Calculator_static_square(_ value: Int32) -> Int32 {
#if arch(wasm32)
let ret = Calculator.square(value: Int.bridgeJSLiftParameter(value))
return ret.bridgeJSLowerReturn()
#else
fatalError("Only available on WebAssembly")
#endif
}
@_expose(wasm, "bjs_Calculator_static_cube")
@_cdecl("bjs_Calculator_static_cube")
public func _bjs_Calculator_static_cube(_ value: Int32) -> Int32 {
#if arch(wasm32)
let ret = Calculator.cube(value: Int.bridgeJSLiftParameter(value))
return ret.bridgeJSLowerReturn()
#else
fatalError("Only available on WebAssembly")
#endif
}
@_expose(wasm, "bjs_Calculator_static_version_get")
@_cdecl("bjs_Calculator_static_version_get")
public func _bjs_Calculator_static_version_get() -> Void {
#if arch(wasm32)
let ret = Calculator.version
return ret.bridgeJSLowerReturn()
#else
fatalError("Only available on WebAssembly")
#endif
}
extension APIResult: _BridgedSwiftAssociatedValueEnum {
@_spi(BridgeJS) @_transparent public static func bridgeJSStackPopPayload(_ caseId: Int32) -> APIResult {
switch caseId {
case 0:
return .success(String.bridgeJSStackPop())
case 1:
return .failure(Int.bridgeJSStackPop())
default:
fatalError("Unknown APIResult case ID: \(caseId)")
}
}
@_spi(BridgeJS) @_transparent public consuming func bridgeJSStackPushPayload() -> Int32 {
switch self {
case .success(let param0):
param0.bridgeJSStackPush()
return Int32(0)
case .failure(let param0):
param0.bridgeJSStackPush()
return Int32(1)
}
}
}
@_expose(wasm, "bjs_APIResult_static_roundtrip")
@_cdecl("bjs_APIResult_static_roundtrip")
public func _bjs_APIResult_static_roundtrip(_ value: Int32) -> Void {
#if arch(wasm32)
let ret = APIResult.roundtrip(value: APIResult.bridgeJSLiftParameter(value))
return ret.bridgeJSLowerReturn()
#else
fatalError("Only available on WebAssembly")
#endif
}
@_expose(wasm, "bjs_Utils_String_static_uppercase")
@_cdecl("bjs_Utils_String_static_uppercase")
public func _bjs_Utils_String_static_uppercase(_ textBytes: Int32, _ textLength: Int32) -> Void {
#if arch(wasm32)
let ret = Utils.String.uppercase(_: String.bridgeJSLiftParameter(textBytes, textLength))
return ret.bridgeJSLowerReturn()
#else
fatalError("Only available on WebAssembly")
#endif
}
@_expose(wasm, "bjs_MathUtils_init")
@_cdecl("bjs_MathUtils_init")
public func _bjs_MathUtils_init() -> UnsafeMutableRawPointer {
#if arch(wasm32)
let ret = MathUtils()
return ret.bridgeJSLowerReturn()
#else
fatalError("Only available on WebAssembly")
#endif
}
@_expose(wasm, "bjs_MathUtils_static_subtract")
@_cdecl("bjs_MathUtils_static_subtract")
public func _bjs_MathUtils_static_subtract(_ a: Int32, _ b: Int32) -> Int32 {
#if arch(wasm32)
let ret = MathUtils.subtract(a: Int.bridgeJSLiftParameter(a), b: Int.bridgeJSLiftParameter(b))
return ret.bridgeJSLowerReturn()
#else
fatalError("Only available on WebAssembly")
#endif
}
@_expose(wasm, "bjs_MathUtils_static_add")
@_cdecl("bjs_MathUtils_static_add")
public func _bjs_MathUtils_static_add(_ a: Int32, _ b: Int32) -> Int32 {
#if arch(wasm32)
let ret = MathUtils.add(a: Int.bridgeJSLiftParameter(a), b: Int.bridgeJSLiftParameter(b))
return ret.bridgeJSLowerReturn()
#else
fatalError("Only available on WebAssembly")
#endif
}
@_expose(wasm, "bjs_MathUtils_multiply")
@_cdecl("bjs_MathUtils_multiply")
public func _bjs_MathUtils_multiply(_ _self: UnsafeMutableRawPointer, _ x: Int32, _ y: Int32) -> Int32 {
#if arch(wasm32)
let ret = MathUtils.bridgeJSLiftParameter(_self).multiply(x: Int.bridgeJSLiftParameter(x), y: Int.bridgeJSLiftParameter(y))
return ret.bridgeJSLowerReturn()
#else
fatalError("Only available on WebAssembly")
#endif
}
@_expose(wasm, "bjs_MathUtils_static_divide")
@_cdecl("bjs_MathUtils_static_divide")
public func _bjs_MathUtils_static_divide(_ a: Int32, _ b: Int32) -> Int32 {
#if arch(wasm32)
let ret = MathUtils.divide(a: Int.bridgeJSLiftParameter(a), b: Int.bridgeJSLiftParameter(b))
return ret.bridgeJSLowerReturn()
#else
fatalError("Only available on WebAssembly")
#endif
}
@_expose(wasm, "bjs_MathUtils_static_pi_get")
@_cdecl("bjs_MathUtils_static_pi_get")
public func _bjs_MathUtils_static_pi_get() -> Float64 {
#if arch(wasm32)
let ret = MathUtils.pi
return ret.bridgeJSLowerReturn()
#else
fatalError("Only available on WebAssembly")
#endif
}
@_expose(wasm, "bjs_MathUtils_deinit")
@_cdecl("bjs_MathUtils_deinit")
public func _bjs_MathUtils_deinit(_ pointer: UnsafeMutableRawPointer) -> Void {
#if arch(wasm32)
Unmanaged<MathUtils>.fromOpaque(pointer).release()
#else
fatalError("Only available on WebAssembly")
#endif
}
extension MathUtils: ConvertibleToJSValue, _BridgedSwiftHeapObject, _BridgedSwiftProtocolExportable {
var jsValue: JSValue {
return .object(JSObject(id: UInt32(bitPattern: _bjs_MathUtils_wrap(Unmanaged.passRetained(self).toOpaque()))))
}
consuming func bridgeJSLowerAsProtocolReturn() -> Int32 {
_bjs_MathUtils_wrap(Unmanaged.passRetained(self).toOpaque())
}
}
#if arch(wasm32)
@_extern(wasm, module: "TestModule", name: "bjs_MathUtils_wrap")
fileprivate func _bjs_MathUtils_wrap_extern(_ pointer: UnsafeMutableRawPointer) -> Int32
#else
fileprivate func _bjs_MathUtils_wrap_extern(_ pointer: UnsafeMutableRawPointer) -> Int32 {
fatalError("Only available on WebAssembly")
}
#endif
@inline(never) fileprivate func _bjs_MathUtils_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 {
return _bjs_MathUtils_wrap_extern(pointer)
}