• E1_131953
    了解作者
  • 182.5KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-04-22 02:51
    上传日期
Lua:Go中用于Lua的VM和编译器。 edundx lua fork gopher-lua porject,这是一个用Go编写的Lua5.1 VM和编译器。 GopherLua与Lua的目标相同:成为一种具有可扩展语义的脚本语言。 它提供了Go API,使您可以轻松地将脚本语言嵌入到Go宿主程序中。 内容 成为具有可扩展语义的脚本语言。 用户友好的Go API 基于堆栈的API(如原始Lua实现中使用的API)将提高GopherLua的性能(它将减少内存分配和具体的类型<->接口转换)。 GopherLua API不是基于堆栈的API。 GopherLua在性能上优先考虑用户友好性。 我认为GopherLua不太快,但也不太慢。 在微型基准测试中,GopherLua的性能几乎与Python3相当(或更好)。 上有一些基准。 go get github.com/edunx/
lua-master.zip
  • lua-master
  • pm
  • pm.go
    12.7KB
  • _tools
  • go-inline
    2.6KB
  • .idea
  • misc.xml
    174B
  • lua.iml
    322B
  • modules.xml
    258B
  • .gitignore
    176B
  • vcs.xml
    180B
  • ast
  • ast.go
    395B
  • token.go
    272B
  • expr.go
    1.4KB
  • misc.go
    191B
  • stmt.go
    972B
  • _lua5.1-tests
  • attrib.lua
    8.2KB
  • verybig.lua
    1.7KB
  • math.lua
    5.4KB
  • vararg.lua
    2.6KB
  • checktable.lua
    1.9KB
  • sort.lua
    1.6KB
  • main.lua
    3.2KB
  • strings.lua
    5.9KB
  • calls.lua
    6.3KB
  • errors.lua
    6.1KB
  • constructs.lua
    5.6KB
  • code.lua
    3.2KB
  • files.lua
    8.3KB
  • big.lua
    7.6KB
  • literals.lua
    6.5KB
  • locals.lua
    2.7KB
  • all.lua
    2.6KB
  • closure.lua
    8.5KB
  • db.lua
    11.8KB
  • gc.lua
    6.8KB
  • pm.lua
    9.3KB
  • nextvar.lua
    8.4KB
  • README
    1.5KB
  • api.lua
    18.6KB
  • events.lua
    8.5KB
  • parse
  • parser.go
    27.4KB
  • lexer.go
    11.1KB
  • Makefile
    106B
  • parser.go.y
    13.6KB
  • _glua-tests
  • vm.lua
    5.4KB
  • base.lua
    939B
  • math.lua
    297B
  • os.lua
    501B
  • strings.lua
    407B
  • coroutine.lua
    339B
  • issues.lua
    6.7KB
  • table.lua
    719B
  • db.lua
    2.1KB
  • cmd
  • glua
  • glua.go
    3.6KB
  • utils.go
    5.6KB
  • oslib.go
    4.4KB
  • table.go
    9.2KB
  • README.rst
    28.4KB
  • mathlib.go
    4.5KB
  • auxlib_test.go
    7.7KB
  • function.go
    4KB
  • value.go
    8.8KB
  • stringlib.go
    9.4KB
  • table_test.go
    4.9KB
  • loadlib.go
    2.8KB
  • testutils_test.go
    2.1KB
  • linit.go
    1.6KB
  • auxlib.go
    10.3KB
  • script_test.go
    2.8KB
  • package.go
    266B
  • alloc.go
    2.1KB
  • _vm.go
    25.2KB
  • LICENSE
    1.1KB
  • tablelib.go
    1.8KB
  • state_test.go
    16.9KB
  • opcode.go
    13.3KB
  • channellib_test.go
    6.7KB
  • Makefile
    241B
  • compile.go
    44KB
  • state.go
    51.1KB
  • iolib.go
    15.5KB
  • channellib.go
    3.7KB
  • baselib.go
    11.4KB
  • coroutinelib.go
    1.9KB
  • vm.go
    44.6KB
  • _state.go
    46.9KB
  • config.go
    746B
  • debuglib.go
    3.3KB
内容介绍
package lua //////////////////////////////////////////////////////// // This file was generated by go-inline. DO NOT EDIT. // //////////////////////////////////////////////////////// import ( "context" "fmt" "io" "math" "os" "runtime" "strings" "sync" "sync/atomic" "time" "github.com/edunx/lua/parse" ) const MultRet = -1 const RegistryIndex = -10000 const EnvironIndex = -10001 const GlobalsIndex = -10002 /* ApiError {{{ */ type ApiError struct { Type ApiErrorType Object LValue StackTrace string // Underlying error. This attribute is set only if the Type is ApiErrorFile or ApiErrorSyntax Cause error } func newApiError(code ApiErrorType, object LValue) *ApiError { return &ApiError{code, object, "", nil} } func newApiErrorS(code ApiErrorType, message string) *ApiError { return newApiError(code, LString(message)) } func newApiErrorE(code ApiErrorType, err error) *ApiError { return &ApiError{code, LString(err.Error()), "", err} } func (e *ApiError) Error() string { if len(e.StackTrace) > 0 { return fmt.Sprintf("%s\n%s", e.Object.String(), e.StackTrace) } return e.Object.String() } type ApiErrorType int const ( ApiErrorSyntax ApiErrorType = iota ApiErrorFile ApiErrorRun ApiErrorError ApiErrorPanic ) /* }}} */ /* ResumeState {{{ */ type ResumeState int const ( ResumeOK ResumeState = iota ResumeYield ResumeError ) /* }}} */ /* P {{{ */ type P struct { Fn LValue NRet int Protect bool Handler *LFunction } /* }}} */ /* Options {{{ */ // Options is a configuration that is used to create a new LState. type Options struct { // Call stack size. This defaults to `lua.CallStackSize`. CallStackSize int // Data stack size. This defaults to `lua.RegistrySize`. RegistrySize int // Allow the registry to grow from the registry size specified up to a value of RegistryMaxSize. A value of 0 // indicates no growth is permitted. The registry will not shrink again after any growth. RegistryMaxSize int // If growth is enabled, step up by an additional `RegistryGrowStep` each time to avoid having to resize too often. // This defaults to `lua.RegistryGrowStep` RegistryGrowStep int // Controls whether or not libraries are opened by default SkipOpenLibs bool // Tells whether a Go stacktrace should be included in a Lua stacktrace when panics occur. IncludeGoStackTrace bool // If `MinimizeStackMemory` is set, the call stack will be automatically grown or shrank up to a limit of // `CallStackSize` in order to minimize memory usage. This does incur a slight performance penalty. MinimizeStackMemory bool } /* }}} */ /* Debug {{{ */ type Debug struct { frame *callFrame Name string What string Source string CurrentLine int NUpvalues int LineDefined int LastLineDefined int } /* }}} */ /* callFrame {{{ */ type callFrame struct { Idx int Fn *LFunction Parent *callFrame Pc int Base int LocalBase int ReturnBase int NArgs int NRet int TailCall int } type callFrameStack interface { Push(v callFrame) Pop() *callFrame Last() *callFrame SetSp(sp int) Sp() int At(sp int) *callFrame IsFull() bool IsEmpty() bool FreeAll() } type fixedCallFrameStack struct { array []callFrame sp int } func newFixedCallFrameStack(size int) callFrameStack { return &fixedCallFrameStack{ array: make([]callFrame, size), sp: 0, } } func (cs *fixedCallFrameStack) IsEmpty() bool { return cs.sp == 0 } func (cs *fixedCallFrameStack) IsFull() bool { return cs.sp == len(cs.array) } func (cs *fixedCallFrameStack) Clear() { cs.sp = 0 } func (cs *fixedCallFrameStack) Push(v callFrame) { cs.array[cs.sp] = v cs.array[cs.sp].Idx = cs.sp cs.sp++ } func (cs *fixedCallFrameStack) Sp() int { return cs.sp } func (cs *fixedCallFrameStack) SetSp(sp int) { cs.sp = sp } func (cs *fixedCallFrameStack) Last() *callFrame { if cs.sp == 0 { return nil } return &cs.array[cs.sp-1] } func (cs *fixedCallFrameStack) At(sp int) *callFrame { return &cs.array[sp] } func (cs *fixedCallFrameStack) Pop() *callFrame { cs.sp-- return &cs.array[cs.sp] } func (cs *fixedCallFrameStack) FreeAll() { // nothing to do for fixed callframestack } // FramesPerSegment should be a power of 2 constant for performance reasons. It will allow the go compiler to change // the divs and mods into bitshifts. Max is 256 due to current use of uint8 to count how many frames in a segment are // used. const FramesPerSegment = 8 type callFrameStackSegment struct { array [FramesPerSegment]callFrame } type segIdx uint16 type autoGrowingCallFrameStack struct { segments []*callFrameStackSegment segIdx segIdx // segSp is the number of frames in the current segment which are used. Full 'sp' value is segIdx * FramesPerSegment + segSp. // It points to the next stack slot to use, so 0 means to use the 0th element in the segment, and a value of // FramesPerSegment indicates that the segment is full and cannot accommodate another frame. segSp uint8 } var segmentPool sync.Pool func newCallFrameStackSegment() *callFrameStackSegment { seg := segmentPool.Get() if seg == nil { return &callFrameStackSegment{} } return seg.(*callFrameStackSegment) } func freeCallFrameStackSegment(seg *callFrameStackSegment) { segmentPool.Put(seg) } // newCallFrameStack allocates a new stack for a lua state, which will auto grow up to a max size of at least maxSize. // it will actually grow up to the next segment size multiple after maxSize, where the segment size is dictated by // FramesPerSegment. func newAutoGrowingCallFrameStack(maxSize int) callFrameStack { cs := &autoGrowingCallFrameStack{ segments: make([]*callFrameStackSegment, (maxSize+(FramesPerSegment-1))/FramesPerSegment), segIdx: 0, } cs.segments[0] = newCallFrameStackSegment() return cs } func (cs *autoGrowingCallFrameStack) IsEmpty() bool { return cs.segIdx == 0 && cs.segSp == 0 } // IsFull returns true if the stack cannot receive any more stack pushes without overflowing func (cs *autoGrowingCallFrameStack) IsFull() bool { return int(cs.segIdx) == len(cs.segments) && cs.segSp >= FramesPerSegment } func (cs *autoGrowingCallFrameStack) Clear() { for i := segIdx(1); i <= cs.segIdx; i++ { freeCallFrameStackSegment(cs.segments[i]) cs.segments[i] = nil } cs.segIdx = 0 cs.segSp = 0 } func (cs *autoGrowingCallFrameStack) FreeAll() { for i := segIdx(0); i <= cs.segIdx; i++ { freeCallFrameStackSegment(cs.segments[i]) cs.segments[i] = nil } } // Push pushes the passed callFrame onto the stack. it panics if the stack is full, caller should call IsFull() before // invoking this to avoid this. func (cs *autoGrowingCallFrameStack) Push(v callFrame) { curSeg := cs.segments[cs.segIdx] if cs.segSp >= FramesPerSegment { // segment full, push new segment if allowed if cs.segIdx < segIdx(len(cs.segments)-1) { curSeg = newCallFrameStackSegment() cs.segIdx++ cs.segments[cs.segIdx] = curSeg cs.segSp = 0 } else { panic("lua callstack overflow") } } curSeg.array[cs.segSp] = v curSeg.array[cs.segSp].Idx = int(cs.segSp) + FramesPerSegment*int(cs.segIdx) cs.segSp++ } // Sp retrieves the current stack depth, which is the number of frames currently pushed on the stack. func (cs *autoGrowingCallFrameStack) Sp() int { return int(cs.segSp) + int(cs.segIdx)*FramesPerSegment } // SetSp can be used to rapidly unwind the stack, freeing all stack frames on the way. It should not be used to // allocate new stack space, use Push() for that. func (cs *autoGrowingCallFrameStack) SetSp(sp int) { desiredSegIdx := segIdx(sp / FramesPerSegment) desiredFramesInLastSeg := uint8(sp % FramesPerSegment) for { if cs.segIdx <= desiredSegIdx { break } freeCallFrameStackSegment(cs.segments[cs.segIdx]) cs.segments[cs.segIdx] = nil cs.segIdx-- } cs.segSp = desiredFramesInLastSeg } func (cs *autoGrowingCallFrameStack) Last() *callFrame { curSeg :=
评论
    相关推荐