Skip to content

Commit

Permalink
Fix label references on control statements
Browse files Browse the repository at this point in the history
Signed-off-by: Miquel Sabaté Solà <[email protected]>
  • Loading branch information
mssola committed Dec 18, 2024
1 parent 67b8f14 commit a9f50ef
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion lib/xixanta/src/assembler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,7 @@ impl Assembler {
Some(args) => {
for arg in args {
// Evaluate the argument as a node.
self.literal_mode = None;
let mut bundle = self.evaluate_node(arg)?;

// If there is a missmatch between the expected number of
Expand All @@ -904,7 +905,7 @@ impl Assembler {
_ => panic!("bad argument when evaluating arguments"),
}
}
self.push_bundle(bundle, node)?;
self.push_bundle(bundle, arg)?;
}
}
None => {
Expand Down Expand Up @@ -2520,6 +2521,51 @@ code:
assert_eq!(bundles[2].bytes[2], 0x80);
}

#[test]
fn proc_reference_another_segment() {
let mut asm = Assembler::new(one_two().to_vec());
asm.mappings[0].segments[0].bundles = minimal_header();
asm.mappings[0].offset = 6;
let bundles = &asm
.assemble(
r#"
.segment "ONE"
.addr code
.segment "TWO"
nop
code:
rts
"#
.as_bytes(),
)
.unwrap()[0x10..]; // Ignoring HEADER

assert_eq!(bundles[0].size, 2);
assert_eq!(bundles[0].bytes[0], 0x03);
assert_eq!(bundles[0].bytes[1], 0x80);
}

#[test]
fn cannot_fit_address_in_one_byte() {
let mut asm = Assembler::new(one_two().to_vec());
assert_error_with_assembler(
&mut asm,
r#".segment "ONE"
.byte code
.segment "TWO"
nop
code:
rts
"#,
"Evaluation",
2,
false,
"expecting an argument that fits into a byte",
);
}

#[test]
fn cannot_switch_to_segment_inside_of_scope() {
let mut asm = Assembler::new(EMPTY.to_vec());
Expand Down

0 comments on commit a9f50ef

Please sign in to comment.