ssainterp

package module
v0.0.0-...-8c0afba Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2016 License: MIT Imports: 8 Imported by: 0

README

ssainterp

A Golang interpreter, built upon golang.org/x/tools/go/ssa/interp. That original code contains the comment that "It is not, and will never be, a production-quality Go interpreter.", but that does not mean that it could not be of use in some very limited circumstances.

The planned use-case for this interpreter is where there is no access to a Go compiler in the production environment, for example in an embedded system or in Google App Engine.

NOT PRODUCTION READY

This code is a work-in-progress. It is neither fully working nor properly documented, and is full of security vulnerabilities.

The tests are only known to pass on OSX & Ubuntu. The very simple benchmark suggests this interpreter runs 881x slower than compiled code, but 12x faster than the original implementation it was developed from.

Some ideas for future development were set-out in a discussion document.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExtFunc

type ExtFunc struct {
	Nam string // e.g. "main.Foo"
	Fun Func
}

ExtFunc defines an external go function callable from the interpreter.

type Func

type Func func([]interp.Ivalue) interp.Ivalue

Func is the signature of a normal go function that can be called from the interpreter. TODO: currently the parameters can only reliably contain simple values.

type Interpreter

type Interpreter struct {
	Context *interp.Context
	Panic   interface{}
	MainPkg *ssa.Package
	// contains filtered or unexported fields
}

Interpreter defines the datastructure to run an interpreter.

func Run

func Run(code string, extFns []ExtFunc, args []string, output io.Writer) (interp *Interpreter, exitCode int, error error)

Run the interpreter, given some code.

Example

ExampleRun trivial example, more to add.

package main

import (
	"bytes"
	"fmt"

	"github.com/go-interpreter/ssainterp"
)

const code = `
package main

import "fmt"

func main() {
	fmt.Println("42")
}

`

// ExampleRun trivial example, more to add.
func main() {
	var output bytes.Buffer
	ssainterp.Run(code, nil, nil, &output)
	fmt.Println(output.String())
}
Output:

42

func (*Interpreter) Call

func (ssai *Interpreter) Call(name string, args []interp.Ivalue) (interp.Ivalue, error)

Call a function in an already created interpreter.

Directories

Path Synopsis
Package interp defines an interpreter for the SSA representation of Go programs.
Package interp defines an interpreter for the SSA representation of Go programs.

Jump to

Keyboard shortcuts

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