2 Copyright (C) 2017 Keziah Wesley
4 You can redistribute and/or modify this file under the terms of the
5 GNU Affero General Public License as published by the Free Software
6 Foundation, either version 3 of the License, or (at your option) any
9 This file 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 Affero General Public License for more details.
14 You should have received a copy of the GNU Affero General Public
15 License along with this file. If not, see
16 <http://www.gnu.org/licenses/>.
28 // TODO: put these in interpreter-wide ctx object
33 // TODO: store these in current PROCESS
38 // Define the address spaces.
41 // Max objects that can be in linked lists (must be < 2^32).
43 // Max size, in objects, of control stack segment.
45 // Max size, in objects, of VECTOR heap.
47 // Max objects reader can handle at once.
48 // TODO: allocate as VECTOR and eliminate this arbitrary limit
55 // The REST pool (in low mem).
57 mmap (0, POOL_OBJCT * sizeof (object), PROT_READ | PROT_WRITE,
58 MAP_PRIVATE | MAP_ANONYMOUS | MAP_32BIT, -1, 0);
61 // The CONTROL STACKs (TODO: per-PROCESS).
63 mmap (0, STACK_OBJCT * sizeof (object), PROT_READ | PROT_WRITE,
64 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
67 cst += sizeof (frame) / sizeof (object);
71 mmap (0, VECTOR_OBJCT * sizeof (object), PROT_READ | PROT_WRITE,
72 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
75 // Reader stack (TODO: dynamically allocate as VECTOR).
76 object rst_base[READER_OBJCT];
77 object *rst = rst_base + READER_OBJCT;
79 // TODO: push frames for `<REPEAT <PRINT <EVAL <READ>>>>`.
80 // Entire toplevel becomes `for (;;) cf->cont.fn();`
83 while ((n = read (STDIN_FILENO, buf, sizeof (buf))) > 0)
85 // mock GC (no object persistence)
89 assert (buf[n - 1] == '\n');
98 p = read_token (p, &st);
103 assert (st.framelen == 1);
106 push_frame (eval, new_tuple (st.pos, 1), 0);
114 // debugging: print without eval
115 print_object (st.pos);
120 munmap (cst_base, STACK_OBJCT * sizeof (object));
121 munmap (vhp_base, VECTOR_OBJCT * sizeof (object));
122 munmap (pool_base, POOL_OBJCT * sizeof (object));