feat: WIP

This commit is contained in:
2025-08-22 21:40:52 +08:00
parent 3c7722a3d2
commit 65bcfcb47b
9 changed files with 312 additions and 154 deletions

View File

@@ -52,7 +52,7 @@ ir! {
pub enum LookupResult {
Stack(StackIdx),
/// The variable was found and resolved to a specific expression.
Expr(ExprId),
PrimOp(ExprId),
/// The variable could not be resolved statically, likely due to a `with` expression.
/// The lookup must be performed dynamically at evaluation time.
Unknown,
@@ -71,8 +71,6 @@ pub trait ResolveContext {
/// Triggers the resolution of a given expression.
fn resolve(&mut self, expr: ExprId) -> Result<()>;
fn resolve_call(&mut self, func: ExprId, arg: ExprId) -> Result<()>;
fn resolve_root(self, expr: ExprId) -> Result<()>;
/// Looks up a variable by name in the current scope.
@@ -233,7 +231,6 @@ impl<Ctx: ResolveContext> Resolve<Ctx> for Call {
fn resolve(self, ctx: &mut Ctx) -> Result<Lir> {
ctx.resolve(self.func)?;
ctx.resolve(self.arg)?;
ctx.resolve_call(self.func, self.arg)?;
Ok(self.to_lir())
}
}
@@ -280,7 +277,7 @@ impl<Ctx: ResolveContext> Resolve<Ctx> for Var {
use LookupResult::*;
match ctx.lookup(&self.sym) {
Stack(idx) => Ok(Lir::StackRef(idx)),
Expr(expr) => Ok(Lir::ExprRef(expr)),
PrimOp(id) => Ok(Lir::ExprRef(id)),
Unknown => Ok(self.to_lir()),
NotFound => Err(Error::resolution_error(format!(
"undefined variable '{}'",