feat: stack var (WIP)

This commit is contained in:
2025-08-09 08:12:53 +08:00
parent fd182b6233
commit d8ad7fe904
36 changed files with 1521 additions and 1058 deletions

View File

@@ -4,8 +4,10 @@ pub trait BuiltinsContext {}
#[builtins]
pub mod builtins {
use std::rc::Rc;
use nixjit_error::{Error, Result};
use nixjit_eval::Value;
use nixjit_eval::{List, Value};
use nixjit_value::Const;
use super::BuiltinsContext;
@@ -21,7 +23,24 @@ pub mod builtins {
(Int(a), Float(b)) => Float(a as f64 + b),
(Float(a), Int(b)) => Float(a + b as f64),
(Float(a), Float(b)) => Float(a + b),
_ => return Err(Error::EvalError(format!(""))),
(Int(_), b) => {
return Err(Error::eval_error(format!(
"expected an integer but found {}",
b.typename()
)));
}
(Float(_), b) => {
return Err(Error::eval_error(format!(
"expected an float but found {}",
b.typename()
)));
}
(a, _) => {
return Err(Error::eval_error(format!(
"expected an integer but found {}",
a.typename()
)));
}
})
}
@@ -29,16 +48,10 @@ pub mod builtins {
todo!()
}
fn elem_at(list: Value, idx: Value) -> Result<Value> {
let list = list
.try_unwrap_list()
.map_err(|_| Error::EvalError("expected a list but found ...".to_string()))?;
let idx = idx
.try_unwrap_int()
.map_err(|_| Error::EvalError("expected a int but found ...".to_string()))?;
fn elem_at(list: Rc<List>, idx: i64) -> Result<Value> {
list.get(idx as usize)
.ok_or_else(|| {
Error::EvalError(format!(
Error::eval_error(format!(
"'builtins.elemAt' called with index {idx} on a list of size {}",
list.len()
))
@@ -46,7 +59,7 @@ pub mod builtins {
.cloned()
}
fn elem(elem: Value, list: Value) -> Result<Value> {
fn elem(elem: Value, list: Rc<List>) -> Result<Value> {
todo!()
}
}