64-make-cell.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /* -*-comment-start: "//";comment-end:""-*-
  2. * GNU Mes --- Maxwell Equations of Software
  3. * Copyright © 2017 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 <mes/lib.h>
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24. struct scm
  25. {
  26. int type;
  27. int car;
  28. int cdr;
  29. };
  30. int bla = 1234;
  31. char g_arena[84];
  32. struct scm *g_cells = (struct scm *) g_arena;
  33. char *g_chars = g_arena;
  34. int
  35. foo ()
  36. {
  37. oputs ("t: foo\n");
  38. return 0;
  39. };
  40. int
  41. bar (int i)
  42. {
  43. oputs ("t: bar\n");
  44. return 0;
  45. };
  46. struct function
  47. {
  48. int (*function) (void);
  49. int arity;
  50. char *name;
  51. };
  52. struct function g_fun = { &exit, 1, "fun" };
  53. struct function g_foo = { &foo, 0, "foo" };
  54. struct function g_bar = { &bar, 1, "bar" };
  55. //void *functions[2];
  56. int functions[2];
  57. struct function g_functions[2];
  58. int g_function = 0;
  59. enum type_t
  60. { TCHAR, TCLOSURE, TCONTINUATION, TFUNCTION, TKEYWORD, TMACRO, TNUMBER, TPAIR, TREF, TSPECIAL, TSTRING,
  61. TSYMBOL, TVALUES, TVECTOR, TBROKEN_HEART };
  62. typedef int SCM;
  63. int g_free = 3;
  64. SCM tmp;
  65. SCM tmp_num;
  66. int ARENA_SIZE = 200;
  67. #define TYPE(x) g_cells[x].type
  68. #define CAR(x) g_cells[x].car
  69. #define CDR(x) g_cells[x].cdr
  70. #define VALUE(x) g_cells[x].cdr
  71. #define CAAR(x) CAR (CAR (x))
  72. struct scm scm_fun = { TFUNCTION, 0, 0 };
  73. SCM cell_fun;
  74. SCM
  75. alloc (int n)
  76. {
  77. oputs ("040\n");
  78. SCM x = g_free;
  79. g_free += n;
  80. return x;
  81. }
  82. SCM
  83. make_cell (SCM type, SCM car, SCM cdr)
  84. {
  85. oputs ("030\n");
  86. SCM x = alloc (1);
  87. TYPE (x) = VALUE (type);
  88. if (VALUE (type) == TCHAR || VALUE (type) == TNUMBER)
  89. {
  90. if (car)
  91. CAR (x) = CAR (car);
  92. if (cdr)
  93. CDR (x) = CDR (cdr);
  94. }
  95. else if (VALUE (type) == TFUNCTION)
  96. {
  97. if (car)
  98. CAR (x) = car;
  99. if (cdr)
  100. CDR (x) = CDR (cdr);
  101. }
  102. else
  103. {
  104. CAR (x) = car;
  105. CDR (x) = cdr;
  106. }
  107. return x;
  108. }
  109. SCM
  110. make_cell_test ()
  111. {
  112. oputs ("010\n");
  113. VALUE (tmp_num) = TPAIR;
  114. oputs ("011\n");
  115. make_cell (tmp_num, 0, 1);
  116. oputs ("012\n");
  117. return 0;
  118. }
  119. SCM
  120. make_tmps_test (struct scm * cells)
  121. {
  122. oputs ("t: tmp = g_free++\n");
  123. tmp = g_free++;
  124. oputs ("t: cells[tmp].type = CHAR\n");
  125. cells[tmp].type = TCHAR;
  126. oputs ("000\n");
  127. tmp_num = g_free++;
  128. oputs ("001\n");
  129. cells[tmp_num].type = TNUMBER;
  130. oputs ("002\n");
  131. return 0;
  132. }
  133. int
  134. main ()
  135. {
  136. oputs ("\n");
  137. make_tmps_test (g_cells);
  138. make_cell_test ();
  139. oputs ("020\n");
  140. return 0;
  141. }