Skip to content

Commit 05a091c

Browse files
WasmParser/WAT: Add support for the tail-call proposal
1 parent dbce3f1 commit 05a091c

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

Sources/WasmParser/WasmParser.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,14 @@ public struct WasmFeatureSet: OptionSet {
193193
/// The WebAssembly threads proposal
194194
@_alwaysEmitIntoClient
195195
public static var threads: WasmFeatureSet { WasmFeatureSet(rawValue: 1 << 2) }
196+
/// The WebAssembly tail-call proposal
197+
@_alwaysEmitIntoClient
198+
public static var tailCall: WasmFeatureSet { WasmFeatureSet(rawValue: 1 << 3) }
196199

197200
/// The default feature set
198201
public static let `default`: WasmFeatureSet = [.referenceTypes]
199202
/// The feature set with all features enabled
200-
public static let all: WasmFeatureSet = [.memory64, .referenceTypes, .threads]
203+
public static let all: WasmFeatureSet = [.memory64, .referenceTypes, .threads, .tailCall]
201204
}
202205

203206
/// An error that occurs during parsing of a WebAssembly binary
@@ -629,6 +632,16 @@ extension Parser: BinaryInstructionDecoder {
629632
return (typeIndex, tableIndex)
630633
}
631634

635+
@inlinable mutating func visitReturnCall() throws -> UInt32 {
636+
try parseUnsigned()
637+
}
638+
639+
@inlinable mutating func visitReturnCallIndirect() throws -> (typeIndex: UInt32, tableIndex: UInt32) {
640+
let typeIndex: TypeIndex = try parseUnsigned()
641+
let tableIndex: TableIndex = try parseUnsigned()
642+
return (typeIndex, tableIndex)
643+
}
644+
632645
@inlinable mutating func visitTypedSelect() throws -> WasmTypes.ValueType {
633646
let results = try parseVector { try parseValueType() }
634647
guard results.count == 1 else {

Tests/WATTests/EncoderTests.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,12 @@ class EncoderTests: XCTestCase {
116116

117117
let wast2jsonProcess = try Process.run(
118118
wast2json,
119-
arguments: [wastFile.path, "-o", json.path]
119+
arguments: [
120+
wastFile.path,
121+
"--enable-memory64",
122+
"--enable-tail-call",
123+
"-o", json.path,
124+
]
120125
)
121126
wast2jsonProcess.waitUntilExit()
122127

Tests/WATTests/Spectest.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ enum Spectest {
2020
var allFiles = [
2121
testsuitePath,
2222
testsuitePath.appendingPathComponent("proposals/memory64"),
23+
testsuitePath.appendingPathComponent("proposals/tail-call"),
2324
rootDirectory.appendingPathComponent("Tests/WasmKitTests/ExtraSuite"),
2425
].flatMap {
2526
try! FileManager.default.contentsOfDirectory(at: $0, includingPropertiesForKeys: nil)

0 commit comments

Comments
 (0)