@@ -54,31 +54,25 @@ struct WastParser {
5454 }
5555
5656 struct ConstExpressionCollector : WastConstInstructionVisitor {
57- let addValue : ( Value ) -> Void
57+ let addValue : ( WastConstValue ) -> Void
5858
5959 mutating func visitI32Const( value: Int32 ) throws { addValue ( . i32( UInt32 ( bitPattern: value) ) ) }
6060 mutating func visitI64Const( value: Int64 ) throws { addValue ( . i64( UInt64 ( bitPattern: value) ) ) }
6161 mutating func visitF32Const( value: IEEE754 . Float32 ) throws { addValue ( . f32( value. bitPattern) ) }
6262 mutating func visitF64Const( value: IEEE754 . Float64 ) throws { addValue ( . f64( value. bitPattern) ) }
6363 mutating func visitRefFunc( functionIndex: UInt32 ) throws {
64- addValue ( . ref ( . function ( FunctionAddress ( functionIndex) ) ) )
64+ addValue ( . refFunc ( functionIndex: functionIndex ) )
6565 }
66- mutating func visitRefNull( type: ReferenceType ) throws {
67- let value : Reference
68- switch type. heapType {
69- case . externRef: value = . extern( nil )
70- case . funcRef: value = . function( nil )
71- }
72- addValue ( . ref( value) )
66+ mutating func visitRefNull( type: HeapType ) throws {
67+ addValue ( . refNull( type) )
7368 }
74-
75- mutating func visitRefExtern( value: UInt32 ) throws {
76- addValue ( . ref( . extern( ExternAddress ( value) ) ) )
69+ func visitRefExtern( value: UInt32 ) throws {
70+ addValue ( . refExtern( value: value) )
7771 }
7872 }
7973
80- mutating func constExpression ( ) throws -> [ Value ] {
81- var values : [ Value ] = [ ]
74+ mutating func argumentValues ( ) throws -> [ WastConstValue ] {
75+ var values : [ WastConstValue ] = [ ]
8276 var collector = ConstExpressionCollector ( addValue: { values. append ( $0) } )
8377 var exprParser = ExpressionParser < ConstExpressionCollector > ( lexer: parser. lexer, features: features)
8478 while try exprParser. parseWastConstInstruction ( visitor: & collector) { }
@@ -137,16 +131,26 @@ public enum WastExecute {
137131 }
138132}
139133
134+ public enum WastConstValue {
135+ case i32( UInt32 )
136+ case i64( UInt64 )
137+ case f32( UInt32 )
138+ case f64( UInt64 )
139+ case refNull( HeapType )
140+ case refFunc( functionIndex: UInt32 )
141+ case refExtern( value: UInt32 )
142+ }
143+
140144public struct WastInvoke {
141145 public let module : String ?
142146 public let name : String
143- public let args : [ Value ]
147+ public let args : [ WastConstValue ]
144148
145149 static func parse( wastParser: inout WastParser ) throws -> WastInvoke {
146150 try wastParser. parser. expectKeyword ( " invoke " )
147151 let module = try wastParser. parser. takeId ( )
148152 let name = try wastParser. parser. expectString ( )
149- let args = try wastParser. constExpression ( )
153+ let args = try wastParser. argumentValues ( )
150154 try wastParser. parser. expect ( . rightParen)
151155 let invoke = WastInvoke ( module: module? . value, name: name, args: args)
152156 return invoke
@@ -155,7 +159,7 @@ public struct WastInvoke {
155159
156160public enum WastExpectValue {
157161 /// A concrete value that is expected to be returned.
158- case value( Value )
162+ case value( WastConstValue )
159163 /// A value that is expected to be a canonical NaN.
160164 /// Corresponds to `f32.const nan:canonical` in WAST.
161165 case f32CanonicalNaN
0 commit comments