value

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package value defines the type that represents the evaluation result.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNil     = errors.New("nil error")
	ErrType    = errors.New("type error")
	ErrZeroDiv = errors.New("division by zero")
	ErrIndex   = errors.New("index error")
)

Predefined errors.

View Source
var Nil = Type{/* contains filtered or unexported fields */}

Nil is the nil value.

Functions

This section is empty.

Types

type FunctionData added in v1.3.0

type FunctionData struct {
	Node     int     // Pointer to the code of the function - the AST node that holds the function
	Frame    *[]Type // Pointer to the closure stack frame
	ParamCnt int     // ParamCnt is the number of parameters of the function
	LocalCnt int     // LocalCnt is the number of local variables of the function including ParamCnt
}

A structure that represents a function value.

type Type

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

Type is evaluation result value.

It is a uniform structure, not an interface, to keep evaluation on the stack as much as possible.

func NewArray added in v1.3.0

func NewArray(a []Type) Type

NewArray allocates a new array value.

func NewBool added in v1.3.0

func NewBool(b bool) Type

NewBool allocates a new bool value.

func NewFloat added in v1.3.0

func NewFloat(f float64) Type

NewFloat allocates a new float value.

func NewFunction added in v1.3.0

func NewFunction(node int, frame *[]Type, paramCnt int, localCnt int) Type

NewFunction allocates a new function value.

func NewInt added in v1.3.0

func NewInt(i int) Type

NewInt allocates a new int value.

func NewString added in v1.3.0

func NewString(s string) Type

NewString allocates a new string value.

func (Type) Abbrev added in v1.4.0

func (t Type) Abbrev() string

Abbrev abbreviates string of t to 20 characters with ellipses.

func (Type) Arith

func (t Type) Arith(op bytecode.OpCode, b Type) (Type, error)

Arith is value arithmetics, +, -, * /.

func (Type) Display added in v1.4.0

func (t Type) Display() string

Display converts a value to a string for calc result printing.

Adds extra quotes around string type.

func (Type) Eq

func (t Type) Eq(op bytecode.OpCode, b Type) (Type, error)

Equality check, ==, !=.

func (Type) Flip added in v1.4.0

func (t Type) Flip() (Type, error)

Flip is integer bit flip operator.

func (Type) Index

func (t Type) Index(b ...Type) (Type, error)

Index is value indexing, [] and [:].

func (Type) IsNil added in v1.4.0

func (t Type) IsNil() bool

IsNil determines whether a value is nil.

func (Type) Len

func (t Type) Len() (Type, error)

Len is value length.

func (Type) Logic

func (t Type) Logic(op bytecode.OpCode, b Type) (Type, error)

Logic is value logic ops &, |.

func (Type) Mod added in v1.3.0

func (t Type) Mod(b Type) (Type, error)

func (Type) Not added in v1.3.0

func (t Type) Not() (Type, error)

Not is boolean not operator.

func (Type) Relational

func (t Type) Relational(op bytecode.OpCode, b Type) (Type, error)

Relational is value relational <, >, <= ...

func (*Type) SetFrame added in v1.5.0

func (t *Type) SetFrame(frame *[]Type)

func (Type) Shift added in v1.4.0

func (t Type) Shift(op bytecode.OpCode, b Type) (Type, error)

Shift is bit shift ops <<, >>.

func (*Type) StrictEq added in v1.3.0

func (t *Type) StrictEq(b Type) bool

StrictEq decides whether a and b are exactly the same value.

1 == 1.0 -> false

in strict equality all functions are equal, this is counter intuitive, but for testing it makes sense.

func (Type) String added in v1.3.0

func (t Type) String() string

String converts any value.Type to string.

func (Type) ToArray added in v1.3.0

func (t Type) ToArray() ([]Type, bool)

func (Type) ToBool added in v1.3.0

func (t Type) ToBool() (bool, bool)

ToBool converts a value to bool.

It returns ok false if not an bool.

func (Type) ToFunction added in v1.3.0

func (t Type) ToFunction() (FunctionData, bool)

ToFunction converts a value to FunctionData.

It returns ok false if not a function.

func (Type) ToInt added in v1.3.0

func (t Type) ToInt() (int, bool)

ToInt converts a value to int.

It returns ok false if not an int.

func (Type) ToString added in v1.3.0

func (t Type) ToString() (string, bool)

ToString converts a value to string.

It returns ok false if not a string.

func (*Type) WeakEq added in v1.3.0

func (t *Type) WeakEq(b Type) (bool, error)

WeakEq decides whether a and b are the same value as per language rules.

1 == 1.0 -> true

All functions are un-equal.

Jump to

Keyboard shortcuts

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