internal

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2026 License: BlueOak-1.0.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PragmaDisplayCount   = "count"
	PragmaDisplaySummary = "summary"
	PragmaDisplayNone    = "none"
)
View Source
const (
	PragmaDedupIDs    = "ids"
	PragmaDedupNumber = "number"
	PragmaDedupNone   = "none"
)

Variables

View Source
var (
	ErrOutOfGas                  = errors.New("processed more than maximum number of instructions")
	ErrEmptyStack                = errors.New("tried to pop off empty stack")
	ErrUnexpectedStackState      = errors.New("unexpected stack state")
	ErrNotIterating              = errors.New("not iterating a goroutine dump")
	ErrOutOfStackBounds          = errors.New("jump outside of stack bounds")
	ErrInvalidType               = errors.New("invalid type for operation")
	ErrWrongTag                  = errors.New("data had wrong tag for type")
	ErrInvalidOpArg              = errors.New("invalid argument for operation")
	ErrArgumentUnset             = errors.New("expected argument is unset")
	ErrNoSuchOpCode              = errors.New("no such op code")
	ErrExpectedConstantValueByte = errors.New("expected value after constant load byte")
	ErrExpectedJumpAddress       = errors.New("expected address for jump")
	ErrExpectedCommand           = errors.New("expected valid command after command byte")
	ErrNoSuchEnv                 = errors.New("no identifer with name")
	ErrNoSuchPragma              = errors.New("no pragma with name")
	ErrExpectedDiffAssign        = errors.New("assigning a diff must have 3 identifiers or \"_\"")

	ErrCommandQuit    = errors.New("user quit")
	ErrCommandOk      = errors.New("command ok")
	ErrCommandConfirm = errors.New("are you sure?")
)
View Source
var EmptyToken = Token{}
View Source
var ErrEOF = errors.New("EOF")
View Source
var ErrExpectedMaybeType = errors.New("expected optional")
View Source
var ErrExpectedPath = errors.New("expected a path argument")
View Source
var ErrInvalidArg = errors.New("invalid argument")
View Source
var ErrMissingArgs = errors.New("expected more arguments")
View Source
var ErrTooManyArgs = errors.New("too many arguments")
View Source
var NoValue = Value{Tag: TagNone}

Functions

func NewWritersFrom

func NewWritersFrom(cfg *Config) (*Writer, *Writer)

NewWritersFrom returns a "stdout" and a "stderr" Writer based on the configuration

Types

type BindingPower

type BindingPower = int
const (
	BindingNone BindingPower = iota
	BindingComma
	BindingAssignment
	BindingPipe
	BindingFunc
	BindingOr
	BindingAnd
	BindingEq
	BindingCompare
	BindingUnary
	BindingCall
	BindingPrimary
	BindingAtom
)

type Chunk

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

func NewChunk

func NewChunk() *Chunk

type Compiler

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

func NewCompiler

func NewCompiler() *Compiler

func (*Compiler) Compile

func (p *Compiler) Compile(tokenizer *Tokenizer) (*Chunk, error)

type CompilerError

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

func (CompilerError) Error

func (e CompilerError) Error() string

func (CompilerError) Unwrap

func (e CompilerError) Unwrap() error

type Config

type Config struct {
	WorkDir string
	Stdout  io.Writer
	Stderr  io.Writer
	Color   bool
}

type ConfirmationAction

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

ConfirmationAction lets us close over a function and smuggle it back out to the REPL for execution

func (ConfirmationAction) Error

func (c ConfirmationAction) Error() string

func (ConfirmationAction) Run

func (c ConfirmationAction) Run()

type Diff

type Diff struct {
	Left   *GoroutineDump
	Right  *GoroutineDump
	Common *GoroutineDump
}

type Evaluator

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

func NewEvaluator

func NewEvaluator(cfg *Config) *Evaluator

func (*Evaluator) Completions

func (e *Evaluator) Completions() []string

Completions returns all the known functions, commands, and keywords, plus all the tokens in the environment

func (*Evaluator) Eval

func (e *Evaluator) Eval(ctx context.Context, src string) error

type Goroutine

type Goroutine struct {
	ID        int    `json:"id"`
	Duration  int    `json:"duration"` // In minutes, from meta in header
	State     string `json:"state"`    // From meta in header
	CreatedBy int    `json:"createdBy"`
	Trace     string `json:"trace"`
	LineCount int    `json:"lines"`
	// contains filtered or unexported fields
}

func NewGoroutine

func NewGoroutine(header string) (*Goroutine, error)

NewGoroutine creates and returns a new Goroutine.

func (*Goroutine) AddLine

func (g *Goroutine) AddLine(l string)

AddLine appends a line to the goroutine info.

func (*Goroutine) Debug

func (g *Goroutine) Debug() string

func (*Goroutine) Freeze

func (g *Goroutine) Freeze()

Freeze freezes the goroutine info.

func (*Goroutine) Print

func (g *Goroutine) Print(w *Writer, duplicateIDs []int, pragma PragmaDedup)

Print outputs the goroutine details to stdout with color.

type GoroutineDump

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

func NewGoroutineDump

func NewGoroutineDump() *GoroutineDump

func (*GoroutineDump) Add

func (gd *GoroutineDump) Add(g *Goroutine)

func (*GoroutineDump) Copy

func (gd *GoroutineDump) Copy() *GoroutineDump

Copy duplicates the goroutine dump with a shallow copy of the goroutines and a reset iterator

func (*GoroutineDump) Has

func (gd *GoroutineDump) Has(p *Goroutine) bool

func (*GoroutineDump) Index

func (gd *GoroutineDump) Index()

Index creates an lookup table for duplicates. It assumes the dump is sorted. Because dumps are intended to be immutable, it'll check/set the isIndexed flag so that we only do this expensive work once.

func (*GoroutineDump) Len

func (gd *GoroutineDump) Len() int

func (*GoroutineDump) Next

func (gd *GoroutineDump) Next() *Goroutine

func (GoroutineDump) Save

func (gd GoroutineDump) Save(fn string) error

Save saves the goroutine dump to the given file. Assumes the dump is already sorted.

func (*GoroutineDump) Show

func (gd *GoroutineDump) Show(w *Writer, pragma PragmaDedup, limit, offset int)

Show displays the goroutines with the given limit and offset

func (*GoroutineDump) Sort

func (gd *GoroutineDump) Sort()

Sort sorts the goroutines by ID. Generally speaking we only need this once we've unioned two dumps

func (*GoroutineDump) StartIter

func (gd *GoroutineDump) StartIter()

func (*GoroutineDump) String

func (gd *GoroutineDump) String() string

String is a placeholder until we wire this all up to the REPL writer

func (*GoroutineDump) Summary

func (gd *GoroutineDump) Summary(w *Writer, name string)

type MultiAssignment

type MultiAssignment []int

MultiAssignment is stored as a constant and itself contains indexes into the constants table. This lets us multi-assign by emitting an OpCodeAssignment that the VM will then dereference into these values and pop items off the stack. Like Go, you can use the _ sigil, which maps to a -1 xindex. In that case, the VM will pop a value off the stack and drop it.

type Op

type Op uint

func (Op) String

func (code Op) String() string

type OpCode

type OpCode uint
const (
	OpCodeNoop OpCode = iota

	// loads
	OpCodeLoadGoroutineDump
	OpCodeLoadFieldAccessor
	OpCodeLoadNumber
	OpCodeLoadString

	// stores
	OpCodeAssignment
	OpCodePushBool
	OpCodePushDump
	OpCodeDup

	// filter iteration
	OpCodeAddGoroutine
	OpCodeNextGoroutine
	OpCodeTempDump

	// comparisons
	OpCodeContains
	OpCodeIn // opContains
	OpCodeRegexMatches
	OpCodeRegexNotMatches // opRegexMatches
	OpCodeEqual           // opComparison
	OpCodeGreater         // opComparison
	OpCodeGreaterEqual    // opComparison
	OpCodeLess            // opComparison
	OpCodeLessEqual       // opComparison
	OpCodeNotEqual        // opComparison

	// control flow
	OpCodeJumpIfFalse // opConditionalJump
	OpCodeJumpIfTrue  // opConditionalJump
	OpCodeJumpTo

	// functions
	OpCodeFuncDiff
	OpCodeFuncIntersect
	OpCodeFuncLoad
	OpCodeFuncSave
	OpCodeFuncShowDump
	OpCodeFuncToJSON
	OpCodeFuncToDot
	OpCodeFuncUnion
	OpCodeFuncGraph

	// commands
	OpCodeCommandChangeDir
	OpCodeCommandEmpty
	OpCodeCommandGetWorkingDir
	OpCodeCommandHelp
	OpCodeCommandListDir
	OpCodeCommandQuit
	OpCodeCommandVars
	OpCodeCommandSetPragma
	OpCodeCommandGetPragma

	OpCodePatchPlaceholder = 0x000000000000ffff
)

func (OpCode) String

func (i OpCode) String() string

type Pragma

type Pragma struct {
	EmptyConfirm bool
	ExitConfirm  bool
	ListFormat   string
	ShowColor    bool
	ShowCount    int
	ShowDedup    string
	VarsDisplay  string
	Gas          int
	StackSize    int
}

Pragma represents all the VM's configuration values.

func NewPragma

func NewPragma() *Pragma

type PragmaDedup

type PragmaDedup string

type PragmaDisplay

type PragmaDisplay string

type Tag

type Tag uint
const (
	TagNone          Tag = iota
	TagBool              // bool
	TagNumber            // number
	TagString            // string
	TagIdentifier        // identifier
	TagFieldAccessor     // field accessor
	TagCommand           // command
	TagDump              // dump
	TagGoroutine         // goroutine
	TagAddress           // address
	TagDiff              // diff
)

func (Tag) String

func (i Tag) String() string

type Token

type Token struct {
	Type   TokenType
	Lexeme string // text of the token
	Pos    scanner.Position
}

func (Token) String

func (t Token) String() string

type TokenType

type TokenType uint8
const (
	TokenInvalid    TokenType = iota // invalid
	TokenPipe                        // pipe
	TokenLeftParen                   // left paren
	TokenRightParen                  // right paren
	TokenPlus                        // +
	TokenMinus                       // -
	TokenStar                        // *
	TokenSlash                       // /
	TokenBang                        // !
	TokenComma                       // ,
	TokenAssign                      // =

	// comparisons
	TokenEqual            // ==
	TokenNotEqual         // !=
	TokenLessThan         // <
	TokenLessEqualThan    // <=
	TokenGreaterThan      // >
	TokenGreaterEqualThan // >=
	TokenKeywordContains  // contains
	TokenKeywordMatches   // match
	TokenKeywordIn        // in
	TokenRegexMatch       // =~
	TokenRegexNotMatch    // !~

	// literals
	TokenIdentifier    // identifier
	TokenString        // string
	TokenNumber        // number
	TokenFieldAccessor // field accessor

	// logic
	TokenKeywordAnd // and
	TokenKeywordOr  // or

	//
	TokenCommand  // command
	TokenFunction // function
	TokenMethod   // method
	TokenPragma   // pragma
)

func (TokenType) String

func (i TokenType) String() string

type Tokenizer

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

func NewTokenizer

func NewTokenizer() *Tokenizer

func (*Tokenizer) Next

func (s *Tokenizer) Next() (Token, error)

Next returns the next token

func (*Tokenizer) Peek

func (s *Tokenizer) Peek() (Token, error)

Peek looks at the next token but doesn't consume it from the source, such that a subsequent call to Next will return this same token

func (*Tokenizer) Reset

func (s *Tokenizer) Reset(ctx context.Context, body io.Reader)

func (*Tokenizer) Tokens

func (s *Tokenizer) Tokens() iter.Seq2[Token, error]

Tokens returns an iterator over the source and yields an EOF error when out of tokens

type VM

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

func NewVM

func NewVM(cfg *Config) *VM

func (*VM) Reset

func (vm *VM) Reset(chunk *Chunk)

func (*VM) Run

func (vm *VM) Run(ctx context.Context) error

type Value

type Value struct {
	Tag  Tag
	Data any
}

type Writer

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

Writer wraps a io.Writer and lets us add color to output

func NewWriter

func NewWriter(inner io.Writer) *Writer

NewWriter is the default constructor without color (typically for tests)

func (*Writer) Write

func (w *Writer) Write(p []byte) (int, error)

Write implements io.Writer. It tries to always write the entire contents to the inner io.Writer before returning. If configured for color, it'll emit an ANSI color code byte before writing and then reset when it'd done.

Jump to

Keyboard shortcuts

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