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.
130 lines
3.6 KiB
Go
130 lines
3.6 KiB
Go
package langsvc
|
|
|
|
import (
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
const asyncTmpl = `package c
|
|
|
|
script Mover {
|
|
signal Hit(amount int)
|
|
|
|
var task Coroutine
|
|
|
|
func Blink(times int) coroutine {
|
|
yield
|
|
}
|
|
|
|
func OnHit(amount int) {
|
|
}
|
|
|
|
func Other() {
|
|
}
|
|
|
|
func Update(dt float) {
|
|
CURSOR
|
|
}
|
|
}
|
|
`
|
|
|
|
func TestAsyncCompletion(t *testing.T) {
|
|
s, w, _ := setup(t)
|
|
cases := []struct {
|
|
line string
|
|
want []string
|
|
}{
|
|
{"\t\ttask = start |", []string{"Blink"}},
|
|
{"\t\tyield |", []string{"wait", "frames", "fixed"}},
|
|
{"\t\tHit.|", []string{"Emit", "Connect"}},
|
|
{"\t\tx := node.GetScript<|", []string{"Mover"}},
|
|
{"\t\ttask.|", []string{"Stop", "Running"}},
|
|
}
|
|
for _, tc := range cases {
|
|
id, off := overlay(t, s, w, strings.Replace(asyncTmpl, "CURSOR", tc.line, 1))
|
|
got := labels(s.CompleteNow(id, off))
|
|
for _, want := range tc.want {
|
|
if !slices.Contains(got, want) {
|
|
t.Errorf("%q: missing %s in %v", tc.line, want, got)
|
|
}
|
|
}
|
|
}
|
|
id, off := overlay(t, s, w, strings.Replace(asyncTmpl, "CURSOR", "\t\tHit.Connect(|", 1))
|
|
got := labels(s.CompleteNow(id, off))
|
|
on, other := slices.Index(got, "OnHit"), slices.Index(got, "Other")
|
|
if on < 0 || other < 0 || on > other {
|
|
t.Fatalf("matching handler must come first: %v", got)
|
|
}
|
|
if slices.Contains(got, "Blink") || slices.Contains(got, "Update") {
|
|
t.Fatalf("coroutines and lifecycle methods offered as handlers: %v", got)
|
|
}
|
|
id, off = overlay(t, s, w, strings.Replace(asyncTmpl, "\tsignal Hit(amount int)\n", "\tsignal Hit(amount int)\n\t|\n", 1))
|
|
got = labels(s.CompleteNow(id, off))
|
|
for _, want := range []string{"coroutine", "signal", "Reloaded"} {
|
|
if !slices.Contains(got, want) {
|
|
t.Errorf("script body: missing snippet %s", want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestAsyncHoverAndSignature(t *testing.T) {
|
|
s, w, _ := setup(t)
|
|
src := strings.Replace(asyncTmpl, "CURSOR", "\t\ttask = start Blink(2)\n\t\tHit.Emit(1)", 1)
|
|
id, _ := overlay(t, s, w, src+"|")
|
|
at := func(sub string, delta int) uint32 { return uint32(strings.Index(src, sub) + delta) }
|
|
cases := []struct {
|
|
off uint32
|
|
want string
|
|
}{
|
|
{at("yield", 1), "yield frames(n)"},
|
|
{at("coroutine {", 2), "start"},
|
|
{at("start Blink", 1), "returns its Coroutine"},
|
|
{at("Emit(1)", 1), "synchronously"},
|
|
{at("signal Hit", 8), "signal Hit(amount int)"},
|
|
}
|
|
for _, tc := range cases {
|
|
h, ok := s.Hover(id, tc.off)
|
|
if !ok || !strings.Contains(h.Signature+"\n"+h.Doc, tc.want) {
|
|
t.Errorf("hover at %d = %+v, want %q", tc.off, h, tc.want)
|
|
}
|
|
}
|
|
for _, tc := range []struct {
|
|
line string
|
|
want string
|
|
}{
|
|
{"\t\tHit.Emit(|", "Emit(amount int)"},
|
|
{"\t\tHit.Connect(|", "Connect(handler func(amount int)) Connection"},
|
|
{"\t\ttask = start Blink(|", "times int"},
|
|
} {
|
|
full := strings.Replace(asyncTmpl, "CURSOR", tc.line, 1)
|
|
id, off := overlay(t, s, w, full)
|
|
text := strings.Replace(full, "|", "", 1)
|
|
sig, ok := s.SignatureAt(s.Latest(), id, []byte(text), int(off))
|
|
if !ok || !strings.Contains(sig.Label, tc.want) {
|
|
t.Errorf("%q: signature %+v", tc.line, sig)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestAsyncTokens(t *testing.T) {
|
|
s, w, _ := setup(t)
|
|
src := strings.Replace(asyncTmpl, "CURSOR", "\t\ttask = start Blink(2)\n\t\tHit.Emit(1)", 1)
|
|
id, _ := overlay(t, s, w, src+"|")
|
|
kinds := map[uint32]TokenKind{}
|
|
for _, tk := range s.SemanticTokens(id) {
|
|
kinds[tk.Span.Start] = tk.Kind
|
|
}
|
|
want := map[int]TokenKind{
|
|
strings.Index(src, "Hit(amount"): TokSignal,
|
|
strings.Index(src, "Hit.Emit"): TokSignal,
|
|
strings.Index(src, "Blink(times"): TokCoroutine,
|
|
strings.Index(src, "Blink(2)"): TokCoroutine,
|
|
}
|
|
for off, k := range want {
|
|
if kinds[uint32(off)] != k {
|
|
t.Errorf("token at %d: %d, want %d", off, kinds[uint32(off)], k)
|
|
}
|
|
}
|
|
}
|