Skip to main content

ExprCodegen

Struct ExprCodegen 

Source
pub(crate) struct ExprCodegen<'cx, 'db> {
    cx: &'cx mut Cx<'db>,
    generics: Map<SymVariable<'db>, SymGenericTerm<'db>>,
    wasm_locals: Vec<ValType>,
    wasm_stack_pointer: WasmLocal,
    wasm_stack_frame_size: u32,
    variables: Map<SymVariable<'db>, Arc<WasmPlaceRepr>>,
    instructions: Vec<Instruction<'static>>,
}

Fields§

§cx: &'cx mut Cx<'db>§generics: Map<SymVariable<'db>, SymGenericTerm<'db>>

Values of any generic variables

§wasm_locals: Vec<ValType>

Accumulates wasm locals. We make no effort to reduce the number of local variables created.

§wasm_stack_pointer: WasmLocal

Local variable that stores starting address in our stack frame

§wasm_stack_frame_size: u32

Values we are putting onto the stack frame (actually located in the WASM heap)

§variables: Map<SymVariable<'db>, Arc<WasmPlaceRepr>>

Maps each Dada variable to a range of wasm locals. Note that a single value can be inlined into multiple wasm locals.

§instructions: Vec<Instruction<'static>>

Accumulates wasm instructions.

Implementations§

Source§

impl<'db> ExprCodegen<'_, 'db>

Source

pub(super) fn next_stack_frame(&self) -> WasmPointer

Returns a WasmPointer to the current start of a callee’s stack frame. This value is only valid until Self::insert_variable is next called.

Source

pub(super) fn insert_variable(&mut self, lv: SymVariable<'db>, ty: SymTy<'db>)

Introduce the variable lv into scope and create a place for it. This can allocate more stack space in WASM memory. You can find this place by invoking Self::place_for_local later on.

Source

pub(super) fn place_for_local( &self, local_variable: SymVariable<'db>, ) -> Arc<WasmPlaceRepr>

The representation of the place represented by local_variable.

Source

pub(super) fn place(&self, place: SymPlaceExpr<'db>) -> Arc<WasmPlaceRepr>

The representation of the given Dada place.

Source

pub(super) fn push_from(&mut self, place: &WasmPlaceRepr)

Push the value found in place onto the WASM stack.

Source

pub(super) fn push_shared_from(&mut self, place: &WasmPlaceRepr)

Push a shared copy the value found in place onto the WASM stack.

Source

pub(super) fn push_leased_from(&mut self, place: &WasmPlaceRepr)

Push a shared copy the value found in place onto the WASM stack.

Source

pub(super) fn pop_and_store(&mut self, to_place: &WasmPlaceRepr)

Given that a value of type value_ty is on the wasm stack, pop it and store it into to_place.

Source

fn field_place( &self, owner_place_repr: Arc<WasmPlaceRepr>, owner_ty: SymTy<'db>, field: SymField<'db>, ) -> Arc<WasmPlaceRepr>

Representation for the place storing a given field found in an owner of type owner_ty that is stored in owner_place.

Source

fn emplace_local(&mut self, repr: &WasmRepr) -> Arc<WasmPlaceRepr>

Returns the representation of a “local” storing a value of type repr. A “local” place is one that uses WASM local variables as much as possible.

Source

fn emplace_memory(&mut self, repr: &WasmRepr) -> Arc<WasmPlaceRepr>

The representation for a Dada place found in WASM memory that stores values with representation repr.

Source

fn fresh_local_index(&mut self, v: ValType) -> WasmLocal

Create a fresh local index storing a value of type v.

Source

fn fresh_memory_slot(&mut self, v: ValType) -> WasmPointer

Create a fresh slot in memory storing a value of type v.

Source

fn push_from_local(&mut self, val_type: ValType, local: WasmLocal)

Push a value of type val_type found in local.

Source

fn pop_to_local(&mut self, v: ValType, local: WasmLocal)

Pop a value of type val_type and store it in local.

Source

fn push_from_memory(&mut self, v: ValType, _: WasmPointer)

Push a value of type val_type found in the given memory slot.

Source

pub(super) fn push_pointer(&mut self, _: WasmPointer)

Push a pointer itself onto the WASM stack (not the data it refers to).

Source

fn pop_to_memory(&mut self, v: ValType, _: WasmPointer)

Pop a value of type val_type and store it to the given memory slot.

Source§

impl<'cx, 'db> ExprCodegen<'cx, 'db>

Source

pub fn new( cx: &'cx mut Cx<'db>, generics: Map<SymVariable<'db>, SymGenericTerm<'db>>, ) -> Self

Source

pub fn into_function(self) -> Function

Source

pub fn wasm_repr_of_type(&self, ty: SymTy<'db>) -> WasmRepr

Returns the WasmRepr for a Dada type.

Source

pub fn pop_arguments( &mut self, inputs: &[SymVariable<'db>], input_tys: &[SymTy<'db>], )

Source

pub fn push_expr(&mut self, expr: SymExpr<'db>)

Generate code to execute the expression, leaving the result on the top of the wasm stack.

Source

fn pop_and_drop(&mut self, _of_type: SymTy<'db>)

Source

pub(super) fn pop_and_return(&mut self, _of_type: SymTy<'db>)

Source

fn execute_binary_op( &mut self, binary_op: SymBinaryOp, lhs_ty: SymTy<'db>, rhs_ty: SymTy<'db>, )

Push the correct instructions to execute binary_op on operands of type lhs_ty and rhs_ty

Source

fn execute_binary_op_on_primitives( &mut self, binary_op: SymBinaryOp, prim_kind: SymPrimitiveKind, )

Push the correct instructions to execute binary_op on operands of type prim_kind

Source

fn primitive_kind( &self, ty: SymTy<'db>, ) -> Result<SymPrimitiveKind, NotPrimitive>

Return the primitive kind that represents ty or Err if ty is not a primitive.

Source

fn push_match_expr(&mut self, match_ty: SymTy<'db>, arms: &[SymMatchArm<'db>])

Source

fn block_type(&mut self, match_ty: SymTy<'db>) -> BlockType

Block control-flow instructions like if and friends come equipped with an associated “block type”. This is a function type indicating the inputs they consume from the stack (in our case, always none) and the outputs they produce. As a shorthand, if they produce nothing or a single value, there is a shorthand form. This function converts an object-type into this form.

Source

fn push_literal(&mut self, ty: SymTy<'db>, literal: SymLiteral)

Source

fn push_error(&mut self, _reported: Reported)

Auto Trait Implementations§

§

impl<'cx, 'db> Freeze for ExprCodegen<'cx, 'db>

§

impl<'cx, 'db> !RefUnwindSafe for ExprCodegen<'cx, 'db>

§

impl<'cx, 'db> !Send for ExprCodegen<'cx, 'db>

§

impl<'cx, 'db> !Sync for ExprCodegen<'cx, 'db>

§

impl<'cx, 'db> Unpin for ExprCodegen<'cx, 'db>

§

impl<'cx, 'db> UnsafeUnpin for ExprCodegen<'cx, 'db>

§

impl<'cx, 'db> !UnwindSafe for ExprCodegen<'cx, 'db>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Lookup<T> for T

§

fn into_owned(self) -> T

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T