flowchart LR
  subgraph Project[项目输入数据]
    A1[robot.urdf]
    A2[main.grl]
    A3[targets / paths / operations]
    A4[io_map.json]
    A5[post profile]
  end

  subgraph Compile[TypeScript 编译层]
    B1[URDF Parser]
    B2[GRL Lexer/Parser]
    B3[AST]
    B4[Symbol Table]
    B5[Semantic Analyzer]
    B6[Executable IR]
    B7[Motion Request Builder]
  end

  subgraph KDL[KDL Worker / WASM]
    C1[KdlRpcRequest]
    C2[RobotHandle]
    C3[KDL Solvers]
    C4[FK / IK / Jacobian]
    C5[Trap Profile]
    C6[Motion Planner]
    C7[KdlRpcResponse]
  end

  subgraph Runtime[虚拟控制器运行层]
    D1[Program Counter]
    D2[Call Stack]
    D3[Scope Stack]
    D4[Motion Queue]
    D5[IO Image]
    D6[Wait Registry]
    D7[Alarm Queue]
    D8[Trace Buffer]
  end

  subgraph Output[输出数据]
    E1[TrajectoryResult]
    E2[PathPlanResult]
    E3[PathValidationResult]
    E4[MotionDiagnostic]
    E5[CycleTimeResult]
    E6[ABB/FANUC/KUKA 程序]
    E7[转换报告]
  end

  A1 --> B1
  B1 -->|NormalizedRobotModel| C1
  C1 --> C2
  C2 --> C3

  A2 --> B2
  A3 --> B5
  A4 --> B5
  B2 --> B3
  B3 --> B4
  B4 --> B5
  B5 --> B6

  B6 -->|MotionInstruction| B7
  B7 -->|MoveJRequest / MoveLRequest / MoveCRequest / PathPlanRequest| C1
  C1 --> C4
  C1 --> C5
  C4 --> C6
  C5 --> C6
  C6 --> C7

  C7 --> E1
  C7 --> E2
  C7 --> E3
  C7 --> E4
  C7 --> E5

  B6 --> D1
  B6 --> D2
  B6 --> D3
  E1 --> D4
  E2 --> D4
  B6 -->|IO / wait / pulse| D5
  B6 -->|wait| D6
  E4 --> D7
  D4 --> D8
  D5 --> D8
  D6 --> D8

  B6 -->|IR + post profile| A5
  A5 --> E6
  A5 --> E7
