Compare commits
4 Commits
7eb3acf26f
...
45096f5254
| Author | SHA1 | Date | |
|---|---|---|---|
| 45096f5254 | |||
| b57fea3104 | |||
| 4380fa85c4 | |||
| 99045aa76c |
@@ -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;
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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,14 +470,14 @@ impl<Ctx: CodegenContext> Compile<Ctx> for [(ExprId, ExprId)] {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for &(slot, inner) in self {
|
code!(
|
||||||
let inner_ir = ctx.get_ir(inner);
|
buf, ctx;
|
||||||
code!(
|
"const "
|
||||||
buf, ctx;
|
joined(self.iter(), ",", |ctx: &Ctx, buf, &(slot, inner)| {
|
||||||
"let expr" slot.0 "=$t(()=>(" inner_ir "),"
|
code!(buf, ctx; "e" slot.0 "=$t(()=>(" ctx.get_ir(inner) ")," "'e" slot.0 "')");
|
||||||
"\"expr" slot.0 "\");"
|
})
|
||||||
);
|
";"
|
||||||
}
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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)]
|
||||||
@@ -180,7 +180,7 @@ fn main() -> Result<()> {
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
match cli.command {
|
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::Eval { source } => run_eval(&mut context, source),
|
||||||
Command::Repl => run_repl(&mut context),
|
Command::Repl => run_repl(&mut context),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 {
|
||||||
|| {
|
std::env::set_var("HOME", "/fake-home");
|
||||||
unsafe {
|
|
||||||
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);
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user