Documentation
¶
Overview ¶
Environment is a map of string to Object that represents the environment in which an object is evaluated. It also contains a reference to an outer environment, which is used to implement lexical scoping (eg. enables closures)
object package is a collection of types that represent the objects in our language (eg. Integer).
The object package contains the definition of the Object interface, which is implemented by all objects in our language. All object types have a Type method that returns the type of the object, and an Inspect method that returns a string representation of the object. The object package also contains the definition of the ObjectType type, which is a string that represents the type of an object.
Index ¶
Constants ¶
const ( NULL_OBJ = "NULL" ERROR_OBJ = "ERROR" CSV_OBJ = "CSV" CSV_ROW = "CSV_ROW" CSV_VAL = "CSV_VAL" STRING_OBJ = "STRING" INTEGER_OBJ = "INTEGER" BOOLEAN_OBJ = "BOOLEAN" RETURN_VALUE_OBJ = "RETURN_VALUE" FUNCTION_OBJ = "FUNCTION" ARRAY = "ARRAY" BUILTIN_OBJ = "BUILTIN" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Array ¶
type Array struct {
Elements []Object
}
Array struct represents an array object in our language.
func (*Array) Type ¶
func (a *Array) Type() ObjectType
type Boolean ¶
type Boolean struct {
Value bool
}
Bool struct represents a boolean object in our language.
func (*Boolean) Type ¶
func (b *Boolean) Type() ObjectType
type Builtin ¶
type Builtin struct {
Fn BuiltinFunction
}
Built-in functionality to our lang which the host lang (Go) doesn't provide This allows us to add new functions to our language without modifying the host language (eg. fill_empty())
func (*Builtin) Type ¶
func (b *Builtin) Type() ObjectType
type BuiltinFunction ¶
type BuiltinFunction func(env *Environment, args ...Object) Object
type CSV ¶
type CSV struct {
Headers []string
ColumnTypes []ColumnType
Rows []map[string]string
}
CSV struct represents a CSV object in our language.
func (*CSV) InferColumnTypes ¶
func (c *CSV) InferColumnTypes()
InferColumnTypes infers the data types of the columns in the CSV object.
func (*CSV) Type ¶
func (c *CSV) Type() ObjectType
type ColumnType ¶
type ColumnType struct {
Name string
DataType ObjectType // STRING_OBJ or INTEGER_OBJ
}
ColumnType struct stores data type info about columns in a CSV object
func InferType ¶
func InferType(obj Object) ColumnType
TODO: this sticks out in object godoc, see how we want to position this fn
type Environment ¶
type Environment struct {
// contains filtered or unexported fields
}
Environment is a map of string to Object that represents the environment in which an object is evaluated. It also contains a reference to an outer environment, which is used to implement lexical scoping (eg. enables closures)
func NewEnclosedEnvironment ¶
func NewEnclosedEnvironment(outer *Environment) *Environment
NewEnclosedEnvironment creates a new environment with the given outer environment.
func NewEnvironment ¶
func NewEnvironment() *Environment
NewEnvironment creates a new environment without an outer environment.
func (*Environment) Get ¶
func (e *Environment) Get(name string) (Object, bool)
Get retrieves the object with the given name from the environment.
func (*Environment) GetStore ¶
func (e *Environment) GetStore() map[string]Object
GetStore returns the store of the environment.
func (*Environment) Set ¶
func (e *Environment) Set(name string, val Object) Object
Set sets the object with the given name in the environment.
func (*Environment) Unset ¶
func (e *Environment) Unset(name string)
Unset removes the object with the given name from the environment.
type Error ¶
type Error struct {
Message string
}
Error struct represents an error object in our language.
func (*Error) Type ¶
func (e *Error) Type() ObjectType
type Function ¶
type Function struct {
Parameters []*ast.Identifier
Body *ast.BlockStatement
Env *Environment
}
Function struct represents a function object in our language.
func (*Function) Type ¶
func (f *Function) Type() ObjectType
type Integer ¶
type Integer struct {
Value int64
}
Integer struct represents an integer object in our language.
func (*Integer) Type ¶
func (i *Integer) Type() ObjectType
type Null ¶
type Null struct{}
Null struct represents a null object in our language.
func (*Null) Type ¶
func (n *Null) Type() ObjectType
type Object ¶
type Object interface {
Type() ObjectType
Inspect() string
// Add method to attempt conversion to CSV
ToCSV(env *Environment) (*CSV, error)
}
Object interface specifies the methods that all objects in our language must implement.
- Type method returns the type of the object
- Inspect method returns a string representation of the object.
- ToCSV method attempts to convert the object to a CSV object. It is idempotent, meaning it should return the same CSV object if called multiple times.
type ObjectType ¶
type ObjectType string
type ReturnValue ¶
type ReturnValue struct {
Value Object
}
Return struct represents a return value object in our language.
func (*ReturnValue) Inspect ¶
func (rv *ReturnValue) Inspect() string
func (*ReturnValue) ToCSV ¶
func (rv *ReturnValue) ToCSV(env *Environment) (*CSV, error)
func (*ReturnValue) Type ¶
func (rv *ReturnValue) Type() ObjectType