ops

package
v0.0.0-...-35dec8a Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BasicType

func BasicType[T Number]() types.Basic

func Cast

func Cast(ctx *parser.CustomContext, t types.Basic, expr ExprNumber) any

разные функции под разные типы -> мапа не подходит

Types

type Any

type Any interface {
	Statement | Int64 | Float64 | Bool
}

type Bool

type Bool = Op[bool]

type Expr

type Expr interface {
	Type() types.Basic
	IsConstant() bool
	IsExpr()
}

func Binary

func Binary(ctx *parser.CustomContext, op Operator, left, right ExprNumber, castType types.Basic) Expr

func Constant

func Constant(v types.Variable) Expr

принимает types.Variable // TODO лучше сделать интерфейс

func MakeExpr

func MakeExpr(v any) (Expr, error)

func Variable

func Variable(ctx *parser.CustomContext, name string, v types.Variable) Expr

type ExprBool

type ExprBool struct{ Bool }

func (ExprBool) IsConstant

func (x ExprBool) IsConstant() bool

func (ExprBool) IsExpr

func (x ExprBool) IsExpr()

func (ExprBool) Type

func (x ExprBool) Type() types.Basic

type ExprFloat64

type ExprFloat64 struct{ Float64 }

func (ExprFloat64) IsConstant

func (x ExprFloat64) IsConstant() bool

func (ExprFloat64) IsExpr

func (x ExprFloat64) IsExpr()

func (ExprFloat64) IsNumber

func (x ExprFloat64) IsNumber()

func (ExprFloat64) Type

func (x ExprFloat64) Type() types.Basic

type ExprInt64

type ExprInt64 struct{ Int64 }

func (ExprInt64) IsConstant

func (x ExprInt64) IsConstant() bool

func (ExprInt64) IsExpr

func (x ExprInt64) IsExpr()

func (ExprInt64) IsNumber

func (x ExprInt64) IsNumber()

func (ExprInt64) Type

func (x ExprInt64) Type() types.Basic

type ExprNumber

type ExprNumber interface {
	Expr
	IsNumber()
}

func MakeExprNumber

func MakeExprNumber(v any) (ExprNumber, error)

func UnaryMinus

func UnaryMinus(ctx *parser.CustomContext, expr ExprNumber) ExprNumber

type ExprString

type ExprString struct{ String }

func (ExprString) IsConstant

func (x ExprString) IsConstant() bool

func (ExprString) IsExpr

func (x ExprString) IsExpr()

func (ExprString) Type

func (x ExprString) Type() types.Basic

type Float64

type Float64 = Op[float64]

type Int64

type Int64 = Op[int64]

type Number

type Number interface {
	constraints.Integer | constraints.Float
}

type NumberOpTypes

type NumberOpTypes interface {
	int64 | float64
}

type Op

type Op[T OpTypes | struct{}] struct {
	// нужно принимать в колбэк ресивер, так как при использовании замыкания,
	// оно захватывает ресивер из конструктора, но этот указатель может быть заменён после
	Do      func(self *Statement) (T, *Statement) // результат вычислений и следующий Statement (может быть nil)
	DoDebug func(self *Statement) (T, *Statement) // тоже самое, что Do, но с выводом в логгер дебажной инфы
	// инты передаю всегда через int64
	// это поле говорит об ограничениях, например INT -> int16
	// эти ограничения надо учитывать для возможного неявного приведения
	ResultType types.Basic
	// у константы тип приводиться к аргументу не константе
	// TODO константы вообще можно не через оператор передавать, а сразу аргументом
	IsConstant bool
	// contains filtered or unexported fields
}

func StatementVariable

func StatementVariable[T OpTypes](ctx *parser.CustomContext, stmt *Statement, name string, variable types.Variable) Op[T]

сначала выполняются инструкции, потом возвращается переменная

type OpTypes

type OpTypes interface {
	int64 | float64 | string | bool
}

только такие типы могут быть результатом оператора специально ограничил, чтобы было меньше ветвлений с типами меньшего размера буду приводить при вычислении

type Operator

type Operator int
const (
	Undefined Operator = iota
	Plus
	Minus
	Mult
	Div
	Mod
	Eq    // ==
	NotEq // !=
	Gt    // >
	Gte   // >=
	Lt    // <
	Lte   // <=
)

type Placeholders

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

структура сохраняет все заглушки, чтобы в случае замены на новую заглушку заменить везде указатели, и в случае замены на другую заглушку тоже это нужно, когда будут ветвления внутри ветвлений для вставки следующего шага

func NewPlaceholders

func NewPlaceholders() *Placeholders

func (*Placeholders) AddToStatementChain

func (x *Placeholders) AddToStatementChain(chain, next *Statement) *Statement

возвращает указатель на последний вставленный Statement может отличаться от next, когда происходит замена плейсхолдера так как плейсхолдера обычно используется для связи с другими узлами и его указатель менять нелья меняется только содержимое по указателю, и возвращается этот неизменённый указатель

type Statement

type Statement = Op[struct{}]

func Assign

func Assign(ctx *parser.CustomContext, name string, v types.Variable, expr Expr) *Statement

func IfTrue

func IfTrue(_ *parser.CustomContext, cond ExprBool, body *Statement) *Statement

func Jump

func Jump(ctx *parser.CustomContext, to *Statement, message string) *Statement

func Placeholder

func Placeholder() *Statement

указатель, для подстановки и последующей замены содержимого

type String

type String = Op[string]

Jump to

Keyboard shortcuts

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