Giter Club home page Giter Club logo

remeta's Introduction

remeta logo

Automatically generate Go package bindings for ReRect!

Remeta uses Go's parser and some metaprogramming magic to quickly generate easy to read bindings

Installation    User Guide    Contributing   

Go module ReRect bindings
package test

type Vector3 struct {
	x int
	y int
	z int
}

func Vector3Add(v1, v2 Vector3) Vector3 {
	return Vector3{
		x: v1.x + v2.x,
		y: v1.y + v2.y,
		z: v1.z + v2.z,
	}
}

func (v1 Vector3) Add(v2 Vector3) Vector3 {
	return Vector3Add(v1, v2)
}
package gopackages

import (
"bytespace.network/rerect/compunit"
"bytespace.network/rerect/eval_objects"
"bytespace.network/rerect/symbols"
_origin "bytespace.network/rerect/go_packages/test"
)

func LoadTest() {
	test := registerPackage("test")

	Vector3TypeSymbol := symbols.NewTypeSymbol(
		"Vector3",
		[]*symbols.TypeSymbol{},
		symbols.CON,
		0,
		nil,
	)

	Vector3Container := symbols.NewContainerSymbol(
		test, "Vector3", Vector3TypeSymbol,
	)

	Vector3Container.Fields = append(
		Vector3Container.Fields,
		symbols.NewFieldSymbol(
			Vector3Container, "x", 
			compunit.GlobalDataTypeRegister["int"],
		),
	)
	Vector3Container.Fields = append(
		Vector3Container.Fields,
		symbols.NewFieldSymbol(
			Vector3Container, "y", 
			compunit.GlobalDataTypeRegister["int"],
		),
	)
	Vector3Container.Fields = append(
		Vector3Container.Fields,
		symbols.NewFieldSymbol(
			Vector3Container, "z", 
			compunit.GlobalDataTypeRegister["int"],
		),
	)

	symbols.NewVMFunctionSymbol(
		test,
		"Vector3Add",
		compunit.GlobalDataTypeRegister["Vector3"],
		[]*symbols.ParameterSymbol{
			symbols.NewParameterSymbol(
				"v1",
				0,
				compunit.GlobalDataTypeRegister["Vector3"],
			),
		},
		Vector3Add,
	)
	symbols.NewVMFunctionSymbol(
		test,
		"Add",
		compunit.GlobalDataTypeRegister["Vector3"],
		[]*symbols.ParameterSymbol{
			symbols.NewParameterSymbol(
				"v2",
				0,
				compunit.GlobalDataTypeRegister["Vector3"],
			),
		},
		Add,
		)
}

func Vector3Add(args []any) any {
	v1 := args[0].(Vector3)
	v2 := args[0].(Vector3)
	return _origin.Vector3Add(v1, v2)
}

func Vector3_Add(instance any, args []any) any {
	v2 := args[0].(Vector3)
	return Add(v2)
}

remeta's People

Contributors

hrszpuk avatar

Watchers

 avatar

remeta's Issues

Container typechecking

When we register an new typo symbol the generate need to keep track in case a function/method uses a Container type symbol (other we keep generating global data type lookups?)

The compunit.GlobalDataTypeRegister["Vector3"] need to be replaced with a reference to the type symbol &Vector3TypoSymbol in this case.

Functions with simplified type parameters fail to generate a local scrope type asserted variable.

// example from Vector3
func Vector3Add(v1, v2 Vector3) Vector3 {
	return Vector3{
		x: v1.x + v2.x,
		y: v1.y + v2.y,
		z: v1.z + v2.z,
	}
}

v1 and v2 are of the same type and they are parsed differently from the Go compiler than if the parameters were written like v1 Vector3, v2 Vector3.

This causes the function to generate like so:

func Vector3Add(args []any) any {
        v1 := args[0].(Vector3)
        return Vector3Add(v1)
}

v2 isn't found.

Container Constructors

Constructing containers from the field list.
This needs to generate both the method registration and the method's implementation (should be able to modify the GenerateFunctionImplementation to allow methods too).

Add postfix to distinguish methods and functions

Currently function and method implementations are generated using the pure names from the source. This is bad because conflict can happen. To avoid this... All functions should be appended with "Func" and all methods will be appended with "Meth".
This also means function reigstration needs to use the postfix names (not the original source code ones).

Container instance checking, type assertion, and field look ups

So we need to check if the instance is nil, cast the instance, and a field look ups.

from the hot dog example.go:

func Hotdog_Constructor(instance any, args []any) any {
	if instance == nil { // instance checking
		return nil
	}

	con := instance.(*evalobjects.ContainerInstance) // type assertion
	con.Fields["name"] = args[0].(string) // field look up (+ assignment)

	return nil
}

Generating imports

Scan the Go file for imports and include them all in an import declaration.

Add User Guide

How to use Remeta? Git clone into go_packages, run the tool, add the load function to load.go:Load(). (expanded ofc)

Automatically add go_package imports

Can't believe I forgot about this but each module needs to import the following:

import (
	"bytespace.network/rerect/compunit"
	"bytespace.network/rerect/eval_objects"
	"bytespace.network/rerect/symbols"
)

These are required for the generated functions to work in go_packages

Add Installation guide

The primary way of installation will just be building + adding to PATH.
On Linux/MacOS adding to PATH can be done automatically, on Window it will have to be manual.

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.