Skip to main content

Body

Struct Body 

Source
pub(super) struct Body<'a, 'b, 'p, M: Module> {
    pub b: &'a mut FunctionBuilder<'b>,
    pub module: &'a mut M,
    pub shared: &'a mut Shared<'p>,
    pub context: Value,
    pub frame: Value,
    pub locals: &'a [Type],
    pub aliases: HashMap<LocalId, Alias>,
    pub returns: Option<Returns>,
    fail: Option<Block>,
    scratch: Option<StackSlot>,
    temporaries: Vec<(Value, Type)>,
}

Fields§

§b: &'a mut FunctionBuilder<'b>§module: &'a mut M§shared: &'a mut Shared<'p>§context: Value§frame: Value

The locals’ slots.

§locals: &'a [Type]

The type of each of the frame’s locals.

§aliases: HashMap<LocalId, Alias>§returns: Option<Returns>§fail: Option<Block>§scratch: Option<StackSlot>

Where calls write their results, read straight after each call.

§temporaries: Vec<(Value, Type)>

Owned values held across statements, such as the list a loop walks, released if the function returns from inside.

Implementations§

Source§

impl<M: Module> Body<'_, '_, '_, M>

Source

pub(super) fn download( &mut self, download: &Download, span: Span, ) -> Result<(), CodegenError>

Asks for a download once the event finishes. The places are worked out after the address, folder and settings, as in the interpreter, so each borrowed value is held across everything worked out after it.

Source

fn download_bindings( &mut self, places: &[(u8, Value)], ) -> Result<Value, CodegenError>

Each field’s code and place, as an array of nifty_rt::DownloadBindings on the stack, and its address.

Source

pub(super) fn download_command( &mut self, command: DownloadCommand, id: &Expr, ) -> Result<(), CodegenError>

cancel_download(id) and the like: asks for it, done once the event finishes.

Source

pub(super) fn format_bytes( &mut self, bytes: &Expr, ) -> Result<Value, CodegenError>

format_bytes(n): an owned string.

Source§

impl<'a, 'b, 'p, M: Module> Body<'a, 'b, 'p, M>

Source

pub fn new( b: &'a mut FunctionBuilder<'b>, module: &'a mut M, shared: &'a mut Shared<'p>, context: Value, frame: Value, locals: &'a [Type], ) -> Self

Source

pub fn finish(self)

Returns true from where the body ended, then emits the failure block.

Source

pub fn succeed_here(&mut self)

Returns true here, and carries on in a new block.

Source

fn succeed(&mut self)

Source

fn continue_after_terminator(&mut self)

Continues in a new block, after a terminator.

Source

pub fn call(&mut self, function: FuncId, args: &[Value]) -> Vec<Value>

Source

pub fn call1(&mut self, function: FuncId, args: &[Value]) -> Value

Source

pub fn call_checked(&mut self, function: FuncId, args: &[Value])

Makes a call that returns whether it succeeded, going to the failure block if not.

Source

fn check(&mut self, ok: Value)

Source

fn fail_block(&mut self) -> Block

Source

fn fail_if( &mut self, condition: Value, failure: FuncId, span: Span, ) -> Result<(), CodegenError>

Fails with failure at span when condition holds.

Source

pub fn span(&mut self, span: Span) -> Result<Value, CodegenError>

Source

pub fn u32(&mut self, value: usize) -> Result<Value, CodegenError>

Source

fn usize(&mut self, value: usize) -> Result<Value, CodegenError>

Source

pub fn address(&mut self, data: DataId) -> Value

Source

pub fn desc(&mut self, ty: &Type) -> Result<Value, CodegenError>

Source

fn stack(&mut self, size: usize) -> Result<Value, CodegenError>

A stack slot of size bytes, aligned for slots, and its address.

Source

fn scratch(&mut self) -> Value

The address of the slot calls write their results to.

Source

fn array(&mut self, values: &[Value]) -> Result<Value, CodegenError>

values, stored in order in a stack array, and its address.

Source

fn load(&mut self, address: Value) -> Value

Source

pub fn own( &mut self, operand: Operand, ty: &Type, ) -> Result<Value, CodegenError>

operand, owned: retained if it was borrowed.

Source

pub fn discard( &mut self, operand: Operand, ty: &Type, ) -> Result<(), CodegenError>

Lets go of operand: released if it was owned.

Source

pub fn release(&mut self, value: Value, ty: &Type) -> Result<(), CodegenError>

Source

pub fn store( &mut self, place: Value, value: Value, ty: &Type, ) -> Result<(), CodegenError>

Writes an owned value of type ty to the slot at place, releasing what was there.

Source

pub fn slot(&mut self, local: usize) -> Result<Value, CodegenError>

Source

pub fn release_locals(&mut self) -> Result<(), CodegenError>

Releases every local of the frame, as a function does before it returns.

Source

pub fn path(&mut self, place: &Place) -> Result<Alias, CodegenError>

Where place is: its root, then its steps, with its list positions worked out now.

Source

fn index(&mut self, index: Index) -> Result<Value, CodegenError>

Source

pub fn pointer( &mut self, path: &Alias, span: Span, ) -> Result<Value, CodegenError>

The slot path leads to, made its only owner’s at each step so it can be changed. Writing through it marks a state root changed.

Source

pub fn read(&mut self, path: &Alias, span: Span) -> Result<Value, CodegenError>

The value path leads to, borrowed.

Source

pub fn list_item( &mut self, list: Value, index: Value, span: Span, ) -> Result<Value, CodegenError>

The item at index of the borrowed list, borrowed from it.

Source

pub fn block(&mut self, stmts: &Stmts) -> Result<(), CodegenError>

Source

fn stmt(&mut self, stmt: &Stmt) -> Result<(), CodegenError>

Source

fn assign( &mut self, place: &Place, op: Option<BinaryOp>, value: &Expr, ) -> Result<(), CodegenError>

The value is worked out before the place, as in the interpreter.

Source

fn if_stmt( &mut self, branches: &[(Expr, Stmts)], otherwise: Option<&Stmts>, ) -> Result<(), CodegenError>

Source

fn for_value( &mut self, head: &Loop, list: &Expr, body: &Stmts, ) -> Result<(), CodegenError>

Walks a copy of the list, putting each item in the loop’s item.

Source

fn for_place( &mut self, head: &Loop, place: &Place, body: &Stmts, ) -> Result<(), CodegenError>

Walks the list at place, with the loop’s item standing for each of its items in turn. The length is read each time round, so the body may change the list.

Source

fn for_range( &mut self, local: LocalId, start: &Expr, end: &Expr, body: &Stmts, ) -> Result<(), CodegenError>

Counts local from start up to, but not including, end.

Source

fn set_index( &mut self, index: Option<LocalId>, position: Value, ) -> Result<(), CodegenError>

Puts a round’s position in the loop’s index, when the loop names one.

Source

pub fn count_up( &mut self, len: Value, step: impl FnMut(&mut Self, Value) -> Result<(), CodegenError>, ) -> Result<(), CodegenError>

Runs step with each index from 0 up to len.

Source

pub fn count( &mut self, start: Value, end: Value, step: impl FnMut(&mut Self, Value) -> Result<(), CodegenError>, ) -> Result<(), CodegenError>

Runs step with each count from start up to, but not including, end.

Source

fn count_with( &mut self, counter: Variable, start: Value, end: impl FnMut(&mut Self) -> Result<Value, CodegenError>, step: impl FnMut(&mut Self, Value) -> Result<(), CodegenError>, ) -> Result<(), CodegenError>

Runs step with each value of counter from start while it is below what end gives; end is worked out again each time round.

Source

fn return_stmt(&mut self, value: Option<&Expr>) -> Result<(), CodegenError>

Source

fn int(&mut self, expr: &Expr) -> Result<Value, CodegenError>

An int (or bool) expression’s value.

Source

pub fn expr(&mut self, expr: &Expr) -> Result<Operand, CodegenError>

Source

fn nothing(&mut self) -> Operand

What an expression of type void gives.

Source

fn aggregate( &mut self, parts: &[Expr], ty: &Type, ) -> Result<Value, CodegenError>

A list or struct of type ty holding parts, worked out in order.

Source

fn push(&mut self, place: &Place, value: &Expr) -> Result<(), CodegenError>

The value is worked out before the place, as in the interpreter.

Source

fn remove( &mut self, place: &Place, index: &Expr, span: Span, ) -> Result<(), CodegenError>

Source

fn owned_all(&mut self, exprs: &[Expr]) -> Result<Vec<Value>, CodegenError>

Each expression’s value, owned, in order.

Source

fn hold( &mut self, operand: Operand, ty: &Type, next: &Expr, ) -> Result<Operand, CodegenError>

operand, kept while next is worked out: owned unless next can’t change state.

Source

fn hold_across<'e>( &mut self, operand: Operand, ty: &Type, later: impl IntoIterator<Item = &'e Expr>, ) -> Result<Operand, CodegenError>

operand, kept while each of later is worked out: owned unless none of them can change state.

Source

fn part_of( &mut self, container: Operand, container_ty: &Type, part: Value, part_ty: &Type, ) -> Result<Operand, CodegenError>

A part borrowed from container: still borrowed if the container was, and otherwise owned, since the container is released.

Source

fn string(&mut self, text: &str) -> Result<Value, CodegenError>

Source

fn interpolate(&mut self, segments: &[Segment]) -> Result<Value, CodegenError>

Source

fn len(&mut self, value: &Expr) -> Result<Value, CodegenError>

Source

fn float(&mut self, bits: Value) -> Value

Source

fn bits(&mut self, float: Value) -> Value

Source

fn binary( &mut self, op: BinaryOp, lhs: &Expr, rhs: &Expr, span: Span, ) -> Result<Operand, CodegenError>

Source

fn short_circuit( &mut self, op: BinaryOp, lhs: &Expr, rhs: &Expr, ) -> Result<Operand, CodegenError>

Source

pub fn apply( &mut self, op: BinaryOp, ty: &Type, left: Operand, right: Operand, span: Span, ) -> Result<Operand, CodegenError>

Applies op to operands of type ty, releasing whichever are owned.

Source

fn int_op( &mut self, op: BinaryOp, a: Value, b: Value, span: Span, ) -> Result<Value, CodegenError>

Source

fn float_op( &mut self, op: BinaryOp, a: Value, b: Value, ) -> Result<Value, CodegenError>

Source

fn call_fn( &mut self, function: usize, args: &[Expr], ty: &Type, span: Span, ) -> Result<Operand, CodegenError>

Calls Nifty function function. Its arguments are worked out before the call depth is checked, as in the interpreter.

Source

fn dialog(&mut self, dialog: &Dialog, span: Span) -> Result<(), CodegenError>

pick_file($path, …) and the other file dialogs: asks for one, shown once the event finishes, whose answer goes to the bound state.

Source

fn window_request( &mut self, action: WindowAction, window: WindowId, ) -> Result<(), CodegenError>

open_window(…) or close_window(…): asks for it, done once the event finishes.

Source

fn fail_now(&mut self, fail: FuncId, span: Span) -> Result<(), CodegenError>

Calls the runtime’s fail(context, span) and leaves through the failure block.

Source

fn place_desc(&mut self, path: &Alias) -> Result<Option<Value>, CodegenError>

path as a nifty_rt::PlaceDesc on the stack, or None if it isn’t in state.

Auto Trait Implementations§

§

impl<'a, 'b, 'p, M> !Send for Body<'a, 'b, 'p, M>

§

impl<'a, 'b, 'p, M> !Sync for Body<'a, 'b, 'p, M>

§

impl<'a, 'b, 'p, M> !UnwindSafe for Body<'a, 'b, 'p, M>

§

impl<'a, 'b, 'p, M> Freeze for Body<'a, 'b, 'p, M>

§

impl<'a, 'b, 'p, M> RefUnwindSafe for Body<'a, 'b, 'p, M>
where M: RefUnwindSafe,

§

impl<'a, 'b, 'p, M> Unpin for Body<'a, 'b, 'p, M>

§

impl<'a, 'b, 'p, M> UnsafeUnpin for Body<'a, 'b, 'p, M>

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> AutoreleaseSafe for T
where T: ?Sized,

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.

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, 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.