|
7 | 7 |
|
8 | 8 | #define AREA "REGISTER"
|
9 | 9 |
|
10 |
| -struct core core0; |
11 |
| -struct core *cr0 = &core0; |
| 10 | +static struct core cores[ncore]; |
12 | 11 |
|
13 |
| -// tge // 9 |
14 |
| -obj anenv; // 10 |
15 |
| -obj ambenv; // 11 |
16 |
| -obj savetmp; // 12 |
| 12 | +// global-env |
| 13 | +obj ambenv; |
| 14 | +obj anenv; |
| 15 | +obj svtmp; |
17 | 16 |
|
18 |
| -const int rootlen = 12; |
| 17 | +const int rootlen = nother + ncore; |
19 | 18 | static obj rootlst;
|
20 | 19 |
|
| 20 | +static void init(void) |
| 21 | +{ |
| 22 | + static bool initdone = false; |
| 23 | + if (initdone) |
| 24 | + return; |
| 25 | + |
| 26 | + rootlst = emptylst; |
| 27 | + int i, j; |
| 28 | + for (i = 0; i < ncore; i++) { |
| 29 | + obj reglst = emptylst; |
| 30 | + for (j = 0; j < nreg; j++) { |
| 31 | + reglst = cons(unspecified, reglst); |
| 32 | + } |
| 33 | + rootlst = cons(reglst, rootlst); |
| 34 | + } |
| 35 | + for (i = 0; i < nother; i++) { |
| 36 | + rootlst = cons(unspecified, rootlst); |
| 37 | + } |
| 38 | + initdone = true; |
| 39 | +} |
| 40 | + |
21 | 41 | obj getroot(void)
|
22 | 42 | {
|
23 |
| - int actlen; |
| 43 | + int i; |
24 | 44 | obj lst = rootlst;
|
25 | 45 |
|
26 |
| - // intentionally not using rootlen here, change number manually after |
27 |
| - // modifying body below. |
28 |
| - if ((actlen = length_u(rootlst)) != 12) { |
29 |
| - error_internal( |
30 |
| - AREA, |
31 |
| - "Bug! getroot() got list of unexpected length: %d ", |
32 |
| - actlen); |
33 |
| - exit(1); |
34 |
| - } |
35 |
| - // order must match setroot |
36 |
| - set_car(lst, cr0->argl); |
37 |
| - lst = cdr(lst); |
38 |
| - set_car(lst, cr0->cont); |
39 |
| - lst = cdr(lst); |
40 |
| - set_car(lst, cr0->env); |
41 |
| - lst = cdr(lst); |
42 |
| - set_car(lst, cr0->expr); |
43 |
| - lst = cdr(lst); |
44 |
| - set_car(lst, cr0->proc); |
45 |
| - lst = cdr(lst); |
46 |
| - set_car(lst, cr0->stack); |
47 |
| - lst = cdr(lst); |
48 |
| - set_car(lst, cr0->unev); |
49 |
| - lst = cdr(lst); |
50 |
| - set_car(lst, cr0->val); |
51 |
| - lst = cdr(lst); |
52 | 46 | set_car(lst, the_global_environment());
|
53 | 47 | lst = cdr(lst);
|
| 48 | + |
| 49 | + set_car(lst, ambenv); |
| 50 | + lst = cdr(lst); |
| 51 | + |
54 | 52 | set_car(lst, anenv);
|
55 | 53 | lst = cdr(lst);
|
56 |
| - set_car(lst, ambenv); |
| 54 | + |
| 55 | + set_car(lst, svtmp); |
57 | 56 | lst = cdr(lst);
|
58 |
| - set_car(lst, savetmp); |
| 57 | + |
| 58 | + for (i = 0; i < ncore; i++, lst = cdr(lst)) { |
| 59 | + struct core *cr = &cores[i]; |
| 60 | + obj reglst = car(lst); |
| 61 | + |
| 62 | + set_car(reglst, cr->argl); |
| 63 | + reglst = cdr(reglst); |
| 64 | + |
| 65 | + set_car(reglst, cr->cont); |
| 66 | + reglst = cdr(reglst); |
| 67 | + |
| 68 | + set_car(reglst, cr->env); |
| 69 | + reglst = cdr(reglst); |
| 70 | + |
| 71 | + set_car(reglst, cr->expr); |
| 72 | + reglst = cdr(reglst); |
| 73 | + |
| 74 | + set_car(reglst, cr->proc); |
| 75 | + reglst = cdr(reglst); |
| 76 | + |
| 77 | + set_car(reglst, cr->stack); |
| 78 | + reglst = cdr(reglst); |
| 79 | + |
| 80 | + set_car(reglst, cr->unev); |
| 81 | + reglst = cdr(reglst); |
| 82 | + |
| 83 | + set_car(reglst, cr->val); |
| 84 | + reglst = cdr(reglst); |
| 85 | + } |
59 | 86 |
|
60 | 87 | return rootlst;
|
61 | 88 | }
|
62 | 89 |
|
63 |
| -// used for garbage collection |
64 |
| -obj setroot(obj rlst) |
| 90 | +void setroot(obj rlst) |
65 | 91 | {
|
66 |
| - int actlen; |
| 92 | + int i; |
67 | 93 | obj lst = rootlst = rlst;
|
68 | 94 |
|
69 |
| - // intentionally not using rootlen here, change number manually after |
70 |
| - // modifying body below. |
71 |
| - if ((actlen = length_u(rootlst)) != 12) { |
72 |
| - return error_internal( |
73 |
| - AREA, |
74 |
| - "Bug! setroot() got list of unexpected length: %d", |
75 |
| - actlen); |
76 |
| - } |
77 |
| - // order must match getroot |
78 |
| - cr0->argl = car(lst); |
79 |
| - lst = cdr(lst); |
80 |
| - cr0->cont = car(lst); |
81 |
| - lst = cdr(lst); |
82 |
| - cr0->env = car(lst); |
83 |
| - lst = cdr(lst); |
84 |
| - cr0->expr = car(lst); |
85 |
| - lst = cdr(lst); |
86 |
| - cr0->proc = car(lst); |
87 |
| - lst = cdr(lst); |
88 |
| - cr0->stack = car(lst); |
89 |
| - lst = cdr(lst); |
90 |
| - cr0->unev = car(lst); |
91 |
| - lst = cdr(lst); |
92 |
| - cr0->val = car(lst); |
93 |
| - lst = cdr(lst); |
94 | 95 | set_global_environment(car(lst));
|
95 | 96 | lst = cdr(lst);
|
| 97 | + |
| 98 | + ambenv = car(lst); |
| 99 | + lst = cdr(lst); |
| 100 | + |
96 | 101 | anenv = car(lst);
|
97 | 102 | lst = cdr(lst);
|
98 |
| - ambenv = car(lst); |
| 103 | + |
| 104 | + svtmp = car(lst); |
99 | 105 | lst = cdr(lst);
|
100 |
| - savetmp = car(lst); |
101 | 106 |
|
102 |
| - return unspecified; |
103 |
| -} |
| 107 | + for (i = 0; i < ncore; i++, lst = cdr(lst)) { |
| 108 | + struct core *cr = &cores[i]; |
| 109 | + obj reglst = car(lst); |
104 | 110 |
|
105 |
| -static bool initdone = false; |
106 |
| -static obj init(void) |
107 |
| -{ |
108 |
| - int actlen; |
109 |
| - |
110 |
| - cr0->stack = emptylst; |
111 |
| - // preallocate storage for gc root |
112 |
| - rootlst = listn(12, // <----- actual length |
113 |
| - unspecified, // 1 |
114 |
| - unspecified, // 2 |
115 |
| - unspecified, // 3 |
116 |
| - unspecified, // 4 |
117 |
| - unspecified, // 5 |
118 |
| - unspecified, // 6 |
119 |
| - unspecified, // 7 |
120 |
| - unspecified, // 8 |
121 |
| - unspecified, // 9 |
122 |
| - unspecified, // 10 |
123 |
| - unspecified, // 11 |
124 |
| - unspecified // 12 |
125 |
| - ); |
126 |
| - if ((actlen = length_u(rootlst)) != rootlen) { |
127 |
| - error_internal( |
128 |
| - AREA, |
129 |
| - "Bug! init, root wrong length. is: %d, expected %d", |
130 |
| - actlen, rootlen); |
131 |
| - exit(1); |
| 111 | + cr->argl = car(reglst); |
| 112 | + reglst = cdr(reglst); |
| 113 | + |
| 114 | + cr->cont = car(reglst); |
| 115 | + reglst = cdr(reglst); |
| 116 | + |
| 117 | + cr->env = car(reglst); |
| 118 | + reglst = cdr(reglst); |
| 119 | + |
| 120 | + cr->expr = car(reglst); |
| 121 | + reglst = cdr(reglst); |
| 122 | + |
| 123 | + cr->proc = car(reglst); |
| 124 | + reglst = cdr(reglst); |
| 125 | + |
| 126 | + cr->stack = car(reglst); |
| 127 | + reglst = cdr(reglst); |
| 128 | + |
| 129 | + cr->unev = car(reglst); |
| 130 | + reglst = cdr(reglst); |
| 131 | + |
| 132 | + cr->val = car(reglst); |
| 133 | + reglst = cdr(reglst); |
132 | 134 | }
|
133 |
| - initdone = true; |
134 |
| - return unspecified; |
135 | 135 | }
|
136 | 136 |
|
137 | 137 | struct core *dfltcore(void)
|
138 | 138 | {
|
139 |
| - if (!initdone) { |
140 |
| - init(); |
141 |
| - } |
142 |
| - return cr0; |
| 139 | + init(); |
| 140 | + return &cores[0]; |
143 | 141 | }
|
0 commit comments