2 * Copyright © 2016 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
15 #include "ao_scheme.h"
20 static char save_file[] = "scheme.image";
23 ao_scheme_os_save(void)
25 FILE *save = fopen(save_file, "w");
31 fwrite(ao_scheme_pool, 1, AO_SCHEME_POOL_TOTAL, save);
37 ao_scheme_os_restore_save(struct ao_scheme_os_save *save, int offset)
39 FILE *restore = fopen(save_file, "r");
46 fseek(restore, offset, SEEK_SET);
47 ret = fread(save, sizeof (struct ao_scheme_os_save), 1, restore);
55 ao_scheme_os_restore(void)
57 FILE *restore = fopen(save_file, "r");
64 ret = fread(ao_scheme_pool, 1, AO_SCHEME_POOL_TOTAL, restore);
66 if (ret != AO_SCHEME_POOL_TOTAL)
71 static const struct option options[] = {
72 { .name = "load", .has_arg = 1, .val = 'l' },
76 static void usage(char *program)
78 fprintf(stderr, "usage: %s [--load=<library> ...] <program ...>\n", program);
84 if (ao_scheme_exception & AO_SCHEME_EXIT) {
87 if (v == _ao_scheme_bool_true)
91 if (ao_scheme_is_integer(v))
92 ret = ao_scheme_poly_integer(v);
105 in = fopen(name, "r");
114 } while (c != EOF && c != '\n');
118 v = ao_scheme_read_eval_print(in, NULL, false);
124 main (int argc, char **argv)
128 while ((o = getopt_long(argc, argv, "?l:", options, NULL)) != -1) {
134 #ifdef AO_SCHEME_FEATURE_POSIX
135 ao_scheme_set_argv(&argv[argc]);
144 #ifdef AO_SCHEME_FEATURE_POSIX
145 ao_scheme_set_argv(argv + optind);
148 run_file(argv[optind]);
151 v = ao_scheme_read_eval_print(stdin, stdout, true);
157 printf ("collects: full: %lu incremental %lu\n",
158 ao_scheme_collects[AO_SCHEME_COLLECT_FULL],
159 ao_scheme_collects[AO_SCHEME_COLLECT_INCREMENTAL]);
161 printf ("freed: full %lu incremental %lu\n",
162 ao_scheme_freed[AO_SCHEME_COLLECT_FULL],
163 ao_scheme_freed[AO_SCHEME_COLLECT_INCREMENTAL]);
165 printf("loops: full %lu incremental %lu\n",
166 ao_scheme_loops[AO_SCHEME_COLLECT_FULL],
167 ao_scheme_loops[AO_SCHEME_COLLECT_INCREMENTAL]);
169 printf("loops per collect: full %f incremental %f\n",
170 (double) ao_scheme_loops[AO_SCHEME_COLLECT_FULL] /
171 (double) ao_scheme_collects[AO_SCHEME_COLLECT_FULL],
172 (double) ao_scheme_loops[AO_SCHEME_COLLECT_INCREMENTAL] /
173 (double) ao_scheme_collects[AO_SCHEME_COLLECT_INCREMENTAL]);
175 printf("freed per collect: full %f incremental %f\n",
176 (double) ao_scheme_freed[AO_SCHEME_COLLECT_FULL] /
177 (double) ao_scheme_collects[AO_SCHEME_COLLECT_FULL],
178 (double) ao_scheme_freed[AO_SCHEME_COLLECT_INCREMENTAL] /
179 (double) ao_scheme_collects[AO_SCHEME_COLLECT_INCREMENTAL]);
181 printf("freed per loop: full %f incremental %f\n",
182 (double) ao_scheme_freed[AO_SCHEME_COLLECT_FULL] /
183 (double) ao_scheme_loops[AO_SCHEME_COLLECT_FULL],
184 (double) ao_scheme_freed[AO_SCHEME_COLLECT_INCREMENTAL] /
185 (double) ao_scheme_loops[AO_SCHEME_COLLECT_INCREMENTAL]);