Documentation ¶
Index ¶
- Constants
- Variables
- func CollectNestedUnquotes(unquote UnaryExpr) ([]token.Token, []token.Pos)
- func DescendNestedUnquotes(unquote UnaryExpr) (lastUnquote UnaryExpr, depth int)
- func DuplicateNestedUnquotes(src UnaryExpr, depth int, toappend Ast) Ast
- func IsGensym(name string) bool
- func IsGensymAnonymous(name string) bool
- func IsGensymInterface(name string) bool
- func IsGensymPrivate(name string) bool
- func MakeNestedQuote(form AstWithNode, toks []token.Token, pos []token.Pos) AstWithNode
- func MakeQuote(form UnaryExpr) (UnaryExpr, BlockStmt)
- func MakeQuote2(form UnaryExpr, toQuote AstWithNode) UnaryExpr
- func ReadBytes(src interface{}) []byte
- func ReadMultiline(in Readline, opts ReadOptions, 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 StartSignalHandler(handler func(os.Signal)) chan os.Signal
- func StopSignalHandler(c chan os.Signal)
- func UnwrapTrivialAst(in Ast) Ast
- func UnwrapTrivialAstKeepBlocks(in Ast) Ast
- func UnwrapTrivialNode(node ast.Node) ast.Node
- type BufReadline
- type CmdOpt
- type Globals
- func (g *Globals) CollectAst(form Ast)
- func (g *Globals) CollectNode(node ast.Node)
- func (g *Globals) Gensym() string
- func (g *Globals) GensymAnonymous(name string) string
- func (g *Globals) GensymPrivate(name string) string
- func (g *Globals) ParseBytes(src []byte) []ast.Node
- func (g *Globals) Print(values []xr.Value, types []xr.Type)
- func (g *Globals) PrintR(values []r.Value, types []xr.Type)
- func (g *Globals) ReadMultiline(opts ReadOptions, prompt string) (str string, firstToken int)
- func (g *Globals) UnloadPackage(path string)
- func (g *Globals) WriteDeclsToFile(filename string, prologue ...string)
- func (g *Globals) WriteDeclsToStream(out io.Writer)
- type Inspector
- type Options
- type Output
- type P_github_com_muazhari_gomacro_base_Inspector
- type P_github_com_muazhari_gomacro_base_Readline
- type ReadOptions
- type Readline
- type Signal
- type Signals
- type TtyReadline
- type WhichMacroExpand
Constants ¶
const ( StrGensymInterface string = "\U0001202A" // name of extra struct field needed by the interpreter when creating interface proxies StrGensymPrivate string = "\U00012038" // prefix to generate names for unexported struct fields StrGensymAnonymous string = "\U00012039" // prefix to generate names for anonymous struct fields StrGensym string = "\U00012035" // prefix to generate names in macros MaxUint16 = ^uint16(0) MaxUint = ^uint(0) MaxInt = int(MaxUint >> 1) MinInt = ^MaxInt GoModuleSupported = genimport.GoModuleSupported // true if compiled with Go >= 1.11 )
the following constants must match with github.com/muazhari/gomacro-custom/xreflect/gensym.go
const ( CmdOptQuit = 1 << iota CmdOptForceEval // temporarily re-enable evaluation even if in macroexpand-only mode )
Variables ¶
var ( NilR = reflect.NilR NoneR = reflect.NoneR // used to indicate "no value" True = r.ValueOf(true) False = r.ValueOf(false) One = r.ValueOf(1) TypeOfInt = reflect.TypeOfInt TypeOfInt8 = reflect.TypeOfInt8 TypeOfInt16 = reflect.TypeOfInt16 TypeOfInt32 = reflect.TypeOfInt32 TypeOfInt64 = reflect.TypeOfInt64 TypeOfUint = reflect.TypeOfUint TypeOfUint8 = reflect.TypeOfUint8 TypeOfUint16 = reflect.TypeOfUint16 TypeOfUint32 = reflect.TypeOfUint32 TypeOfUint64 = reflect.TypeOfUint64 TypeOfUintptr = reflect.TypeOfUintptr TypeOfFloat32 = reflect.TypeOfFloat32 TypeOfFloat64 = reflect.TypeOfFloat64 TypeOfComplex64 = reflect.TypeOfComplex64 TypeOfComplex128 = reflect.TypeOfComplex128 TypeOfBool = reflect.TypeOfBool TypeOfString = reflect.TypeOfString TypeOfByte = r.TypeOf(byte(0)) TypeOfRune = r.TypeOf(rune(0)) TypeOfInterface = r.TypeOf((*interface{})(nil)).Elem() TypeOfError = r.TypeOf((*error)(nil)).Elem() TypeOfDeferFunc = r.TypeOf(func() {}) TypeOfReflectType = r.TypeOf((*r.Type)(nil)).Elem() // inception 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 CollectNestedUnquotes ¶
return the sequence of nested etoken.UNQUOTE and/or etoken.UNQUOTE_SPLICE contained in 'unquote'
func DescendNestedUnquotes ¶
func DescendNestedUnquotes(unquote UnaryExpr) (lastUnquote UnaryExpr, depth int)
return the expression inside nested etoken.UNQUOTE and/or etoken.UNQUOTE_SPLICE contained in 'unquote'
func DuplicateNestedUnquotes ¶
func DuplicateNestedUnquotes(src UnaryExpr, depth int, toappend 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 IsGensymAnonymous ¶
func IsGensymInterface ¶
func IsGensymPrivate ¶
func MakeNestedQuote ¶
MakeNestedQuote invokes parser.MakeQuote() multiple times, passing op=toks[i] at each call
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 ReadMultiline(in Readline, opts ReadOptions, prompt string) (src string, firstToken int, err error)
return read string, position of first non-comment token and error (if any) on EOF, return "", -1, io.EOF
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 StopSignalHandler ¶
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
Types ¶
type BufReadline ¶
type BufReadline struct {
// contains filtered or unexported fields
}
a Readline implementation that reads from a *bufio.Reader
func MakeBufReadline ¶
func MakeBufReadline(in *bufio.Reader) BufReadline
type Globals ¶
type Globals struct { Output Options Options PackagePath string Filepath string Importer *genimport.Importer Imports []*ast.GenDecl Declarations []ast.Decl Statements []ast.Stmt Prompt string Readline Readline GensymN uint ParserMode mp.Mode MacroChar rune // prefix for macro-related keywords macro, quote, quasiquote, splice... The default is '~' ReplCmdChar byte // prefix for special REPL commands env, help, inspect, quit, unload... The default is ':' Inspector Inspector }
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) GensymAnonymous ¶
func (*Globals) GensymPrivate ¶
func (*Globals) ParseBytes ¶
parse phase. no macroexpansion.
func (*Globals) ReadMultiline ¶
func (g *Globals) ReadMultiline(opts ReadOptions, prompt string) (str string, firstToken int)
read phase return read string and position of first non-comment token. return "", -1 on EOF
func (*Globals) UnloadPackage ¶
remove package 'path' from the list of known packages. later attempts to import it again will trigger a recompile.
func (*Globals) WriteDeclsToFile ¶
func (*Globals) WriteDeclsToStream ¶
type Options ¶
type Options uint
const ( OptCollectDeclarations Options = 1 << iota OptCollectStatements OptCtrlCEnterDebugger // Ctrl+C enters the debugger instead of injecting a panic. requires OptDebugger OptDebugger // enable debugger support. "break" and _ = "break" are breakpoints and enter the debugger OptKeepUntyped OptMacroExpandOnly // do not compile or execute code, only parse and macroexpand it OptModuleImport // if built with Go >= 1.11, import "foo" will use modules OptPanicStackTrace OptTrapPanic OptDebugCallStack OptDebugDebugger // print debug information related to the debugger OptDebugField OptDebugFromReflect OptDebugMacroExpand OptDebugMethod OptDebugParse OptDebugRecover OptDebugQuasiquote OptDebugSleepOnSwitch // to torture-test "switch" implementation for race conditions OptDebugGenerics OptShowCompile OptShowEval OptShowEvalType OptShowMacroExpand OptShowParse OptShowPrompt OptShowTime )
func ParseOptions ¶
type P_github_com_muazhari_gomacro_base_Inspector ¶
type P_github_com_muazhari_gomacro_base_Inspector struct { Object interface{} Inspect_ func(_proxy_obj_ interface{}, name string, val reflect.Value, typ reflect.Type, xtyp xreflect.Type, globals *Globals) }
--------------- proxy for github.com/muazhari/gomacro-custom/base.Inspector ---------------
type P_github_com_muazhari_gomacro_base_Readline ¶
type P_github_com_muazhari_gomacro_base_Readline struct { Object interface{} Read_ func(_proxy_obj_ interface{}, prompt string) ([]byte, error) }
--------------- proxy for github.com/muazhari/gomacro-custom/base.Readline ---------------
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 Signal ¶
type Signal uint8
const ( SigDefer Signal = 1 << iota // request to install a defer function SigReturn SigInterrupt // user pressed Ctrl+C, process received SIGINT, or similar SigDebug // debugger asked to execute in single-step mode SigNone = Signal(0) // no signal SigAll = ^SigNone // mask of all possible signals )
type Signals ¶
type TtyReadline ¶
func MakeTtyReadline ¶
func MakeTtyReadline(historyfile string) (TtyReadline, error)
func (TtyReadline) Close ¶
func (tty TtyReadline) Close(historyfile string) (err error)
type WhichMacroExpand ¶
type WhichMacroExpand uint
const ( CMacroExpand1 WhichMacroExpand = iota CMacroExpand CMacroExpandCodewalk )
func (WhichMacroExpand) String ¶
func (m WhichMacroExpand) String() string