tidwall cfc65a13f6 Refactor repository and build scripts
This commit includes updates that affects the build, testing, and
deployment of Tile38.

- The root level build.sh has been broken up into multiple scripts
  and placed in the "scripts" directory.

- The vendor directory has been updated to follow the Go modules
  rules, thus `make` should work on isolated environments. Also
  some vendored packages may have been updated to a later
  version, if needed.

- The Makefile has been updated to allow for making single
  binaries such as `make tile38-server`. There is some scaffolding
  during the build process, so from now on all binaries should be
  made using make. For example, to run a development version of
  the tile38-cli binary, do this:
     make tile38-cli && ./tile38-cli
  not this:
     go run cmd/tile38-cli/main.go

- Travis.CI docker push script has been updated to address a
  change to Docker's JSON repo meta output, which in turn fixes
  a bug where new Tile38 versions were not being properly pushed
  to Docker
2019-11-18 10:33:15 -07:00

74 lines
1.8 KiB
Go

package lua
import (
"reflect"
"unsafe"
)
// iface is an internal representation of the go-interface.
type iface struct {
itab unsafe.Pointer
word unsafe.Pointer
}
const preloadLimit LNumber = 128
var _fv float64
var _uv uintptr
// allocator is a fast bulk memory allocator for the LValue.
type allocator struct {
top int
size int
nptrs []LValue
nheader *reflect.SliceHeader
fptrs []float64
fheader *reflect.SliceHeader
itabLNumber unsafe.Pointer
preloads [int(preloadLimit)]LValue
}
func newAllocator(size int) *allocator {
al := &allocator{
top: 0,
size: size,
nptrs: make([]LValue, size),
nheader: nil,
fptrs: make([]float64, size),
fheader: nil,
itabLNumber: unsafe.Pointer(nil),
}
al.nheader = (*reflect.SliceHeader)(unsafe.Pointer(&al.nptrs))
al.fheader = (*reflect.SliceHeader)(unsafe.Pointer(&al.fptrs))
var v LValue = LNumber(0)
vp := (*iface)(unsafe.Pointer(&v))
al.itabLNumber = vp.itab
for i := 0; i < int(preloadLimit); i++ {
al.preloads[i] = LNumber(i)
}
return al
}
func (al *allocator) LNumber2I(v LNumber) LValue {
if v >= 0 && v < preloadLimit && float64(v) == float64(int64(v)) {
return al.preloads[int(v)]
}
if al.top == len(al.nptrs)-1 {
al.top = 0
al.nptrs = make([]LValue, al.size)
al.nheader = (*reflect.SliceHeader)(unsafe.Pointer(&al.nptrs))
al.fptrs = make([]float64, al.size)
al.fheader = (*reflect.SliceHeader)(unsafe.Pointer(&al.fptrs))
}
fptr := (*float64)(unsafe.Pointer(al.fheader.Data + uintptr(al.top)*unsafe.Sizeof(_fv)))
e := *(*LValue)(unsafe.Pointer(al.nheader.Data + uintptr(al.top)*unsafe.Sizeof(_uv)))
al.top++
ep := (*iface)(unsafe.Pointer(&e))
ep.itab = al.itabLNumber
*fptr = float64(v)
ep.word = unsafe.Pointer(fptr)
return e
}