@@ -57,11 +57,13 @@ public struct WasmFeatureSet: OptionSet {
5757 public static let memory64 = WasmFeatureSet ( rawValue: 1 << 0 )
5858 /// The WebAssembly reference types proposal
5959 public static let referenceTypes = WasmFeatureSet ( rawValue: 1 << 1 )
60+ /// The WebAssembly threads proposal
61+ public static let threads = WasmFeatureSet ( rawValue: 1 << 2 )
6062
6163 /// The default feature set
6264 public static let `default` : WasmFeatureSet = [ . referenceTypes]
6365 /// The feature set with all features enabled
64- public static let all : WasmFeatureSet = [ . memory64, . referenceTypes]
66+ public static let all : WasmFeatureSet = [ . memory64, . referenceTypes, . threads ]
6567}
6668
6769public enum WasmParserError : Swift . Error {
@@ -274,19 +276,39 @@ extension Parser {
274276 /// <https://webassembly.github.io/spec/core/binary/types.html#limits>
275277 func parseLimits( ) throws -> Limits {
276278 let b = try stream. consumeAny ( )
279+ let sharedMask : UInt8 = 0b0010
280+ let isMemory64Mask : UInt8 = 0b0100
277281
278- switch b {
279- case 0x00 :
280- return try Limits ( min: UInt64 ( parseUnsigned ( UInt32 . self) ) , max: nil )
281- case 0x01 :
282- return try Limits ( min: UInt64 ( parseUnsigned ( UInt32 . self) ) , max: UInt64 ( parseUnsigned ( UInt32 . self) ) )
283- case 0x04 where features. contains ( . memory64) :
284- return try Limits ( min: parseUnsigned ( UInt64 . self) , max: nil , isMemory64: true )
285- case 0x05 where features. contains ( . memory64) :
286- return try Limits ( min: parseUnsigned ( UInt64 . self) , max: parseUnsigned ( UInt64 . self) , isMemory64: true )
287- default :
282+ let hasMax = b & 0b0001 != 0
283+ let shared = b & sharedMask != 0
284+ let isMemory64 = b & isMemory64Mask != 0
285+
286+ var flagMask : UInt8 = 0b0001
287+ if features. contains ( . threads) {
288+ flagMask |= sharedMask
289+ }
290+ if features. contains ( . memory64) {
291+ flagMask |= isMemory64Mask
292+ }
293+ guard ( b & ~ flagMask) == 0 else {
288294 throw WasmParserError . malformedLimit ( b)
289295 }
296+
297+ let min : UInt64
298+ if isMemory64 {
299+ min = try parseUnsigned ( UInt64 . self)
300+ } else {
301+ min = try UInt64 ( parseUnsigned ( UInt32 . self) )
302+ }
303+ var max : UInt64 ?
304+ if hasMax {
305+ if isMemory64 {
306+ max = try parseUnsigned ( UInt64 . self)
307+ } else {
308+ max = try UInt64 ( parseUnsigned ( UInt32 . self) )
309+ }
310+ }
311+ return Limits ( min: min, max: max, isMemory64: isMemory64, shared: shared)
290312 }
291313
292314 /// > Note:
0 commit comments