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

69 lines
2.5 KiB
Go

package verify_test
import (
"testing"
"aego/script/abi"
bc "aego/script/bytecode"
"aego/script/verify"
)
func asyncModule() *bc.Module {
m := valid()
m.Scripts[0].Signals = []bc.SignalDef{{Name: "Hit", Params: []abi.TypeRef{abi.T(abi.Int)}, Slots: 1}}
m.ScriptRefs = []string{"v.S"}
m.XFields = []bc.XFieldDef{{Ref: 0, Name: "A", Type: "int", Slots: 1}}
m.XMethods = []bc.XMethodDef{{Ref: 0, Name: "Poke"}}
m.Connects = []bc.ConnectDef{{Source: "v.S", Signal: "Hit", Target: "v.S", Handler: "Poke"}}
m.Functions = append(m.Functions, bc.Function{
Name: "S.Blink", Registers: 1, Script: 0, Coroutine: true,
Code: []bc.Instr{bc.ABC(bc.YIELD, 0, 0, 0), bc.ABC(bc.RET, 0, 0, 0)},
})
return m
}
func TestAsyncModuleValid(t *testing.T) {
if ds := verify.Module(asyncModule()); len(ds) != 0 {
t.Fatalf("%v", ds)
}
}
func TestAsyncCorrupt(t *testing.T) {
cases := map[string]func(m *bc.Module){
"startPlain": func(m *bc.Module) { m.Functions[1].Code[2] = bc.ABx(bc.START, 1, 0) },
"callCoroutine": func(m *bc.Module) { m.Functions[1].Code[2] = bc.ABx(bc.CALL, 1, 2) },
"yieldOutside": func(m *bc.Module) { m.Functions[0].Code[0] = bc.ABC(bc.YIELD, 0, 0, 0) },
"yieldKind": func(m *bc.Module) { m.Functions[2].Code[0] = bc.ABC(bc.YIELD, 0, 0, 9) },
"scriptRefIdx": func(m *bc.Module) { m.Functions[1].Code[0] = bc.ABx(bc.GETSCRIPT, 1, 4) },
"xfieldRef": func(m *bc.Module) { m.XFields[0].Ref = 5 },
"xfieldIdx": func(m *bc.Module) { m.Functions[1].Code[0] = bc.ABC(bc.GETXF, 1, 1, 7) },
"xmethodRef": func(m *bc.Module) { m.XMethods[0].Ref = 5 },
"xmethodIdx": func(m *bc.Module) { m.Functions[1].Code[0] = bc.ABx(bc.CALLR, 1, 7) },
"connectIdx": func(m *bc.Module) { m.Functions[1].Code[0] = bc.ABx(bc.CONNECT, 0, 3) },
"emitIdx": func(m *bc.Module) { m.Functions[1].Code[0] = bc.ABx(bc.EMIT, 1, 7) },
"signalVoid": func(m *bc.Module) { m.Scripts[0].Signals[0].Params[0] = abi.T(abi.Void) },
"emptyConnect": func(m *bc.Module) { m.Connects[0].Handler = "" },
"selfrefOut": func(m *bc.Module) { m.Functions[0].Code[0] = bc.ABC(bc.SELFREF, 0, 0, 0) },
}
for name, corrupt := range cases {
t.Run(name, func(t *testing.T) {
m := asyncModule()
corrupt(m)
if ds := verify.Module(m); len(ds) == 0 {
t.Fatal("corruption was not detected")
}
})
}
}
func FuzzDecodeVerifyV3(f *testing.F) {
f.Add(bc.Encode(asyncModule()))
f.Fuzz(func(t *testing.T, data []byte) {
m, err := bc.Decode(data)
if err != nil {
return
}
verify.Module(m)
})
}