Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit 33af7d5

Browse files
committed
Try revert parser.mly (Will revert)
1 parent 09e3b45 commit 33af7d5

File tree

1 file changed

+70
-30
lines changed

1 file changed

+70
-30
lines changed

interpreter/text/parser.mly

Lines changed: 70 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -373,16 +373,12 @@ align_opt :
373373

374374
/* Instructions & Expressions */
375375

376-
instr_list :
377-
| /* empty */ { fun c -> [] }
378-
| instr1 instr_list { fun c -> $1 c @ $2 c }
379-
| select_instr_instr_list { $1 }
380-
| call_instr_instr_list { $1 }
381-
382-
instr1 :
376+
instr :
383377
| plain_instr { let at = at () in fun c -> [$1 c @@ at] }
378+
| select_instr_instr { fun c -> let e, es = $1 c in e :: es }
379+
| call_instr_instr { fun c -> let e, es = $1 c in e :: es }
384380
| block_instr { let at = at () in fun c -> [$1 c @@ at] }
385-
| expr { $1 } /* Sugar */
381+
| expr { $1 } /* Sugar */
386382

387383
plain_instr :
388384
| UNREACHABLE { fun c -> unreachable }
@@ -455,51 +451,89 @@ plain_instr :
455451
| VEC_REPLACE NAT { let at = at () in fun c -> $1 (vec_lane_index $2 at) }
456452

457453

458-
select_instr_instr_list :
459-
| SELECT select_instr_results_instr_list
454+
select_instr :
455+
| SELECT select_instr_results
456+
{ let at = at () in fun c -> let b, ts = $2 in
457+
select (if b then (Some ts) else None) @@ at }
458+
459+
select_instr_results :
460+
| LPAR RESULT value_type_list RPAR select_instr_results
461+
{ let _, ts = $5 in true, $3 @ ts }
462+
| /* empty */
463+
{ false, [] }
464+
465+
select_instr_instr :
466+
| SELECT select_instr_results_instr
460467
{ let at1 = ati 1 in
461468
fun c -> let b, ts, es = $2 c in
462-
(select (if b then (Some ts) else None) @@ at1) :: es }
469+
select (if b then (Some ts) else None) @@ at1, es }
463470

464-
select_instr_results_instr_list :
465-
| LPAR RESULT value_type_list RPAR select_instr_results_instr_list
471+
select_instr_results_instr :
472+
| LPAR RESULT value_type_list RPAR select_instr_results_instr
466473
{ fun c -> let _, ts, es = $5 c in true, $3 @ ts, es }
467-
| instr_list
474+
| instr
468475
{ fun c -> false, [], $1 c }
469476

470477

471-
call_instr_instr_list :
472-
| CALL_INDIRECT var call_instr_type_instr_list
478+
call_instr :
479+
| CALL_INDIRECT var call_instr_type
480+
{ let at = at () in fun c -> call_indirect ($2 c table) ($3 c) @@ at }
481+
| CALL_INDIRECT call_instr_type /* Sugar */
482+
{ let at = at () in fun c -> call_indirect (0l @@ at) ($2 c) @@ at }
483+
484+
call_instr_type :
485+
| type_use call_instr_params
486+
{ let at1 = ati 1 in
487+
fun c ->
488+
match $2 c with
489+
| FuncType ([], []) -> $1 c type_
490+
| ft -> inline_type_explicit c ($1 c type_) ft at1 }
491+
| call_instr_params
492+
{ let at = at () in fun c -> inline_type c ($1 c) at }
493+
494+
call_instr_params :
495+
| LPAR PARAM value_type_list RPAR call_instr_params
496+
{ fun c -> let FuncType (ts1, ts2) = $5 c in FuncType ($3 @ ts1, ts2) }
497+
| call_instr_results
498+
{ fun c -> FuncType ([], $1 c) }
499+
500+
call_instr_results :
501+
| LPAR RESULT value_type_list RPAR call_instr_results
502+
{ fun c -> $3 @ $5 c }
503+
| /* empty */
504+
{ fun c -> [] }
505+
506+
507+
call_instr_instr :
508+
| CALL_INDIRECT var call_instr_type_instr
473509
{ let at1 = ati 1 in
474-
fun c -> let x, es = $3 c in
475-
(call_indirect ($2 c table) x @@ at1) :: es }
476-
| CALL_INDIRECT call_instr_type_instr_list /* Sugar */
510+
fun c -> let x, es = $3 c in call_indirect ($2 c table) x @@ at1, es }
511+
| CALL_INDIRECT call_instr_type_instr /* Sugar */
477512
{ let at1 = ati 1 in
478-
fun c -> let x, es = $2 c in
479-
(call_indirect (0l @@ at1) x @@ at1) :: es }
513+
fun c -> let x, es = $2 c in call_indirect (0l @@ at1) x @@ at1, es }
480514

481-
call_instr_type_instr_list :
482-
| type_use call_instr_params_instr_list
515+
call_instr_type_instr :
516+
| type_use call_instr_params_instr
483517
{ let at1 = ati 1 in
484518
fun c ->
485519
match $2 c with
486520
| FuncType ([], []), es -> $1 c type_, es
487521
| ft, es -> inline_type_explicit c ($1 c type_) ft at1, es }
488-
| call_instr_params_instr_list
522+
| call_instr_params_instr
489523
{ let at = at () in
490524
fun c -> let ft, es = $1 c in inline_type c ft at, es }
491525

492-
call_instr_params_instr_list :
493-
| LPAR PARAM value_type_list RPAR call_instr_params_instr_list
526+
call_instr_params_instr :
527+
| LPAR PARAM value_type_list RPAR call_instr_params_instr
494528
{ fun c ->
495529
let FuncType (ts1, ts2), es = $5 c in FuncType ($3 @ ts1, ts2), es }
496-
| call_instr_results_instr_list
530+
| call_instr_results_instr
497531
{ fun c -> let ts, es = $1 c in FuncType ([], ts), es }
498532

499-
call_instr_results_instr_list :
500-
| LPAR RESULT value_type_list RPAR call_instr_results_instr_list
533+
call_instr_results_instr :
534+
| LPAR RESULT value_type_list RPAR call_instr_results_instr
501535
{ fun c -> let ts, es = $5 c in $3 @ ts, es }
502-
| instr_list
536+
| instr
503537
{ fun c -> [], $1 c }
504538

505539

@@ -710,6 +744,12 @@ try_ :
710744
| LPAR DO instr_list RPAR handler
711745
{ fun bt c c' -> $5 bt ($3 c') c c' }
712746

747+
instr_list :
748+
| /* empty */ { fun c -> [] }
749+
| select_instr { fun c -> [$1 c] }
750+
| call_instr { fun c -> [$1 c] }
751+
| instr instr_list { fun c -> $1 c @ $2 c }
752+
713753
expr_list :
714754
| /* empty */ { fun c -> [] }
715755
| expr expr_list { fun c -> $1 c @ $2 c }

0 commit comments

Comments
 (0)