Go -> Haxe -> JS Java C# C++ C Python Lua

Overview

go2hx

Compile: Go -> Haxe -> Js, Lua, C#, C++, Java, C, Python

warning: heavily experimental still a ways to go before an alpha.

Come give feedback on what Go libraries you want supported!

Getting started

haxelib git go2hx https://github.com/go2hx/go2hx
haxelib run go2hx ./main.go

Shows percentage of tests passing out of total

Language features

go2hx supports a subset of language features that have not been extensively tested yet. It does not include any support for go routines, The list includes:

  • control flow statements for/if/range
  • all statements except statements relating to go routines, control-flows/branches/decls
  • all exprs conversion/literals/access

Standard library support

The standard library that has been rewritten in Haxe has partial support, It does not include any support for unsafe, embeds, testing, and cgo, The most supported libraries in order includes:

  • reflect
  • fmt
  • os
  • strings
  • strconv
  • math

Acknowledgement

A spiritual successor to Tardisgo written by Elliott Stoneham, The developer that has set the building blocks conceptually for this project, as well as a code contributor, with use of some of his code from Tardisgo.

Build from source

haxelib dev go2hx .

Look at Run.hx to see how the building occurs.

Issues
  • Go TypeSwitch

    Go TypeSwitch

    Currently can not use Abstracts as values for the "is" operator, blocked by needed compiler changes. https://github.com/HaxeFoundation/haxe/issues/2976

     x = Go.assert(((1 : Byte)));
    if ((x is UInt8)) { } else {
        panic("byte != uint8");
    };
    x = Go.assert(((2 : UInt8)));
    if ((x is Byte)) { } else {
        panic("uint8 != byte");
    };
    var rune32 = false;
    x = Go.assert(((3 : Rune)));
    if ((x is Int)) { } else if ((x is Int32)) {
        rune32 = true;
    } else {
        panic("rune != int and rune != int32");
    };
    opened by PXshadow 44
  • Representation of Go pointers in go2hx

    Representation of Go pointers in go2hx

    All Haxe objects are of course pointers to the start of the contents of the object.

    But how to represent pointers to elements within an object, or elements within elements?

    I think a Go pointer type rendered in Haxe might contain two values:

    1. (a pointer to) the base object
    2. an array of indexes(into arrays) or field-names(for structures)

    So a pointer to Go element dingbat[4].foo.bar[26] would be{dingbat,[4,"foo","bar",26]} in Haxe (inside a Class of course).

    I fear Haxe reflection may be required to achieve this.

    I see @PXshadow may be ahead of me on this, due to his work on https://github.com/andyli/ptr.

    opened by elliott5 26
  • Go divide by zero behaviour

    Go divide by zero behaviour

    In Go, all integers panic when divided by zero. This is a different behaviour from Haxe.

    For floats & complexes, NaN should be returned. This means the code for complex number division in TardisGo was wrong (and so is wrong now in go2hx).

    Go has a specific test for divide-by-zero behaviour at https://golang.org/test/zerodivide.go

    opened by elliott5 25
  • Access to native Haxe from go2hx Go

    Access to native Haxe from go2hx Go

    In GopherJS they have a specific js pseudo-Go module, see https://pkg.go.dev/github.com/gopherjs/gopherjs/js

    TardisGo also had a similar hx pseudo-Go module, see https://github.com/tardisgo/tardisgo/blob/e0dd9a7e46b597cdc4d310c8a677c2da7444008e/haxe/hx/hx.go

    So go2hx needs a similar pseudo-Go module. This will allow much of the reflect (and maybe other low-level) modules to be written in Go, and therefore able to reuse existing Go code from elsewhere.

    Originally posted by @elliott5 in https://github.com/PXshadow/go2hx/issues/8#issuecomment-796662137

    opened by elliott5 21
  • Preface generated class and interface declarations with @:rtti

    Preface generated class and interface declarations with @:rtti

    I'm planning to fork this repo and write the prototype reflect module in the correct location.

    It would be really helpful to my testing @PXshadow if you could preface generated class and interface code with @:rtti.

    There will be more code generation tweaks required, if the prototype approach works.

    opened by elliott5 20
  • first iteration of removing unneeded parts of reflect, and bringing b…

    first iteration of removing unneeded parts of reflect, and bringing b…

    This is the first version of a revamp for the reflect system, going to a full macro approach and as such @:rtti as well as typeName and other parts do not seem to be maintained. The main motiviation for a revamp is to make AnyInterface much more useful and deeply integrated with Reflect.

    It currently does not work at all at the moment and various places that @:rtti and other systems like type aliases and haxeClassPath have been removed.

    Some things need to be sorted as well, for instance:

    • How will the macro know the type when going into a function argument and having the type changed?
    • What system will be used for typeswitch?
    • Will anonymous functions now be correctly handled?

    List of changes

    • abstract Type -> class Type
    • abstract Kind -> @:enum abstract Kind
    • all golang func String() -> function toString() (haxe's equivlant https://api.haxe.org/Std.html#string)
    • remove @:rtti, typeName and is_pointer (can all be done via macros)
    • remove @:to function __promote() as it can be handled inside reflect
    • changed AnyInterface from value, typeName : String to value, type : Reflect.Type
    • removed all function typeName()
    • Removed fieldInfo as it isn't macro based.
    • Rewrote test harness in Go inside Rnd
    opened by PXshadow 17
  • GopherJS handling of goto

    GopherJS handling of goto

    I see from the part-generated code for goto in go2hx that you are thinking of using functions, that was my first thought too.

    As a cross-check, I thought it would be helpful to see how GopherJS did it...

    I took the example of a Go goto program from https://www.tutorialspoint.com/go/go_goto_statement.htm

    Set up GopherJS on a virtual machine (it now requires an old version of Go), and inspected what was generated.

    GopherJS uses a case statement to implement goto (but also for) ... so the Go code:

    func main() {
    	var a int = 10
    LOOP:
    	for a < 20 {
    		if a == 15 {
    			a = a + 1
    			goto LOOP
    		}
    		println("value of a:",a)
    		a++
    	}
    }
    

    ...generates this JS:

    	main = function() {
    		var a, $s;
    		/* */ $s = 0; s: while (true) { switch ($s) { case 0:
    		a = 10;
    		/* LOOP: */ case 1:
    		/* while (true) { */ case 2:
    			/* if (!(a < 20)) { break; } */ if(!(a < 20)) { $s = 3; continue; }
    			/* */ if (a === 15) { $s = 4; continue; }
    			/* */ $s = 5; continue;
    			/* if (a === 15) { */ case 4:
    				a = a + 1 >> 0;
    				/* goto LOOP */ $s = 1; continue;
    			/* } */ case 5:
    			console.log("value of a:", a);
    			a = a + (1) >> 0;
    		/* } */ $s = 2; continue; case 3:
    		$s = -1; return;
    		/* */ } return; }
    	};
    

    I hope that helps your thinking @PXshadow , let me know if you want to see other GopherJS examples.

    opened by elliott5 17
  • front page instructions do not work for trivial program + should there be an

    front page instructions do not work for trivial program + should there be an "interp" target

    [email protected] go2hx_june22 % haxelib run go2hx --interp ./main.go
    listening on local port: 6218
    Generated: golibs//Main.hx - 0.44kb
    haxe -cp golibs -lib go2hx --interp -m Main
    /usr/local/lib/haxe/lib/go2hx/git/stdgo/Go.hx:147: characters 10-25 : Too many arguments
    

    I don't think interp should even be an option now.

    opened by elliott5 15
  • iota and methods on non-struct named types - example reflect.Kind

    iota and methods on non-struct named types - example reflect.Kind

    package main
    
    import "fmt"
    
    const (
    	Invalid Kind = iota
    	Bool
    	Int
    	Int8
    	Int16
    	Int32
    	Int64
    	Uint
    	Uint8
    	Uint16
    	Uint32
    	Uint64
    	Uintptr
    	Float32
    	Float64
    	Complex64
    	Complex128
    	String
    	UnsafePointer
    	Chan
    	Interface
    	Ptr
    	Slice
    	Array
    	Func
    	Map
    	Struct
    )
    
    type Kind int
    
    func (k Kind) String() string {
    	switch k {
    	case Bool:
    		return "bool"
    	case Int:
    		return "int"
    	case Int8:
    		return "int8"
    	case Int16:
    		return "int16"
    	case Int32:
    		return "int32"
    	case Int64:
    		return "int64"
    	case Uint:
    		return "uint"
    	case Uint8:
    		return "uint8"
    	case Uint16:
    		return "uint16"
    	case Uint32:
    		return "uint32"
    	case Uint64:
    		return "uint64"
    	case Uintptr:
    		return "uintptr"
    	case Float32:
    		return "float32"
    	case Float64:
    		return "float64"
    	case Complex64:
    		return "complex64"
    	case Complex128:
    		return "complex128"
    	case String:
    		return "string"
    	case UnsafePointer:
    		return "unsafe.Pointer"
    	case Chan:
    		return "chan"
    	case Interface:
    		return "interface"
    	case Ptr:
    		return "ptr"
    	case Slice:
    		return "slice"
    	case Array:
    		return "array"
    	case Func:
    		return "func"
    	case Map:
    		return "map"
    	case Struct:
    		return "struct"
    	default:
    		return "invalid"
    	}
    }
    
    func main() {
    	fmt.Println("Kind test harness")
    	for i := 0; i < 30; i++ {
    		k := Kind(i)
    		fmt.Println(i, k.String())
    	}
    }
    
    

    Does not compile on go2hx. Both because iota is not implemented; and because Go methods on non-struct named types are not implemented properly (no link between code and type).

    opened by elliott5 15
  • Very invalid type Rec ***Rec

    Very invalid type Rec ***Rec

    src/encoding/gob/codec_test.go

    func TestBadRecursiveType(t *testing.T) {
    	type Rec ***Rec // WHAT IS THIS ?!
    	var rec Rec
    	b := new(bytes.Buffer)
    	err := NewEncoder(b).Encode(&rec)
    	if err == nil {
    		t.Error("expected error; got none")
    	} else if !strings.Contains(err.Error(), "recursive") {
    		t.Error("expected recursive type error; got", err)
    	}
    	// Can't test decode easily because we can't encode one, so we can't pass one to a Decoder.
    }
    

    It compiles Go code:

    type Rec ***Rec
    

    to Haxe code:

    @:named typedef Rec_testBadRecursiveType_0 = Rec_testBadRecursiveType_0;
    

    Biggest issue I see is that I can't find any other type Rec in the package, perhaps this is supposed to error for the compiler?

    opened by PXshadow 10
  • Get the reflect tests working first, using Go's own reflect code

    Get the reflect tests working first, using Go's own reflect code

    @PXshadow wrote in an e-mail to @elliott5: "...from what I understand now, I think it would be better to get the reflect tests working first and instead of handwriting the go's std reflect or go2hx needing it's own modified go repo, go2hx can transpile the package and then inject in the functions that use //:go:noescape for instance in tardisgo's modified go, you do this here. This idea may also be applicable to speed up, finishing the go standard library as before my thought was that if any package used syscall or internal it would need to be hand written in Haxe however this could make it only necessary to write the functions in the package that use syscall or internal."

    This seems a good idea, but in addition to rewriting the syscall and internal functions, would also require hx2go to create all of the data-structures around Go type information (routinely created by the Go compiler) that the reflect code expects. "These data structures are known to the compiler..."

    Further investigation is required, looking both at how GopherJS and TinyGo handle this issue, and also at how TardisGo did.

    opened by elliott5 9
  • Compile godebug diff library for test runner output

    Compile godebug diff library for test runner output

    @elliott5 for test runner prototype used the godebug's diff library, it has no external dependencies and would be a great addition to see the diff for test suites such as yaegi that are based on output comparison.

    This issue will track the progress on compiling the library.

    opened by PXshadow 9
  • Go standard library 'sort' does not implement 3 type-specific sort functions.

    Go standard library 'sort' does not implement 3 type-specific sort functions.

    In testing https://gobyexample.com/sorting three type wrappers are not implemented, although Haxe typedefs are defined for IntSlice, Float64Slice and StringSlice (lines 48-50 of Sort.hx).

    /Users/elliott/Documents/haxe/haxelib/go2hx/git/stdgo/sort/Sort.hx:434: characters 29-45 : Type not found : IntSlice_wrapper
    /Users/elliott/Documents/haxe/haxelib/go2hx/git/stdgo/sort/Sort.hx:422: characters 18-38 : Type not found : Float64Slice_wrapper
    /Users/elliott/Documents/haxe/haxelib/go2hx/git/stdgo/sort/Sort.hx:428: characters 18-37 : Type not found : StringSlice_wrapper
    
    opened by elliott5 0
  • Type resolving has a more simplified path then functions

    Type resolving has a more simplified path then functions

    For example inside of github_com.go2hx.go4hx.rnd.Rnd modular class:

    github_com.go2hx.go4hx.rnd.X where X is a class or typedef.

    github_com.go2hx.go4hx.rnd.Rnd.y where y is a function.

    Found this out by using haxe.macro.TypeTools.toString to resolve where types are located.

    opened by PXshadow 0
  • gobyexample interfaces.go calls to methods do not work

    gobyexample interfaces.go calls to methods do not work

    The current interface implementation does not properly simulate the look-up required to implement Go methods (in the general case) so I have rewritten it to provide a model implementation:

    /* ****original code****
    	typedef T_geometry = StructType & {
    	public function _area():GoFloat64;
    	public function _perim():GoFloat64;
    	};
     */
    // ****rewrite start****
    //
    // Any Go type can implement a Go interface, sometimes unintentionally.
    // c.f. "String() string" methods and the "fmt" package.
    // Because of this, in the general case, calls to Go interface methods involve dynamic lookup.
    //
    // When (as here) a type implementing an interface and the interface itself
    // are in the same Go package, optimisation is possible in future.
    //
    class T_geometry extends stdgo.StdGoTypes.AnyInterfaceData {
    	var xtn:Dynamic; // extension class
    	var xtn_area:Dynamic; // _area function within extension class
    	var xtn_perim:Dynamic; // _perim function within extension class
    
    	public function new(x:stdgo.StdGoTypes.AnyInterface) {
    		super(x.value, x.type);
    		var t = Type.getClass(x.value); // type of class holding data
    		// because methods are held in an extension class, we must find extension class
    		// this requires all Go type classes to be prefaced by "@:rtti"
    		var m = haxe.rtti.Rtti.getRtti(t).meta;
    		for (i in m) {
    			if (i.name == ":using") { // the haxe metadata of the using clause
    				var c:String = i.params[0]; // the extension class path.name
    				this.xtn = Type.resolveClass(c);
    				if (this.xtn == null) {
    					// TODO I think that when used in the top-level code, no path is required
    					var s = c.split(".");
    					c = s[s.length - 1]; // remove the path from the class name
    					this.xtn = Type.resolveClass(c);
    				}
    				break;
    			}
    		}
    		if (this.xtn == null)
    			throw("Unable to resolve extension class");
    		this.xtn_area = Reflect.field(this.xtn, "_area"); // to avoid lookup per-use
    		this.xtn_perim = Reflect.field(this.xtn, "_perim"); // to avoid lookup per-use
    	}
    
    	inline public function _area():GoFloat64 {
    		return Reflect.callMethod(this.xtn, this.xtn_area, [this.value]);
    	}
    
    	inline public function _perim():GoFloat64 {
    		return Reflect.callMethod(this.xtn, this.xtn_perim, [this.value]);
    	}
    }
    // ****rewrite end****
    
    @:rtti // ****added****
    @:structInit @:using(Interfaces2.T_rect_static_extension) class T_rect { 
    ...
    

    Interface invocations must be of the right type:

    function main():Void {
    	var _r:T_rect = (({_width: ((3 : GoFloat64)), _height: ((4 : GoFloat64))} : T_rect));
    	var _c:T_circle = (({_radius: ((5 : GoFloat64))} : T_circle));
    	_measure(new T_geometry(Go.toInterface(_r))); // ****added (new T_geometry(Go.toInterface(...****
    	_measure(new T_geometry(Go.toInterface(_c))); // ****added (new T_geometry(Go.toInterface(...*****
    }
    

    I will send full details to @PXshadow by email.

    opened by elliott5 4
  • Documentation efforts

    Documentation efforts

    I think the wiki pages should be removed and the content moved to the go2hx github site. The reasoning is the wiki is obscure in terms of looking through the project, having the documentation be on the website makes it more seamless, and also more friendly on mobile.

    Nice looking graphs and charts are huge QOL features and should be prioritized more, charts/graphs could include:

    • passing std pkgs with per target check results
    • go2hx per target to go native comparisons
    • supported library graphs with per target performance test passing and binary size compared to go native as well
    • go2hx compile speed comparisons to native go

    Another thing is branding and nice looking pictures for both documentation/blogs. Well developed pictures capture the mind's imagination and therefore should have resources dedicated to them.

    The content delivery stream should be as follows: Twice a month goal, Once a month minimum, github releases with a minimal and polished changelog -> link to a corresponding go2hx blog post showing off the new features/bug fixes in practice -> the info from the blog post should then be cut up and included into the go2hx documentation boat.

    Each new version should be valuable enough both from a new shiny utility aspect but also as content to spread effortlessly through word of mouth for devs that would be interested in this compiler.

    Lots of work should be done on the documentation part to make the initial impression and subsequent views enjoyable to look through, highly valuable from an information standpoint and easy to navigate and look through all of the documentation with ease.

    The work for this on my part should be phased in as more std pkgs publicly pass test compliance on multiple targets.

    opened by PXshadow 7
GopherLua: VM and compiler for Lua in Go

GopherLua: VM and compiler for Lua in Go. GopherLua is a Lua5.1 VM and compiler written in Go. GopherLua has a same goal with Lua: Be a scripting lang

Yusuke Inuzuka 4.8k Jun 26, 2022
A Lua VM in Go

A Lua VM in pure Go go-lua is a port of the Lua 5.2 VM to pure Go. It is compatible with binary files dumped by luac, from the Lua reference implement

Shopify 2.4k Jul 1, 2022
A Lua 5.3 VM and compiler written in Go.

DCLua - Go Lua Compiler and VM: This is a Lua 5.3 VM and compiler written in Go. This is intended to allow easy embedding into Go programs, with minim

Milo Christiansen 894 Jun 13, 2022
Java properties scanner for Go

Overview Please run git pull --tags to update the tags. See below why. properties is a Go library for reading and writing properties files. It support

Frank Schröder 269 Jun 22, 2022
gpython is a python interpreter written in go "batteries not included"

gpython gpython is a part re-implementation / part port of the Python 3.4 interpreter to the Go language, "batteries not included". It includes: runti

go-python 591 Jun 23, 2022
Grumpy is a Python to Go source code transcompiler and runtime.

Grumpy: Go running Python Overview Grumpy is a Python to Go source code transcompiler and runtime that is intended to be a near drop-in replacement fo

Google 10.5k Jun 28, 2022
Golang->Haxe->CPP/CSharp/Java/JavaScript transpiler

TARDIS Go -> Haxe transpiler Haxe -> C++ / C# / Java / JavaScript Project status: a non-working curiosity, development currently on-ice The advent of

TARDIS Go 418 Jun 18, 2022
🎀 a nice lil shell for lua people made with go and lua

Hilbish ?? a nice lil shell for lua people made with go and lua It is currently in a mostly beta state but is very much usable (I'm using it right now

Hilbis Development 209 Jun 24, 2022
LuaHelper is a High-performance lua plugin, Language Server Protocol for lua.

LuaHelper is a High-performance lua plugin, Language Server Protocol for lua.

Tencent 262 Jun 29, 2022
Aes for go and java; build go fo wasm and use wasm parse java response.

aes_go_wasm_java aes for go and java; build go fo wasm and use wasm parse java response. vscode setting config settings.json { "go.toolsEnvVars":

忆年 0 Dec 14, 2021
Update-java-ca-certificates - Small utility to convert the system trust store to a system Java KeyStore

update-java-ca-certificates This small utility takes care of creating a system-w

Swisscom 3 Jan 7, 2022
convert curl commands to Python, JavaScript, Go, PHP, R, Dart, Java, MATLAB, Rust, Elixir and more

curlconverter curlconverter transpiles curl commands into programs in other programming languages. $ curlconverter --data "Hello, world!" example.com

null 5.6k Jun 30, 2022
Solutions to AlgoExpert Problems in Six Programming Languages: Python, Java, Go, C++, C#, JavaScript/TypeScript

Solutions to AlgoExpert Problems in Six Programming Languages: Python, Java, Go, C++, C#, JavaScript/TypeScript Discover solutions to AlgoExpert probl

Nsikak Imoh 4 Jun 12, 2022
High level go to Lua binder. Write less, do more.

Binder High level go to Lua binder. Write less, do more. Package binder allows to easily bind to Lua. Based on gopher-lua. Write less, do more! Killer

Alexey Popov 58 Jun 2, 2022
A Lua VM in Go

A Lua VM in pure Go go-lua is a port of the Lua 5.2 VM to pure Go. It is compatible with binary files dumped by luac, from the Lua reference implement

Shopify 2.4k Jun 25, 2022
Go bindings for Lua C API - in progress

Go Bindings for the lua C API Simplest way to install: # go get github.com/aarzilli/golua/lua You can then try to run the examples: $ cd golua/_examp

Alessandro Arzilli 588 Jun 13, 2022
GopherLua: VM and compiler for Lua in Go

GopherLua: VM and compiler for Lua in Go. GopherLua is a Lua5.1 VM and compiler written in Go. GopherLua has a same goal with Lua: Be a scripting lang

Yusuke Inuzuka 4.8k Jun 24, 2022
:tophat: Small self-contained pure-Go web server with Lua, Markdown, HTTP/2, QUIC, Redis and PostgreSQL support

Web server with built-in support for QUIC, HTTP/2, Lua, Markdown, Pongo2, HyperApp, Amber, Sass(SCSS), GCSS, JSX, BoltDB (built-in, stores the databas

Alexander F. Rødseth 2k Jun 25, 2022
Go bindings for Lua C API - in progress

Go Bindings for the lua C API Simplest way to install: # go get github.com/aarzilli/golua/lua You can then try to run the examples: $ cd golua/_examp

Alessandro Arzilli 588 Jun 13, 2022
A Lua VM in Go

A Lua VM in pure Go go-lua is a port of the Lua 5.2 VM to pure Go. It is compatible with binary files dumped by luac, from the Lua reference implement

Shopify 2.4k Jun 29, 2022
GopherLua: VM and compiler for Lua in Go

GopherLua: VM and compiler for Lua in Go. GopherLua is a Lua5.1 VM and compiler written in Go. GopherLua has a same goal with Lua: Be a scripting lang

Yusuke Inuzuka 4.8k Jun 25, 2022
Heart 💜A high performance Lua web server with a simple, powerful API

Heart ?? A high performance Lua web server with a simple, powerful API. See the full documentation here. Overview Heart combines Go's fasthttp with Lu

Hyperspace Logistics 75 Jun 22, 2022
GopherLua: VM and compiler for Lua in Go

GopherLua: VM and compiler for Lua in Go. GopherLua is a Lua5.1 VM and compiler written in Go. GopherLua has a same goal with Lua: Be a scripting lang

Yusuke Inuzuka 4.8k Jun 26, 2022
A Lua VM in Go

A Lua VM in pure Go go-lua is a port of the Lua 5.2 VM to pure Go. It is compatible with binary files dumped by luac, from the Lua reference implement

Shopify 2.4k Jul 1, 2022
A Lua 5.3 VM and compiler written in Go.

DCLua - Go Lua Compiler and VM: This is a Lua 5.3 VM and compiler written in Go. This is intended to allow easy embedding into Go programs, with minim

Milo Christiansen 894 Jun 13, 2022
The Humboldt Web Framework and Toolkit. Using this as an interpeter and server, build webistes in an MVC pattern using Lua.

Humboldt Web Framework Humboldt is a framework written in Go using Lua files to build web applications. What is this framework for? People who want to

Selene Software 0 Jan 21, 2022
Lua runtime to control Philips Hue lamps 💡

go-hue Control Philips Hue Lamps with Lua About This is just a throw-away tooling to control Hue Lamps with a simple Lua script. hue -interval=2000 sc

Willi 0 Dec 10, 2021
A Teardown API to Lua stub generator written in Go.

Teardown API Stub Generator This project aims to provide a parser for the XML files at https://www.teardowngame.com/modding/api.xml These files descri

Josua Müller 1 Feb 9, 2022
bluemonday: a fast golang HTML sanitizer (inspired by the OWASP Java HTML Sanitizer) to scrub user generated content of XSS

bluemonday bluemonday is a HTML sanitizer implemented in Go. It is fast and highly configurable. bluemonday takes untrusted user generated content as

Microcosm 2.3k Jun 24, 2022