Giter Site home page Giter Site logo

vilsol / go-mlog Goto Github PK

View Code? Open in Web Editor NEW
25.0 2.0 6.0 15.26 MB

Go to Mindustry (MLOG) compiler, runtime and decompiler (WIP)

Home Page: https://vilsol.github.io/go-mlog-web/

License: GNU General Public License v3.0

Go 100.00%
mlog mindustry transpiler go mindustry-logic golang compiler

go-mlog's Introduction

go-mlog

GitHub Workflow Status GitHub release (latest SemVer) codecov CodeFactor GitHub go.mod Go version Go Reference

Web IDE

A Web IDE is available here

Examples

There are several example programs available on the wiki.

Supports

  • Functions
  • Multiple function parameters/arguments
  • Multiple function return values
  • return from functions
  • for loops
  • if/else if/else statements
  • switch statement
  • break/continue/fallthrough statements
  • Statement labeling
  • goto statements
  • Binary and Unary math
  • Function level variable scopes
  • Contextual errors
  • Tree-shaking unused functions
  • Multi-pass pre/post-processing
  • Stackless functions
  • Comment generation including source mapping
  • Sub-selector support
  • Type checking
  • Full variable block scoping

In Progress

  • MLOG Runtime
  • MLOG to Go decompiler

Roadmap

  • Nested sub-selector support
  • Merged compiler and decompiler registries
  • Constant string and number slices

Planned Optimizations

  • Simple jump instructions
  • Recursive constant propagation
  • Write directly to function return variable
  • Write directly to function parameters before jump
  • Single-reference function inlining

Design Limitations

  • Only hardcoded (translated) imports allowed
  • Single file support only
  • No recursion (more info here)

Endgame Roadmap

  • Transpilation optimizations
  • Support tail-recursion

CLI Usage

Usage:
  go-mlog [command]

Available Commands:
  completion  generate the autocompletion script for the specified shell
  decompile   Decompile MLOG to Go
  execute     Execute MLOG
  help        Help about any command
  transpile   Transpile Go to MLOG
  trex        Transpile Go to MLOG and execute it
  typings     Output typings as JSON
  version     Print current go-mlog version

Flags:
      --colors               Force log output with colors
      --comment-offset int   Comment offset from line start (default 60)
      --comments             Output comments
  -h, --help                 help for go-mlog
      --log string           The log level to output (default "info")
      --metrics              Output source metrics after execution
      --numbers              Output line numbers
      --output string        Output file. Outputs to stdout if unspecified
      --source               Output source code after comment
      --stacked string       Use a provided memory cell/bank as a stack

go-mlog's People

Contributors

vilsol avatar wu452148993 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

go-mlog's Issues

`m.UnitGetBlock` returns blockType of type `string`, which breaks comparisons

Consider the go-mlog code:

bType, _ := m.UnitGetBlock(float64(m.ThisX), float64(m.ThisY))
if bType != "hyper-processor" {
	// do something
}

This doesn't work because the generated mindustry code is:

op notEqual _searchAboutFor_12 _searchAboutFor_bType "hyper-processor"

when it needs to be

op notEqual _searchAboutFor_12 _searchAboutFor_bType @hyper-processor

There doesnt appear to be any way to cause this code to be generated in go-mlog.

Suggested fix

Make UnitGetBlock return buildingType of type m.Building rather than string.

"Therapist" example not working

Trying to transcode the "Therapist" example fails with the following error message

error at 282: cannot use "@this" (constant of type string) as interface{GetHealth() int; GetItemCapacity() int; GetName() string; GetRotation() float64; GetShootX() float64; GetShootY() float64; GetTotalItems() int; GetX() float64; GetY() float64; IsShooting() bool} value in argument to m.Sensor: missing method GetHealth

The following modification on lines [15-17] transpiles and should retain the desired behaviour.

        if health == maxHealth {
		print("Home")
		homeX := float64(m.ThisX)
		homeY := float64(m.ThisY)
		m.UnitApproach(homeX, homeY, 10)
	}

I tried to edit the wiki myself but I cannot figure out a good way to do so. Seems like public access to the wiki isn't allowed and a "fork + pull-request" of the repo won't work since the wiki isn't forked along with the rest of the repo.

Example scripts

Absolutely awesome project!
It would be helpful to have a few examples. They would help to see how to use the game API easier, and help those not very familiar with go.

about use "Processor Variables and Constants" in IDE

hi,I saw "Processor Variables and Constants" variable changed to SpecialVar(string) type,that could lead to compilation warning when written code in IDE.
Example:
image
image
In my opinion, we should use TYPE to limit the parameter type of the incoming function, so that we can detect the TYPE ERROR in our code by IDA.
At present, the only way I can think of is to separate the type field from the conversion field. I hope to find a better way, because my method seems a little stupid.lol

Link implementation incomplete?

Hello,

Am I missing something or is the Link functionality incomplete?
If I get a Link I cannot use Sensor on it, or do anything else for that matter.

Because Link is of type Link, and Sensor expects HealthC I think...
I looked through the source and could not find any way to convert it. If I try a casting expression I also get an error.

[Feature] Go "math" module mappings

Some operations from mlog are not useable since the mapping of the regarding math functions is missing

example:
MLOG:

op abs result a b
op len result a b
op sqrt result a b
op max result a b
op min result a b
op angle result a b

Go-mlog:

import (
	"github.com/Vilsol/go-mlog/m"
	"math"
)
func main(){
  result := math.Abs(a)
  result = m.vectorLen(a,b)
  result = math.Sqrt(a)
  result = math.Max(a,b)
  result = math.Min(a,b)
  result = m.vectorAngle(a,b)
}

This are not all missing mappings but the imo most common ones that are missing

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.