diff --git a/Changelog.md b/Changelog.md index 7f9a5b2..90a5575 100644 --- a/Changelog.md +++ b/Changelog.md @@ -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 diff --git a/ModData/About/About.xml b/ModData/About/About.xml index f300749..7e6b73a 100644 --- a/ModData/About/About.xml +++ b/ModData/About/About.xml @@ -2,7 +2,7 @@ Slang JoeDiertay - 0.4.5 + 0.4.6 [h1]Slang: High-Level Programming for Stationeers[/h1] diff --git a/csharp_mod/Plugin.cs b/csharp_mod/Plugin.cs index b719291..8893012 100644 --- a/csharp_mod/Plugin.cs +++ b/csharp_mod/Plugin.cs @@ -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; diff --git a/rust_compiler/Cargo.lock b/rust_compiler/Cargo.lock index 91769ce..6cf03a8 100644 --- a/rust_compiler/Cargo.lock +++ b/rust_compiler/Cargo.lock @@ -930,7 +930,7 @@ checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e" [[package]] name = "slang" -version = "0.4.5" +version = "0.4.6" dependencies = [ "anyhow", "clap", diff --git a/rust_compiler/Cargo.toml b/rust_compiler/Cargo.toml index 94ee887..e529722 100644 --- a/rust_compiler/Cargo.toml +++ b/rust_compiler/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "slang" -version = "0.4.5" +version = "0.4.6" edition = "2021" [workspace] diff --git a/rust_compiler/libs/compiler/src/test/declaration_literal.rs b/rust_compiler/libs/compiler/src/test/declaration_literal.rs index 5f438d3..20f01f5 100644 --- a/rust_compiler/libs/compiler/src/test/declaration_literal.rs +++ b/rust_compiler/libs/compiler/src/test/declaration_literal.rs @@ -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(()) +} diff --git a/rust_compiler/libs/compiler/src/v1.rs b/rust_compiler/libs/compiler/src/v1.rs index 61a26f0..ea049f2 100644 --- a/rust_compiler/libs/compiler/src/v1.rs +++ b/rust_compiler/libs/compiler/src/v1.rs @@ -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)