glulx_asm/
lib.rs

1// SPDX-License-Identifier: Apache-2.0 WITH LLVM-Exception
2// Copyright 2024 Daniel Fox Franke.
3
4//! This crate implements an assembler for the Glulx virtual machine for
5//! interactive fiction. It supports version 3.1.3 of the [Glulx
6//! specification](https://www.eblong.com/zarf/glulx/Glulx-Spec.html#moving-data).
7//!
8//! Currently, the functionality of this crate is limited to generating binary
9//! Glulx files from the in-memory data structures defined herein. It is
10//! designed and suitable as a library for use by translation tools that
11//! generate Glulx, but cannot be used as a standalone assembler. `Display`
12//! impls are provided for generating human-readable assembly listings, but the
13//! syntax is subject to change and there is no tool which parses what these
14//! impls emit. This crate may be extended with such functionality in the
15//! future.
16//!
17//! This crate's main entry point is the [`Assembly`] struct and its
18//! [`assemble`](Assembly::assemble) method, which outputs a
19//! [`BytesMut`](bytes::BytesMut) (see the [`bytes`] crate) from the public
20//! fields you create the `Assembly` from.
21//!
22//! The bulk of what you provide to the `Assembly` is a list of [`Item`]s, each
23//! of which may be tagged with a label. The label parameter is generic; you can
24//! use any type you like provided only that it implements `Clone + Eq + Hash`.
25//! Do note that the assembler is a bit indiscriminant about cloning, so if
26//! you're considering using [`String`]s as labels you may want to use something
27//! like [`Rc<str>`](alloc::rc::Rc) instead. Every type in this crate which
28//! takes a label parameter is, in the Haskell/loosely-category-theoretical
29//! sense, a functor over its labels. That is, it provides a `map` method which
30//! lets you replace every label within it with the output of a callback,
31//! possibly changing the label's type.
32//!
33//! See `examples/hello.rs` for an illustration of using this crate to assemble
34//! a story file that prints "Hello, Sailor!" and exits.
35
36#![warn(
37    clippy::as_conversions,
38    missing_copy_implementations,
39    missing_debug_implementations,
40    missing_docs
41)]
42#![cfg_attr(not(feature = "std"), no_std)]
43extern crate alloc;
44
45mod assemble;
46mod cast;
47pub mod concise;
48mod decoding_table;
49mod error;
50mod instr_def;
51mod instr_impls;
52mod items;
53mod operands;
54mod resolver;
55mod strings;
56
57pub use assemble::Assembly;
58pub use decoding_table::{DecodeArg, DecodeNode};
59pub use error::AssemblerError;
60pub use instr_def::Instr;
61pub use items::{CallingConvention, Item, LabelRef, ZeroItem};
62pub use operands::{f32_to_imm, f64_to_imm, LoadOperand, StoreOperand};
63pub use strings::{MysteryString, StringConversionError, Utf32String};