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

164 lines
3.7 KiB
Go

package langsvc
import (
"sort"
"aego/script/ast"
"aego/script/checker"
"aego/script/resolver"
"aego/script/source"
"aego/script/types"
"aego/script/workspace"
)
func objToken(o *resolver.Object) TokenKind {
switch o.Kind {
case resolver.ObjPkg:
return TokNamespace
case resolver.ObjType:
if o.Type != nil {
switch o.Type.Kind {
case types.KEnum:
return TokEnum
case types.KStruct:
return TokStruct
}
}
return TokType
case resolver.ObjGeneric:
return TokType
case resolver.ObjFunc:
if f, ok := o.Data.(*checker.Func); ok && f.Script != nil {
if f.Decl != nil && f.Decl.Coroutine {
return TokCoroutine
}
return TokMethod
}
return TokFunction
case resolver.ObjScript:
return TokScript
case resolver.ObjParam:
return TokParameter
case resolver.ObjField:
return TokField
case resolver.ObjConst:
return TokConstant
case resolver.ObjBuiltin:
return TokBuiltin
case resolver.ObjSignal:
return TokSignal
}
return TokVariable
}
func (s *Service) SemanticTokens(file source.FileID) []Token {
return semanticTokens(s.Latest(), file)
}
func semanticTokens(snap *workspace.Snapshot, file source.FileID) []Token {
if snap == nil {
return nil
}
f := snap.Files[file]
if f == nil {
return nil
}
a := snap.Analysis
marked := map[*ast.Ident]TokenKind{}
ast.Inspect(f, func(n ast.Node) bool {
switch x := n.(type) {
case *ast.File:
if x.Package != nil {
marked[x.Package] = TokNamespace
}
case *ast.Attr:
marked[x.Name] = TokAttribute
case *ast.AttrArg:
if x.Key != nil {
marked[x.Key] = TokParameter
}
case *ast.EnumDecl:
for _, m := range x.Members {
marked[m] = TokEnumMember
}
case *ast.Element:
if x.Key != nil {
marked[x.Key] = TokField
}
case *ast.SelectorExpr:
if sel := a.Selections[x]; sel != nil {
switch sel.Kind {
case checker.SelField, checker.SelLane, checker.SelScriptField:
marked[x.Sel] = TokField
case checker.SelComponentField:
marked[x.Sel] = TokProperty
case checker.SelEnumMember:
marked[x.Sel] = TokEnumMember
case checker.SelHostConst:
marked[x.Sel] = TokConstant
case checker.SelSignal:
marked[x.Sel] = TokSignal
}
}
case *ast.CallExpr:
k := a.Calls[x]
if k == nil {
break
}
if sel, ok := x.Fun.(*ast.SelectorExpr); ok {
switch k.Kind {
case checker.CallHost:
marked[sel.Sel] = TokFunction
case checker.CallHostMethod, checker.CallScriptMethod:
marked[sel.Sel] = TokMethod
case checker.CallGetComponent, checker.CallHasComponent, checker.CallGetScript,
checker.CallEmit, checker.CallConnect, checker.CallDisconnect, checker.CallConnected,
checker.CallCoStop, checker.CallCoRunning:
marked[sel.Sel] = TokBuiltin
}
}
if k.Kind == checker.CallGetComponent || k.Kind == checker.CallHasComponent || k.Kind == checker.CallGetScript {
for _, ta := range x.TypeArgs {
if nt, ok := ta.(*ast.NamedType); ok {
marked[nt.Name] = TokType
if k.Kind == checker.CallGetScript {
marked[nt.Name] = TokScript
}
if nt.Pkg != nil {
marked[nt.Pkg] = TokNamespace
}
}
}
}
}
return true
})
var out []Token
ast.Inspect(f, func(n ast.Node) bool {
id, ok := n.(*ast.Ident)
if !ok || id.Sp.End == id.Sp.Start {
return true
}
k, ok := marked[id]
if !ok {
if o := object(a, id); o != nil {
k, ok = objToken(o), true
}
}
if ok {
out = append(out, Token{Span: id.Sp, Kind: k})
}
return true
})
sort.Slice(out, func(i, j int) bool { return out[i].Span.Start < out[j].Span.Start })
n := 0
for i, t := range out {
if i > 0 && t.Span.Start == out[n-1].Span.Start {
continue
}
out[n] = t
n++
}
return out[:n]
}