Documentation ¶
Index ¶
- Variables
- func BooleanToScheme(v bool) string
- func CharacterToScheme(r rune) string
- func Eq(a, b Value) bool
- func Equal(a, b Value) bool
- func Int64(v Value) (int64, error)
- func IsBoolean(value Value) (v bool, ok bool)
- func IsString(value Value) (v string, ok bool)
- func IsTrue(v Value) bool
- func ListLength(list Value) (int, bool)
- func Map(f func(idx int, v Value) error, list Value) error
- func MapPairs(f func(idx int, p Pair) error, list Value) error
- func StringToScheme(s string) string
- func ToScheme(v Value) string
- func ToString(v Value) string
- type AST
- type ASTAnd
- type ASTApply
- type ASTCall
- type ASTCallUnary
- type ASTCase
- type ASTCaseChoice
- type ASTCond
- type ASTCondChoice
- type ASTConstant
- type ASTDefine
- type ASTIdentifier
- func (ast *ASTIdentifier) Bytecode(lib *Library) error
- func (ast *ASTIdentifier) Equal(o AST) bool
- func (ast *ASTIdentifier) Locator() Locator
- func (ast *ASTIdentifier) String() string
- func (ast *ASTIdentifier) Type(ctx types.Ctx) *types.Type
- func (ast *ASTIdentifier) Typecheck(lib *Library, round int) error
- type ASTIf
- type ASTLambda
- func (ast *ASTLambda) Bytecode(lib *Library) error
- func (ast *ASTLambda) Equal(o AST) bool
- func (ast *ASTLambda) Locator() Locator
- func (ast *ASTLambda) Parametrize(ctx types.Ctx, params []*types.Type) *types.Type
- func (ast *ASTLambda) Type(ctx types.Ctx) *types.Type
- func (ast *ASTLambda) Typecheck(lib *Library, round int) error
- type ASTLet
- type ASTLetBinding
- type ASTOr
- type ASTPragma
- type ASTSequence
- type ASTSet
- type Args
- type BigFloat
- type BigInt
- type Boolean
- type Builtin
- type Bytevector
- type Character
- type Code
- type Env
- func (e *Env) Copy() *Env
- func (e *Env) CopyEnvFrames() *Env
- func (e *Env) Define(name string, t *types.Type) (*EnvBinding, error)
- func (e *Env) Depth() int
- func (e *Env) Lookup(name string) (*EnvBinding, bool)
- func (e *Env) PopFrame()
- func (e *Env) Print()
- func (e *Env) PushCaptureFrame(captures bool, usage FrameUsage, size int) *EnvFrame
- func (e *Env) PushFrame(t FrameType, usage FrameUsage, size int) *EnvFrame
- type EnvBinding
- type EnvFrame
- type EnvStats
- type Flags
- type Float
- type Frame
- type FrameType
- type FrameUsage
- type Identifier
- type Instr
- type Int
- type Keyword
- type Lambda
- type LambdaImpl
- type Lexer
- type Library
- type LocationPair
- func (pair *LocationPair) Eq(o Value) bool
- func (pair *LocationPair) Errorf(format string, a ...interface{}) error
- func (pair *LocationPair) From() Point
- func (pair *LocationPair) Infof(format string, a ...interface{})
- func (pair *LocationPair) SetTo(p Point)
- func (pair *LocationPair) String() string
- func (pair *LocationPair) To() Point
- type Locator
- type Native
- type Operand
- type PCLine
- type PCMap
- type Pair
- type Params
- type Parser
- type PlainPair
- func (pair *PlainPair) Car() Value
- func (pair *PlainPair) Cdr() Value
- func (pair *PlainPair) Eq(o Value) bool
- func (pair *PlainPair) Equal(o Value) bool
- func (pair *PlainPair) Errorf(format string, a ...interface{}) error
- func (pair *PlainPair) From() Point
- func (pair *PlainPair) Infof(format string, a ...interface{})
- func (pair *PlainPair) Scheme() string
- func (pair *PlainPair) SetCar(v Value) error
- func (pair *PlainPair) SetCdr(v Value) error
- func (pair *PlainPair) SetTo(p Point)
- func (pair *PlainPair) String() string
- func (pair *PlainPair) To() Point
- func (pair *PlainPair) Type() *types.Type
- type Point
- type Port
- type Scheme
- func (scm *Scheme) Apply(lambda Value, args []Value) (Value, error)
- func (scm *Scheme) Breakf(format string, a ...interface{}) error
- func (scm *Scheme) DefineBuiltin(builtin Builtin)
- func (scm *Scheme) DefineBuiltins(builtins []Builtin)
- func (scm *Scheme) Eval(source string, in io.Reader) (Value, error)
- func (scm *Scheme) EvalFile(file string) (Value, error)
- func (scm *Scheme) Global(name string) (Value, error)
- func (scm *Scheme) Intern(name string) *Identifier
- func (scm *Scheme) Load(source string, in io.Reader) (Value, error)
- func (scm *Scheme) LoadFile(file string) (Value, error)
- func (scm *Scheme) Location() (source string, line int, err error)
- func (scm *Scheme) PrintStack()
- func (scm *Scheme) SetGlobal(name string, value Value) error
- func (scm *Scheme) StackTrace() []StackFrame
- func (scm *Scheme) VMErrorf(format string, a ...interface{}) error
- func (scm *Scheme) VMWarningf(format string, a ...interface{})
- type SexprParser
- type StackFrame
- type String
- type Token
- type TokenType
- type TypedName
- type VMEnvFrame
- type Value
- type Vector
Constants ¶
This section is empty.
Variables ¶
var ErrorInvalidList = errors.New("invalid list")
ErrorInvalidList is used to indicate when a malformed or otherwise invalid list is passed to list functions.
Functions ¶
func BooleanToScheme ¶
BooleanToScheme returns the bool as Scheme boolean literal.
func CharacterToScheme ¶
CharacterToScheme returns the rune as Scheme character literal.
func Int64 ¶
Int64 returns the number value as int64 integer number. The function returns an error if the argument is not a number.
func IsTrue ¶
IsTrue tests if the argument value is true according to Scheme truth semantics i.e. the value is true unless it is boolean #f.
func ListLength ¶
ListLength check if the argument value is a valid Scheme list.
func Map ¶
Map maps function for each element of the list. The function returns nil if the argument list is a list and map functions returns nil for each of its element.
func MapPairs ¶
MapPairs maps function for each pair of the list. The function returns nil if the argument list is a list and map functions returns nil for each of its element.
func StringToScheme ¶
StringToScheme returns the string as Scheme string literal.
Types ¶
type AST ¶
type AST interface { Locator() Locator Equal(o AST) bool Type(ctx types.Ctx) *types.Type Typecheck(lib *Library, round int) error Bytecode(lib *Library) error }
AST defines an abstract syntax tree entry
type ASTAnd ¶
ASTAnd implements (and ...) syntax.
type ASTApply ¶
ASTApply implements apply syntax.
type ASTCall ¶
type ASTCall struct { From Locator Inline bool InlineOp Operand Func AST ArgFrame *EnvFrame Args []AST ArgLocs []Locator Tail bool }
ASTCall implements function call syntax.
type ASTCallUnary ¶
ASTCallUnary implements inlined unary function calls.
func (*ASTCallUnary) Bytecode ¶
func (ast *ASTCallUnary) Bytecode(lib *Library) error
Bytecode implements AST.Bytecode.
func (*ASTCallUnary) Locator ¶
func (ast *ASTCallUnary) Locator() Locator
Locator implements AST.Locator.
type ASTCase ¶
type ASTCase struct { From Locator Choices []*ASTCaseChoice ValueFrame *EnvFrame EqvArgFrame *EnvFrame Expr AST Tail bool Captures bool }
ASTCase implements case syntax.
type ASTCaseChoice ¶
ASTCaseChoice implements a case choice.
func (*ASTCaseChoice) Equal ¶
func (c *ASTCaseChoice) Equal(o *ASTCaseChoice) bool
Equal test if this choice is equal to the argument choice.
type ASTCond ¶
type ASTCond struct { From Locator Choices []*ASTCondChoice Tail bool Captures bool }
ASTCond implements cond syntax.
type ASTCondChoice ¶
type ASTCondChoice struct { From Locator Cond AST Func AST FuncValueFrame *EnvFrame FuncArgsFrame *EnvFrame Exprs []AST }
ASTCondChoice implements a cond choice.
func (*ASTCondChoice) Equal ¶
func (c *ASTCondChoice) Equal(o *ASTCondChoice) bool
Equal test if this choice is equal to the argument choice.
type ASTConstant ¶
ASTConstant implements contant values.
func (*ASTConstant) Bytecode ¶
func (ast *ASTConstant) Bytecode(lib *Library) error
Bytecode implements AST.Bytecode.
func (*ASTConstant) Locator ¶
func (ast *ASTConstant) Locator() Locator
Locator implements AST.Locator.
func (*ASTConstant) String ¶
func (ast *ASTConstant) String() string
type ASTDefine ¶
type ASTDefine struct { From Locator Name *Identifier Flags Flags Value AST }
ASTDefine implements (define name value).
type ASTIdentifier ¶
type ASTIdentifier struct { From Locator Name string Binding *EnvBinding Global *Identifier Init AST }
ASTIdentifier implements identifer references.
func (*ASTIdentifier) Bytecode ¶
func (ast *ASTIdentifier) Bytecode(lib *Library) error
Bytecode implements AST.Bytecode.
func (*ASTIdentifier) Equal ¶
func (ast *ASTIdentifier) Equal(o AST) bool
Equal implements AST.Equal.
func (*ASTIdentifier) Locator ¶
func (ast *ASTIdentifier) Locator() Locator
Locator implements AST.Locator.
func (*ASTIdentifier) String ¶
func (ast *ASTIdentifier) String() string
type ASTLambda ¶
type ASTLambda struct { From Locator Name *Identifier Args Args ArgBindings []*EnvBinding Body []AST Env *Env Captures bool Define bool Flags Flags }
ASTLambda implements lambda syntax.
func (*ASTLambda) Parametrize ¶
Parametrize implements types.Parametrizer.
type ASTLet ¶
type ASTLet struct { From Locator Kind Keyword Captures bool Tail bool Bindings []*ASTLetBinding Body []AST }
ASTLet implements let syntaxes.
type ASTLetBinding ¶
type ASTLetBinding struct { From Locator Binding *EnvBinding Init AST }
ASTLetBinding implements a let binding.
type ASTOr ¶
ASTOr implements (or ...) syntax.
type ASTPragma ¶
ASTPragma implements compiler pragmas.
type ASTSequence ¶
ASTSequence implements a (begin ...) sequence.
func (*ASTSequence) Bytecode ¶
func (ast *ASTSequence) Bytecode(lib *Library) error
Bytecode implements AST.Bytecode.
func (*ASTSequence) Locator ¶
func (ast *ASTSequence) Locator() Locator
Locator implements AST.Locator.
type ASTSet ¶
type ASTSet struct { From Locator Name string Binding *EnvBinding Value AST }
ASTSet implements (set name value).
type Args ¶
Args specify lambda arguments.
type Boolean ¶
type Boolean bool
Boolean implements boolean values.
type Builtin ¶
type Builtin struct { Name string Aliases []string Args []string Return *types.Type Flags Flags Native Native }
Builtin defines a built-in native function.
type Bytevector ¶
type Bytevector []byte
Bytevector implements bytevector values.
func (Bytevector) Eq ¶
func (v Bytevector) Eq(o Value) bool
Eq tests if the argument value is eq? to this value.
func (Bytevector) Equal ¶
func (v Bytevector) Equal(o Value) bool
Equal tests if the argument value is equal to this value.
func (Bytevector) Scheme ¶
func (v Bytevector) Scheme() string
Scheme returns the value as a Scheme string.
func (Bytevector) String ¶
func (v Bytevector) String() string
type Character ¶
type Character rune
Character implements character values.
type Env ¶
Env implements environment bindings.
func (*Env) Copy ¶
Copy creates a new copy of the environment that shares the contents of all environment frames and statistics.
func (*Env) CopyEnvFrames ¶
CopyEnvFrames creates a new copy of the environment sharing TypeEnv frames and statistics.
func (*Env) Lookup ¶
func (e *Env) Lookup(name string) (*EnvBinding, bool)
Lookup finds the symbol from the environment.
func (*Env) PushCaptureFrame ¶
func (e *Env) PushCaptureFrame(captures bool, usage FrameUsage, size int) *EnvFrame
PushCaptureFrame pushes a new stack frame. The capture argument specifies if the frame is an env or a stack frame.
type EnvBinding ¶
EnvBinding defines symbol's location in the environment.
type EnvFrame ¶
type EnvFrame struct { Type FrameType Usage FrameUsage Index int Size int Bindings map[string]*EnvBinding }
EnvFrame implements an environment frame.
type Frame ¶
type Frame struct { Index int Next int Toplevel bool Lambda *Lambda PC int Code Code Env *VMEnvFrame // contains filtered or unexported fields }
Frame implements a SCM call stack frame.
type FrameUsage ¶
type FrameUsage int
FrameUsage defines how frame is used.
const ( FUFrame FrameUsage = iota FUArgs FULet FUValue )
Frame usages.
func (FrameUsage) String ¶
func (fu FrameUsage) String() string
type Identifier ¶
Identifier implements identifier values.
func (*Identifier) Eq ¶
func (v *Identifier) Eq(o Value) bool
Eq tests if the argument value is eq? to this value.
func (*Identifier) Equal ¶
func (v *Identifier) Equal(o Value) bool
Equal tests if the argument value is equal to this value.
func (*Identifier) Scheme ¶
func (v *Identifier) Scheme() string
Scheme returns the value as a Scheme string.
func (*Identifier) String ¶
func (v *Identifier) String() string
type Instr ¶
type Instr struct { Op Operand V Value I int J int Sym *Identifier }
Instr implements a Scheme bytecode instruction.
type Keyword ¶
type Keyword int
Keyword defines a Scheme keyword.
const ( KwElse Keyword = iota KwImplies KwDefine KwDefineConstant KwUnquote KwUnquoteSplicing KwQuote KwLambda KwIf KwSet KwBegin KwCond KwAnd KwOr KwCase KwLet KwLetStar KwLetrec KwDo KwDelay KwQuasiquote KwSchemeApply KwPragma )
Scheme keywords.
type Lambda ¶
type Lambda struct { Capture *VMEnvFrame Impl *LambdaImpl }
Lambda implements lambda values.
type LambdaImpl ¶
type LambdaImpl struct { Name string Args Args Return *types.Type Captures bool Capture *VMEnvFrame Native Native Source string Code Code MaxStack int PCMap PCMap Body []AST }
LambdaImpl implements lambda functions.
func (*LambdaImpl) Equal ¶
func (v *LambdaImpl) Equal(o Value) bool
Equal implements the Value.Equal().
func (*LambdaImpl) Scheme ¶
func (v *LambdaImpl) Scheme() string
Scheme implements the Value.Scheme().
func (*LambdaImpl) Signature ¶
func (v *LambdaImpl) Signature(body bool) string
Signature prints the lambda signature with optional lambda body.
type Lexer ¶
type Lexer struct {
// contains filtered or unexported fields
}
Lexer implement lexical analyser.
type Library ¶
type Library struct { Source string Name Value Body *ASTSequence Exports Value ExportAll bool Imports Value Init Code PCMap PCMap // contains filtered or unexported fields }
Library implements a Scheme compilation unit.
type LocationPair ¶
type LocationPair struct { PlainPair // contains filtered or unexported fields }
LocationPair implements a Scheme pair with location information.
func (*LocationPair) Eq ¶
func (pair *LocationPair) Eq(o Value) bool
Eq tests if the argument value is eq? to this value.
func (*LocationPair) Errorf ¶
func (pair *LocationPair) Errorf(format string, a ...interface{}) error
Errorf implements Locator.Errorf.
func (*LocationPair) From ¶
func (pair *LocationPair) From() Point
From returns pair's start location.
func (*LocationPair) Infof ¶
func (pair *LocationPair) Infof(format string, a ...interface{})
Infof implements Locator.Infof.
func (*LocationPair) SetTo ¶
func (pair *LocationPair) SetTo(p Point)
SetTo sets pair's end location.
func (*LocationPair) String ¶
func (pair *LocationPair) String() string
type Locator ¶
type Locator interface { From() Point To() Point SetTo(p Point) // Errorf returns an error with the location information. Errorf(format string, a ...interface{}) error // Infof prints information with the location information. Infof(format string, a ...interface{}) }
Locator interface a source location.
type Operand ¶
type Operand int
Operand defines a Scheme bytecode instruction.
const ( OpConst Operand = iota OpDefine OpLambda OpLabel OpLocal OpEnv OpGlobal OpLocalSet OpEnvSet OpGlobalSet OpPushF OpPushS OpPushE OpPopS OpPopE OpPushA OpCall OpIf OpIfNot OpJmp OpReturn OpPairp OpCons OpCar OpCdr OpNullp OpZerop OpNot OpAdd OpAddI64 OpAddConst OpSub OpSubI64 OpSubConst OpMul OpMulConst OpDiv OpEq OpLt OpGt OpLe OpGe OpCastNumber OpCastSymbol )
Bytecode instructions.
type PCMap ¶
type PCMap []PCLine
PCMap implements mapping from program counter values to source line numbers.
type Pair ¶
type Pair interface { Locator Car() Value Cdr() Value SetCar(v Value) error SetCdr(v Value) error Scheme() string Eq(o Value) bool Equal(o Value) bool Type() *types.Type }
Pair implements a Scheme pair.
func NewLocationPair ¶
NewLocationPair creates a new pair with the car and cdr values and location information.
type Params ¶
type Params struct { // Verbose output. Verbose bool // Quiet output. Quiet bool // NoRuntime specifies if the Scheme-implemented runtime is // initialized. NoRuntime bool // Do not warn when redefining global symbols. NoWarnDefine bool }
Params define the configuration parameters for Scheme.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser implements the byte-code compiler.
type PlainPair ¶
type PlainPair struct {
// contains filtered or unexported fields
}
PlainPair implements a Scheme pair with car and cdr values.
type Point ¶
Point defines a position in the input data.
type Port ¶
type Port struct {
Native interface{}
}
Port implements Scheme ports.
func NewPort ¶
func NewPort(native interface{}) *Port
NewPort creates a new port for the native I/O channel.
type Scheme ¶
type Scheme struct { Params Params Stdout *Port Stderr *Port Parsing bool // contains filtered or unexported fields }
Scheme implements Scheme interpreter and virtual machine.
func NewWithParams ¶
NewWithParams creates a new Scheme interpreter with the parameters.
func (*Scheme) Apply ¶
Apply applies lambda for arguments. This function implements the virtual machine program execution.
The virtual machine is a stack machine with the following registers:
- env - the current environment
- fp - the current stack frame
- pc - program counter
- accu - holds the value of the latest operation
The virtual machine stack is as follows:
sp ---> Value{n} ... Value{0} Arg{n} ... Arg{0} fp ---> Next fp ---+ | v
func (*Scheme) DefineBuiltin ¶
DefineBuiltin defines a built-in native function.
func (*Scheme) DefineBuiltins ¶
DefineBuiltins defines the built-in functions, defined in the argument array.
func (*Scheme) Intern ¶
func (scm *Scheme) Intern(name string) *Identifier
Intern interns the name and returns the interned symbol.
func (*Scheme) PrintStack ¶
func (scm *Scheme) PrintStack()
PrintStack prints the virtual machine stack.
func (*Scheme) SetGlobal ¶
SetGlobal sets the value of the global symbol. The function returns an error if the symbols was defined to be a FlagFinal. The symbol will became defined if it was undefined before the call.
func (*Scheme) StackTrace ¶
func (scm *Scheme) StackTrace() []StackFrame
StackTrace returns information about the virtual machine stack.
func (*Scheme) VMWarningf ¶
VMWarningf prints a virtual machine warning.
type SexprParser ¶
type SexprParser struct {
// contains filtered or unexported fields
}
SexprParser implements S-expression parser.
func NewSexprParser ¶
func NewSexprParser(source string, in io.Reader) *SexprParser
NewSexprParser creates a new parser for the input file.
func (*SexprParser) Errorf ¶
func (p *SexprParser) Errorf(format string, a ...interface{}) error
Errorf implements Locator.Errorf.
func (*SexprParser) From ¶
func (p *SexprParser) From() Point
From returns the parser's current location.
func (*SexprParser) Infof ¶
func (p *SexprParser) Infof(format string, a ...interface{})
Infof implements Locator.Infof.
type StackFrame ¶
StackFrame provides information about the virtual machine stack frame.
type String ¶
type String string
String implements string values.
type Token ¶
type Token struct { Type TokenType From Point To Point Identifier string Bool bool Number Value Char rune Str string Keyword Keyword }
Token specifies an input token.
type TokenType ¶
type TokenType int
TokenType specifies input token types.
type VMEnvFrame ¶
type VMEnvFrame struct { Next *VMEnvFrame Index int Values []Value }
VMEnvFrame implement a virtual machine environment frame.
type Value ¶
Value implements a Scheme value.
func ListValues ¶
ListValues returns the list values as []Value.
Source Files ¶
- arithmetic.go
- ast.go
- boolean.go
- character.go
- debug.go
- env.go
- lambda.go
- lexer.go
- library.go
- list.go
- load.go
- parser.go
- procedure.go
- rnrs_bytevectors.go
- rnrs_files.go
- rnrs_io_simple.go
- rnrs_mutable_pairs.go
- rnrs_mutable_strings.go
- rnrs_programs.go
- rnrs_unicode.go
- scheme.go
- sexpr.go
- string.go
- symbols.go
- value.go
- vector.go
- vm.go