Struct datafusion_jit::api::CodeBlock
source · [−]pub struct CodeBlock<'a> { /* private fields */ }
Expand description
Code block consists of statements and acts as anonymous namespace scope for items and variable declarations.
Implementations
sourceimpl<'a> CodeBlock<'a>
impl<'a> CodeBlock<'a>
pub fn build(&mut self) -> GeneratedFunction
sourcepub fn declare(&mut self, name: impl Into<String>, ty: JITType) -> Result<()>
pub fn declare(&mut self, name: impl Into<String>, ty: JITType) -> Result<()>
Declare variable name
of a type.
sourcepub fn assign(&mut self, name: impl Into<String>, expr: Expr) -> Result<()>
pub fn assign(&mut self, name: impl Into<String>, expr: Expr) -> Result<()>
Assignment statement. Assign a expression value to a variable.
sourcepub fn declare_as(&mut self, name: impl Into<String>, expr: Expr) -> Result<()>
pub fn declare_as(&mut self, name: impl Into<String>, expr: Expr) -> Result<()>
Declare variable with initialization.
sourcepub fn call_stmt(
&mut self,
name: impl Into<String>,
args: Vec<Expr>
) -> Result<()>
pub fn call_stmt(
&mut self,
name: impl Into<String>,
args: Vec<Expr>
) -> Result<()>
Call external function for side effect only.
sourcepub fn if_block<C, T, E>(
&mut self,
cond: C,
then_blk: T,
else_blk: E
) -> Result<()> where
C: FnMut(&mut CodeBlock<'_>) -> Result<Expr>,
T: FnMut(&mut CodeBlock<'_>) -> Result<()>,
E: FnMut(&mut CodeBlock<'_>) -> Result<()>,
pub fn if_block<C, T, E>(
&mut self,
cond: C,
then_blk: T,
else_blk: E
) -> Result<()> where
C: FnMut(&mut CodeBlock<'_>) -> Result<Expr>,
T: FnMut(&mut CodeBlock<'_>) -> Result<()>,
E: FnMut(&mut CodeBlock<'_>) -> Result<()>,
Construct a if-then-else
block with each part provided.
E.g. if n == 0 { r = 0 } else { r = 1} could be write as: x.if_block( |cond| cond.eq(cond.id(“n”)?, cond.lit_i(0)), |t| { t.assign(“r”, t.lit_i(0))?; Ok(()) }, |e| t.assign(“r”, t.lit_i(1))?; Ok(()) }, )?;
sourcepub fn while_block<C, B>(&mut self, cond: C, body_blk: B) -> Result<()> where
C: FnMut(&mut CodeBlock<'_>) -> Result<Expr>,
B: FnMut(&mut CodeBlock<'_>) -> Result<()>,
pub fn while_block<C, B>(&mut self, cond: C, body_blk: B) -> Result<()> where
C: FnMut(&mut CodeBlock<'_>) -> Result<Expr>,
B: FnMut(&mut CodeBlock<'_>) -> Result<()>,
Construct a while
block with each part provided.
E.g. while n != 0 { n = n - 1;} could be write as: x.while_block( |cond| cond.ne(cond.id(“n”)?, cond.lit_i(0)), |w| { w.assign(“n”, w.sub(w.id(“n”)?, w.lit_i(1))?)?; Ok(()) }, )?;
sourcepub fn lit(&self, val: impl Into<String>, ty: JITType) -> Expr
pub fn lit(&self, val: impl Into<String>, ty: JITType) -> Expr
Create a literal val
of ty
type.
sourcepub fn id(&self, name: impl Into<String>) -> Result<Expr>
pub fn id(&self, name: impl Into<String>) -> Result<Expr>
Create a reference to an already defined variable.
sourcepub fn eq(&self, lhs: Expr, rhs: Expr) -> Result<Expr>
pub fn eq(&self, lhs: Expr, rhs: Expr) -> Result<Expr>
Binary comparison expression: lhs == rhs
sourcepub fn ne(&self, lhs: Expr, rhs: Expr) -> Result<Expr>
pub fn ne(&self, lhs: Expr, rhs: Expr) -> Result<Expr>
Binary comparison expression: lhs != rhs
sourcepub fn le(&self, lhs: Expr, rhs: Expr) -> Result<Expr>
pub fn le(&self, lhs: Expr, rhs: Expr) -> Result<Expr>
Binary comparison expression: lhs <= rhs
sourcepub fn ge(&self, lhs: Expr, rhs: Expr) -> Result<Expr>
pub fn ge(&self, lhs: Expr, rhs: Expr) -> Result<Expr>
Binary comparison expression: lhs >= rhs
sourcepub fn add(&self, lhs: Expr, rhs: Expr) -> Result<Expr>
pub fn add(&self, lhs: Expr, rhs: Expr) -> Result<Expr>
Binary arithmetic expression: lhs + rhs
sourcepub fn sub(&self, lhs: Expr, rhs: Expr) -> Result<Expr>
pub fn sub(&self, lhs: Expr, rhs: Expr) -> Result<Expr>
Binary arithmetic expression: lhs - rhs
sourcepub fn mul(&self, lhs: Expr, rhs: Expr) -> Result<Expr>
pub fn mul(&self, lhs: Expr, rhs: Expr) -> Result<Expr>
Binary arithmetic expression: lhs * rhs
sourcepub fn div(&self, lhs: Expr, rhs: Expr) -> Result<Expr>
pub fn div(&self, lhs: Expr, rhs: Expr) -> Result<Expr>
Binary arithmetic expression: lhs / rhs
sourcepub fn call(&self, name: impl Into<String>, params: Vec<Expr>) -> Result<Expr>
pub fn call(&self, name: impl Into<String>, params: Vec<Expr>) -> Result<Expr>
Call external function name
with parameters
Auto Trait Implementations
impl<'a> !RefUnwindSafe for CodeBlock<'a>
impl<'a> !Send for CodeBlock<'a>
impl<'a> !Sync for CodeBlock<'a>
impl<'a> Unpin for CodeBlock<'a>
impl<'a> !UnwindSafe for CodeBlock<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more