Skip to content
This repository was archived by the owner on Nov 3, 2021. It is now read-only.

Commit 2364a56

Browse files
committed
Remove n-ary select for now
1 parent c21da2a commit 2364a56

File tree

7 files changed

+34
-35
lines changed

7 files changed

+34
-35
lines changed

interpreter/binary/decode.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ let rec instr s =
259259

260260
| 0x1a -> drop
261261
| 0x1b -> select None
262-
| 0x1c -> select (Some (vec value_type s))
262+
| 0x1c -> select (Some (value_type s))
263263

264264
| 0x1d | 0x1e | 0x1f as b -> illegal s pos b
265265

interpreter/binary/encode.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ let encode m =
168168

169169
| Drop -> op 0x1a
170170
| Select None -> op 0x1b
171-
| Select (Some ts) -> op 0x1c; vec value_type ts
171+
| Select (Some t) -> op 0x1c; value_type t
172172

173173
| LocalGet x -> op 0x20; var x
174174
| LocalSet x -> op 0x21; var x

interpreter/syntax/ast.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ and instr' =
7171
| Unreachable (* trap unconditionally *)
7272
| Nop (* do nothing *)
7373
| Drop (* forget a value *)
74-
| Select of value_type list option (* branchless conditional *)
74+
| Select of value_type option (* branchless conditional *)
7575
| Block of stack_type * instr list (* execute in sequence *)
7676
| Loop of stack_type * instr list (* loop header *)
7777
| If of stack_type * instr list * instr list (* conditional *)

interpreter/text/arrange.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,7 @@ let rec instr e =
225225
| Nop -> "nop", []
226226
| Drop -> "drop", []
227227
| Select None -> "select", []
228-
| Select (Some []) -> "select", [Node ("result", [])]
229-
| Select (Some ts) -> "select", decls "result" ts
228+
| Select (Some t) -> "select", decls "result" [t]
230229
| Block (ts, es) -> "block", stack_type ts @ list instr es
231230
| Loop (ts, es) -> "loop", stack_type ts @ list instr es
232231
| If (ts, es1, es2) ->

interpreter/text/parser.mly

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -348,26 +348,25 @@ plain_instr :
348348
349349
select_instr :
350350
| SELECT select_instr_results
351-
{ let at = at () in fun c -> let b, ts = $2 in
352-
select (if b then (Some ts) else None) @@ at }
351+
{ let at = at () in fun c -> select $2 @@ at }
353352
354353
select_instr_results :
355-
| LPAR RESULT value_type_list RPAR select_instr_results
356-
{ let _, ts = $5 in true, $3 @ ts }
354+
| LPAR RESULT value_type RPAR
355+
{ Some $3 }
357356
| /* empty */
358-
{ false, [] }
357+
{ None }
359358
360359
select_instr_instr :
361360
| SELECT select_instr_results_instr
362361
{ let at1 = ati 1 in
363-
fun c -> let b, ts, es = $2 c in
364-
select (if b then (Some ts) else None) @@ at1, es }
362+
fun c -> let t_opt, es = $2 c in
363+
select t_opt @@ at1, es }
365364
366365
select_instr_results_instr :
367-
| LPAR RESULT value_type_list RPAR select_instr_results_instr
368-
{ fun c -> let _, ts, es = $5 c in true, $3 @ ts, es }
366+
| LPAR RESULT value_type RPAR instr
367+
{ fun c -> Some $3, $5 c }
369368
| instr
370-
{ fun c -> false, [], $1 c }
369+
{ fun c -> None, $1 c }
371370
372371
373372
call_instr :
@@ -458,7 +457,7 @@ expr : /* Sugar */
458457
expr1 : /* Sugar */
459458
| plain_instr expr_list { fun c -> $2 c, $1 c }
460459
| SELECT select_expr_results
461-
{ fun c -> let b, ts, es = $2 c in es, select (if b then (Some ts) else None) }
460+
{ fun c -> let t_opt, es = $2 c in es, select t_opt }
462461
| CALL_INDIRECT var call_expr_type
463462
{ fun c -> let x, es = $3 c in es, call_indirect ($2 c table) x }
464463
| CALL_INDIRECT call_expr_type /* Sugar */
@@ -473,10 +472,10 @@ expr1 : /* Sugar */
473472
let ts, (es, es1, es2) = $3 c c' in es, if_ ts es1 es2 }
474473
475474
select_expr_results :
476-
| LPAR RESULT value_type_list RPAR select_expr_results
477-
{ fun c -> let _, ts, es = $5 c in true, $3 @ ts, es }
475+
| LPAR RESULT value_type RPAR expr_list
476+
{ fun c -> Some $3, $5 c }
478477
| expr_list
479-
{ fun c -> false, [], $1 c }
478+
{ fun c -> None, $1 c }
480479
481480
call_expr_type :
482481
| type_use call_expr_params

interpreter/valid/valid.ml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,8 @@ let rec check_instr (c : context) (e : instr) (s : infer_stack_type) : op_type =
185185
" but stack has " ^ string_of_value_type t);
186186
[t; t; NumType I32Type] --> [t]
187187

188-
| Select (Some ts) ->
189-
check_arity (List.length ts) e.at;
190-
require (List.length ts <> 0) e.at "invalid result arity, 0 is not (yet) allowed";
191-
(ts @ ts @ [NumType I32Type]) --> ts
188+
| Select (Some t) ->
189+
[t; t; NumType I32Type] --> [t]
192190

193191
| Block (ts, es) ->
194192
check_arity (List.length ts) e.at;

test/core/select.wast

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -365,19 +365,22 @@
365365
(module (func $arity-0-implicit (select (nop) (nop) (i32.const 1))))
366366
"type mismatch"
367367
)
368-
(assert_invalid
369-
(module (func $arity-0 (select (result) (nop) (nop) (i32.const 1))))
370-
"invalid result arity"
368+
369+
(assert_malformed
370+
(module quote "(func $arity-0 (select (result) (nop) (nop) (i32.const 1)))")
371+
"unexpected token"
371372
)
372-
(assert_invalid
373-
(module (func $arity-2 (result i32 i32)
374-
(select (result i32 i32)
375-
(i32.const 0) (i32.const 0)
376-
(i32.const 0) (i32.const 0)
377-
(i32.const 1)
378-
)
379-
))
380-
"invalid result arity"
373+
(assert_malformed
374+
(module quote
375+
"(func $arity-2 (result i32 i32)"
376+
" (select (result i32 i32)"
377+
" (i32.const 0) (i32.const 0)"
378+
" (i32.const 0) (i32.const 0)"
379+
" (i32.const 1)"
380+
" )"
381+
")"
382+
)
383+
"unexpected token"
381384
)
382385

383386

0 commit comments

Comments
 (0)