Enum bitsy_lang::Expr

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

An expression.

Variants§

§

Reference(Span, OnceCell<Type>, Path)

A referenec to a port, reg, or node.

§

Net(Span, OnceCell<Type>, NetId)

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

§

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

A literal Word.

§

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

A literal enum value.

§

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

Constructor (for Valid<T>)

§

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

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

§

Let(Span, OnceCell<Type>, String, Option<Type>, Arc<Expr>, Arc<Expr>)

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

§

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

A unary operation. Eg, !0b101w3.

§

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

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

§

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

An if expression.

§

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

A match expression.

§

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

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

§

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

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

§

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

A sign extension expression.

§

Zext(Span, OnceCell<Type>, Arc<Expr>)

A zero extension expression.

§

TryCast(Span, OnceCell<Type>, Arc<Expr>)

Try to cast a Word to an enum type.

§

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

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

§

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

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

§

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

§

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

A static index. Eg, foo[0].

§

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

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

§

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

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

§

Hole(Span, 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, 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 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 HasSpan for Expr

source§

fn span(&self) -> Span

Auto Trait Implementations§

§

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.