gi

package module
v0.0.0-...-2cb6afa Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 2 Imported by: 0

README

gi logo

Go GoDoc codecov examples

gi is a Go interpreter that creates an executable representation of a Go program from source. It offers a virtual machine that can step through such a program and allows access to the full stack and scoped variables (environment).

gi is implemented using Go reflection API so one can expect 10x slower program execution depending on the complexity.

mission

runtime

  • support latest Go SDK
  • support type parameterization (generics)
  • support Go modules (will require pre-compilation)

debugging

  • offer a DAP interface
  • handle source changes during a debugging session:
    • change a function definition
    • change a struct definition
    • add package constant|variable
  • debugging concurrent programs

status

This is work in progress. See examples for runnable examples using the gi cli. See status for the supported Go language features.

install

go install github.com/emicklei/gi/cmd/gi@latest

Use CLI

run

gi run .

step

gi step .

DAP server

gi dap --listen=127.0.0.1:52950 --log-dest=3 --log

For development, the following environment variables control the execution and output:

  • GI_TRACE=1 : produce tracing of the virtual machine that executes the statements and expressions.
  • GI_CALL=out.dot : produce a Graphviz DOT file showing the call graph.
  • GI_AST=out.ast : produce the mirror AST text file.

Use as package

run a program

package main

import "github.com/emicklei/gi"

func main() {
	pkg, _ := gi.ParseSource(`package main

import "fmt"

func Hello(name string) int {
	fmt.Println("Hello,", name)
	return 42
}
`)
	answer, err := gi.Call(pkg, "Hello", "3i/Atlas")
}

use of in-process DAP (Debug Adapter Protocol)

	gopkg, _ := pkg.LoadPackage(".", nil)
	ipkg, _ := pkg.BuildPackage(gopkg)
	runner := pkg.NewDAPAccess(pkg.NewVM(ipkg))
	runner.Launch("main", nil)
	for {
		if err := runner.Next(); err != nil {
			if err == io.EOF {
				return
			}
		}
		_ = runner.Threads()
		_ = runner.StackFrames(...)
		_ = runner.Scopes(...)
		_ = runner.Variables(...)
	}
Credits

The build pipeline uses all programs of Go By Example to check whether they are executable with gi.

© 2026. https://ernestmicklei.com . MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Call

func Call(p *pkg.Package, funcName string, params ...any) ([]any, error)

Call calls a function named funcName in the given package pkg with the provided parameters values. It returns the results of the function call and an error if any occurred during the call.

func ParseSource

func ParseSource(source string) (*pkg.Package, error)

ParseSource parses the provided Go source code string and returns a Package representation of it. The source must be valid Go, e.g. main package with a main function. It cannot have external dependencies ; only standard library packages are allowed.

func RegisterPackage

func RegisterPackage(pkgPath string, symbols map[string]reflect.Value)

RegisterPackage registers an external package with its symbols for use within gi-executed code. This function exist to support generated code and it not meant to be used beyond that.

func Run

func Run(filePath string) error

Run loads, builds, and runs the Go package located at the specified file path. filePath is the file path to a folder that contains a main.go file or any Go source file with a main function.

Types

This section is empty.

Directories

Path Synopsis
cmd
genstdlib command
gi command
treerunner command
api_call command
nestedloop command
pointers command
remoting command
pkg
Code generated by cmd/genstdlib/main.go; DO NOT EDIT.
Code generated by cmd/genstdlib/main.go; DO NOT EDIT.
dap

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL