Enum Expr

Source
pub enum Expr {
Show 21 variants Reference(Loc, OnceCell<Type>, Path), Net(Loc, OnceCell<Type>, NetId), Word(Loc, OnceCell<Type>, Option<Width>, u64), Enum(Loc, OnceCell<Type>, Type, String), Ctor(Loc, OnceCell<Type>, String, Vec<Arc<Expr>>), Struct(Loc, OnceCell<Type>, Vec<(String, Arc<Expr>)>), Let(Loc, OnceCell<Type>, String, Arc<Expr>, Arc<Expr>), UnOp(Loc, OnceCell<Type>, UnOp, Arc<Expr>), BinOp(Loc, OnceCell<Type>, BinOp, Arc<Expr>, Arc<Expr>), If(Loc, OnceCell<Type>, Arc<Expr>, Arc<Expr>, Arc<Expr>), Match(Loc, OnceCell<Type>, Arc<Expr>, Vec<MatchArm>), Mux(Loc, OnceCell<Type>, Arc<Expr>, Arc<Expr>, Arc<Expr>), Cat(Loc, OnceCell<Type>, Vec<Arc<Expr>>), Sext(Loc, OnceCell<Type>, Arc<Expr>), ToWord(Loc, OnceCell<Type>, Arc<Expr>), Vec(Loc, OnceCell<Type>, Vec<Arc<Expr>>), IdxField(Loc, OnceCell<Type>, Arc<Expr>, String), Idx(Loc, OnceCell<Type>, Arc<Expr>, u64), IdxRange(Loc, OnceCell<Type>, Arc<Expr>, u64, u64), Call(Loc, OnceCell<Type>, Arc<FnDef>, Vec<Arc<Expr>>), Hole(Loc, OnceCell<Type>, Option<String>),
}
Expand description

An expression.

Variants§

§

Reference(Loc, OnceCell<Type>, Path)

A referenec to a port, reg, or node.

§

Net(Loc, OnceCell<Type>, NetId)

A referenec to a net. Used only in crate::sim::Sim.

§

Word(Loc, OnceCell<Type>, Option<Width>, u64)

A literal Word.

§

Enum(Loc, OnceCell<Type>, Type, String)

A literal enum value.

§

Ctor(Loc, OnceCell<Type>, String, Vec<Arc<Expr>>)

Constructor (for Valid<T>)

§

Struct(Loc, OnceCell<Type>, Vec<(String, Arc<Expr>)>)

Constructor for structs. Eg, { x = 0, y = 0}.

§

Let(Loc, OnceCell<Type>, String, Arc<Expr>, Arc<Expr>)

Let binding. Eg, let x = a + b in x + x.

§

UnOp(Loc, OnceCell<Type>, UnOp, Arc<Expr>)

A unary operation. Eg, !0b101w3.

§

BinOp(Loc, OnceCell<Type>, BinOp, Arc<Expr>, Arc<Expr>)

A binary operation. Eg, 1w8 + 1w8.

§

If(Loc, OnceCell<Type>, Arc<Expr>, Arc<Expr>, Arc<Expr>)

An if expression.

§

Match(Loc, OnceCell<Type>, Arc<Expr>, Vec<MatchArm>)

A match expression.

§

Mux(Loc, OnceCell<Type>, Arc<Expr>, Arc<Expr>, Arc<Expr>)

A multiplexer. Eg, mux(cond, a, b).

§

Cat(Loc, OnceCell<Type>, Vec<Arc<Expr>>)

A concatenate expression. Eg, cat(foo, 0w1).

§

Sext(Loc, OnceCell<Type>, Arc<Expr>)

A sign extension expression.

§

ToWord(Loc, OnceCell<Type>, Arc<Expr>)

A word expression. Used to cast user-defined enum types to their bit values.

§

Vec(Loc, OnceCell<Type>, Vec<Arc<Expr>>)

A vector constructor expression. Eg, [0w2, 1w2, 2w2].

§

IdxField(Loc, OnceCell<Type>, Arc<Expr>, String)

§

Idx(Loc, OnceCell<Type>, Arc<Expr>, u64)

A static index. Eg, foo[0].

§

IdxRange(Loc, OnceCell<Type>, Arc<Expr>, u64, u64)

A static index range. Eg, foo[8..4].

§

Call(Loc, OnceCell<Type>, Arc<FnDef>, Vec<Arc<Expr>>)

A function call. Eg, foo(x, y).

§

Hole(Loc, OnceCell<Type>, Option<String>)

A hole. Eg, ?foo.

Implementations§

Source§

impl Expr

Source

pub fn eval(&self, bitsy: &Sim) -> Value

Source§

impl Expr

Source

pub fn rebase(&self, current_path: Path) -> Arc<Expr>

Source§

impl Expr

Source

pub fn typecheck( self: &Arc<Self>, type_expected: Type, ctx: Context<Path, Type>, ) -> Result<(), TypeError>

Source

pub fn typeinfer(self: &Arc<Self>, ctx: Context<Path, Type>) -> Option<Type>

Source§

impl Expr

Source

pub fn assert_has_types(&self)

Source

pub fn with_subexprs(&self, callback: &mut dyn FnMut(&Expr))

Walk the expression tree in-order, calling callback for each subexpression.

Source

pub fn paths(&self) -> Vec<Path>

Source

pub fn is_constant(&self) -> bool

Source

pub fn free_vars(&self) -> BTreeSet<Path>

Source

pub fn depends_on(&self, path: Path) -> bool

Source

pub fn depends_on_net(&self, net_id: NetId) -> bool

Source

pub fn type_of(&self) -> Type

Trait Implementations§

Source§

impl Clone for Expr

Source§

fn clone(&self) -> Expr

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 Debug for Expr

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl HasLoc for Expr

Source§

fn loc(&self) -> Loc

Auto Trait Implementations§

§

impl !Freeze for Expr

§

impl RefUnwindSafe for Expr

§

impl Send for Expr

§

impl Sync for Expr

§

impl Unpin for Expr

§

impl UnwindSafe for Expr

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.