qxlang

package module
v0.0.0-...-3ee5a1a Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2024 License: MIT Imports: 9 Imported by: 0

README

qxlang

A simple, quick, cross-platform, embeddable, ASM/shell-like script language inspired by Xielang.

Documentation

Index

Constants

View Source
const OpNameListG = `` /* 224-byte string literal not displayed */

Variables

View Source
var DebugG = false
View Source
var InstrNameSet map[string]int = map[string]int{

	"invalidInstr": 12,

	"version": 100,

	"pass": 101,

	"testByText": 122,

	"goto": 180,

	"exit": 199,

	"push": 220,

	"peek": 222,

	"pop": 224,

	"=": 401,

	"if": 610,

	"<": 703,

	"call": 1010,

	"ret": 1020,

	"getArrayItem": 1123,
	"[]":           1123,

	"now": 1910,

	"pln": 10410,
	"plo": 10411,

	"pl": 10420,

	"sleep": 20501,

	"getClipText": 20511,

	"setClipText": 20512,

	"getEnv":    20521,
	"setEnv":    20522,
	"removeEnv": 20523,

	"systemCmd": 20601,

	"++i": 9999900011,
	"--i": 9999900015,

	"+i": 9999900101,

	"-t": 9999900701,
}

instructions start

View Source
var OpNameMapG map[int]string = nil
View Source
var VersionG string = "0.0.1"

Functions

func ParseLine

func ParseLine(commandA string) ([]string, error)

func RunCode

func RunCode(scriptA string, optsA ...string) interface{}

func RunInstr

func RunInstr(p *VM, instrA *Instr) (resultR interface{})

func Test

func Test()

Types

type ByteCode

type ByteCode struct {
	Source []string

	Labels map[string]int

	Consts []interface{}

	InstrList  []Instr
	OpCodeList []OpCode

	// for trace
	InstrToLineMap map[int]int
}

func Compile

func Compile(scriptA string) (*ByteCode, error)

func (*ByteCode) DealInputParams

func (p *ByteCode) DealInputParams(instrA *Instr, startA int) int

func (*ByteCode) DealOutputParams

func (p *ByteCode) DealOutputParams(instrA *Instr, startA int) error

func (*ByteCode) DeepCompile

func (p *ByteCode) DeepCompile() error

func (*ByteCode) ParseVar

func (p *ByteCode) ParseVar(strA string, optsA ...interface{}) VarRef

type CallStruct

type CallStruct struct {
	ReturnPointer int
	ReturnRef     VarRef
	Value         interface{}
}

type DeepCallStruct

type DeepCallStruct struct {
	ReturnPointer int
	ReturnRef     OpCode
	Value         interface{}
}

type FuncContext

type FuncContext struct {
	Vars []interface{}

	Tmp interface{}

	DeferStack *tk.SimpleStack
}

func NewFuncContext

func NewFuncContext() *FuncContext

func (*FuncContext) RunDefer

func (p *FuncContext) RunDefer(vmA *VM) error

type Instr

type Instr struct {
	SourceLine int
	Code       int
	ParamLen   int
	Params     []VarRef
}

type LoopStruct

type LoopStruct struct {
	Cond       interface{}
	LoopIndex  int
	BreakIndex int
	LoopInstr  *Instr
}

type OpCode

type OpCode struct {
	SourceLine int
	Code       OpCodeNum
	ParamLen   int
	Params     []int
}

type OpCodeNum

type OpCodeNum int
const (
	OpConst OpCodeNum = iota

	OpValue

	OpPush
	OpPop
	OpPeek

	OpAssignReg

	OpAssignLocal
	OpGetLocalVarValue

	OpGoto

	OpAddInt

	OpPln
	OpPl

	OpEqual

	OpExit

	OpCall
	OpRet

	OpNow
	OpTimeSub
)

func (OpCodeNum) String

func (v OpCodeNum) String() string

type RangeStruct

type RangeStruct struct {
	Iterator   tk.Iterator
	LoopIndex  int
	BreakIndex int
}

type VM

type VM struct {
	Code *ByteCode

	Regs  []interface{} // the first(index 0) is always global vars map, the second is input param, the third is the return/output value
	Stack *tk.SimpleStack
	Vars  []interface{}

	Seq *tk.Seq

	FuncStack *tk.SimpleStack

	CodePointer int

	InternalStack *tk.SimpleStack

	PointerStack *tk.SimpleStack

	ErrorHandler int
}

func NewVM

func NewVM(codeA *ByteCode, inputA ...interface{}) *VM

func (*VM) Errf

func (p *VM) Errf(formatA string, argsA ...interface{}) error

func (*VM) GetCurrentFuncContext

func (p *VM) GetCurrentFuncContext() *FuncContext

func (*VM) GetLabelIndex

func (p *VM) GetLabelIndex(inputA interface{}) int

func (*VM) GetVarValue

func (p *VM) GetVarValue(vA VarRef) interface{}

func (*VM) ParamsToInts

func (p *VM) ParamsToInts(v *Instr, fromA int) []int

func (*VM) ParamsToList

func (p *VM) ParamsToList(v *Instr, fromA int) []interface{}

func (*VM) ParamsToStrs

func (p *VM) ParamsToStrs(v *Instr, fromA int) []string

func (*VM) Run

func (p *VM) Run(posA ...int) interface{}

func (*VM) RunDeferUpToRoot

func (p *VM) RunDeferUpToRoot() error

func (*VM) RunOpCodes

func (p *VM) RunOpCodes() (resultR interface{})

func (*VM) SetVar

func (p *VM) SetVar(refA VarRef, setValueA interface{}) error

type VarRef

type VarRef struct {
	Ref   int // -99 - invalid, -56 - integer label, -31 - clipboard(text), -23 - slice of array/slice, -22 - map item, -21 - array/slice item, -18 - local reg, -17 - reg, -16 - label, -15 - ref, -12 - unref, -11 - seq, -10 - quickEval, -9 - flexEval, -8 - pop, -7 - peek, -6 - push, -5 - tmp, -4 - pln, -3 - value only, -2 - drop, -1 - debug, 3 normal vars
	Value interface{}
}

Jump to

Keyboard shortcuts

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