type checking !?!?

This commit is contained in:
2025-03-22 14:40:32 -04:00
parent 606cb30c6b
commit 7f809d797c
44 changed files with 664 additions and 314 deletions
+8 -8
View File
@@ -1,10 +1,10 @@
use crate::ir::{IRUInstruction, VarID};
use crate::ir::{IRUInstruction, VarInst};
use super::{PBlock, FnLowerCtx, FnLowerable, PStatement};
use super::{FnLowerCtx, FnLowerable, PBlock, PStatement};
impl FnLowerable for PBlock {
type Output = VarID;
fn lower(&self, ctx: &mut FnLowerCtx) -> Option<VarID> {
type Output = VarInst;
fn lower(&self, ctx: &mut FnLowerCtx) -> Option<VarInst> {
let ctx = &mut ctx.sub();
for statement in &self.statements {
statement.lower(ctx);
@@ -14,20 +14,20 @@ impl FnLowerable for PBlock {
}
impl FnLowerable for PStatement {
type Output = VarID;
fn lower(&self, ctx: &mut FnLowerCtx) -> Option<VarID> {
type Output = VarInst;
fn lower(&self, ctx: &mut FnLowerCtx) -> Option<VarInst> {
match self {
super::PStatement::Let(def, e) => {
let def = def.lower(ctx.map, ctx.output)?;
let res = e.lower(ctx);
if let Some(res) = res {
ctx.map.name_var(&def, res);
ctx.map.name_var(&def, res.id);
}
None
}
super::PStatement::Return(e) => {
let src = e.lower(ctx)?;
ctx.push(IRUInstruction::Ret { src });
ctx.push_at(IRUInstruction::Ret { src }, src.span);
None
}
super::PStatement::Expr(e) => e.lower(ctx),