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§
Sourcefn can_apply(&self, lhs: &Type, rhs: &Type, env: &Env) -> Result<bool, Error>
fn can_apply(&self, lhs: &Type, rhs: &Type, env: &Env) -> Result<bool, Error>
Checks if the operation can be applied to the given types.
Sourcefn eval(
&self,
lhs: &ConstExpr,
rhs: &ConstExpr,
env: &mut Env,
) -> Result<ConstExpr, Error>
fn eval( &self, lhs: &ConstExpr, rhs: &ConstExpr, env: &mut Env, ) -> Result<ConstExpr, Error>
Evaluates the operation on the given constant expressions.
Sourcefn compile_types(
&self,
lhs: &Type,
rhs: &Type,
env: &mut Env,
output: &mut dyn AssemblyProgram,
) -> Result<(), Error>
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§
fn name(&self) -> String
Sourcefn type_check(&self, lhs: &Expr, rhs: &Expr, env: &Env) -> Result<(), Error>
fn type_check(&self, lhs: &Expr, rhs: &Expr, env: &Env) -> Result<(), Error>
Typechecks the operation on the given expressions.
Sourcefn return_type(&self, lhs: &Expr, rhs: &Expr, env: &Env) -> Result<Type, Error>
fn return_type(&self, lhs: &Expr, rhs: &Expr, env: &Env) -> Result<Type, Error>
Gets the type of the operation on the given expressions.