diff --git a/README.md b/README.md index fd3d78d..5b09f37 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,67 @@ # BASIC to Mindustry logic -This is a small transpiler from a dialect of the [BASIC](https://en.wikipedia.org/wiki/BASIC) language, "MinBasic" (also known as `mbas`), to [Mindustry](https://github.com/Anuken/Mindustry/)'s [logic system](https://www.reddit.com/r/Mindustry/comments/kfea1e/an_overly_indepth_logic_guide/) (also known as `mlog`). +*Write simple code for complex logic in [Mindustry](https://github.com/Anuken/Mindustry/)* + +```basic +LET time = 0 + +WHILE true + time = time + 1 + + reactor1.enabled = time % 3 == 0 + reactor2.enabled = time % 3 == 1 + reactor3.enabled = time % 3 == 2 + + WAIT(1) +WEND +``` + +![Output of the above code block](./assets/blinking-reactors.gif) + +`basic-to-mindustry` is a small transpiler from a dialect of the [BASIC](https://en.wikipedia.org/wiki/BASIC) language, "MinBasic" (also known as `mbas`), to [Mindustry](https://github.com/Anuken/Mindustry/)'s [logic system](https://www.reddit.com/r/Mindustry/comments/kfea1e/an_overly_indepth_logic_guide/) (also known as `mlog`). Basic is chosen as the source language as it already contains jumps (which mindustry heavily relies on), while allowing for some higher-order constructs like conditions, loops and functions. ## Installation and running -To use this project, start by cloning this git repository: +You will need an installation of the Rust compiler, which you can quickly get from [rustup.rs](https://rustup.rs/). + +Then, simply run the following command to install the MinBasic compiler: ```sh -git clone https://git.shadamethyst.xyz/amethyst/basic-to-mindustry/ +cargo install --git "https://github.com/adri326/basic-to-mindustry/" +``` + +Finally, you can run `basic-to-mindustry --help` to get a usage guide: + +``` +A BASIC to Mindustry Logic compiler and optimizer. + +Usage: basic-to-mindustry [OPTIONS] + +Arguments: + + The path to the input program + +Options: + -c, --copy + If set, copies the results to the clipboard. + + -o, --opt + Defines the amount of optimizations done on the generated program: + - A value of 0 means that no optimizations will be done (useful for debugging the compiler itself) + - A value of 1 means that conservative optimizations will be done (which still allows you to embed the code generated with other pieces of code) +``` + +### For contributing + +If you wish to make changes to the source code, then you will need to clone this git repository: + +```sh +git clone https://github.com/adri326/basic-to-mindustry/ cd basic-to-mindustry ``` -You will then need an installation of the Rust compiler, which you can quickly get from [rustup.rs](https://rustup.rs/). +You will also need an installation of the Rust compiler, which you can quickly get from [rustup.rs](https://rustup.rs/). ```sh # To build the source code: @@ -23,9 +72,10 @@ cargo build # You can do both of these with the following command (note the --): cargo run -- examples/prime.mbas -``` - +# To run the unit tests: +cargo test +``` ## VSCode syntax highlighting diff --git a/assets/blinking-reactors.gif b/assets/blinking-reactors.gif new file mode 100644 index 0000000..5bac6fe Binary files /dev/null and b/assets/blinking-reactors.gif differ diff --git a/minbasic-vscode/package.json b/minbasic-vscode/package.json index 9534cff..a9110c8 100644 --- a/minbasic-vscode/package.json +++ b/minbasic-vscode/package.json @@ -13,6 +13,9 @@ "type": "git", "url": "https://git.shadamethyst.xyz/amethyst/basic-to-mindustry" }, + "scripts": { + "build": "vsce package" + }, "author": "Shad Amethyst", "license": "MIT", "contributes": { diff --git a/minbasic-vscode/syntaxes/minbasic.tmLanguage.json b/minbasic-vscode/syntaxes/minbasic.tmLanguage.json index 1ce8cfd..5129206 100644 --- a/minbasic-vscode/syntaxes/minbasic.tmLanguage.json +++ b/minbasic-vscode/syntaxes/minbasic.tmLanguage.json @@ -33,7 +33,7 @@ }, { "comment": "Operator", - "match": "(?i)(([+\\-*/\\.%]|[!=]=|<[=<]?|>[=>]?|<>|AND|OR))", + "match": "(?i)(([+\\-*/\\.%]|[!=]=|<[=<]?|>[=>]?|<>|\\bAND\\b|\\bOR\\b))", "name": "keyword.operator.minbasic" }, { diff --git a/src/interpreter/mod.rs b/src/interpreter/mod.rs index 00becda..d070e8b 100644 --- a/src/interpreter/mod.rs +++ b/src/interpreter/mod.rs @@ -110,7 +110,7 @@ pub fn run(program: &MindustryProgram, stop_condition: StopCondition) -> HashMap let mut variables = HashMap::new(); while !stop_condition.should_stop(steps) { - step(&compiled, &mut variables, &mut counter); + let _ = step(&compiled, &mut variables, &mut counter); steps = steps.saturating_add(1); }