Skip to content

Commit

Permalink
WasmParser/WAT: Add support for the tail-call proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
kateinoigakukun committed Jan 4, 2025
1 parent 5372f16 commit 5cc0e46
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
15 changes: 14 additions & 1 deletion Sources/WasmParser/WasmParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 6 additions & 1 deletion Tests/WATTests/EncoderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
1 change: 1 addition & 0 deletions Tests/WATTests/Spectest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5cc0e46

Please sign in to comment.