2 Copyright (C) 2017-2018 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
34 // TODO: store these in current PROCESS
39 // Define the address spaces.
42 // Max objects that can be in linked lists (must be < 2^32).
44 // Max size, in objects, of control stack segment.
46 // Max size, in objects, of VECTOR heap.
48 // Max objects reader can handle at once.
49 // TODO: allocate as VECTOR and eliminate this arbitrary limit
56 // The REST pool (in low mem).
58 mmap (0, POOL_OBJCT * sizeof (object), PROT_READ | PROT_WRITE,
59 MAP_PRIVATE | MAP_ANONYMOUS | MAP_32BIT, -1, 0);
60 ptop = 1; // 0 is null
62 // The CONTROL STACKs (TODO: per-PROCESS).
64 mmap (0, STACK_OBJCT * sizeof (object), PROT_READ | PROT_WRITE,
65 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
68 cst += sizeof (frame) / sizeof (object);
72 mmap (0, VECTOR_OBJCT * sizeof (object), PROT_READ | PROT_WRITE,
73 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
76 // Reader stack (TODO: dynamically allocate as VECTOR).
77 object rst_base[READER_OBJCT];
78 object *rst = rst_base + READER_OBJCT;
80 // TODO: push frames for `<REPEAT <PRINT <EVAL <READ>>>>`.
81 // Entire toplevel becomes `for (;;) cf->cont.fn();`
84 while ((n = read (STDIN_FILENO, buf, sizeof (buf))) > 0)
86 // mock GC (no object persistence)
90 assert (buf[n - 1] == '\n');
99 p = read_token (p, &st);
104 assert (st.framelen == 1);
107 push_frame (eval, new_tuple (st.pos, 1), 0);
108 while (cf->cont.val.fn)
118 munmap (cst_base, STACK_OBJCT * sizeof (object));
119 munmap (vhp_base, VECTOR_OBJCT * sizeof (object));
120 munmap (pool, POOL_OBJCT * sizeof (object));