@@ -57,11 +57,13 @@ public struct WasmFeatureSet: OptionSet {
57
57
public static let memory64 = WasmFeatureSet ( rawValue: 1 << 0 )
58
58
/// The WebAssembly reference types proposal
59
59
public static let referenceTypes = WasmFeatureSet ( rawValue: 1 << 1 )
60
+ /// The WebAssembly threads proposal
61
+ public static let threads = WasmFeatureSet ( rawValue: 1 << 2 )
60
62
61
63
/// The default feature set
62
64
public static let `default` : WasmFeatureSet = [ . referenceTypes]
63
65
/// The feature set with all features enabled
64
- public static let all : WasmFeatureSet = [ . memory64, . referenceTypes]
66
+ public static let all : WasmFeatureSet = [ . memory64, . referenceTypes, . threads ]
65
67
}
66
68
67
69
public enum WasmParserError : Swift . Error {
@@ -274,19 +276,39 @@ extension Parser {
274
276
/// <https://webassembly.github.io/spec/core/binary/types.html#limits>
275
277
func parseLimits( ) throws -> Limits {
276
278
let b = try stream. consumeAny ( )
279
+ let sharedMask : UInt8 = 0b0010
280
+ let isMemory64Mask : UInt8 = 0b0100
277
281
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 {
288
294
throw WasmParserError . malformedLimit ( b)
289
295
}
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)
290
312
}
291
313
292
314
/// > Note:
0 commit comments