Documentation
¶
Index ¶
- Constants
- Variables
- func InitializeBuiltins(dirname string, filename string, args []string)
- func RuntimeWaitGroup() *sync.WaitGroup
- func ToNumber(obj Object) (float64, error)
- func ToString(obj Object) (string, error)
- func Tokenize(input string) []string
- type BuiltinFunction
- type Function
- type Item
- type List
- func (l *List) Append(obj Object)
- func (l *List) Copy() List
- func (l *List) Index(index int) Object
- func (self *List) Join(other List)
- func (l *List) Next(item *Item, index int) *Item
- func (l *List) Slice(begin int, end int) Object
- func (l *List) SliceStep(begin int, end int, step int, sliceAll bool) Object
- func (l *List) ToSlice() []Object
- type Object
- func BuiltinComparisonFunction(op string) Object
- func BuiltinConst(scope Scope, arguments []Object) Object
- func BuiltinDef(scope Scope, arguments []Object) Object
- func BuiltinDo(scope Scope, arguments []Object) Object
- func BuiltinFunctionObject(name string, fn BuiltinFunction) Object
- func BuiltinGo(scope Scope, arguments []Object) Object
- func BuiltinIf(scope Scope, args []Object) Object
- func BuiltinLambda(scope Scope, arguments []Object) Object
- func BuiltinMathFunction(op string) Object
- func BuiltinPrintf(scope Scope, arguments []Object) Object
- func BuiltinRequire(scope Scope, args []Object) Object
- func BuiltinSleep(scope Scope, arguments []Object) Object
- func BuiltinSprintf(scope Scope, args []Object) Object
- func BuiltinWhen(scope Scope, args []Object) Object
- func CallFunction(fnobj Object, args List) Object
- func CopyObject(object Object) Object
- func Eval(scope Scope, root STNode) Object
- func EvalArgs(scp Scope, args []Object) []Object
- func EvalMap(glmap Object, arguments List) Object
- func EvalSlice(list Object, arguments List) Object
- func ListObject(slice []string) Object
- func LookupIdentifier(scope Scope, identifier string) Object
- func MapObject(gomap map[string]Object) Object
- func NumberObject(num float64) Object
- func Run(dirname string, filename string, args []string, program string) Object
- func StringObject(str string) Object
- func UndefinedObject() Object
- type ObjectType
- type OperatorType
- type STNode
- type STNodeType
- type Scope
Constants ¶
const ARGS = "__args__"
const DIRNAME = "__dirname__"
const FILENAME = "__filename__"
const UNDEFINED = "undefined"
names of special builtin identifiers
Variables ¶
var Builtins = Scope{}
var LiteralDelimiterTypes = map[string]STNodeType{ "\"": STNodeTypeStringLiteral, "#": STNodeTypeComment, }
var LiteralDelimiters = map[string]string{"\"": "\"", "#": "\n"}
var OperatorTypes = map[string]OperatorType{ "...": OperatorTypeSpread, ":": OperatorTypeZip, ".": OperatorTypeDot, }
var Operators = []string{"...", ":", "."}
var TokenDelimiterTypes = map[string]STNodeType{ "": STNodeTypeScope, "[": STNodeTypeExpression, "{": STNodeTypeList, "(": STNodeTypeMap, }
var TokenDelimiters = map[string]string{
"": "",
"[": "]",
"]": "",
"{": "}",
"}": "",
"(": ")",
")": "",
}
Functions ¶
func InitializeBuiltins ¶
InitializeBuiltins: Initialize the default builtin scope ('Builtins') with builtin identifiers
func RuntimeWaitGroup ¶
func ToNumber ¶
ToNumber: Extract a number from a number object. This function cannot convert non-number objects to numbers `obj`: the number object this function returns a number (as a float64) and an optional error
Types ¶
type BuiltinFunction ¶
type Function ¶
type Function struct { Name string FunctionPatterns [][]STNode FunctionBodies []STNode BuiltinFunc BuiltinFunction }
func CopyFunction ¶
CopyFunction: Copy a Function struct `fn`: the function to copy this function returns a copy of fn
type List ¶
func ListFromSlice ¶
func SpreadNode ¶
SpreadNode: Apply the spread operator to a syntax tree node `scope`: the scope within which the node is being spread `node`: the node to spread this function returns the List of Objects that the node spreads to
type Object ¶
type Object struct { Scope Scope Type ObjectType Function Function Value STNode Elements List Map map[string]Object MapKeys []Object }
func BuiltinComparisonFunction ¶
BuiltinComparisonFunction: This function produces a builtin comparison function for the specified operator `op`: the comparison operator, one of == != > < >= <= this function retuns the produced builtin function
func BuiltinConst ¶
func BuiltinDo ¶
BuiltinDo: The builtin 'do' function. This function evaluates a series of statements within an enclosed, isolated scope this function returns the result of evaluating the final statement in the scope
func BuiltinFunctionObject ¶
func BuiltinFunctionObject(name string, fn BuiltinFunction) Object
BuiltinFunctionObject: Produce a function object from a BuiltinFunction-type function `name`: the name of the function `fn`: the builtin function this function returns the Object containing the builtin function
func BuiltinGo ¶
BuiltinGo: The builtin 'go' function. This function concurrently evaluates a series of statements within an enclosed, isolated scope this function returns UNDEFINED
func BuiltinIf ¶
BuiltinIf: the builtin 'if' function. This function evaluates a predicate and evaluates one of two expressions depending on the result of the predicate the function returns the result of the expression that is evaluated, or UNDEFINED
func BuiltinLambda ¶
BuiltinLambda: The builtin 'lambda' function. This produces a function-type object with one pattern and one expression this function returns the function object that is produced
func BuiltinMathFunction ¶
BuiltinMathFunction: Produce a builtin function for a given math operator `op`: the math operator, one of + - * / % this function returns a Object containing the builtin function for the math operator
func BuiltinPrintf ¶
BuiltinPrintf: The builtin 'printf' function. This function formats a Go-style format string with a set of arguments and writes the result to stdout this function returns the formatted string
func BuiltinRequire ¶
BuiltinRequire: The builtin 'require' function. This function evaluates a file and returns the Object that the file exports.
func BuiltinSleep ¶
BuiltinSleep: the builtin 'sleep' function. This function waits for a specified number of milliseconds this function returns UNDEFINED
func BuiltinSprintf ¶
BuiltinSprintf: The builtin 'sprintf' function. This function formats a Go-style format string with a set of arguments this function returns the formatted string
func BuiltinWhen ¶
BuiltinWhen: the builtin 'when' function. This function takes a set of predicate-body pairs (expressed as zipped expressions), evaluates the predicates one by one and evaluates a 'body' when it reaches a predicate that is true. this function returns the result of the body expression that is evaluated, or UNDEFINED
func CallFunction ¶
CallFunction: call a function object with a list of arguments `fnobj`: the function object `args`: the list of arguments this function returns the result of the function call
func CopyObject ¶
CopyObject: Copy an Object `object`: the object to copy this function returns a copy of object. Note that it does not copy object.Value since that property is never modified
func Eval ¶
Eval: Evaluate a syntax tree node within a scope `scope`: the scope within which to evaluate the node `root`: the root node to evaluate this function returns the result of evaluating the node as an Object
func EvalArgs ¶
EvalArgs: evaluate a list of arguments passed to builtin functions, primarily used to handle spreading `scp`: the scope within which to evaluate the arguments `args`: the arguments to evaluate this function returns the evaluated arguments as a list of Objects
func EvalMap ¶
EvalMap: Lookup key(s) in a map `glmap`: the map object `arguments`: the key or keys to look up this function returns the object or list of objects that the key(s) map to
func EvalSlice ¶
EvalSlice: Evaluate a slice expression, i.e `[list begin end step]` `list`: the list or string that is sliced `arguments`: the arguments passed in the expression this function returns a slice of the list/string or UNDEFINED
func ListObject ¶
ListObject: Produce a list object from a slice of strings. This function cannot produce lists that contain non-string objects `slice`: the slice this function returns the produced Object
func LookupIdentifier ¶
LookupIdentifier: lookup an identifier within a particular scope `scope`: the scope in which to search for the identifier `identifier`: the name of the identifier this function returns the object corresponding to the identifier or UNDEFINED
func MapObject ¶
MapObject: Produce a map object from a map of strings to Objects. This function cannot produce maps that bind numbers to objects `gomap`: the map this function returns the produced Object
func NumberObject ¶
NumberObject: Produce a number object from a number `num`: the number this function returns the produced Object
func Run ¶
Run: Run a Golsp program `program`: the program to run `dirname`: the directory of the program file `filename`: the name of the program file `args`: command line arguments passed to the program this function returns the result of running the program
func StringObject ¶
StringObject: Produce a string object from a string `str`: the string this function returns the produced Object
func UndefinedObject ¶
func UndefinedObject() Object
UndefinedObject: Produce the UNDEFINED identifier object. Used because structs and other data structures are mutable by default and cannot be stored in consts this function returns the UNDEFINED Object
type ObjectType ¶
type ObjectType int
const ( ObjectTypeBuiltinArgument ObjectType = -1 ObjectTypeLiteral ObjectType = 0 ObjectTypeFunction ObjectType = 1 ObjectTypeList ObjectType = 2 ObjectTypeMap ObjectType = 3 )
type OperatorType ¶
type OperatorType int
const ( OperatorTypeSpread OperatorType = 0 OperatorTypeZip OperatorType = 1 OperatorTypeDot OperatorType = 2 )
type STNode ¶
type STNodeType ¶
type STNodeType int
const ( STNodeTypeScope STNodeType = 0 STNodeTypeExpression STNodeType = 1 STNodeTypeStringLiteral STNodeType = 2 STNodeTypeNumberLiteral STNodeType = 3 STNodeTypeList STNodeType = 4 STNodeTypeMap STNodeType = 5 STNodeTypeIdentifier STNodeType = 6 STNodeTypeComment STNodeType = 7 )
type Scope ¶
func IsolateScope ¶
IsolateScope: 'Isolate' a scope object by copying all values from its parent scopes into the scope struct, effectively orphaning it and flattening its inheritance tree `scope`: the scope to isolate this function returns the isolated scope