sage::lir

Trait BinaryOp

Source
pub trait BinaryOp:
    Debug
    + Display
    + Send
    + Sync {
    // Required methods
    fn clone_box(&self) -> Box<dyn BinaryOp>;
    fn can_apply(
        &self,
        lhs: &Type,
        rhs: &Type,
        env: &Env,
    ) -> Result<bool, Error>;
    fn eval(
        &self,
        lhs: &ConstExpr,
        rhs: &ConstExpr,
        env: &mut Env,
    ) -> Result<ConstExpr, Error>;
    fn compile_types(
        &self,
        lhs: &Type,
        rhs: &Type,
        env: &mut Env,
        output: &mut dyn AssemblyProgram,
    ) -> Result<(), Error>;

    // Provided methods
    fn name(&self) -> String { ... }
    fn type_check(&self, lhs: &Expr, rhs: &Expr, env: &Env) -> Result<(), Error> { ... }
    fn return_type(
        &self,
        lhs: &Expr,
        rhs: &Expr,
        env: &Env,
    ) -> Result<Type, Error> { ... }
    fn display(&self, lhs: &Expr, rhs: &Expr) -> String { ... }
    fn can_apply_exprs(
        &self,
        lhs: &Expr,
        rhs: &Expr,
        env: &Env,
    ) -> Result<bool, Error> { ... }
    fn compile(
        &self,
        lhs: &Expr,
        rhs: &Expr,
        env: &mut Env,
        output: &mut dyn AssemblyProgram,
    ) -> Result<(), Error> { ... }
}
Expand description

A trait used to implement a binary operation.

This trait is used to implement binary operations like + and ==.

Required Methods§

Source

fn clone_box(&self) -> Box<dyn BinaryOp>

Clones the operation into a boxed trait object.

Source

fn can_apply(&self, lhs: &Type, rhs: &Type, env: &Env) -> Result<bool, Error>

Checks if the operation can be applied to the given types.

Source

fn eval( &self, lhs: &ConstExpr, rhs: &ConstExpr, env: &mut Env, ) -> Result<ConstExpr, Error>

Evaluates the operation on the given constant expressions.

Source

fn compile_types( &self, lhs: &Type, rhs: &Type, env: &mut Env, output: &mut dyn AssemblyProgram, ) -> Result<(), Error>

Compiles the operation on the given types. (Generates the code for the operation.)

Provided Methods§

Source

fn name(&self) -> String

Source

fn type_check(&self, lhs: &Expr, rhs: &Expr, env: &Env) -> Result<(), Error>

Typechecks the operation on the given expressions.

Source

fn return_type(&self, lhs: &Expr, rhs: &Expr, env: &Env) -> Result<Type, Error>

Gets the type of the operation on the given expressions.

Source

fn display(&self, lhs: &Expr, rhs: &Expr) -> String

Formats the operation for display.

Source

fn can_apply_exprs( &self, lhs: &Expr, rhs: &Expr, env: &Env, ) -> Result<bool, Error>

Checks if the operation can be applied to the given expressions.

Source

fn compile( &self, lhs: &Expr, rhs: &Expr, env: &mut Env, output: &mut dyn AssemblyProgram, ) -> Result<(), Error>

Compiles the operation on the given expressions.

Trait Implementations§

Source§

impl Clone for Box<dyn BinaryOp>

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Ord for dyn BinaryOp

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
Source§

impl PartialEq for dyn BinaryOp

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for dyn BinaryOp

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for dyn BinaryOp

Implementors§