funl

package
v0.0.0-...-ab47e86 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2024 License: MIT Imports: 23 Imported by: 4

Documentation

Index

Constants

View Source
const (
	IntValue ValueType = iota
	StringValue
	BoolValue
	FuncProtoValue
	FunctionValue
	ListValue
	ExtProcValue
	ChanValue
	FloatValue
	OpaqueValue
	MapValue
	ThunkValue

	ValueItem ItemType = iota
	SymbolPathItem
	OperCallItem

	AndOP OperType = iota
	OrOP
	NotOP
	CallOP
	EqOP
	IfOP
	PlusOP
	MinusOP
	MulOP
	DivOP
	ModOP
	ListOP
	EmptyOP
	HeadOP
	LastOP
	RestOP
	AppendOP
	AddOP
	LenOP
	TypeOP
	InOP
	IndOP
	FindOP
	SliceOP
	RrestOP
	ReverseOP
	ExtendOP
	SplitOP
	GtOP
	LtOP
	LeOP
	GeOP
	StrOP
	ConvOP
	CaseOP
	NameOP
	ErrorOP
	PrintOP
	SpawnOP
	ChanOP
	SendOP
	RecvOP
	SymvalOP
	TryOP
	TrylOP
	SelectOP
	EvalOP
	WhileOP
	FloatOP
	MapOP
	PutOP
	GetOP
	GetlOP
	KeysOP
	ValsOP
	KeyvalsOP
	LetOP
	ImpOP
	DelOP
	DellOP
	SprintfOP
	ArgslistOP
	CondOP
	HelpOP
	RecwithOP
	DeferOP
	ForceOP
	MaximumOP
)
View Source
const DeletionsLimit = 1000

DeletionsLimit is limit for amount of items marked as deleted in map, before making new map

Variables

View Source
var AnySymSid = SymIDMap.Add("_")
View Source
var PrintingDisabledInFunctions bool
View Source
var PrintingRTElocationAndScopeEnabled bool

Functions

func AddExtensionInitializer

func AddExtensionInitializer(initializer func(*Interpreter) error)

AddExtensionInitializer can be used for registering initializer for some extension module (registered in init -function)

func AddFunModToNamespace

func AddFunModToNamespace(importModName string, content []byte, interpreter *Interpreter) (err error)

func AddImportsToNamespace

func AddImportsToNamespace(nspace *NSpace, frame *Frame, interpreter *Interpreter)

func AddImportsToNamespaceSub

func AddImportsToNamespaceSub(nspace *NSpace, frame *Frame, interpreter *Interpreter)

func DebugPrint

func DebugPrint(format string, args ...interface{})

func EvalAndAssignValuesForSymbolsInFrameForNS

func EvalAndAssignValuesForSymbolsInFrameForNS(frame *Frame, ns *NSpace)

func GetModsFromTar

func GetModsFromTar(tarContent []byte) (map[string][]byte, error)

func GetReplCode

func GetReplCode() string

GetReplCode return REPL code

func GetWastedName

func GetWastedName() string

GetWastedName is for stdast use

func InitFunSourceSTD

func InitFunSourceSTD(interpreter *Interpreter) (err error)

InitFunSourceSTD provided for initializing std externally

func NewOperatorDocs

func NewOperatorDocs() map[string]string

NewOperatorDocs returns documentation for operators

func NewTokenizer

func NewTokenizer(operators Operators) *tokenizer

NewTokenizer exposes tokenizer API

func RunTimeError

func RunTimeError(format string, args ...interface{})

func RunTimeError2

func RunTimeError2(frame *Frame, format string, args ...interface{})

Types

type AddInfo

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

type ExtProcType

type ExtProcType struct {
	Impl       func(*Frame, []Value) Value
	IsFunction bool
}

type ExtSetupHandler

type ExtSetupHandler func(FNIApi) error

type FNIApi

type FNIApi interface {
	RegExtProc(ExtProcType, string) error
}

type FNIHandler

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

func (*FNIHandler) RegExtProc

func (fni *FNIHandler) RegExtProc(extProc ExtProcType, extProcName string) (err error)

type Frame

type Frame struct {
	FuncProto  *Function
	Syms       *Symt
	OtherNS    map[SymID]ImportInfo
	AccessLink *Frame // nil if root
	Imported   map[SymID]*Frame

	EvaluatedArgs []Value
	Interpreter   *Interpreter
	// contains filtered or unexported fields
}

func AddNStoCache

func AddNStoCache(inProcCall bool, importModName string, nspace *NSpace, interpreter *Interpreter) *Frame

AddNStoCache is for std usage

func NewTopFrameWithInterpreter

func NewTopFrameWithInterpreter(interpreter *Interpreter) *Frame

NewTopFrameWithInterpreter returns new top level frame

func SetupExtModule

func SetupExtModule(targetPath string, interpreter *Interpreter) (topFrame *Frame, err error)

func (*Frame) FindFuncSID

func (fr *Frame) FindFuncSID(fptr *Function) (sid SymID, found bool)

func (*Frame) GetFuncDebugInfos

func (fr *Frame) GetFuncDebugInfos(prev []fdebugInfo) []fdebugInfo

GetFuncDebugInfos gets function infos for backtrace

func (*Frame) GetImportedSymItem

func (fr *Frame) GetImportedSymItem(modSid SymID, rest SymbolPath) (*Item, bool)

GetImportedSymItem gets item from imported namespaces

func (*Frame) GetSymItem

func (fr *Frame) GetSymItem(sid SymID) (*Item, bool)

GetSymItem gets item ralated to symbol

func (*Frame) GetSymItemsOfImportedModule

func (fr *Frame) GetSymItemsOfImportedModule(modSid SymID) (*Symt, bool)

GetSymItemsOfImportedModule finds symbol table for module

func (*Frame) GetTopFrame

func (fr *Frame) GetTopFrame() *Frame

GetTopFrame gets top frame

func (*Frame) SetInProcCall

func (fr *Frame) SetInProcCall(v bool)

SetInProcCall sets inProcCall in Frame

type FuncValue

type FuncValue struct {
	FuncProto  *Function
	AccessLink *Frame // nil if root
}

type Function

type Function struct {
	IsProc      bool
	ArgNames    []SymID
	Body        *Item
	NSpace      NSpace
	Lineno      int
	Pos         int
	SrcFileName string
}

func (*Function) Show

func (f *Function) Show()

type ImportInfo

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

func (*ImportInfo) Path

func (imp *ImportInfo) Path() string

func (*ImportInfo) SetPath

func (imp *ImportInfo) SetPath(path string)

type Interpreter

type Interpreter struct {
	NsDir    *NSAccess
	Importer ModuleImporter
}

func NewInterpreter

func NewInterpreter() *Interpreter

type Item

type Item struct {
	Type             ItemType
	Data             interface{}
	Expand           bool
	ExpandArgIndexes map[int]bool
}

func GetArgs

func GetArgs(argsAsStr string) (argsItems []*Item, err error)

func (*Item) Print

func (item *Item) Print(depth int) (s string)

type ItemType

type ItemType int

func (ItemType) GoString

func (it ItemType) GoString() string

func (ItemType) String

func (it ItemType) String() string

type KeyVal

type KeyVal struct {
	Key Value
	Val Value
}

type List

type List struct {
	Head *ListObject
	Tail *ListObject
}

func (List) GoString

func (l List) GoString() string

func (List) String

func (l List) String() string

type ListIterator

type ListIterator struct {
	NextItem *ListObject
	HeadDone bool
	Tail     *ListObject
}

func NewListIterator

func NewListIterator(val Value) (lit *ListIterator)

func (*ListIterator) Next

func (lit *ListIterator) Next() *Value

type ListObject

type ListObject struct {
	Val  *Value
	Next *ListObject
}

type ModuleImporter

type ModuleImporter interface {
	FindModule(importModName string, extensionName string) (targetPath string, content []byte, err error)
}

type NSAccess

type NSAccess struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

NSAccess is access point to namespaces

func (*NSAccess) FillFromAstNSpaceAndStore

func (nsa *NSAccess) FillFromAstNSpaceAndStore(frame *Frame, sid SymID, nspace *NSpace)

func (*NSAccess) GetTopFrameBySID

func (nsa *NSAccess) GetTopFrameBySID(sid SymID) (frame *Frame, found bool)

func (*NSAccess) HasNS

func (nsa *NSAccess) HasNS(sid SymID) bool

func (*NSAccess) Print

func (nsa *NSAccess) Print() (s string)

func (*NSAccess) Put

func (nsa *NSAccess) Put(sid SymID, frame *Frame)

type NSTopInfo

type NSTopInfo struct {
	TopFrame         *Frame
	SymbolsEvaluated bool
}

type NSpace

type NSpace struct {
	Syms    *Symt
	OtherNS map[SymID]ImportInfo
}

func (*NSpace) Print

func (ns *NSpace) Print(depth int) (s string)

type Node

type Node struct {
	NodeType NodeType
	Childs   []*Node
}

Node represents one syntax node in syntax tree

type NodeHandler

type NodeHandler struct{}

func (*NodeHandler) HandleSameKey

func (nh *NodeHandler) HandleSameKey(srcNode *pmap.Node, key pmap.MKey, val pmap.MValue) (trgNode *pmap.Node)

func (*NodeHandler) MarkDeletion

func (nh *NodeHandler) MarkDeletion(srcNode *pmap.Node, key pmap.MKey, actualKey pmap.MValue) (trgNode *pmap.Node, keyFound bool)

type NodeType

type NodeType int

NodeType defines type of AST node

const (
	NodeTypeRoot NodeType = iota
	NodeTypeValue
	NodeTypeLet
	NodeTypeSymbolPath
	NodeTypeOperCall
)

type NodeValue

type NodeValue struct {
	Val           KeyVal
	SameKeyValues []KeyVal
	Deleted       bool
}

func NewNodeValue

func NewNodeValue(key, val Value) NodeValue

type OpCall

type OpCall struct {
	OperID   OperType
	Operands []*Item
}

type OpaqueAPI

type OpaqueAPI interface {
	TypeName() string
	Str() string
	Equals(with OpaqueAPI) bool
}

OpaqueAPI is interface for opaque type

type OperHandler

type OperHandler func(*Frame, []*Item) Value

type OperType

type OperType int

func OperNameToID

func OperNameToID(opName string) (op OperType, ok bool)

OperNameToID is for std usage

func (OperType) GoString

func (ot OperType) GoString() string

func (OperType) String

func (ot OperType) String() string

type OperatorInfo

type OperatorInfo struct{}

OperatorInfo contains information about one operator

type Operators

type Operators map[string]OperatorInfo

Operators contains operator information (operator name as key)

func NewDefaultOperators

func NewDefaultOperators() Operators

NewDefaultOperators returns default set of operators

type PMap

type PMap struct {
	Rbm *pmap.RBMap
	// contains filtered or unexported fields
}

PMap is persistent map

func (PMap) GoString

func (pm PMap) GoString() string

func (PMap) String

func (pm PMap) String() string

type ParseErrorHandler

type ParseErrorHandler interface {
	HandleParseError(errorText string)
}

type Parser

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

Parser implements syntax tree parser

func NewParser

func NewParser(operators Operators, srcFileName *string) *Parser

NewParser returns new parser instance

func (*Parser) Parse

func (p *Parser) Parse(source string) (nsName string, ns *NSpace, err error)

Parse calls token iterator to scan source text and based on tokens it forms syntax tree

func (*Parser) ParseArgs

func (p *Parser) ParseArgs(source string) (argsItems []*Item, err error)

func (*Parser) ParseExpandedLet

func (p *Parser) ParseExpandedLet() (symbols []string, item *Item)

func (*Parser) ParseExpr

func (p *Parser) ParseExpr() (item *Item)

ParseExpr parses expression

func (*Parser) ParseFuncValue

func (p *Parser) ParseFuncValue(procOrFuncToken token) (funcData *Function)

func (*Parser) ParseImport

func (p *Parser) ParseImport() (modName string, importInfo ImportInfo)

ParseImport parses import definition

func (*Parser) ParseLet

func (p *Parser) ParseLet() (symbol string, item *Item)

ParseLet parses let definition

func (*Parser) ParseNamespace

func (p *Parser) ParseNamespace() (nsName string, ns *NSpace)

ParseNamespace parses namespace definition

func (*Parser) ParseOneExpression

func (p *Parser) ParseOneExpression(source string) (item *Item, err error)

func (*Parser) ParseOperCall

func (p *Parser) ParseOperCall() (item *Item)

ParseOperCall parses operator call

func (*Parser) ParseSymbolPath

func (p *Parser) ParseSymbolPath() (item *Item)

ParseSymbolPath

func (*Parser) ParseValue

func (p *Parser) ParseValue() (item *Item)

ParseValue parses value

func (*Parser) SetCanEndWithSymbol

func (p *Parser) SetCanEndWithSymbol(canSet bool)

func (*Parser) SetErrorHandler

func (p *Parser) SetErrorHandler(peh ParseErrorHandler)

type SymID

type SymID int

func (SymID) GoString

func (sid SymID) GoString() string

func (SymID) String

func (sid SymID) String() string

type SymbolPath

type SymbolPath []SymID

func (*SymbolPath) ToString

func (sp *SymbolPath) ToString() string

type SymbolToIDConverter

type SymbolToIDConverter struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewSymbolToIDConverter

func NewSymbolToIDConverter() *SymbolToIDConverter

func (*SymbolToIDConverter) Add

func (sidc *SymbolToIDConverter) Add(symbol string) SymID

func (*SymbolToIDConverter) AsString

func (sidc *SymbolToIDConverter) AsString(sid SymID) string

func (*SymbolToIDConverter) Get

func (sidc *SymbolToIDConverter) Get(symbol string) (sid SymID, found bool)

func (*SymbolToIDConverter) SymbolCount

func (sidc *SymbolToIDConverter) SymbolCount() int

type Symt

type Symt struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewSymt

func NewSymt() *Symt

func (*Symt) Add

func (sym *Symt) Add(symbol string, item *Item) error

func (*Symt) AddBySID

func (sym *Symt) AddBySID(sid SymID, item *Item) bool

func (*Symt) AddBySIDByOverwriteIfNeeded

func (sym *Symt) AddBySIDByOverwriteIfNeeded(sid SymID, item *Item) bool

func (*Symt) AsMap

func (sym *Symt) AsMap() map[SymID]*Item

func (*Symt) FindFuncSID

func (sym *Symt) FindFuncSID(fptr *Function) (sid SymID, found bool)

func (*Symt) GetByName

func (sym *Symt) GetByName(symbol string) (*Item, bool)

func (*Symt) GetBySID

func (sym *Symt) GetBySID(sid SymID) (*Item, bool)

func (*Symt) Has

func (sym *Symt) Has(key SymID) bool

func (*Symt) Keys

func (sym *Symt) Keys() []SymID

func (*Symt) MakeCopy

func (sym *Symt) MakeCopy() *Symt

func (*Symt) Print

func (sym *Symt) Print(depth int) (s string)

type Thunk

type Thunk struct {
	EvaluatedValue *Value
	Expr           *Item
	AccessLink     *Frame
	sync.Mutex
}

type Value

type Value struct {
	Kind ValueType
	Data interface{}
}

func EvalItem

func EvalItem(item *Item, frame *Frame) (retVal Value)

func EvalItemV2

func EvalItemV2(item *Item, frame *Frame, addInfo *AddInfo) (retVal Value)

TODO: its copy-paste, but no wrapper because it would add additional overhead

func FunlMainWithArgs

func FunlMainWithArgs(content string, argsItems []*Item, name, srcFileName string, initSTD func(*Interpreter) error) (retValue Value, err error)

func FunlMainWithInterpreter

func FunlMainWithInterpreter(content string, argsItems []*Item, name, srcFileName string, initSTD func(*Interpreter) error, interpreter *Interpreter) (retValue Value, err error)

func FunlMainWithPackImport

func FunlMainWithPackImport(impPackName string, content string, argsItems []*Item, name, srcFileName string, initSTD func(*Interpreter) error) (retValue Value, err error)

func FunlMainWithPackImportContent

func FunlMainWithPackImportContent(data []byte, content string, argsItems []*Item, name, srcFileName string, initSTD func(*Interpreter) error) (retValue Value, err error)

func FunlMainWithPackage

func FunlMainWithPackage(argsItems []*Item, name, srcFileName string, initSTD func(*Interpreter) error) (retValue Value, err error)

func FunlMainWithPackageContent

func FunlMainWithPackageContent(data []byte, argsItems []*Item, name, srcFileName string, initSTD func(*Interpreter) error) (retValue Value, err error)

func HandleCallOP

func HandleCallOP(frame *Frame, operands []*Item) (retVal Value)

HandleCallOP for std lib usage

func HandleEvalOP

func HandleEvalOP(frame *Frame, operands []*Item) (retVal Value)

HandleEvalOP can be used from Go code

func HandleGetlOP

func HandleGetlOP(frame *Frame, operands []*Item) (retVal Value)

HandleGetlOP is for std usage

func HandleKeyvalsOP

func HandleKeyvalsOP(frame *Frame, operands []*Item) (retVal Value)

HandleKeyvalsOP is for std usage

func HandleMapOP

func HandleMapOP(frame *Frame, operands []*Item) (retVal Value)

HandleMapOP is for std usage

func HandlePutOP

func HandlePutOP(frame *Frame, operands []*Item) (retVal Value)

HandlePutOP is for std usage

func HandleSprintfOP

func HandleSprintfOP(frame *Frame, operands []*Item) (retVal Value)

func MakeListOfValues

func MakeListOfValues(frame *Frame, values []Value) (retVal Value)

MakeListOfValues offers API for std to create list for values

func (Value) GoString

func (val Value) GoString() string

func (Value) String

func (val Value) String() string

type ValueType

type ValueType int

func (ValueType) GoString

func (vt ValueType) GoString() string

func (ValueType) String

func (vt ValueType) String() string

Jump to

Keyboard shortcuts

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