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/>.
30 // TODO: put these in interpreter-wide ctx object
35 vector_object globals;
37 // oblists (move to ASOCs once implemented)
40 // TODO: store these in current PROCESS
45 // Define the address spaces.
48 // Max objects that can be in linked lists (must be < 2^32).
50 // Max size, in objects, of control stack segment.
52 // Max size, in objects, of VECTOR heap.
54 // Max objects reader can handle at once.
55 // TODO: allocate as VECTOR and eliminate this arbitrary limit
59 void init_standard_env ();
64 // The REST pool (in low mem).
66 mmap (0, POOL_OBJCT * sizeof (object), PROT_READ | PROT_WRITE,
67 MAP_PRIVATE | MAP_ANONYMOUS | MAP_32BIT, -1, 0);
68 ptop = 1; // 0 is null
70 // The CONTROL STACKs (TODO: per-PROCESS).
72 mmap (0, STACK_OBJCT * sizeof (object), PROT_READ | PROT_WRITE,
73 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
76 cst += sizeof (frame) / sizeof (object);
80 mmap (0, VECTOR_OBJCT * sizeof (object), PROT_READ | PROT_WRITE,
81 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
84 // Reader stack (TODO: dynamically allocate as VECTOR).
85 object rst_base[READER_OBJCT];
86 object *rst = rst_base + READER_OBJCT;
88 // TODO: push frames for `<REPEAT <PRINT <EVAL <READ>>>>`.
89 // Entire toplevel becomes `for (;;) cf->cont.fn();`
92 // no GC (leak everything)
95 root = oblist_create (13);
96 globals = vector_create (64);
98 while ((n = read (STDIN_FILENO, buf, sizeof (buf))) > 0)
101 assert (buf[n - 1] == '\n');
110 p = read_token (p, &st);
115 assert (st.framelen == 1);
118 push_frame (eval, new_tuple (st.pos, 1), 0);
119 while (cf->cont.val.fn)
127 // debugging oblists...
128 print_object ((object*) &root);
134 munmap (cst_base, STACK_OBJCT * sizeof (object));
135 munmap (vhp_base, VECTOR_OBJCT * sizeof (object));
136 munmap (pool, POOL_OBJCT * sizeof (object));