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

350 lines
4.9 KiB
Go

// Package ast defines the Aego Script syntax tree.
//
// Some invariants the tree cannot express in its types but that the parser
// guarantees and the checker may rely on:
//
// - The literals true, false and nil are *BasicLit with Kind token.True,
// token.False or token.Nil — never *Ident.
// - AttrArg.Value is only a *BasicLit or a *UnaryExpr{Op: token.Sub, X:
// *BasicLit}; the parser rejects anything else (so @export(min=-1) parses
// and @export(min=f()) never reaches the checker), which folds the minus.
// - CompositeLit.Elems are either all keyed or all unkeyed; mixing the two is
// a parser error.
// - ForStmt.Init and ForStmt.Post are only *ShortVarStmt, *AssignStmt,
// *IncDecStmt or *ExprStmt.
package ast
import (
"aego/script/source"
"aego/script/token"
)
type Loc struct {
Sp source.Span
}
func (l *Loc) Span() source.Span {
return l.Sp
}
type Node interface {
Span() source.Span
}
type Expr interface {
Node
exprNode()
}
type Stmt interface {
Node
stmtNode()
}
type Decl interface {
Node
declNode()
}
type TypeExpr interface {
Node
typeNode()
}
type File struct {
Loc
ID source.FileID
Package *Ident
Imports []*Import
Decls []Decl
}
type Import struct {
Loc
Path string
}
type Attr struct {
Loc
Name *Ident
Args []*AttrArg
}
func (a *Attr) Arg(key string) (*AttrArg, bool) {
for _, arg := range a.Args {
if arg.Key != nil && arg.Key.Name == key {
return arg, true
}
}
return nil, false
}
type AttrArg struct {
Loc
Key *Ident
Value Expr
}
type Ident struct {
Loc
Name string
}
type BasicLit struct {
Loc
Kind token.Kind
Raw string
Str string
}
type Element struct {
Loc
Key *Ident
Value Expr
}
type CompositeLit struct {
Loc
Type TypeExpr
Elems []*Element
}
type ParenExpr struct {
Loc
X Expr
}
type SelectorExpr struct {
Loc
X Expr
Sel *Ident
}
type IndexExpr struct {
Loc
X Expr
Index Expr
}
type CallExpr struct {
Loc
Fun Expr
TypeArgs []TypeExpr
Args []Expr
}
type UnaryExpr struct {
Loc
Op token.Kind
X Expr
}
type BinaryExpr struct {
Loc
Op token.Kind
X Expr
Y Expr
}
type BadExpr struct {
Loc
}
func (*Ident) exprNode() {}
func (*BasicLit) exprNode() {}
func (*CompositeLit) exprNode() {}
func (*ParenExpr) exprNode() {}
func (*SelectorExpr) exprNode() {}
func (*IndexExpr) exprNode() {}
func (*CallExpr) exprNode() {}
func (*UnaryExpr) exprNode() {}
func (*BinaryExpr) exprNode() {}
func (*BadExpr) exprNode() {}
type NamedType struct {
Loc
Pkg *Ident
Name *Ident
Args []TypeExpr
}
type SliceType struct {
Loc
Elem TypeExpr
}
type BadType struct {
Loc
}
func (*NamedType) typeNode() {}
func (*SliceType) typeNode() {}
func (*BadType) typeNode() {}
type VarStmt struct {
Loc
Name *Ident
Type TypeExpr
Value Expr
}
type ShortVarStmt struct {
Loc
Name *Ident
Value Expr
}
type AssignStmt struct {
Loc
Target Expr
Op token.Kind
Value Expr
}
type IncDecStmt struct {
Loc
X Expr
Inc bool
}
type ExprStmt struct {
Loc
X Expr
}
type ReturnStmt struct {
Loc
Value Expr
}
type BranchStmt struct {
Loc
Tok token.Kind
}
type BlockStmt struct {
Loc
Stmts []Stmt
}
type IfStmt struct {
Loc
Cond Expr
Then *BlockStmt
Else Stmt
}
type ForStmt struct {
Loc
Init Stmt
Cond Expr
Post Stmt
Body *BlockStmt
}
type CaseClause struct {
Loc
Values []Expr
Default bool
Body []Stmt
}
type SwitchStmt struct {
Loc
Tag Expr
Cases []*CaseClause
}
type BadStmt struct {
Loc
}
func (*VarStmt) stmtNode() {}
func (*ShortVarStmt) stmtNode() {}
func (*AssignStmt) stmtNode() {}
func (*IncDecStmt) stmtNode() {}
func (*ExprStmt) stmtNode() {}
func (*ReturnStmt) stmtNode() {}
func (*BranchStmt) stmtNode() {}
func (*BlockStmt) stmtNode() {}
func (*IfStmt) stmtNode() {}
func (*ForStmt) stmtNode() {}
func (*SwitchStmt) stmtNode() {}
func (*BadStmt) stmtNode() {}
type ConstDecl struct {
Loc
Doc string
Name *Ident
Type TypeExpr
Value Expr
}
type Field struct {
Loc
Doc string
Name *Ident
Type TypeExpr
}
type StructDecl struct {
Loc
Doc string
Name *Ident
Fields []*Field
}
type EnumDecl struct {
Loc
Doc string
Name *Ident
Members []*Ident
}
type Param struct {
Loc
Name *Ident
Type TypeExpr
}
type FuncDecl struct {
Loc
Doc string
Attrs []*Attr
Name *Ident
Params []*Param
Result TypeExpr
Coroutine bool
Body *BlockStmt
}
type ScriptVar struct {
Loc
Doc string
Attrs []*Attr
Name *Ident
Type TypeExpr
Value Expr
}
type ScriptDecl struct {
Loc
Doc string
Attrs []*Attr
Name *Ident
Signals []*SignalDecl
Vars []*ScriptVar
Funcs []*FuncDecl
}
type BadDecl struct {
Loc
}
func (*ConstDecl) declNode() {}
func (*StructDecl) declNode() {}
func (*EnumDecl) declNode() {}
func (*FuncDecl) declNode() {}
func (*ScriptDecl) declNode() {}
func (*BadDecl) declNode() {}