Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
14c4c10
imm attributes, unsigned, single byte padding
zero318 Jun 29, 2022
4638a41
First batch of updated signatures
zero318 Jul 1, 2022
acb2d45
Second batch of updated signatures
zero318 Jul 2, 2022
3d0b17a
Add scratch registers for IN-StB and fix size arg sign
zero318 Jul 2, 2022
ef34549
Third batch of updated signatures
zero318 Jul 3, 2022
63b60ab
Fourth batch of updated signatures
zero318 Jul 5, 2022
76c893e
use script keyword for timelines
ExpHP Jun 24, 2022
df07b30
code for reading and writing stack ECL
ExpHP Jun 24, 2022
caeea5a
working ecl-redump for stack ecl
ExpHP Jun 26, 2022
a25638e
add arg_count so ecl-redump can roundtrip files
ExpHP Jun 26, 2022
480c25f
decompilation of stack ECL to raw output
ExpHP Jun 26, 2022
55bd66c
fix inconsistent EOF logic in read_instrs
ExpHP Jun 26, 2022
841bc9d
add decompilation of @pop, @nargs
ExpHP Jun 27, 2022
a167116
barebones compile function for stack ecl
ExpHP Jun 27, 2022
6e93ba9
finish missing details of stack ecl raw compilation
ExpHP Jun 27, 2022
24d317d
also show pseudo args for separated args
ExpHP Jun 27, 2022
285528a
decompile and compile 'o' args in stack ECL
ExpHP Jun 27, 2022
4664d95
actually use pop and nargs pseudos when compiling with signatures
ExpHP Jun 27, 2022
fc634bd
add 'p' abi format
ExpHP Jun 30, 2022
8bbc4fe
allow exprs in rel time labels and interrupts
ExpHP Jul 4, 2022
bac441d
update tests for exprs in rel time and interrupt
ExpHP Jul 4, 2022
cba6213
Update CHANGELOG.md
ExpHP Jul 4, 2022
500189a
Update CHANGELOG.md
ExpHP Jul 4, 2022
2ca04a2
allow enums internally to be floats or strings
ExpHP Jul 5, 2022
7151436
define EclSubName enum consts
ExpHP Jul 5, 2022
ee694bf
make P use stack ECL enum name
ExpHP Jul 5, 2022
899b01d
correctly type-check enums
ExpHP Jul 6, 2022
792be8a
Merge commit '919108a389dbc1a4210ff02b91595fcb63398454' into re-zero-2
ExpHP Aug 26, 2025
849a09d
(now no-op) please let the merge work
zero318 Jul 5, 2022
95aea7b
Merge branch 're-zero-2' into main-2
ExpHP Aug 27, 2025
a929a90
warn on nonzero padding
ExpHP Aug 27, 2025
a0bad4c
adding this Makefile to VCS
ExpHP Aug 27, 2025
af48268
stop classifying the 8 to bezier as padding
ExpHP Aug 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@
* **Bitwise negation.** The unary `~` (bitwise not) operator has been added. No language natively provides it, but even when unavailable, it can be used (and will compile as `-1 - x`).
* **`--no-builtin-mapfiles`** option for both compilation and decompilation. This will disable the core mapfiles which provide the builtin signatures and intrinsic mappings for all games, which can be useful if you are trying to design a comprehensive mapfile from scratch.

<<<<<<< HEAD
## Other changes
||||||| 919108a
## Other bugfixes
=======
## Other changes

* Relative time labels and interrupts now accept expressions, so you can use consts. Technically this also makes negative relative time labels possible; whether you choose to write them as `+(-15):` or (gasp) `+-15:` is up to you...
>>>>>>> re-zero-2

* The ternary operator `a ? b : c` can now be used in any expression, not just const expressions.
* Relative time labels and interrupts now accept expressions, so you can use consts. Technically this also makes negative relative time labels possible; whether you choose to write them as `+(-15):` or (gasp) `+-15:` is up to you...
Expand Down
5 changes: 4 additions & 1 deletion src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,10 @@ pub enum Expr {
LitInt {
value: raw::LangInt,
/// A hint to the formatter on how it should write the integer.
/// (not meaningful when parsing)
///
/// (not meaningful/left as default when parsing source code;
/// if you want an integer in a diagnostic to appear as it was written,
/// consider labeling its span in the message instead)
format: IntFormat,
},
LitFloat { value: raw::LangFloat },
Expand Down
22 changes: 3 additions & 19 deletions src/context/defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1252,34 +1252,18 @@ impl Signature {
signature_from_func_ast(ty_keyword, params)
}

pub(crate) fn validate(&self, ctx: &CompilerContext) -> Result<(), ErrorReported> {
self._check_non_optional_after_optional(ctx)
}

fn _check_non_optional_after_optional(&self, ctx: &CompilerContext) -> Result<(), ErrorReported> {
let mut first_optional = None;
for param in self.params.iter() {
if param.default.is_some() {
first_optional = Some(param);
} else if let Some(optional) = first_optional {
return Err(ctx.emitter.emit(error!(
message("invalid function signature"),
secondary(optional.useful_span, "optional parameter"),
primary(param.useful_span, "non-optional parameter after optional"),
)));
}
}
pub(crate) fn validate(&self, _ctx: &CompilerContext) -> Result<(), ErrorReported> {
Ok(())
}

/// Minimum number of arguments accepted.
pub fn min_args(&self) -> usize {
self.params.iter().take_while(|param| param.default.is_none()).count()
self.params.iter().fold(0, |count, param| count + param.default.is_none() as usize)
}

/// Maximum number of arguments accepted.
pub fn max_args(&self) -> usize {
self.params.len()
self.min_args()
}

/// Matches arguments at a call site to their corresponding parameters.
Expand Down
145 changes: 79 additions & 66 deletions src/core_mapfiles/anm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,35 +49,35 @@ static ANM_INS_06: &'static CoreSignatures = &CoreSignatures {
(Th06, 0, Some(("", None))),
(Th06, 1, Some(("n", None))),
(Th06, 2, Some(("ff", None))),
(Th06, 3, Some(("S", None))),
(Th06, 4, Some(("C", None))),
(Th06, 3, Some(("b(hex)---", None))),
(Th06, 4, Some(("b(hex)b(hex)b(hex)-", None))),
(Th06, 5, Some(("o", Some(IKind::Jmp)))),
(Th06, 6, Some(("", None))),
(Th06, 7, Some(("", None))),
(Th06, 8, Some(("", None))),
(Th06, 9, Some(("fff", None))),
(Th06, 10, Some(("fff", None))),
(Th06, 11, Some(("ff", None))),
(Th06, 12, Some(("SS", None))),
(Th06, 12, Some(("b(hex)---s--", None))),
(Th06, 13, Some(("", None))),
(Th06, 14, Some(("", None))),
(Th06, 15, Some(("", None))),
(Th06, 16, Some(("nS", None))),
(Th06, 16, Some(("nu--", None))),
(Th06, 17, Some(("fff", None))),
(Th06, 18, Some(("fffS", None))),
(Th06, 19, Some(("fffS", None))),
(Th06, 20, Some(("fffS", None))),
(Th06, 18, Some(("fffs--", None))),
(Th06, 19, Some(("fffs--", None))),
(Th06, 20, Some(("fffs--", None))),
(Th06, 21, Some(("", None))),
(Th06, 22, Some(("S", Some(IKind::InterruptLabel)))),
(Th06, 23, Some(("", None))),
(Th06, 24, Some(("", None))),
(Th06, 25, Some(("S", None))),
(Th06, 26, Some(("S", None))),
(Th06, 25, Some((r#"U(enum="bool")"#, None))), // zero: U(enum="BitBool")
(Th06, 26, Some(("s--", None))),
(Th06, 27, Some(("f", None))),
(Th06, 28, Some(("f", None))),
(Th06, 29, Some(("S", None))),
(Th06, 30, Some(("ffS", None))),
(Th06, 31, Some(("S", None))),
(Th06, 29, Some((r#"U(enum="bool")"#, None))), // zero: U(enum="BitBool")
(Th06, 30, Some(("ffs--", None))),
(Th06, 31, Some((r#"U(enum="bool")"#, None))), // zero: U(enum="BitBool")
],
var: &[],
};
Expand All @@ -86,44 +86,44 @@ static ANM_INS_06: &'static CoreSignatures = &CoreSignatures {
static ANM_INS_07_09: &'static CoreSignatures = &CoreSignatures {
inherit: &[],
ins: &[
// v2
// v2 (PCB)
(Th07, 0, Some(("", None))),
(Th07, 1, Some(("", None))),
(Th07, 2, Some(("", None))),
(Th07, 3, Some(("n", None))),
(Th07, 4, Some(("ot", Some(IKind::Jmp)))),
(Th07, 5, Some(("Sot", Some(IKind::CountJmp(B::Ne))))),
(Th07, 5, Some(("Sot", Some(IKind::CountJmp(B::Gt))))),
(Th07, 6, Some(("fff", None))),
(Th07, 7, Some(("ff", None))),
(Th07, 8, Some(("S", None))),
(Th07, 9, Some(("S", None))),
(Th07, 8, Some(("b(imm;hex)---", None))),
(Th07, 9, Some(("b(imm;hex)b(imm;hex)b(imm;hex)-", None))),
(Th07, 10, Some(("", None))),
(Th07, 11, Some(("", None))),
(Th07, 12, Some(("fff", None))),
(Th07, 13, Some(("fff", None))),
(Th07, 14, Some(("ff", None))),
(Th07, 15, Some(("SS", None))),
(Th07, 16, Some(("S", None))),
(Th07, 15, Some(("b(imm;hex)---S", None))),
(Th07, 16, Some(("U(imm)", None))),
(Th07, 17, Some(("fffS", None))),
(Th07, 18, Some(("fffS", None))),
(Th07, 19, Some(("fffS", None))),
(Th07, 20, Some(("", None))),
(Th07, 21, Some(("S", Some(IKind::InterruptLabel)))),
(Th07, 21, Some(("S(imm)", Some(IKind::InterruptLabel)))),
(Th07, 22, Some(("", None))),
(Th07, 23, Some(("", None))),
(Th07, 24, Some(("S", None))),
(Th07, 25, Some(("S", None))),
(Th07, 24, Some((r#"U(imm;enum="bool")"#, None))), // zero: U(imm;enum="BitBool")
(Th07, 25, Some(("s(imm)--", None))),
(Th07, 26, Some(("f", None))),
(Th07, 27, Some(("f", None))),
(Th07, 28, Some(("S", None))),
(Th07, 28, Some((r#"U(imm;enum="bool")"#, None))), // zero: U(imm;enum="BitBool")
(Th07, 29, Some(("ffS", None))),
(Th07, 30, Some(("S", None))),
(Th07, 31, Some(("S", None))),
(Th07, 32, Some(("SSfff", None))),
(Th07, 33, Some(("SSS", None))),
(Th07, 34, Some(("SSS", None))),
(Th07, 35, Some(("SSfff", None))),
(Th07, 36, Some(("SSff", None))),
(Th07, 30, Some((r#"U(imm;enum="bool")"#, None))), // zero: U(imm;enum="BitBool")
(Th07, 31, Some((r#"U(imm;enum="bool")"#, None))), // zero: U(imm;enum="BitBool")
(Th07, 32, Some(("Sb(imm)---fff", None))),
(Th07, 33, Some(("Sb(imm)---b(imm;hex)b(imm;hex)b(imm;hex)-", None))),
(Th07, 34, Some(("Sb(imm)---b(imm;hex)---", None))),
(Th07, 35, Some(("Sb(imm)---fff", None))),
(Th07, 36, Some(("Sb(imm)---ff", None))),
(Th07, 37, Some(("SS", Some(IKind::AssignOp(A::Assign, Ty::Int))))),
(Th07, 38, Some(("ff", Some(IKind::AssignOp(A::Assign, Ty::Float))))),
(Th07, 39, Some(("SS", Some(IKind::AssignOp(A::Add, Ty::Int))))),
Expand All @@ -146,7 +146,7 @@ static ANM_INS_07_09: &'static CoreSignatures = &CoreSignatures {
(Th07, 56, Some(("fff", Some(IKind::BinOp(B::Div, Ty::Float))))),
(Th07, 57, Some(("SSS", Some(IKind::BinOp(B::Rem, Ty::Int))))),
(Th07, 58, Some(("fff", Some(IKind::BinOp(B::Rem, Ty::Float))))),
(Th07, 59, Some(("SS", None))),
(Th07, 59, Some(("SU", None))),
(Th07, 60, Some(("ff", None))),
(Th07, 61, Some(("ff", Some(IKind::UnOp(U::Sin, Ty::Float))))),
(Th07, 62, Some(("ff", Some(IKind::UnOp(U::Cos, Ty::Float))))),
Expand All @@ -170,18 +170,22 @@ static ANM_INS_07_09: &'static CoreSignatures = &CoreSignatures {
(Th07, 80, Some(("f", None))),
(Th07, 81, Some(("f", None))),

// v3
// color instructions changed to take 3 dwords
(Th08, 9, Some(("SSS", None))),
(Th08, 33, Some(("SSSSS", None))),
// v3, v3b (IN, PoFV)
// alpha/color/alphaTime/colorTime instructions changed to take dword variables
// alphaTimeLinear not updated
(Th08, 8, Some(("C", None))),
(Th08, 9, Some(("CCC", None))),
(Th08, 16, Some((r#"U(imm;enum="bool")"#, None))),
(Th08, 33, Some(("Sb(imm)---CCC", None))),
(Th08, 34, Some(("Sb(imm)---C", None))),
// new instructions
(Th08, 82, Some(("S", None))),
(Th08, 83, Some(("S", None))),
(Th08, 84, Some(("SSS", None))),
(Th08, 85, Some(("S", None))),
(Th08, 86, Some(("SSSSS", None))),
(Th08, 87, Some(("SSS", None))),
(Th08, 88, Some(("S", None))),
(Th08, 82, Some(("U(imm)", None))),
(Th08, 83, Some(("S(imm)", None))),
(Th08, 84, Some(("CCC", None))),
(Th08, 85, Some(("C", None))),
(Th08, 86, Some(("Sb(imm)---CCC", None))),
(Th08, 87, Some(("Sb(imm)---C", None))),
(Th08, 88, Some(("-b(imm)--", None))),
(Th08, 89, Some(("", None))),
],
var: &[],
Expand All @@ -191,6 +195,7 @@ static ANM_INS_07_09: &'static CoreSignatures = &CoreSignatures {
static ANM_INS_095_128: &'static CoreSignatures = &CoreSignatures {
inherit: &[],
ins: &[
// v4 (StB)
(Th095, 0, Some(("", None))),
(Th095, 1, Some(("", None))),
(Th095, 2, Some(("", None))),
Expand Down Expand Up @@ -242,46 +247,49 @@ static ANM_INS_095_128: &'static CoreSignatures = &CoreSignatures {
(Th095, 48, Some(("fff", None))),
(Th095, 49, Some(("fff", None))),
(Th095, 50, Some(("ff", None))),
(Th095, 51, Some(("S", None))),
(Th095, 52, Some(("SSS", None))),
(Th095, 51, Some(("C", None))),
(Th095, 52, Some(("CCC", None))),
(Th095, 53, Some(("fff", None))),
(Th095, 54, Some(("ff", None))),
(Th095, 55, Some(("SS", None))),
(Th095, 56, Some(("SSfff", None))),
(Th095, 57, Some(("SSSSS", None))),
(Th095, 58, Some(("SSS", None))),
(Th095, 59, Some(("SSfff", None))),
(Th095, 60, Some(("SSff", None))),
(Th095, 55, Some(("b(imm;hex)---S", None))),
(Th095, 56, Some(("Sb(imm)---fff", None))),
(Th095, 57, Some(("Sb(imm)---CCC", None))),
(Th095, 58, Some(("Sb(imm)---C", None))),
(Th095, 59, Some(("Sb(imm)---fff", None))),
(Th095, 60, Some(("Sb(imm)---ff", None))),
(Th095, 61, Some(("", None))),
(Th095, 62, Some(("", None))),
(Th095, 63, Some(("", None))),
(Th095, 64, Some(("S", Some(IKind::InterruptLabel)))),
(Th095, 65, Some(("ss", None))),
(Th095, 66, Some(("S", None))),
(Th095, 67, Some(("S", None))),
(Th095, 68, Some(("S", None))),
(Th095, 64, Some(("S(imm)", Some(IKind::InterruptLabel)))),
(Th095, 65, Some(("u(imm)u(imm)", None))),
(Th095, 66, Some(("U(imm)", None))),
(Th095, 67, Some(("U(imm)", None))),
(Th095, 68, Some(("b(imm)---", None))),
(Th095, 69, Some(("", None))),
(Th095, 70, Some(("f", None))),
(Th095, 71, Some(("f", None))),
(Th095, 72, Some(("S", None))),
(Th095, 73, Some(("S", None))),
(Th095, 74, Some(("S", None))),
(Th095, 72, Some((r#"U(imm;enum="bool")"#, None))), // zero: U(imm;enum="BitBool")
(Th095, 73, Some((r#"U(imm;enum="bool")"#, None))), // zero: U(imm;enum="BitBool")
(Th095, 74, Some((r#"U(imm;enum="bool")"#, None))), // zero: U(imm;enum="BitBool")
(Th095, 75, Some(("S", None))),
(Th095, 76, Some(("SSS", None))),
(Th095, 77, Some(("S", None))),
(Th095, 78, Some(("SSSSS", None))),
(Th095, 79, Some(("SSS", None))),
(Th095, 80, Some(("S", None))),
(Th095, 80, Some(("b(imm)---", None))),
(Th095, 81, Some(("", None))),
(Th095, 82, Some(("S", None))),
(Th095, 82, Some((r#"b(imm;enum="bool")---"#, None))), // zero: b(imm;enum="BitBool")---
(Th095, 83, Some(("", None))),
(Th095, 84, Some(("S", None))),
(Th095, 85, Some(("S", None))),
(Th095, 86, Some(("S", None))),
(Th095, 87, Some(("S", None))),
(Th095, 85, Some((r#"b(imm;enum="bool")---"#, None))), // zero: b(imm;enum="BitBool")---
(Th095, 86, Some((r#"U(enum="bool")"#, None))), // zero: U(enum="BitBool")
(Th095, 87, Some(("b(imm)---", None))),

// v4b (MoF)
(Th10, 56, Some(("SU(imm)fff", None))),
(Th10, 59, Some(("SU(imm)fff", None))),
(Th10, 88, Some(("N", None))),
(Th10, 89, Some(("S", None))),
(Th10, 89, Some((r#"U(imm;enum="bool")"#, None))), // zero: U(imm;enum="BitBool")
(Th10, 90, Some(("N", None))),
(Th10, 91, Some(("N", None))),
(Th10, 92, Some(("N", None))),
Expand Down Expand Up @@ -475,6 +483,7 @@ static ANM_VAR: &'static CoreSignatures = &CoreSignatures {
inherit: &[],
ins: &[],
var: &[
// v2, v3 (PCB, IN)
(Th07, 10000, Some("$")),
(Th07, 10001, Some("$")),
(Th07, 10002, Some("$")),
Expand All @@ -486,13 +495,17 @@ static ANM_VAR: &'static CoreSignatures = &CoreSignatures {
(Th07, 10008, Some("$")),
(Th07, 10009, Some("$")),

(Th095, 10010, Some("%")),
(Th095, 10011, Some("%")),
(Th095, 10012, Some("%")),
// v3b (PoFV)
(Th09, 10010, Some("%")),
(Th09, 10011, Some("%")),
(Th09, 10012, Some("%")),

// v4 (StB)
(Th095, 10013, Some("%")),
(Th095, 10014, Some("%")),
(Th095, 10015, Some("%")),

// v4b (MoF)
(Th10, 10016, Some("%")),
(Th10, 10017, Some("%")),
(Th10, 10018, Some("%")),
Expand Down
Loading