Documentation
¶
Overview ¶
Package parse contains the code that parses code text and transforms it into bytecode and constants that are able to be run in a virtual machine or translated into another format.
Index ¶
- type Config
- type FnProto
- func File(path string, mode LoadMode) (*FnProto, error)
- func NewEmptyFnProto(name string, rootFn *FnProto) *FnProto
- func NewFnProto(filename, name string, prev *FnProto, params []*Local, vararg bool, ...) *FnProto
- func NewFnProtoFrom(fn *FnProto) *FnProto
- func Parse(filename string, src io.ReadSeeker, mode LoadMode) (*FnProto, error)
- func TryStat(src string, parentFn *FnProto) (*FnProto, error)
- func UndumpFnProto(buf io.Reader) (*FnProto, error)
- type LineInfo
- type LoadMode
- type Local
- type MetaMethod
- type Parser
- type Upindex
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
StringCoers bool // disallow string coersion in arith
RequireOnly bool // require std libs instead of available by default
EnvReadonly bool // not allowed to change _ENV
LocalOnly bool // not allowed to define globals only locals
Strict bool // type checking and throw parsing errors if types are bad
}
Config not fully implemented yet. It is a configuration for how the Parser behaves on each file that it parses. It may allow for the program to be more strict.
type FnProto ¶
type FnProto struct {
Name string
Filename string
Comment string
Locals []*Local // name mapped to stack index of where the local was loaded
Constants []any // constant values to be loaded into the stack
UpIndexes []Upindex // name mapped to upindex
ByteCodes []uint32 // bytecode for this function
FnTable []*FnProto // indexes of functions in constants
LineTrace []LineInfo
LineInfo
Arity int64 // parameter count
Varargs bool // if the function call has varargs
// contains filtered or unexported fields
}
FnProto is a construct that captures a function scope that can be called. it is not always a function, even the main scope of a file outside of a function is a FnProto.
func NewEmptyFnProto ¶
NewEmptyFnProto creates a new fnproto without any parsing. This is mainly used by the runtime package for running a repl.
func NewFnProto ¶
func NewFnProto( filename, name string, prev *FnProto, params []*Local, vararg bool, defn *types.Function, linfo LineInfo, ) *FnProto
NewFnProto creates a new FnProto for parsing. It is the result from parsing that contains the bytecode and debugging information for if an error happens.
func NewFnProtoFrom ¶
NewFnProtoFrom creates a new FnProto from another, used for repl.
func Parse ¶
Parse will, depending on the LoadMode, parse a text file and return bytecode or if the load mode is binary, it will undump an already parsed fnproto. If both modes are passed, it will try to figure out which kind of file it is parsing.
func UndumpFnProto ¶
UndumpFnProto will deserialize fnproto data into a new fnproto ready for interpreting.
func (*FnProto) Dump ¶
Dump will serialize fnproto data into a byte array for writing out to a file.
type LineInfo ¶
LineInfo is a shared struct that is used for tracking where the behviour originated from in the sourcecode.
type LoadMode ¶
type LoadMode uint
LoadMode are flags to indicate how to load/parse a chunk of data.
type Local ¶
type Local struct {
// contains filtered or unexported fields
}
Local is a local variable refence.
type MetaMethod ¶
type MetaMethod string
MetaMethod is the enum of valid meta methods.
const ( // MetaAdd is the __add metamethod. MetaAdd MetaMethod = "__add" // MetaSub is the __sub metamethod. MetaSub MetaMethod = "__sub" // MetaMul is the __mul metamethod. MetaMul MetaMethod = "__mul" // MetaDiv is the __div metamethod. MetaDiv MetaMethod = "__div" // MetaMod is the __mod methamethod. MetaMod MetaMethod = "__mod" // MetaPow is the __pow methamethod. MetaPow MetaMethod = "__pow" // MetaUNM is the __unm methamethod. MetaUNM MetaMethod = "__unm" // MetaIDiv is the __idiv methamethod. MetaIDiv MetaMethod = "__idiv" // MetaBAnd is the __band methamethod. MetaBAnd MetaMethod = "__band" // MetaBOr is the __bor methamethod. MetaBOr MetaMethod = "__bor" // MetaBXOr is the __bxor methamethod. MetaBXOr MetaMethod = "__bxor" // MetaBNot is the __bnot methamethod. MetaBNot MetaMethod = "__bnot" // MetaShl is the __shl methamethod. MetaShl MetaMethod = "__shl" // MetaShr is the __shr methamethod. MetaShr MetaMethod = "__shr" // MetaConcat is the __concat methamethod. MetaConcat MetaMethod = "__concat" // MetaLen is the __len methamethod. MetaLen MetaMethod = "__len" // MetaEq is the __eq methamethod. MetaEq MetaMethod = "__eq" // MetaLt is the __lt methamethod. MetaLt MetaMethod = "__lt" // MetaLe is the __le methamethod. MetaLe MetaMethod = "__le" // MetaIndex is the __index methamethod. MetaIndex MetaMethod = "__index" // MetaNewIndex is the __newindex methamethod. MetaNewIndex MetaMethod = "__newindex" // MetaCall is the __call methamethod. MetaCall MetaMethod = "__call" // MetaClose is the __close methamethod. MetaClose MetaMethod = "__close" // MetaToString is the __tostring methamethod. MetaToString MetaMethod = "__tostring" // MetaName is the __name methamethod. MetaName MetaMethod = "__name" // MetaPairs is the __pairs methamethod. MetaPairs MetaMethod = "__pairs" // MetaMeta is the __metatable methamethod. MetaMeta MetaMethod = "__metatable" // MetaGC is the __gc methamethod. MetaGC MetaMethod = "__gc" )