base

package
v0.0.0-...-48c8420 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2017 License: LGPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
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

func ConvertValue(v r.Value, to r.Type) r.Value

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 Debugf

func Debugf(format string, args ...interface{})

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 Error

func Error(err error) interface{}

func Errorf

func Errorf(format string, args ...interface{})

func FindFirstToken

func FindFirstToken(src []byte) int

func IsCategory

func IsCategory(k r.Kind, categories ...r.Kind) bool

func IsGensym

func IsGensym(name string) bool

func IsGensymEmbedded

func IsGensymEmbedded(name string) bool

func IsGensymInterface

func IsGensymInterface(name string) bool

func IsGensymPrivate

func IsGensymPrivate(name string) bool

func IsNillableKind

func IsNillableKind(k r.Kind) bool

func IsOptimizedKind

func IsOptimizedKind(k r.Kind) bool

IsOptimizedKind returns true if fast interpreter expects optimized expressions for given Kind

func KindToCategory

func KindToCategory(k r.Kind) r.Kind

func KindToType

func KindToType(k r.Kind) r.Type

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 MarshalUntyped

func MarshalUntyped(kind types.BasicKind, val constant.Value) string

func PackValues

func PackValues(val0 r.Value, vals []r.Value) []r.Value

func ReadBytes

func ReadBytes(src interface{}) []byte

func ReadMultiline

func ReadMultiline(in *bufio.Reader, opts ReadOptions, out io.Writer, prompt string) (src string, firstToken int, err error)

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

func SimplifyNodeForQuote(in ast.Node, unwrapTrivialBlocks bool) ast.Node

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 UnescapeChar(str string) (rune, error)

func UnescapeString

func UnescapeString(str string) string

func UnmarshalUntyped

func UnmarshalUntyped(marshalled string) (types.BasicKind, constant.Value)

func UnpackValues

func UnpackValues(vals []r.Value) (r.Value, []r.Value)

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

func UnwrapTrivialNode(node ast.Node) ast.Node

restricted version of UnwrapTrivialAst

func ValueInterface

func ValueInterface(v r.Value) interface{}

ValueInterface() is a zero-value-safe version of reflect.Value.Interface()

func ValueType

func ValueType(v r.Value) r.Type

ValueType() is a zero-value-safe version of reflect.Value.Type()

func Warnf

func Warnf(format string, args ...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 (g *Globals) CollectNode(node ast.Node)

func (*Globals) Gensym

func (g *Globals) Gensym() string

func (*Globals) GensymEmbedded

func (g *Globals) GensymEmbedded(name string) string

func (*Globals) GensymPrivate

func (g *Globals) GensymPrivate(name string) string

func (*Globals) ImportPackage

func (g *Globals) ImportPackage(name, path string) *PackageRef

func (*Globals) Init

func (g *Globals) Init()

func (*Globals) LookupPackage

func (g *Globals) LookupPackage(name, path string) *PackageRef

LookupPackage returns a package if already present in cache

func (*Globals) ParseBytes

func (g *Globals) ParseBytes(src []byte) []ast.Node

parse phase. no macroexpansion.

func (*Globals) WriteDeclsToFile

func (g *Globals) WriteDeclsToFile(filename string, prologue ...string)

func (*Globals) WriteDeclsToStream

func (g *Globals) WriteDeclsToStream(out io.Writer)

type ImportMode

type ImportMode int
const (
	ImSharedLib ImportMode = iota
	ImBuiltin
	ImInception
)

type Importer

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

func DefaultImporter

func DefaultImporter() *Importer

func (*Importer) Import

func (imp *Importer) Import(path string) (*types.Package, error)

func (*Importer) ImportFrom

func (imp *Importer) ImportFrom(path string, srcDir string, mode types.ImportMode) (*types.Package, error)

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

func ParseOptions(str string) Options

func (Options) String

func (o Options) String() string

type Output

type Output struct {
	Stringer
	Stdout io.Writer
	Stderr io.Writer
}

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) Debugf

func (o *Output) Debugf(format string, args ...interface{})

func (*Output) Error

func (o *Output) Error(err error) interface{}

func (*Output) WarnExtraValues

func (o *Output) WarnExtraValues(extraValues []r.Value)

func (*Output) Warnf

func (o *Output) Warnf(format string, args ...interface{})

type PackageRef

type PackageRef struct {
	imports.Package
	Name, Path string
}

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

type Stringer struct {
	Fileset    *mt.FileSet
	Pos        token.Pos
	Line       int
	NamedTypes map[r.Type]string
}

func (*Stringer) Copy

func (st *Stringer) Copy(other *Stringer)

func (*Stringer) Errorf

func (st *Stringer) Errorf(format string, args ...interface{}) (r.Value, []r.Value)

func (*Stringer) Fprintf

func (st *Stringer) Fprintf(out io.Writer, format string, values ...interface{}) (n int, err error)

func (*Stringer) IncLine

func (st *Stringer) IncLine(src string)

func (*Stringer) IncLineBytes

func (st *Stringer) IncLineBytes(src []byte)

func (*Stringer) Position

func (st *Stringer) Position() token.Position

func (*Stringer) Sprintf

func (st *Stringer) Sprintf(format string, values ...interface{}) string

func (*Stringer) ToString

func (st *Stringer) ToString(separator string, values ...interface{}) string

type TypeVisitor

type TypeVisitor func(name string, t types.Type) bool

type WhichMacroExpand

type WhichMacroExpand uint
const (
	CMacroExpand1 WhichMacroExpand = iota
	CMacroExpand
	CMacroExpandCodewalk
)

func (WhichMacroExpand) String

func (m WhichMacroExpand) String() string

Jump to

Keyboard shortcuts

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