Fixed const -> let bug
This commit is contained in:
2
rust_compiler/Cargo.lock
generated
2
rust_compiler/Cargo.lock
generated
@@ -930,7 +930,7 @@ checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e"
|
||||
|
||||
[[package]]
|
||||
name = "slang"
|
||||
version = "0.4.5"
|
||||
version = "0.4.6"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "slang"
|
||||
version = "0.4.5"
|
||||
version = "0.4.6"
|
||||
edition = "2021"
|
||||
|
||||
[workspace]
|
||||
|
||||
@@ -168,3 +168,28 @@ fn test_const_hash_expr() -> anyhow::Result<()> {
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_declaration_is_const() -> anyhow::Result<()> {
|
||||
let compiled = compile! {
|
||||
debug
|
||||
r#"
|
||||
const MAX = 100;
|
||||
|
||||
let max = MAX;
|
||||
"#
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
main:
|
||||
move r8 100
|
||||
"
|
||||
}
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -714,7 +714,12 @@ impl<'a> Compiler<'a> {
|
||||
|
||||
Operand::Register(VariableScope::TEMP_STACK_REGISTER)
|
||||
}
|
||||
VariableLocation::Constant(_) | VariableLocation::Device(_) => unreachable!(),
|
||||
VariableLocation::Constant(Literal::Number(num)) => Operand::Number(num.into()),
|
||||
VariableLocation::Constant(Literal::Boolean(b)) => {
|
||||
Operand::Number(Number::from(b).into())
|
||||
}
|
||||
VariableLocation::Device(_)
|
||||
| VariableLocation::Constant(Literal::String(_)) => unreachable!(),
|
||||
};
|
||||
self.emit_variable_assignment(&var_loc, src)?;
|
||||
(var_loc, None)
|
||||
|
||||
Reference in New Issue
Block a user