core/model: add util::gen_for_model
This commit is contained in:
parent
1a61a000b2
commit
7f4b4597c5
|
@ -6,6 +6,7 @@ pub mod function;
|
||||||
mod int;
|
mod int;
|
||||||
mod ptr;
|
mod ptr;
|
||||||
mod structure;
|
mod structure;
|
||||||
|
pub mod util;
|
||||||
|
|
||||||
pub use any::*;
|
pub use any::*;
|
||||||
pub use array::*;
|
pub use array::*;
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
use super::*;
|
||||||
|
use crate::codegen::{
|
||||||
|
stmt::{gen_for_callback_incrementing, BreakContinueHooks},
|
||||||
|
CodeGenContext, CodeGenerator,
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Like [`gen_for_callback_incrementing`] with [`Model`] abstractions.
|
||||||
|
///
|
||||||
|
/// The value for `stop` is exclusive.
|
||||||
|
pub fn gen_for_model<'ctx, 'a, G, F, N>(
|
||||||
|
generator: &mut G,
|
||||||
|
ctx: &mut CodeGenContext<'ctx, 'a>,
|
||||||
|
start: Instance<'ctx, Int<N>>,
|
||||||
|
stop: Instance<'ctx, Int<N>>,
|
||||||
|
step: Instance<'ctx, Int<N>>,
|
||||||
|
body: F,
|
||||||
|
) -> Result<(), String>
|
||||||
|
where
|
||||||
|
G: CodeGenerator + ?Sized,
|
||||||
|
F: FnOnce(
|
||||||
|
&mut G,
|
||||||
|
&mut CodeGenContext<'ctx, 'a>,
|
||||||
|
BreakContinueHooks<'ctx>,
|
||||||
|
Instance<'ctx, Int<N>>,
|
||||||
|
) -> Result<(), String>,
|
||||||
|
N: IntKind<'ctx> + Default,
|
||||||
|
{
|
||||||
|
let int_model = Int(N::default());
|
||||||
|
gen_for_callback_incrementing(
|
||||||
|
generator,
|
||||||
|
ctx,
|
||||||
|
None,
|
||||||
|
start.value,
|
||||||
|
(stop.value, false),
|
||||||
|
|g, ctx, hooks, i| {
|
||||||
|
let i = unsafe { int_model.believe_value(i) };
|
||||||
|
body(g, ctx, hooks, i)
|
||||||
|
},
|
||||||
|
step.value,
|
||||||
|
)
|
||||||
|
}
|
Loading…
Reference in New Issue