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 url = forceStringValue(select("attrs", ["url"]));
const url = forceStringValue(select(attrs, ["url"]));
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 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 => {
const mapA = forceAttrs(a);
const mapB = forceAttrs(b);
if (mapA.size === 0) {
return mapB;
}
if (mapB.size === 0) {
return mapA;
}
const result: NixAttrs = new Map(mapA);
for (const [k, v] of mapB) {
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::Call(x) => x.compile(ctx, buf),
Ir::Arg(x) => {
code!(buf, "arg{}", x.inner.0);
code!(buf, "a{}", x.inner.0);
}
Ir::TopLevel(x) => x.compile(ctx, buf),
Ir::Select(x) => x.compile(ctx, buf),
&Ir::Thunk(Thunk { inner: expr_id, .. }) => {
code!(buf, "expr{}", expr_id.0);
code!(buf, "e{}", expr_id.0);
}
Ir::Builtins(_) => {
// Nix.builtins
@@ -416,7 +416,7 @@ impl<Ctx: CodegenContext> Compile<Ctx> for Func {
ellipsis,
}) = &self.param
{
code!(buf, "$mf(arg{}=>", id);
code!(buf, "$mf(a{}=>", id);
if has_thunks {
code!(buf, ctx; "{" self.thunks "return " self.body "}");
} else {
@@ -440,7 +440,7 @@ impl<Ctx: CodegenContext> Compile<Ctx> for Func {
")"
);
} else {
code!(buf, "arg{}=>", id);
code!(buf, "a{}=>", id);
if has_thunks {
code!(buf, ctx; "{" self.thunks "return " self.body "}");
} else {
@@ -470,15 +470,15 @@ impl<Ctx: CodegenContext> Compile<Ctx> for [(ExprId, ExprId)] {
return;
}
for &(slot, inner) in self {
let inner_ir = ctx.get_ir(inner);
code!(
buf, ctx;
"let expr" slot.0 "=$t(()=>(" inner_ir "),"
"\"expr" slot.0 "\");"
"const "
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 {

View File

@@ -30,7 +30,7 @@ enum Command {
#[clap(flatten)]
source: ExprSource,
#[arg(long)]
silent: bool
silent: bool,
},
Eval {
#[clap(flatten)]
@@ -180,7 +180,7 @@ fn main() -> Result<()> {
)?;
match cli.command {
Command::Compile { source , silent } => run_compile(&mut context, source, silent),
Command::Compile { source, silent } => run_compile(&mut context, source, silent),
Command::Eval { source } => run_eval(&mut context, source),
Command::Repl => run_repl(&mut context),
}

View File

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

View File

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