classic

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: 24 Imported by: 0

README

gomacro - A Go interpreter with Lisp-like macros

The package classic contains the original old, small (and slow) implementation of gomacro interpreter.

For the current fast interpreter, see ../fast/README.md.

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

Current Status

STABLE.

Features and limitations

The classic interpreter has some additional limitations with respect to the fast one. Most notably:

  • untyped constants and arithmetic on them, as 1<<100, are evaluated as typed constants.
  • types are not accurate when mixing untyped constants with typed values, i.e. uint8(10) + 1 gives uint64(11) instead of uint8(11).
  • interpreted interfaces are not functional (they can only be declared).
  • interpreted types cannot implement compiled interfaces.
  • struct tags are ignored.
  • support for embedded fields in structs is very limited - they mostly work as non-embedded fields.

Documentation

Index

Constants

View Source
const MultiThread = true

Variables

View Source
var (
	NilREnv = []r.Value{r.ValueOf(nilEnv)}
)

Functions

This section is empty.

Types

type BindMap

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

func (*BindMap) AsMap

func (x *BindMap) AsMap() map[string]r.Value

func (*BindMap) Clear

func (x *BindMap) Clear()

func (*BindMap) Del

func (x *BindMap) Del(key string)

func (*BindMap) Ensure

func (x *BindMap) Ensure() *BindMap

ALWAYS use pointers to BindMap, because it contains a sync.RWMutex and https://golang.org/pkg/sync/#RWMutex states "A RWMutex must not be copied after first use."

func (*BindMap) Get

func (x *BindMap) Get(key string) (r.Value, bool)

func (*BindMap) Get1

func (x *BindMap) Get1(key string) r.Value

func (*BindMap) Merge

func (x *BindMap) Merge(binds map[string]r.Value)

func (*BindMap) Set

func (x *BindMap) Set(key string, val r.Value)

type CallFrame

type CallFrame struct {
	FuncEnv     *Env
	InnerEnv    *Env          // innermost Env
	CurrentCall *ast.CallExpr // call currently in progress
	// contains filtered or unexported fields
}

type CallStack

type CallStack struct {
	Frames []CallFrame
}

type Cmd

type Cmd struct {
	Name string
	Func func(ir *Interp, arg string, opt CmdOpt) (string, CmdOpt)
}

func (*Cmd) Match

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

type Cmds

type Cmds map[byte]Cmd

func (Cmds) Lookup

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

func (Cmds) ShowHelp

func (cmds Cmds) ShowHelp(g *Globals)

type Constructor

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

type Env

type Env struct {
	*ThreadGlobals
	Binds     BindMap
	Types     TypeMap
	Proxies   TypeMap
	Outer     *Env
	CallStack *CallStack

	Name, Path string
	// contains filtered or unexported fields
}

func NewEnv

func NewEnv(outer *Env, path string) *Env

func (*Env) AsPackage

func (env *Env) AsPackage() imports.Package

func (*Env) CallerFrame

func (env *Env) CallerFrame() *CallFrame

CallerFrame returns the CallFrame representing the caller's function. needed by recover()

func (*Env) ChangePackage

func (env *Env) ChangePackage(path string) *Env

func (*Env) CurrentFrame

func (env *Env) CurrentFrame() *CallFrame

CurrentFrame returns the CallFrame representing the current function call

func (*Env) DefineConst

func (env *Env) DefineConst(name string, t r.Type, value r.Value) r.Value

func (*Env) DefineFunc

func (env *Env) DefineFunc(name string, t r.Type, value r.Value) r.Value

func (*Env) DefineVar

func (env *Env) DefineVar(name string, t r.Type, value r.Value) r.Value

func (*Env) Eval

func (env *Env) Eval(src interface{}) (r.Value, []r.Value)

func (*Env) Eval1

func (env *Env) Eval1(src interface{}) r.Value

func (*Env) EvalAst

func (env *Env) EvalAst(in ast2.Ast) (r.Value, []r.Value)

func (*Env) EvalAst1

func (env *Env) EvalAst1(in ast2.Ast) r.Value

func (*Env) EvalNode

func (env *Env) EvalNode(node ast.Node) (r.Value, []r.Value)

func (*Env) EvalNode1

func (env *Env) EvalNode1(node ast.Node) r.Value

func (*Env) FileEnv

func (env *Env) FileEnv() *Env

func (*Env) Inspect

func (env *Env) Inspect(str string)

func (*Env) MacroExpand

func (env *Env) MacroExpand(in ast.Node) (out ast.Node, everExpanded bool)

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

func (*Env) MacroExpand1

func (env *Env) MacroExpand1(in ast.Node) (out ast.Node, expanded bool)

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

func (*Env) MacroExpandAstCodewalk

func (env *Env) MacroExpandAstCodewalk(in Ast) (out Ast, anythingExpanded bool)

func (*Env) MacroExpandCodewalk

func (env *Env) MacroExpandCodewalk(in ast.Node) (out ast.Node, 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 (*Env) MergePackage

func (env *Env) MergePackage(pkg imports.Package)

func (*Env) Parse

func (env *Env) Parse(src interface{}) ast2.Ast

Parse, with macroexpansion

func (*Env) ParseOnly

func (env *Env) ParseOnly(src interface{}) ast2.Ast

parse, without macroexpansion

func (*Env) ShowPackage

func (env *Env) ShowPackage(packageName string)

func (*Env) TopEnv

func (env *Env) TopEnv() *Env

func (*Env) ValueOf

func (env *Env) ValueOf(name string) (value r.Value)

ValueOf returns the value of a constant, function or variable. for variables, the returned reflect.Value is settable and addressable returns the zero reflect.Value if not found

type Error_builtin

type Error_builtin struct {
	Obj    interface{}
	Error_ func() string
}

func (*Error_builtin) Error

func (Proxy *Error_builtin) Error() string

type Function

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

type Interp

type Interp struct {
	*Env
}

func New

func New() *Interp

func (*Interp) ChangePackage

func (ir *Interp) ChangePackage(path string)

func (*Interp) Cmd

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

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

func (*Interp) EvalFile

func (ir *Interp) EvalFile(filePath string)

func (*Interp) Interrupt

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

func (*Interp) ParseEvalPrint

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

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()

type Macro

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

type Methods

type Methods map[string]TypedValue

*

  • inside Methods, each string is the method name
  • and each TypedValue is {
  • Type: the method signature, i.e. the type of a func() *without* the receiver (to allow comparison with Interface methods)
  • Value: the method implementation, i.e. a func() whose first argument is the receiver,
  • }

type PackageName

type PackageName = genimport.PackageName

type ThreadGlobals

type ThreadGlobals struct {
	*Globals
	AllMethods map[r.Type]Methods // methods implemented by interpreted code
	// contains filtered or unexported fields
}

func NewThreadGlobals

func NewThreadGlobals() *ThreadGlobals

func (*ThreadGlobals) ObjMethodByName

func (ir *ThreadGlobals) ObjMethodByName(obj r.Value, name string) r.Value

ObjMethodByName returns a function value corresponding to the method of obj with the given name. The arguments to a Call on the returned function should not include a receiver; the returned function will always use obj as the receiver. It returns the zero Value if no method was found.

type TypeMap

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

func (*TypeMap) AsMap

func (x *TypeMap) AsMap() map[string]r.Type

func (*TypeMap) Clear

func (x *TypeMap) Clear()

func (*TypeMap) Del

func (x *TypeMap) Del(key string)

func (*TypeMap) Ensure

func (x *TypeMap) Ensure() *TypeMap

func (*TypeMap) Get

func (x *TypeMap) Get(key string) (r.Type, bool)

func (*TypeMap) Merge

func (x *TypeMap) Merge(types map[string]r.Type)

func (*TypeMap) Set

func (x *TypeMap) Set(key string, val r.Type)

type TypedValue

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

Jump to

Keyboard shortcuts

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