Files
sanspie cf68c71f05 Stage 6: coroutines, signals, ScriptRef, workspace CLI, editor tooling
Language: yield/signal/coroutine become keywords, start is contextual.
Coroutine methods (func Name() coroutine) with start and
yield / wait / frames / fixed / await; signals with Emit/Connect and
Connection handles; ScriptRef<T> and node.GetScript<T>() for fields,
plain methods and signals of other scripts. Diagnostics AES2050-AES2059.

Bytecode v3: ScriptRefs, XFields, XMethods and Connects tables resolved by
name in vm.Link, per-script signals, coroutine flag on functions; new
opcodes START/YIELD/EMIT/CONNECT/DISCONNECT/CONNECTED/COSTOP/CORUN/
SELFREF/GETSCRIPT/GETXF/SETXF/CALLR, checked by verify.

Runtime: script/coroutine scheduler (frames/fixed counters, time heap,
await lists; only due coroutines are visited) and script/signal registry
(snapshot per Emit, deferred removal, no allocations in steady state).
Hot reload cancels coroutines of changed scripts, rebinds connections by
name and signature, then runs Reloaded.

Tooling: script/build removed, aego check/test/dump run on the workspace
(test builds include _test.aes); langsvc completion, hover, signatures and
semantic tokens for the new syntax; editor highlighting, snippets with
placeholders, coroutine/signal profiler graphs and stats.

Docs (script.md sections 16-19, editor.md, ARCHITECTURE), test fixtures and
golden files, platformer enemies wired to the player, scriptreload demo,
and run.Config.FrameTime for deterministic headless fixed steps.

Modules (6.5): engine/module registry and ComponentBuilder are the one
registration path for engine subsystems and native code; render2d,
render3d and script/engine are modules over scene/frame, the script
component moved to scene/scriptcomp, and scene/components and
scene/systems are gone. Editor inspector, templates, picking shapes and
extension hooks are driven by descriptors and editor/builtins; sdk gains
Component/EditorHook; depcheck checks the module graph and the
aego_runtime graph.

Also: stop tracking built tool binaries; gl33 activates the scratch unit
before binding for texture updates.

Verification: typed component method adapters (Method0..2, Proc0..2)
with direct field access and no allocations; app.Build as the single
construction path for run and the editor; modules attach per scene
document; depcheck aego_editor pass; diagnostic codes in one place and
every code covered by a test; indexed coroutine heaps with eager
cancel; dead component references and nil intrinsics fault with
AES6004, host faults keep their code; GC roots of struct fields checked
in verify and vm.Link; 255-field limit; AES4010 for script packages
shadowing host modules; architecture registry D111-D147.

Golden: the harness renders on the thread that owns the GL context,
ReadPixels returns rows in memory order (render targets are top-down per
D17), and the first rendering references are committed.
2026-10-12 14:22:08 +03:00

89 lines
1.7 KiB
Go

package reload
import (
"sort"
"aego/script/abi"
"aego/script/bytecode"
)
type Program struct {
ID uint64
Modules map[string]*bytecode.Module
Hashes map[string][32]byte
}
func NewProgram(id uint64, mods map[string]*bytecode.Module, hashes map[string][32]byte) Program {
return Program{ID: id, Modules: mods, Hashes: hashes}
}
func (p Program) Ordered() []*bytecode.Module {
keys := make([]string, 0, len(p.Modules))
for k := range p.Modules {
keys = append(keys, k)
}
sort.Strings(keys)
out := make([]*bytecode.Module, len(keys))
for i, k := range keys {
out[i] = p.Modules[k]
}
return out
}
type layout struct {
structs map[string]*bytecode.StructDef
enums map[string][]string
}
func newLayout(p Program) *layout {
l := &layout{structs: map[string]*bytecode.StructDef{}, enums: map[string][]string{}}
for _, m := range p.Modules {
for i := range m.Structs {
s := &m.Structs[i]
l.structs[s.Name] = s
}
for _, e := range m.Enums {
l.enums[e.Name] = e.Members
}
}
return l
}
func (l *layout) slots(t abi.TypeRef) int {
if t.Kind == abi.Struct {
if s := l.structs[t.Name]; s != nil {
return int(s.Slots)
}
}
return t.Slots()
}
func (l *layout) mask(t abi.TypeRef) uint32 {
switch t.Kind {
case abi.String, abi.Slice:
return 1
case abi.Struct:
s := l.structs[t.Name]
if s == nil {
return 0
}
var m uint32
for _, f := range s.Fields {
if ft, ok := abi.Parse(f.Type); ok && f.Slot < 32 {
m |= l.mask(ft) << f.Slot
}
}
return m
}
return 0
}
func structField(s *bytecode.StructDef, name string) *bytecode.StructField {
for i := range s.Fields {
if s.Fields[i].Name == name {
return &s.Fields[i]
}
}
return nil
}