Code Monkey home page Code Monkey logo

basic-to-mindustry's Introduction

BASIC to Mindustry logic

Write simple code for complex logic in Mindustry

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

basic-to-mindustry is a small transpiler from a dialect of the BASIC language, "MinBasic" (also known as mbas), to Mindustry's logic system (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

You will need an installation of the Rust compiler, which you can quickly get from rustup.rs.

Then, simply run the following command to install the MinBasic compiler:

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] <INPUT>

Arguments:
  <INPUT>
          The path to the input program

Options:
  -c, --copy
          If set, copies the results to the clipboard.

  -o, --opt <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:

git clone https://github.com/adri326/basic-to-mindustry/
cd basic-to-mindustry

You will also need an installation of the Rust compiler, which you can quickly get from rustup.rs.

# To build the source code:
cargo build

# To run the binary:
./target/debug/basic-to-mindustry examples/prime.mbas

# 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

Any language support extension for QuickBasic (the dialect MinBasic is based on) will work, but if you would like an extension that was tailored to support MinBasic, you can have a look at the one bundled with this project.

Language features

The GUIDE.md file describes how to write programs in MinBasic.

basic-to-mindustry's People

Contributors

adri326 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.