Skip to content

Commit

Permalink
libnixt: allow eval decoded expression (#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
inclyc authored Apr 8, 2024
1 parent 83a1305 commit 8fb17e8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
7 changes: 6 additions & 1 deletion libnixt/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ libnixt_test_exe = executable(
dependencies: [ gtest_main, nixt ]
)

subdir('tools')
nixt_decode = executable(
'nixt-decode',
'tools/nixt-decode.cpp',
dependencies: [ nixt ],
install: true
)

test(
'unit/libnixt',
Expand Down
1 change: 0 additions & 1 deletion libnixt/tools/meson.build

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,24 @@
#include "nixt/InitEval.h"
#include "nixt/PtrPool.h"

int main() {
namespace {

// --eval, -e
// Should we perform eval?
bool Eval = false;

void parseArgs(int Argc, const char *Argv[]) {
for (int I = 0; I < Argc; I++) {
std::string_view Arg(Argv[I]);
if (Arg == "--eval" || Arg == "-e")
Eval = true;
}
}

} // namespace

int main(int Argc, const char *Argv[]) {
parseArgs(Argc, Argv);
nixt::initEval();
std::unique_ptr<nix::EvalState> State(
new nix::EvalState{{}, nix::openStore("dummy://")});
Expand All @@ -24,7 +41,18 @@ int main() {

auto *AST = nixt::deserializeHookable(Data, Ctx, Pool, VMap, EMap);

AST->show(State->symbols, std::cout);
if (Eval) {
try {
AST->bindVars(*State, State->staticBaseEnv);
nix::Value V;
State->eval(AST, V);
V.print(State->symbols, std::cout);
} catch (nix::BaseError &E) {
std::cerr << E.what() << "\n";
}
} else {
AST->show(State->symbols, std::cout);
}

return 0;
}
5 changes: 0 additions & 5 deletions libnixt/tools/nixt-decode/meson.build

This file was deleted.

0 comments on commit 8fb17e8

Please sign in to comment.