base

package
v0.0.0-...-a6136ef Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: MPL-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

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

View Source
const (
	CmdOptQuit      = 1 << iota
	CmdOptForceEval // temporarily re-enable evaluation even if in macroexpand-only mode
)

Variables

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

func CollectNestedUnquotes(unquote UnaryExpr) ([]token.Token, []token.Pos)

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 IsGensym

func IsGensym(name string) bool

func IsGensymAnonymous

func IsGensymAnonymous(name string) bool

func IsGensymInterface

func IsGensymInterface(name string) bool

func IsGensymPrivate

func IsGensymPrivate(name string) bool

func MakeNestedQuote

func MakeNestedQuote(form AstWithNode, toks []token.Token, pos []token.Pos) AstWithNode

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 ReadBytes

func ReadBytes(src interface{}) []byte

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

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 StartSignalHandler

func StartSignalHandler(handler func(os.Signal)) chan os.Signal

func StopSignalHandler

func StopSignalHandler(c chan os.Signal)

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

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

func (BufReadline) Read

func (buf BufReadline) Read(prompt string) ([]byte, error)

type CmdOpt

type CmdOpt uint32

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 (g *Globals) CollectNode(node ast.Node)

func (*Globals) Gensym

func (g *Globals) Gensym() string

func (*Globals) GensymAnonymous

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

func (*Globals) GensymPrivate

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

func (*Globals) ParseBytes

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

parse phase. no macroexpansion.

func (*Globals) Print

func (g *Globals) Print(values []xr.Value, types []xr.Type)

func (*Globals) PrintR

func (g *Globals) PrintR(values []r.Value, types []xr.Type)

print values

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

func (g *Globals) UnloadPackage(path string)

remove package 'path' from the list of known packages. later attempts to import it again will trigger a recompile.

func (*Globals) WriteDeclsToFile

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

func (*Globals) WriteDeclsToStream

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

type Inspector

type Inspector interface {
	Inspect(name string, val r.Value, rtyp r.Type, xtyp xr.Type, globals *Globals)
}

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

func ParseOptions(str string) Options

func (Options) String

func (o Options) String() string

type Output

type Output = output.Output

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

func (*P_github_com_muazhari_gomacro_base_Inspector) Inspect

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

func (*P_github_com_muazhari_gomacro_base_Readline) Read

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 Readline

type Readline interface {
	Read(prompt string) ([]byte, error)
}

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
)

func (Signal) String

func (sig Signal) String() string

type Signals

type Signals struct {
	Sync  Signal
	Debug Signal
	Async Signal
	// contains filtered or unexported fields
}

func (*Signals) IsEmpty

func (s *Signals) IsEmpty() bool

type TtyReadline

type TtyReadline struct {
	Term *liner.State
}

func MakeTtyReadline

func MakeTtyReadline(historyfile string) (TtyReadline, error)

func (TtyReadline) Close

func (tty TtyReadline) Close(historyfile string) (err error)

func (TtyReadline) Read

func (tty TtyReadline) Read(prompt string) ([]byte, error)

type WhichMacroExpand

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

func (WhichMacroExpand) String

func (m WhichMacroExpand) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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