From fd9964ea5a5661d03f2011073a8d0fdf84ed1d8b Mon Sep 17 00:00:00 2001 From: Devin Bidwell Date: Sat, 22 Nov 2025 17:54:06 -0700 Subject: [PATCH] Add README.md --- Cargo.lock | 26 +++--- README.md | 30 +++++++ .../test/declaration_function_invocation.rs | 82 +++++++++++++++++++ libs/compiler/src/test/declaration_literal.rs | 4 +- libs/compiler/src/v2.rs | 1 + 5 files changed, 129 insertions(+), 14 deletions(-) create mode 100644 README.md diff --git a/Cargo.lock b/Cargo.lock index 897a276..b534c4b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -197,9 +197,9 @@ checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" [[package]] name = "clap" -version = "4.5.52" +version = "4.5.53" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa8120877db0e5c011242f96806ce3c94e0737ab8108532a76a3300a01db2ab8" +checksum = "c9e340e012a1bf4935f5282ed1436d1489548e8f72308207ea5df0e23d2d03f8" dependencies = [ "clap_builder", "clap_derive", @@ -207,9 +207,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.52" +version = "4.5.53" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02576b399397b659c26064fbc92a75fede9d18ffd5f80ca1cd74ddab167016e1" +checksum = "d76b5d13eaa18c901fd2f7fca939fefe3a0727a953561fefdf3b2922b8569d00" dependencies = [ "anstream", "anstyle", @@ -334,9 +334,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.16.0" +version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5419bdc4f6a9207fbeba6d11b604d481addf78ecd10c11ad51e76c2f6482748d" +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" [[package]] name = "heck" @@ -346,12 +346,12 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "indexmap" -version = "2.12.0" +version = "2.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6717a8d2a5a929a1a2eb43a12812498ed141a0bcfb7e8f7844fbdbe4303bba9f" +checksum = "0ad4bb2b565bca0645f4d68c5c9af97fba094e9791da685bf83cb5f3ce74acf2" dependencies = [ "equivalent", - "hashbrown 0.16.0", + "hashbrown 0.16.1", ] [[package]] @@ -1071,18 +1071,18 @@ checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049" [[package]] name = "zerocopy" -version = "0.8.27" +version = "0.8.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0894878a5fa3edfd6da3f88c4805f4c8558e2b996227a3d864f47fe11e38282c" +checksum = "43fa6694ed34d6e57407afbccdeecfa268c470a7d2a5b0cf49ce9fcc345afb90" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.27" +version = "0.8.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88d2b8d9c68ad2b9e4340d7832716a4d21a22a1154777ad56ea55c51a9cf3831" +checksum = "c640b22cd9817fae95be82f0d2f90b11f7605f6c319d16705c459b27ac2cbc26" dependencies = [ "proc-macro2", "quote", diff --git a/README.md b/README.md new file mode 100644 index 0000000..b169a15 --- /dev/null +++ b/README.md @@ -0,0 +1,30 @@ +# Stationeers Language (slang) + +This is an ambitious attempt at creating: + +- A new programming language (slang) +- A compiler to translate slang -> IC10 +- A mod to allow direct input of slang in the in-game script editor to + automatically compile to IC10 before running + +This project currently outputs 3 files: + +- A Linux CLI +- A Windows CLI +- A Windows FFI dll + - Contains a single function: `compile_from_string` + +The aim of this project is to lower the amount of time it takes to code simple +scripts in Stationeers so you can get back to engineering atmospherics or +whatever you are working on. This project is NOT meant to fully replace IC10. +Obviously hand-coded assembly written by an experienced programmer is more +optimized and smaller than something that a C compiler will spit out. This is +the same way. It WILL produce valid IC10, but for large complicated projects it +might produce over the allowed limit of lines the in-game editor supports. + +Current Unknowns + +- Should I support a configurable script line length in-game to allow larger + scripts to be saved? +- Should compilation be "behind the scenes" (in game editor will ALWAYS be what + you put in. IC10 will be IC10, slang will be slang) diff --git a/libs/compiler/src/test/declaration_function_invocation.rs b/libs/compiler/src/test/declaration_function_invocation.rs index 3a028ca..02302a1 100644 --- a/libs/compiler/src/test/declaration_function_invocation.rs +++ b/libs/compiler/src/test/declaration_function_invocation.rs @@ -88,3 +88,85 @@ fn incorrect_args_count() -> anyhow::Result<()> { Ok(()) } + +#[test] +fn inline_literal_args() -> anyhow::Result<()> { + let compiled = compile! { + debug + " + fn doSomething(arg1, arg2) {}; + let thisVariableShouldStayInPlace = 123; + let returnedValue = doSomething(12, 34); + " + }; + + assert_eq!( + compiled, + indoc! { + " + j main + doSomething: + pop r8 #arg2 + pop r9 #arg1 + push ra + sub r0 sp 1 + get ra db r0 + sub sp sp 1 + j ra + main: + move r8 123 #thisVariableShouldStayInPlace + push r8 + push 12 + push 34 + jal doSomething + sub r0 sp 1 + get r8 db r0 + sub sp sp 1 + move r9 r15 #returnedValue + " + } + ); + + Ok(()) +} + +#[test] +fn mixed_args() -> anyhow::Result<()> { + let compiled = compile! { + debug + " + let arg1 = 123; + let returnValue = doSomething(arg1, 456); + fn doSomething(arg1, arg2) {}; + " + }; + + assert_eq!( + compiled, + indoc! { + " + j main + doSomething: + pop r8 #arg2 + pop r9 #arg1 + push ra + sub r0 sp 1 + get ra db r0 + sub sp sp 1 + j ra + main: + move r8 123 #arg1 + push r8 + push r8 + push 456 + jal doSomething + sub r0 sp 1 + get r8 db r0 + sub sp sp 1 + move r9 r15 #returnValue + " + } + ); + + Ok(()) +} diff --git a/libs/compiler/src/test/declaration_literal.rs b/libs/compiler/src/test/declaration_literal.rs index 5a881a4..b5e88cd 100644 --- a/libs/compiler/src/test/declaration_literal.rs +++ b/libs/compiler/src/test/declaration_literal.rs @@ -25,7 +25,9 @@ fn variable_declaration_numeric_literal() -> anyhow::Result<()> { #[test] fn variable_declaration_numeric_literal_stack_spillover() -> anyhow::Result<()> { - let compiled = compile! {debug r#" + let compiled = compile! { + debug + r#" let a = 0; let b = 1; let c = 2; diff --git a/libs/compiler/src/v2.rs b/libs/compiler/src/v2.rs index c411d8c..6ccc637 100644 --- a/libs/compiler/src/v2.rs +++ b/libs/compiler/src/v2.rs @@ -53,6 +53,7 @@ quick_error! { } #[derive(Default)] +#[repr(C)] pub struct CompilerConfig { pub debug: bool, }