forked from swiftwasm/JavaScriptKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBridgeJSSkeleton.swift
More file actions
123 lines (101 loc) · 2.89 KB
/
BridgeJSSkeleton.swift
File metadata and controls
123 lines (101 loc) · 2.89 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
// This file is shared between BridgeTool and BridgeJSLink
// MARK: - Types
enum BridgeType: Codable, Equatable {
case int, float, double, string, bool, jsObject(String?), swiftHeapObject(String), void
}
enum WasmCoreType: String, Codable {
case i32, i64, f32, f64, pointer
}
struct Parameter: Codable {
let label: String?
let name: String
let type: BridgeType
}
struct Effects: Codable {
var isAsync: Bool
var isThrows: Bool
}
// MARK: - Exported Skeleton
struct ExportedFunction: Codable {
var name: String
var abiName: String
var parameters: [Parameter]
var returnType: BridgeType
var effects: Effects
var namespace: [String]?
}
struct ExportedClass: Codable {
var name: String
var constructor: ExportedConstructor?
var methods: [ExportedFunction]
var namespace: [String]?
}
struct ExportedConstructor: Codable {
var abiName: String
var parameters: [Parameter]
var effects: Effects
var namespace: [String]?
}
struct ExportedSkeleton: Codable {
let functions: [ExportedFunction]
let classes: [ExportedClass]
}
// MARK: - Imported Skeleton
struct ImportedFunctionSkeleton: Codable {
let name: String
let parameters: [Parameter]
let returnType: BridgeType
let documentation: String?
func abiName(context: ImportedTypeSkeleton?) -> String {
return context.map { "bjs_\($0.name)_\(name)" } ?? "bjs_\(name)"
}
}
struct ImportedConstructorSkeleton: Codable {
let parameters: [Parameter]
func abiName(context: ImportedTypeSkeleton) -> String {
return "bjs_\(context.name)_init"
}
}
struct ImportedPropertySkeleton: Codable {
let name: String
let isReadonly: Bool
let type: BridgeType
let documentation: String?
func getterAbiName(context: ImportedTypeSkeleton) -> String {
return "bjs_\(context.name)_\(name)_get"
}
func setterAbiName(context: ImportedTypeSkeleton) -> String {
return "bjs_\(context.name)_\(name)_set"
}
}
struct ImportedTypeSkeleton: Codable {
let name: String
let constructor: ImportedConstructorSkeleton?
let methods: [ImportedFunctionSkeleton]
let properties: [ImportedPropertySkeleton]
let documentation: String?
}
struct ImportedFileSkeleton: Codable {
let functions: [ImportedFunctionSkeleton]
let types: [ImportedTypeSkeleton]
}
struct ImportedModuleSkeleton: Codable {
let moduleName: String
var children: [ImportedFileSkeleton]
}
extension BridgeType {
var abiReturnType: WasmCoreType? {
switch self {
case .void: return nil
case .bool: return .i32
case .int: return .i32
case .float: return .f32
case .double: return .f64
case .string: return nil
case .jsObject: return .i32
case .swiftHeapObject:
// UnsafeMutableRawPointer is returned as an i32 pointer
return .pointer
}
}
}