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>
impl<L> Assembly<'_, L>
Sourcepub fn map<F, M>(self, f: F) -> Assembly<'static, M>
pub fn map<F, M>(self, f: F) -> Assembly<'static, M>
Applies the given mapping function to all labels within the assembly.
Sourcepub fn assemble(&self) -> Result<BytesMut, AssemblerError<L>>
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)
5fn main() {
6 let main_label = 0;
7 let hello_sailor_label = 1;
8 let fail_label = 2;
9
10 let assembly: Assembly<i32> = Assembly {
11 rom_items: Cow::Owned(vec![
12 // The string we'll print. Add some newlines at the beginning so
13 // that the "game session has ended" message doesn't cover it.
14 label(hello_sailor_label),
15 mystery_string(&"\n\n\nHello, sailor!\n"),
16 // Header for our main function, which uses no locals.
17 label(main_label),
18 fnhead_stack(0),
19 // Set Glk as our IO system.
20 setiosys(imm(2), imm(0)),
21 // Push arguments to create our main window
22 // rock = 0
23 copy(imm(0), push()),
24 // wintype = Textbuffer
25 copy(imm(3), push()),
26 // size = 0 (ignored for root window)
27 copy(imm(0), push()),
28 // method = 0 (ignored for root window)
29 copy(imm(0), push()),
30 // split = 0
31 copy(imm(0), push()),
32 // call glk_window_open (0x23) with these five arguments. Push the
33 // return value to the stack.
34 glk(imm(0x23), imm(5), push()),
35 // Duplicate the return value on the stack.
36 stkcopy(imm(1)),
37 // Jump to fail_label if we got a null return.
38 jz(pop(), fail_label),
39 // Call glk_set_window (0x21) with one argument (the winid that's on
40 // the stack) to set our new window as current.
41 glk(imm(0x2f), imm(1), discard()),
42 // Print our message.
43 streamstr(imml(hello_sailor_label)),
44 // Return from main.
45 label(fail_label),
46 ret(imm(0)),
47 ]),
48 ram_items: Cow::Owned(vec![]),
49 zero_items: Cow::Owned(vec![]),
50 stack_size: 256,
51 start_func: LabelRef(main_label, 0),
52 decoding_table: None,
53 };
54
55 let bytes = assembly.assemble().unwrap();
56 let mut stdout = std::io::stdout();
57 stdout.write_all(&bytes).unwrap();
58}
Trait Implementations§
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>
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>where
L: UnwindSafe + RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more