Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 8 additions & 56 deletions Benchmarks/Sources/Generated/BridgeJS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1565,16 +1565,7 @@ public func _bjs_ArrayRoundtrip_makePointArrayLarge(_ _self: UnsafeMutableRawPoi
@_cdecl("bjs_ArrayRoundtrip_takeNestedIntArray")
public func _bjs_ArrayRoundtrip_takeNestedIntArray(_ _self: UnsafeMutableRawPointer) -> Void {
#if arch(wasm32)
ArrayRoundtrip.bridgeJSLiftParameter(_self).takeNestedIntArray(_: {
let __count = Int(_swift_js_pop_i32())
var __result: [[Int]] = []
__result.reserveCapacity(__count)
for _ in 0..<__count {
__result.append([Int].bridgeJSLiftParameter())
}
__result.reverse()
return __result
}())
ArrayRoundtrip.bridgeJSLiftParameter(_self).takeNestedIntArray(_: [[Int]].bridgeJSLiftParameter())
#else
fatalError("Only available on WebAssembly")
#endif
Expand All @@ -1585,10 +1576,7 @@ public func _bjs_ArrayRoundtrip_takeNestedIntArray(_ _self: UnsafeMutableRawPoin
public func _bjs_ArrayRoundtrip_makeNestedIntArray(_ _self: UnsafeMutableRawPointer) -> Void {
#if arch(wasm32)
let ret = ArrayRoundtrip.bridgeJSLiftParameter(_self).makeNestedIntArray()
for __bjs_elem_ret in ret {
__bjs_elem_ret.bridgeJSLowerReturn()
}
_swift_js_push_i32(Int32(ret.count))
ret.bridgeJSLowerReturn()
#else
fatalError("Only available on WebAssembly")
#endif
Expand All @@ -1598,20 +1586,8 @@ public func _bjs_ArrayRoundtrip_makeNestedIntArray(_ _self: UnsafeMutableRawPoin
@_cdecl("bjs_ArrayRoundtrip_roundtripNestedIntArray")
public func _bjs_ArrayRoundtrip_roundtripNestedIntArray(_ _self: UnsafeMutableRawPointer) -> Void {
#if arch(wasm32)
let ret = ArrayRoundtrip.bridgeJSLiftParameter(_self).roundtripNestedIntArray(_: {
let __count = Int(_swift_js_pop_i32())
var __result: [[Int]] = []
__result.reserveCapacity(__count)
for _ in 0..<__count {
__result.append([Int].bridgeJSLiftParameter())
}
__result.reverse()
return __result
}())
for __bjs_elem_ret in ret {
__bjs_elem_ret.bridgeJSLowerReturn()
}
_swift_js_push_i32(Int32(ret.count))
let ret = ArrayRoundtrip.bridgeJSLiftParameter(_self).roundtripNestedIntArray(_: [[Int]].bridgeJSLiftParameter())
ret.bridgeJSLowerReturn()
#else
fatalError("Only available on WebAssembly")
#endif
Expand All @@ -1621,16 +1597,7 @@ public func _bjs_ArrayRoundtrip_roundtripNestedIntArray(_ _self: UnsafeMutableRa
@_cdecl("bjs_ArrayRoundtrip_takeNestedPointArray")
public func _bjs_ArrayRoundtrip_takeNestedPointArray(_ _self: UnsafeMutableRawPointer) -> Void {
#if arch(wasm32)
ArrayRoundtrip.bridgeJSLiftParameter(_self).takeNestedPointArray(_: {
let __count = Int(_swift_js_pop_i32())
var __result: [[Point]] = []
__result.reserveCapacity(__count)
for _ in 0..<__count {
__result.append([Point].bridgeJSLiftParameter())
}
__result.reverse()
return __result
}())
ArrayRoundtrip.bridgeJSLiftParameter(_self).takeNestedPointArray(_: [[Point]].bridgeJSLiftParameter())
#else
fatalError("Only available on WebAssembly")
#endif
Expand All @@ -1641,10 +1608,7 @@ public func _bjs_ArrayRoundtrip_takeNestedPointArray(_ _self: UnsafeMutableRawPo
public func _bjs_ArrayRoundtrip_makeNestedPointArray(_ _self: UnsafeMutableRawPointer) -> Void {
#if arch(wasm32)
let ret = ArrayRoundtrip.bridgeJSLiftParameter(_self).makeNestedPointArray()
for __bjs_elem_ret in ret {
__bjs_elem_ret.bridgeJSLowerReturn()
}
_swift_js_push_i32(Int32(ret.count))
ret.bridgeJSLowerReturn()
#else
fatalError("Only available on WebAssembly")
#endif
Expand All @@ -1654,20 +1618,8 @@ public func _bjs_ArrayRoundtrip_makeNestedPointArray(_ _self: UnsafeMutableRawPo
@_cdecl("bjs_ArrayRoundtrip_roundtripNestedPointArray")
public func _bjs_ArrayRoundtrip_roundtripNestedPointArray(_ _self: UnsafeMutableRawPointer) -> Void {
#if arch(wasm32)
let ret = ArrayRoundtrip.bridgeJSLiftParameter(_self).roundtripNestedPointArray(_: {
let __count = Int(_swift_js_pop_i32())
var __result: [[Point]] = []
__result.reserveCapacity(__count)
for _ in 0..<__count {
__result.append([Point].bridgeJSLiftParameter())
}
__result.reverse()
return __result
}())
for __bjs_elem_ret in ret {
__bjs_elem_ret.bridgeJSLowerReturn()
}
_swift_js_push_i32(Int32(ret.count))
let ret = ArrayRoundtrip.bridgeJSLiftParameter(_self).roundtripNestedPointArray(_: [[Point]].bridgeJSLiftParameter())
ret.bridgeJSLowerReturn()
#else
fatalError("Only available on WebAssembly")
#endif
Expand Down
40 changes: 16 additions & 24 deletions Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -838,18 +838,16 @@ struct StackCodegen {

func liftArrayExpression(elementType: BridgeType) -> ExprSyntax {
switch elementType {
case .int, .uint, .float, .double, .string, .bool, .jsValue,
.jsObject(nil), .swiftStruct, .caseEnum, .swiftHeapObject,
.unsafePointer, .rawValueEnum, .associatedValueEnum:
return "[\(raw: elementType.swiftType)].bridgeJSLiftParameter()"
case .jsObject(_?):
case .jsObject(let className?) where className != "JSObject":
return liftArrayExpressionInline(elementType: elementType)
case .swiftProtocol(let protocolName):
return "[Any\(raw: protocolName)].bridgeJSLiftParameter()"
case .nullable, .array, .closure, .dictionary:
case .nullable, .closure:
return liftArrayExpressionInline(elementType: elementType)
case .void, .namespaceEnum:
fatalError("Invalid array element type: \(elementType)")
default:
return "[\(raw: elementType.swiftType)].bridgeJSLiftParameter()"
}
}

Expand All @@ -872,11 +870,7 @@ struct StackCodegen {

func liftDictionaryExpression(valueType: BridgeType) -> ExprSyntax {
switch valueType {
case .int, .uint, .float, .double, .string, .bool, .jsValue,
.jsObject(nil), .swiftStruct, .caseEnum, .swiftHeapObject,
.unsafePointer, .rawValueEnum, .associatedValueEnum:
return "[String: \(raw: valueType.swiftType)].bridgeJSLiftParameter()"
case .jsObject(let className?):
case .jsObject(let className?) where className != "JSObject":
return """
{
let __dict = [String: JSObject].bridgeJSLiftParameter()
Expand All @@ -890,10 +884,12 @@ struct StackCodegen {
return __dict.mapValues { $0 as! Any\(raw: protocolName) }
}()
"""
case .nullable, .array, .dictionary, .closure:
case .nullable, .closure:
return liftDictionaryExpressionInline(valueType: valueType)
case .void, .namespaceEnum:
fatalError("Invalid dictionary value type: \(valueType)")
default:
return "[String: \(raw: valueType.swiftType)].bridgeJSLiftParameter()"
}
}

Expand Down Expand Up @@ -1005,22 +1001,20 @@ struct StackCodegen {
varPrefix: String
) -> [CodeBlockItemSyntax] {
switch elementType {
case .int, .uint, .float, .double, .string, .bool, .jsValue,
.jsObject(nil), .swiftStruct, .caseEnum, .swiftHeapObject,
.unsafePointer, .rawValueEnum, .associatedValueEnum:
return ["\(raw: accessor).bridgeJSLowerReturn()"]
case .jsObject(_?):
case .jsObject(let className?) where className != "JSObject":
return ["\(raw: accessor).map { $0.jsObject }.bridgeJSLowerReturn()"]
case .swiftProtocol(let protocolName):
return ["\(raw: accessor).map { $0 as! Any\(raw: protocolName) }.bridgeJSLowerReturn()"]
case .nullable, .array, .closure, .dictionary:
case .nullable, .closure:
return lowerArrayStatementsInline(
elementType: elementType,
accessor: accessor,
varPrefix: varPrefix
)
case .void, .namespaceEnum:
fatalError("Invalid array element type: \(elementType)")
default:
return ["\(raw: accessor).bridgeJSLowerReturn()"]
}
}

Expand Down Expand Up @@ -1054,22 +1048,20 @@ struct StackCodegen {
varPrefix: String
) -> [CodeBlockItemSyntax] {
switch valueType {
case .int, .uint, .float, .double, .string, .bool, .jsValue,
.jsObject(nil), .swiftStruct, .caseEnum, .swiftHeapObject,
.unsafePointer, .rawValueEnum, .associatedValueEnum:
return ["\(raw: accessor).bridgeJSLowerReturn()"]
case .jsObject(_?):
case .jsObject(let className?) where className != "JSObject":
return ["\(raw: accessor).mapValues { $0.jsObject }.bridgeJSLowerReturn()"]
case .swiftProtocol(let protocolName):
return ["\(raw: accessor).mapValues { $0 as! Any\(raw: protocolName) }.bridgeJSLowerReturn()"]
case .nullable, .array, .dictionary, .closure:
case .nullable, .closure:
return lowerDictionaryStatementsInline(
valueType: valueType,
accessor: accessor,
varPrefix: varPrefix
)
case .void, .namespaceEnum:
fatalError("Invalid dictionary value type: \(valueType)")
default:
return ["\(raw: accessor).bridgeJSLowerReturn()"]
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,20 +381,8 @@ public func _bjs_processOptionalStatusArray() -> Void {
@_cdecl("bjs_processNestedIntArray")
public func _bjs_processNestedIntArray() -> Void {
#if arch(wasm32)
let ret = processNestedIntArray(_: {
let __count = Int(_swift_js_pop_i32())
var __result: [[Int]] = []
__result.reserveCapacity(__count)
for _ in 0..<__count {
__result.append([Int].bridgeJSLiftParameter())
}
__result.reverse()
return __result
}())
for __bjs_elem_ret in ret {
__bjs_elem_ret.bridgeJSLowerReturn()
}
_swift_js_push_i32(Int32(ret.count))
let ret = processNestedIntArray(_: [[Int]].bridgeJSLiftParameter())
ret.bridgeJSLowerReturn()
#else
fatalError("Only available on WebAssembly")
#endif
Expand All @@ -404,20 +392,8 @@ public func _bjs_processNestedIntArray() -> Void {
@_cdecl("bjs_processNestedStringArray")
public func _bjs_processNestedStringArray() -> Void {
#if arch(wasm32)
let ret = processNestedStringArray(_: {
let __count = Int(_swift_js_pop_i32())
var __result: [[String]] = []
__result.reserveCapacity(__count)
for _ in 0..<__count {
__result.append([String].bridgeJSLiftParameter())
}
__result.reverse()
return __result
}())
for __bjs_elem_ret in ret {
__bjs_elem_ret.bridgeJSLowerReturn()
}
_swift_js_push_i32(Int32(ret.count))
let ret = processNestedStringArray(_: [[String]].bridgeJSLiftParameter())
ret.bridgeJSLowerReturn()
#else
fatalError("Only available on WebAssembly")
#endif
Expand All @@ -427,20 +403,8 @@ public func _bjs_processNestedStringArray() -> Void {
@_cdecl("bjs_processNestedPointArray")
public func _bjs_processNestedPointArray() -> Void {
#if arch(wasm32)
let ret = processNestedPointArray(_: {
let __count = Int(_swift_js_pop_i32())
var __result: [[Point]] = []
__result.reserveCapacity(__count)
for _ in 0..<__count {
__result.append([Point].bridgeJSLiftParameter())
}
__result.reverse()
return __result
}())
for __bjs_elem_ret in ret {
__bjs_elem_ret.bridgeJSLowerReturn()
}
_swift_js_push_i32(Int32(ret.count))
let ret = processNestedPointArray(_: [[Point]].bridgeJSLiftParameter())
ret.bridgeJSLowerReturn()
#else
fatalError("Only available on WebAssembly")
#endif
Expand All @@ -461,20 +425,8 @@ public func _bjs_processItemArray() -> Void {
@_cdecl("bjs_processNestedItemArray")
public func _bjs_processNestedItemArray() -> Void {
#if arch(wasm32)
let ret = processNestedItemArray(_: {
let __count = Int(_swift_js_pop_i32())
var __result: [[Item]] = []
__result.reserveCapacity(__count)
for _ in 0..<__count {
__result.append([Item].bridgeJSLiftParameter())
}
__result.reverse()
return __result
}())
for __bjs_elem_ret in ret {
__bjs_elem_ret.bridgeJSLowerReturn()
}
_swift_js_push_i32(Int32(ret.count))
let ret = processNestedItemArray(_: [[Item]].bridgeJSLiftParameter())
ret.bridgeJSLowerReturn()
#else
fatalError("Only available on WebAssembly")
#endif
Expand Down Expand Up @@ -522,20 +474,8 @@ public func _bjs_processOptionalJSObjectArray() -> Void {
@_cdecl("bjs_processNestedJSObjectArray")
public func _bjs_processNestedJSObjectArray() -> Void {
#if arch(wasm32)
let ret = processNestedJSObjectArray(_: {
let __count = Int(_swift_js_pop_i32())
var __result: [[JSObject]] = []
__result.reserveCapacity(__count)
for _ in 0..<__count {
__result.append([JSObject].bridgeJSLiftParameter())
}
__result.reverse()
return __result
}())
for __bjs_elem_ret in ret {
__bjs_elem_ret.bridgeJSLowerReturn()
}
_swift_js_push_i32(Int32(ret.count))
let ret = processNestedJSObjectArray(_: [[JSObject]].bridgeJSLiftParameter())
ret.bridgeJSLowerReturn()
#else
fatalError("Only available on WebAssembly")
#endif
Expand Down
Loading