Documentation ¶
Overview ¶
Package quasigo implements a Go subset compiler and interpreter.
The implementation details are not part of the contract of this package.
Index ¶
- func Disasm(env *Env, fn Func) string
- type CallResult
- type CompileContext
- type Env
- func (env *Env) AddFunc(pkgPath, funcName string, f Func)
- func (env *Env) AddNativeFunc(pkgPath, funcName string, f func(qnative.CallContext))
- func (env *Env) AddNativeMethod(typeName, methodName string, f func(qnative.CallContext))
- func (env *Env) GetEvalEnv(stackSize int) *EvalEnv
- func (env *Env) GetFunc(pkgPath, funcName string) Func
- type EvalEnv
- type Func
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CallResult ¶
type CallResult struct {
// contains filtered or unexported fields
}
CallResult is a return value of Call function.
func Call ¶
func Call(env *EvalEnv, fn Func) CallResult
Call invokes a given function. Before calling this function, be sure to bind arguments to the env using BindArgs.
func (CallResult) BoolValue ¶
func (res CallResult) BoolValue() bool
func (CallResult) IntValue ¶
func (res CallResult) IntValue() int
func (CallResult) StringValue ¶
func (res CallResult) StringValue() string
type CompileContext ¶
type CompileContext struct { // Env is shared environment that should be used for all functions // being compiled; then it should be used to execute these functions. Env *Env Package *types.Package Types *types.Info Sizes types.Sizes Fset *token.FileSet Optimize bool Static bool TestingContext interface{} }
CompileContext is used to provide necessary data to the compiler.
type Env ¶
type Env struct {
// contains filtered or unexported fields
}
Env is used to hold both compilation and evaluation data.
func (*Env) AddNativeFunc ¶
func (env *Env) AddNativeFunc(pkgPath, funcName string, f func(qnative.CallContext))
AddNativeFunc binds `$pkgPath.$funcName` symbol with f. A pkgPath should be a full package path in which funcName is defined.
func (*Env) AddNativeMethod ¶
func (env *Env) AddNativeMethod(typeName, methodName string, f func(qnative.CallContext))
AddNativeMethod binds `$typeName.$methodName` symbol with f. A typeName should be fully qualified, like `github.com/user/pkgname.TypeName`. It method is defined only on pointer type, the typeName should start with `*`.
func (*Env) GetEvalEnv ¶
GetEvalEnv creates a new goroutine-local handle of env. Stack size is amount of bytes we allocate for all stack frames of this env.
type EvalEnv ¶
type EvalEnv struct {
// contains filtered or unexported fields
}
EvalEnv is a goroutine-local handle for Env. To get one, use Env.GetEvalEnv() method.
func (*EvalEnv) BindArgs ¶
func (env *EvalEnv) BindArgs(args ...interface{})
BindArgs prepares the arguments for the call. Bound args can be used many times if you don't need to change the call arguments.
If BindArgs+Call is not convenient for you, consider using the simple wrapper that does this combination for you. Note, however, that reusing bound arguments, whether possible, if more efficient.
type Func ¶
type Func struct {
// contains filtered or unexported fields
}
Func is a compiled function that is ready to be executed.
func Compile ¶
func Compile(ctx *CompileContext, fn *ast.FuncDecl) (Func, error)
Compile prepares an executable version of fn.
func (Func) ScalarConstants ¶
TODO: remove this. Only needed for testing.
func (Func) StringConstants ¶
TODO: remove this. Only needed for testing.