File tree Expand file tree Collapse file tree 21 files changed +36
-31
lines changed Expand file tree Collapse file tree 21 files changed +36
-31
lines changed Original file line number Diff line number Diff line change @@ -221,7 +221,7 @@ Instruction Binary Opcode Type
221
221
(reserved) :math: `\hex {CE}`
222
222
(reserved) :math: `\hex {CF}`
223
223
:math: `\REFNULL ~t` :math: `\hex {D0 }` :math: `[] \to [t]` :ref: `validation <valid-ref.null >` :ref: `execution <exec-ref.null >`
224
- :math: `\REFISNULL ~t` :math: `\hex {D1 }` :math: `[t] \to [\I32 ]` :ref: `validation <valid-ref.is_null >` :ref: `execution <exec-ref.is_null >`
224
+ :math: `\REFISNULL ` :math: `\hex {D1 }` :math: `[t] \to [\I32 ]` :ref: `validation <valid-ref.is_null >` :ref: `execution <exec-ref.is_null >`
225
225
:math: `\REFFUNC ~x` :math: `\hex {D2 }` :math: `[] \to [\FUNCREF ]` :ref: `validation <valid-ref.func >` :ref: `execution <exec-ref.func >`
226
226
(reserved) :math: `\hex {D3 }`
227
227
(reserved) :math: `\hex {D4 }`
Original file line number Diff line number Diff line change @@ -91,7 +91,7 @@ Reference Instructions
91
91
\begin {array}{llclll}
92
92
\production {instruction} & \Binstr &::=& \dots \\ &&|&
93
93
\hex {D0 }~~t{:}\Breftype &\Rightarrow & \REFNULL ~t \\ &&|&
94
- \hex {D1 }~~t{:} \Breftype &\Rightarrow & \REFISNULL ~t \\ &&|&
94
+ \hex {D1 } &\Rightarrow & \REFISNULL \\ &&|&
95
95
\hex {D2 }~~x{:}\Bfuncidx &\Rightarrow & \REFFUNC ~x \\
96
96
\end {array}
97
97
Original file line number Diff line number Diff line change @@ -203,8 +203,8 @@ Reference Instructions
203
203
204
204
.. _exec-ref.is_null :
205
205
206
- :math: `\REFISNULL ~t `
207
- ....................
206
+ :math: `\REFISNULL `
207
+ ..................
208
208
209
209
1. Assert: due to :ref: `validation <valid-ref.is_null >`, a :ref: `reference value <syntax-ref >` is on the top of the stack.
210
210
@@ -220,9 +220,9 @@ Reference Instructions
220
220
221
221
.. math ::
222
222
\begin {array}{lcl@{\qquad }l}
223
- \val ~\REFISNULL ~t &\stepto & \I32 .\CONST ~1
223
+ \val ~\REFISNULL &\stepto & \I32 .\CONST ~1
224
224
& (\iff \val = \REFNULL ~t) \\
225
- \val ~\REFISNULL ~t &\stepto & \I32 .\CONST ~0
225
+ \val ~\REFISNULL &\stepto & \I32 .\CONST ~0
226
226
& (\otherwise ) \\
227
227
\end {array}
228
228
Original file line number Diff line number Diff line change @@ -187,7 +187,7 @@ Instructions in this group are concerned with accessing :ref:`references <syntax
187
187
\production {instruction} & \instr &::=&
188
188
\dots \\&&|&
189
189
\REFNULL ~\reftype \\&&|&
190
- \REFISNULL ~ \reftype \\&&|&
190
+ \REFISNULL \\&&|&
191
191
\REFFUNC ~\funcidx \\
192
192
\end {array}
193
193
Original file line number Diff line number Diff line change @@ -159,7 +159,7 @@ Reference Instructions
159
159
\begin {array}{llclll}
160
160
\production {instruction} & \Tplaininstr _I &::=& \dots \\ &&|&
161
161
\text {ref.null}~~t{:}\Trefedtype &\Rightarrow & \REFNULL ~t \\ &&|&
162
- \text {ref.is\_null}~~t{:} \Trefedtype &\Rightarrow & \REFISNULL ~t \\ &&|&
162
+ \text {ref.is\_null} &\Rightarrow & \REFISNULL \\ &&|&
163
163
\text {ref.func}~~x{:}\Tfuncidx &\Rightarrow & \REFFUNC ~x \\ &&|&
164
164
\end {array}
165
165
Original file line number Diff line number Diff line change @@ -182,15 +182,16 @@ Reference Instructions
182
182
183
183
.. _valid-ref.is_null :
184
184
185
- :math: `\REFISNULL ~t `
186
- ....................
185
+ :math: `\REFISNULL `
186
+ ..................
187
187
188
- * The instruction is valid with type :math: `[t] \to [\I32 ]`.
188
+ * The instruction is valid with type :math: `[t] \to [\I32 ]`, for any :ref: ` reference type < syntax-reftype >` :math: `t` .
189
189
190
190
.. math ::
191
191
\frac {
192
+ t = \reftype
192
193
}{
193
- C \vdashinstr \REFISNULL ~t : [t] \to [\I32 ]
194
+ C \vdashinstr \REFISNULL : [t] \to [\I32 ]
194
195
}
195
196
196
197
.. _valid-ref.func :
Original file line number Diff line number Diff line change @@ -453,7 +453,7 @@ let rec instr s =
453
453
| 0xcc | 0xcd | 0xce | 0xcf as b -> illegal s pos b
454
454
455
455
| 0xd0 -> ref_null (ref_type s)
456
- | 0xd1 -> ref_is_null (ref_type s)
456
+ | 0xd1 -> ref_is_null
457
457
| 0xd2 -> ref_func (at var s)
458
458
459
459
| 0xfc as b1 ->
Original file line number Diff line number Diff line change @@ -230,7 +230,7 @@ let encode m =
230
230
| DataDrop x -> op 0xfc ; op 0x09 ; var x
231
231
232
232
| RefNull t -> op 0xd0 ; ref_type t
233
- | RefIsNull t -> op 0xd1 ; ref_type t
233
+ | RefIsNull -> op 0xd1
234
234
| RefFunc x -> op 0xd2 ; var x
235
235
236
236
| Const {it = I32 c ; _} -> op 0x41 ; vs32 c
Original file line number Diff line number Diff line change @@ -427,7 +427,7 @@ let rec step (c : config) : config =
427
427
| RefNull t , vs' ->
428
428
Ref (NullRef t) :: vs', []
429
429
430
- | RefIsNull _ , Ref r :: vs' ->
430
+ | RefIsNull , Ref r :: vs' ->
431
431
(match r with
432
432
| NullRef _ ->
433
433
Num (I32 1l ) :: vs', []
Original file line number Diff line number Diff line change @@ -287,7 +287,7 @@ let assert_return ress ts at =
287
287
Test (Values. I32 I32Op. Eqz ) @@ at;
288
288
BrIf (0l @@ at) @@ at ]
289
289
| LitResult {it = Values. Ref (Values. NullRef t ); _} ->
290
- [ RefIsNull t @@ at;
290
+ [ RefIsNull @@ at;
291
291
Test (Values. I32 I32Op. Eqz ) @@ at;
292
292
BrIf (0l @@ at) @@ at ]
293
293
| LitResult {it = Values. Ref (ExternRef n ); _} ->
Original file line number Diff line number Diff line change @@ -106,7 +106,7 @@ and instr' =
106
106
| MemoryInit of var (* initialize memory range from segment *)
107
107
| DataDrop of var (* drop passive data segment *)
108
108
| RefNull of ref_type (* null reference *)
109
- | RefIsNull of ref_type (* null test *)
109
+ | RefIsNull (* null test *)
110
110
| RefFunc of var (* function reference *)
111
111
| Const of num (* constant *)
112
112
| Test of testop (* numeric test *)
Original file line number Diff line number Diff line change @@ -62,7 +62,7 @@ let list free xs = List.fold_left union empty (List.map free xs)
62
62
let rec instr (e : instr ) =
63
63
match e.it with
64
64
| Unreachable | Nop | Drop | Select _ -> empty
65
- | RefNull _ | RefIsNull _ -> empty
65
+ | RefNull _ | RefIsNull -> empty
66
66
| RefFunc x -> funcs (var x)
67
67
| Const _ | Test _ | Compare _ | Unary _ | Binary _ | Convert _ -> empty
68
68
| Block (_ , es ) | Loop (_ , es ) -> block es
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ let f32_const n = Const (F32 n.it @@ n.at)
10
10
let f64_const n = Const (F64 n.it @@ n.at)
11
11
let ref_func x = RefFunc x
12
12
let ref_null t = RefNull t
13
- let ref_is_null t = RefIsNull t
13
+ let ref_is_null = RefIsNull
14
14
15
15
let unreachable = Unreachable
16
16
let nop = Nop
Original file line number Diff line number Diff line change @@ -271,7 +271,7 @@ let rec instr e =
271
271
| MemoryInit x -> " memory.init " ^ var x, []
272
272
| DataDrop x -> " data.drop " ^ var x, []
273
273
| RefNull t -> " ref.null" , [Atom (refed_type t)]
274
- | RefIsNull t -> " ref.is_null" , [Atom (refed_type t) ]
274
+ | RefIsNull -> " ref.is_null" , []
275
275
| RefFunc x -> " ref.func " ^ var x, []
276
276
| Const n -> constop n ^ " " ^ num n, []
277
277
| Test op -> testop op, []
Original file line number Diff line number Diff line change @@ -376,7 +376,7 @@ plain_instr :
376
376
| MEMORY_INIT var { fun c -> memory_init ($2 c data) }
377
377
| DATA_DROP var { fun c -> data_drop ($2 c data) }
378
378
| REF_NULL ref_kind { fun c -> ref_null $2 }
379
- | REF_IS_NULL ref_kind { fun c -> ref_is_null $2 }
379
+ | REF_IS_NULL { fun c -> ref_is_null }
380
380
| REF_FUNC var { fun c -> ref_func ($2 c func) }
381
381
| CONST num { fun c -> fst (num $1 $2) }
382
382
| TEST { fun c -> $1 }
Original file line number Diff line number Diff line change @@ -360,8 +360,12 @@ let rec check_instr (c : context) (e : instr) (s : infer_stack_type) : op_type =
360
360
| RefNull t ->
361
361
[] --> [RefType t]
362
362
363
- | RefIsNull t ->
364
- [RefType t] --> [NumType I32Type ]
363
+ | RefIsNull ->
364
+ let t = peek 1 s in
365
+ require (match t with None -> true | Some t -> is_ref_type t) e.at
366
+ (" type mismatch: instruction requires reference type" ^
367
+ " but stack has " ^ string_of_infer_type t);
368
+ [t] -~> [Some (NumType I32Type )]
365
369
366
370
| RefFunc x ->
367
371
let _ft = func c x in
Original file line number Diff line number Diff line change 24
24
(func $ff2 )
25
25
26
26
(func (export " is_null-f" ) (result i32 )
27
- (ref.is_null func (ref.func $f ))
27
+ (ref.is_null (ref.func $f ))
28
28
)
29
29
(func (export " is_null-g" ) (result i32 )
30
- (ref.is_null func (ref.func $g ))
30
+ (ref.is_null (ref.func $g ))
31
31
)
32
32
(func (export " is_null-v" ) (result i32 )
33
- (ref.is_null func (global.get $v ))
33
+ (ref.is_null (global.get $v ))
34
34
)
35
35
36
36
(func (export " set-f" ) (global.set $v (ref.func $f )))
Original file line number Diff line number Diff line change 1
1
(module
2
2
(func $f1 (export " funcref" ) (param $x funcref ) (result i32 )
3
- (ref.is_null func (local.get $x ))
3
+ (ref.is_null (local.get $x ))
4
4
)
5
5
(func $f2 (export " externref" ) (param $x externref ) (result i32 )
6
- (ref.is_null extern (local.get $x ))
6
+ (ref.is_null (local.get $x ))
7
7
)
8
8
9
9
(table $t1 2 funcref )
Original file line number Diff line number Diff line change 17
17
)
18
18
19
19
(func (export " is_null-funcref" ) (param $i i32 ) (result i32 )
20
- (ref.is_null func (call $f3 (local.get $i )))
20
+ (ref.is_null (call $f3 (local.get $i )))
21
21
)
22
22
)
23
23
Original file line number Diff line number Diff line change 90
90
(block
91
91
(loop
92
92
(local.set 2 (table.get $t (local.get 0 )))
93
- (br_if 1 (i32.eqz (ref.is_null func (local.get 2 ))))
93
+ (br_if 1 (i32.eqz (ref.is_null (local.get 2 ))))
94
94
(br_if 1 (i32.ge_u (local.get 0 ) (local.get 1 )))
95
95
(local.set 0 (i32.add (local.get 0 ) (i32.const 1 )))
96
96
(br_if 0 (i32.le_u (local.get 0 ) (local.get 1 )))
Original file line number Diff line number Diff line change 22
22
)
23
23
24
24
(func (export " is_null-funcref" ) (param $i i32 ) (result i32 )
25
- (ref.is_null func (call $f3 (local.get $i )))
25
+ (ref.is_null (call $f3 (local.get $i )))
26
26
)
27
27
)
28
28
You can’t perform that action at this time.
0 commit comments