vile

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2021 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AnyType = Intern("<any>")

AnyType is a pseudo type specifier indicating any type

View Source
var Apply = &Object{Type: FunctionType}

Apply is a primitive instruction to apply a function to a list of arguments

View Source
var ArgumentErrorKey = Intern("argument-error:")

ArgumentErrorKey

View Source
var BooleanType = Intern("<boolean>")

BooleanType is the type of true and false

View Source
var CallCC = &Object{Type: FunctionType}

CallCC is a primitive instruction to executable (restore) a continuation

View Source
var CallSymbol = Intern("call")
View Source
var CharacterType = Intern("<character>")

CharacterType is the type of all characters

View Source
var ClosureSymbol = Intern("closure")
View Source
var CodeType = Intern("<code>")

CodeType is the type of compiled code

View Source
var DefglobalSymbol = Intern("defglobal")
View Source
var DefmacroSymbol = Intern("macro")
View Source
var EmptyList = initEmpty()

EmptyList - the value of (), terminates linked lists

View Source
var EmptyString = String("")

EmptyString

View Source
var EmptyStruct = MakeStruct(0)

EmptyStruct - a <struct> with no bindings

View Source
var ErrorKey = Intern("error:")

ErrorKey - used to generic errors

View Source
var ErrorType = Intern("<error>")

ErrorType is the type of all errors

View Source
var False = &Object{Type: BooleanType, fval: 0}

False is the singleton boolean false value

View Source
var FuncSymbol = Intern("func")
View Source
var FunctionType = Intern("<function>")

FunctionType is the type of all functions

View Source
var GlobalSymbol = Intern("global")
View Source
var HTTPErrorKey = Intern("http-error:")

HttpErrorKey

View Source
var IOErrorKey = Intern("io-error:")

IOErrorKey

View Source
var ImportSymbol = Intern("import")
View Source
var InterruptKey = Intern("interrupt:")

InterruptKey

View Source
var JumpSymbol = Intern("jump")
View Source
var JumpfalseSymbol = Intern("jumpfalse")
View Source
var ListType = Intern("<list>")

ListType is the type of all lists

View Source
var LiteralSymbol = Intern("literal")
View Source
var LocalSymbol = Intern("local")
View Source
var MacroErrorKey = Intern("macro-error:")

MacroErrorKey

View Source
var MinusOne = Number(-1)

MinusOne is the Vile -1 value

View Source
var Null = &Object{Type: NullType}

Null is Vile's version of nil. It means "nothing" and is not the same as EmptyList. It is a singleton.

View Source
var NullType = Intern("<null>")

NullType the type of the null object

View Source
var NumberType = Intern("<number>")

NumberType is the type of all numbers

View Source
var One = Number(1)

One is the Vile 1 value

View Source
var PopSymbol = Intern("pop")
View Source
var QuasiquoteSymbol = Intern("quasiquote")
View Source
var QuoteSymbol = Intern("quote")
View Source
var ReturnSymbol = Intern("return")
View Source
var SetlocalSymbol = Intern("setlocal")
View Source
var Spawn = &Object{Type: FunctionType}

Apply is a primitive instruction to apply a function to a list of arguments

View Source
var StringType = Intern("<string>")

StringType is the type of all strings

View Source
var StructSymbol = Intern("struct")
View Source
var StructType = Intern("<struct>")

VectorType is the type of all structs

View Source
var SyntaxErrorKey = Intern("syntax-error:")

SyntaxErrorKey

View Source
var TailcallSymbol = Intern("tailcall")
View Source
var True = &Object{Type: BooleanType, fval: 1}

True is the singleton boolean true value

View Source
var UndefineSymbol = Intern("undefine")
View Source
var UnquoteSymbol = Intern("unquote")
View Source
var UnquoteSymbolSplicing = Intern("unquote-splicing")
View Source
var VectorSymbol = Intern("vector")
View Source
var VectorType = Intern("<vector>")

VectorType is the type of all vectors

View Source
var Version = "(development version)"

Version - this version of vole

View Source
var Zero = Number(0)

Zero is the Vile 0 value

Functions

func AddVileDirectory

func AddVileDirectory(dirname string)

func AsByteValue

func AsByteValue(obj *Object) (byte, error)

func AsFloat64Value

func AsFloat64Value(obj *Object) (float64, error)

func AsInt64Value

func AsInt64Value(obj *Object) (int64, error)

func AsIntValue

func AsIntValue(obj *Object) (int, error)

func AsRuneValue

func AsRuneValue(c *Object) (rune, error)

AsCharacter - return the native rune representation of the character object, if possible

func AsStringValue

func AsStringValue(obj *Object) (string, error)

AsStringValue - return the native string representation of the object, if possible

func BoolValue

func BoolValue(obj *Object) bool

BoolValue - return native bool value of the object

func Cleanup

func Cleanup()

func DefineFunction

func DefineFunction(name string, fun PrimitiveFunction, result *Object, args ...*Object)

Register a primitive function to the specified global name

func DefineFunctionKeyArgs

func DefineFunctionKeyArgs(name string, fun PrimitiveFunction, result *Object, args []*Object, defaults []*Object, keys []*Object)

Register a primitive function with keyword arguments to the specified global name

func DefineFunctionOptionalArgs

func DefineFunctionOptionalArgs(name string, fun PrimitiveFunction, result *Object, args []*Object, defaults ...*Object)

Register a primitive function with optional arguments to the specified global name

func DefineFunctionRestArgs

func DefineFunctionRestArgs(name string, fun PrimitiveFunction, result *Object, rest *Object, args ...*Object)

Register a primitive function with Rest arguments to the specified global name

func DefineGlobal

func DefineGlobal(name string, obj *Object)

Bind the value to the global name

func DefineMacro

func DefineMacro(name string, fun PrimitiveFunction)

Register a primitive macro with the specified name.

func EncodeString

func EncodeString(s string) string

EncodeString - return the encoded form of a string value

func Equal

func Equal(o1 *Object, o2 *Object) bool

func Error

func Error(errkey *Object, args ...interface{}) error

Error - creates a new Error from the arguments. The first is an actual Vile keyword object, the rest are interpreted as/converted to strings

func ExpandFilePath

func ExpandFilePath(path string) string

func Fatal

func Fatal(args ...interface{})

func FindModuleByName

func FindModuleByName(moduleName string) (string, error)

func FindModuleFile

func FindModuleFile(name string) (string, error)

func Float64Value

func Float64Value(obj *Object) float64

Float64Value - return native float64 value of the object

func GetMacro

func GetMacro(sym *Object) *macro

GetMacro - return the macro for the symbol, or nil if not defined

func Has

func Has(obj *Object, key *Object) (bool, error)

func Identical

func Identical(o1 *Object, o2 *Object) bool

Identical - return if two objects are identical

func Import

func Import(sym *Object) error

func Init

func Init(extns ...Extension)

func InitPrimitives

func InitPrimitives()

func Int64Value

func Int64Value(obj *Object) int64

Int64Value - return native int64 value of the object

func IntValue

func IntValue(obj *Object) int

IntValue - return native int value of the object

func IsBoolean

func IsBoolean(obj *Object) bool

func IsCharacter

func IsCharacter(obj *Object) bool

func IsCode

func IsCode(obj *Object) bool

func IsDefined

func IsDefined(sym *Object) bool

IsDefined - return true if the there is a global value defined for the symbol

func IsDirectoryReadable

func IsDirectoryReadable(path string) bool

IsDirectoryReadable - return true of the directory is readable

func IsError

func IsError(o interface{}) bool

func IsFileReadable

func IsFileReadable(path string) bool

IsFileReadable - return true of the file is readable

func IsFloat

func IsFloat(obj *Object) bool

func IsFunction

func IsFunction(obj *Object) bool

func IsInstance

func IsInstance(obj *Object) bool

instances have arbitrary Type symbols, all we can check is that the instanceValue is set

func IsInt

func IsInt(obj *Object) bool

func IsKeyword

func IsKeyword(obj *Object) bool

func IsList

func IsList(obj *Object) bool

func IsNull

func IsNull(obj *Object) bool

func IsNumber

func IsNumber(obj *Object) bool

func IsPrimitiveType

func IsPrimitiveType(tag *Object) bool

func IsString

func IsString(obj *Object) bool

func IsStruct

func IsStruct(obj *Object) bool

func IsSymbol

func IsSymbol(obj *Object) bool

func IsType

func IsType(obj *Object) bool

func IsValidKeywordName

func IsValidKeywordName(s string) bool

func IsValidStructKey

func IsValidStructKey(o *Object) bool

IsValidStructKey - return true of the object is a valid <struct> key.

func IsValidSymbolName

func IsValidSymbolName(name string) bool

func IsValidTypeName

func IsValidTypeName(s string) bool

func IsVector

func IsVector(obj *Object) bool

func ListEqual

func ListEqual(lst *Object, a *Object) bool

ListEqual returns true if the object is equal to the argument

func ListLength

func ListLength(lst *Object) int

func Load

func Load(name string) error

func LoadFile

func LoadFile(file string) error

func Macro

func Macro(name *Object, expander *Object) *macro

Macro - create a new Macro

func Main

func Main(extns ...Extension)

func NumberEqual

func NumberEqual(f1 float64, f2 float64) bool

Equal returns true if the object is equal to the argument, within epsilon

func Pretty

func Pretty(obj *Object) string

func PrettyAll

func PrettyAll(obj *Object) string

func Print

func Print(args ...interface{})

func Println

func Println(args ...interface{})

func Put

func Put(obj *Object, key *Object, val *Object)

func RandomSeed

func RandomSeed(n int64)

func ReadEvalPrintLoop

func ReadEvalPrintLoop()

func Round

func Round(f float64) float64

Round - return the closest integer value to the float value

func Run

func Run(args ...string)

func RunStringEval

func RunStringEval(vileCode string) error

func RuneValue

func RuneValue(obj *Object) rune

RuneValue - return native rune value of the object

func SetFlags

func SetFlags(o bool, v bool, d bool, t bool, i bool)

SetFlags - set various flags controlling the runtime

func SpitFile

func SpitFile(path string, data string) error

SpitFile - write the string to the file.

func StringLength

func StringLength(s string) int

StringLength - return the string length

func StringValue

func StringValue(obj *Object) string

StringValue - return native string value of the object

func StructEqual

func StructEqual(s1 *Object, s2 *Object) bool

Equal returns true if the object is equal to the argument

func StructLength

func StructLength(strct *Object) int

StructLength - return the length (field count) of the <struct> object

func Unput

func Unput(obj *Object, key *Object)

func VM

func VM(stackSize int) *vm

func VectorEqual

func VectorEqual(v1 *Object, v2 *Object) bool

VectorEqual - return true of the two vectors are equal, i.e. the same length and all the elements are also equal

func Write

func Write(obj *Object) string

func WriteAll

func WriteAll(obj *Object) string

Types

type Code

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

Code - compiled Vile bytecode

func (*Code) String

func (code *Code) String() string

type Extension

type Extension interface {
	Init() error
	Cleanup()
	String() string
}

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 is the Vile object: a union of all possible primitive types. Which fields are used depends on the variant the variant is a type object i.e. Intern("<string>"). For arbitrary embedded extension types, the Value field is an interface{}. It is used for Channels internally, but is generally useful for app-specific native types when extending Vile.

var KeywordType *Object // bootstrapped in initSymbolTable => Intern("<keyword>")

KeywordType is the type of all keywords

var SymbolType *Object // bootstrapped in initSymbolTable = Intern("<symbol>")

SymbolType is the type of all symbols

var TypeType *Object // bootstrapped in initSymbolTable => Intern("<type>")

TypeType is the metatype, the type of all types | Wikipedia => "... kind (a type of a type, or metatype) ..."

func Caar

func Caar(lst *Object) *Object

Caar - return the Car of the Car of the list

func Cadar

func Cadar(lst *Object) *Object

Cadar - return the Car of the Cdr of the Car of the list

func Cadddr

func Cadddr(lst *Object) *Object

Cadddr - return the Car of the Cdr of the Cdr of the Cdr of the list

func Caddr

func Caddr(lst *Object) *Object

Caddr - return the Car of the Cdr of the Cdr of the list

func Cadr

func Cadr(lst *Object) *Object

Cadr - return the Car of the Cdr of the list

func Car

func Car(lst *Object) *Object

Car - return the first object in a list

func Cdar

func Cdar(lst *Object) *Object

Cdar - return the Cdr of the Car of the list

func Cddddr

func Cddddr(lst *Object) *Object

Cddddr - return the Cdr of the Cdr of the Cdr of the Cdr of the list

func Cdddr

func Cdddr(lst *Object) *Object

Cdddr - return the Cdr of the Cdr of the Cdr of the list

func Cddr

func Cddr(lst *Object) *Object

Cddr - return the Cdr of the Cdr of the list

func Cdr

func Cdr(lst *Object) *Object

Cdr - return the rest of the list

func Character

func Character(c rune) *Object

Character - return a new <character> object

func Closure

func Closure(code *Code, frame *frame) *Object

func Compile

func Compile(expr *Object) (*Object, error)

Compile - compile the source into a code object

func CompileFile

func CompileFile(name string) (*Object, error)

caveats: when you compile a file, you actually run it. This is so we can handle imports and macros correctly.

func Concat

func Concat(seq1 *Object, seq2 *Object) (*Object, error)

func Cons

func Cons(car *Object, cdr *Object) *Object

Cons - create a new list consisting of the first object and the rest of the list

func Continuation

func Continuation(frame *frame, ops []int, pc int, stack []*Object) *Object

func CopyVector

func CopyVector(vec *Object) *Object

CopyVector - return a copy of the <vector>

func ErrorData

func ErrorData(err *Object) *Object

func Eval

func Eval(expr *Object) (*Object, error)

func Flatten

func Flatten(lst *Object) *Object

func Get

func Get(obj *Object, key *Object) (*Object, error)

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

func GetGlobal(sym *Object) *Object

GetGlobal - return the global value for the specified symbol, or nil if the symbol is not defined.

func GetKeywords

func GetKeywords() []*Object

GetKeywords - return a slice of Vile primitive reserved words Vile keywords e.g: ("fn" main(n1 n2) (+ n1 n2))

func Globals

func Globals() []*Object

Globals - return a slice of all defined global symbols

func Instance

func Instance(tag *Object, val *Object) (*Object, error)

func Int

func Int(n int64) *Object

func Intern

func Intern(name string) *Object

Intern - internalize the name into the global symbol table

func KeywordName

func KeywordName(t *Object) (*Object, error)

<keyword> -> <symbol>

func List

func List(values ...*Object) *Object

func ListFromValues

func ListFromValues(values []*Object) *Object

func Macroexpand

func Macroexpand(expr *Object) (*Object, error)

Macroexpand - return the expansion of all macros in the object and return the result

func Macros

func Macros() []*Object

Macros - return a slice of all defined macros

func MakeCode

func MakeCode(argc int, defaults []*Object, keys []*Object, name string) *Object

MakeCode - create a new code object

func MakeError

func MakeError(elements ...*Object) *Object

func MakeList

func MakeList(count int, val *Object) *Object

func MakeStruct

func MakeStruct(capacity int) *Object

MakeStruct - create an empty <struct> object with the specified capacity

func MakeVector

func MakeVector(size int, init *Object) *Object

MakeVector - create a new <vector> object of the specified size, with all elements initialized to the specified value

func NewObject

func NewObject(variant *Object, value interface{}) *Object

NewObject is the constructor for externally defined objects, where the value is an interface{}.

func Number

func Number(f float64) *Object

Number - create a Number object for the given value

func Primitive

func Primitive(name string, fun PrimitiveFunction, result *Object, args []*Object, rest *Object, defaults []*Object, keys []*Object) *Object

used in module.go - five places

func Random

func Random(min float64, max float64) *Object

func RandomList

func RandomList(size int, min float64, max float64) *Object

func Read

func Read(input *Object, keys *Object) (*Object, error)

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 ReadAll

func ReadAll(input *Object, keys *Object) (*Object, error)

ReadAll - read all items in the input, returning a list of them.

func Reverse

func Reverse(lst *Object) *Object

func SlurpFile

func SlurpFile(path string) (*Object, error)

SlurpFile - return the file contents as a string

func String

func String(s string) *Object

String - create a new string object

func StringCharacters

func StringCharacters(s *Object) []*Object

StringCharacters - return a slice of <character> objects that represent the string

func StringJoin

func StringJoin(seq *Object, delims *Object) (*Object, error)

func StringRef

func StringRef(s *Object, idx int) *Object

StringRef - return the <character> object at the specified string index

func StringSplit

func StringSplit(obj *Object, delims *Object) (*Object, error)

func Struct

func Struct(fieldvals []*Object) (*Object, error)

Struct - create a new <struct> object from the arguments, which can be other structs, or key/value pairs

func StructKeys

func StructKeys(s *Object) *Object

func StructValues

func StructValues(s *Object) *Object

func Symbol

func Symbol(names []*Object) (*Object, error)

func Symbols

func Symbols() []*Object

unknowns

func ToCharacter

func ToCharacter(c *Object) (*Object, error)

ToCharacter - convert object to a <character> object, if possible

func ToInt

func ToInt(o *Object) (*Object, error)

ToInt - convert the object to an integer number, if possible

func ToKeyword

func ToKeyword(obj *Object) (*Object, error)

func ToList

func ToList(obj *Object) (*Object, error)

ToList - convert the argument to a List, if possible

func ToNumber

func ToNumber(o *Object) (*Object, error)

ToNumber - convert object to a number, if possible

func ToString

func ToString(a *Object) (*Object, error)

ToString - convert the object to a string, if possible

func ToStruct

func ToStruct(obj *Object) (*Object, error)

func ToSymbol

func ToSymbol(obj *Object) (*Object, error)

func ToVector

func ToVector(obj *Object) (*Object, error)

ToVector - convert the object to a <vector>, if possible

func TypeName

func TypeName(t *Object) (*Object, error)

<type> -> <symbol>

func Value

func Value(obj *Object) *Object

func Vector

func Vector(elements ...*Object) *Object

Vector - create a new <vector> object from the given element objects.

func VectorFromElements

func VectorFromElements(elements []*Object, count int) *Object

VectorFromElements - return a new <vector> object from the given slice of elements. The slice is copied.

func VectorFromElementsNoCopy

func VectorFromElementsNoCopy(elements []*Object) *Object

VectorFromElementsNoCopy - create a new <vector> object from the given slice of elements. The slice is NOT copied.

func (*Object) Error

func (lob *Object) Error() string

Error

func (*Object) String

func (lob *Object) String() string

type PrimitiveFunction

type PrimitiveFunction func(argv []*Object) (*Object, error)

PrimitiveFunction is the native go function signature for all Vile primitive functions

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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