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

192 lines
5.0 KiB
Go

package langsvc
import (
"slices"
"sort"
"aego/script/ast"
"aego/script/source"
"aego/script/workspace"
)
func symbolsOf(snap *workspace.Snapshot, f *ast.File) []Symbol {
a := snap.Analysis
detail := func(id *ast.Ident) string {
if o := a.Defs[id]; o != nil {
return describe(o)
}
return ""
}
var out []Symbol
for _, d := range f.Decls {
switch x := d.(type) {
case *ast.ConstDecl:
out = append(out, Symbol{Name: x.Name.Name, Kind: SymConst, Detail: detail(x.Name), Span: x.Sp, Selection: x.Name.Sp})
case *ast.StructDecl:
sym := Symbol{Name: x.Name.Name, Kind: SymStruct, Detail: detail(x.Name), Span: x.Sp, Selection: x.Name.Sp}
for _, fl := range x.Fields {
sym.Children = append(sym.Children, Symbol{Name: fl.Name.Name, Kind: SymField, Detail: detail(fl.Name), Span: fl.Sp, Selection: fl.Name.Sp})
}
out = append(out, sym)
case *ast.EnumDecl:
sym := Symbol{Name: x.Name.Name, Kind: SymEnum, Detail: detail(x.Name), Span: x.Sp, Selection: x.Name.Sp}
for _, m := range x.Members {
sym.Children = append(sym.Children, Symbol{Name: m.Name, Kind: SymEnumMember, Span: m.Sp, Selection: m.Sp})
}
out = append(out, sym)
case *ast.FuncDecl:
out = append(out, Symbol{Name: x.Name.Name, Kind: SymFunc, Detail: detail(x.Name), Span: x.Sp, Selection: x.Name.Sp})
case *ast.ScriptDecl:
sym := Symbol{Name: x.Name.Name, Kind: SymScript, Detail: detail(x.Name), Span: x.Sp, Selection: x.Name.Sp}
for _, sg := range x.Signals {
sym.Children = append(sym.Children, Symbol{Name: sg.Name.Name, Kind: SymSignal, Detail: detail(sg.Name), Span: sg.Sp, Selection: sg.Name.Sp})
}
for _, v := range x.Vars {
sym.Children = append(sym.Children, Symbol{Name: v.Name.Name, Kind: SymField, Detail: detail(v.Name), Span: v.Sp, Selection: v.Name.Sp})
}
for _, fn := range x.Funcs {
sym.Children = append(sym.Children, Symbol{Name: fn.Name.Name, Kind: SymMethod, Detail: detail(fn.Name), Span: fn.Sp, Selection: fn.Name.Sp})
}
out = append(out, sym)
}
}
return out
}
func (s *Service) Symbols(file source.FileID) []Symbol {
return s.SymbolsIn(s.Latest(), file)
}
func (s *Service) SymbolsIn(snap *workspace.Snapshot, file source.FileID) []Symbol {
if snap == nil {
return nil
}
f := snap.Files[file]
if f == nil {
return nil
}
return symbolsOf(snap, f)
}
func (s *Service) WorkspaceSymbols() []SymbolRef {
snap := s.Latest()
if snap == nil {
return nil
}
var out []SymbolRef
for id, f := range snap.Files {
path := snap.Sources.Path(id)
var walk func(list []Symbol, container string)
walk = func(list []Symbol, container string) {
for _, sym := range list {
line, col := snap.Sources.LineCol(id, sym.Selection.Start)
out = append(out, SymbolRef{
Name: sym.Name, Container: container, Detail: sym.Detail,
Kind: sym.Kind, Path: path, Line: line, Col: col,
})
walk(sym.Children, sym.Name)
}
}
walk(symbolsOf(snap, f), "")
}
sort.Slice(out, func(i, j int) bool {
a, b := out[i], out[j]
if a.Name != b.Name {
return a.Name < b.Name
}
if a.Path != b.Path {
return a.Path < b.Path
}
return a.Line < b.Line
})
return out
}
func (s *Service) RangesIn(snap *workspace.Snapshot, file source.FileID, lo, hi uint32) []source.Span {
if snap == nil {
return nil
}
f := snap.Files[file]
if f == nil {
return nil
}
var out []source.Span
ast.Inspect(f, func(n ast.Node) bool {
sp := n.Span()
if sp.Start > lo || sp.End < hi {
return false
}
if sp.End > sp.Start {
out = append(out, sp)
}
return true
})
sort.SliceStable(out, func(i, j int) bool { return out[i].Len() < out[j].Len() })
n := 0
for i, sp := range out {
if i > 0 && sp.Start == out[n-1].Start && sp.End == out[n-1].End {
continue
}
out[n] = sp
n++
}
return out[:n]
}
func scriptIdent(snap *workspace.Snapshot, typeName, field string) *ast.Ident {
for _, st := range snap.Analysis.Scripts {
if st.FullName != typeName && !slices.Contains(st.Former, typeName) {
continue
}
if field == "" {
return st.Decl.Name
}
for _, f := range st.Fields {
if f.Name == field || slices.Contains(f.Former, field) {
return f.Decl.Name
}
}
}
return nil
}
func (s *Service) ScriptDeclaration(typeName, field string) (Location, bool) {
snap := s.Latest()
if snap == nil {
return Location{}, false
}
id := scriptIdent(snap, typeName, field)
if id == nil {
return Location{}, false
}
return loc(snap, id.Sp), true
}
func (s *Service) ScriptUsages(typeName, field string) ([]Location, *workspace.Snapshot) {
snap := s.Latest()
if snap == nil {
return nil, nil
}
id := scriptIdent(snap, typeName, field)
if id == nil {
return nil, snap
}
o := snap.Analysis.Defs[id]
if o == nil {
return nil, snap
}
var out []Location
for _, r := range snap.Analysis.References {
if r.Object == o {
out = append(out, loc(snap, r.Ident.Sp))
}
}
sort.Slice(out, func(i, j int) bool {
if out[i].Path != out[j].Path {
return out[i].Path < out[j].Path
}
return out[i].Span.Start < out[j].Span.Start
})
return out, snap
}