feat: render interactive manuscript from Endor through generic graphics

This commit is contained in:
2026-11-12 10:52:28 +08:00
parent d29a1be329
commit 2715c1ce2c
71 changed files with 3000 additions and 78 deletions
+43 -5
View File
@@ -185,6 +185,32 @@ fn compile_plan_with_globals(
}
}
let mut compiled = Vec::with_capacity(plan.roots().len());
fn assigned(statement: &Stmt, globals: &mut BTreeSet<String>) {
match &statement.kind {
StmtKind::Binding(b) => {
globals.insert(b.name.text.clone());
}
StmtKind::Assignment(a) => {
globals.insert(a.name.text.clone());
}
StmtKind::If(b) => {
for s in &b.body.statements {
assigned(s, globals);
}
if let Some(other) = &b.otherwise {
for s in &other.statements {
assigned(s, globals);
}
}
}
StmtKind::While(b) => {
for s in &b.body.statements {
assigned(s, globals);
}
}
_ => {}
}
}
for root in plan.roots() {
let options = compiler::CompileOptions {
globals: globals.iter().cloned().collect(),
@@ -195,11 +221,7 @@ fn compile_plan_with_globals(
);
if let AstRoot::Interactive(input) = root {
for statement in &input.statements {
if let StmtKind::Binding(binding) = &statement.kind {
globals.insert(binding.name.text.clone());
} else if let StmtKind::Assignment(assignment) = &statement.kind {
globals.insert(assignment.name.text.clone());
}
assigned(statement, &mut globals);
}
}
}
@@ -1387,6 +1409,19 @@ impl Architecture {
/// 将相应语法结构投影为带源码范围的 CodeNode,供 Sources 展示和定位。
fn statement(&mut self, statement: &Stmt) -> CodeNode {
match &statement.kind {
StmtKind::If(branch) => {
let mut children = vec![self.expression(&branch.condition)];
children.extend(branch.body.statements.iter().map(|s| self.statement(s)));
if let Some(body) = &branch.otherwise {
children.extend(body.statements.iter().map(|s| self.statement(s)));
}
self.node("if".into(), "if", statement.span, children)
}
StmtKind::While(loop_) => {
let mut children = vec![self.expression(&loop_.condition)];
children.extend(loop_.body.statements.iter().map(|s| self.statement(s)));
self.node("while".into(), "while", statement.span, children)
}
StmtKind::MemberAssignment(assignment) => {
let object = self.expression(&assignment.object);
let value = self.expression(&assignment.value);
@@ -1458,3 +1493,6 @@ impl Architecture {
#[cfg(test)]
mod tests;
#[cfg(test)]
mod manuscript_tests;