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.
19 static struct ao_lisp_builtin *
20 ao_lisp_make_builtin(enum ao_lisp_builtin_id func, int args) {
21 struct ao_lisp_builtin *b = ao_lisp_alloc(sizeof (struct ao_lisp_builtin));
23 b->type = AO_LISP_BUILTIN;
35 struct builtin_func funcs[] = {
36 "car", AO_LISP_LEXPR, builtin_car,
37 "cdr", AO_LISP_LEXPR, builtin_cdr,
38 "cons", AO_LISP_LEXPR, builtin_cons,
39 "quote", AO_LISP_NLAMBDA,builtin_quote,
40 "set", AO_LISP_LEXPR, builtin_set,
41 "setq", AO_LISP_MACRO, builtin_setq,
42 "print", AO_LISP_LEXPR, builtin_print,
43 "+", AO_LISP_LEXPR, builtin_plus,
44 "-", AO_LISP_LEXPR, builtin_minus,
45 "*", AO_LISP_LEXPR, builtin_times,
46 "/", AO_LISP_LEXPR, builtin_divide,
47 "%", AO_LISP_LEXPR, builtin_mod
50 #define N_FUNC (sizeof funcs / sizeof funcs[0])
53 main(int argc, char **argv)
57 struct ao_lisp_atom *a;
59 for (f = 0; f < N_FUNC; f++) {
60 struct ao_lisp_builtin *b = ao_lisp_make_builtin(funcs[f].func, funcs[f].args);
61 struct ao_lisp_atom *a = ao_lisp_atom_intern(funcs[f].name);
62 a->val = ao_lisp_builtin_poly(b);
66 atom = ao_lisp_read();
72 if (ao_lisp_poly_type(atom) != AO_LISP_ATOM) {
73 fprintf(stderr, "input must be atom val pairs\n");
76 ao_lisp_poly_atom(atom)->val = val;
79 printf("/* constant objects, all referenced from atoms */\n\n");
80 printf("#define AO_LISP_POOL_CONST %d\n", ao_lisp_top);
81 printf("extern const uint8_t ao_lisp_const[AO_LISP_POOL_CONST] __attribute__((aligned(4)));\n");
82 printf("#define ao_builtin_atoms 0x%04x\n", ao_lisp_atom_poly(ao_lisp_atoms));
84 for (a = ao_lisp_atoms; a; a = ao_lisp_poly_atom(a->next)) {
86 printf ("#define _ao_lisp_atom_");
93 printf(" 0x%04x\n", ao_lisp_atom_poly(a));
95 printf("#ifdef AO_LISP_CONST_BITS\n");
96 printf("const uint8_t ao_lisp_const[] = {");
97 for (o = 0; o < ao_lisp_top; o++) {
103 c = ao_lisp_const[o];
104 if (' ' < c && c <= '~' && c != '\'')
105 printf (" '%c',", c);
107 printf("0x%02x,", c);
110 printf("#endif /* AO_LISP_CONST_BITS */\n");