Compare commits
3 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
56761e0ab7 | ||
|
|
2dd82c6784 | ||
| c44f737a0e |
4 changed files with 37 additions and 11 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -13,3 +13,4 @@ stats.ods
|
|||
|
||||
bin/
|
||||
typescript
|
||||
.main.c.swp
|
||||
|
|
|
|||
|
|
@ -30,6 +30,13 @@
|
|||
python3
|
||||
];
|
||||
};
|
||||
packages.default = pkgs.stdenv.mkDerivation rec {
|
||||
pname = "4-variable-simplifier";
|
||||
version = "1.0";
|
||||
src = ./.;
|
||||
nativeBuildInputs = with pkgs; [ gcc gnumake ];
|
||||
buildInputs = with pkgs; [ readline.dev ];
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
27
main.c
27
main.c
|
|
@ -41,6 +41,8 @@ struct {
|
|||
bool ternary;
|
||||
} use_operators;
|
||||
|
||||
bool print_truthtable = false;
|
||||
|
||||
bool assume_yes = false;
|
||||
|
||||
bool verbose = false;
|
||||
|
|
@ -59,8 +61,12 @@ static void parse_args(int argc, char* const* argv)
|
|||
|
||||
print_with_color = isatty(1);
|
||||
|
||||
for (int opt; (opt = getopt(argc, argv, "pyqmvc:eEo:C:B")) != -1; ) switch (opt)
|
||||
for (int opt; (opt = getopt(argc, argv, "tpyqmvc:eEo:C:B")) != -1; ) switch (opt)
|
||||
{
|
||||
case 't':
|
||||
print_truthtable = true;
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
print_all_and_quit = true;
|
||||
break;
|
||||
|
|
@ -1514,7 +1520,10 @@ int main(int argc, char* const* argv)
|
|||
{
|
||||
uint16_t truthtable = evaluate(command);
|
||||
|
||||
// printf("truthtable = 0b%016b\n", truthtable);
|
||||
if (print_truthtable)
|
||||
{
|
||||
printf("truthtable: 0b%016b\n", truthtable);
|
||||
}
|
||||
|
||||
if (lookup[truthtable].kind == ek_unreachable)
|
||||
{
|
||||
|
|
@ -1522,7 +1531,8 @@ int main(int argc, char* const* argv)
|
|||
}
|
||||
else
|
||||
{
|
||||
printf("%2i: ", lookup[truthtable].cost), print(truthtable, 0), puts("");
|
||||
// printf("%2i: ", lookup[truthtable].cost), print(truthtable, 0), puts("");
|
||||
print(truthtable, 0), puts("");
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -1544,7 +1554,10 @@ int main(int argc, char* const* argv)
|
|||
|
||||
uint16_t truthtable = evaluate(line);
|
||||
|
||||
// printf("truthtable = 0b%016b\n", truthtable);
|
||||
if (print_truthtable)
|
||||
{
|
||||
printf("truthtable: 0b%016b\n", truthtable);
|
||||
}
|
||||
|
||||
if (lookup[truthtable].kind == ek_unreachable)
|
||||
{
|
||||
|
|
@ -1552,8 +1565,10 @@ int main(int argc, char* const* argv)
|
|||
}
|
||||
else
|
||||
{
|
||||
printf("%2i: ", lookup[truthtable].cost),
|
||||
print(truthtable, 0), puts("");
|
||||
// printf("%2i: ", lookup[truthtable].cost);
|
||||
printf(" ");
|
||||
|
||||
print(truthtable, 0), puts("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
13
makefile
13
makefile
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
# vim: noexpandtab tabstop=4 :
|
||||
|
||||
PREFIX ?= ${out}
|
||||
PREFIX ?= ${HOME}
|
||||
|
||||
args =
|
||||
|
|
@ -14,21 +15,23 @@ cflags = -Werror -Wall -Wextra -Wstrict-prototypes -Wfatal-errors
|
|||
|
||||
cflags += -O3
|
||||
|
||||
cflags += -Wno-unused
|
||||
# cflags += -Wno-unused
|
||||
|
||||
ldflags += -lreadline -lm
|
||||
|
||||
/tmp/4-variable-simplifier: main.c
|
||||
bin/4-variable-simplifier: main.c | bin/
|
||||
$(cc) $(cppflags) $(cflags) $< -o $@ $(ldflags)
|
||||
|
||||
run: /tmp/4-variable-simplifier
|
||||
bin/:
|
||||
mkdir -pv bin
|
||||
|
||||
run: bin/4-variable-simplifier
|
||||
$< $(args)
|
||||
|
||||
install: ${PREFIX}/bin/4-variable-simplifier
|
||||
|
||||
${PREFIX}/bin/4-variable-simplifier: /tmp/4-variable-simplifier
|
||||
${PREFIX}/bin/4-variable-simplifier: bin/4-variable-simplifier
|
||||
mkdir -pv ${PREFIX}/bin/
|
||||
cp -vau $< $@
|
||||
|
||||
# nix --extra-experimental-features nix-command --extra-experimental-features flakes develop --command 'make'
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue