Another example, testing rule priorities a bit
This commit is contained in:
19
cranelift/isle/isle_examples/test2.isle
Normal file
19
cranelift/isle/isle_examples/test2.isle
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
(type u32 (primitive u32))
|
||||||
|
(type A (enum
|
||||||
|
(A1 (x B) (y B))))
|
||||||
|
(type B (enum
|
||||||
|
(B1 (x u32))))
|
||||||
|
|
||||||
|
(decl A2B (A) B)
|
||||||
|
|
||||||
|
(rule 1
|
||||||
|
(A2B (A.A1 _ (B.B1 x)))
|
||||||
|
(B.B1 x))
|
||||||
|
|
||||||
|
(rule 1
|
||||||
|
(A2B (A.A1 (B.B1 x) _))
|
||||||
|
(B.B1 x))
|
||||||
|
|
||||||
|
(rule -1
|
||||||
|
(A2B (A.A1 _ _))
|
||||||
|
(B.B1 42))
|
||||||
@@ -712,7 +712,11 @@ impl<'a> Codegen<'a> {
|
|||||||
|
|
||||||
let mut body_ctx: BodyContext = Default::default();
|
let mut body_ctx: BodyContext = Default::default();
|
||||||
body_ctx.expected_return_vals = 1;
|
body_ctx.expected_return_vals = 1;
|
||||||
self.generate_body(code, /* depth = */ 0, trie, " ", &mut body_ctx)?;
|
let returned =
|
||||||
|
self.generate_body(code, /* depth = */ 0, trie, " ", &mut body_ctx)?;
|
||||||
|
if !returned {
|
||||||
|
writeln!(code, " return None;")?;
|
||||||
|
}
|
||||||
|
|
||||||
writeln!(code, "}}")?;
|
writeln!(code, "}}")?;
|
||||||
}
|
}
|
||||||
@@ -768,7 +772,11 @@ impl<'a> Codegen<'a> {
|
|||||||
let mut body_ctx: BodyContext = Default::default();
|
let mut body_ctx: BodyContext = Default::default();
|
||||||
body_ctx.expected_return_vals = ret_tuple_tys.len();
|
body_ctx.expected_return_vals = ret_tuple_tys.len();
|
||||||
body_ctx.tuple_return = true;
|
body_ctx.tuple_return = true;
|
||||||
self.generate_body(code, /* depth = */ 0, trie, " ", &mut body_ctx)?;
|
let returned =
|
||||||
|
self.generate_body(code, /* depth = */ 0, trie, " ", &mut body_ctx)?;
|
||||||
|
if !returned {
|
||||||
|
writeln!(code, " return None;")?;
|
||||||
|
}
|
||||||
writeln!(code, "}}")?;
|
writeln!(code, "}}")?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1092,9 +1100,6 @@ impl<'a> Codegen<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !returned {
|
|
||||||
writeln!(code, "{}return None;", indent)?;
|
|
||||||
}
|
|
||||||
Ok(returned)
|
Ok(returned)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user