object

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Builtins = map[string]Object{

	"inf": &Float{Value: math.Inf(1)},

	"nan": &Float{Value: math.NaN()},

	"print": &BuiltinFunction{
		Name:      "print",
		Parameter: []string{"a"},
		DefaultValue: []Object{
			nil,
		},
		HaveVariadic: true,
		Fn: func(f *frame.Frame, posStart, posEnd *util.Pos, args ...Object) (Object, error) {
			for i, arg := range args {
				if i > 0 {
					fmt.Print(" ")
				}
				fmt.Print(arg.String())
			}

			_ = os.Stdout.Sync()
			return &Null{}, nil
		},
	},

	"println": &BuiltinFunction{
		Name:      "println",
		Parameter: []string{"a"},
		DefaultValue: []Object{
			nil,
		},
		HaveVariadic: true,
		Fn: func(f *frame.Frame, posStart, posEnd *util.Pos, args ...Object) (Object, error) {
			for i, arg := range args {
				if i > 0 {
					fmt.Print(" ")
				}
				fmt.Print(arg.String())
			}
			fmt.Println()

			_ = os.Stdout.Sync()
			return &Null{}, nil
		},
	},

	"len": &BuiltinFunction{
		Name:      "len",
		Parameter: []string{"a"},
		DefaultValue: []Object{
			nil,
		},
		HaveVariadic: false,
		Fn: func(f *frame.Frame, posStart, posEnd *util.Pos, args ...Object) (Object, error) {
			a := args[0]
			switch a := a.(type) {
			case *String:
				return &Int{Value: int64(utf8.RuneCountInString(a.Value))}, nil
			case *List:
				return &Int{Value: int64(len(a.Elements))}, nil
			default:
				return nil, &TypeError{
					Frame:    f,
					Message:  "len() argument must be a sequence or collection.",
					PosStart: posStart,
					PosEnd:   posEnd,
				}
			}
		},
	},

	"power": &BuiltinFunction{
		Name:      "power",
		Parameter: []string{"a", "n"},
		DefaultValue: []Object{
			nil,
		},
		HaveVariadic: false,
		Fn: func(f *frame.Frame, posStart, posEnd *util.Pos, args ...Object) (Object, error) {
			a := args[0]
			n := args[1]
			var base, exp float64
			switch a := a.(type) {
			case *Int:
				base = float64(a.Value)
			case *Float:
				base = a.Value
			default:
				return nil, &TypeError{
					Frame:    f,
					Message:  "power() arguments must be integers or floats.",
					PosStart: posStart,
					PosEnd:   posEnd,
				}
			}
			switch n := n.(type) {
			case *Int:
				exp = float64(n.Value)
			case *Float:
				exp = n.Value
			default:
				return nil, &TypeError{
					Frame:    f,
					Message:  "power() arguments must be integers or floats.",
					PosStart: posStart,
					PosEnd:   posEnd,
				}
			}
			return &Float{Value: math.Pow(base, exp)}, nil
		},
	},
}

Builtins 是内建函数和常量

Functions

This section is empty.

Types

type Bool

type Bool struct {
	Value bool // 布尔值的实际值
}

Bool 表示布尔值类型,实现了Object接口 支持逻辑运算

func (*Bool) Add

func (b *Bool) Add(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Add 对值进行加法运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Bool) And

func (b *Bool) And(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

And 执行逻辑与运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Bool) BitAnd

func (b *Bool) BitAnd(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

BitAnd 对值进行按位与运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Bool) BitNot

func (b *Bool) BitNot(posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

BitNot 对值进行按位非运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Bool) BitOr

func (b *Bool) BitOr(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

BitOr 对值进行按位或运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Bool) Divide

func (b *Bool) Divide(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Divide 对值进行除法运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Bool) Equal

func (b *Bool) Equal(other Object, _, _ *util.Pos, _ *frame.Frame) (Object, error)

Equal 对值进行等于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*Bool) GreaterThan

func (b *Bool) GreaterThan(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

GreaterThan 对值进行大于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*Bool) GreaterThanOrEqual

func (b *Bool) GreaterThanOrEqual(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

GreaterThanOrEqual 对值进行大于等于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*Bool) Index

func (b *Bool) Index(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Index 执行索引运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Bool) LeftShift

func (b *Bool) LeftShift(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

LeftShift 对值进行左移运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Bool) LessThan

func (b *Bool) LessThan(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

LessThan 对值进行小于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*Bool) LessThanOrEqual

func (b *Bool) LessThanOrEqual(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

LessThanOrEqual 对值进行小于等于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*Bool) Mod

func (b *Bool) Mod(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Mod 对值进行取模运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Bool) Multiply

func (b *Bool) Multiply(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Multiply 对值进行乘法运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Bool) Negative

func (b *Bool) Negative(posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Negative 对值进行负运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Bool) Not

func (b *Bool) Not(*util.Pos, *util.Pos, *frame.Frame) (Object, error)

Not 返回当前布尔值的否定

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

包含否定值的新Bool实例;无错误

func (*Bool) NotEqual

func (b *Bool) NotEqual(other Object, _, _ *util.Pos, _ *frame.Frame) (Object, error)

NotEqual 对值进行不等于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*Bool) Or

func (b *Bool) Or(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Or 执行逻辑或运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Bool) RightShift

func (b *Bool) RightShift(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

RightShift 对值进行右移运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Bool) String

func (b *Bool) String() string

String 返回值的字符串表示

返回值:

string - 格式化的字符串表示

func (*Bool) Subtract

func (b *Bool) Subtract(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Subtract 对值进行减法运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Bool) Type

func (b *Bool) Type() string

Type 返回值的类型

返回值:

string - 值的类型

func (*Bool) Xor

func (b *Bool) Xor(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Xor 对值进行异或运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

type BreakValue added in v0.2.0

type BreakValue struct{}

BreakValue 表示break语句的返回值

func (*BreakValue) Add added in v0.2.0

func (bv *BreakValue) Add(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Add 对值进行加法运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*BreakValue) And added in v0.2.0

func (bv *BreakValue) And(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

And 对值进行逻辑与运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*BreakValue) BitAnd added in v0.2.0

func (bv *BreakValue) BitAnd(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

BitAnd 对值进行按位与运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*BreakValue) BitNot added in v0.2.0

func (bv *BreakValue) BitNot(posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

BitNot 对值进行按位非运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*BreakValue) BitOr added in v0.2.0

func (bv *BreakValue) BitOr(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

BitOr 对值进行按位或运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*BreakValue) Divide added in v0.2.0

func (bv *BreakValue) Divide(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Divide 对值进行除法运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*BreakValue) Equal added in v0.2.0

func (bv *BreakValue) Equal(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Equal 判断当前空值与另一个值是否相等

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*BreakValue) GreaterThan added in v0.2.0

func (bv *BreakValue) GreaterThan(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

GreaterThan 对值进行大于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*BreakValue) GreaterThanOrEqual added in v0.2.0

func (bv *BreakValue) GreaterThanOrEqual(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

GreaterThanOrEqual 对值进行大于等于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*BreakValue) Index added in v0.2.0

func (bv *BreakValue) Index(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Index 执行索引运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*BreakValue) LeftShift added in v0.2.0

func (bv *BreakValue) LeftShift(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

LeftShift 对值进行左移运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*BreakValue) LessThan added in v0.2.0

func (bv *BreakValue) LessThan(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

LessThan 对值进行小于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*BreakValue) LessThanOrEqual added in v0.2.0

func (bv *BreakValue) LessThanOrEqual(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

LessThanOrEqual 对值进行小于等于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*BreakValue) Mod added in v0.2.0

func (bv *BreakValue) Mod(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Mod 对值进行取模运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*BreakValue) Multiply added in v0.2.0

func (bv *BreakValue) Multiply(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Multiply 对值进行乘法运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*BreakValue) Negative added in v0.2.0

func (bv *BreakValue) Negative(posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Negative 对值进行负运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*BreakValue) Not added in v0.2.0

func (bv *BreakValue) Not(posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Not 对值进行逻辑非运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*BreakValue) NotEqual added in v0.2.0

func (bv *BreakValue) NotEqual(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

NotEqual 判断当前空值与另一个值是否不相等

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*BreakValue) Or added in v0.2.0

func (bv *BreakValue) Or(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Or 对值进行逻辑或运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*BreakValue) RightShift added in v0.2.0

func (bv *BreakValue) RightShift(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

RightShift 对值进行右移运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*BreakValue) String added in v0.2.0

func (bv *BreakValue) String() string

String 返回值的字符串表示

返回值:

string - 格式化的字符串表示

func (*BreakValue) Subtract added in v0.2.0

func (bv *BreakValue) Subtract(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Subtract 对值进行减法运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*BreakValue) Type added in v0.2.0

func (bv *BreakValue) Type() string

Type 返回值的类型

返回值:

string - 值的类型

func (*BreakValue) Xor added in v0.2.0

func (bv *BreakValue) Xor(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Xor 对值进行异或运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

type BuiltinFunction

type BuiltinFunction struct {
	Name         string                                                                           // 函数名
	Parameter    []string                                                                         // 参数名
	DefaultValue []Object                                                                         // 默认参数值
	HaveVariadic bool                                                                             // 是否为可变参数
	Fn           func(f *frame.Frame, posStart, posEnd *util.Pos, args ...Object) (Object, error) // 函数体
}

BuiltinFunction 表示内建函数类型,实现了Object接口 支持的操作包括调用函数等

func (*BuiltinFunction) Add

func (bf *BuiltinFunction) Add(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Add 对值进行加法运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*BuiltinFunction) And

func (bf *BuiltinFunction) And(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

And 对值进行逻辑与运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*BuiltinFunction) BitAnd

func (bf *BuiltinFunction) BitAnd(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

BitAnd 对值进行按位与运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*BuiltinFunction) BitNot

func (bf *BuiltinFunction) BitNot(posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

BitNot 对值进行按位非运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*BuiltinFunction) BitOr

func (bf *BuiltinFunction) BitOr(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

BitOr 对值进行按位或运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*BuiltinFunction) Divide

func (bf *BuiltinFunction) Divide(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Divide 对值进行除法运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*BuiltinFunction) Equal

func (bf *BuiltinFunction) Equal(other Object, _, _ *util.Pos, _ *frame.Frame) (Object, error)

Equal 判断当前函数与另一个值是否相等

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

布尔值,表示比较结果;无错误

比较规则:

引用性比较

func (*BuiltinFunction) GreaterThan

func (bf *BuiltinFunction) GreaterThan(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

GreaterThan 对值进行大于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*BuiltinFunction) GreaterThanOrEqual

func (bf *BuiltinFunction) GreaterThanOrEqual(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

GreaterThanOrEqual 对值进行大于等于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*BuiltinFunction) Index

func (bf *BuiltinFunction) Index(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Index 执行索引运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*BuiltinFunction) LeftShift

func (bf *BuiltinFunction) LeftShift(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

LeftShift 对值进行左移运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*BuiltinFunction) LessThan

func (bf *BuiltinFunction) LessThan(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

LessThan 对值进行小于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*BuiltinFunction) LessThanOrEqual

func (bf *BuiltinFunction) LessThanOrEqual(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

LessThanOrEqual 对值进行小于等于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*BuiltinFunction) Mod

func (bf *BuiltinFunction) Mod(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Mod 对值进行取模运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*BuiltinFunction) Multiply

func (bf *BuiltinFunction) Multiply(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Multiply 对值进行乘法运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*BuiltinFunction) Negative

func (bf *BuiltinFunction) Negative(posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Negative 对值进行负运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*BuiltinFunction) Not

func (bf *BuiltinFunction) Not(posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Not 对值进行逻辑非运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*BuiltinFunction) NotEqual

func (bf *BuiltinFunction) NotEqual(other Object, _, _ *util.Pos, _ *frame.Frame) (Object, error)

NotEqual 判断当前函数与另一个值是否不相等

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

布尔值,表示比较结果;无错误

比较规则:

引用性比较

func (*BuiltinFunction) Or

func (bf *BuiltinFunction) Or(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Or 对值进行逻辑或运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*BuiltinFunction) RightShift

func (bf *BuiltinFunction) RightShift(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

RightShift 对值进行右移运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*BuiltinFunction) String

func (bf *BuiltinFunction) String() string

String 返回值的字符串表示

返回值:

string - 格式化的字符串表示

func (*BuiltinFunction) Subtract

func (bf *BuiltinFunction) Subtract(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Subtract 对值进行减法运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*BuiltinFunction) Type

func (bf *BuiltinFunction) Type() string

Type 返回值的类型

返回值:

string - 值的类型

func (*BuiltinFunction) Xor

func (bf *BuiltinFunction) Xor(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Xor 对值进行异或运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

type ContinueValue added in v0.2.0

type ContinueValue struct{}

ContinueValue 表示continue语句的返回值

func (*ContinueValue) Add added in v0.2.0

func (cv *ContinueValue) Add(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Add 对值进行加法运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*ContinueValue) And added in v0.2.0

func (cv *ContinueValue) And(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

And 对值进行逻辑与运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*ContinueValue) BitAnd added in v0.2.0

func (cv *ContinueValue) BitAnd(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

BitAnd 对值进行按位与运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*ContinueValue) BitNot added in v0.2.0

func (cv *ContinueValue) BitNot(posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

BitNot 对值进行按位非运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*ContinueValue) BitOr added in v0.2.0

func (cv *ContinueValue) BitOr(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

BitOr 对值进行按位或运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*ContinueValue) Divide added in v0.2.0

func (cv *ContinueValue) Divide(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Divide 对值进行除法运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*ContinueValue) Equal added in v0.2.0

func (cv *ContinueValue) Equal(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Equal 判断当前空值与另一个值是否相等

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*ContinueValue) GreaterThan added in v0.2.0

func (cv *ContinueValue) GreaterThan(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

GreaterThan 对值进行大于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*ContinueValue) GreaterThanOrEqual added in v0.2.0

func (cv *ContinueValue) GreaterThanOrEqual(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

GreaterThanOrEqual 对值进行大于等于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*ContinueValue) Index added in v0.2.0

func (cv *ContinueValue) Index(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Index 执行索引运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*ContinueValue) LeftShift added in v0.2.0

func (cv *ContinueValue) LeftShift(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

LeftShift 对值进行左移运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*ContinueValue) LessThan added in v0.2.0

func (cv *ContinueValue) LessThan(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

LessThan 对值进行小于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*ContinueValue) LessThanOrEqual added in v0.2.0

func (cv *ContinueValue) LessThanOrEqual(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

LessThanOrEqual 对值进行小于等于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*ContinueValue) Mod added in v0.2.0

func (cv *ContinueValue) Mod(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Mod 对值进行取模运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*ContinueValue) Multiply added in v0.2.0

func (cv *ContinueValue) Multiply(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Multiply 对值进行乘法运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*ContinueValue) Negative added in v0.2.0

func (cv *ContinueValue) Negative(posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Negative 对值进行负运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*ContinueValue) Not added in v0.2.0

func (cv *ContinueValue) Not(posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Not 对值进行逻辑非运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*ContinueValue) NotEqual added in v0.2.0

func (cv *ContinueValue) NotEqual(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

NotEqual 判断当前空值与另一个值是否不相等

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*ContinueValue) Or added in v0.2.0

func (cv *ContinueValue) Or(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Or 对值进行逻辑或运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*ContinueValue) RightShift added in v0.2.0

func (cv *ContinueValue) RightShift(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

RightShift 对值进行右移运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*ContinueValue) String added in v0.2.0

func (cv *ContinueValue) String() string

String 返回值的字符串表示

返回值:

string - 格式化的字符串表示

func (*ContinueValue) Subtract added in v0.2.0

func (cv *ContinueValue) Subtract(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Subtract 对值进行减法运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*ContinueValue) Type added in v0.2.0

func (cv *ContinueValue) Type() string

Type 返回值的类型

返回值:

string - 值的类型

func (*ContinueValue) Xor added in v0.2.0

func (cv *ContinueValue) Xor(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Xor 对值进行异或运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

type Environment

type Environment struct {
	Name  string             // 环境名称
	Store map[string]*Symbol // 变量名到值的映射
	Outer *Environment       // 外部环境
}

Environment 表示程序运行时的上下文环境,用于管理符号表和上下文嵌套关系 在函数调用、作用域切换等场景中使用,实现变量的作用域隔离和查找

func (*Environment) Assign

func (e *Environment) Assign(name string, sym *Symbol)

Assign 设置符号的值到当前环境 沿作用域链查找并设置符号的值 若当前作用域未定义该符号,则递归查找父作用域,直到找到或到达全局作用域

参数:

name - 要设置的符号名称
sym - 符号

func (*Environment) Exists

func (e *Environment) Exists(name string) bool

Exists 检查符号是否存在于当前环境(不包含父环境) 仅判断当前作用域中是否已定义该符号,不进行作用域链查找

参数:

name - 要检查的符号名称

返回值:

bool - 存在性结果,true表示存在,false表示不存在

func (*Environment) Get

func (e *Environment) Get(name string) (*Symbol, bool)

Get 查找符号的值,支持作用域链向上查找 先在当前环境中查找,若不存在且存在父环境,则递归查找父环境

参数:

name - 要查找的符号名称

返回值:

Symbol - 符号,若未找到则为nil
bool - 查找结果,true表示找到,false表示未找到

func (*Environment) Set

func (e *Environment) Set(name string, sym *Symbol)

Set 设置符号的值到当前环境 仅在当前作用域中添加或修改变量,不影响父环境

参数:

name - 要设置的符号名称
sym - 符号

type Float

type Float struct {
	Value float64
}

Float 表示浮点数值类型,实现了Number和Object接口 支持的操作包括算术运算、比较运算等

func (*Float) Add

func (f *Float) Add(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Add 对值进行加法运算

参数:

other - 右操作数,可以是Int或Float类型
posStart - 节点起始位置
posEnd - 节点结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Float) And

func (f *Float) And(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

And 对值进行逻辑与运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Float) BitAnd

func (f *Float) BitAnd(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

BitAnd 对值进行按位与运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Float) BitNot

func (f *Float) BitNot(posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

BitNot 对值进行按位非运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Float) BitOr

func (f *Float) BitOr(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

BitOr 对值进行按位或运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Float) Divide

func (f *Float) Divide(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Divide 对值进行除法运算

参数:

other - 右操作数,可以是Int或Float类型
posStart - 节点起始位置
posEnd - 节点结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Float) Equal

func (f *Float) Equal(other Object, _, _ *util.Pos, _ *frame.Frame) (Object, error)

Equal 判断当前值与另一个值是否相等

参数:

other - 右操作数,可以是Int或Float类型
posStart - 节点起始位置
posEnd - 节点结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Float) GreaterThan

func (f *Float) GreaterThan(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

GreaterThan 对值进行大于比较

参数:

other - 右操作数,可以是Int或Float类型
posStart - 节点起始位置
posEnd - 节点结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Float) GreaterThanOrEqual

func (f *Float) GreaterThanOrEqual(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

GreaterThanOrEqual 对值进行大于等于比较

参数:

other - 右操作数,可以是Int或Float类型
posStart - 节点起始位置
posEnd - 节点结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Float) Index

func (f *Float) Index(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Index 执行索引运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Float) LeftShift

func (f *Float) LeftShift(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

LeftShift 对值进行左移运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Float) LessThan

func (f *Float) LessThan(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

LessThan 对值进行小于比较

参数:

other - 右操作数,可以是Int或Float类型
posStart - 节点起始位置
posEnd - 节点结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Float) LessThanOrEqual

func (f *Float) LessThanOrEqual(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

LessThanOrEqual 对值进行小于等于比较

参数:

other - 右操作数,可以是Int或Float类型
posStart - 节点起始位置
posEnd - 节点结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Float) Mod

func (f *Float) Mod(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Mod 对值进行取模运算

参数:

other - 右操作数,可以是Int或Float类型
posStart - 节点起始位置
posEnd - 节点结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Float) Multiply

func (f *Float) Multiply(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Multiply 对值进行乘法运算

参数:

other - 右操作数,可以是Int或Float类型
posStart - 节点起始位置
posEnd - 节点结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Float) Negative

func (f *Float) Negative(*util.Pos, *util.Pos, *frame.Frame) (Object, error)

Negative 对值进行负运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Float) Not

func (f *Float) Not(posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Not 对值进行逻辑非运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Float) NotEqual

func (f *Float) NotEqual(other Object, _, _ *util.Pos, _ *frame.Frame) (Object, error)

NotEqual 判断当前值与另一个值是否不相等

参数:

other - 右操作数,可以是Int或Float类型
posStart - 节点起始位置
posEnd - 节点结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Float) Or

func (f *Float) Or(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Or 对值进行逻辑或运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Float) RightShift

func (f *Float) RightShift(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

RightShift 对值进行右移运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Float) String

func (f *Float) String() string

String 返回值的字符串表示

返回值:

string - 格式化的字符串表示

func (*Float) Subtract

func (f *Float) Subtract(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Subtract 对值进行减法运算

参数:

other - 右操作数,可以是Int或Float类型
posStart - 节点起始位置
posEnd - 节点结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Float) Type

func (f *Float) Type() string

Type 返回值的类型

返回值:

string - 值的类型

func (*Float) Xor

func (f *Float) Xor(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Xor 对值进行异或运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

type Function

type Function struct {
	Name      string           // 函数名
	Parameter []*ast.Parameter // 参数
	Body      ast.Statement    // 函数体
	Env       *Environment     // 环境
}

Function 表示函数类型,实现了Object接口 支持的操作包括调用函数等

func (*Function) Add

func (f *Function) Add(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Add 对值进行加法运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Function) And

func (f *Function) And(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

And 对值进行逻辑与运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Function) BitAnd

func (f *Function) BitAnd(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

BitAnd 对值进行按位与运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Function) BitNot

func (f *Function) BitNot(posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

BitNot 对值进行按位非运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Function) BitOr

func (f *Function) BitOr(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

BitOr 对值进行按位或运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Function) Divide

func (f *Function) Divide(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Divide 对值进行除法运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Function) Equal

func (f *Function) Equal(other Object, _, _ *util.Pos, _ *frame.Frame) (Object, error)

Equal 判断当前函数与另一个值是否相等

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

布尔值,表示比较结果;无错误

比较规则:

引用性比较

func (*Function) GreaterThan

func (f *Function) GreaterThan(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

GreaterThan 对值进行大于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*Function) GreaterThanOrEqual

func (f *Function) GreaterThanOrEqual(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

GreaterThanOrEqual 对值进行大于等于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*Function) Index

func (f *Function) Index(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Index 执行索引运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Function) LeftShift

func (f *Function) LeftShift(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

LeftShift 对值进行左移运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Function) LessThan

func (f *Function) LessThan(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

LessThan 对值进行小于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*Function) LessThanOrEqual

func (f *Function) LessThanOrEqual(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

LessThanOrEqual 对值进行小于等于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*Function) Mod

func (f *Function) Mod(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Mod 对值进行取模运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Function) Multiply

func (f *Function) Multiply(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Multiply 对值进行乘法运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Function) Negative

func (f *Function) Negative(posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Negative 对值进行负运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Function) Not

func (f *Function) Not(posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Not 对值进行逻辑非运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Function) NotEqual

func (f *Function) NotEqual(other Object, _, _ *util.Pos, _ *frame.Frame) (Object, error)

NotEqual 判断当前函数与另一个值是否不相等

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

布尔值,表示比较结果;无错误

比较规则:

引用性比较

func (*Function) Or

func (f *Function) Or(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Or 对值进行逻辑或运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Function) RightShift

func (f *Function) RightShift(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

RightShift 对值进行右移运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Function) String

func (f *Function) String() string

String 返回值的字符串表示

返回值:

string - 格式化的字符串表示

func (*Function) Subtract

func (f *Function) Subtract(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Subtract 对值进行减法运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Function) Type

func (f *Function) Type() string

Type 返回值的类型

返回值:

string - 值的类型

func (*Function) Xor

func (f *Function) Xor(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Xor 对值进行异或运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

type IndexError

type IndexError struct {
	Frame    *frame.Frame // 错误发生时的调用栈
	Message  string       // 错误描述文本
	PosStart *util.Pos    // 错误起始位置
	PosEnd   *util.Pos    // 错误结束位置
}

IndexError 索引错误类型,表示索引越界等相关的运行时错误 拥有完整的错误跟踪和格式化能力

func (*IndexError) Error

func (e *IndexError) Error() string

Error 生成格式化的索引错误信息字符串 前缀为"Index Error"

type Int

type Int struct {
	Value int64 // 整数实际值
}

Int 整数类型结构体,表示运行时的整数数值 实现Number接口和Object接口,支持各种整数运算

func (*Int) Add

func (i *Int) Add(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Add 对值进行加法运算

参数:

other - 右操作数,可以是Int或Float类型
posStart - 节点起始位置
posEnd - 节点结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Int) And

func (i *Int) And(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

And 对值进行逻辑与运算

参数:

other - 右侧表达式
posStart - 节点起始位置
posEnd - 节点结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Int) BitAnd

func (i *Int) BitAnd(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

BitAnd 对值进行按位与运算

参数:

other - 右侧整数值
posStart - 节点起始位置
posEnd - 节点结束位置
frame - 当前调用栈

返回值:

新的整数值,表示按位与的结果;若操作失败则返回运行时错误
error - 可能出现的错误

注意事项:

仅支持与*Int类型进行按位与操作,其他类型将返回错误

func (*Int) BitNot

func (i *Int) BitNot(*util.Pos, *util.Pos, *frame.Frame) (Object, error)

BitNot 对值进行按位非运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Int) BitOr

func (i *Int) BitOr(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

BitOr 对值进行按位或运算

参数:

other - 右侧整数值
posStart - 节点起始位置
posEnd - 节点结束位置
frame - 当前调用栈

返回值:

新的整数值,表示按位或的结果;若操作失败则返回运行时错误
error - 可能出现的错误

注意事项:

仅支持与*Int类型进行按位或操作,其他类型将返回错误

func (*Int) Divide

func (i *Int) Divide(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Divide 对值进行除法运算

参数:

other - 右操作数,可以是Int或Float类型
posStart - 节点起始位置
posEnd - 节点结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Int) Equal

func (i *Int) Equal(other Object, _, _ *util.Pos, _ *frame.Frame) (Object, error)

Equal 判断当前值与另一个值是否相等

参数:

other - 要比较的右侧值
posStart - 节点起始位置
posEnd - 节点结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Int) GreaterThan

func (i *Int) GreaterThan(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

GreaterThan 对值进行大于比较

参数:

other - 要比较的右侧值
posStart - 节点起始位置
posEnd - 节点结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Int) GreaterThanOrEqual

func (i *Int) GreaterThanOrEqual(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

GreaterThanOrEqual 对值进行大于等于比较

参数:

other - 要比较的右侧值
posStart - 节点起始位置
posEnd - 节点结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Int) Index

func (i *Int) Index(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Index 执行索引运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Int) LeftShift

func (i *Int) LeftShift(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

LeftShift 对值进行异或运算

参数:

other - 左移的位数
posStart - 节点起始位置
posEnd - 节点结束位置
frame - 当前调用栈

返回值:

新的整数值,表示左移后的结果;若操作失败则返回运行时错误
error - 可能出现的错误

注意事项:

  1. 仅支持与*Int类型进行左移操作,其他类型将返回错误
  2. 右操作数不能为负数,否则返回错误

error - 可能出现的错误

func (*Int) LessThan

func (i *Int) LessThan(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

LessThan 对值进行小于比较

参数:

other - 要比较的右侧值
posStart - 节点起始位置
posEnd - 节点结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Int) LessThanOrEqual

func (i *Int) LessThanOrEqual(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

LessThanOrEqual 对值进行小于等于比较

参数:

other - 要比较的右侧值
posStart - 节点起始位置
posEnd - 节点结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Int) Mod

func (i *Int) Mod(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Mod 对值进行取模运算

参数:

other - 要取模的右侧值
posStart - 节点起始位置
posEnd - 节点结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Int) Multiply

func (i *Int) Multiply(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Multiply 对值进行乘法运算

参数:

other - 右操作数,可以是Int、Float或String类型
posStart - 节点起始位置
posEnd - 节点结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Int) Negative

func (i *Int) Negative(*util.Pos, *util.Pos, *frame.Frame) (Object, error)

Negative 对值进行负运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Int) Not

func (i *Int) Not(posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Not 对值进行逻辑非运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Int) NotEqual

func (i *Int) NotEqual(other Object, _, _ *util.Pos, _ *frame.Frame) (Object, error)

NotEqual 判断当前值与另一个值是否不相等

参数:

other - 要比较的右侧值
posStart - 节点起始位置
posEnd - 节点结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Int) Or

func (i *Int) Or(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Or 对值进行逻辑或运算

参数:

other - 右侧表达式
posStart - 节点起始位置
posEnd - 节点结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Int) RightShift

func (i *Int) RightShift(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

RightShift 对值进行右移运算

参数:

other - 右移的位数
posStart - 节点起始位置
posEnd - 节点结束位置
frame - 当前调用栈

返回值:

新的整数值,表示右移后的结果;若操作失败则返回运行时错误
error - 可能出现的错误

注意事项:

  1. 仅支持与*Int类型进行右移操作,其他类型将返回错误
  2. 右操作数不能为负数,否则返回错误

func (*Int) String

func (i *Int) String() string

String 返回值的字符串表示

返回值:

string - 格式化的字符串表示

func (*Int) Subtract

func (i *Int) Subtract(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Subtract 对值进行减法运算

参数:

other - 右操作数,可以是Int或Float类型
posStart - 节点起始位置
posEnd - 节点结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Int) Type

func (i *Int) Type() string

Type 返回值的类型

返回值:

string - 值的类型

func (*Int) Xor

func (i *Int) Xor(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Xor 对值进行异或运算

参数:

other - 右侧整数值
posStart - 节点起始位置
posEnd - 节点结束位置
frame - 当前调用栈

返回值:

新的整数值,表示按位异或的结果;若操作失败则返回运行时错误
error - 可能出现的错误

注意事项:

仅支持与*Int类型进行按位异或操作,其他类型将返回错误

type List

type List struct {
	Elements []Object // 列表元素
}

List 列表类型结构体,表示运行时的列表 实现Object接口

func (*List) Add

func (l *List) Add(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Add 对值进行加法运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*List) And

func (l *List) And(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

And 对值进行逻辑与运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*List) BitAnd

func (l *List) BitAnd(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

BitAnd 对值进行按位与运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*List) BitNot

func (l *List) BitNot(posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

BitNot 对值进行按位非运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*List) BitOr

func (l *List) BitOr(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

BitOr 对值进行按位或运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*List) Divide

func (l *List) Divide(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Divide 对值进行除法运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*List) Equal

func (l *List) Equal(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Equal 判断当前值与另一个值是否相等

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

布尔值,表示比较结果;无错误

比较规则:

  • 与*Null类型比较:返回true
  • 与其他类型比较:返回false

func (*List) GreaterThan

func (l *List) GreaterThan(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

GreaterThan 对值进行大于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*List) GreaterThanOrEqual

func (l *List) GreaterThanOrEqual(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

GreaterThanOrEqual 对值进行大于等于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*List) Index

func (l *List) Index(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Index 执行索引运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*List) LeftShift

func (l *List) LeftShift(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

LeftShift 对值进行左移运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*List) Length added in v0.3.0

func (l *List) Length() int64

Length 返回列表的长度

返回值:

int64 - 列表的长度

func (*List) LessThan

func (l *List) LessThan(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

LessThan 对值进行小于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*List) LessThanOrEqual

func (l *List) LessThanOrEqual(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

LessThanOrEqual 对值进行小于等于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*List) Mod

func (l *List) Mod(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Mod 对值进行取模运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*List) Multiply

func (l *List) Multiply(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Multiply 对值进行乘法运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果(重复后的新列表)
error - 可能出现的错误

func (*List) Negative

func (l *List) Negative(posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Negative 对值进行负运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*List) Not

func (l *List) Not(posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Not 对值进行逻辑非运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*List) NotEqual

func (l *List) NotEqual(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

NotEqual 判断当前值与另一个值是否不相等

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

布尔值,表示比较结果;无错误

比较规则:

  • 与*Null类型比较:返回false
  • 与其他类型比较:返回true

func (*List) Or

func (l *List) Or(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Or 对值进行逻辑或运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*List) RightShift

func (l *List) RightShift(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

RightShift 对值进行右移运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*List) Set

func (l *List) Set(index Object, value Object, posStart, posEnd *util.Pos, frame *frame.Frame) error

Set 设置索引位置的值

参数:

index - 索引值
value - 要设置的值
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

error - 可能出现的错误

func (*List) String

func (l *List) String() string

String 返回值的字符串表示

返回值:

string - 格式化的字符串表示

func (*List) Subtract

func (l *List) Subtract(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Subtract 对值进行减法运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*List) Type

func (l *List) Type() string

Type 返回值的类型

返回值:

string - 值的类型

func (*List) Xor

func (l *List) Xor(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Xor 对值进行异或运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

type MathError

type MathError struct {
	Frame    *frame.Frame // 错误发生时的调用栈
	Message  string       // 错误描述文本
	PosStart *util.Pos    // 错误起始位置
	PosEnd   *util.Pos    // 错误结束位置
}

MathError 数学错误类型,表示数学运算相关的错误 例如除以零、数值溢出、无效的数学函数参数等 拥有完整的错误跟踪和格式化能力

func (*MathError) Error

func (e *MathError) Error() string

Error 生成格式化的数学错误信息字符串 前缀为"Math Error"

返回值:

string - 格式化的数学错误信息,格式同基础Error但错误类型为"Math Error"

type Namespace added in v0.3.0

type Namespace struct {
	Name   string
	Member *Environment
}

Namespace 表示命名空间类型,实现了Object接口 用于表示命名空间

func (*Namespace) Add added in v0.3.0

func (n *Namespace) Add(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Add 对值进行加法运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Namespace) And added in v0.3.0

func (n *Namespace) And(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

And 对值进行逻辑与运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Namespace) BitAnd added in v0.3.0

func (n *Namespace) BitAnd(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

BitAnd 对值进行按位与运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Namespace) BitNot added in v0.3.0

func (n *Namespace) BitNot(posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

BitNot 对值进行按位非运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Namespace) BitOr added in v0.3.0

func (n *Namespace) BitOr(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

BitOr 对值进行按位或运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Namespace) Divide added in v0.3.0

func (n *Namespace) Divide(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Divide 对值进行除法运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Namespace) Equal added in v0.3.0

func (n *Namespace) Equal(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Equal 判断当前值与另一个值是否相等

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Namespace) GreaterThan added in v0.3.0

func (n *Namespace) GreaterThan(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

GreaterThan 对值进行大于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*Namespace) GreaterThanOrEqual added in v0.3.0

func (n *Namespace) GreaterThanOrEqual(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

GreaterThanOrEqual 对值进行大于等于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*Namespace) Index added in v0.3.0

func (n *Namespace) Index(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Index 执行索引运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Namespace) LeftShift added in v0.3.0

func (n *Namespace) LeftShift(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

LeftShift 对值进行左移运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Namespace) LessThan added in v0.3.0

func (n *Namespace) LessThan(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

LessThan 对值进行小于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*Namespace) LessThanOrEqual added in v0.3.0

func (n *Namespace) LessThanOrEqual(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

LessThanOrEqual 对值进行小于等于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*Namespace) Mod added in v0.3.0

func (n *Namespace) Mod(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Mod 对值进行取模运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Namespace) Multiply added in v0.3.0

func (n *Namespace) Multiply(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Multiply 对值进行乘法运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Namespace) Negative added in v0.3.0

func (n *Namespace) Negative(posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Negative 对值进行负运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Namespace) Not added in v0.3.0

func (n *Namespace) Not(posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Not 对值进行逻辑非运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Namespace) NotEqual added in v0.3.0

func (n *Namespace) NotEqual(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

NotEqual 判断当前值与另一个值是否不相等

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Namespace) Or added in v0.3.0

func (n *Namespace) Or(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Or 对值进行逻辑或运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Namespace) RightShift added in v0.3.0

func (n *Namespace) RightShift(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

RightShift 对值进行右移运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Namespace) String added in v0.3.0

func (n *Namespace) String() string

String 返回值的字符串表示

返回值:

string - 格式化的字符串表示

func (*Namespace) Subtract added in v0.3.0

func (n *Namespace) Subtract(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Subtract 对值进行减法运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Namespace) Type added in v0.3.0

func (n *Namespace) Type() string

Type 返回值的类型

返回值:

string - 值的类型

func (*Namespace) Xor added in v0.3.0

func (n *Namespace) Xor(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Xor 对值进行异或运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

type Null

type Null struct{}

Null 表示空值类型,实现了Object接口 用于表示不存在的值或空值

func (*Null) Add

func (n *Null) Add(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Add 对值进行加法运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Null) And

func (n *Null) And(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

And 对值进行逻辑与运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Null) BitAnd

func (n *Null) BitAnd(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

BitAnd 对值进行按位与运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Null) BitNot

func (n *Null) BitNot(posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

BitNot 对值进行按位非运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Null) BitOr

func (n *Null) BitOr(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

BitOr 对值进行按位或运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Null) Divide

func (n *Null) Divide(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Divide 对值进行除法运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Null) Equal

func (n *Null) Equal(other Object, _, _ *util.Pos, _ *frame.Frame) (Object, error)

Equal 判断当前值与另一个值是否相等

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

布尔值,表示比较结果;无错误

比较规则:

  • 与*Null类型比较:返回true
  • 与其他类型比较:返回false

func (*Null) GreaterThan

func (n *Null) GreaterThan(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

GreaterThan 对值进行大于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*Null) GreaterThanOrEqual

func (n *Null) GreaterThanOrEqual(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

GreaterThanOrEqual 对值进行大于等于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*Null) Index

func (n *Null) Index(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Index 执行索引运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Null) LeftShift

func (n *Null) LeftShift(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

LeftShift 对值进行左移运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Null) LessThan

func (n *Null) LessThan(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

LessThan 对值进行小于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*Null) LessThanOrEqual

func (n *Null) LessThanOrEqual(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

LessThanOrEqual 对值进行小于等于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*Null) Mod

func (n *Null) Mod(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Mod 对值进行取模运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Null) Multiply

func (n *Null) Multiply(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Multiply 对值进行乘法运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Null) Negative

func (n *Null) Negative(posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Negative 对值进行负运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Null) Not

func (n *Null) Not(posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Not 对值进行逻辑非运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Null) NotEqual

func (n *Null) NotEqual(other Object, _, _ *util.Pos, _ *frame.Frame) (Object, error)

NotEqual 判断当前值与另一个值是否不相等

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

布尔值,表示比较结果;无错误

比较规则:

  • 与*Null类型比较:返回false
  • 与其他类型比较:返回true

func (*Null) Or

func (n *Null) Or(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Or 对值进行逻辑或运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Null) RightShift

func (n *Null) RightShift(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

RightShift 对值进行右移运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Null) String

func (n *Null) String() string

String 返回值的字符串表示

返回值:

string - 格式化的字符串表示

func (*Null) Subtract

func (n *Null) Subtract(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Subtract 对值进行减法运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*Null) Type

func (n *Null) Type() string

Type 返回值的类型

返回值:

string - 值的类型

func (*Null) Xor

func (n *Null) Xor(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Xor 对值进行异或运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

type Number

type Number interface {
	Object
}

Number 数值类型接口,定义所有数值类型共有的操作 实现此接口的类型包括Int和Float 接口方法包括算术运算、位运算等数值操作

type Object

type Object interface {
	// Type 返回值的类型
	//
	// 返回值:
	//
	//  string - 值的类型
	Type() string

	// String 返回值的字符串表示
	//
	// 返回值:
	//
	//  string - 格式化的字符串表示
	String() string

	// Negative 对值进行负运算
	//
	// 参数:
	//
	//  posStart - 表达式起始位置
	//  posEnd - 表达式结束位置
	//  frame - 当前调用栈
	//
	// 返回值:
	//
	//  Object - 运算结果
	//  error - 可能出现的错误
	Negative(posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

	// BitNot 对值进行按位非运算
	//
	// 参数:
	//
	//  posStart - 表达式起始位置
	//  posEnd - 表达式结束位置
	//  frame - 当前调用栈
	//
	// 返回值:
	//
	//  Object - 运算结果
	//  error - 可能出现的错误
	BitNot(posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

	// Not 对值进行逻辑非运算
	//
	// 参数:
	//
	//  posStart - 表达式起始位置
	//  posEnd - 表达式结束位置
	//  frame - 当前调用栈
	//
	// 返回值:
	//
	//  Object - 运算结果
	//  error - 可能出现的错误
	Not(posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

	// Add 对值进行加法运算
	//
	// 参数:
	//
	//  other - 另一个操作数
	//  posStart - 表达式起始位置
	//  posEnd - 表达式结束位置
	//  frame - 当前调用栈
	//
	// 返回值:
	//
	//  Object - 运算结果
	//  error - 可能出现的错误
	Add(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

	// Subtract 对值进行减法运算
	//
	// 参数:
	//
	//  other - 另一个操作数
	//  posStart - 表达式起始位置
	//  posEnd - 表达式结束位置
	//  frame - 当前调用栈
	//
	// 返回值:
	//
	//  Object - 运算结果
	//  error - 可能出现的错误
	Subtract(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

	// Multiply 对值进行乘法运算
	//
	// 参数:
	//
	//  other - 另一个操作数
	//  posStart - 表达式起始位置
	//  posEnd - 表达式结束位置
	//  frame - 当前调用栈
	//
	// 返回值:
	//
	//  Object - 运算结果
	//  error - 可能出现的错误
	Multiply(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

	// Divide 对值进行除法运算
	//
	// 参数:
	//
	//  other - 另一个操作数
	//  posStart - 表达式起始位置
	//  posEnd - 表达式结束位置
	//  frame - 当前调用栈
	//
	// 返回值:
	//
	//  Object - 运算结果
	//  error - 可能出现的错误
	Divide(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

	// Mod 对值进行取模运算
	//
	// 参数:
	//
	//  other - 另一个操作数
	//  posStart - 表达式起始位置
	//  posEnd - 表达式结束位置
	//  frame - 当前调用栈
	//
	// 返回值:
	//
	//  Object - 运算结果
	//  error - 可能出现的错误
	Mod(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

	// Equal 对值进行等于比较
	//
	// 参数:
	//
	//  other - 另一个操作数
	//  posStart - 表达式起始位置
	//  posEnd - 表达式结束位置
	//  frame - 当前调用栈
	//
	// 返回值:
	//
	//  Object - 比较结果
	Equal(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

	// NotEqual 对值进行不等于比较
	//
	// 参数:
	//
	//  other - 另一个操作数
	//  posStart - 表达式起始位置
	//  posEnd - 表达式结束位置
	//  frame - 当前调用栈
	//
	// 返回值:
	//
	//  Object - 比较结果
	NotEqual(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

	// LessThan 对值进行小于比较
	//
	// 参数:
	//
	//  other - 另一个操作数
	//  posStart - 表达式起始位置
	//  posEnd - 表达式结束位置
	//  frame - 当前调用栈
	//
	// 返回值:
	//
	//  Object - 比较结果
	LessThan(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

	// GreaterThan 对值进行大于比较
	//
	// 参数:
	//
	//  other - 另一个操作数
	//  posStart - 表达式起始位置
	//  posEnd - 表达式结束位置
	//  frame - 当前调用栈
	//
	// 返回值:
	//
	//  Object - 比较结果
	GreaterThan(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

	// LessThanOrEqual 对值进行小于等于比较
	//
	// 参数:
	//
	//  other - 另一个操作数
	//  posStart - 表达式起始位置
	//  posEnd - 表达式结束位置
	//  frame - 当前调用栈
	//
	// 返回值:
	//
	//  Object - 比较结果
	LessThanOrEqual(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

	// GreaterThanOrEqual 对值进行大于等于比较
	//
	// 参数:
	//
	//  other - 另一个操作数
	//  posStart - 表达式起始位置
	//  posEnd - 表达式结束位置
	//  frame - 当前调用栈
	//
	// 返回值:
	//
	//  Object - 比较结果
	GreaterThanOrEqual(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

	// BitAnd 对值进行按位与运算
	//
	// 参数:
	//
	//  other - 另一个操作数
	//  posStart - 表达式起始位置
	//  posEnd - 表达式结束位置
	//  frame - 当前调用栈
	//
	// 返回值:
	//
	//  Object - 运算结果
	//  error - 可能出现的错误
	BitAnd(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

	// BitOr 对值进行按位或运算
	//
	// 参数:
	//
	//  other - 另一个操作数
	//  posStart - 表达式起始位置
	//  posEnd - 表达式结束位置
	//  frame - 当前调用栈
	//
	// 返回值:
	//
	//  Object - 运算结果
	//  error - 可能出现的错误
	BitOr(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

	// Xor 对值进行异或运算
	//
	// 参数:
	//
	//  other - 另一个操作数
	//  posStart - 表达式起始位置
	//  posEnd - 表达式结束位置
	//  frame - 当前调用栈
	//
	// 返回值:
	//
	//  Object - 运算结果
	//  error - 可能出现的错误
	Xor(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

	// LeftShift 对值进行左移运算
	//
	// 参数:
	//
	//  other - 另一个操作数
	//  posStart - 表达式起始位置
	//  posEnd - 表达式结束位置
	//  frame - 当前调用栈
	//
	// 返回值:
	//
	//  Object - 运算结果
	//  error - 可能出现的错误
	LeftShift(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

	// RightShift 对值进行右移运算
	//
	// 参数:
	//
	//  other - 另一个操作数
	//  posStart - 表达式起始位置
	//  posEnd - 表达式结束位置
	//  frame - 当前调用栈
	//
	// 返回值:
	//
	//  Object - 运算结果
	//  error - 可能出现的错误
	RightShift(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

	// And 对值进行逻辑与运算
	//
	// 参数:
	//
	//  other - 另一个操作数
	//  posStart - 表达式起始位置
	//  posEnd - 表达式结束位置
	//  frame - 当前调用栈
	//
	// 返回值:
	//
	//  Object - 运算结果
	//  error - 可能出现的错误
	And(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

	// Or 对值进行逻辑或运算
	//
	// 参数:
	//
	//  other - 另一个操作数
	//  posStart - 表达式起始位置
	//  posEnd - 表达式结束位置
	//  frame - 当前调用栈
	//
	// 返回值:
	//
	//  Object - 运算结果
	//  error - 可能出现的错误
	Or(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

	// Index 对值进行索引运算
	//
	// 参数:
	//
	//  other - 另一个操作数
	//  posStart - 表达式起始位置
	//  posEnd - 表达式结束位置
	//  frame - 当前调用栈
	//
	// 返回值:
	//
	//  Object - 运算结果
	//  error - 可能出现的错误
	Index(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)
}

Value 运行时值接口,定义所有可计算值的通用操作 实现此接口的类型包括整数、浮点数、字符串、函数等

type OperationError

type OperationError struct {
	Frame    *frame.Frame // 错误发生时的调用栈
	Message  string       // 错误描述文本
	PosStart *util.Pos    // 错误起始位置
	PosEnd   *util.Pos    // 错误结束位置
}

OperationError 操作错误类型,表示执行不支持的操作时发生的错误 例如对不兼容类型执行运算、调用未定义的方法等 拥有完整的错误跟踪和格式化能力

func (*OperationError) Error

func (e *OperationError) Error() string

Error 生成格式化的操作错误信息字符串 前缀为"Operation Error"

返回值:

string - 格式化的操作错误信息,格式同基础Error但错误类型为"Operation Error"

type ReturnValue

type ReturnValue struct {
	Value Object // 返回的值
}

ReturnValue 返回值

func (*ReturnValue) Add

func (rv *ReturnValue) Add(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Add 对值进行加法运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*ReturnValue) And

func (rv *ReturnValue) And(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

And 对值进行逻辑与运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*ReturnValue) BitAnd

func (rv *ReturnValue) BitAnd(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

BitAnd 对值进行按位与运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*ReturnValue) BitNot

func (rv *ReturnValue) BitNot(posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

BitNot 对值进行按位非运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*ReturnValue) BitOr

func (rv *ReturnValue) BitOr(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

BitOr 对值进行按位或运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*ReturnValue) Divide

func (rv *ReturnValue) Divide(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Divide 对值进行除法运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*ReturnValue) Equal

func (rv *ReturnValue) Equal(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Equal 判断当前空值与另一个值是否相等

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*ReturnValue) GreaterThan

func (rv *ReturnValue) GreaterThan(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

GreaterThan 对值进行大于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*ReturnValue) GreaterThanOrEqual

func (rv *ReturnValue) GreaterThanOrEqual(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

GreaterThanOrEqual 对值进行大于等于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*ReturnValue) Index

func (rv *ReturnValue) Index(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Index 执行索引运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*ReturnValue) LeftShift

func (rv *ReturnValue) LeftShift(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

LeftShift 对值进行左移运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*ReturnValue) LessThan

func (rv *ReturnValue) LessThan(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

LessThan 对值进行小于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*ReturnValue) LessThanOrEqual

func (rv *ReturnValue) LessThanOrEqual(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

LessThanOrEqual 对值进行小于等于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*ReturnValue) Mod

func (rv *ReturnValue) Mod(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Mod 对值进行取模运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*ReturnValue) Multiply

func (rv *ReturnValue) Multiply(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Multiply 对值进行乘法运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*ReturnValue) Negative

func (rv *ReturnValue) Negative(posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Negative 对值进行负运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*ReturnValue) Not

func (rv *ReturnValue) Not(posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Not 对值进行逻辑非运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*ReturnValue) NotEqual

func (rv *ReturnValue) NotEqual(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

NotEqual 判断当前空值与另一个值是否不相等

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*ReturnValue) Or

func (rv *ReturnValue) Or(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Or 对值进行逻辑或运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*ReturnValue) RightShift

func (rv *ReturnValue) RightShift(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

RightShift 对值进行右移运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*ReturnValue) String

func (rv *ReturnValue) String() string

String 返回值的字符串表示

返回值:

string - 格式化的字符串表示

func (*ReturnValue) Subtract

func (rv *ReturnValue) Subtract(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Subtract 对值进行减法运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*ReturnValue) Type

func (rv *ReturnValue) Type() string

Type 返回值的类型

返回值:

string - 值的类型

func (*ReturnValue) Xor

func (rv *ReturnValue) Xor(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Xor 对值进行异或运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

type String

type String struct {
	Value string // 字符串的实际值
}

String 表示字符串值类型,实现了Object接口 用于存储和操作文本数据

func (*String) Add

func (s *String) Add(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Add 实现字符串的加法运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

运算结果;若操作失败则返回运行时错误

支持的操作:

  • 与*String类型相加:返回连接后的新字符串
  • 与其他类型相加:返回操作错误

func (*String) And

func (s *String) And(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

And 对值进行逻辑与运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*String) BitAnd

func (s *String) BitAnd(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

BitAnd 对值进行按位与运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*String) BitNot

func (s *String) BitNot(posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

BitNot 对值进行按位非运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*String) BitOr

func (s *String) BitOr(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

BitOr 对值进行按位或运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*String) Divide

func (s *String) Divide(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Divide 对值进行除法运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*String) Equal

func (s *String) Equal(other Object, _, _ *util.Pos, _ *frame.Frame) (Object, error)

Equal 判断当前字符串与另一个值是否相等

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

布尔值,表示比较结果;若操作失败则返回运行时错误

支持的比较:

  • 与*String类型比较:比较字符串内容是否相同
  • 与*Null类型比较:始终返回false
  • 与其他类型比较:返回操作错误

func (*String) GreaterThan

func (s *String) GreaterThan(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

GreaterThan 对值进行大于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*String) GreaterThanOrEqual

func (s *String) GreaterThanOrEqual(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

GreaterThanOrEqual 对值进行大于等于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*String) Index

func (s *String) Index(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Index 执行索引运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*String) LeftShift

func (s *String) LeftShift(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

LeftShift 对值进行左移运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*String) Length added in v0.3.0

func (s *String) Length() int64

Length 返回字符串的长度

返回值:

int64 - 字符串的长度

func (*String) LessThan

func (s *String) LessThan(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

LessThan 对值进行小于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*String) LessThanOrEqual

func (s *String) LessThanOrEqual(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

LessThanOrEqual 对值进行小于等于比较

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 比较结果

func (*String) Mod

func (s *String) Mod(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Mod 对值进行取模运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*String) Multiply

func (s *String) Multiply(other Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Multiply 实现字符串的乘法运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

运算结果;若操作失败则返回运行时错误

支持的操作:

  • 与*Int类型相乘:返回重复指定次数的新字符串
  • 若整数为负数或超过math.MaxInt:返回操作错误
  • 与其他类型相乘:返回操作错误

func (*String) Negative

func (s *String) Negative(posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Negative 对值进行负运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*String) Not

func (s *String) Not(posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Not 对值进行逻辑非运算

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*String) NotEqual

func (s *String) NotEqual(other Object, _, _ *util.Pos, _ *frame.Frame) (Object, error)

NotEqual 判断当前字符串与另一个值是否不相等

参数:

posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

布尔值,表示比较结果;若操作失败则返回运行时错误

支持的比较:

  • 与*String类型比较:比较字符串内容是否不同
  • 与*Null类型比较:始终返回true
  • 与其他类型比较:返回操作错误

func (*String) Or

func (s *String) Or(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Or 对值进行逻辑或运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*String) RightShift

func (s *String) RightShift(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

RightShift 对值进行右移运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*String) Set

func (s *String) Set(index Object, value Object, posStart, posEnd *util.Pos, frame *frame.Frame) error

Set 设置索引位置的值

参数:

index - 索引值
value - 要设置的值
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

error - 可能出现的错误

func (*String) String

func (s *String) String() string

String 返回值的字符串表示

返回值:

string - 格式化的字符串表示

func (*String) Subtract

func (s *String) Subtract(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Subtract 对值进行减法运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

func (*String) Type

func (s *String) Type() string

Type 返回值的类型

返回值:

string - 值的类型

func (*String) Xor

func (s *String) Xor(_ Object, posStart, posEnd *util.Pos, frame *frame.Frame) (Object, error)

Xor 对值进行异或运算

参数:

other - 另一个操作数
posStart - 表达式起始位置
posEnd - 表达式结束位置
frame - 当前调用栈

返回值:

Object - 运算结果
error - 可能出现的错误

type Symbol

type Symbol struct {
	Name    string // 符号名称
	Value   Object // 值
	IsConst bool   // 是否是常量
}

Symbol 表示一个标识符的完整信息

type TypeError

type TypeError struct {
	Frame    *frame.Frame // 错误发生时的调用栈
	Message  string       // 错误描述文本
	PosStart *util.Pos    // 错误起始位置
	PosEnd   *util.Pos    // 错误结束位置
}

TypeError 类型错误类型,表示类型相关的运行时错误 例如访问类型不匹配等 拥有完整的错误跟踪和格式化能力

func (*TypeError) Error

func (e *TypeError) Error() string

Error 生成格式化的类型错误信息字符串 前缀为"Type Error"

返回值:

string - 格式化的变量错误信息,格式同基础Error但错误类型为"Type Error"

Jump to

Keyboard shortcuts

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