ref: 1b0c99b7821ae56932c1e1f1ac9b910aaff51f9e
parent: 8accc5fc85f2072f6f6e81f89a10688f089e7abc
author: Lennart Augustsson <lennart@augustsson.net>
date: Thu Oct 12 10:21:21 EDT 2023
Add a flag to eval.c to just write out the GCed combinators.
--- a/Makefile
+++ b/Makefile
@@ -153,7 +153,8 @@
tmp/eval.c: src/runtime/eval.c $(EVAL) $(COMB)$(MHS).comb
@mkdir -p tmp
cp src/runtime/eval.c tmp/eval.c
- $(EVAL) +RTS -K10M -r$(COMB)$(MHS).comb -RTS -ilib -iTools -r Compress < $(COMB)$(MHS).comb | \
+ $(EVAL) +RTS -r$(COMB)$(MHS).comb -o$(COMB)$(MHS)-gc.comb -RTS
+ $(EVAL) +RTS -K10M -r$(COMB)$(MHS).comb -RTS -ilib -iTools -r Compress < $(COMB)$(MHS)-gc.comb | \
$(EVAL) +RTS -K10M -r$(COMB)$(MHS).comb -RTS -ilib -iTools -r Addcombs >> tmp/eval.c
###
--- a/src/runtime/eval.c
+++ b/src/runtime/eval.c
@@ -2190,7 +2190,8 @@
int
main(int argc, char **argv)
{- char *fn = 0;
+ char *inname = 0;
+ char *outname = 0;
char **av;
size_t file_size;
NODEPTR prog;
@@ -2215,9 +2216,11 @@
else if (strncmp(p, "-K", 2) == 0)
stack_size = memsize(&p[2]);
else if (strncmp(p, "-r", 2) == 0)
- fn = &p[2];
+ inname = &p[2];
+ else if (strncmp(p, "-o", 2) == 0)
+ outname = &p[2];
else
- ERR("Usage: eval [+RTS [-v] [-Hheap-size] [-Kstack-size] [-rFILE] -RTS] arg ...");+ ERR("Usage: eval [+RTS [-v] [-Hheap-size] [-Kstack-size] [-rFILE] [-oFILE] -RTS] arg ...");}
} else { if (strcmp(p, "+RTS") == 0) {@@ -2229,8 +2232,8 @@
}
glob_argc = av - glob_argv;
- if (fn == 0)
- fn = "out.comb";
+ if (inname == 0)
+ inname = "out.comb";
init_nodes();
stack = malloc(sizeof(NODEPTR) * stack_size);
@@ -2252,16 +2255,19 @@
prog = parse_top(bf);
bf->closeb(bf);
} else {- prog = parse_file(fn, &file_size);
+ prog = parse_file(inname, &file_size);
}
PUSH(prog); gc(); prog = TOP(0); POP(1);
heapoffs_t start_size = num_marked;
- if (0) {- /* Save GCed file, it's smaller */
- FILE *out = fopen("gc.comb", "w");+ if (outname) {+ /* Save GCed file (smaller), and exit. */
+ FILE *out = fopen(outname, "w");
+ if (!out)
+ ERR("output file");print(out, prog, 1);
fclose(out);
+ exit(0);
}
if (verbose > 2) {//pp(stdout, prog);
--
⑨