Documentation ¶
Index ¶
- Constants
- Variables
- func ArrayEqual(v1 *Object, v2 *Object) bool
- func AsByteValue(obj *Object) (byte, error)
- func AsFloat64Value(obj *Object) (float64, error)
- func AsInt64Value(obj *Object) (int64, error)
- func AsIntValue(obj *Object) (int, error)
- func AsRuneValue(c *Object) (rune, error)
- func AsStringValue(obj *Object) (string, error)
- func BlobValue(obj *Object) []byte
- func BoolValue(obj *Object) bool
- func ChannelValue(obj *Object) chan *Object
- func CloseChannel(obj *Object)
- func EncodeString(s string) string
- func Equal(o1 *Object, o2 *Object) bool
- func Error(errkey *Object, args ...interface{}) error
- func ExpandFilePath(path string) string
- func ExpandPath(filename string) (string, error)
- func Fatal(args ...interface{})
- func FindModuleByName(moduleName string) (string, error)
- func FindModuleFile(name string) (string, error)
- func Float64Value(obj *Object) float64
- func Has(obj *Object, key *Object) (bool, error)
- func Identical(o1 *Object, o2 *Object) bool
- func Init()
- func Int64Value(obj *Object) int64
- func IntValue(obj *Object) int
- func IsArray(obj *Object) bool
- func IsBoolean(obj *Object) bool
- func IsCharacter(obj *Object) bool
- func IsCode(obj *Object) bool
- func IsDefined(sym *Object) bool
- func IsDirectoryReadable(path string) bool
- func IsError(o interface{}) bool
- func IsFileReadable(path string) bool
- func IsFloat(obj *Object) bool
- func IsFunction(obj *Object) bool
- func IsInstance(obj *Object) bool
- func IsInt(obj *Object) bool
- func IsKeyword(obj *Object) bool
- func IsList(obj *Object) bool
- func IsNull(obj *Object) bool
- func IsNumber(obj *Object) bool
- func IsPrimitiveType(tag *Object) bool
- func IsString(obj *Object) bool
- func IsStruct(obj *Object) bool
- func IsSymbol(obj *Object) bool
- func IsType(obj *Object) bool
- func IsValidKeywordName(s string) bool
- func IsValidStructKey(o *Object) bool
- func IsValidSymbolName(name string) bool
- func IsValidTypeName(s string) bool
- func ListEqual(lst *Object, a *Object) bool
- func ListLength(lst *Object) int
- func Now() float64
- func NumberEqual(f1 float64, f2 float64) bool
- func Pretty(obj *Object) string
- func PrettyAll(obj *Object) string
- func Print(args ...interface{})
- func Println(args ...interface{})
- func Put(obj *Object, key *Object, val *Object)
- func REPL(vm *VM) error
- func RandomSeed(n int64)
- func Round(f float64) float64
- func RuneValue(obj *Object) rune
- func Sleep(delayInSeconds float64)
- func SpitFile(path string, data string) error
- func StringLength(s string) int
- func StringValue(obj *Object) string
- func StructEqual(s1 *Object, s2 *Object) bool
- func StructLength(strct *Object) int
- func Unput(obj *Object, key *Object)
- func Write(obj *Object) string
- func WriteAll(obj *Object) string
- type Code
- type Extension
- type Flags
- type Macro
- type Object
- func Array(elements ...*Object) *Object
- func ArrayFromElements(elements []*Object, count int) *Object
- func ArrayFromElementsNoCopy(elements []*Object) *Object
- func Blob(bytes []byte) *Object
- func Caar(lst *Object) *Object
- func Cadar(lst *Object) *Object
- func Cadddr(lst *Object) *Object
- func Caddr(lst *Object) *Object
- func Cadr(lst *Object) *Object
- func Car(lst *Object) *Object
- func Cdar(lst *Object) *Object
- func Cddddr(lst *Object) *Object
- func Cdddr(lst *Object) *Object
- func Cddr(lst *Object) *Object
- func Cdr(lst *Object) *Object
- func Channel(bufsize int, name string) *Object
- func Character(c rune) *Object
- func Closure(code *Code, frame *frame) *Object
- func Concat(seq1 *Object, seq2 *Object) (*Object, error)
- func Cons(car *Object, cdr *Object) *Object
- func Continuation(frame *frame, ops []int, pc int, stack []*Object) *Object
- func CopyArray(a *Object) *Object
- func ErrorData(err *Object) *Object
- func Flatten(lst *Object) *Object
- func Get(obj *Object, key *Object) (*Object, error)
- func GetGlobal(sym *Object) *Object
- func Instance(tag *Object, val *Object) (*Object, error)
- func Int(n int64) *Object
- func List(values ...*Object) *Object
- func ListFromValues(values []*Object) *Object
- func MakeArray(size int, init *Object) *Object
- func MakeBlob(size int) *Object
- func MakeCode(vm *VM, argc int, defaults []*Object, keys []*Object, name string) *Object
- func MakeError(elements ...*Object) *Object
- func MakeList(count int, val *Object) *Object
- func MakeStruct(capacity int) *Object
- func NewObject(variant *Object, value interface{}) *Object
- func Number(f float64) *Object
- func Primitive(name string, fun PrimitiveFunction, result *Object, args []*Object, ...) *Object
- func Random(min float64, max float64) *Object
- func RandomList(size int, min float64, max float64) *Object
- func Reverse(lst *Object) *Object
- func SlurpFile(path string) (*Object, error)
- func String(s string) *Object
- func StringCharacters(s *Object) []*Object
- func StringJoin(seq *Object, delims *Object) (*Object, error)
- func StringRef(s *Object, idx int) *Object
- func StringSplit(obj *Object, delims *Object) (*Object, error)
- func Struct(fieldvals []*Object) (*Object, error)
- func StructKeys(s *Object) *Object
- func StructValues(s *Object) *Object
- func Timestamp(t time.Time) *Object
- func ToArray(obj *Object) (*Object, error)
- func ToBlob(obj *Object) (*Object, error)
- func ToCharacter(c *Object) (*Object, error)
- func ToInt(o *Object) (*Object, error)
- func ToList(obj *Object) (*Object, error)
- func ToNumber(o *Object) (*Object, error)
- func ToString(a *Object) (*Object, error)
- func ToStruct(obj *Object) (*Object, error)
- func Value(obj *Object) *Object
- type PrimitiveFunction
- type VM
- func (vm *VM) AddVesperDirectory(dirname string)
- func (vm *VM) Compile(expr *Object) (*Object, error)
- func (vm *VM) CompileFile(name string) (*Object, error)
- func (vm *VM) DefineFunction(name string, fun PrimitiveFunction, result *Object, args ...*Object)
- func (vm *VM) DefineFunctionKeyArgs(name string, fun PrimitiveFunction, result *Object, args []*Object, ...)
- func (vm *VM) DefineFunctionOptionalArgs(name string, fun PrimitiveFunction, result *Object, args []*Object, ...)
- func (vm *VM) DefineFunctionRestArgs(name string, fun PrimitiveFunction, result *Object, rest *Object, ...)
- func (vm *VM) DefineGlobal(name string, obj *Object)
- func (vm *VM) DefineMacro(name string, fun PrimitiveFunction)
- func (vm *VM) Eval(expr *Object) (*Object, error)
- func (vm *VM) Execute(code *Code, args []*Object) (*Object, error)
- func (vm *VM) GetKeywords() []*Object
- func (vm *VM) GetMacro(sym *Object) *Macro
- func (vm *VM) Globals() []*Object
- func (vm *VM) Init(extns ...Extension) *VM
- func (vm *VM) InitPrimitives()
- func (vm *VM) Intern(name string) *Object
- func (vm *VM) KeywordName(t *Object) (*Object, error)
- func (vm *VM) Load(name string) error
- func (vm *VM) LoadFile(file string) error
- func (vm *VM) Macroexpand(expr *Object) (*Object, error)
- func (vm *VM) Macros() []*Object
- func (vm *VM) Read(input *Object, keys *Object) (*Object, error)
- func (vm *VM) ReadAll(input *Object, keys *Object) (*Object, error)
- func (vm *VM) Run(args ...string)
- func (vm *VM) SetFlags(v bool, d bool, i bool)
- func (vm *VM) Symbol(names []*Object) (*Object, error)
- func (vm *VM) ToKeyword(obj *Object) (*Object, error)
- func (vm *VM) ToSymbol(obj *Object) (*Object, error)
- func (vm *VM) TypeName(t *Object) (*Object, error)
- func (vm *VM) Use(sym *Object) error
Constants ¶
const Version = "vesper v0.1"
Version - this version of vesper
Variables ¶
var ( // BooleanType is the type of true and false BooleanType = defaultVM.Intern("<boolean>") // True is the singleton boolean true value True = &Object{Type: BooleanType, fval: 1} // False is the singleton boolean false value False = &Object{Type: BooleanType, fval: 0} )
var ( // ErrorKey - used for generic errors ErrorKey = defaultVM.Intern("error:") // ArgumentErrorKey used for argument errors ArgumentErrorKey = defaultVM.Intern("argument-error:") // SyntaxErrorKey used for syntax errors SyntaxErrorKey = defaultVM.Intern("syntax-error:") // MacroErrorKey used for macro errors MacroErrorKey = defaultVM.Intern("macro-error:") // IOErrorKey used for IO errors IOErrorKey = defaultVM.Intern("io-error:") // InterruptKey used for interrupts that were captured InterruptKey = defaultVM.Intern("interrupt:") // InternalErrorKey used for internal errors InternalErrorKey = defaultVM.Intern("internal-error:") )
var ( // GenfnsSymbol used to define generic Function GenfnsSymbol = defaultVM.Intern("*genfns*") // MethodsKeyword used to define methods MethodsKeyword = defaultVM.Intern("methods:") )
var ( // TypeType is the metatype, the type of all types TypeType *Object // bootstrapped in initSymbolTable => Intern("<type>") // KeywordType is the type of all keywords KeywordType *Object // bootstrapped in initSymbolTable => Intern("<keyword>") // SymbolType is the type of all symbols SymbolType *Object // bootstrapped in initSymbolTable = Intern("<symbol>") // StringType is the type of all strings StringType *Object // bootstrapped in initSymbolTable = Intern("<string>") // CharacterType is the type of all characters CharacterType = defaultVM.Intern("<character>") // NumberType is the type of all numbers NumberType = defaultVM.Intern("<number>") // BlobType is the type of all bytearrays BlobType = defaultVM.Intern("<blob>") // ListType is the type of all lists ListType = defaultVM.Intern("<list>") // ArrayType is the type of all arrays ArrayType = defaultVM.Intern("<array>") // StructType is the type of all structs StructType = defaultVM.Intern("<struct>") // FunctionType is the type of all functions FunctionType = defaultVM.Intern("<function>") // CodeType is the type of compiled code CodeType = defaultVM.Intern("<code>") // ErrorType is the type of all errors ErrorType = defaultVM.Intern("<error>") // AnyType is a pseudo type specifier indicating any type AnyType = defaultVM.Intern("<any>") )
var ( // NoneSymbol represents a nil operation NoneSymbol = defaultVM.Intern("none") // LiteralSymbol represents a bytecode for a literal LiteralSymbol = defaultVM.Intern("literal") // LocalSymbol represents bytecode for a local variable LocalSymbol = defaultVM.Intern("local") // JumpfalseSymbol represents a jump on false JumpfalseSymbol = defaultVM.Intern("jumpfalse") // JumpSymbol represents an unconditional jump JumpSymbol = defaultVM.Intern("jump") // TailcallSymbol represents a tailcall operation TailcallSymbol = defaultVM.Intern("tailcall") // CallSymbol represents a function call CallSymbol = defaultVM.Intern("call") // ReturnSymbol represents a return from the current function ReturnSymbol = defaultVM.Intern("return") // ClosureSymbol represents the creation of a closure ClosureSymbol = defaultVM.Intern("closure") // PopSymbol represents the pop operation PopSymbol = defaultVM.Intern("pop") // GlobalSymbol represents a reference to a global GlobalSymbol = defaultVM.Intern("global") // DefglobalSymbol represents the definition of a global symbol DefglobalSymbol = defaultVM.Intern("defglobal") // SetlocalSymbol represents setting a local varioble SetlocalSymbol = defaultVM.Intern("setlocal") // UseSymbol represents the "use" of a module UseSymbol = defaultVM.Intern("use") // DefmacroSymbol represents a macro definition DefmacroSymbol = defaultVM.Intern("defmacro") // ArraySymbol represents the creation of a literal array ArraySymbol = defaultVM.Intern("array") // StructSymbol represents creation of a literal struct StructSymbol = defaultVM.Intern("struct") // UndefineSymbol represents an undefine operation UndefineSymbol = defaultVM.Intern("undefine") // FuncSymbol represents a function definition FuncSymbol = defaultVM.Intern("func") )
var Apply = &Object{Type: FunctionType}
Apply is a primitive instruction to apply a function to a list of arguments
var CallCC = &Object{Type: FunctionType}
CallCC is a primitive instruction to executable (restore) a continuation
var ChannelType = defaultVM.Intern("<channel>")
ChannelType - the type of Vesper's channel object
var EmptyBlob = MakeBlob(0)
EmptyBlob - a blob with no bytes
var EmptyList = initEmpty()
EmptyList - the value of (), terminates linked lists
var EmptyString = String("")
EmptyString an empty string
var EmptyStruct = MakeStruct(0)
EmptyStruct - a <struct> with no bindings
var GoFunc = &Object{Type: FunctionType}
GoFunc is a primitive instruction to create a goroutine
var MinusOne = Number(-1)
MinusOne is the Vesper -1 value
var Null = &Object{Type: NullType}
Null is a singleton representing nothing. It is distinct from an empty list.
var NullType = defaultVM.Intern("<null>")
NullType the type of the null object
var One = Number(1)
One is the Vesper 1 value
var QuasiquoteSymbol = defaultVM.Intern("quasiquote")
QuasiquoteSymbol represents a quasiquoted expression
var QuoteSymbol = defaultVM.Intern("quote")
QuoteSymbol represents a quoted expression
var UnquoteSplicingSymbol = defaultVM.Intern("unquote-splicing")
UnquoteSplicingSymbol represents an unquote-splicing expression
var UnquoteSymbol = defaultVM.Intern("unquote")
UnquoteSymbol represents an unquoted expression
var Zero = Number(0)
Zero is the Vesper 0 value
Functions ¶
func ArrayEqual ¶
ArrayEqual - return true of the two arrays are equal, i.e. the same length and all the elements are also equal
func AsByteValue ¶
AsByteValue returns the value of the object as a byte
func AsFloat64Value ¶
AsFloat64Value returns the floating point value of the object
func AsInt64Value ¶
AsInt64Value returns the int64 value of the object
func AsIntValue ¶
AsIntValue returns the int value of the object
func AsRuneValue ¶
AsRuneValue - return the native rune representation of the character object, if possible
func AsStringValue ¶
AsStringValue - return the native string representation of the object, if possible
func ChannelValue ¶
ChannelValue - return the Go channel object for the Vesper channel
func EncodeString ¶
EncodeString - return the encoded form of a string value
func Error ¶
Error creates a new Error from the arguments. The first is an actual Vesper keyword object, the rest are interpreted as/converted to strings
func ExpandFilePath ¶
ExpandFilePath returns the absolute path of a file or directory
func ExpandPath ¶
ExpandPath returns the absolute path including
func FindModuleByName ¶
FindModuleByName returns the file filename of a vesper module
func FindModuleFile ¶
FindModuleFile finds a readable module file or errors
func Float64Value ¶
Float64Value - return native float64 value of the object
func Has ¶
Has returns whether the struct has the given key. Returns an error if the object is not a struct.
func Int64Value ¶
Int64Value - return native int64 value of the object
func IsCharacter ¶
IsCharacter returns true if the object is a character
func IsDirectoryReadable ¶
IsDirectoryReadable - return true of the directory is readable
func IsFileReadable ¶
IsFileReadable - return true of the file is readable
func IsFunction ¶
IsFunction returns true if the object is a function
func IsInstance ¶
IsInstance returns true if the object is an instance. Since instances have arbitrary Type symbols, all we can check is that the car value is set
func IsPrimitiveType ¶
IsPrimitiveType returns true if the object is a primitive
func IsValidKeywordName ¶
IsValidKeywordName returns true if the string is a keyword
func IsValidStructKey ¶
IsValidStructKey - return true of the object is a valid <struct> key.
func IsValidSymbolName ¶
IsValidSymbolName returns true if the string is a valid symbol
func IsValidTypeName ¶
IsValidTypeName returns true if the string is a typename
func NumberEqual ¶
NumberEqual returns true if the object is equal to the argument, within epsilon
func RandomSeed ¶
func RandomSeed(n int64)
RandomSeed seeds the random number generator with the given seed value
func StringValue ¶
StringValue - return native string value of the object
func StructEqual ¶
StructEqual returns true if the object is equal to the argument
func StructLength ¶
StructLength - return the length (field count) of the <struct> object
Types ¶
type Code ¶
type Code struct {
// contains filtered or unexported fields
}
Code - compiled Vesper bytecode
type Object ¶
type Object struct { Type *Object // i.e. <string> Value interface{} // the rest of the data for more complex things // contains filtered or unexported fields }
Object represents all objects in Vesper
func ArrayFromElements ¶
ArrayFromElements - return a new <array> object from the given slice of elements. The slice is copied.
func ArrayFromElementsNoCopy ¶
ArrayFromElementsNoCopy - create a new <array> object from the given slice of elements. The slice is NOT copied.
func Blob ¶
Blob - create a new blob, using the specified byte slice as the data. The data is not copied.
func Continuation ¶
Continuation creates a continuation object
func Get ¶
Get - return the value for the key of the object. The Value() function is first called to handle typed instances of <struct>. This is called by the VM, when a keyword is used as a function.
func GetGlobal ¶
GetGlobal - return the global value for the specified symbol, or nil if the symbol is not defined.
func ListFromValues ¶
ListFromValues creates a list from the given array
func MakeArray ¶
MakeArray - create a new <array> object of the specified size, with all elements initialized to the specified value
func MakeBlob ¶
MakeBlob - create a new blob of the given size. It will be initialized to all zeroes
func MakeStruct ¶
MakeStruct - create an empty <struct> object with the specified capacity
func NewObject ¶
NewObject is the constructor for externally defined objects, where the value is an interface{}.
func Primitive ¶
func Primitive(name string, fun PrimitiveFunction, result *Object, args []*Object, rest *Object, defaults []*Object, keys []*Object) *Object
Primitive creates a primitive function
func RandomList ¶
RandomList returns a list of random numbers with the given size and range
func StringCharacters ¶
StringCharacters - return a slice of <character> objects that represent the string
func StringJoin ¶
StringJoin joins a string with the given delimters
func StringSplit ¶
StringSplit splits a string by the delimiters
func Struct ¶
Struct - create a new <struct> object from the arguments, which can be other structs, or key/value pairs
func StructValues ¶
StructValues returns a list of the values of the struct
func ToCharacter ¶
ToCharacter - convert object to a <character> object, if possible
type PrimitiveFunction ¶
PrimitiveFunction is the native go function signature for all Vesper primitive functions
type VM ¶
type VM struct { StackSize int Symbols map[string]*Object MacroMap map[*Object]*Macro ConstantsMap map[*Object]int Constants []*Object Extensions []Extension Flags Flags }
VM - the Vesper VM
func (*VM) AddVesperDirectory ¶
AddVesperDirectory adds a directory to the load path
func (*VM) CompileFile ¶
CompileFile compiles a file and returns a String object or an error caveats: when you compile a file, you actually run it. This is so we can handle imports and macros correctly.
func (*VM) DefineFunction ¶
func (vm *VM) DefineFunction(name string, fun PrimitiveFunction, result *Object, args ...*Object)
DefineFunction registers a primitive function to the specified global name
func (*VM) DefineFunctionKeyArgs ¶
func (vm *VM) DefineFunctionKeyArgs(name string, fun PrimitiveFunction, result *Object, args []*Object, defaults []*Object, keys []*Object)
DefineFunctionKeyArgs registers a primitive function with keyword arguments to the specified global name
func (*VM) DefineFunctionOptionalArgs ¶
func (vm *VM) DefineFunctionOptionalArgs(name string, fun PrimitiveFunction, result *Object, args []*Object, defaults ...*Object)
DefineFunctionOptionalArgs registers a primitive function with optional arguments to the specified global name
func (*VM) DefineFunctionRestArgs ¶
func (vm *VM) DefineFunctionRestArgs(name string, fun PrimitiveFunction, result *Object, rest *Object, args ...*Object)
DefineFunctionRestArgs registers a primitive function with Rest arguments to the specified global name
func (*VM) DefineGlobal ¶
DefineGlobal binds the value to the global name
func (*VM) DefineMacro ¶
func (vm *VM) DefineMacro(name string, fun PrimitiveFunction)
DefineMacro registers a primitive macro with the specified name.
func (*VM) GetKeywords ¶
GetKeywords - return a slice of Vesper primitive reserved words
func (*VM) InitPrimitives ¶
func (vm *VM) InitPrimitives()
InitPrimitives defines the global functions/variables/macros for the top level environment
func (*VM) KeywordName ¶
KeywordName returns the keyword as a string
func (*VM) Macroexpand ¶
Macroexpand - return the expansion of all macros in the object and return the result
func (*VM) Read ¶
Read - only reads the first item in the input, along with how many characters it read for subsequence calls, you can slice the string to continue
func (*VM) ToSymbol ¶
ToSymbol converts the object to a symbol, or returns an error if the object cannot be converted.