Compare commits

..

4 Commits

Author SHA1 Message Date
45096f5254 fix: fetchGit 2026-02-19 22:34:41 +08:00
b57fea3104 optimize: short-circuit update (//) 2026-02-19 21:54:55 +08:00
4380fa85c4 optimize: compact 2026-02-19 21:14:02 +08:00
99045aa76c chore: fmt 2026-02-19 20:14:06 +08:00
6 changed files with 26 additions and 23 deletions

View File

@@ -185,7 +185,7 @@ export const fetchGit = (args: NixValue): NixAttrs => {
]); ]);
} }
const attrs = forceAttrs(args); const attrs = forceAttrs(args);
const url = forceStringValue(select("attrs", ["url"])); const url = forceStringValue(select(attrs, ["url"]));
const gitRef = attrs.has("ref") ? forceStringValue(attrs.get("ref") as NixValue) : null; const gitRef = attrs.has("ref") ? forceStringValue(attrs.get("ref") as NixValue) : null;
const rev = attrs.has("rev") ? forceStringValue(attrs.get("rev") as NixValue) : null; const rev = attrs.has("rev") ? forceStringValue(attrs.get("rev") as NixValue) : null;
const shallow = attrs.has("shallow") ? forceBool(attrs.get("shallow") as NixValue) : false; const shallow = attrs.has("shallow") ? forceBool(attrs.get("shallow") as NixValue) : false;

View File

@@ -270,6 +270,12 @@ export const op = {
update: (a: NixValue, b: NixValue): NixAttrs => { update: (a: NixValue, b: NixValue): NixAttrs => {
const mapA = forceAttrs(a); const mapA = forceAttrs(a);
const mapB = forceAttrs(b); const mapB = forceAttrs(b);
if (mapA.size === 0) {
return mapB;
}
if (mapB.size === 0) {
return mapA;
}
const result: NixAttrs = new Map(mapA); const result: NixAttrs = new Map(mapA);
for (const [k, v] of mapB) { for (const [k, v] of mapB) {
result.set(k, v); result.set(k, v);

View File

@@ -238,12 +238,12 @@ impl<Ctx: CodegenContext> Compile<Ctx> for Ir {
Ir::List(x) => x.compile(ctx, buf), Ir::List(x) => x.compile(ctx, buf),
Ir::Call(x) => x.compile(ctx, buf), Ir::Call(x) => x.compile(ctx, buf),
Ir::Arg(x) => { Ir::Arg(x) => {
code!(buf, "arg{}", x.inner.0); code!(buf, "a{}", x.inner.0);
} }
Ir::TopLevel(x) => x.compile(ctx, buf), Ir::TopLevel(x) => x.compile(ctx, buf),
Ir::Select(x) => x.compile(ctx, buf), Ir::Select(x) => x.compile(ctx, buf),
&Ir::Thunk(Thunk { inner: expr_id, .. }) => { &Ir::Thunk(Thunk { inner: expr_id, .. }) => {
code!(buf, "expr{}", expr_id.0); code!(buf, "e{}", expr_id.0);
} }
Ir::Builtins(_) => { Ir::Builtins(_) => {
// Nix.builtins // Nix.builtins
@@ -416,7 +416,7 @@ impl<Ctx: CodegenContext> Compile<Ctx> for Func {
ellipsis, ellipsis,
}) = &self.param }) = &self.param
{ {
code!(buf, "$mf(arg{}=>", id); code!(buf, "$mf(a{}=>", id);
if has_thunks { if has_thunks {
code!(buf, ctx; "{" self.thunks "return " self.body "}"); code!(buf, ctx; "{" self.thunks "return " self.body "}");
} else { } else {
@@ -440,7 +440,7 @@ impl<Ctx: CodegenContext> Compile<Ctx> for Func {
")" ")"
); );
} else { } else {
code!(buf, "arg{}=>", id); code!(buf, "a{}=>", id);
if has_thunks { if has_thunks {
code!(buf, ctx; "{" self.thunks "return " self.body "}"); code!(buf, ctx; "{" self.thunks "return " self.body "}");
} else { } else {
@@ -470,16 +470,16 @@ impl<Ctx: CodegenContext> Compile<Ctx> for [(ExprId, ExprId)] {
return; return;
} }
for &(slot, inner) in self {
let inner_ir = ctx.get_ir(inner);
code!( code!(
buf, ctx; buf, ctx;
"let expr" slot.0 "=$t(()=>(" inner_ir ")," "const "
"\"expr" slot.0 "\");" joined(self.iter(), ",", |ctx: &Ctx, buf, &(slot, inner)| {
code!(buf, ctx; "e" slot.0 "=$t(()=>(" ctx.get_ir(inner) ")," "'e" slot.0 "')");
})
";"
); );
} }
} }
}
impl<Ctx: CodegenContext> Compile<Ctx> for TopLevel { impl<Ctx: CodegenContext> Compile<Ctx> for TopLevel {
fn compile(&self, ctx: &Ctx, buf: &mut CodeBuffer) { fn compile(&self, ctx: &Ctx, buf: &mut CodeBuffer) {

View File

@@ -30,7 +30,7 @@ enum Command {
#[clap(flatten)] #[clap(flatten)]
source: ExprSource, source: ExprSource,
#[arg(long)] #[arg(long)]
silent: bool silent: bool,
}, },
Eval { Eval {
#[clap(flatten)] #[clap(flatten)]

View File

@@ -192,14 +192,11 @@ eval_okay_test!(
eval_okay_test!(partition); eval_okay_test!(partition);
eval_okay_test!(path); eval_okay_test!(path);
eval_okay_test!(pathexists); eval_okay_test!(pathexists);
eval_okay_test!( eval_okay_test!(path_string_interpolation, || {
path_string_interpolation,
|| {
unsafe { unsafe {
std::env::set_var("HOME", "/fake-home"); std::env::set_var("HOME", "/fake-home");
} }
} });
);
eval_okay_test!(patterns); eval_okay_test!(patterns);
eval_okay_test!(print); eval_okay_test!(print);
eval_okay_test!(readDir); eval_okay_test!(readDir);

View File

@@ -6,6 +6,7 @@ mod findfile;
mod free_globals; mod free_globals;
mod functions; mod functions;
mod io_operations; mod io_operations;
mod lang;
mod numeric_types; mod numeric_types;
mod operators; mod operators;
mod path_operations; mod path_operations;
@@ -13,5 +14,4 @@ mod regex;
mod string_context; mod string_context;
mod thunk_scope; mod thunk_scope;
mod to_string; mod to_string;
mod lang;
mod utils; mod utils;