• Stars
    star
    139
  • Rank 262,954 (Top 6 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created over 3 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Code generator for the Go language

gox - Code generator for the Go language

Build Status Go Report Card GitHub release Coverage Status GoDoc

Quick start

Create a file named hellogen.go, like below:

package main

import (
	"go/token"
	"go/types"
	"os"

	"github.com/goplus/gox"
)

func ctxRef(pkg *gox.Package, name string) gox.Ref {
	return pkg.CB().Scope().Lookup(name)
}

func main() {
	pkg := gox.NewPackage("", "main", nil)
	fmt := pkg.Import("fmt")
	v := pkg.NewParam(token.NoPos, "v", types.Typ[types.String]) // v string

	pkg.NewFunc(nil, "main", nil, nil, false).BodyStart(pkg).
		DefineVarStart(token.NoPos, "a", "b").Val("Hi").Val(3).EndInit(2). // a, b := "Hi", 3
		NewVarStart(nil, "c").Val(ctxRef(pkg, "b")).EndInit(1).            // var c = b
		NewVar(gox.TyEmptyInterface, "x", "y").                            // var x, y interface{}
		Val(fmt.Ref("Println")).
		/**/ Val(ctxRef(pkg, "a")).Val(ctxRef(pkg, "b")).Val(ctxRef(pkg, "c")). // fmt.Println(a, b, c)
		/**/ Call(3).EndStmt().
		NewClosure(gox.NewTuple(v), nil, false).BodyStart(pkg).
		/**/ Val(fmt.Ref("Println")).Val(v).Call(1).EndStmt(). // fmt.Println(v)
		/**/ End().
		Val("Hello").Call(1).EndStmt(). // func(v string) { ... } ("Hello")
		End()

	pkg.WriteTo(os.Stdout)
}

Try it like:

go mod init hello
go mod tidy
go run hellogen.go

This will dump Go source code to stdout. The following is the output content:

package main

import fmt "fmt"

func main() {
	a, b := "Hi", 3
	var c = b
	var x, y interface {
	}
	fmt.Println(a, b, c)
	func(v string) {
		fmt.Println(v)
	}("Hello")
}

More Repositories

1

gop

The Go+ programming language is designed for engineering, STEM education, and data science
Go
8,682
star
2

c2go

Convert C to Go
Go
304
star
3

bpl

Binary Processing Language
Go
149
star
4

spx

spx - A Scratch Compatible Go/Go+ 2D Game Engine for STEM education
Go
97
star
5

igop

The Go/Go+ Interpreter
Go
97
star
6

tutorial

Tutorials for GoPlus (The Go+ Language)
Go
38
star
7

hdq

HTML DOM Query Language for Go+
Go
38
star
8

reflectx

Golang reflect package hack tools
Assembly
28
star
9

yaigop

Yet Another Go+ interpreter (still in beta version)
Go
26
star
10

www

Source code of https://goplus.org/
Go
26
star
11

pandas

Flexible and powerful data analysis / manipulation library for Go+, providing labeled data structures similar to R data.frame objects, statistical functions, and much more
25
star
12

builder

Go+ Builder
Vue
25
star
13

libc

Porting libc from C to Go
Go
24
star
14

pyg

Python to Go tools
Go
13
star
15

community

Go+ Community written in Go+
JavaScript
11
star
16

llgo

A Go compiler based on LLVM in order to better integrate Go with the C ecosystem
Go
9
star
17

ispx

The Interpreter of Go+ spx engine
Go
8
star
18

yap

Yet Another Go/Go+ HTTP Web Framework
Go
8
star
19

sqlite

sqlite for Go+
Go
7
star
20

spx-editor

Spx editor
JavaScript
6
star
21

igo

Yet another interpreter for the Go language
Go
6
star
22

mod

Module support for Go/Go+
Go
6
star
23

canvas

HTML Canvas 2D Context API for mobile, desktop and web
Go
5
star
24

FlappyCalf

FlappyCalf - a game powered by Go+ spx game engine
Shell
3
star
25

goplus.github.io

Thoughts on Go+
2
star
26

ipkg

Go
2
star
27

setup-goplus

Set up your GitHub Actions workflow with a specific version of Go+
TypeScript
2
star
28

installer

Go+ Installer for Windows, MacOS, etc.
Go
2
star
29

gopdlv

gopdlv is a debugger for the Go/Go+ programming language
Go
2
star
30

llama2

LLGo support for Inference Llama 2
LLVM
2
star
31

MazePlay

MazePlay - a game powered by Go+ Builder
Shell
1
star
32

AircraftWar

AircraftWar - a game powered by Go+ spx game engine
Shell
1
star
33

xtypes

Golang types convert utils
Go
1
star
34

classfile-project-template

A template for starting a new classfile project
1
star
35

expect

Expect for Go+
Go
1
star
36

show

show.goplus.org
Go
1
star
37

xtools

Extended tools for Go+
Go
1
star
38

run

run.goplus.org
Go
1
star
39

llgoexamples

LLGo Examples
Rust
1
star
40

account

Go+ Account System
1
star
41

goxls

The Go/Go+ Language Server
Go
1
star