Files
aego/script/ast/print.go
T
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

151 lines
3.0 KiB
Go

package ast
import (
"io"
"strconv"
"strings"
"aego/script/source"
)
func Label(n Node) string {
switch x := n.(type) {
case *File:
if x.Package != nil {
return "File " + x.Package.Name
}
return "File"
case *Import:
return "Import " + strconv.Quote(x.Path)
case *Attr:
return "Attr"
case *AttrArg:
return "AttrArg"
case *Ident:
return "Ident " + x.Name
case *BasicLit:
return "BasicLit " + x.Kind.String() + " " + x.Raw
case *CompositeLit:
return "CompositeLit"
case *Element:
return "Element"
case *ParenExpr:
return "Paren"
case *SelectorExpr:
return "Selector"
case *IndexExpr:
return "Index"
case *CallExpr:
return "Call targs=" + strconv.Itoa(len(x.TypeArgs)) + " args=" + strconv.Itoa(len(x.Args))
case *UnaryExpr:
return "Unary " + x.Op.String()
case *BinaryExpr:
return "Binary " + x.Op.String()
case *BadExpr:
return "BadExpr"
case *NamedType:
return "NamedType"
case *SliceType:
return "SliceType"
case *BadType:
return "BadType"
case *VarStmt:
return "Var"
case *ShortVarStmt:
return "ShortVar"
case *AssignStmt:
return "Assign " + x.Op.String()
case *IncDecStmt:
if x.Inc {
return "IncDec ++"
}
return "IncDec --"
case *ExprStmt:
return "ExprStmt"
case *ReturnStmt:
return "Return"
case *BranchStmt:
return "Branch " + x.Tok.String()
case *BlockStmt:
return "Block"
case *IfStmt:
if x.Else != nil {
return "If else"
}
return "If"
case *ForStmt:
return "For init=" + strconv.FormatBool(x.Init != nil) + " cond=" + strconv.FormatBool(x.Cond != nil) + " post=" + strconv.FormatBool(x.Post != nil)
case *SwitchStmt:
return "Switch"
case *CaseClause:
if x.Default {
return "Default"
}
return "Case"
case *BadStmt:
return "BadStmt"
case *ConstDecl:
return "Const"
case *StructDecl:
return "Struct"
case *Field:
return "Field"
case *EnumDecl:
return "Enum"
case *FuncDecl:
if x.Coroutine {
return "Func coroutine"
}
return "Func"
case *SignalDecl:
return "Signal"
case *StartExpr:
if x.Name != nil {
return "Start " + x.Name.Name
}
return "Start"
case *YieldStmt:
return "Yield " + x.Kind.String()
case *Param:
return "Param"
case *ScriptDecl:
return "Script"
case *ScriptVar:
return "ScriptVar"
case *BadDecl:
return "BadDecl"
}
return "?"
}
func Fprint(w io.Writer, sm *source.Manager, n Node) error {
var b strings.Builder
write(&b, sm, n, 0)
_, err := io.WriteString(w, b.String())
return err
}
func Sprint(sm *source.Manager, n Node) string {
var b strings.Builder
write(&b, sm, n, 0)
return b.String()
}
func write(b *strings.Builder, sm *source.Manager, n Node, depth int) {
for i := 0; i < depth; i++ {
b.WriteString(" ")
}
b.WriteString(Label(n))
if sp := n.Span(); sm != nil && sp.Valid() {
line, col := sm.LineCol(sp.File, sp.Start)
b.WriteByte(' ')
b.WriteString(strconv.Itoa(line))
b.WriteByte(':')
b.WriteString(strconv.Itoa(col))
}
b.WriteByte('\n')
for _, c := range Children(n) {
write(b, sm, c, depth+1)
}
}