Files
aego/script/vm/heap.go
T
sanspie 50be5c04bc
ci-platforms / darwin amd64 smoke (push) Skipped
GitHub / linux amd64 native GitHub-hosted native CI: success
ci-platforms / windows amd64 smoke (push) Skipped
GitHub / windows amd64 native GitHub-hosted native CI: success
GitHub / darwin arm64 native GitHub-hosted native CI: success
GitHub / darwin amd64 native GitHub-hosted native CI: success
ci / checks (push) Failing after 1h21m34s
ci / native-authoring (push) Skipped
ci-platforms / darwin arm64 smoke (push) Skipped
github-native / gitea-pending (push) Skipped
github-native / darwin amd64 native (push) Skipped
github-native / linux amd64 native (push) Skipped
github-native / windows amd64 native (push) Skipped
github-native / darwin arm64 native (push) Skipped
github-native / gitea-result (push) Skipped
ci / build (amd64, linux, ubuntu-24.04) (push) Successful in 12m4s
ci / release (push) Skipped
Stage 12.5: Art Workspace and asset authoring
Add dockable Art tools, animation and previews, guarded asset workflows,
and the Web Asset Studio built on the shared Art Core. Expand English and
Russian documentation, interactive Try scenes, examples and editor icons.

Add audio waveform navigation, source analysis, guarded previews and a
browser Worker mixer. Preserve source changes and recovery with bounded
checks, and strengthen native, browser and interoperability CI.

Prepare version 0.12.5 and manually built native artifact candidates.
Fix the production site image demo build dependency.
Reuse immutable scene indices when capturing keyframes.
Wait for real Persist save/load completion in component tests.
Stabilize browser Game View captures outside pointer hover.
Aseprite interchange and persistent Audio EDL recovery remain limited;
the artifact workflow does not publish releases or change stable.
2026-11-15 10:37:50 +03:00

108 lines
2.0 KiB
Go

package vm
import "strconv"
const staticBit = uint64(1) << 63
type object struct {
gen uint32
live bool
mark bool
str bool
s string
elems []Value
width int
mask uint32
size int
}
type heapFull struct {
limit int
}
func (f heapFull) Error() string {
return "the script heap is over its " + strconv.Itoa(f.limit>>20) + " MB limit"
}
type Heap struct {
objs []object
free []uint32
live int
// Live slice objects, maintained by allocation, collection and restore.
// When zero, every object's elems is nil and snapshots need no slice scan.
sliceCount int
bytes int
since int
limit int
armed int
}
func (h *Heap) charge(size int) {
if h.armed > 0 && h.limit > 0 && h.bytes+size > h.limit {
panic(heapFull{limit: h.limit})
}
}
func heapHandle(idx, gen uint32) uint64 {
return uint64(idx)<<32 | uint64(gen)
}
func (h *Heap) alloc(size int) (uint32, *object) {
h.charge(size)
var idx uint32
if n := len(h.free); n > 0 {
idx = h.free[n-1]
h.free = h.free[:n-1]
} else {
h.objs = append(h.objs, object{})
idx = uint32(len(h.objs) - 1)
}
o := &h.objs[idx]
o.gen++
if o.gen == 0 {
o.gen = 1
}
o.live, o.mark, o.size = true, false, size
h.live++
h.bytes += size
h.since += size
return idx, o
}
func (h *Heap) get(a uint64) *object {
if a == 0 || a&staticBit != 0 {
return nil
}
idx := uint32(a >> 32)
if int(idx) >= len(h.objs) {
return nil
}
o := &h.objs[idx]
if !o.live || o.gen != uint32(a) {
return nil
}
return o
}
func (h *Heap) newString(s string) Value {
idx, o := h.alloc(len(s) + 32)
o.str, o.s, o.elems, o.width, o.mask = true, s, nil, 0, 0
return Value{A: heapHandle(idx, o.gen)}
}
func (h *Heap) newSlice(width int, mask uint32, capacity int) Value {
idx, o := h.alloc(capacity*width*16 + 48)
o.str, o.s = false, ""
o.elems = make([]Value, 0, capacity*width)
o.width, o.mask = width, mask
h.sliceCount++
return Value{A: heapHandle(idx, o.gen)}
}
func (h *Heap) grow(o *object, delta int) {
h.charge(delta)
o.size += delta
h.bytes += delta
h.since += delta
}