simplify typeuse rule
This commit is contained in:
+32
-34
@@ -574,11 +574,15 @@ plaininstr :: { PlainInstr }
|
|||||||
| 'f32.reinterpret_i32' { FReinterpretI BS32 }
|
| 'f32.reinterpret_i32' { FReinterpretI BS32 }
|
||||||
| 'f64.reinterpret_i64' { FReinterpretI BS64 }
|
| 'f64.reinterpret_i64' { FReinterpretI BS64 }
|
||||||
|
|
||||||
typeuse_cont(close, next)
|
typeuse(next)
|
||||||
: '(' typeuse1_cont(close, next) { $2 }
|
: '(' typeuse1(folded_instr_list(next), instruction_list(next)) {
|
||||||
| next { (emptyTypeUse, Left $1) }
|
let (tu, rest) = $2 in
|
||||||
|
let (next, instr) = either id id rest in
|
||||||
|
(tu, instr, next)
|
||||||
|
}
|
||||||
|
| instruction_list(next) { let (next, instr) = $1 in (emptyTypeUse, instr, next) }
|
||||||
|
|
||||||
typeuse1_cont(close, next)
|
typeuse1(close, next)
|
||||||
: 'type' index ')' typesign(close, next) {
|
: 'type' index ')' typesign(close, next) {
|
||||||
case $4 of
|
case $4 of
|
||||||
(FuncType [] [], rest) -> (IndexedTypeUse $2 Nothing, rest)
|
(FuncType [] [], rest) -> (IndexedTypeUse $2 Nothing, rest)
|
||||||
@@ -638,28 +642,25 @@ memarg8 :: { MemArg }
|
|||||||
instruction_list(terminator)
|
instruction_list(terminator)
|
||||||
: terminator { ($1, []) }
|
: terminator { ($1, []) }
|
||||||
| plaininstr mixed_instruction_list(terminator) { ([PlainInstr $1] ++) `fmap` $2 }
|
| plaininstr mixed_instruction_list(terminator) { ([PlainInstr $1] ++) `fmap` $2 }
|
||||||
| 'call_indirect' typeuse_cont(folded_instr_list(terminator), instruction_list(terminator)) {
|
| 'call_indirect' typeuse(terminator) {
|
||||||
let (tu, rest) = $2 in
|
let (tu, instr, end) = $2 in
|
||||||
([PlainInstr $ CallIndirect tu] ++) `fmap` (either id id rest)
|
(end, [PlainInstr $ CallIndirect tu] ++ instr)
|
||||||
}
|
}
|
||||||
| 'block' opt(ident) typeuse_cont(folded_instr_list('end'), instruction_list('end')) opt(ident) mixed_instruction_list(terminator) {%
|
| 'block' opt(ident) typeuse('end') opt(ident) mixed_instruction_list(terminator) {%
|
||||||
let (tu, rest) = $3 in
|
let (tu, instr, _) = $3 in
|
||||||
let (_, instr) = either id id rest in
|
if matchIdents $2 $4
|
||||||
if $2 == $4 || isNothing $4
|
|
||||||
then Right $ ([BlockInstr $2 tu instr] ++) `fmap` $5
|
then Right $ ([BlockInstr $2 tu instr] ++) `fmap` $5
|
||||||
else Left "Block labels have to match"
|
else Left "Block labels have to match"
|
||||||
}
|
}
|
||||||
| 'loop' opt(ident) typeuse_cont(folded_instr_list('end'), instruction_list('end')) opt(ident) mixed_instruction_list(terminator) {%
|
| 'loop' opt(ident) typeuse('end') opt(ident) mixed_instruction_list(terminator) {%
|
||||||
let (tu, rest) = $3 in
|
let (tu, instr, _) = $3 in
|
||||||
let (_, instr) = either id id rest in
|
if matchIdents $2 $4
|
||||||
if $2 == $4 || isNothing $4
|
|
||||||
then Right $ ([LoopInstr $2 tu instr] ++) `fmap` $5
|
then Right $ ([LoopInstr $2 tu instr] ++) `fmap` $5
|
||||||
else Left "Loop labels have to match"
|
else Left "Loop labels have to match"
|
||||||
}
|
}
|
||||||
| 'if' opt(ident) typeuse_cont(folded_instr_list(if_else), instruction_list(if_else)) mixed_instruction_list(terminator) {%
|
| 'if' opt(ident) typeuse(if_else) mixed_instruction_list(terminator) {%
|
||||||
let (tu, rest) = $3 in
|
let (tu, trueBranch, (falseBranch, identAfter)) = $3 in
|
||||||
let ((falseBranch, identAfter), trueBranch) = either id id rest in
|
if matchIdents $2 identAfter
|
||||||
if $2 == identAfter || isNothing identAfter
|
|
||||||
then Right $ ([IfInstr $2 tu trueBranch falseBranch] ++) `fmap` $4
|
then Right $ ([IfInstr $2 tu trueBranch falseBranch] ++) `fmap` $4
|
||||||
else Left "If labels have to match"
|
else Left "If labels have to match"
|
||||||
}
|
}
|
||||||
@@ -683,22 +684,19 @@ folded_instr :: { [Instruction] }
|
|||||||
|
|
||||||
folded_instr1 :: { [Instruction] }
|
folded_instr1 :: { [Instruction] }
|
||||||
: plaininstr mixed_instruction_list(')') { snd $2 ++ [PlainInstr $1] }
|
: plaininstr mixed_instruction_list(')') { snd $2 ++ [PlainInstr $1] }
|
||||||
| 'call_indirect' typeuse_cont(folded_instr_list(')'), instruction_list(')')) {
|
| 'call_indirect' typeuse(')') {
|
||||||
let (tu, rest) = $2 in
|
let (tu, instr, _) = $2 in
|
||||||
let instr = snd $ either id id rest in
|
|
||||||
instr ++ [PlainInstr $ CallIndirect tu]
|
instr ++ [PlainInstr $ CallIndirect tu]
|
||||||
}
|
}
|
||||||
| 'block' opt(ident) typeuse_cont(folded_instr_list(')'), instruction_list(')')) {
|
| 'block' opt(ident) typeuse(')') {
|
||||||
let (typeUse, rest) = $3 in
|
let (typeUse, instr, _) = $3 in
|
||||||
let instr = snd $ either id id rest in
|
|
||||||
[BlockInstr $2 typeUse instr]
|
[BlockInstr $2 typeUse instr]
|
||||||
}
|
}
|
||||||
| 'loop' opt(ident) typeuse_cont(folded_instr_list(')'), instruction_list(')')) {
|
| 'loop' opt(ident) typeuse(')') {
|
||||||
let (typeUse, rest) = $3 in
|
let (typeUse, instr, _) = $3 in
|
||||||
let instr = snd $ either id id rest in
|
|
||||||
[LoopInstr $2 typeUse instr]
|
[LoopInstr $2 typeUse instr]
|
||||||
}
|
}
|
||||||
| 'if' opt(ident) '(' typeuse1_cont(folded_then_else, never) {
|
| 'if' opt(ident) '(' typeuse1(folded_then_else, never) {
|
||||||
let (typeUse, Right (pred, (trueBranch, falseBranch))) = $4 in
|
let (typeUse, Right (pred, (trueBranch, falseBranch))) = $4 in
|
||||||
pred ++ [IfInstr $2 typeUse trueBranch falseBranch]
|
pred ++ [IfInstr $2 typeUse trueBranch falseBranch]
|
||||||
}
|
}
|
||||||
@@ -715,8 +713,8 @@ folded_else :: { [Instruction] }
|
|||||||
| '(' 'else' mixed_instruction_list(')') ')' { snd $3 }
|
| '(' 'else' mixed_instruction_list(')') ')' { snd $3 }
|
||||||
|
|
||||||
importdesc :: { ImportDesc }
|
importdesc :: { ImportDesc }
|
||||||
: 'func' opt(ident) typeuse_cont(')', ')') {
|
: 'func' opt(ident) typeuse(')') {
|
||||||
let (ft, _) = $3 in ImportFunc $2 ft
|
let (ft, _, _) = $3 in ImportFunc $2 ft
|
||||||
}
|
}
|
||||||
| 'table' opt(ident) tabletype ')' { ImportTable $2 $3 }
|
| 'table' opt(ident) tabletype ')' { ImportTable $2 $3 }
|
||||||
| 'memory' opt(ident) limits ')' { ImportMemory $2 $3 }
|
| 'memory' opt(ident) limits ')' { ImportMemory $2 $3 }
|
||||||
@@ -746,11 +744,11 @@ export_import_typeuse_locals_body1 :: { Maybe Ident -> ModuleField }
|
|||||||
| import_typeuse_locals_body1 { $1 }
|
| import_typeuse_locals_body1 { $1 }
|
||||||
|
|
||||||
import_typeuse_locals_body1 :: { Maybe Ident -> ModuleField }
|
import_typeuse_locals_body1 :: { Maybe Ident -> ModuleField }
|
||||||
: 'import' name name ')' typeuse_cont(')', ')') {
|
: 'import' name name ')' typeuse(')') {
|
||||||
let (ft, _) = $5 in
|
let (ft, _, _) = $5 in
|
||||||
\ident -> MFImport $ Import [] $2 $3 $ ImportFunc ident ft
|
\ident -> MFImport $ Import [] $2 $3 $ ImportFunc ident ft
|
||||||
}
|
}
|
||||||
| typeuse1_cont(func_mid1, instruction_list(')')) {
|
| typeuse1(func_mid1, instruction_list(')')) {
|
||||||
let (funcType, rest) = $1 in
|
let (funcType, rest) = $1 in
|
||||||
let (locals, body) = either (\a -> ([], snd a)) id rest in
|
let (locals, body) = either (\a -> ([], snd a)) id rest in
|
||||||
\ident -> MFFunc $ emptyFunction { locals, body, ident, funcType }
|
\ident -> MFFunc $ emptyFunction { locals, body, ident, funcType }
|
||||||
|
|||||||
Reference in New Issue
Block a user