feat: implement assert
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"target": "ES2022",
|
||||
"module": "ESNext",
|
||||
"lib": ["ES2020", "DOM"],
|
||||
"lib": ["ES2022", "DOM"],
|
||||
"moduleResolution": "bundler",
|
||||
"strict": true,
|
||||
"noUnusedLocals": false,
|
||||
|
||||
@@ -65,7 +65,11 @@ impl<Ctx: CodegenContext> Compile<Ctx> for Ir {
|
||||
Ir::Builtin(_) => "Nix.builtins".to_string(),
|
||||
Ir::ConcatStrings(x) => x.compile(ctx),
|
||||
Ir::HasAttr(x) => x.compile(ctx),
|
||||
ir => todo!("{ir:?}"),
|
||||
&Ir::Assert(Assert { assertion, expr }) => {
|
||||
let assertion = ctx.get_ir(assertion).compile(ctx);
|
||||
let expr = ctx.get_ir(expr).compile(ctx);
|
||||
format!("({assertion})?({expr}):(()=>{{throw \"assertion failed\"}})()")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,6 @@ ir! {
|
||||
Select,
|
||||
If,
|
||||
Call,
|
||||
With,
|
||||
Assert,
|
||||
ConcatStrings,
|
||||
Const,
|
||||
@@ -59,7 +58,6 @@ ir! {
|
||||
Func,
|
||||
Let,
|
||||
Arg(ArgId),
|
||||
PrimOp(PrimOpId),
|
||||
ExprRef(ExprId),
|
||||
Thunk(ExprId),
|
||||
Builtin,
|
||||
@@ -150,10 +148,6 @@ pub struct ExprId(pub usize);
|
||||
|
||||
pub type SymId = SymbolU32;
|
||||
|
||||
#[repr(transparent)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct PrimOpId(pub usize);
|
||||
|
||||
#[repr(transparent)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub struct ArgId(pub usize);
|
||||
@@ -342,15 +336,6 @@ pub struct Call {
|
||||
pub arg: ExprId,
|
||||
}
|
||||
|
||||
/// Represents a `with` expression.
|
||||
#[derive(Debug)]
|
||||
pub struct With {
|
||||
/// The namespace to bring into scope.
|
||||
pub namespace: ExprId,
|
||||
/// The expression to be evaluated within the new scope.
|
||||
pub expr: ExprId,
|
||||
}
|
||||
|
||||
/// Represents an `assert` expression.
|
||||
#[derive(Debug)]
|
||||
pub struct Assert {
|
||||
|
||||
@@ -353,7 +353,7 @@ fn to_value<'a, 'b>(val: v8::Local<'a, v8::Value>, ctx: &RuntimeContext<'a, 'b>)
|
||||
.collect();
|
||||
Value::AttrSet(AttrSet::new(attrs))
|
||||
}
|
||||
_ => todo!("{}", val.type_repr()),
|
||||
_ => unimplemented!("can not convert {} to NixValue", val.type_repr()),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user