glisp

package module
v0.0.0-...-fe623b8 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: BSD-2-Clause Imports: 20 Imported by: 0

README

GLisp

Image text

This is a LISP dialect designed as an embedded extension language for the Go programming language. It is implemented in pure Go, so it can be easily ported to all systems and architectures that Go targets.

Here is a list of what features are implemented and not implemented so far.

  • Float, Int, Char, String, Bytes, Symbol, List, Array, and Hash datatypes
  • Arithmetic (+, -, *, /, mod)
  • Shift Operators (sla, sra)
  • Big integer
  • Bitwise operations (bit-and, bit-or, bit-xor)
  • Comparison operations (<, >, <=, >=, =, and not=)
  • Short-circuit boolean operators (and and or)
  • Conditionals (cond)
  • A Basic Repl
  • Lambdas (fn)
  • Bindings (def, defn, and let)
  • Tail-call optimization
  • Go API
  • Macro System
  • Syntax quoting (backticks)
  • Channel and goroutine support

The full documentation can be found in the Wiki.

Documentation

Index

Constants

View Source
const CallStackSize = 25
View Source
const DataStackSize = 100
View Source
const Many = -1
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]+$")
	BinaryStreamRegex = regexp.MustCompile("^0B[0-9a-z]+$")
	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 Float64EqualityThreshold = 1e-10
View Source
var MissingFunction = &SexpFunction{
	name:    "__missing",
	user:    true,
	nargs:   0,
	varargs: false,
	fun:     nil,
}
View Source
var OutOfBounds error = errors.New("jump out of bounds")
View Source
var UnexpectedEnd error = errors.New("Unexpected end of input")
View Source
var WrongType error = errors.New("operands have invalid type")

Functions

func BuiltinFunctions

func BuiltinFunctions() map[string]UserFunction

func Compare

func Compare(a Sexp, b Sexp) (int, error)

func DecodeChar

func DecodeChar(atom string) (string, error)

func DumpFunction

func DumpFunction(w io.Writer, fun Function)

func EscapeChar

func EscapeChar(char rune) (rune, error)

func HashCountKeys

func HashCountKeys(hash *SexpHash) (int, error)

func HashExpression

func HashExpression(expr Sexp) (int, error)

func HashIsEmpty

func HashIsEmpty(hash *SexpHash) bool

func InspectType

func InspectType(expr Sexp) string

func IsArray

func IsArray(expr Sexp) bool

func IsBool

func IsBool(expr Sexp) bool

func IsBytes

func IsBytes(expr Sexp) bool

func IsChar

func IsChar(expr Sexp) bool

func IsEmpty

func IsEmpty(expr Sexp) bool

func IsFloat

func IsFloat(expr Sexp) bool

func IsFunction

func IsFunction(expr Sexp) bool

func IsHash

func IsHash(expr Sexp) bool

func IsIType

func IsIType(s Sexp) bool

func IsInt

func IsInt(expr Sexp) bool

func IsList

func IsList(expr Sexp) bool

func IsNumber

func IsNumber(expr Sexp) bool

func IsString

func IsString(expr Sexp) bool

func IsSymbol

func IsSymbol(expr Sexp) bool

func IsTruthy

func IsTruthy(expr Sexp) bool

func IsZero

func IsZero(expr Sexp) bool

func Marshal

func Marshal(a Sexp) ([]byte, error)

func ParseDoc

func ParseDoc(docstr string) map[string]string

func QueryBuiltinDoc

func QueryBuiltinDoc(funcName string) string

func StringToRunes

func StringToRunes(str string) []rune

func WrongGeneratorNumberArguments

func WrongGeneratorNumberArguments(funcname string, current int, expect ...int) error

Types

type AddScopeInstr

type AddScopeInstr int

func (AddScopeInstr) Execute

func (a AddScopeInstr) Execute(env *Environment) 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 BindDynFunInstr

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

func (BindDynFunInstr) Execute

func (p BindDynFunInstr) Execute(env *Environment) error

func (BindDynFunInstr) InstrString

func (p BindDynFunInstr) InstrString() string

type BindlistInstr

type BindlistInstr struct{}

func (BindlistInstr) Execute

func (b BindlistInstr) Execute(env *Environment) 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 *Environment) error

func (BranchInstr) InstrString

func (b BranchInstr) InstrString() string

type CallInstr

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

func (CallInstr) Execute

func (c CallInstr) Execute(env *Environment) error

func (CallInstr) InstrString

func (c CallInstr) InstrString() string

type Clonable

type Clonable interface {
	StackElem
	Clone() StackElem
}

type Comparable

type Comparable interface {
	Sexp
	// Cmp compares x and y and returns:
	//
	//   -1 if x <  y
	//    0 if x == y
	//   +1 if x >  y
	//
	Cmp(Comparable) (int, error)
}

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 *Environment) error

func (DispatchInstr) InstrString

func (d DispatchInstr) InstrString() string

type DupInstr

type DupInstr int

func (DupInstr) Execute

func (d DupInstr) Execute(env *Environment) error

func (DupInstr) InstrString

func (d DupInstr) InstrString() string

type Environment

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

func New

func New() *Environment

func (*Environment) AddFunction

func (env *Environment) AddFunction(name string, function UserFunction, opts ...FuntionOption)

func (*Environment) AddFuzzyMacro

func (env *Environment) AddFuzzyMacro(name string, function UserFunction, opts ...FuntionOption)

func (*Environment) AddMacro

func (env *Environment) AddMacro(name string, function UserFunction, opts ...FuntionOption)

func (*Environment) AddNamedFunction

func (env *Environment) AddNamedFunction(name string, function NamedUserFunction, opts ...FuntionOption)

func (*Environment) Apply

func (env *Environment) Apply(fun *SexpFunction, args []Sexp) (Sexp, error)

func (*Environment) ApplyByName

func (env *Environment) ApplyByName(fun string, args []Sexp) (Sexp, error)

func (*Environment) Bind

func (env *Environment) Bind(name string, expr Sexp) error

func (*Environment) BindGlobal

func (env *Environment) BindGlobal(name string, expr Sexp) error

func (*Environment) CallFunction

func (env *Environment) CallFunction(function *SexpFunction, nargs int) error

func (*Environment) CallUserFunction

func (env *Environment) CallUserFunction(function *SexpFunction, name string, nargs int) error

func (*Environment) Clear

func (env *Environment) Clear()

func (*Environment) Clone

func (env *Environment) Clone() *Environment

func (*Environment) CurrentFunctionSize

func (env *Environment) CurrentFunctionSize() int

func (*Environment) DumpEnvironment

func (env *Environment) DumpEnvironment(w io.Writer)

func (*Environment) DumpFunctionByName

func (env *Environment) DumpFunctionByName(w io.Writer, name string) error

func (*Environment) Duplicate

func (env *Environment) Duplicate() *Environment

func (*Environment) EvalString

func (env *Environment) EvalString(str string) (Sexp, error)

func (*Environment) FindMacro

func (env *Environment) FindMacro(name string) (*SexpFunction, bool)

func (*Environment) FindObject

func (env *Environment) FindObject(name string) (Sexp, bool)

func (*Environment) GenSymbol

func (env *Environment) GenSymbol(optionalPrefix ...string) SexpSymbol

func (*Environment) GetStackTrace

func (env *Environment) GetStackTrace(err error) string

func (*Environment) GlobalFunctions

func (env *Environment) GlobalFunctions() []string

func (*Environment) ImportEval

func (env *Environment) ImportEval() error

func (*Environment) LoadExpressions

func (env *Environment) LoadExpressions(expressions []Sexp) error

func (*Environment) LoadFile

func (env *Environment) LoadFile(file *os.File) error

func (*Environment) LoadStream

func (env *Environment) LoadStream(stream io.Reader) error

LoadStream, load this in via running a __main function and setting main on the environment

func (*Environment) LoadString

func (env *Environment) LoadString(str string) error

func (*Environment) MakeScriptFunction

func (env *Environment) MakeScriptFunction(script string) (*SexpFunction, error)

func (*Environment) MakeSymbol

func (env *Environment) MakeSymbol(name string) SexpSymbol

func (*Environment) OverrideFunction

func (env *Environment) OverrideFunction(name string, f OverrideFunction, opts ...FuntionOption) error

func (*Environment) ParseFile

func (env *Environment) ParseFile(file string) ([]Sexp, error)

ParseFile, used in the generator at read time to dynamiclly add more defs from other files

func (*Environment) ParseStream

func (env *Environment) ParseStream(in io.Reader) ([]Sexp, error)

func (*Environment) PopGlobalScope

func (env *Environment) PopGlobalScope() error

func (*Environment) PushGlobalScope

func (env *Environment) PushGlobalScope() error

func (*Environment) ReachedEnd

func (env *Environment) ReachedEnd() bool

func (*Environment) ReturnFromFunction

func (env *Environment) ReturnFromFunction() error

func (*Environment) Run

func (env *Environment) Run() (Sexp, error)

func (*Environment) SetFileReader

func (env *Environment) SetFileReader(fr FileReader)

func (*Environment) SourceExpressions

func (env *Environment) SourceExpressions(expressions []Sexp) error

func (*Environment) SourceStream

func (env *Environment) SourceStream(stream io.Reader) error

SourceStream, load this in via a __source dynamic function, after it runs it no longer exists

type ExplodeInstr

type ExplodeInstr int

func (ExplodeInstr) Execute

func (e ExplodeInstr) Execute(env *Environment) error

func (ExplodeInstr) InstrString

func (e ExplodeInstr) InstrString() string

type FileReader

type FileReader interface {
	Open(file string) (io.ReadCloser, error)
}

func DefaultFileReader

func DefaultFileReader() FileReader

type FuncMap

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

func NewFuncMap

func NewFuncMap() *FuncMap

func (*FuncMap) Add

func (fm *FuncMap) Add(sym SexpSymbol, f *SexpFunction)

func (*FuncMap) Clone

func (fm *FuncMap) Clone() *FuncMap

func (*FuncMap) Find

func (fm *FuncMap) Find(sym SexpSymbol) (*SexpFunction, bool)

func (*FuncMap) Names

func (fm *FuncMap) Names() (ret []string)

type Function

type Function []Instruction

type FuntionOption

type FuntionOption func(*SexpFunction)

func WithDoc

func WithDoc(doc string) FuntionOption

type Generator

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

func NewGenerator

func NewGenerator(env *Environment) *Generator

func (*Generator) AddInstruction

func (gen *Generator) AddInstruction(instr Instruction)

func (*Generator) AddInstructions

func (gen *Generator) AddInstructions(instr []Instruction)

func (*Generator) Generate

func (gen *Generator) Generate(expr Sexp) error

func (*Generator) GenerateAll

func (gen *Generator) GenerateAll(expressions []Sexp) error

func (*Generator) GenerateArray

func (gen *Generator) GenerateArray(arr SexpArray) error

func (*Generator) GenerateAssert

func (gen *Generator) GenerateAssert(args []Sexp) error

func (*Generator) GenerateBegin

func (gen *Generator) GenerateBegin(expressions []Sexp) error

func (*Generator) GenerateCall

func (gen *Generator) GenerateCall(expr *SexpPair) error

func (*Generator) GenerateCallBySymbol

func (gen *Generator) GenerateCallBySymbol(sym SexpSymbol, args []Sexp) error

func (*Generator) GenerateCond

func (gen *Generator) GenerateCond(args []Sexp) error

func (*Generator) GenerateDef

func (gen *Generator) GenerateDef(args []Sexp, isSet bool) error

func (*Generator) GenerateDefmac

func (gen *Generator) GenerateDefmac(args []Sexp) error

func (*Generator) GenerateDefn

func (gen *Generator) GenerateDefn(args []Sexp) error

func (*Generator) GenerateDispatch

func (gen *Generator) GenerateDispatch(fun Sexp, args []Sexp) error

func (*Generator) GenerateFn

func (gen *Generator) GenerateFn(args []Sexp) error

func (*Generator) GenerateInclude

func (gen *Generator) GenerateInclude(args []Sexp) error

func (*Generator) GenerateLet

func (gen *Generator) GenerateLet(name string, args []Sexp) error

func (*Generator) GenerateMacexpand

func (gen *Generator) GenerateMacexpand(args []Sexp) error

func (*Generator) GenerateQuote

func (gen *Generator) GenerateQuote(args []Sexp) error

func (*Generator) GenerateSharpQuote

func (gen *Generator) GenerateSharpQuote(args []Sexp) error

func (*Generator) GenerateShortCircuit

func (gen *Generator) GenerateShortCircuit(or bool, args []Sexp) error

func (*Generator) GenerateSyntaxQuote

func (gen *Generator) GenerateSyntaxQuote(args []Sexp) error

side-effect (or main effect) has to be pushing an expression on the top of the datastack that represents the expanded and substituted expression

func (*Generator) Reset

func (gen *Generator) Reset()

type GetInstr

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

func (GetInstr) Execute

func (g GetInstr) Execute(env *Environment) error

func (GetInstr) InstrString

func (g GetInstr) InstrString() string

type GotoInstr

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

func (GotoInstr) Execute

func (g GotoInstr) Execute(env *Environment) error

func (GotoInstr) InstrString

func (g GotoInstr) InstrString() string

type HashizeInstr

type HashizeInstr struct {
	HashLen int
}

func (HashizeInstr) Execute

func (s HashizeInstr) Execute(env *Environment) error

func (HashizeInstr) InstrString

func (s HashizeInstr) InstrString() string

type ITypeName

type ITypeName interface {
	TypeName() string
}

type Instruction

type Instruction interface {
	InstrString() string
	Execute(env *Environment) error
}

type JumpInstr

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

func (JumpInstr) Execute

func (j JumpInstr) Execute(env *Environment) error

func (JumpInstr) InstrString

func (j JumpInstr) InstrString() string

type Lexer

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

func NewLexerFromStream

func NewLexerFromStream(stream io.RuneReader) *Lexer

func (*Lexer) CurLine

func (lexer *Lexer) CurLine() string

func (*Lexer) GetNextToken

func (lexer *Lexer) GetNextToken() (Token, error)

func (*Lexer) LexNextRune

func (lexer *Lexer) LexNextRune(r rune) error

func (*Lexer) LineOffset

func (lexer *Lexer) LineOffset() int

func (*Lexer) Linenum

func (lexer *Lexer) Linenum() int

func (*Lexer) PeekNextToken

func (lexer *Lexer) PeekNextToken() (Token, error)

type LexerState

type LexerState int
const (
	LexerNormal LexerState = iota
	LexerComment
	LexerStrLit
	LexerRawStrLit
	LexerStrEscaped
	LexerUnquote
	LexerSharp
)

type ListBuilder

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

func NewListBuilder

func NewListBuilder() *ListBuilder

func (*ListBuilder) Add

func (b *ListBuilder) Add(exprs ...Sexp) *ListBuilder

func (*ListBuilder) Get

func (b *ListBuilder) Get() Sexp

func (*ListBuilder) Size

func (b *ListBuilder) Size() int

type Loop

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

func (*Loop) IsStackElem

func (loop *Loop) IsStackElem()

type NamedUserFunction

type NamedUserFunction func(string) UserFunction

type OverrideFunction

type OverrideFunction func(*SexpFunction) UserFunction

type Parser

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

func NewParser

func NewParser(l *Lexer, e *Environment) *Parser

type PopInstr

type PopInstr int

func (PopInstr) Execute

func (p PopInstr) Execute(env *Environment) error

func (PopInstr) InstrString

func (p PopInstr) InstrString() string

type PrepareCallInstr

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

func (PrepareCallInstr) Execute

func (c PrepareCallInstr) Execute(env *Environment) error

func (PrepareCallInstr) InstrString

func (c PrepareCallInstr) InstrString() string

type PushInstr

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

func (PushInstr) Execute

func (p PushInstr) Execute(env *Environment) error

func (PushInstr) InstrString

func (p PushInstr) InstrString() string

type PushInstrClosure

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

func (PushInstrClosure) Execute

func (p PushInstrClosure) Execute(env *Environment) error

func (PushInstrClosure) InstrString

func (p PushInstrClosure) InstrString() string

type PutInstr

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

func (PutInstr) Execute

func (p PutInstr) Execute(env *Environment) error

func (PutInstr) InstrString

func (p PutInstr) InstrString() string

type RefSymInstr

type RefSymInstr struct {
}

func (RefSymInstr) Execute

func (p RefSymInstr) Execute(env *Environment) error

func (RefSymInstr) InstrString

func (p RefSymInstr) InstrString() string

type RemoveScopeInstr

type RemoveScopeInstr int

func (RemoveScopeInstr) Execute

func (a RemoveScopeInstr) Execute(env *Environment) 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 *Environment) error

func (ReturnInstr) InstrString

func (r ReturnInstr) InstrString() string

type RuneReader

type RuneReader interface {
	Offset() (line int, offset int)
	CurLine() string
	ReadRune() (r rune, size int, err error)
}

func NewRuneReader

func NewRuneReader(r io.RuneReader) RuneReader

type Scope

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

func (*Scope) Bind

func (s *Scope) Bind(n int, e Sexp)

func (*Scope) Clone

func (s *Scope) Clone() StackElem

func (*Scope) Find

func (s *Scope) Find(n int) (Sexp, bool)

func (*Scope) IsStackElem

func (s *Scope) IsStackElem()

type ScopeElem

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

type Sexp

type Sexp interface {
	SexpString() string
}

func ConcatHash

func ConcatHash(h *SexpHash, b ...Sexp) (Sexp, error)

func ConcatList

func ConcatList(a *SexpPair, b ...Sexp) (Sexp, error)

func FilterList

func FilterList(env *Environment, fun *SexpFunction, list *SexpPair) (Sexp, error)

func FlatMapHash

func FlatMapHash(env *Environment, fun *SexpFunction, arr *SexpHash) (Sexp, error)

func FlatMapList

func FlatMapList(env *Environment, fun *SexpFunction, expr Sexp) (Sexp, error)

func FoldlArray

func FoldlArray(env *Environment, fun *SexpFunction, lst Sexp, acc Sexp) (Sexp, error)

func FoldlHash

func FoldlHash(env *Environment, fun *SexpFunction, hash *SexpHash, acc Sexp) (Sexp, error)

func FoldlList

func FoldlList(env *Environment, fun *SexpFunction, lst, acc Sexp) (Sexp, error)

func ListToArray

func ListToArray(expr Sexp) ([]Sexp, error)

func MakeList

func MakeList(expressions []Sexp) Sexp

func MapHash

func MapHash(env *Environment, fun *SexpFunction, arr *SexpHash) (Sexp, error)

func MapList

func MapList(env *Environment, fun *SexpFunction, expr Sexp) (Sexp, error)

func ParseArray

func ParseArray(parser *Parser) (Sexp, error)

func ParseExpression

func ParseExpression(parser *Parser) (Sexp, error)

func ParseHash

func ParseHash(parser *Parser) (Sexp, error)

func ParseList

func ParseList(parser *Parser) (Sexp, error)

func ParseTokens

func ParseTokens(env *Environment, lexer *Lexer) ([]Sexp, error)

func WrongNumberArguments

func WrongNumberArguments(funcname string, current int, expect ...int) (Sexp, error)

type SexpArray

type SexpArray []Sexp

func ConcatArray

func ConcatArray(arr SexpArray, exprs ...Sexp) (SexpArray, error)

func FilterArray

func FilterArray(env *Environment, fun *SexpFunction, arr SexpArray) (SexpArray, error)

func FlatMapArray

func FlatMapArray(env *Environment, fun *SexpFunction, arr SexpArray) (SexpArray, error)

func MapArray

func MapArray(env *Environment, fun *SexpFunction, arr SexpArray) (SexpArray, error)

func (SexpArray) MarshalJSON

func (a SexpArray) MarshalJSON() ([]byte, error)

func (SexpArray) SexpString

func (arr SexpArray) SexpString() string

type SexpBool

type SexpBool bool

func (SexpBool) MarshalJSON

func (a SexpBool) MarshalJSON() ([]byte, error)

func (SexpBool) SexpString

func (b SexpBool) SexpString() string

type SexpBytes

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

func ConcatBytes

func ConcatBytes(str SexpBytes, exprs ...Sexp) (SexpBytes, error)

func NewSexpBytes

func NewSexpBytes(b []byte) SexpBytes

func NewSexpBytesByHex

func NewSexpBytesByHex(hexstr string) (SexpBytes, error)

func (SexpBytes) Bytes

func (bs SexpBytes) Bytes() []byte

func (SexpBytes) MarshalJSON

func (a SexpBytes) MarshalJSON() ([]byte, error)

func (SexpBytes) SexpString

func (bs SexpBytes) SexpString() string

type SexpChar

type SexpChar rune

func (SexpChar) MarshalJSON

func (a SexpChar) MarshalJSON() ([]byte, error)

func (SexpChar) SexpString

func (c SexpChar) SexpString() string

type SexpFloat

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

func NewSexpFloat

func NewSexpFloat(c float64) SexpFloat

func NewSexpFloatInt

func NewSexpFloatInt(i SexpInt) SexpFloat

func NewSexpFloatStr

func NewSexpFloatStr(str string) (SexpFloat, error)

func (SexpFloat) Add

func (f SexpFloat) Add(f2 SexpFloat) SexpFloat

func (SexpFloat) Ceil

func (f SexpFloat) Ceil() SexpInt

func (SexpFloat) Cmp

func (f SexpFloat) Cmp(f2 SexpFloat) int

func (SexpFloat) Div

func (f SexpFloat) Div(f2 SexpFloat) SexpFloat

func (SexpFloat) Floor

func (f SexpFloat) Floor() SexpInt

func (SexpFloat) Format

func (f SexpFloat) Format(s string) string

func (SexpFloat) MarshalJSON

func (a SexpFloat) MarshalJSON() ([]byte, error)

func (SexpFloat) Mul

func (f SexpFloat) Mul(f2 SexpFloat) SexpFloat

func (SexpFloat) Round

func (f SexpFloat) Round() SexpInt

func (SexpFloat) SexpString

func (f SexpFloat) SexpString() string

func (SexpFloat) Sub

func (f SexpFloat) Sub(f2 SexpFloat) SexpFloat

func (SexpFloat) ToFloat64

func (f SexpFloat) ToFloat64() float64

func (SexpFloat) ToString

func (f SexpFloat) ToString(prec int) string

type SexpFunction

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

func MakeFunction

func MakeFunction(name string, nargs int, varargs bool, fun Function, opts ...FuntionOption) *SexpFunction

func MakeUserFunction

func MakeUserFunction(name string, ufun UserFunction, opts ...FuntionOption) *SexpFunction

func (*SexpFunction) Clone

func (sf *SexpFunction) Clone() *SexpFunction

func (*SexpFunction) Doc

func (sf *SexpFunction) Doc() string

func (*SexpFunction) MarshalJSON

func (a *SexpFunction) MarshalJSON() ([]byte, error)

func (*SexpFunction) Name

func (sf *SexpFunction) Name() string

func (*SexpFunction) SexpString

func (sf *SexpFunction) SexpString() string

type SexpHash

type SexpHash struct {
	Map      map[int][]*SexpPair
	KeyOrder []Sexp // must user pointers here, else hset! will fail to update.
	NumKeys  int
}

func FilterHash

func FilterHash(env *Environment, fun *SexpFunction, hash *SexpHash) (*SexpHash, error)

func MakeHash

func MakeHash(args []Sexp) (*SexpHash, error)

func (*SexpHash) Explain

func (hash *SexpHash) Explain(env *Environment, field string, args []Sexp) (Sexp, error)

func (*SexpHash) Foreach

func (hash *SexpHash) Foreach(fn func(Sexp, Sexp) bool)

func (*SexpHash) HashDelete

func (hash *SexpHash) HashDelete(key Sexp) error

func (*SexpHash) HashExist

func (hash *SexpHash) HashExist(key Sexp) bool

func (*SexpHash) HashGet

func (hash *SexpHash) HashGet(key Sexp) (Sexp, error)

func (*SexpHash) HashGetDefault

func (hash *SexpHash) HashGetDefault(key Sexp, defaultval Sexp) (Sexp, error)

func (*SexpHash) HashSet

func (hash *SexpHash) HashSet(key Sexp, val Sexp) error

func (*SexpHash) MarshalJSON

func (a *SexpHash) MarshalJSON() ([]byte, error)

func (*SexpHash) SexpString

func (hash *SexpHash) SexpString() string

type SexpInt

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

func NewSexpInt

func NewSexpInt(i int) SexpInt

func NewSexpInt64

func NewSexpInt64(i int64) SexpInt

func NewSexpIntStr

func NewSexpIntStr(str string) (SexpInt, error)

func NewSexpIntStrWithBase

func NewSexpIntStrWithBase(str string, base int) (SexpInt, error)

func NewSexpUint64

func NewSexpUint64(i uint64) SexpInt

func (SexpInt) Add

func (i SexpInt) Add(j SexpInt) SexpInt

func (SexpInt) And

func (i SexpInt) And(j SexpInt) SexpInt

func (SexpInt) BitNot

func (i SexpInt) BitNot() SexpInt

func (SexpInt) Div

func (i SexpInt) Div(j SexpInt) SexpInt

func (SexpInt) Format

func (i SexpInt) Format(s string) string

func (SexpInt) IsInt64

func (i SexpInt) IsInt64() bool

func (SexpInt) IsUint64

func (i SexpInt) IsUint64() bool

func (SexpInt) IsZero

func (i SexpInt) IsZero() bool

func (SexpInt) MarshalJSON

func (a SexpInt) MarshalJSON() ([]byte, error)

func (SexpInt) Mod

func (i SexpInt) Mod(j SexpInt) SexpInt

func (SexpInt) Mul

func (i SexpInt) Mul(j SexpInt) SexpInt

func (SexpInt) Or

func (i SexpInt) Or(j SexpInt) SexpInt

func (SexpInt) Random

func (i SexpInt) Random(rnd *rand.Rand) SexpInt

func (SexpInt) SexpString

func (i SexpInt) SexpString() string

func (SexpInt) ShiftLeft

func (i SexpInt) ShiftLeft(j SexpInt) SexpInt

func (SexpInt) ShiftRight

func (i SexpInt) ShiftRight(j SexpInt) SexpInt

func (SexpInt) Sign

func (i SexpInt) Sign() int

func (SexpInt) Sub

func (i SexpInt) Sub(j SexpInt) SexpInt

func (SexpInt) ToInt

func (i SexpInt) ToInt() int

func (SexpInt) ToInt64

func (i SexpInt) ToInt64() int64

func (SexpInt) ToUint64

func (i SexpInt) ToUint64() uint64

func (SexpInt) Xor

func (i SexpInt) Xor(j SexpInt) SexpInt

type SexpPair

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

func Cons

func Cons(a Sexp, b Sexp) *SexpPair

func (*SexpPair) Foreach

func (pair *SexpPair) Foreach(f func(Sexp) bool)

func (*SexpPair) Head

func (pair *SexpPair) Head() Sexp

func (*SexpPair) MarshalJSON

func (a *SexpPair) MarshalJSON() ([]byte, error)

func (*SexpPair) SexpString

func (pair *SexpPair) SexpString() string

func (*SexpPair) Tail

func (pair *SexpPair) Tail() Sexp

type SexpSentinel

type SexpSentinel int
const (
	SexpNull SexpSentinel = iota
	SexpEnd
	SexpMarker
)

func (SexpSentinel) MarshalJSON

func (a SexpSentinel) MarshalJSON() ([]byte, error)

func (SexpSentinel) SexpString

func (sent SexpSentinel) SexpString() string

type SexpStr

type SexpStr string

func AppendStr

func AppendStr(str SexpStr, exprs ...Sexp) (SexpStr, error)

func ConcatStr

func ConcatStr(str SexpStr, exprs ...Sexp) (SexpStr, error)

func (SexpStr) MarshalJSON

func (a SexpStr) MarshalJSON() ([]byte, error)

func (SexpStr) SexpString

func (s SexpStr) SexpString() string

type SexpSymbol

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

func (SexpSymbol) MarshalJSON

func (a SexpSymbol) MarshalJSON() ([]byte, error)

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 *Environment) error

func (SquashInstr) InstrString

func (s SquashInstr) InstrString() string

type Stack

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

func NewStack

func NewStack(size int) *Stack

func (*Stack) BindSymbol

func (stack *Stack) BindSymbol(sym SexpSymbol, expr Sexp) error

func (*Stack) Clone

func (stack *Stack) Clone() *Stack

func (*Stack) Get

func (stack *Stack) Get(n int) (StackElem, error)

func (*Stack) GetExpr

func (stack *Stack) GetExpr(n int) (Sexp, error)

func (*Stack) GetExpressions

func (stack *Stack) GetExpressions(n int) ([]Sexp, error)

func (*Stack) IsEmpty

func (stack *Stack) IsEmpty() bool

func (*Stack) IsStackElem

func (stack *Stack) IsStackElem()

func (*Stack) LookupSymbol

func (stack *Stack) LookupSymbol(sym SexpSymbol) (Sexp, error)

func (*Stack) Pop

func (stack *Stack) Pop() (StackElem, error)

func (*Stack) PopAddr

func (stack *Stack) PopAddr() (*SexpFunction, int, error)

func (*Stack) PopExpr

func (stack *Stack) PopExpr() (Sexp, error)

func (*Stack) PopExpressions

func (stack *Stack) PopExpressions(n int) ([]Sexp, error)

func (*Stack) PopScope

func (stack *Stack) PopScope() error

func (*Stack) PrintStack

func (stack *Stack) PrintStack(w io.Writer)

func (*Stack) Push

func (stack *Stack) Push(elem StackElem)

func (*Stack) PushAddr

func (stack *Stack) PushAddr(function *SexpFunction, pc int)

func (*Stack) PushAllTo

func (stack *Stack) PushAllTo(target *Stack) int

func (*Stack) PushExpr

func (stack *Stack) PushExpr(expr Sexp)

func (*Stack) PushMulti

func (stack *Stack) PushMulti(elems ...StackElem)

func (*Stack) PushScope

func (stack *Stack) PushScope()

func (*Stack) SetSymbol

func (stack *Stack) SetSymbol(sym SexpSymbol, expr Sexp) error

func (*Stack) Top

func (stack *Stack) Top() int

type StackElem

type StackElem interface {
	IsStackElem()
}

type Stringer

type Stringer interface {
	Stringify() string
}

type Token

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

func DecodeAtom

func DecodeAtom(atom string) (Token, error)

func DecodeBrace

func DecodeBrace(brace rune) Token

func (Token) String

func (t Token) String() string

type TokenType

type TokenType int
const (
	TokenLParen TokenType = iota
	TokenRParen
	TokenLSquare
	TokenRSquare
	TokenLCurly
	TokenRCurly
	TokenDot
	TokenQuote
	TokenSharpQuote
	TokenBacktick
	TokenLambda
	TokenTilde
	TokenTildeAt
	TokenSymbol
	TokenBool
	TokenDecimal
	TokenHex
	TokenOct
	TokenBinary
	TokenBinaryStream
	TokenFloat
	TokenChar
	TokenString
	TokenEnd
)

type UserFunction

type UserFunction func(*Environment, []Sexp) (Sexp, error)

func GetAnyToBool

func GetAnyToBool(name string) UserFunction

func GetAnyToBytes

func GetAnyToBytes(name string) UserFunction

func GetAnyToChar

func GetAnyToChar(name string) UserFunction

func GetAnyToFloat

func GetAnyToFloat(name string) UserFunction

func GetAnyToInteger

func GetAnyToInteger(name string) UserFunction

func GetAnyToSymbolFunction

func GetAnyToSymbolFunction(name string) UserFunction

func GetAppendFunction

func GetAppendFunction(name string) UserFunction

func GetApplyFunction

func GetApplyFunction(name string) UserFunction

func GetArrayAccessFunction

func GetArrayAccessFunction(name string) UserFunction

func GetConcatFunction

func GetConcatFunction(name string) UserFunction

func GetConsFunction

func GetConsFunction(name string) UserFunction

func GetConstructorFunction

func GetConstructorFunction(name string) UserFunction

func GetEvalFunction

func GetEvalFunction(name string) UserFunction

func GetExistFunction

func GetExistFunction(name string) UserFunction

func GetFirstFunction

func GetFirstFunction(name string) UserFunction

func GetGenSymFunction

func GetGenSymFunction(name string) UserFunction

func GetHashAccessFunction

func GetHashAccessFunction(name string) UserFunction

func GetLenFunction

func GetLenFunction(name string) UserFunction

func GetMakeArrayFunction

func GetMakeArrayFunction(name string) UserFunction

func GetNotFunction

func GetNotFunction(name string) UserFunction

func GetReadFunction

func GetReadFunction(name string) UserFunction

func GetRestFunction

func GetRestFunction(name string) UserFunction

func GetSexpString

func GetSexpString(name string) UserFunction

func GetSgetFunction

func GetSgetFunction(name string) UserFunction

func GetSliceFunction

func GetSliceFunction(name string) UserFunction

func GetSourceFileFunction

func GetSourceFileFunction(name string) UserFunction

func GetStringifyFunction

func GetStringifyFunction(name string) UserFunction

GetStringifyFunction return s-expr's string representation

func GetSymnumFunction

func GetSymnumFunction(name string) UserFunction

func GetTypeFunction

func GetTypeFunction(name string) UserFunction

func GetTypeQueryFunction

func GetTypeQueryFunction(name string) UserFunction

type VectorizeInstr

type VectorizeInstr int

func (VectorizeInstr) Execute

func (s VectorizeInstr) Execute(env *Environment) error

func (VectorizeInstr) InstrString

func (s VectorizeInstr) InstrString() string

type Zerable

type Zerable interface {
	IsZero() bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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