mes.h (6920B)
1 /* -*-comment-start: "//";comment-end:""-*- 2 * GNU Mes --- Maxwell Equations of Software 3 * Copyright © 2016,2017,2018,2019,2020,2021,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> 4 * Copyright © 2022 Timothy Sample <samplet@ngyro.com> 5 * 6 * This file is part of GNU Mes. 7 * 8 * GNU Mes is free software; you can redistribute it and/or modify it 9 * under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 3 of the License, or (at 11 * your option) any later version. 12 * 13 * GNU Mes is distributed in the hope that it will be useful, but 14 * WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. 20 */ 21 22 #ifndef __MES_MES_H 23 #define __MES_MES_H 24 25 #include <sys/types.h> 26 #include "mes/cc.h" 27 28 struct scm 29 { 30 long type; 31 union 32 { 33 struct scm *car; 34 long car_value; 35 char *bytes; 36 long length; 37 struct scm *ref; 38 struct scm *binding; 39 struct scm *macro; 40 long port; 41 }; 42 union 43 { 44 struct scm *cdr; 45 long cdr_value; 46 struct scm *closure; 47 struct scm *continuation; 48 char *name; 49 struct scm *string; 50 struct scm *structure; 51 long value; 52 FUNCTION function; 53 struct scm *vector; 54 long lexical_p; /* for bindings */ 55 }; 56 }; 57 58 /* M2-Planet does not support pointer arithmetic. Explicitly compensate 59 for that by multiplying with M2_CELL_SIZE when using cell 60 pointers. */ 61 #if __M2__ 62 #define M2_CELL_SIZE sizeof (struct scm) 63 #else 64 #define M2_CELL_SIZE 1 65 #endif 66 67 /* mes */ 68 extern char *g_datadir; 69 extern int g_debug; 70 extern char *g_buf; 71 extern int g_continuations; 72 extern struct scm *g_symbols; 73 extern struct scm *g_symbol_max; 74 extern int g_mini; 75 76 /* a/env */ 77 extern struct scm *R0; 78 /* param 1 */ 79 extern struct scm *R1; 80 /* save 2 */ 81 extern struct scm *R2; 82 /* continuation */ 83 extern struct scm *R3; 84 /* initial module obarray */ 85 extern struct scm *M0; 86 /* current module */ 87 extern struct scm *M1; 88 /* macro */ 89 extern struct scm *g_macros; 90 extern struct scm *g_ports; 91 92 /* gc */ 93 extern size_t ARENA_SIZE; 94 extern size_t MAX_ARENA_SIZE; 95 extern size_t STACK_SIZE; 96 extern size_t JAM_SIZE; 97 extern size_t GC_SAFETY; 98 extern size_t MAX_STRING; 99 extern char *g_arena; 100 extern struct scm *cell_arena; 101 extern struct scm *cell_zero; 102 103 extern struct scm *g_free; 104 extern struct scm *g_symbol; 105 106 extern struct scm **g_stack_array; 107 extern struct scm *g_cells; 108 extern struct scm *g_news; 109 extern long g_stack; 110 extern size_t gc_count; 111 extern struct timespec *gc_start_time; 112 extern struct timespec *gc_end_time; 113 extern size_t gc_time; 114 115 extern char **__execl_c_argv; 116 extern char **__execle_c_env; 117 extern char *__open_boot_buf; 118 extern char *__open_boot_file_name; 119 extern char *__setenv_buf; 120 extern char *__reader_read_char_buf; 121 extern struct timespec *g_start_time; 122 extern struct timeval *__gettimeofday_time; 123 extern struct timespec *__get_internal_run_time_ts; 124 extern struct utsname *__uts; 125 126 extern struct scm *scm_hash_table_type; 127 extern struct scm *scm_variable_type; 128 129 struct scm *cast_charp_to_scmp (char const *i); 130 struct scm **cast_charp_to_scmpp (char const *i); 131 char *cast_voidp_to_charp (void const *i); 132 long cast_scmp_to_long (struct scm *i); 133 char *cast_scmp_to_charp (struct scm *i); 134 135 struct scm *alloc (long n); 136 struct scm *apply (struct scm *f, struct scm *x, struct scm *a); 137 struct scm *apply_builtin (struct scm *fn, struct scm *x); 138 struct scm *apply_builtin0 (struct scm *fn); 139 struct scm *apply_builtin1 (struct scm *fn, struct scm *x); 140 struct scm *apply_builtin2 (struct scm *fn, struct scm *x, struct scm *y); 141 struct scm *apply_builtin3 (struct scm *fn, struct scm *x, struct scm *y, struct scm *z); 142 struct scm *builtin_name (struct scm *builtin); 143 struct scm *cstring_to_list (char const *s); 144 struct scm *cstring_to_symbol (char const *s); 145 struct scm *cell_ref (struct scm *cell, long index); 146 struct scm *current_module_variable (struct scm *name, struct scm *define_p); 147 struct scm *standard_eval_closure (struct scm *name, struct scm *define_p); 148 struct scm *standard_interface_eval_closure (struct scm *name, struct scm *define_p); 149 struct scm *module_make_local_var_x (struct scm *module, struct scm *name); 150 struct scm *module_variable (struct scm *module, struct scm *name); 151 struct scm *fdisplay_ (struct scm *, int, int); 152 struct scm *init_symbols (); 153 struct scm *init_time (struct scm *a); 154 struct scm *lookup_binding (struct scm *name, struct scm *define_p); 155 struct scm *lookup_value (struct scm *name); 156 struct scm *make_builtin_type (); 157 struct scm *make_bytes (size_t length); 158 struct scm *make_cell (long type, struct scm *car, struct scm *cdr); 159 struct scm *make_pointer_cell (long type, long car, void *cdr); 160 struct scm *make_value_cell (long type, long car, long cdr); 161 struct scm *make_char (int n); 162 struct scm *make_continuation (long n); 163 struct scm *make_hash_table_ (long size); 164 struct scm *make_hash_table_type (); 165 struct scm *make_initial_module (struct scm *a); 166 struct scm *make_macro (struct scm *name, struct scm *x); 167 struct scm *make_number (long n); 168 struct scm *make_ref (struct scm *x); 169 struct scm *make_string (char const *s, size_t length); 170 struct scm *make_string0 (char const *s); 171 struct scm *make_string_port (struct scm *x); 172 struct scm *make_variable_type (); 173 struct scm *make_vector_ (long k, struct scm *e); 174 struct scm *mes_builtins (struct scm *a); 175 struct scm *push_cc (struct scm *p1, struct scm *p2, struct scm *a, struct scm *c); 176 struct scm *set_x (struct scm *x, struct scm *e, int define_p); 177 struct scm *struct_ref_ (struct scm *x, long i); 178 struct scm *struct_set_x_ (struct scm *x, long i, struct scm *e); 179 struct scm *vector_ref_ (struct scm *x, long i); 180 struct scm *vector_set_x_ (struct scm *x, long i, struct scm *e); 181 FUNCTION builtin_function (struct scm *builtin); 182 void assert_num (long pos, struct scm *x); 183 void assert_range (int assert, long x); 184 void assert_struct (long pos, struct scm *x); 185 #if 0 186 void assert_type (long type, char const *name_name, struct scm *x) 187 #endif 188 char *cell_bytes (struct scm *x); 189 int peekchar (); 190 int readchar (); 191 int unreadchar (); 192 long gc_free (); 193 long length__ (struct scm *x); 194 size_t bytes_cells (size_t length); 195 void assert_max_string (size_t i, char const *msg, char const *string); 196 void assert_msg (int check, char *msg); 197 void assert_number (char const *name, struct scm *x); 198 void copy_cell (struct scm *to, struct scm *from); 199 void gc_ (); 200 void gc_dump_arena (struct scm *cells, long size); 201 void gc_init (); 202 void gc_peek_frame (); 203 void gc_pop_frame (); 204 void gc_push_frame (); 205 void gc_stats_ (char const* where); 206 void init_symbols_ (); 207 long seconds_and_nanoseconds_to_long (long s, long ns); 208 209 #include "mes/builtins.h" 210 #include "mes/constants.h" 211 #include "mes/symbols.h" 212 213 #endif /* __MES_MES_H */