Documentation
¶
Index ¶
- Constants
- Variables
- func ConvertValue(v r.Value, to r.Type) r.Value
- func Debugf(format string, args ...interface{})
- func DescendNestedUnquotes(unquote UnaryExpr) (lastUnquote UnaryExpr, depth int)
- func DuplicateNestedUnquotes(src UnaryExpr, depth int, content Ast) Ast
- func Error(err error) interface{}
- func Errorf(format string, args ...interface{})
- func FindFirstToken(src []byte) int
- func IsCategory(k r.Kind, categories ...r.Kind) bool
- func IsGensym(name string) bool
- func IsGensymEmbedded(name string) bool
- func IsGensymInterface(name string) bool
- func IsGensymPrivate(name string) bool
- func IsNillableKind(k r.Kind) bool
- func IsOptimizedKind(k r.Kind) bool
- func KindToCategory(k r.Kind) r.Kind
- func KindToType(k r.Kind) r.Type
- func MakeQuote(form UnaryExpr) (UnaryExpr, BlockStmt)
- func MakeQuote2(form UnaryExpr, toQuote AstWithNode) UnaryExpr
- func MarshalUntyped(kind types.BasicKind, val constant.Value) string
- func PackValues(val0 r.Value, vals []r.Value) []r.Value
- func ReadBytes(src interface{}) []byte
- func ReadMultiline(in *bufio.Reader, opts ReadOptions, out io.Writer, prompt string) (src string, firstToken int, err error)
- func ReadString(src interface{}) string
- func SimplifyAstForQuote(in Ast, unwrapTrivialBlocks bool) Ast
- func SimplifyNodeForQuote(in ast.Node, unwrapTrivialBlocks bool) ast.Node
- func UnescapeChar(str string) (rune, error)
- func UnescapeString(str string) string
- func UnmarshalUntyped(marshalled string) (types.BasicKind, constant.Value)
- func UnpackValues(vals []r.Value) (r.Value, []r.Value)
- func UnwrapTrivialAst(in Ast) Ast
- func UnwrapTrivialAstKeepBlocks(in Ast) Ast
- func UnwrapTrivialNode(node ast.Node) ast.Node
- func ValueInterface(v r.Value) interface{}
- func ValueType(v r.Value) r.Type
- func Warnf(format string, args ...interface{})
- type Globals
- func (g *Globals) CollectAst(form Ast)
- func (g *Globals) CollectNode(node ast.Node)
- func (g *Globals) Gensym() string
- func (g *Globals) GensymEmbedded(name string) string
- func (g *Globals) GensymPrivate(name string) string
- func (g *Globals) ImportPackage(name, path string) *PackageRef
- func (g *Globals) Init()
- func (g *Globals) LookupPackage(name, path string) *PackageRef
- func (g *Globals) ParseBytes(src []byte) []ast.Node
- func (g *Globals) WriteDeclsToFile(filename string, prologue ...string)
- func (g *Globals) WriteDeclsToStream(out io.Writer)
- type ImportMode
- type Importer
- type Options
- type Output
- func (o *Output) CollectPackageImports(pkg *types.Package, requireAllInterfaceMethodsExported bool) []string
- func (o *Output) Debugf(format string, args ...interface{})
- func (o *Output) Error(err error) interface{}
- func (o *Output) WarnExtraValues(extraValues []r.Value)
- func (o *Output) Warnf(format string, args ...interface{})
- type PackageRef
- type ReadOptions
- type RuntimeError
- type Stringer
- func (st *Stringer) Copy(other *Stringer)
- func (st *Stringer) Errorf(format string, args ...interface{}) (r.Value, []r.Value)
- func (st *Stringer) Fprintf(out io.Writer, format string, values ...interface{}) (n int, err error)
- func (st *Stringer) IncLine(src string)
- func (st *Stringer) IncLineBytes(src []byte)
- func (st *Stringer) Position() token.Position
- func (st *Stringer) Sprintf(format string, values ...interface{}) string
- func (st *Stringer) ToString(separator string, values ...interface{}) string
- type TypeVisitor
- type WhichMacroExpand
Constants ¶
const ( StrGensymInterface = "\U0001202A" // name of extra struct field needed by the interpreter when creating interface proxies StrGensymPrivate = "\U00012038" // prefix to generate names for unexported struct fields StrGensymEmbedded = "\U00012039" // prefix to generate names for embedded struct fields StrGensym = "\U00012035" // prefix to generate names in macros MaxUint16 = ^uint16(0) MaxUint = ^uint(0) MinUint = 0 MaxInt = int(MaxUint >> 1) MinInt = ^MaxInt )
the following constants must match with github.com/cosmos72/gomacro/xreflect/gensym.go
Variables ¶
var ( Nil = r.Value{} None = r.ValueOf(none{}) // used to indicate "no value" True = r.ValueOf(true) False = r.ValueOf(false) One = r.ValueOf(1) TypeOfInt = r.TypeOf(int(0)) TypeOfInt8 = r.TypeOf(int8(0)) TypeOfInt16 = r.TypeOf(int16(0)) TypeOfInt32 = r.TypeOf(int32(0)) TypeOfInt64 = r.TypeOf(int64(0)) TypeOfUint = r.TypeOf(uint(0)) TypeOfUint8 = r.TypeOf(uint8(0)) TypeOfUint16 = r.TypeOf(uint16(0)) TypeOfUint32 = r.TypeOf(uint32(0)) TypeOfUint64 = r.TypeOf(uint64(0)) TypeOfUintptr = r.TypeOf(uintptr(0)) TypeOfFloat32 = r.TypeOf(float32(0)) TypeOfFloat64 = r.TypeOf(float64(0)) TypeOfComplex64 = r.TypeOf(complex64(0)) TypeOfComplex128 = r.TypeOf(complex128(0)) TypeOfBool = r.TypeOf(false) TypeOfByte = r.TypeOf(byte(0)) TypeOfRune = r.TypeOf(rune(0)) TypeOfString = r.TypeOf("") TypeOfInterface = r.TypeOf((*interface{})(nil)).Elem() TypeOfError = r.TypeOf((*error)(nil)).Elem() TypeOfDeferFunc = r.TypeOf(func() {}) TypeOfReflectType = r.TypeOf((*r.Type)(nil)).Elem() // inception TypeOfSliceOfByte = r.TypeOf([]byte{}) TypeOfSliceOfInterface = r.TypeOf([]interface{}{}) TypeOfPtrInt = r.TypeOf((*int)(nil)) TypeOfPtrInt8 = r.TypeOf((*int8)(nil)) TypeOfPtrInt16 = r.TypeOf((*int16)(nil)) TypeOfPtrInt32 = r.TypeOf((*int32)(nil)) TypeOfPtrInt64 = r.TypeOf((*int64)(nil)) TypeOfPtrUint = r.TypeOf((*uint)(nil)) TypeOfPtrUint8 = r.TypeOf((*uint8)(nil)) TypeOfPtrUint16 = r.TypeOf((*uint16)(nil)) TypeOfPtrUint32 = r.TypeOf((*uint32)(nil)) TypeOfPtrUint64 = r.TypeOf((*uint64)(nil)) TypeOfPtrUintptr = r.TypeOf((*uintptr)(nil)) TypeOfPtrFloat32 = r.TypeOf((*float32)(nil)) TypeOfPtrFloat64 = r.TypeOf((*float64)(nil)) TypeOfPtrComplex64 = r.TypeOf((*complex64)(nil)) TypeOfPtrComplex128 = r.TypeOf((*complex128)(nil)) TypeOfPtrBool = r.TypeOf((*bool)(nil)) TypeOfPtrString = r.TypeOf((*string)(nil)) ZeroStrings = []string{} ZeroTypes = []r.Type{} ZeroValues = []r.Value{} )
Functions ¶
func ConvertValue ¶
ConvertValue converts a value to type t and returns the converted value. extends reflect.Value.Convert(t) by allowing conversions from/to complex numbers. does not check for overflows or truncation.
func DescendNestedUnquotes ¶
func DescendNestedUnquotes(unquote UnaryExpr) (lastUnquote UnaryExpr, depth int)
func DuplicateNestedUnquotes ¶
func DuplicateNestedUnquotes(src UnaryExpr, depth int, content Ast) Ast
DuplicateNestedUnquotes is a support function to handle the following complication: in Common Lisp, the right-most unquote pairs with the left-most comma! we implement the same mechanics, so we must drill down to the last unquote/unquote_splice and, for unquote_splice, create a copy of the unquote/unquote_splice stack for each result. Example:
x:=quote{7; 8}
quasiquote{quasiquote{1; unquote{2}; unquote{unquote_splice{x}}}}
must return
quasiquote{1; unquote{2}; unquote{7}; unquote{8}}
func FindFirstToken ¶
func IsGensymEmbedded ¶
func IsGensymInterface ¶
func IsGensymPrivate ¶
func IsNillableKind ¶
func IsOptimizedKind ¶
IsOptimizedKind returns true if fast interpreter expects optimized expressions for given Kind
func MakeQuote ¶
func MakeQuote(form UnaryExpr) (UnaryExpr, BlockStmt)
MakeQuote invokes parser.MakeQuote() and wraps the resulting ast.Node, which represents quote{<form>}, into an Ast struct
func MakeQuote2 ¶
func MakeQuote2(form UnaryExpr, toQuote AstWithNode) UnaryExpr
MakeQuote2 invokes parser.MakeQuote() and wraps the resulting ast.Node, which represents quote{<form>}, into an Ast struct
func ReadMultiline ¶
func ReadString ¶
func ReadString(src interface{}) string
func SimplifyAstForQuote ¶
func SimplifyAstForQuote(in Ast, unwrapTrivialBlocks bool) Ast
SimplifyAstForQuote unwraps ast2.BlockStmt, ast2.ExprStmt, ast2.ParenExpr and ast2.DeclStmt and returns their contents. used to implement fast.Comp.QuasiQuote(), be extra careful if you patch it!
func SimplifyNodeForQuote ¶
SimplifyNodeForQuote unwraps ast.BlockStmt, ast.ExprStmt, ast.ParenExpr and ast.DeclStmt and returns their contents. used to implement classic.Env.evalQuote() and classic.Env.evalQuasiQuote(), be extra careful if you patch it!
func UnescapeChar ¶
func UnescapeString ¶
func UnwrapTrivialAst ¶
func UnwrapTrivialAst(in Ast) Ast
unwrapTrivialAst extract the content from ParenExpr, ExprStmt, DeclStmt: such nodes are trivial wrappers for their contents
func UnwrapTrivialAstKeepBlocks ¶
func UnwrapTrivialAstKeepBlocks(in Ast) Ast
func UnwrapTrivialNode ¶
restricted version of UnwrapTrivialAst
func ValueInterface ¶
ValueInterface() is a zero-value-safe version of reflect.Value.Interface()
Types ¶
type Globals ¶
type Globals struct {
Output
Options Options
PackagePath string
Filename string
GensymN uint
Importer *Importer
Imports []*ast.GenDecl
Declarations []ast.Decl
Statements []ast.Stmt
ParserMode mp.Mode
SpecialChar rune
}
func NewGlobals ¶
func NewGlobals() *Globals
func (*Globals) CollectAst ¶
func (g *Globals) CollectAst(form Ast)
CollectAst accumulates declarations in ir.Decls and statements in ir.Stmts allows generating a *.go file on user request
func (*Globals) CollectNode ¶
func (*Globals) GensymEmbedded ¶
func (*Globals) GensymPrivate ¶
func (*Globals) ImportPackage ¶
func (g *Globals) ImportPackage(name, path string) *PackageRef
func (*Globals) LookupPackage ¶
func (g *Globals) LookupPackage(name, path string) *PackageRef
LookupPackage returns a package if already present in cache
func (*Globals) ParseBytes ¶
parse phase. no macroexpansion.
func (*Globals) WriteDeclsToFile ¶
func (*Globals) WriteDeclsToStream ¶
type Importer ¶
type Importer struct {
// contains filtered or unexported fields
}
func DefaultImporter ¶
func DefaultImporter() *Importer
func (*Importer) ImportFrom ¶
type Options ¶
type Options uint
const ( OptTrapPanic Options = 1 << iota OptPanicStackTrace OptMacroExpandOnly // do not compile or execute code, only parse and macroexpand it OptFastInterpreter // use the new (and incomplete) fast interpreter OptCollectDeclarations OptCollectStatements OptShowCompile OptShowEval OptShowEvalType OptShowMacroExpand OptShowParse OptShowPrompt OptShowTime OptDebugCallStack OptDebugField OptDebugMacroExpand OptDebugMethod OptDebugPanicRecover OptDebugParse OptDebugQuasiquote OptDebugSleepOnSwitch // to torture-test "switch" implementation for race conditions )
func ParseOptions ¶
type Output ¶
func (*Output) CollectPackageImports ¶
func (o *Output) CollectPackageImports(pkg *types.Package, requireAllInterfaceMethodsExported bool) []string
we need to collect only the imports that actually appear in package's interfaces methods because Go rejects programs with unused imports
func (*Output) WarnExtraValues ¶
type PackageRef ¶
type ReadOptions ¶
type ReadOptions int
const ( ReadOptShowPrompt ReadOptions = 1 << iota ReadOptCollectAllComments // continue until non-comment is found. default is to return comments one by one )
type RuntimeError ¶
type RuntimeError struct {
// contains filtered or unexported fields
}
func (RuntimeError) Error ¶
func (err RuntimeError) Error() string
type Stringer ¶
func (*Stringer) IncLineBytes ¶
type WhichMacroExpand ¶
type WhichMacroExpand uint
const ( CMacroExpand1 WhichMacroExpand = iota CMacroExpand CMacroExpandCodewalk )
func (WhichMacroExpand) String ¶
func (m WhichMacroExpand) String() string