symbol

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package symbol implements symbol utilities.

Index

Constants

View Source
const UnsetAddr = -65535

UnsetAddr denotes an unset symbol index (vs 0).

Variables

This section is empty.

Functions

func Vtype

func Vtype(s *Symbol) *vm.Type

Vtype returns the VM type of a symbol.

Types

type Kind

type Kind int

Kind represents the symbol kind.

const (
	Unset    Kind = iota
	Value         // a value defined in the runtime
	Type          // a type
	Label         // a label indicating a position in the VM code
	Const         // a constant
	Var           // a variable in global data
	LocalVar      // a variable in the local call frame
	Func          // a function, located in the VM code
	Pkg           // a package
	Builtin       // a built-in function (len, cap, append, etc.)
	Generic       // a generic function or type template
)

Symbol kinds.

func (Kind) String

func (i Kind) String() string

type Package

type Package struct {
	Path   string
	Bin    bool
	Values map[string]vm.Value
}

Package is a package struct containing source or binary values.

func BinPkg

func BinPkg(m map[string]reflect.Value, name string) *Package

BinPkg returns a binary package from a map of reflect values.

type SymMap

type SymMap map[string]*Symbol

SymMap is a map of Symbols.

func (SymMap) Get

func (sm SymMap) Get(name, scope string) (sym *Symbol, sc string, ok bool)

Get searches for an existing symbol starting from the deepest scope.

func (SymMap) Init

func (sm SymMap) Init()

Init fills the symbol map with default Go symbols.

func (SymMap) MethodByName

func (sm SymMap) MethodByName(sym *Symbol, name string) (*Symbol, []int)

MethodByName returns the method symbol and the field index path to the receiver (empty for direct methods, non-empty for promoted methods through embedded fields).

type Symbol

type Symbol struct {
	Kind       Kind
	Name       string         //
	Index      int            // address of symbol in frame
	PkgPath    string         //
	Type       *vm.Type       //
	Value      vm.Value       //
	Cval       constant.Value //
	Used       bool           //
	Captured   bool           // true if this variable escapes to a heap cell
	LoopVar    bool           // true if this is a for-init or range variable (snapshot capture)
	CellSlot   bool           // true if the local frame slot holds a heap cell pointer (promoted)
	FreeVars   []string       // closure: scoped names of captured outer-scope locals, in Heap order
	RecvName   string         // for methods: raw receiver variable name
	InNames    []string       // raw input param names, cached from Phase 1 for Phase 2
	OutNames   []string       // raw output param names, cached from Phase 1 for Phase 2
	MethodExpr bool           // true if this is a method expression (Type.Method)
	Composite  bool           // true if this symbol is a composite literal value (T{})
	NoFnew     bool           // true if this Type-kind stack entry was pushed without an Fnew emit (T(x), T.M, etc.); consumers must skip removeFnew
	// FieldOffset and HasFieldOffset are set when this symbol is produced by a
	// struct field selector chain; FieldOffset is the accumulated byte offset
	// from the outermost operand to this field. Used by unsafe.Offsetof.
	HasFieldOffset bool
	FieldOffset    uintptr
	Data           any              // optional extra data (e.g. generic template)
	Reads          map[*Symbol]bool // for Func: package-level Var symbols read transitively by the body
}

Symbol structure used in parser and compiler.

func (*Symbol) FreeVarIndex

func (s *Symbol) FreeVarIndex(name string) int

FreeVarIndex returns the index of name in FreeVars, or -1 if not found.

func (*Symbol) IsConst

func (s *Symbol) IsConst() bool

IsConst returns true if symbol is a constant.

func (*Symbol) IsFunc

func (s *Symbol) IsFunc() bool

IsFunc returns true if symbol is a function.

func (*Symbol) IsInt

func (s *Symbol) IsInt() bool

IsInt returns true if symbol is an int.

func (*Symbol) IsParam added in v0.2.0

func (s *Symbol) IsParam() bool

IsParam reports whether s is a function parameter slot.

func (*Symbol) IsPtr

func (s *Symbol) IsPtr() bool

IsPtr returns true if symbol is a pointer.

func (*Symbol) IsType

func (s *Symbol) IsType() bool

IsType returns true if symbol is a type.

func (*Symbol) NeedsCell

func (s *Symbol) NeedsCell() bool

NeedsCell reports whether this variable should be promoted to a heap cell (captured by a closure and not a loop iteration variable).

Jump to

Keyboard shortcuts

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