2024-12-03 19:00:27 +00:00
|
|
|
use dust_lang::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn subtract_assign() {
|
|
|
|
let source = "let mut x = 42; x -= 2; x";
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
compile(source),
|
|
|
|
Ok(Chunk::with_data(
|
|
|
|
None,
|
|
|
|
FunctionType {
|
|
|
|
type_parameters: None,
|
|
|
|
value_parameters: None,
|
2024-12-10 08:34:41 +00:00
|
|
|
return_type: Type::Integer,
|
2024-12-03 19:00:27 +00:00
|
|
|
},
|
|
|
|
vec![
|
2024-12-10 08:34:41 +00:00
|
|
|
(Instruction::load_constant(0, 0, false), Span(12, 14)),
|
2024-12-03 19:00:27 +00:00
|
|
|
(
|
2024-12-10 08:34:41 +00:00
|
|
|
Instruction::subtract(0, Argument::Register(0), Argument::Constant(2)),
|
2024-12-03 19:00:27 +00:00
|
|
|
Span(18, 20)
|
|
|
|
),
|
2024-12-10 08:34:41 +00:00
|
|
|
(Instruction::get_local(1, 0), Span(24, 25)),
|
2024-12-03 19:00:27 +00:00
|
|
|
(Instruction::r#return(true), Span(25, 25)),
|
|
|
|
],
|
|
|
|
vec![
|
|
|
|
ConcreteValue::Integer(42),
|
|
|
|
ConcreteValue::string("x"),
|
|
|
|
ConcreteValue::Integer(2)
|
|
|
|
],
|
2024-12-10 08:34:41 +00:00
|
|
|
vec![Local::new(1, 0, true, Scope::default())]
|
2024-12-03 19:00:27 +00:00
|
|
|
)),
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(run(source), Ok(Some(ConcreteValue::Integer(40))));
|
|
|
|
}
|