Implement Phase 1: MIR + VM backend with golden tests

Co-authored-by: moe-charm <217100418+moe-charm@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-08-13 05:59:10 +00:00
parent 5170889285
commit 2f3b453fcb
13 changed files with 567 additions and 2 deletions

View File

@ -132,6 +132,10 @@ impl MirBuilder {
self.build_function_call(name.clone(), arguments.clone())
},
ASTNode::Print { expression, .. } => {
self.build_print_statement(*expression.clone())
},
ASTNode::Program { statements, .. } => {
self.build_block(statements.clone())
},
@ -271,6 +275,20 @@ impl MirBuilder {
Ok(dst)
}
/// Build print statement - converts to console output
fn build_print_statement(&mut self, expression: ASTNode) -> Result<ValueId, String> {
let value = self.build_expression(expression)?;
// For now, use a special Print instruction (minimal scope)
self.emit_instruction(MirInstruction::Print {
value,
effects: EffectMask::PURE.add(Effect::IO),
})?;
// Return the value that was printed
Ok(value)
}
/// Build a block of statements
fn build_block(&mut self, statements: Vec<ASTNode>) -> Result<ValueId, String> {
let mut last_value = None;