mes.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /* -*-comment-start: "//";comment-end:""-*-
  2. * GNU Mes --- Maxwell Equations of Software
  3. * Copyright © 2016,2017,2018,2019,2020,2021 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
  4. *
  5. * This file is part of GNU Mes.
  6. *
  7. * GNU Mes is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * GNU Mes is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include <sys/types.h>
  21. #include "mes/cc.h"
  22. struct scm
  23. {
  24. long type;
  25. union
  26. {
  27. struct scm *car;
  28. long car_value;
  29. char *bytes;
  30. long length;
  31. struct scm *ref;
  32. struct scm *variable;
  33. struct scm *macro;
  34. long port;
  35. };
  36. union
  37. {
  38. struct scm *cdr;
  39. long cdr_value;
  40. struct scm *closure;
  41. struct scm *continuation;
  42. char *name;
  43. struct scm *string;
  44. struct scm *structure;
  45. long value;
  46. FUNCTION function;
  47. struct scm *vector;
  48. };
  49. };
  50. /* mes */
  51. char *g_datadir;
  52. int g_debug;
  53. char *g_buf;
  54. int g_continuations;
  55. struct scm *g_symbols;
  56. struct scm *g_symbol_max;
  57. int g_mini;
  58. /* a/env */
  59. struct scm *R0;
  60. /* param 1 */
  61. struct scm *R1;
  62. /* save 2 */
  63. struct scm *R2;
  64. /* continuation */
  65. struct scm *R3;
  66. /* current-module */
  67. struct scm *M0;
  68. /* macro */
  69. struct scm *g_macros;
  70. struct scm *g_ports;
  71. /* gc */
  72. size_t ARENA_SIZE;
  73. size_t MAX_ARENA_SIZE;
  74. size_t STACK_SIZE;
  75. size_t JAM_SIZE;
  76. size_t GC_SAFETY;
  77. size_t MAX_STRING;
  78. char *g_arena;
  79. struct scm *cell_arena;
  80. struct scm *cell_zero;
  81. struct scm *g_free;
  82. struct scm *g_symbol;
  83. struct scm **g_stack_array;
  84. struct scm *g_cells;
  85. struct scm *g_news;
  86. long g_stack;
  87. size_t gc_count;
  88. struct timespec *gc_start_time;
  89. struct timespec *gc_end_time;
  90. size_t gc_time;
  91. char **__execl_c_argv;
  92. char *__open_boot_buf;
  93. char *__open_boot_file_name;
  94. char *__setenv_buf;
  95. char *__reader_read_char_buf;
  96. struct timespec *g_start_time;
  97. struct timeval *__gettimeofday_time;
  98. struct timespec *__get_internal_run_time_ts;
  99. struct scm *cast_charp_to_scmp (char const *i);
  100. struct scm **cast_charp_to_scmpp (char const *i);
  101. char *cast_voidp_to_charp (void const *i);
  102. long cast_scmp_to_long (struct scm *i);
  103. char *cast_scmp_to_charp (struct scm *i);
  104. struct scm *alloc (long n);
  105. struct scm *apply (struct scm *f, struct scm *x, struct scm *a);
  106. struct scm *apply_builtin (struct scm *fn, struct scm *x);
  107. struct scm *apply_builtin0 (struct scm *fn);
  108. struct scm *apply_builtin1 (struct scm *fn, struct scm *x);
  109. struct scm *apply_builtin2 (struct scm *fn, struct scm *x, struct scm *y);
  110. struct scm *apply_builtin3 (struct scm *fn, struct scm *x, struct scm *y, struct scm *z);
  111. struct scm *builtin_name (struct scm *builtin);
  112. struct scm *cstring_to_list (char const *s);
  113. struct scm *cstring_to_symbol (char const *s);
  114. struct scm *cell_ref (struct scm *cell, long index);
  115. struct scm *fdisplay_ (struct scm *, int, int);
  116. struct scm *init_symbols ();
  117. struct scm *init_time (struct scm *a);
  118. struct scm *make_builtin_type ();
  119. struct scm *make_bytes (char const *s, size_t length);
  120. struct scm *make_cell (long type, struct scm *car, struct scm *cdr);
  121. struct scm *make_pointer_cell (long type, long car, void *cdr);
  122. struct scm *make_value_cell (long type, long car, long cdr);
  123. struct scm *make_char (int n);
  124. struct scm *make_continuation (long n);
  125. struct scm *make_hash_table_ (long size);
  126. struct scm *make_hashq_type ();
  127. struct scm *make_initial_module (struct scm *a);
  128. struct scm *make_macro (struct scm *name, struct scm *x);
  129. struct scm *make_number (long n);
  130. struct scm *make_ref (struct scm *x);
  131. struct scm *make_string (char const *s, size_t length);
  132. struct scm *make_string0 (char const *s);
  133. struct scm *make_string_port (struct scm *x);
  134. struct scm *make_vector_ (long k, struct scm *e);
  135. struct scm *mes_builtins (struct scm *a);
  136. struct scm *push_cc (struct scm *p1, struct scm *p2, struct scm *a, struct scm *c);
  137. struct scm *struct_ref_ (struct scm *x, long i);
  138. struct scm *struct_set_x_ (struct scm *x, long i, struct scm *e);
  139. struct scm *vector_ref_ (struct scm *x, long i);
  140. struct scm *vector_set_x_ (struct scm *x, long i, struct scm *e);
  141. FUNCTION builtin_function (struct scm *builtin);
  142. char *cell_bytes (struct scm *x);
  143. char *news_bytes (struct scm *x);
  144. int peekchar ();
  145. int readchar ();
  146. int unreadchar ();
  147. long gc_free ();
  148. long length__ (struct scm *x);
  149. size_t bytes_cells (size_t length);
  150. void assert_max_string (size_t i, char const *msg, char const *string);
  151. void assert_msg (int check, char *msg);
  152. void assert_number (char const *name, struct scm *x);
  153. void copy_cell (struct scm *to, struct scm *from);
  154. void gc_ ();
  155. void gc_dump_arena (struct scm *cells, long size);
  156. void gc_init ();
  157. void gc_peek_frame ();
  158. void gc_pop_frame ();
  159. void gc_push_frame ();
  160. void gc_stats_ (char const* where);
  161. void init_symbols_ ();
  162. long seconds_and_nanoseconds_to_long (long s, long ns);
  163. #include "mes/builtins.h"
  164. #include "mes/constants.h"
  165. #include "mes/symbols.h"