Struct glulx_asm::Assembly

source ·
pub struct Assembly<'a, L>
where L: Clone,
{ pub rom_items: Cow<'a, [Item<L>]>, pub ram_items: Cow<'a, [Item<L>]>, pub zero_items: Cow<'a, [ZeroItem<L>]>, pub stack_size: u32, pub start_func: LabelRef<L>, pub decoding_table: Option<LabelRef<L>>, }
Expand description

Collection of all inputs needed to assemble a story file.

Fields§

§rom_items: Cow<'a, [Item<L>]>

List of items which should appear in the ROM section.

§ram_items: Cow<'a, [Item<L>]>

List of items which should appear in the RAM section.

§zero_items: Cow<'a, [ZeroItem<L>]>

List of items which should have space in the RAM section and be initialized to zero.

§stack_size: u32

How much space to allocate for the stack.

§start_func: LabelRef<L>

Reference to the function to be called at the start of execution.

§decoding_table: Option<LabelRef<L>>

Reference to the initial decoding table.

Implementations§

source§

impl<L> Assembly<'_, L>
where L: Clone + Eq + Hash,

source

pub fn map<F, M>(self, f: F) -> Assembly<'static, M>
where F: FnMut(L) -> M, M: Clone,

Applies the given mapping function to all labels within the assembly.

source

pub fn assemble(&self) -> Result<BytesMut, AssemblerError<L>>

Assembles a Glulx binary, ready to be written out as a .ulx file.

Examples found in repository?
examples/hello.rs (line 55)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
fn main() {
    let main_label = 0;
    let hello_sailor_label = 1;
    let fail_label = 2;

    let assembly: Assembly<i32> = Assembly {
        rom_items: Cow::Owned(vec![
            // The string we'll print. Add some newlines at the beginning so
            // that the "game session has ended" message doesn't cover it.
            label(hello_sailor_label),
            mystery_string(&"\n\n\nHello, sailor!\n"),
            // Header for our main function, which uses no locals.
            label(main_label),
            fnhead_stack(0),
            // Set Glk as our IO system.
            setiosys(imm(2), imm(0)),
            // Push arguments to create our main window
            // rock = 0
            copy(imm(0), push()),
            // wintype = Textbuffer
            copy(imm(3), push()),
            // size = 0 (ignored for root window)
            copy(imm(0), push()),
            // method = 0 (ignored for root window)
            copy(imm(0), push()),
            // split = 0
            copy(imm(0), push()),
            // call glk_window_open (0x23) with these five arguments. Push the
            // return value to the stack.
            glk(imm(0x23), imm(5), push()),
            // Duplicate the return value on the stack.
            stkcopy(imm(1)),
            // Jump to fail_label if we got a null return.
            jz(pop(), fail_label),
            // Call glk_set_window (0x21) with one argument (the winid that's on
            // the stack) to set our new window as current.
            glk(imm(0x2f), imm(1), discard()),
            // Print our message.
            streamstr(imml(hello_sailor_label)),
            // Return from main.
            label(fail_label),
            ret(imm(0)),
        ]),
        ram_items: Cow::Owned(vec![]),
        zero_items: Cow::Owned(vec![]),
        stack_size: 256,
        start_func: LabelRef(main_label, 0),
        decoding_table: None,
    };

    let bytes = assembly.assemble().unwrap();
    let mut stdout = std::io::stdout();
    stdout.write_all(&bytes).unwrap();
}
source

pub fn to_owning(&self) -> Assembly<'static, L>

Converts all internal Cow fields to owned.

Trait Implementations§

source§

impl<'a, L> Clone for Assembly<'a, L>
where L: Clone + Clone,

source§

fn clone(&self) -> Assembly<'a, L>

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<'a, L> Debug for Assembly<'a, L>
where L: Clone + Debug,

source§

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

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

impl<L> Display for Assembly<'_, L>
where L: Display + Clone,

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, L> Freeze for Assembly<'a, L>
where L: Freeze,

§

impl<'a, L> RefUnwindSafe for Assembly<'a, L>
where L: RefUnwindSafe,

§

impl<'a, L> Send for Assembly<'a, L>
where L: Send + Sync,

§

impl<'a, L> Sync for Assembly<'a, L>
where L: Sync,

§

impl<'a, L> Unpin for Assembly<'a, L>
where L: Unpin,

§

impl<'a, L> UnwindSafe for Assembly<'a, L>

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 T)

🔬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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. 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.