Skip to content

Commit

Permalink
Merge pull request #171 from WebAssembly/cases-and-labels
Browse files Browse the repository at this point in the history
Clarify spec internal naming regarding cases and targets
  • Loading branch information
sunfishcode committed Nov 11, 2015
2 parents a78b742 + b0d1a62 commit 15bbc4a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
14 changes: 7 additions & 7 deletions ml-proto/host/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ expr1 :
| RETURN expr_opt
{ let at1 = ati 1 in
fun c -> return (label c ("return" @@ at1) @@ at1, $2 c) }
| TABLESWITCH labeling expr LPAR TABLE case_list RPAR case target_list
| TABLESWITCH labeling expr LPAR TABLE target_list RPAR target case_list
{ fun c -> let c', l = $2 c in let e = $3 c' in
let c'' = enter_switch c' in let es = $9 c'' in
tableswitch (l, e, $6 c'', $8 c'', es) }
Expand Down Expand Up @@ -306,21 +306,21 @@ expr_list :
| expr expr_list { fun c -> $1 c :: $2 c }
;
case :
target :
| LPAR CASE var RPAR { let at = at () in fun c -> Case ($3 c case) @@ at }
| LPAR BR var RPAR { let at = at () in fun c -> Case_br ($3 c label) @@ at }
;
case_list :
target_list :
| /* empty */ { fun c -> [] }
| case case_list { fun c -> $1 c :: $2 c }
| target target_list { fun c -> $1 c :: $2 c }
;
target :
case :
| LPAR CASE expr_list RPAR { fun c -> anon_case c; $3 c }
| LPAR CASE bind_var expr_list RPAR { fun c -> bind_case c $3; $4 c }
;
target_list :
case_list :
| /* empty */ { fun c -> [] }
| target target_list { fun c -> let e = $1 c in let es = $2 c in e :: es }
| case case_list { fun c -> let e = $1 c in let es = $2 c in e :: es }
;
Expand Down
10 changes: 5 additions & 5 deletions ml-proto/spec/sugar.ml
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ let br (x, e) =
let return (x, eo) =
Break (x, eo)

let tableswitch (l, e, cs, c, es) =
let case c (xs, es') =
match c.it with
let tableswitch (l, e, ts, t, es) =
let translate_target t (xs, es') =
match t.it with
| Case x -> x :: xs, es'
| Case_br x ->
(List.length es' @@ c.at) :: xs, (Break (x, None) @@ c.at) :: es'
(List.length es' @@ t.at) :: xs, (Break (x, None) @@ t.at) :: es'
in
let xs, es' = List.fold_right case (c :: cs) ([], []) in
let xs, es' = List.fold_right translate_target (t :: ts) ([], []) in
let es'' = List.map expr_seq es in
let n = List.length es' in
let sh x = (if x.it >= n then x.it + n else x.it) @@ x.at in
Expand Down

0 comments on commit 15bbc4a

Please sign in to comment.