Documentation ¶
Index ¶
- Constants
- Variables
- func Equal(obj1 Object, obj2 Object) bool
- func GenerateEqualityString(o Object) string
- type Array
- type Boolean
- type BreakError
- type Builtin
- type BuiltinFunction
- type ContinueError
- type Environment
- type Error
- type Function
- type Hash
- type HashKey
- type HashPair
- type Hashable
- type Iterable
- type Null
- type Number
- type Object
- type ObjectType
- type ReturnValue
- type String
- func (s *String) HashKey() HashKey
- func (s *String) Inspect() string
- func (s *String) Json() string
- func (s *String) Kill() error
- func (s *String) SetCmdResult(Ok *Boolean)
- func (s *String) SetDone()
- func (s *String) SetRunning()
- func (s *String) Type() ObjectType
- func (s *String) Wait()
- func (s *String) ZeroValue() string
Constants ¶
const ( NULL_OBJ = "NULL" ERROR_OBJ = "ERROR" NUMBER_OBJ = "NUMBER" BOOLEAN_OBJ = "BOOLEAN" STRING_OBJ = "STRING" RETURN_VALUE_OBJ = "RETURN_VALUE" // ANY_OBJ represents any ABS type ANY_OBJ = "ANY" FUNCTION_OBJ = "FUNCTION" BUILTIN_OBJ = "BUILTIN" ARRAY_OBJ = "ARRAY" HASH_OBJ = "HASH" )
Variables ¶
Functions ¶
func GenerateEqualityString ¶
GenerateEqualityString is used to compare 2 objects, for example from different arrays.
This function will generate a string that can be used to compare the 2, including their type and their string representation. Only using their string representation wouldn't work as "1" would be the same as 1.
Types ¶
type Array ¶
type Array struct { Token token.Token Elements []Object // ... is aliased to an array of arguments. // // Since this is a special case of an array, // we need a flag to make sure we know when // to unpack them, else if we do func(...), // func would receive only one array argument // as opposd to the unpacked arguments. IsCurrentArgs bool // contains filtered or unexported fields }
func (*Array) Homogeneous ¶
Homogeneous returns whether the array is homogeneous, meaning all of its elements are of a single type
func (*Array) Type ¶
func (ao *Array) Type() ObjectType
type BreakError ¶
type BreakError struct {
Error
}
type Builtin ¶
type Builtin struct { Token token.Token Fn BuiltinFunction Next func() (Object, Object) Types []string Iterable bool }
func (*Builtin) Type ¶
func (b *Builtin) Type() ObjectType
type BuiltinFunction ¶
type BuiltinFunction func(tok token.Token, env *Environment, args ...Object) Object
type ContinueError ¶
type ContinueError struct {
Error
}
type Environment ¶
type Environment struct { // Arguments this environment was created in. // When we call function(1, 2, 3), a new environment // for the function to execute is created, and 1/2/3 // are recorded as arguments for this environment. // // Later, if we need to access the arguments passed // to the function, we can refer back to them // through env.CurrentArgs. This is how ... is // implemented. CurrentArgs []Object // Used to capture output. This is typically os.Stdout, // but you could capture in any io.Writer of choice Writer io.Writer // Dir represents the directory from which we're executing code. // It starts as the directory from which we invoke the ABS // executable, but changes when we call require("...") as each // require call resets the dir to its own directory, so that // relative imports work. // // If we have script A and B in /tmp, A can require("B") // wihout having to specify its full absolute path // eg. require("/tmp/B") Dir string // Version of the ABS runtime Version string // contains filtered or unexported fields }
Environment represent the environment associated with the execution context of an ABS script: it holds all variables etc.
func NewEnclosedEnvironment ¶
func NewEnclosedEnvironment(outer *Environment, args []Object) *Environment
NewEnclosedEnvironment creates an environment with another one embedded to it, so that the new environment has access to identifiers stored in the outer one.
func NewEnvironment ¶
func NewEnvironment(w io.Writer, dir string, version string) *Environment
NewEnvironment creates a new environment to run ABS in, specifying a writer for the output of the program and the base dir (which is used to require other scripts)
func (*Environment) Delete ¶
func (e *Environment) Delete(name string)
Delete deletes an identifier from the environment
func (*Environment) Get ¶
func (e *Environment) Get(name string) (Object, bool)
Get returns an identifier stored within the environment
func (*Environment) GetKeys ¶
func (e *Environment) GetKeys() []string
GetKeys returns the list of all identifiers stored in this environment
type Error ¶
type Error struct {
Message string
}
func (*Error) Type ¶
func (e *Error) Type() ObjectType
type Function ¶
type Function struct { Token token.Token Name string Parameters []*ast.Parameter Body *ast.BlockStatement Env *Environment Node *ast.FunctionLiteral }
func (*Function) Type ¶
func (f *Function) Type() ObjectType
type Hash ¶
func (*Hash) GetKeyType ¶
func (h *Hash) GetKeyType(k string) ObjectType
GetKeyType returns the type of a given key in the hash. If no key is found, it is considered to be a NULL.
func (*Hash) Next ¶
Pretty convoluted logic here we could refactor. First we sort the hash keys alphabetically and then we loop through them until we reach the required position within the loop.
func (*Hash) Type ¶
func (h *Hash) Type() ObjectType
type Number ¶
func (*Number) Inspect ¶
If the number we're dealing with is an integer, print it as such (1.0000 becomes 1). If it's a float, let's remove as many zeroes as possible (1.10000 becomes 1.1).
func (*Number) Type ¶
func (n *Number) Type() ObjectType
type Object ¶
type Object interface { Type() ObjectType Inspect() string Json() string }
type ObjectType ¶
type ObjectType string
type ReturnValue ¶
func (*ReturnValue) Inspect ¶
func (rv *ReturnValue) Inspect() string
func (*ReturnValue) Json ¶
func (rv *ReturnValue) Json() string
func (*ReturnValue) Type ¶
func (rv *ReturnValue) Type() ObjectType
type String ¶
type String struct { Token token.Token Value string Ok *Boolean // A special property to check whether a command exited correctly Cmd *exec.Cmd // A special property to access the underlying command Stdout *bytes.Buffer Stderr *bytes.Buffer Done *Boolean // contains filtered or unexported fields }
The String is a special fella.
Like ints, or bools, you might think it will only have a Value property, the string itself.
TA-DA! No, we also have an Ok and Done properties that are used when running shell commands -- since the shell will return strings.
So, look at this:
cmd = `ls -la` type(cmd) // STRING cmd.ok // TRUE
cmd = `curlzzzzz` type(cmd) // STRING cmd.ok // FALSE
cmd = `sleep 10 &` type(cmd) // STRING cmd.done // FALSE cmd.wait() // ... cmd.done // TRUE
func (*String) SetCmdResult ¶
Sets the result of the underlying command on the string. 3 things are set: - the string itself (output of the command) - str.ok - str.done
func (*String) SetDone ¶
func (s *String) SetDone()
To be called when the command is done. Releases the internal mutex.
func (*String) SetRunning ¶
func (s *String) SetRunning()
To be called when the command is starting in background, so that anyone accessing it will be blocked.
func (*String) Type ¶
func (s *String) Type() ObjectType