Skip to main content

Operand

Trait Operand 

Source
pub trait Operand { }
Expand description

An operand of an operator: an expression, an ExprResult or a literal.

A literal is typed after the expression it meets: an integer takes its type, an f32 is a float32 constant and an f64 a float64 one.

§Examples

use tvm_tirx::ir::prim::op::add;
use tvm_tirx::ir::{PrimType, PrimVar, Var, UNKNOWN_LOC};
use tvm_tirx::script::script;

let n = PrimVar::new("n", PrimType::int(64), UNKNOWN_LOC);
assert_eq!(script(&add(&n, 1)?)?, "n + T.int64(1)");
assert_eq!(script(&add(&n, 0.5)?)?, "T.Cast(\"float64\", n) + T.float64(0.5)");
assert_eq!(script(&add(1, 2)?)?, "3");

Implementations on Foreign Types§

Source§

impl Operand for f32

A float32 constant, whatever the other side.

Source§

impl Operand for f64

A float64 constant, whatever the other side.

Source§

impl Operand for i32

A constant of the other operand’s type. i32 is what an unsuffixed literal falls back to.

Source§

impl Operand for i64

Implementors§