fast

package
v0.0.0-...-f54e8e0 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2024 License: MPL-2.0 Imports: 35 Imported by: 11

README

gomacro - A Go interpreter with Lisp-like macros

The package fast contains a faster reimplementation of gomacro interpreter.

To learn about gomacro, download, compile and use it, please refer to the main README.md

Current Status

STABLE.

Features and limitations

See ../doc/features-and-limitations.md

Misc TODO notes

  • contact github.com/neugram/ng author?
  • when importing a package, reuse compiled .so if exists already?
  • gomacro FILE: execute all the init() functions, then execute main() if (re)defined and package == "main"
  • try to run Go compiler tests

Documentation

Index

Constants

View Source
const (
	NoIndex             = int(-1)                   // index of functions, variables named "_" and of constants
	ConstBindDescriptor = BindDescriptor(ConstBind) // bind descriptor for all constants
)
View Source
const (
	MaxInt = base.MaxInt
)

Variables

View Source
var (
	// NEVER modify these!
	DebugOpContinue = DebugOp{0, nil}
	DebugOpStep     = DebugOp{MaxInt, nil}
)
View Source
var (
	None  = reflect.None // indicates "no value"
	True  = xr.ValueOf(true)
	False = xr.ValueOf(false)

	ZeroStrings = []string{}
	ZeroValues  = []xr.Value{}
)

Functions

func GENERICS_V1_CXX

func GENERICS_V1_CXX() bool

enable C++-style generics?

func GENERICS_V2_CTI

func GENERICS_V2_CTI() bool

enable "contracts are interfaces" generics?

func TailIdentifier

func TailIdentifier(s string) string

return the trailing substring of s that is a valid identifier

Types

type Assign

type Assign struct {
	// contains filtered or unexported fields
}

type Bind

type Bind struct {
	Lit
	Desc BindDescriptor
	Name string
}

Bind represents a constant, variable, function or builtin in the "compiler"

func (*Bind) AsSymbol

func (bind *Bind) AsSymbol(upn int) *Symbol

func (*Bind) AsVar

func (bind *Bind) AsVar(upn int, opt PlaceOption) *Var

func (*Bind) Const

func (bind *Bind) Const() bool

func (*Bind) ConstValue

func (bind *Bind) ConstValue() xr.Value

return bind value for constant binds. if bind is untyped constant, returns UntypedLit wrapped in reflect.Value

func (*Bind) Expr

func (bind *Bind) Expr(g *CompGlobals) *Expr

Expr returns an expression that will read the given Bind at runtime

func (*Bind) RuntimeValue

func (bind *Bind) RuntimeValue(g *CompGlobals, env *Env) xr.Value

return bind value. if bind is untyped constant, returns UntypedLit wrapped in reflect.Value

func (*Bind) String

func (bind *Bind) String() string

type BindClass

type BindClass uint

BindDescriptor uses two bits to store the class. use all remaining bits as unsigned => we lose only one bit when representing non-negative ints

const (
	ConstBind BindClass = iota
	FuncBind
	VarBind
	IntBind
	GenericFuncBind
	GenericTypeBind
)

func (BindClass) MakeDescriptor

func (class BindClass) MakeDescriptor(index int) BindDescriptor

func (BindClass) String

func (class BindClass) String() string

type BindDescriptor

type BindDescriptor BindClass

the zero value of BindDescriptor is a valid descriptor for all constants, and also for functions and variables named "_"

func (BindDescriptor) Class

func (desc BindDescriptor) Class() BindClass

IntBind returns true if BindIndex refers to a slot in Env.IntBinds (the default is a slot in Env.Binds)

func (BindDescriptor) Index

func (desc BindDescriptor) Index() int

Index returns the slice index to use in Env.Binds or Env.IntBinds to access a variable or function. returns NoIndex for variables and functions named "_"

func (BindDescriptor) Settable

func (desc BindDescriptor) Settable() bool

func (BindDescriptor) String

func (desc BindDescriptor) String() string

type Builtin

type Builtin struct {
	// interpreted code should not access "compile": not exported.
	// compile usually needs to modify Symbol: pass it by value.
	Compile func(c *Comp, sym Symbol, node *ast.CallExpr) *Call
	ArgMin  uint16
	ArgMax  uint16
}

Builtin represents a builtin function in the fast interpreter

func (Builtin) String

func (b Builtin) String() string

type Call

type Call struct {
	Fun      *Expr
	Args     []*Expr
	OutTypes []xr.Type
	Builtin  bool // if true, call is a builtin function
	Const    bool // if true, call has no side effects and always returns the same result => it can be invoked at compile time
	Ellipsis bool // if true, must use reflect.Value.CallSlice or equivalent to invoke the function
}

func (*Call) MakeArgfunsX1

func (call *Call) MakeArgfunsX1() []func(*Env) xr.Value

type Cmd

type Cmd struct {
	Name string
	Func func(interp *Interp, arg string, opt base.CmdOpt) (string, base.CmdOpt)
	Help string
}

Cmd is an interpreter special command.

The following Interp methods look for special commands and execute them: Cmd, EvalFile, EvalReader, ParseEvalPrint, ReadParseEvalPrint, Repl, ReplStdin note that Interp.Eval() does **not** look for special commands!

Cmd.Name is the command name **without** the initial ':'

it must be a valid Go identifier and must not be empty.
Using a reserved Go keyword (const, for, func, if, package, return, switch, type, var...)
or predefined identifier (bool, int, rune, true, false, nil...)
is a bad idea because it interferes with gomacro preprocessor mode.
Current limitation: Cmd.Name[0] must be ASCII.

Cmd.Help is the help string that will be displayed by :help

please look at current :help output and use the same layout if possible.

Cmd.Func is the command implementation. it receives as arguments:

  • the current Interp object,
  • the (possibly multi-line) argument string typed by the user note: it will always have balanced amounts of {} [] () ” "" and “
  • the current command options

Cmd.Func can perform any action desired by the implementor, including calls to Interp methods, and it must return:

  • a string to be subsequently evaluated by the interpreter. return the empty string if the command does not need any subsequent evaluation, or if it performed the evaluation by itself.
  • the updated command options. return the received 'opt' argument unless you need to update it.

If Cmd.Func needs to print something, it's recommended to use

   g := &interp.Comp.Globals
   g.Fprintf(g.Stdout, FORMAT, ARGS...)
instead of the various fmt.*Print* functions, in order to
pretty-print interpreter-generated objects (g.Fprintf)
and to honour configured redirections (g.Stdout)

To register a new special command, use Commands.Add() To unregister an existing special command, use Commands.Del() To list existing special commands, use Commands.List()

func (*Cmd) Match

func (cmd *Cmd) Match(prefix string) int

if cmd.Name starts with prefix return 0; else if cmd.Name < prefix return -1; else return 1

func (*Cmd) ShowHelp

func (cmd *Cmd) ShowHelp(g *base.Globals)

type Cmds

type Cmds struct {
	// contains filtered or unexported fields
}
var Commands Cmds

func (Cmds) Add

func (cmds Cmds) Add(cmd Cmd) bool

register a new Cmd. if cmd.Name is the empty string, do nothing and return false. overwrites any existing Cmd with the same name

func (Cmds) Del

func (cmds Cmds) Del(name string) bool

unregister an existing Cmd by name. return true if existed. Use with care!

func (Cmds) List

func (cmds Cmds) List() []Cmd

return the list of currently registered special commands

func (Cmds) Lookup

func (cmds Cmds) Lookup(prefix string) (Cmd, error)

search for a Cmd whose name starts with prefix. return (zero value, io.EOF) if no match. return (cmd, nil) if exactly one match. return (zero value, list of match names) if more than one match

func (Cmds) ShowHelp

func (cmds Cmds) ShowHelp(g *base.Globals)

type Code

type Code struct {
	List       []Stmt
	DebugPos   []token.Pos // for debugging interpreted code: position of each statement
	WithDefers bool        // true if code contains some defers
}

func (*Code) Append

func (code *Code) Append(stmt Stmt, pos token.Pos)

func (*Code) AsExpr

func (code *Code) AsExpr() *Expr

func (*Code) Clear

func (code *Code) Clear()

func (*Code) Exec

func (code *Code) Exec() func(*Env)

Exec returns a func(*Env) that will execute the compiled code

func (*Code) Len

func (code *Code) Len() int

func (*Code) Truncate

func (code *Code) Truncate(n int)

type Comp

type Comp struct {
	*CompGlobals
	CompBinds
	// UpCost is the number of *Env.Outer hops to perform at runtime to reach the *Env corresponding to *Comp.Outer
	// usually equals one. will be zero if this *Comp defines no local variables/functions.
	UpCost    int
	Depth     int
	Code      Code      // "compiled" code
	Loop      *LoopInfo // != nil when compiling a for or switch
	Func      *FuncInfo // != nil when compiling a function
	Labels    map[string]*int
	Outer     *Comp
	FuncMaker *funcMaker // used by debugger command 'backtrace' to obtain function name, type and binds for arguments and results
}

Comp is a tree-of-closures builder: it transforms ast.Nodes into closures for faster execution. Consider it a poor man's compiler (hence the name)

func NewComp

func NewComp(outer *Comp, code *Code) *Comp

func (*Comp) Add

func (c *Comp) Add(node *ast.BinaryExpr, xe *Expr, ye *Expr) *Expr

func (*Comp) AddressOf

func (c *Comp) AddressOf(node *ast.UnaryExpr) *Expr

func (*Comp) AddressOfVar

func (c *Comp) AddressOfVar(name string) *Expr

func (*Comp) And

func (c *Comp) And(node *ast.BinaryExpr, xe *Expr, ye *Expr) *Expr

func (*Comp) Andnot

func (c *Comp) Andnot(node *ast.BinaryExpr, xe *Expr, ye *Expr) *Expr

func (*Comp) Append

func (c *Comp) Append(stmt Stmt, pos token.Pos)

func (*Comp) Assign

func (c *Comp) Assign(node *ast.AssignStmt)

Assign compiles an *ast.AssignStmt into an assignment to one or more place

func (*Comp) BasicLit

func (c *Comp) BasicLit(node *ast.BasicLit) *Expr

func (*Comp) BinaryExpr

func (c *Comp) BinaryExpr(node *ast.BinaryExpr) *Expr

func (*Comp) BinaryExpr1

func (c *Comp) BinaryExpr1(node *ast.BinaryExpr, x *Expr, y *Expr) *Expr

func (*Comp) BinaryExprUntyped

func (c *Comp) BinaryExprUntyped(node *ast.BinaryExpr, x UntypedLit, y UntypedLit) *Expr

func (*Comp) Bind

func (c *Comp) Bind(bind *Bind) *Expr

Bind compiles a read operation on a constant, variable or function declared in 'c'

func (*Comp) BindUntyped

func (c *Comp) BindUntyped(kind untyped.Kind, value constant.Value) *Bind

func (*Comp) Block

func (c *Comp) Block(block *ast.BlockStmt)

Block compiles a block statement, i.e. { ... }

func (*Comp) Branch

func (c *Comp) Branch(node *ast.BranchStmt)

Branch compiles a break, continue, fallthrough or goto statement

func (*Comp) Break

func (c *Comp) Break(node *ast.BranchStmt)

Break compiles a "break" statement

func (*Comp) CallExpr

func (c *Comp) CallExpr(node *ast.CallExpr) *Expr

CallExpr compiles a function call or a type conversion

func (*Comp) Compile

func (c *Comp) Compile(in Ast) *Expr

compile code. support out-of-order declarations

func (*Comp) CompileNode

func (c *Comp) CompileNode(node ast.Node) *Expr

compile code. support out-of-order declarations too

func (*Comp) CompleteWords

func (c *Comp) CompleteWords(words []string) []string

implement code completion on ident.ident.ident.ident...

func (*Comp) CompositeLit

func (c *Comp) CompositeLit(node *ast.CompositeLit, t xr.Type) *Expr

func (*Comp) Continue

func (c *Comp) Continue(node *ast.BranchStmt)

Continue compiles a "continue" statement

func (*Comp) Convert

func (c *Comp) Convert(node ast.Expr, t xr.Type) *Expr

Convert compiles a type conversion expression

func (*Comp) Converter

func (c *Comp) Converter(tin, tout xr.Type) func(xr.Value) xr.Value

Converter returns a function that converts reflect.Value from tin to tout also supports conversion from interpreted types to interfaces

func (*Comp) Decl

func (c *Comp) Decl(node ast.Decl)

Decl compiles a constant, variable, function or type declaration - or an import

func (*Comp) DeclBindRuntimeValue

func (c *Comp) DeclBindRuntimeValue(bind *Bind) func(*Env, xr.Value)

DeclBindRuntimeValue compiles a variable, function or constant declaration with a reflect.Value passed at runtime

func (*Comp) DeclBuiltin0

func (c *Comp) DeclBuiltin0(name string, builtin Builtin) *Bind

DeclBuiltin0 compiles a builtin function declaration. For caller's convenience, returns allocated Bind

func (*Comp) DeclConst0

func (c *Comp) DeclConst0(name string, t xr.Type, value I, valueType xr.Type)

DeclConst0 compiles a constant declaration

func (*Comp) DeclConsts

func (c *Comp) DeclConsts(node ast.Spec, defaultType ast.Expr, defaultExprs []ast.Expr)

DeclConsts compiles a set of constant declarations

func (*Comp) DeclConsts0

func (c *Comp) DeclConsts0(names []string, t xr.Type, inits []*Expr)

func (*Comp) DeclEnvFunc0

func (c *Comp) DeclEnvFunc0(name string, envfun Function) *Bind

DeclEnvFunc0 compiles a function declaration that accesses interpreter's Env. For caller's convenience, returns allocated Bind

func (*Comp) DeclFunc

func (c *Comp) DeclFunc(funcdecl *ast.FuncDecl)

DeclFunc compiles a function, macro or method declaration For closure declarations, use FuncLit()

This method is named DeclFunc instead of FuncDecl for uniformity with DeclType, DeclConst*, DeclVar*, DeclGeneric*

func (*Comp) DeclFunc0

func (c *Comp) DeclFunc0(name string, fun I) *Bind

DeclFunc0 compiles a function declaration. For caller's convenience, returns allocated Bind

func (*Comp) DeclGenericFunc

func (c *Comp) DeclGenericFunc(decl *ast.FuncDecl)

DeclGenericFunc stores a generic function or method declaration for later instantiation

func (*Comp) DeclGenericType

func (c *Comp) DeclGenericType(spec *ast.TypeSpec)

DeclGenericType stores a generic type declaration for later instantiation

func (*Comp) DeclMultiVar0

func (c *Comp) DeclMultiVar0(names []string, t xr.Type, init *Expr, pos []token.Pos)

DeclMultiVar0 compiles multiple variable declarations from a single multi-valued expression

func (*Comp) DeclNamedType

func (c *Comp) DeclNamedType(name string) xr.Type

DeclNamedType executes a named type forward declaration. Returns nil if name == "_" Otherwise it must be followed by Comp.SetUnderlyingType(t) where t is the returned type

func (*Comp) DeclType

func (c *Comp) DeclType(spec ast.Spec)

DeclType compiles a type declaration.

func (*Comp) DeclType0

func (c *Comp) DeclType0(t xr.Type) xr.Type

DeclType0 declares a type in Go, types are computed only at compile time - no need for a runtime *Env

func (*Comp) DeclTypeAlias

func (c *Comp) DeclTypeAlias(name string, t xr.Type) xr.Type

DeclTypeAlias compiles a typealias declaration, i.e. type Foo = /*...*/ Returns the second argument.

func (*Comp) DeclVar0

func (c *Comp) DeclVar0(name string, t xr.Type, init *Expr) *Bind

DeclVar0 compiles a variable declaration. For caller's convenience, returns allocated Bind

func (*Comp) DeclVars

func (c *Comp) DeclVars(node ast.Spec)

DeclVars compiles a set of variable declarations i.e. "var x1, x2... [type] = expr1, expr2..."

func (*Comp) DeclVars0

func (c *Comp) DeclVars0(names []string, t xr.Type, inits []*Expr, pos []token.Pos)

DeclVars0 compiles a set of variable declarations

func (*Comp) DeclVarsShort

func (c *Comp) DeclVarsShort(lhs []ast.Expr, rhs []ast.Expr)

DeclVarsShort compiles a set of variable short declarations i.e. "x1, x2... := expr1, expr2..."

func (*Comp) Defer

func (c *Comp) Defer(node *ast.DeferStmt)

Defer compiles a "defer" statement

func (*Comp) Deref

func (c *Comp) Deref(addr *Expr) *Expr

Deref compiles unary operator * i.e. pointer dereference

func (*Comp) Eql

func (c *Comp) Eql(node *ast.BinaryExpr, xe *Expr, ye *Expr) *Expr

func (*Comp) Expr

func (c *Comp) Expr(in ast.Expr, t xr.Type) *Expr

Expr compiles an expression. t is optional and used for type inference on composite literals, see https://golang.org/ref/spec#Composite_literals

func (*Comp) Expr1

func (c *Comp) Expr1(in ast.Expr, t xr.Type) *Expr

Expr1 compiles an expression that returns a single value t is optional and used for type inference on composite literals, see https://golang.org/ref/spec#Composite_literals

func (*Comp) Expr1OrType

func (c *Comp) Expr1OrType(expr ast.Expr) (e *Expr, t xr.Type)

Expr1OrType compiles an single-valued expression or a type. performs simultaneous lookup for type names, constants, variables and functions

func (*Comp) Exprs

func (c *Comp) Exprs(nodes []ast.Expr) []*Expr

Exprs compiles multiple expressions

func (*Comp) ExprsMultipleValues

func (c *Comp) ExprsMultipleValues(nodes []ast.Expr, expectedValuesN int) (inits []*Expr)

ExprsMultipleValues either a single expression returning multiple values, or multiple expressions each returning a value.

func (*Comp) File

func (c *Comp) File(node *ast.File)

compile file. support out-of-order declarations too

func (*Comp) FileComp

func (c *Comp) FileComp() *Comp

func (*Comp) For

func (c *Comp) For(node *ast.ForStmt, labels []string)

For compiles a "for" statement

func (*Comp) FuncLit

func (c *Comp) FuncLit(funclit *ast.FuncLit) *Expr

FuncLit compiles a function literal, i.e. a closure. For functions or methods declarations, use FuncDecl()

func (*Comp) GenDecl

func (c *Comp) GenDecl(node *ast.GenDecl)

GenDecl compiles a constant, variable or type declaration - or an import

func (*Comp) GenericFunc

func (c *Comp) GenericFunc(node *ast.IndexExpr) *Expr

GenericFunc compiles a generic function name#[T1, T2...] instantiating it if needed.

func (*Comp) GenericType

func (c *Comp) GenericType(node *ast.IndexExpr) xr.Type

GenericType compiles a generic type name#[T1, T2...] instantiating it if needed.

func (*Comp) Geq

func (c *Comp) Geq(node *ast.BinaryExpr, xe *Expr, ye *Expr) *Expr

func (*Comp) GetPlace

func (c *Comp) GetPlace(place *Place) *Expr

compile a read operation on a place

func (*Comp) Go

func (c *Comp) Go(node *ast.GoStmt)

Go compiles a "go" statement i.e. a goroutine

func (*Comp) Goto

func (c *Comp) Goto(node *ast.BranchStmt)

Goto compiles a "goto" statement

func (*Comp) Gtr

func (c *Comp) Gtr(node *ast.BinaryExpr, xe *Expr, ye *Expr) *Expr

func (*Comp) Ident

func (c *Comp) Ident(name string) *Expr

Ident compiles a read operation on a constant, variable or function

func (*Comp) IdentPlace

func (c *Comp) IdentPlace(name string, opt PlaceOption) *Place

IdentPlace compiles an assignment to a variable, or taking the address of a variable

func (*Comp) If

func (c *Comp) If(node *ast.IfStmt)

If compiles an "if" statement

func (*Comp) Import

func (c *Comp) Import(node ast.Spec)

Import compiles a single import statement

func (*Comp) ImportPackagesOrError

func (c *Comp) ImportPackagesOrError(paths map[string]PackageName) (map[string]*Import, error)

ImportPackagesOrError imports multiple packages. If a PackageName is the empty string, it defaults to the name specified in the package clause of the package being imported

func (*Comp) IncDec

func (c *Comp) IncDec(node *ast.IncDecStmt)

IncDec compiles a "place++" or "place--" statement

func (*Comp) IndexExpr

func (c *Comp) IndexExpr(node *ast.IndexExpr) *Expr

IndexExpr compiles a read operation on obj[idx] or a generic function name#[T1, T2...]

func (*Comp) IndexExpr1

func (c *Comp) IndexExpr1(node *ast.IndexExpr) *Expr

IndexExpr1 compiles a single-valued read operation on obj[idx] or a generic function name#[T1, T2...]

func (*Comp) IndexPlace

func (c *Comp) IndexPlace(node *ast.IndexExpr, opt PlaceOption) *Place

func (*Comp) InterfaceProxy

func (c *Comp) InterfaceProxy(t xr.Type) r.Type

InterfaceProxy returns the proxy struct that implements a compiled interface

func (*Comp) Land

func (c *Comp) Land(node *ast.BinaryExpr, x *Expr, y *Expr) *Expr

func (*Comp) Leq

func (c *Comp) Leq(node *ast.BinaryExpr, xe *Expr, ye *Expr) *Expr

func (*Comp) List

func (c *Comp) List(list []ast.Stmt)

List compiles a slice of statements

func (*Comp) LookupField

func (c *Comp) LookupField(t xr.Type, name string) (field xr.StructField, numfound int)

LookupField performs a breadth-first search for struct field with given name

func (*Comp) LookupFieldOrMethod

func (c *Comp) LookupFieldOrMethod(t xr.Type, name string) (xr.StructField, bool, xr.Method, bool)

lookup fields and methods at the same time... it's and error if both exist at the same depth

func (*Comp) LookupMethod

func (c *Comp) LookupMethod(t xr.Type, name string) (mtd xr.Method, numfound int)

LookupMethod performs a breadth-first search for method with given name

func (*Comp) LookupVar

func (c *Comp) LookupVar(name string) *Var

LookupVar compiles the left-hand-side of an assignment, in case it's an identifier (i.e. a variable name)

func (*Comp) Lor

func (c *Comp) Lor(node *ast.BinaryExpr, x *Expr, y *Expr) *Expr

func (*Comp) Lss

func (c *Comp) Lss(node *ast.BinaryExpr, xe *Expr, ye *Expr) *Expr

func (*Comp) MacroExpand

func (c *Comp) MacroExpand(form Ast) (out Ast, everExpanded bool)

MacroExpand repeatedly invokes MacroExpand as long as the node represents a macro call. it returns the resulting node.

func (*Comp) MacroExpand1

func (c *Comp) MacroExpand1(in Ast) (out Ast, expanded bool)

if node represents a macro call, MacroExpandNode1 executes it and returns the resulting node. Otherwise returns the node argument unchanged

func (*Comp) MacroExpandCodewalk

func (c *Comp) MacroExpandCodewalk(in Ast) (out Ast, anythingExpanded bool)

MacroExpandCodewalk traverses the whole AST tree using pre-order traversal, and replaces each node with the result of MacroExpand(node). It implements the macroexpansion phase

func (*Comp) MacroExpandNode

func (c *Comp) MacroExpandNode(in ast.Node) (out ast.Node, everExpanded bool)

MacroExpandNode repeatedly invokes MacroExpandNode1 as long as the node represents a macro call. it returns the resulting node.

func (*Comp) MacroExpandNode1

func (c *Comp) MacroExpandNode1(in ast.Node) (out ast.Node, expanded bool)

if node represents a macro call, MacroExpandNode1 executes it and returns the resulting node. Otherwise returns the node argument unchanged

func (*Comp) MacroExpandNodeCodewalk

func (c *Comp) MacroExpandNodeCodewalk(in ast.Node) (out ast.Node, anythingExpanded bool)

MacroExpandNodeCodewalk traverses the whole AST tree using pre-order traversal, and replaces each node with the result of MacroExpandNode(node). It implements the macroexpansion phase

func (*Comp) Mul

func (c *Comp) Mul(node *ast.BinaryExpr, xe *Expr, ye *Expr) *Expr

func (*Comp) MultiImport

func (c *Comp) MultiImport(node *ast.GenDecl)

MultiImport compiles an 'import ( ... )' declaration, importing zero or more packages

func (*Comp) Neq

func (c *Comp) Neq(node *ast.BinaryExpr, xe *Expr, ye *Expr) *Expr

func (*Comp) NewBind

func (c *Comp) NewBind(name string, class BindClass, t xr.Type) *Bind

NewBind reserves space for a subsequent constant, function or variable declaration

func (*Comp) NewFuncBind

func (c *Comp) NewFuncBind(name string, t xr.Type) *Bind

NewFuncBind reserves space for a subsequent function declaration

func (*Comp) Or

func (c *Comp) Or(node *ast.BinaryExpr, xe *Expr, ye *Expr) *Expr

func (*Comp) Parse

func (c *Comp) Parse(src string) Ast

combined Parse + MacroExpandCodeWalk

func (*Comp) Place

func (c *Comp) Place(node ast.Expr) *Place

Place compiles the left-hand-side of an assignment

func (*Comp) Quasiquote

func (c *Comp) Quasiquote(in Ast) *Expr

Quasiquote expands and compiles ~quasiquote, if Ast starts with it

func (*Comp) Quo

func (c *Comp) Quo(node *ast.BinaryExpr, xe *Expr, ye *Expr) *Expr

func (*Comp) Range

func (c *Comp) Range(node *ast.RangeStmt, labels []string)

Range compiles a "for-range" statement

func (*Comp) Recv

func (c *Comp) Recv(node *ast.UnaryExpr, xe *Expr) *Expr

func (*Comp) Recv1

func (c *Comp) Recv1(node *ast.UnaryExpr, xe *Expr) *Expr

func (*Comp) Rem

func (c *Comp) Rem(node *ast.BinaryExpr, xe *Expr, ye *Expr) *Expr

func (*Comp) Resolve

func (c *Comp) Resolve(name string) *Symbol

func (*Comp) ResolveType

func (c *Comp) ResolveType(name string) xr.Type

func (*Comp) Return

func (c *Comp) Return(node *ast.ReturnStmt)

Return compiles a "return" statement

func (*Comp) Select

func (c *Comp) Select(node *ast.SelectStmt, labels []string)

func (*Comp) SelectorExpr

func (c *Comp) SelectorExpr(node *ast.SelectorExpr) *Expr

SelectorExpr compiles foo.bar, i.e. read access to methods, struct fields and imported packages

func (*Comp) SelectorPlace

func (c *Comp) SelectorPlace(node *ast.SelectorExpr, opt PlaceOption) *Place

SelectorPlace compiles a.b returning a settable and/or addressable Place

func (*Comp) Send

func (c *Comp) Send(node *ast.SendStmt)

func (*Comp) SetPlace

func (c *Comp) SetPlace(place *Place, op token.Token, init *Expr)

SetPlace compiles an assignment to a place: 'place op constant' and 'place op expression'

func (*Comp) SetUnderlyingType

func (c *Comp) SetUnderlyingType(t, underlying xr.Type)

func (*Comp) SetVar

func (c *Comp) SetVar(va *Var, op token.Token, init *Expr)

SetVar compiles an assignment to a variable: 'variable op constant' and 'variable op expression'

func (*Comp) ShiftUntyped

func (c *Comp) ShiftUntyped(node *ast.BinaryExpr, op token.Token, x UntypedLit, y UntypedLit) *Expr

func (*Comp) Shl

func (c *Comp) Shl(node *ast.BinaryExpr, xe *Expr, ye *Expr) *Expr

func (*Comp) Shr

func (c *Comp) Shr(node *ast.BinaryExpr, xe *Expr, ye *Expr) *Expr

func (*Comp) SliceExpr

func (c *Comp) SliceExpr(node *ast.SliceExpr) *Expr

SliceExpr compiles slice[lo:hi] and slice[lo:hi:max]

func (*Comp) StarExpr

func (c *Comp) StarExpr(node *ast.StarExpr) *Expr

StarExpr compiles unary operator * i.e. pointer dereference

func (*Comp) Stmt

func (c *Comp) Stmt(in ast.Stmt)

func (*Comp) Sub

func (c *Comp) Sub(node *ast.BinaryExpr, xe *Expr, ye *Expr) *Expr

func (*Comp) Switch

func (c *Comp) Switch(node *ast.SwitchStmt, labels []string)

func (*Comp) Symbol

func (c *Comp) Symbol(sym *Symbol) *Expr

Symbol compiles a read operation on a constant, variable or function

func (*Comp) TopComp

func (c *Comp) TopComp() *Comp

func (*Comp) TryLookupFieldOrMethod

func (c *Comp) TryLookupFieldOrMethod(t xr.Type, name string) (xr.StructField, bool, xr.Method, bool, error)

lookup fields and methods at the same time... it's and error if both exist at the same depth

func (*Comp) TryResolve

func (c *Comp) TryResolve(name string) *Symbol

func (*Comp) TryResolveType

func (c *Comp) TryResolveType(name string) xr.Type

func (*Comp) Type

func (c *Comp) Type(node ast.Expr) xr.Type

Type compiles a type expression.

func (*Comp) TypeArray

func (c *Comp) TypeArray(node *ast.ArrayType) (t xr.Type, ellipsis bool)

func (*Comp) TypeAssert1

func (c *Comp) TypeAssert1(node *ast.TypeAssertExpr) *Expr

TypeAssert1 compiles a single-valued type assertion

func (*Comp) TypeAssert2

func (c *Comp) TypeAssert2(node *ast.TypeAssertExpr) *Expr

TypeAssert2 compiles a multi-valued type assertion

func (*Comp) TypeFields

func (c *Comp) TypeFields(fields *ast.FieldList) (types []xr.Type, names []string)

func (*Comp) TypeFunction

func (c *Comp) TypeFunction(node *ast.FuncType) (t xr.Type, paramNames []string, resultNames []string)

func (*Comp) TypeFunctionOrMethod

func (c *Comp) TypeFunctionOrMethod(recv *ast.Field, node *ast.FuncType) (t xr.Type, paramNames []string, resultNames []string)

TypeFunctionOrMethod compiles a function type corresponding to given receiver and function declaration If receiver is not null, the returned tFunc will have it as receiver.

func (*Comp) TypeInterface

func (c *Comp) TypeInterface(node *ast.InterfaceType) xr.Type

compile an interface definition

func (*Comp) TypeOf

func (c *Comp) TypeOf(val interface{}) xr.Type

replacement of reflect.TypeOf() that uses xreflect.TypeOf()

func (*Comp) TypeSwitch

func (c *Comp) TypeSwitch(node *ast.TypeSwitchStmt, labels []string)

func (*Comp) UnaryExpr

func (c *Comp) UnaryExpr(node *ast.UnaryExpr) *Expr

func (*Comp) UnaryExprUntyped

func (c *Comp) UnaryExprUntyped(node *ast.UnaryExpr, xe *Expr) *Expr

func (*Comp) UnaryMinus

func (c *Comp) UnaryMinus(node *ast.UnaryExpr, xe *Expr) *Expr

func (*Comp) UnaryNot

func (c *Comp) UnaryNot(node *ast.UnaryExpr, xe *Expr) *Expr

func (*Comp) UnaryPlus

func (c *Comp) UnaryPlus(node *ast.UnaryExpr, xe *Expr) *Expr

func (*Comp) UnaryXor

func (c *Comp) UnaryXor(node *ast.UnaryExpr, xe *Expr) *Expr

func (*Comp) Xor

func (c *Comp) Xor(node *ast.BinaryExpr, xe *Expr, ye *Expr) *Expr

type CompBinds

type CompBinds struct {
	Binds      map[string]*Bind
	BindNum    int // len(Binds) == BindNum + IntBindNum + # of constants
	IntBindNum int
	// if address of some Env.Ints[index] was taken, we must honor it:
	// we can no longer reallocate Env.Ints[], thus we cannot declare IntBind variables
	// beyond Env.Ints[] capacity. In such case, we set IntBindMax to cap(Env.Ints):
	// Comp.NewBind() will allocate IntBind variables only up to IntBindMax,
	// then switch and allocate them as VarBind instead (they are slower and each one allocates memory)
	IntBindMax int
	Types      map[string]xr.Type
	Name       string // set by "package" directive
	Path       string
}

func (*CompBinds) NewBind

func (c *CompBinds) NewBind(o *base.Output, name string, class BindClass, t xr.Type) *Bind

NewBind reserves space for a subsequent constant, function or variable declaration

type CompGlobals

type CompGlobals struct {
	*IrGlobals
	Universe     *xr.Universe
	KnownImports map[string]*Import // map[path]*Import cache of known imports

	Prompt string
	// contains filtered or unexported fields
}

CompGlobals contains interpreter compile bookeeping information

func (*CompGlobals) CompileOptions

func (cg *CompGlobals) CompileOptions() CompileOptions

func (*CompGlobals) NewImport

func (cg *CompGlobals) NewImport(pkgref *genimport.PackageRef) *Import

func (*CompGlobals) TypeOfBool

func (g *CompGlobals) TypeOfBool() xr.Type

func (*CompGlobals) TypeOfBuiltin

func (g *CompGlobals) TypeOfBuiltin() xr.Type

func (*CompGlobals) TypeOfComplex128

func (g *CompGlobals) TypeOfComplex128() xr.Type

func (*CompGlobals) TypeOfComplex64

func (g *CompGlobals) TypeOfComplex64() xr.Type

func (*CompGlobals) TypeOfError

func (g *CompGlobals) TypeOfError() xr.Type

func (*CompGlobals) TypeOfFloat32

func (g *CompGlobals) TypeOfFloat32() xr.Type

func (*CompGlobals) TypeOfFloat64

func (g *CompGlobals) TypeOfFloat64() xr.Type

func (*CompGlobals) TypeOfFunction

func (g *CompGlobals) TypeOfFunction() xr.Type

func (*CompGlobals) TypeOfInt

func (g *CompGlobals) TypeOfInt() xr.Type

func (*CompGlobals) TypeOfInt16

func (g *CompGlobals) TypeOfInt16() xr.Type

func (*CompGlobals) TypeOfInt32

func (g *CompGlobals) TypeOfInt32() xr.Type

func (*CompGlobals) TypeOfInt64

func (g *CompGlobals) TypeOfInt64() xr.Type

func (*CompGlobals) TypeOfInt8

func (g *CompGlobals) TypeOfInt8() xr.Type

func (*CompGlobals) TypeOfInterface

func (g *CompGlobals) TypeOfInterface() xr.Type

func (*CompGlobals) TypeOfMacro

func (g *CompGlobals) TypeOfMacro() xr.Type

func (*CompGlobals) TypeOfPtrGenericFunc

func (g *CompGlobals) TypeOfPtrGenericFunc() xr.Type

func (*CompGlobals) TypeOfPtrGenericType

func (g *CompGlobals) TypeOfPtrGenericType() xr.Type

func (*CompGlobals) TypeOfPtrImport

func (g *CompGlobals) TypeOfPtrImport() xr.Type

func (*CompGlobals) TypeOfString

func (g *CompGlobals) TypeOfString() xr.Type

func (*CompGlobals) TypeOfUint

func (g *CompGlobals) TypeOfUint() xr.Type

func (*CompGlobals) TypeOfUint16

func (g *CompGlobals) TypeOfUint16() xr.Type

func (*CompGlobals) TypeOfUint32

func (g *CompGlobals) TypeOfUint32() xr.Type

func (*CompGlobals) TypeOfUint64

func (g *CompGlobals) TypeOfUint64() xr.Type

func (*CompGlobals) TypeOfUint8

func (g *CompGlobals) TypeOfUint8() xr.Type

func (*CompGlobals) TypeOfUintptr

func (g *CompGlobals) TypeOfUintptr() xr.Type

func (*CompGlobals) TypeOfUntypedLit

func (g *CompGlobals) TypeOfUntypedLit() xr.Type

func (*CompGlobals) UnloadPackage

func (cg *CompGlobals) UnloadPackage(path string)

remove package 'path' from the list of known packages. later attempts to import it again will trigger a recompile.

type CompileOptions

type CompileOptions int
const (
	COptKeepUntyped CompileOptions = 1 << iota // if set, Compile() on expressions will keep all untyped constants as such (in expressions where Go compiler would compute an untyped constant too)
	COptDefaults    CompileOptions = 0
)

type DebugOp

type DebugOp struct {
	// statements at env.CallDepth < Depth will be executed in single-stepping mode,
	// i.e. invoking the debugger after every statement
	Depth int
	// nil = do not panic.
	// otherwise, address of value to panic() in order to terminate execution
	Panic *interface{}
}

type Debugger

type Debugger interface {
	Breakpoint(ir *Interp, env *Env) DebugOp
	At(ir *Interp, env *Env) DebugOp
}

type EFlags

type EFlags uint32

EFlags represents the flags of an expression

const (
	EIsNil EFlags = 1 << iota
	EIsTypeAssert
)

func EFlag4Value

func EFlag4Value(value I) EFlags

func MakeEFlag

func MakeEFlag(flag bool, iftrue EFlags) EFlags

func (EFlags) IsNil

func (f EFlags) IsNil() bool

type Env

type Env struct {
	EnvBinds
	Outer           *Env
	IP              int
	Code            []Stmt
	Run             *Run
	FileEnv         *Env
	DebugPos        []token.Pos // for debugging interpreted code: position of each statement
	DebugComp       *Comp       // for debugging interpreted code: compiler with Binds, and to rebuild an Interp if needed
	Caller          *Env        // for debugging interpreted code: previous function in call stack. nil for nested *Env
	CallDepth       int         // for debugging interpreted code: depth of call stack
	UsedByClosure   bool        // a bitfield would introduce more races among goroutines
	IntAddressTaken bool        // true if &Env.Ints[index] was executed... then we cannot reuse or reallocate Ints
}

Env is the interpreter's runtime environment

func NewEnv

func NewEnv(outer *Env, nbind int, nintbind int) *Env

return a new, nested Env with given number of binds and intbinds

func (*Env) FreeEnv

func (env *Env) FreeEnv()

FreeEnv tells the interpreter that given nested *Env is no longer needed.

func (*Env) MarkUsedByClosure

func (env *Env) MarkUsedByClosure()

func (*Env) Top

func (env *Env) Top() *Env

func (*Env) Up

func (env *Env) Up(n int) *Env

type EnvBinds

type EnvBinds struct {
	Vals []xr.Value
	Ints []uint64
}

type ExecFlags

type ExecFlags uint32
const (
	EFStartDefer ExecFlags = 1 << iota // true next executed function body is a defer
	EFDefer                            // function body being executed is a defer
	EFDebug                            // function body is executed with debugging enabled
)

func (ExecFlags) IsDebug

func (ef ExecFlags) IsDebug() bool

func (ExecFlags) IsDefer

func (ef ExecFlags) IsDefer() bool

func (*ExecFlags) SetDebug

func (ef *ExecFlags) SetDebug(flag bool)

func (*ExecFlags) SetDefer

func (ef *ExecFlags) SetDefer(flag bool)

func (*ExecFlags) SetStartDefer

func (ef *ExecFlags) SetStartDefer(flag bool)

func (ExecFlags) StartDefer

func (ef ExecFlags) StartDefer() bool

type Expr

type Expr struct {
	Lit
	Types []xr.Type // in case the expression produces multiple values. if nil, use Lit.Type.
	Fun   I         // function that evaluates the expression at runtime.
	Sym   *Symbol   // in case the expression is a symbol
	EFlags
}

Expr represents an expression in the "compiler"

func (*Expr) AsStmt

func (e *Expr) AsStmt(c *Comp) Stmt

func (*Expr) AsUint64

func (e *Expr) AsUint64() func(*Env) uint64

* used by Comp.Shl(), Comp.Shr(), Comp.varSh{l,r}Expr() and Comp.placeSh{l,r}Expr(). * If e returns a signed integer type, the returned function * panics at runtime when the integer is negative. * This reproduces the behaviour of shift by signed integer introduced in Go 1.13

func (*Expr) AsX

func (e *Expr) AsX() func(*Env)

func (*Expr) AsX1

func (e *Expr) AsX1() func(*Env) xr.Value

func (*Expr) AsXV

func (e *Expr) AsXV(opts CompileOptions) func(*Env) (xr.Value, []xr.Value)

func (*Expr) CheckX1

func (e *Expr) CheckX1()

CheckX1() panics if given expression cannot be used in single-value context, for example because it returns no value at all. It just prints a warning if expression returns multiple values.

func (*Expr) Const

func (e *Expr) Const() bool

func (*Expr) ConstTo

func (e *Expr) ConstTo(t xr.Type) I

ConstTo checks that a constant Expr can be used as the given type. panics if not constant, or if Expr is a typed constant of different type actually performs type conversion (and subsequent overflow checks) ONLY on untyped constants.

func (*Expr) DefaultType

func (e *Expr) DefaultType() xr.Type

DefaultType returns the default type of an expression.

func (*Expr) EvalConst

func (expr *Expr) EvalConst(opts CompileOptions) I

func (*Expr) NumOut

func (e *Expr) NumOut() int

NumOut returns the number of values that an expression will produce when evaluated

func (*Expr) Out

func (e *Expr) Out(i int) xr.Type

Out returns the i-th type that an expression will produce when evaluated

func (*Expr) SetTypes

func (e *Expr) SetTypes(tout []xr.Type)

SetTypes sets the expression result types

func (*Expr) String

func (e *Expr) String() string

func (*Expr) To

func (e *Expr) To(c *Comp, t xr.Type)

To checks that an Expr can be used as (i.e. is assignable to) the given type, and converts Expr to the given type. panics if Expr has an incompatible type.

func (*Expr) TryAsPred

func (e *Expr) TryAsPred() (value bool, fun func(*Env) bool, err bool)

func (*Expr) WithFun

func (e *Expr) WithFun() I

WithFun ensures that Expr.Fun is a closure that will return the expression result:

if Expr is an untyped constant, WithFun converts the constant to its default type (panics on overflows),

then sets Expr.Fun to a closure that will return such constant.

if Expr is a typed constant, WithFun sets Expr.Fun to a closure that will return such constant. if Expr is not a constant, WithFun does nothing (Expr.Fun must be set already)

type FuncInfo

type FuncInfo struct {
	Name         string
	Param        []*Bind
	Result       []*Bind
	NamedResults bool
}

type Function

type Function struct {
	Fun  interface{}
	Type xr.Type
}

Function represents a function that accesses *Interp in the fast interpreter

type GenericFunc

type GenericFunc struct {
	Master    GenericFuncDecl            // master (i.e. non specialized) declaration
	Special   map[string]GenericFuncDecl // partially or fully specialized declarations. key is GenericFuncDecl.For converted to string
	Instances map[I]*GenericFuncInstance // cache of instantiated functions. key is [N]interface{}{T1, T2...}
	DeclScope *Comp                      // scope where generic function is declared
}

generic function

func (*GenericFunc) HasParam

func (f *GenericFunc) HasParam(name string) bool

func (*GenericFunc) Pos

func (f *GenericFunc) Pos() token.Pos

func (*GenericFunc) Signature

func (f *GenericFunc) Signature(name string) string

func (*GenericFunc) String

func (f *GenericFunc) String() string

type GenericFuncDecl

type GenericFuncDecl struct {
	Decl   *ast.FuncLit // generic function declaration. use a *ast.FuncLit because we will compile it with Comp.FuncLit()
	Params []string     // generic param names
	For    []ast.Expr   // partial or full specialization
}

a generic function declaration. either general, or partially specialized or fully specialized

func (*GenericFuncDecl) HasParam

func (master *GenericFuncDecl) HasParam(name string) bool

func (*GenericFuncDecl) Signature

func (master *GenericFuncDecl) Signature(name string) string

type GenericFuncInstance

type GenericFuncInstance struct {
	Func *func(*Env) xr.Value
	Type xr.Type
}

an instantiated (and compiled) generic function.

type GenericType

type GenericType struct {
	Master    GenericTypeDecl            // master (i.e. non specialized) declaration
	Special   map[string]GenericTypeDecl // partially or fully specialized declarations. key is TemplateTypeDecl.For converted to string
	Instances map[I]xr.Type              // cache of instantiated types. key is [N]interface{}{T1, T2...}
}

func (*GenericType) Pos

func (t *GenericType) Pos() token.Pos

func (*GenericType) String

func (t *GenericType) String() string

type GenericTypeDecl

type GenericTypeDecl struct {
	Decl   ast.Expr   // type declaration body. use an ast.Expr because we will compile it with Comp.Type()
	Alias  bool       // true if declaration is an alias: 'type Foo = ...'
	Params []string   // generic param names
	For    []ast.Expr // for partial or full specialization
}

a generic type declaration. either general, or partially specialized or fully specialized

type I

type I = interface{}

func GenericKey

func GenericKey(vals []I, types []xr.Type) I

type Import

type Import struct {
	// model as a combination of CompBinds and EnvBinds, because to support the command 'package PATH'
	// we must convert Comp+Env to Import and vice-versa.
	// This has the added benefit of allowing packages to freely mix
	// interpreted and compiled constants, functions, variables and types.
	CompBinds
	*EnvBinds
	// contains filtered or unexported fields
}

Import represents an imported package. we cannot name it "Package" because it conflicts with ast2.Package

func (*Import) Show

func (imp *Import) Show(g *CompGlobals, env *Env)

func (*Import) String

func (imp *Import) String() string

type Interp

type Interp struct {
	Comp *Comp
	// contains filtered or unexported fields
}

Interp is the fast interpreter. It contains both the tree-of-closures builder Comp and the interpreter's runtime environment Env

func New

func New() *Interp

func NewInnerInterp

func NewInnerInterp(outer *Interp, name string, path string) *Interp

func (*Interp) AddressOfVar

func (ir *Interp) AddressOfVar(name string) (addr xr.Value)

AddressOfVar compiles the expression &name, then executes it returns the zero value if name is not found or is not addressable

func (*Interp) ChangePackage

func (ir *Interp) ChangePackage(alias PackageName, path string)

func (*Interp) Cmd

func (ir *Interp) Cmd(src string) (string, base.CmdOpt)

execute one of the REPL commands starting with ':' return any remainder string to be evaluated, and the options to evaluate it

func (*Interp) Compile

func (ir *Interp) Compile(src string) *Expr

combined Parse + Compile

func (*Interp) CompileAst

func (ir *Interp) CompileAst(form ast2.Ast) *Expr

func (*Interp) CompileNode

func (ir *Interp) CompileNode(node ast.Node) *Expr

func (*Interp) CompleteWords

func (ir *Interp) CompleteWords(line string, pos int) (head string, completions []string, tail string)

implement code completion API github.com/pererh/liner.WordCompleter Currently only supports global symbols and imported packages, optionally followed by a dot-separated sequence of field or method names, including embedded fields and wrapper methods.

func (*Interp) Debug

func (ir *Interp) Debug(src string) ([]xr.Value, []xr.Type)

combined Parse + Compile + DebugExpr

func (*Interp) DebugExpr

func (ir *Interp) DebugExpr(e *Expr) ([]xr.Value, []xr.Type)

execute with single-step debugging. to run without debugging, use Interp.RunExpr() instead

func (*Interp) DebugExpr1

func (ir *Interp) DebugExpr1(e *Expr) (xr.Value, xr.Type)

execute with single-step debugging. to run without debugging, use Interp.RunExpr() instead

func (*Interp) DeclBuiltin

func (ir *Interp) DeclBuiltin(name string, builtin Builtin)

DeclBuiltin compiles a builtin function declaration

func (*Interp) DeclConst

func (ir *Interp) DeclConst(name string, t xr.Type, value I)

DeclConst compiles a constant declaration

func (*Interp) DeclEnvFunc

func (ir *Interp) DeclEnvFunc(name string, function Function)

DeclEnvFunc compiles a function declaration that accesses interpreter's *CompEnv

func (*Interp) DeclFunc

func (ir *Interp) DeclFunc(name string, fun I)

DeclFunc compiles a function declaration

func (*Interp) DeclType

func (ir *Interp) DeclType(t xr.Type)

DeclType declares a type

func (*Interp) DeclTypeAlias

func (ir *Interp) DeclTypeAlias(alias string, t xr.Type)

DeclType declares a type alias

func (*Interp) DeclVar

func (ir *Interp) DeclVar(name string, t xr.Type, value I)

DeclVar compiles a variable declaration

func (*Interp) Eval

func (ir *Interp) Eval(src string) ([]xr.Value, []xr.Type)

combined Parse + Compile + RunExpr

func (*Interp) Eval1

func (ir *Interp) Eval1(src string) (xr.Value, xr.Type)

combined Parse + Compile + RunExpr1

func (*Interp) EvalFile

func (ir *Interp) EvalFile(filepath string) (comments string, err error)

func (*Interp) EvalReader

func (ir *Interp) EvalReader(src io.Reader) (comments string, err error)

func (*Interp) ImportPackage

func (ir *Interp) ImportPackage(alias PackageName, path string) *Import

ImportPackage imports a single package. Panics if the import fails. If alias is the empty string "", it defaults to the identifier specified in the package clause of the package being imported

If alias is ".", it performs a dot import i.e. it declares all imported constants, functions, types and variables in the current package

func (*Interp) ImportPackagesOrError

func (ir *Interp) ImportPackagesOrError(paths map[string]PackageName) (map[string]*Import, error)

ImportPackagesOrError imports multiple packages. If alias is the empty string "", it defaults to the name specified in the package clause of the package being imported

If alias is ".", it performs a dot import i.e. it declares all imported constants, functions, types and variables in the current package

func (*Interp) Inspect

func (ir *Interp) Inspect(src string)

func (*Interp) Interrupt

func (ir *Interp) Interrupt(os.Signal)

func (*Interp) Parse

func (ir *Interp) Parse(src string) ast2.Ast

parse + macroexpansion + collect declarations & statements

func (*Interp) ParseEvalPrint

func (ir *Interp) ParseEvalPrint(src string) (callAgain bool)

func (*Interp) PrepareEnv

func (ir *Interp) PrepareEnv() *Env

func (*Interp) Read

func (ir *Interp) Read() (string, int)

return read string and position of first non-comment token. return "", -1 on EOF

func (*Interp) ReadParseEvalPrint

func (ir *Interp) ReadParseEvalPrint() (callAgain bool)

func (*Interp) Repl

func (ir *Interp) Repl(in *bufio.Reader)

func (*Interp) ReplStdin

func (ir *Interp) ReplStdin()

func (*Interp) RunExpr

func (ir *Interp) RunExpr(e *Expr) ([]xr.Value, []xr.Type)

run without debugging. to execute with single-step debugging, use Interp.DebugExpr() instead

func (*Interp) RunExpr1

func (ir *Interp) RunExpr1(e *Expr) (xr.Value, xr.Type)

run without debugging. to execute with single-step debugging, use Interp.DebugExpr() instead

func (*Interp) SetDebugger

func (ir *Interp) SetDebugger(debugger Debugger)

func (*Interp) SetInspector

func (ir *Interp) SetInspector(inspector base.Inspector)

func (*Interp) ShowAsPackage

func (ir *Interp) ShowAsPackage()

func (*Interp) ShowImportedPackage

func (ir *Interp) ShowImportedPackage(name string)

func (*Interp) ShowPackage

func (ir *Interp) ShowPackage(name string)

func (*Interp) TypeOf

func (ir *Interp) TypeOf(val interface{}) xr.Type

replacement of reflect.TypeOf() that uses xreflect.TypeOf()

func (*Interp) ValueOf

func (ir *Interp) ValueOf(name string) (value xr.Value)

ValueOf retrieves the value of a constant, function or variable in the current package. The returned value is settable and addressable only for variables. Returns the zero value if name is not found

type IrGlobals

type IrGlobals struct {
	base.Globals
	// contains filtered or unexported fields
}

IrGlobals contains interpreter configuration

func NewIrGlobals

func NewIrGlobals() *IrGlobals

type Lit

type Lit struct {

	// Type is nil for literal nils.
	// For all other literals, Type is xr.TypeOf(Lit.Value)
	//
	// when Lit is embedded in other structs that represent non-constant expressions,
	// Type is the first type returned by the expression (nil if returns no values)
	Type xr.Type

	// Value is one of:
	//   nil, bool, int, int8, int16, int32, int64,
	//   uint, uint8, uint16, uint32, uint64, uintptr,
	//   float32, float64, complex64, complex128, string,
	//   UntypedLit
	//
	// when Lit is embedded in other structs that represent non-constant expressions,
	// Value is usually nil
	//
	// when Lit is embedded in a Bind with class == GenericFuncBind,
	// Value is the *GenericFunc containing the function source code
	// to be specialized and compiled upon instantiation.
	Value I
}

Lit represents a literal value, i.e. a typed or untyped constant

func (*Lit) ConstTo

func (lit *Lit) ConstTo(t xr.Type) I

ConstTo checks that a Lit can be used as the given type. panics if Lit is a typed constant of different type actually performs type conversion (and subsequent overflow checks) ONLY on untyped constants.

func (*Lit) ConstValue

func (lit *Lit) ConstValue() xr.Value

func (*Lit) DefaultType

func (lit *Lit) DefaultType() xr.Type

DefaultType returns the default type of a constant.

func (Lit) String

func (lit Lit) String() string

func (*Lit) Untyped

func (lit *Lit) Untyped() bool

Untyped returns true if Lit is an untyped constant

func (*Lit) UntypedKind

func (lit *Lit) UntypedKind() untyped.Kind

UntypedKind returns the reflect.Kind of untyped constants, i.e. their "default type"

type LoopInfo

type LoopInfo struct {
	Break      *int
	Continue   *int
	ThisLabels []string // sorted. for labeled "switch" and "for"
}

func (*LoopInfo) HasLabel

func (l *LoopInfo) HasLabel(label string) bool

type Macro

type Macro struct {
	// contains filtered or unexported fields
}

Macro represents a macro in the fast interpreter

type PackageName

type PackageName = genimport.PackageName

type Place

type Place struct {
	Var
	// Fun is nil for variables.
	// For non-variables, returns a settable and addressable reflect.Value: the place itself.
	// For map[key], Fun returns the map itself (which may NOT be settable).
	// Call Fun only once, it may have side effects!
	Fun func(*Env) xr.Value
	// Addr is nil for variables.
	// For non-variables, it will return the address of the place.
	// For map[key], it is nil since map[key] is not addressable
	// Call Addr only once, it may have side effects!
	Addr func(*Env) xr.Value
	// used only for map[key], returns key. call it only once, it may have side effects!
	MapKey  func(*Env) xr.Value
	MapType xr.Type
}

Place represents a settable place or, equivalently, its address

func (*Place) IsVar

func (place *Place) IsVar() bool

type PlaceOption

type PlaceOption bool // the reason why we want a place: either to write into it, or to take its address
const (
	PlaceSettable PlaceOption = false
	PlaceAddress  PlaceOption = true
)

func (PlaceOption) String

func (opt PlaceOption) String() string

type Run

type Run struct {
	*IrGlobals

	Interrupt    Stmt
	Signals      base.Signals // set by defer, return, breakpoint, debugger and Run.interrupt(os.Signal)
	ExecFlags    ExecFlags
	CurrEnv      *Env        // caller of current function. used ONLY at function entry to build call stack
	InstallDefer func()      // defer function to be installed
	DeferOfFun   *Env        // function whose defer are running
	PanicFun     *Env        // the currently panicking function
	Panic        interface{} // current panic. needed for recover()
	CmdOpt       base.CmdOpt
	Debugger     Debugger
	DebugDepth   int // depth of function to debug with single-step
	PoolSize     int
	Pool         [poolCapacity]*Env
	// contains filtered or unexported fields
}

Run contains per-goroutine interpreter runtime bookeeping information

type Stmt

type Stmt func(*Env) (Stmt, *Env)

Stmt represents a statement in the fast interpreter

type Symbol

type Symbol struct {
	Bind
	Upn int
}

Symbol represents a resolved constant, function, variable or builtin

func (*Symbol) AsVar

func (sym *Symbol) AsVar(opt PlaceOption) *Var

func (*Symbol) Expr

func (sym *Symbol) Expr(depth int, g *CompGlobals) *Expr

Expr returns an expression that will read the given Symbol at runtime

func (*Symbol) String

func (sym *Symbol) String() string

type TypeAssertionError

type TypeAssertionError struct {
	Interface       xr.Type
	Concrete        xr.Type
	ReflectConcrete r.Type // in case Concrete is not available
	Asserted        xr.Type
	MissingMethod   *xr.Method // one method needed by Interface, missing from Concrete
}

A TypeAssertionError explains a failed type assertion.

func (*TypeAssertionError) Error

func (e *TypeAssertionError) Error() string

func (*TypeAssertionError) RuntimeError

func (*TypeAssertionError) RuntimeError()

type UntypedLit

type UntypedLit = untyped.Lit

type Var

type Var struct {
	// when Var is embedded in other structs that represent non-identifiers,
	// Upn and Desc are usually the zero values
	Upn  int
	Desc BindDescriptor
	Type xr.Type
	Name string
}

Var represents a settable variable

func (*Var) Address

func (va *Var) Address(maxdepth int) *Expr

func (*Var) AsPlace

func (va *Var) AsPlace() *Place

func (*Var) AsSymbol

func (va *Var) AsSymbol() *Symbol

func (*Var) String

func (va *Var) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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