Documentation ¶
Index ¶
- Constants
- Variables
- func Compare(a Sexp, b Sexp) (int, error)
- func DecodeChar(atom string) (string, error)
- func DumpFunction(fun GlispFunction)
- func EscapeChar(char rune) (rune, error)
- func HashCountKeys(hash SexpHash) int
- func HashExpression(expr Sexp) (int, error)
- func HashIsEmpty(hash SexpHash) bool
- func IsArray(expr Sexp) bool
- func IsChar(expr Sexp) bool
- func IsEmpty(expr Sexp) bool
- func IsFloat(expr Sexp) bool
- func IsHash(expr Sexp) bool
- func IsInt(expr Sexp) bool
- func IsList(expr Sexp) bool
- func IsNumber(expr Sexp) bool
- func IsString(expr Sexp) bool
- func IsSymbol(expr Sexp) bool
- func IsTruthy(expr Sexp) bool
- func IsZero(expr Sexp) bool
- func SetHashKeyOrder(hash *SexpHash, keyOrd Sexp) error
- func StringToRunes(str string) []rune
- func Version() string
- type AddScopeInstr
- type Address
- type BindlistInstr
- type BranchInstr
- type CallInstr
- type DataStackElem
- type DispatchInstr
- type DupInstr
- type ExplodeInstr
- type Generator
- func (gen *Generator) AddInstruction(instr Instruction)
- func (gen *Generator) AddInstructions(instr []Instruction)
- func (gen *Generator) Generate(expr Sexp) error
- func (gen *Generator) GenerateAll(expressions []Sexp) error
- func (gen *Generator) GenerateArray(arr SexpArray) error
- func (gen *Generator) GenerateAssert(args []Sexp) error
- func (gen *Generator) GenerateBegin(expressions []Sexp) error
- func (gen *Generator) GenerateCall(expr SexpPair) error
- func (gen *Generator) GenerateCallBySymbol(sym SexpSymbol, args []Sexp) error
- func (gen *Generator) GenerateCond(args []Sexp) error
- func (gen *Generator) GenerateDef(args []Sexp) error
- func (gen *Generator) GenerateDefmac(args []Sexp) error
- func (gen *Generator) GenerateDefn(args []Sexp) error
- func (gen *Generator) GenerateDispatch(fun Sexp, args []Sexp) error
- func (gen *Generator) GenerateFn(args []Sexp) error
- func (gen *Generator) GenerateInclude(args []Sexp) error
- func (gen *Generator) GenerateLet(name string, args []Sexp) error
- func (gen *Generator) GenerateMacexpand(args []Sexp) error
- func (gen *Generator) GenerateQuote(args []Sexp) error
- func (gen *Generator) GenerateShortCircuit(or bool, args []Sexp) error
- func (gen *Generator) GenerateSyntaxQuote(args []Sexp) error
- func (gen *Generator) Reset()
- type GetInstr
- type Glisp
- func (env *Glisp) AddFunction(name string, function GlispUserFunction)
- func (env *Glisp) AddGlobal(name string, obj Sexp)
- func (env *Glisp) AddMacro(name string, function GlispUserFunction)
- func (env *Glisp) AddPostHook(fun PostHook)
- func (env *Glisp) AddPreHook(fun PreHook)
- func (env *Glisp) Apply(fun SexpFunction, args []Sexp) (Sexp, error)
- func (env *Glisp) CallFunction(function SexpFunction, nargs int) error
- func (env *Glisp) CallUserFunction(function SexpFunction, name string, nargs int) error
- func (env *Glisp) Clear()
- func (env *Glisp) Clone() *Glisp
- func (env *Glisp) CurrentFunctionSize() int
- func (env *Glisp) DumpEnvironment()
- func (env *Glisp) DumpFunctionByName(name string) error
- func (env *Glisp) Duplicate() *Glisp
- func (env *Glisp) EvalString(str string) (Sexp, error)
- func (env *Glisp) FindObject(name string) (Sexp, bool)
- func (env *Glisp) GenSymbol(prefix string) SexpSymbol
- func (env *Glisp) GetStackTrace(err error) string
- func (env *Glisp) ImportEval()
- func (env *Glisp) LoadExpressions(expressions []Sexp) error
- func (env *Glisp) LoadFile(file *os.File) error
- func (env *Glisp) LoadStream(stream io.Reader) error
- func (env *Glisp) LoadString(str string) error
- func (env *Glisp) MakeSymbol(name string) SexpSymbol
- func (env *Glisp) ParseFile(file string) ([]Sexp, error)
- func (env *Glisp) ParseStream(in io.Reader) ([]Sexp, error)
- func (env *Glisp) ReachedEnd() bool
- func (env *Glisp) ReturnFromFunction() error
- func (env *Glisp) Run() (Sexp, error)
- func (env *Glisp) SourceExpressions(expressions []Sexp) error
- func (env *Glisp) SourceFile(file *os.File) error
- func (env *Glisp) SourceStream(stream io.Reader) error
- type GlispFunction
- type GlispUserFunction
- type GotoInstr
- type HashizeInstr
- type Instruction
- type IntegerOp
- type JumpInstr
- type Lexer
- type LexerState
- type Loop
- type NumericOp
- type Parser
- type PopInstr
- type PostHook
- type PreHook
- type PushInstr
- type PushInstrClosure
- type PutInstr
- type RemoveScopeInstr
- type ReturnInstr
- type Scope
- type Sexp
- func AppendFunction(env *Glisp, name string, args []Sexp) (Sexp, error)
- func ApplyFunction(env *Glisp, name string, args []Sexp) (Sexp, error)
- func ArrayAccessFunction(env *Glisp, name string, args []Sexp) (Sexp, error)
- func BinaryIntFunction(env *Glisp, name string, args []Sexp) (Sexp, error)
- func BitwiseFunction(env *Glisp, name string, args []Sexp) (Sexp, error)
- func CompareFunction(env *Glisp, name string, args []Sexp) (Sexp, error)
- func ComplementFunction(env *Glisp, name string, args []Sexp) (Sexp, error)
- func ConcatFunction(env *Glisp, name string, args []Sexp) (Sexp, error)
- func ConcatList(a SexpPair, b Sexp) (Sexp, error)
- func ConsFunction(env *Glisp, name string, args []Sexp) (Sexp, error)
- func ConstructorFunction(env *Glisp, name string, args []Sexp) (Sexp, error)
- func EvalFunction(env *Glisp, name string, args []Sexp) (Sexp, error)
- func FirstFunction(env *Glisp, name string, args []Sexp) (Sexp, error)
- func HashAccessFunction(env *Glisp, name string, args []Sexp) (Sexp, error)
- func IntegerDo(op IntegerOp, a, b Sexp) (Sexp, error)
- func LenFunction(env *Glisp, name string, args []Sexp) (Sexp, error)
- func ListToArray(expr Sexp) ([]Sexp, error)
- func MakeArrayFunction(env *Glisp, name string, args []Sexp) (Sexp, error)
- func MakeList(expressions []Sexp) Sexp
- func MapFunction(env *Glisp, name string, args []Sexp) (Sexp, error)
- func MapList(env *Glisp, fun SexpFunction, expr Sexp) (Sexp, error)
- func NotFunction(env *Glisp, name string, args []Sexp) (Sexp, error)
- func NumericDo(op NumericOp, a, b Sexp) (Sexp, error)
- func NumericFloatDo(op NumericOp, a, b SexpFloat) Sexp
- func NumericFunction(env *Glisp, name string, args []Sexp) (Sexp, error)
- func NumericIntDo(op NumericOp, a, b SexpInt) Sexp
- func NumericMatchChar(op NumericOp, a SexpChar, b Sexp) (Sexp, error)
- func NumericMatchFloat(op NumericOp, a SexpFloat, b Sexp) (Sexp, error)
- func NumericMatchInt(op NumericOp, a SexpInt, b Sexp) (Sexp, error)
- func ParseArray(parser *Parser) (Sexp, error)
- func ParseExpression(parser *Parser) (Sexp, error)
- func ParseHash(parser *Parser) (Sexp, error)
- func ParseList(parser *Parser) (Sexp, error)
- func ParseTokens(env *Glisp, lexer *Lexer) ([]Sexp, error)
- func PrintFunction(env *Glisp, name string, args []Sexp) (Sexp, error)
- func ReadFunction(env *Glisp, name string, args []Sexp) (Sexp, error)
- func RestFunction(env *Glisp, name string, args []Sexp) (Sexp, error)
- func SgetFunction(env *Glisp, name string, args []Sexp) (Sexp, error)
- func SliceFunction(env *Glisp, name string, args []Sexp) (Sexp, error)
- func SourceFileFunction(env *Glisp, name string, args []Sexp) (Sexp, error)
- func StringifyFunction(env *Glisp, name string, args []Sexp) (Sexp, error)
- func SymnumFunction(env *Glisp, name string, args []Sexp) (Sexp, error)
- func TypeQueryFunction(env *Glisp, name string, args []Sexp) (Sexp, error)
- type SexpArray
- type SexpBool
- type SexpChar
- type SexpFloat
- type SexpFunction
- type SexpHash
- type SexpInt
- type SexpPair
- type SexpSentinel
- type SexpStackmark
- type SexpStr
- type SexpSymbol
- type SquashInstr
- type Stack
- func (stack *Stack) BindSymbol(sym SexpSymbol, expr Sexp) error
- func (stack *Stack) Clone() *Stack
- func (stack *Stack) Get(n int) (StackElem, error)
- func (stack *Stack) GetExpr(n int) (Sexp, error)
- func (stack *Stack) GetExpressions(n int) ([]Sexp, error)
- func (stack *Stack) IsEmpty() bool
- func (stack *Stack) IsStackElem()
- func (stack *Stack) LookupSymbol(sym SexpSymbol) (Sexp, error)
- func (stack *Stack) LookupSymbolNonGlobal(sym SexpSymbol) (Sexp, error)
- func (stack *Stack) Pop() (StackElem, error)
- func (stack *Stack) PopAddr() (SexpFunction, int, error)
- func (stack *Stack) PopExpr() (Sexp, error)
- func (stack *Stack) PopExpressions(n int) ([]Sexp, error)
- func (stack *Stack) PopScope() error
- func (stack *Stack) PrintStack()
- func (stack *Stack) Push(elem StackElem)
- func (stack *Stack) PushAddr(function SexpFunction, pc int)
- func (stack *Stack) PushAllTo(target *Stack) int
- func (stack *Stack) PushExpr(expr Sexp)
- func (stack *Stack) PushScope()
- func (stack *Stack) Top() int
- type StackElem
- type Token
- type TokenType
- type VectorizeInstr
Constants ¶
View Source
const CallStackSize = 25
View Source
const DataStackSize = 100
View Source
const ScopeStackSize = 50
View Source
const SliceDefaultCap = 10
View Source
const StackStackSize = 5
Variables ¶
View Source
var ( BoolRegex = regexp.MustCompile("^(true|false)$") DecimalRegex = regexp.MustCompile("^-?[0-9]+$") HexRegex = regexp.MustCompile("^0x[0-9a-fA-F]+$") OctRegex = regexp.MustCompile("^0o[0-7]+$") BinaryRegex = regexp.MustCompile("^0b[01]+$") SymbolRegex = regexp.MustCompile("^[^'#]+$") CharRegex = regexp.MustCompile("^#\\\\?.$") FloatRegex = regexp.MustCompile("^-?([0-9]+\\.[0-9]*)|(\\.[0-9]+)|([0-9]+(\\.[0-9]*)?[eE](-?[0-9]+))$") )
View Source
var BuiltinFunctions = map[string]GlispUserFunction{ "<": CompareFunction, ">": CompareFunction, "<=": CompareFunction, ">=": CompareFunction, "=": CompareFunction, "not=": CompareFunction, "sll": BinaryIntFunction, "sra": BinaryIntFunction, "srl": BinaryIntFunction, "mod": BinaryIntFunction, "+": NumericFunction, "-": NumericFunction, "*": NumericFunction, "/": NumericFunction, "bit-and": BitwiseFunction, "bit-or": BitwiseFunction, "bit-xor": BitwiseFunction, "bit-not": ComplementFunction, "read": ReadFunction, "cons": ConsFunction, "first": FirstFunction, "rest": RestFunction, "car": FirstFunction, "cdr": RestFunction, "list?": TypeQueryFunction, "null?": TypeQueryFunction, "array?": TypeQueryFunction, "hash?": TypeQueryFunction, "number?": TypeQueryFunction, "int?": TypeQueryFunction, "float?": TypeQueryFunction, "char?": TypeQueryFunction, "symbol?": TypeQueryFunction, "string?": TypeQueryFunction, "zero?": TypeQueryFunction, "empty?": TypeQueryFunction, "println": PrintFunction, "print": PrintFunction, "not": NotFunction, "apply": ApplyFunction, "map": MapFunction, "make-array": MakeArrayFunction, "aget": ArrayAccessFunction, "aset!": ArrayAccessFunction, "sget": SgetFunction, "hget": HashAccessFunction, "hset!": HashAccessFunction, "hdel!": HashAccessFunction, "slice": SliceFunction, "len": LenFunction, "append": AppendFunction, "concat": ConcatFunction, "array": ConstructorFunction, "list": ConstructorFunction, "hash": ConstructorFunction, "symnum": SymnumFunction, "str": StringifyFunction, }
View Source
var MissingFunction = SexpFunction{"__missing", true, 0, false, nil, nil, nil}
View Source
var NotAList = errors.New("not a list")
View Source
var OutOfBounds error = errors.New("jump out of bounds")
View Source
var SexpFloatSize = reflect.TypeOf(SexpFloat(0.0)).Bits()
View Source
var SexpIntSize = reflect.TypeOf(SexpInt(0)).Bits()
View Source
var UnexpectedEnd error = errors.New("Unexpected end of input")
View Source
var WrongNargs error = errors.New("wrong number of arguments")
View Source
var WrongType error = errors.New("operands have invalid type")
Functions ¶
func DecodeChar ¶
func DumpFunction ¶
func DumpFunction(fun GlispFunction)
func EscapeChar ¶
func HashCountKeys ¶
func HashExpression ¶
func HashIsEmpty ¶
func SetHashKeyOrder ¶
func StringToRunes ¶
Types ¶
type AddScopeInstr ¶
type AddScopeInstr int
func (AddScopeInstr) Execute ¶
func (a AddScopeInstr) Execute(env *Glisp) error
func (AddScopeInstr) InstrString ¶
func (a AddScopeInstr) InstrString() string
type Address ¶
type Address struct {
// contains filtered or unexported fields
}
func (Address) IsStackElem ¶
func (a Address) IsStackElem()
type BindlistInstr ¶
type BindlistInstr struct {
// contains filtered or unexported fields
}
bind these symbols to the SexpPair list found at datastack top.
func (BindlistInstr) Execute ¶
func (b BindlistInstr) Execute(env *Glisp) error
func (BindlistInstr) InstrString ¶
func (b BindlistInstr) InstrString() string
type BranchInstr ¶
type BranchInstr struct {
// contains filtered or unexported fields
}
func (BranchInstr) Execute ¶
func (b BranchInstr) Execute(env *Glisp) error
func (BranchInstr) InstrString ¶
func (b BranchInstr) InstrString() string
type CallInstr ¶
type CallInstr struct {
// contains filtered or unexported fields
}
func (CallInstr) InstrString ¶
type DataStackElem ¶
type DataStackElem struct {
// contains filtered or unexported fields
}
func (DataStackElem) IsStackElem ¶
func (d DataStackElem) IsStackElem()
type DispatchInstr ¶
type DispatchInstr struct {
// contains filtered or unexported fields
}
func (DispatchInstr) Execute ¶
func (d DispatchInstr) Execute(env *Glisp) error
func (DispatchInstr) InstrString ¶
func (d DispatchInstr) InstrString() string
type ExplodeInstr ¶
type ExplodeInstr int
func (ExplodeInstr) Execute ¶
func (e ExplodeInstr) Execute(env *Glisp) error
func (ExplodeInstr) InstrString ¶
func (e ExplodeInstr) InstrString() string
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
func NewGenerator ¶
func (*Generator) AddInstruction ¶
func (gen *Generator) AddInstruction(instr Instruction)
func (*Generator) AddInstructions ¶
func (gen *Generator) AddInstructions(instr []Instruction)
func (*Generator) GenerateAll ¶
func (*Generator) GenerateArray ¶
func (*Generator) GenerateAssert ¶
func (*Generator) GenerateBegin ¶
func (*Generator) GenerateCall ¶
func (*Generator) GenerateCallBySymbol ¶
func (gen *Generator) GenerateCallBySymbol(sym SexpSymbol, args []Sexp) error
func (*Generator) GenerateCond ¶
func (*Generator) GenerateDef ¶
func (*Generator) GenerateDefmac ¶
func (*Generator) GenerateDefn ¶
func (*Generator) GenerateDispatch ¶
func (*Generator) GenerateFn ¶
func (*Generator) GenerateInclude ¶
func (*Generator) GenerateMacexpand ¶
func (*Generator) GenerateQuote ¶
func (*Generator) GenerateShortCircuit ¶
func (*Generator) GenerateSyntaxQuote ¶
side-effect (or main effect) has to be pushing an expression on the top of the datastack that represents the expanded and substituted expression
type GetInstr ¶
type GetInstr struct {
// contains filtered or unexported fields
}
func (GetInstr) InstrString ¶
type Glisp ¶
type Glisp struct {
// contains filtered or unexported fields
}
func (*Glisp) AddFunction ¶
func (env *Glisp) AddFunction(name string, function GlispUserFunction)
func (*Glisp) AddMacro ¶
func (env *Glisp) AddMacro(name string, function GlispUserFunction)
func (*Glisp) AddPostHook ¶
func (*Glisp) AddPreHook ¶
func (*Glisp) CallFunction ¶
func (env *Glisp) CallFunction(function SexpFunction, nargs int) error
func (*Glisp) CallUserFunction ¶
func (env *Glisp) CallUserFunction( function SexpFunction, name string, nargs int) error
func (*Glisp) CurrentFunctionSize ¶
func (*Glisp) DumpEnvironment ¶
func (env *Glisp) DumpEnvironment()
func (*Glisp) DumpFunctionByName ¶
func (*Glisp) GenSymbol ¶
func (env *Glisp) GenSymbol(prefix string) SexpSymbol
func (*Glisp) GetStackTrace ¶
func (*Glisp) ImportEval ¶
func (env *Glisp) ImportEval()
func (*Glisp) LoadExpressions ¶
func (*Glisp) LoadStream ¶
LoadStream, load this in via running a __main function and setting main on the environment
func (*Glisp) LoadString ¶
func (*Glisp) MakeSymbol ¶
func (env *Glisp) MakeSymbol(name string) SexpSymbol
func (*Glisp) ParseFile ¶
ParseFile, used in the generator at read time to dynamiclly add more defs from other files
func (*Glisp) ReachedEnd ¶
func (*Glisp) ReturnFromFunction ¶
func (*Glisp) SourceExpressions ¶
type GlispFunction ¶
type GlispFunction []Instruction
type GotoInstr ¶
type GotoInstr struct {
// contains filtered or unexported fields
}
func (GotoInstr) InstrString ¶
type HashizeInstr ¶
func (HashizeInstr) Execute ¶
func (s HashizeInstr) Execute(env *Glisp) error
func (HashizeInstr) InstrString ¶
func (s HashizeInstr) InstrString() string
type Instruction ¶
type JumpInstr ¶
type JumpInstr struct {
// contains filtered or unexported fields
}
func (JumpInstr) InstrString ¶
type Lexer ¶
type Lexer struct {
// contains filtered or unexported fields
}
func NewLexerFromStream ¶
func NewLexerFromStream(stream io.RuneReader) *Lexer
func (*Lexer) GetNextToken ¶
func (*Lexer) LexNextRune ¶
func (*Lexer) PeekNextToken ¶
type LexerState ¶
type LexerState int
const ( LexerNormal LexerState = iota LexerComment LexerStrLit LexerStrEscaped LexerUnquote )
type Loop ¶
type Loop struct {
// contains filtered or unexported fields
}
func (*Loop) IsStackElem ¶
func (loop *Loop) IsStackElem()
type PushInstr ¶
type PushInstr struct {
// contains filtered or unexported fields
}
func (PushInstr) InstrString ¶
type PushInstrClosure ¶
type PushInstrClosure struct {
// contains filtered or unexported fields
}
func (PushInstrClosure) Execute ¶
func (p PushInstrClosure) Execute(env *Glisp) error
func (PushInstrClosure) InstrString ¶
func (p PushInstrClosure) InstrString() string
type PutInstr ¶
type PutInstr struct {
// contains filtered or unexported fields
}
func (PutInstr) InstrString ¶
type RemoveScopeInstr ¶
type RemoveScopeInstr int
func (RemoveScopeInstr) Execute ¶
func (a RemoveScopeInstr) Execute(env *Glisp) error
func (RemoveScopeInstr) InstrString ¶
func (a RemoveScopeInstr) InstrString() string
type ReturnInstr ¶
type ReturnInstr struct {
// contains filtered or unexported fields
}
func (ReturnInstr) Execute ¶
func (r ReturnInstr) Execute(env *Glisp) error
func (ReturnInstr) InstrString ¶
func (r ReturnInstr) InstrString() string
type Sexp ¶
type Sexp interface {
SexpString() string
}
func ArrayAccessFunction ¶
func ComplementFunction ¶
func ConstructorFunction ¶
func HashAccessFunction ¶
func ListToArray ¶
func NumericFloatDo ¶
func NumericIntDo ¶
func ParseArray ¶
func ParseExpression ¶
func SourceFileFunction ¶
type SexpFunction ¶
type SexpFunction struct {
// contains filtered or unexported fields
}
func MakeFunction ¶
func MakeFunction(name string, nargs int, varargs bool, fun GlispFunction) SexpFunction
func MakeUserFunction ¶
func MakeUserFunction(name string, ufun GlispUserFunction) SexpFunction
func (SexpFunction) SexpString ¶
func (sf SexpFunction) SexpString() string
type SexpHash ¶
type SexpHash struct { TypeName *string Map map[int][]SexpPair KeyOrder *[]Sexp // must user pointers here, else hset! will fail to update. GoStruct *interface{} NumKeys *int }
func (*SexpHash) HashDelete ¶
func (*SexpHash) HashGetDefault ¶
func (SexpHash) SexpString ¶
type SexpPair ¶
type SexpPair struct {
// contains filtered or unexported fields
}
func (SexpPair) SexpString ¶
type SexpSentinel ¶
type SexpSentinel int
const ( SexpNull SexpSentinel = iota SexpEnd SexpMarker )
func (SexpSentinel) SexpString ¶
func (sent SexpSentinel) SexpString() string
type SexpStackmark ¶
type SexpStackmark struct {
// contains filtered or unexported fields
}
func (SexpStackmark) SexpString ¶
func (mark SexpStackmark) SexpString() string
type SexpSymbol ¶
type SexpSymbol struct {
// contains filtered or unexported fields
}
func (SexpSymbol) Name ¶
func (sym SexpSymbol) Name() string
func (SexpSymbol) Number ¶
func (sym SexpSymbol) Number() int
func (SexpSymbol) SexpString ¶
func (sym SexpSymbol) SexpString() string
type SquashInstr ¶
type SquashInstr int
func (SquashInstr) Execute ¶
func (s SquashInstr) Execute(env *Glisp) error
func (SquashInstr) InstrString ¶
func (s SquashInstr) InstrString() string
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
func (*Stack) BindSymbol ¶
func (stack *Stack) BindSymbol(sym SexpSymbol, expr Sexp) error
func (*Stack) IsStackElem ¶
func (stack *Stack) IsStackElem()
func (*Stack) LookupSymbol ¶
func (stack *Stack) LookupSymbol(sym SexpSymbol) (Sexp, error)
func (*Stack) LookupSymbolNonGlobal ¶
func (stack *Stack) LookupSymbolNonGlobal(sym SexpSymbol) (Sexp, error)
LookupSymbolNonGlobal - closures use this to only find symbols below the global scope, to avoid copying globals it'll always be-able to ref
func (*Stack) PrintStack ¶
func (stack *Stack) PrintStack()
func (*Stack) PushAddr ¶
func (stack *Stack) PushAddr(function SexpFunction, pc int)
type Token ¶
type Token struct {
// contains filtered or unexported fields
}
func DecodeAtom ¶
func DecodeBrace ¶
type VectorizeInstr ¶
type VectorizeInstr int
func (VectorizeInstr) Execute ¶
func (s VectorizeInstr) Execute(env *Glisp) error
func (VectorizeInstr) InstrString ¶
func (s VectorizeInstr) InstrString() string
Click to show internal directories.
Click to hide internal directories.