feat(builtins): macro
This commit is contained in:
10
evaluator/nixjit_builtins/Cargo.toml
Normal file
10
evaluator/nixjit_builtins/Cargo.toml
Normal file
@@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "nixjit_builtins"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
nixjit_error = { path = "../nixjit_error" }
|
||||
nixjit_eval = { path = "../nixjit_eval" }
|
||||
nixjit_macros = { path = "../nixjit_macros" }
|
||||
nixjit_value = { path = "../nixjit_value" }
|
||||
38
evaluator/nixjit_builtins/src/lib.rs
Normal file
38
evaluator/nixjit_builtins/src/lib.rs
Normal file
@@ -0,0 +1,38 @@
|
||||
use nixjit_macros::builtins;
|
||||
use nixjit_eval::EvalContext;
|
||||
|
||||
pub trait BuiltinsContext: EvalContext {}
|
||||
|
||||
#[builtins]
|
||||
mod builtins {
|
||||
use nixjit_error::{Error, Result};
|
||||
use nixjit_eval::Value;
|
||||
use nixjit_value::Const;
|
||||
|
||||
use super::BuiltinsContext;
|
||||
|
||||
const TRUE: Const = Const::Bool(true);
|
||||
const FALSE: Const = Const::Bool(false);
|
||||
const NULL: Const = Const::Null;
|
||||
|
||||
fn add<Ctx: BuiltinsContext>(a: Value<Ctx>, b: Value<Ctx>) -> Result<Value<Ctx>> {
|
||||
use Value::*;
|
||||
Ok(match (a, b) {
|
||||
(Int(a), Int(b)) => Int(a + b),
|
||||
(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),
|
||||
(a @ Value::Catchable(_), _) => a,
|
||||
(_, b @ Value::Catchable(_)) => b,
|
||||
_ => return Err(Error::EvalError(format!(""))),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn import<Ctx: BuiltinsContext>(ctx: &mut Ctx, path: Value<Ctx>) -> Result<Value<Ctx>> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn elem_at<Ctx: BuiltinsContext>(list: Value<Ctx>, idx: Value<Ctx>) -> Result<Value<Ctx>> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user