2 Commits

Author SHA1 Message Date
e272737ea2 Merge pull request 'Fixed const -> let bug' (#10) from declaration_const_as_let into master
All checks were successful
CI/CD Pipeline / test (push) Successful in 32s
CI/CD Pipeline / build (push) Successful in 1m43s
CI/CD Pipeline / release (push) Successful in 5s
Reviewed-on: #10
2025-12-29 02:44:50 -07:00
f679601818 Fixed const -> let bug
All checks were successful
CI/CD Pipeline / test (pull_request) Successful in 33s
CI/CD Pipeline / build (pull_request) Has been skipped
CI/CD Pipeline / release (pull_request) Has been skipped
2025-12-29 02:31:23 -07:00
7 changed files with 40 additions and 5 deletions

View File

@@ -1,5 +1,10 @@
# Changelog
[0.4.6]
- Fixed bug in compiler where you were unable to assign a `const` value to
a `let` variable
[0.4.5]
- Fixed issue where after clicking "Cancel" on the IC10 Editor, the side-by-side

View File

@@ -2,7 +2,7 @@
<ModMetadata xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Name>Slang</Name>
<Author>JoeDiertay</Author>
<Version>0.4.5</Version>
<Version>0.4.6</Version>
<Description>
[h1]Slang: High-Level Programming for Stationeers[/h1]

View File

@@ -39,7 +39,7 @@ namespace Slang
{
public const string PluginGuid = "com.biddydev.slang";
public const string PluginName = "Slang";
public const string PluginVersion = "0.4.5";
public const string PluginVersion = "0.4.6";
private static Harmony? _harmony;

View File

@@ -930,7 +930,7 @@ checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e"
[[package]]
name = "slang"
version = "0.4.5"
version = "0.4.6"
dependencies = [
"anyhow",
"clap",

View File

@@ -1,6 +1,6 @@
[package]
name = "slang"
version = "0.4.5"
version = "0.4.6"
edition = "2021"
[workspace]

View File

@@ -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(())
}

View File

@@ -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)