common

package
v0.0.0-...-ed3c113 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2016 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterOpcode

func RegisterOpcode(code byte, load LoadFunc)

Types

type Context

type Context interface {
	// 是否是严格模式
	IsStrict() bool
	// 从栈顶弹出一个元素,未找到返回 nil
	Pop() interface{}
	// 压入一个元素到栈顶
	Push(val interface{}) interface{}
	// 获取或设置一个变量
	Var(name string, val ...interface{}) (interface{}, bool)
	// 打印一个对象到输出
	Print(obj interface{}, escape bool) error
	// 启用一个新的域
	Scope() error
	// 注销一个域
	Unscope() error
	// 释放当前上下文
	Free()

	Load(src, ref string) (Loader, error)

	Exec(loader Loader, ptr Ptr) error

	TemplateFunc(name string, fn ...TemplateFunc) TemplateFunc
}

Context 表示一个运行时上下文

type I18N

type I18N interface {
	Lang(local, name string, args ...interface{}) (lang string)
}

type LineNo

type LineNo uint16

LineNo 行号

type LoadFunc

type LoadFunc func(loader Loader, ptr Ptr, line LineNo, flag byte) Opcode

type Loader

type Loader interface {
	ReadByte() (byte, error)
	ReadBool() (bool, error)
	ReadPtr() (Ptr, error)
	ReadInt() (int, error)
	ReadLong() (int64, error)
	ReadFloat() (float64, error)
	ReadString() (string, error)
	Load(ptr Ptr) (Opcode, error)

	TemplateName() string
	StartPtr() Ptr

	PutBlock(blockID string, block Opcode)
	GetBlock(blockID string) (block Opcode, ok bool)

	SetBody(body Loader, start Ptr)
	BodyLoader() (Loader, bool)
	BodyPtr() Ptr

	Close() error

	Blocks() map[string]Opcode
}

type Number

type Number interface {
	Int() int64
	Float() float64
	IsFloat() bool
}

func ToNumber

func ToNumber(v interface{}) (r Number, err error)

type Opcode

type Opcode interface {
	Load() error
	Exec(ctx Context) (Ptr, error)
}

Opcode 表示一个操作码

func NewOpcode

func NewOpcode(loader Loader, code byte, ptr Ptr, line LineNo, flag byte) (Opcode, error)

type Ptr

type Ptr uint16

Ptr 操作码地址

const ZeroPtr Ptr = 0

type Stack

type Stack []interface{}

func (*Stack) Len

func (stack *Stack) Len() int

func (*Stack) Pop

func (stack *Stack) Pop() (interface{}, bool)

func (*Stack) Push

func (stack *Stack) Push(v interface{}) interface{}

type TemplateFunc

type TemplateFunc func(...interface{}) (interface{}, error)

Jump to

Keyboard shortcuts

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