diff --git a/Sources/WasmParser/WasmParser.swift b/Sources/WasmParser/WasmParser.swift index db7bb815..2f8374b2 100644 --- a/Sources/WasmParser/WasmParser.swift +++ b/Sources/WasmParser/WasmParser.swift @@ -193,11 +193,14 @@ public struct WasmFeatureSet: OptionSet { /// The WebAssembly threads proposal @_alwaysEmitIntoClient public static var threads: WasmFeatureSet { WasmFeatureSet(rawValue: 1 << 2) } + /// The WebAssembly tail-call proposal + @_alwaysEmitIntoClient + public static var tailCall: WasmFeatureSet { WasmFeatureSet(rawValue: 1 << 3) } /// The default feature set public static let `default`: WasmFeatureSet = [.referenceTypes] /// The feature set with all features enabled - public static let all: WasmFeatureSet = [.memory64, .referenceTypes, .threads] + public static let all: WasmFeatureSet = [.memory64, .referenceTypes, .threads, .tailCall] } /// An error that occurs during parsing of a WebAssembly binary @@ -629,6 +632,16 @@ extension Parser: BinaryInstructionDecoder { return (typeIndex, tableIndex) } + @inlinable mutating func visitReturnCall() throws -> UInt32 { + try parseUnsigned() + } + + @inlinable mutating func visitReturnCallIndirect() throws -> (typeIndex: UInt32, tableIndex: UInt32) { + let typeIndex: TypeIndex = try parseUnsigned() + let tableIndex: TableIndex = try parseUnsigned() + return (typeIndex, tableIndex) + } + @inlinable mutating func visitTypedSelect() throws -> WasmTypes.ValueType { let results = try parseVector { try parseValueType() } guard results.count == 1 else { diff --git a/Tests/WATTests/EncoderTests.swift b/Tests/WATTests/EncoderTests.swift index 07e4f4a1..ffe34a27 100644 --- a/Tests/WATTests/EncoderTests.swift +++ b/Tests/WATTests/EncoderTests.swift @@ -116,7 +116,12 @@ class EncoderTests: XCTestCase { let wast2jsonProcess = try Process.run( wast2json, - arguments: [wastFile.path, "-o", json.path] + arguments: [ + wastFile.path, + "--enable-memory64", + "--enable-tail-call", + "-o", json.path + ] ) wast2jsonProcess.waitUntilExit() diff --git a/Tests/WATTests/Spectest.swift b/Tests/WATTests/Spectest.swift index b4f23681..bc743ecf 100644 --- a/Tests/WATTests/Spectest.swift +++ b/Tests/WATTests/Spectest.swift @@ -20,6 +20,7 @@ enum Spectest { var allFiles = [ testsuitePath, testsuitePath.appendingPathComponent("proposals/memory64"), + testsuitePath.appendingPathComponent("proposals/tail-call"), rootDirectory.appendingPathComponent("Tests/WasmKitTests/ExtraSuite"), ].flatMap { try! FileManager.default.contentsOfDirectory(at: $0, includingPropertiesForKeys: nil)