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§context: Value§frame: ValueThe 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>
impl<M: Module> Body<'_, '_, '_, M>
Sourcepub(super) fn download(
&mut self,
download: &Download,
span: Span,
) -> Result<(), CodegenError>
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.
Sourcefn download_bindings(
&mut self,
places: &[(u8, Value)],
) -> Result<Value, CodegenError>
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.
Sourcepub(super) fn download_command(
&mut self,
command: DownloadCommand,
id: &Expr,
) -> Result<(), CodegenError>
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.
Sourcepub(super) fn format_bytes(
&mut self,
bytes: &Expr,
) -> Result<Value, CodegenError>
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>
impl<'a, 'b, 'p, M: Module> Body<'a, 'b, 'p, M>
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
Sourcepub fn succeed_here(&mut self)
pub fn succeed_here(&mut self)
Returns true here, and carries on in a new block.
fn succeed(&mut self)
Sourcefn continue_after_terminator(&mut self)
fn continue_after_terminator(&mut self)
Continues in a new block, after a terminator.
pub fn call(&mut self, function: FuncId, args: &[Value]) -> Vec<Value>
pub fn call1(&mut self, function: FuncId, args: &[Value]) -> Value
Sourcepub fn call_checked(&mut self, function: FuncId, args: &[Value])
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.
fn check(&mut self, ok: Value)
fn fail_block(&mut self) -> Block
Sourcefn fail_if(
&mut self,
condition: Value,
failure: FuncId,
span: Span,
) -> Result<(), CodegenError>
fn fail_if( &mut self, condition: Value, failure: FuncId, span: Span, ) -> Result<(), CodegenError>
Fails with failure at span when condition holds.
pub fn span(&mut self, span: Span) -> Result<Value, CodegenError>
pub fn u32(&mut self, value: usize) -> Result<Value, CodegenError>
fn usize(&mut self, value: usize) -> Result<Value, CodegenError>
pub fn address(&mut self, data: DataId) -> Value
pub fn desc(&mut self, ty: &Type) -> Result<Value, CodegenError>
Sourcefn stack(&mut self, size: usize) -> Result<Value, CodegenError>
fn stack(&mut self, size: usize) -> Result<Value, CodegenError>
A stack slot of size bytes, aligned for slots, and its address.
Sourcefn array(&mut self, values: &[Value]) -> Result<Value, CodegenError>
fn array(&mut self, values: &[Value]) -> Result<Value, CodegenError>
values, stored in order in a stack array, and its address.
fn load(&mut self, address: Value) -> Value
Sourcepub fn own(
&mut self,
operand: Operand,
ty: &Type,
) -> Result<Value, CodegenError>
pub fn own( &mut self, operand: Operand, ty: &Type, ) -> Result<Value, CodegenError>
operand, owned: retained if it was borrowed.
Sourcepub fn discard(
&mut self,
operand: Operand,
ty: &Type,
) -> Result<(), CodegenError>
pub fn discard( &mut self, operand: Operand, ty: &Type, ) -> Result<(), CodegenError>
Lets go of operand: released if it was owned.
pub fn release(&mut self, value: Value, ty: &Type) -> Result<(), CodegenError>
Sourcepub fn store(
&mut self,
place: Value,
value: Value,
ty: &Type,
) -> Result<(), CodegenError>
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.
pub fn slot(&mut self, local: usize) -> Result<Value, CodegenError>
Sourcepub fn release_locals(&mut self) -> Result<(), CodegenError>
pub fn release_locals(&mut self) -> Result<(), CodegenError>
Releases every local of the frame, as a function does before it returns.
Sourcepub fn path(&mut self, place: &Place) -> Result<Alias, CodegenError>
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.
fn index(&mut self, index: Index) -> Result<Value, CodegenError>
Sourcepub fn pointer(
&mut self,
path: &Alias,
span: Span,
) -> Result<Value, CodegenError>
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.
Sourcepub fn read(&mut self, path: &Alias, span: Span) -> Result<Value, CodegenError>
pub fn read(&mut self, path: &Alias, span: Span) -> Result<Value, CodegenError>
The value path leads to, borrowed.
Sourcepub fn list_item(
&mut self,
list: Value,
index: Value,
span: Span,
) -> Result<Value, CodegenError>
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.
pub fn block(&mut self, stmts: &Stmts) -> Result<(), CodegenError>
fn stmt(&mut self, stmt: &Stmt) -> Result<(), CodegenError>
Sourcefn assign(
&mut self,
place: &Place,
op: Option<BinaryOp>,
value: &Expr,
) -> Result<(), CodegenError>
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.
fn if_stmt( &mut self, branches: &[(Expr, Stmts)], otherwise: Option<&Stmts>, ) -> Result<(), CodegenError>
Sourcefn for_value(
&mut self,
head: &Loop,
list: &Expr,
body: &Stmts,
) -> Result<(), CodegenError>
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.
Sourcefn for_place(
&mut self,
head: &Loop,
place: &Place,
body: &Stmts,
) -> Result<(), CodegenError>
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.
Sourcefn for_range(
&mut self,
local: LocalId,
start: &Expr,
end: &Expr,
body: &Stmts,
) -> Result<(), CodegenError>
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.
Sourcefn set_index(
&mut self,
index: Option<LocalId>,
position: Value,
) -> Result<(), CodegenError>
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.
Sourcepub fn count_up(
&mut self,
len: Value,
step: impl FnMut(&mut Self, Value) -> Result<(), CodegenError>,
) -> Result<(), CodegenError>
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.
Sourcepub fn count(
&mut self,
start: Value,
end: Value,
step: impl FnMut(&mut Self, Value) -> Result<(), CodegenError>,
) -> Result<(), CodegenError>
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.
Sourcefn 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>
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.
fn return_stmt(&mut self, value: Option<&Expr>) -> Result<(), CodegenError>
Sourcefn int(&mut self, expr: &Expr) -> Result<Value, CodegenError>
fn int(&mut self, expr: &Expr) -> Result<Value, CodegenError>
An int (or bool) expression’s value.
pub fn expr(&mut self, expr: &Expr) -> Result<Operand, CodegenError>
Sourcefn aggregate(
&mut self,
parts: &[Expr],
ty: &Type,
) -> Result<Value, CodegenError>
fn aggregate( &mut self, parts: &[Expr], ty: &Type, ) -> Result<Value, CodegenError>
A list or struct of type ty holding parts, worked out in order.
Sourcefn push(&mut self, place: &Place, value: &Expr) -> Result<(), CodegenError>
fn push(&mut self, place: &Place, value: &Expr) -> Result<(), CodegenError>
The value is worked out before the place, as in the interpreter.
fn remove( &mut self, place: &Place, index: &Expr, span: Span, ) -> Result<(), CodegenError>
Sourcefn owned_all(&mut self, exprs: &[Expr]) -> Result<Vec<Value>, CodegenError>
fn owned_all(&mut self, exprs: &[Expr]) -> Result<Vec<Value>, CodegenError>
Each expression’s value, owned, in order.
Sourcefn hold(
&mut self,
operand: Operand,
ty: &Type,
next: &Expr,
) -> Result<Operand, CodegenError>
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.
Sourcefn hold_across<'e>(
&mut self,
operand: Operand,
ty: &Type,
later: impl IntoIterator<Item = &'e Expr>,
) -> Result<Operand, CodegenError>
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.
Sourcefn part_of(
&mut self,
container: Operand,
container_ty: &Type,
part: Value,
part_ty: &Type,
) -> Result<Operand, CodegenError>
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.
fn string(&mut self, text: &str) -> Result<Value, CodegenError>
fn interpolate(&mut self, segments: &[Segment]) -> Result<Value, CodegenError>
fn len(&mut self, value: &Expr) -> Result<Value, CodegenError>
fn float(&mut self, bits: Value) -> Value
fn bits(&mut self, float: Value) -> Value
fn binary( &mut self, op: BinaryOp, lhs: &Expr, rhs: &Expr, span: Span, ) -> Result<Operand, CodegenError>
fn short_circuit( &mut self, op: BinaryOp, lhs: &Expr, rhs: &Expr, ) -> Result<Operand, CodegenError>
Sourcepub fn apply(
&mut self,
op: BinaryOp,
ty: &Type,
left: Operand,
right: Operand,
span: Span,
) -> Result<Operand, CodegenError>
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.
fn int_op( &mut self, op: BinaryOp, a: Value, b: Value, span: Span, ) -> Result<Value, CodegenError>
fn float_op( &mut self, op: BinaryOp, a: Value, b: Value, ) -> Result<Value, CodegenError>
Sourcefn call_fn(
&mut self,
function: usize,
args: &[Expr],
ty: &Type,
span: Span,
) -> Result<Operand, CodegenError>
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.
Sourcefn dialog(&mut self, dialog: &Dialog, span: Span) -> Result<(), CodegenError>
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.
Sourcefn window_request(
&mut self,
action: WindowAction,
window: WindowId,
) -> Result<(), CodegenError>
fn window_request( &mut self, action: WindowAction, window: WindowId, ) -> Result<(), CodegenError>
open_window(…) or close_window(…): asks for it, done once the event finishes.
Sourcefn fail_now(&mut self, fail: FuncId, span: Span) -> Result<(), CodegenError>
fn fail_now(&mut self, fail: FuncId, span: Span) -> Result<(), CodegenError>
Calls the runtime’s fail(context, span) and leaves through the failure block.
Sourcefn place_desc(&mut self, path: &Alias) -> Result<Option<Value>, CodegenError>
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.