Commit | Line | Data |
---|---|---|
66bf8260 | 1 | with Ada.Calendar; |
8c49f5a7 | 2 | with Ada.Characters.Latin_1; |
a974463a | 3 | with Ada.Strings.Unbounded; |
0571a45f | 4 | with Ada.Text_IO; |
18e21187 | 5 | with Eval_Callback; |
8c49f5a7 | 6 | with Reader; |
0571a45f CM |
7 | with Smart_Pointers; |
8 | with Types; | |
874db2ac | 9 | with Types.Hash_Map; |
705f3d2c | 10 | with Types.Vector; |
0571a45f CM |
11 | |
12 | package body Core is | |
13 | ||
14 | use Types; | |
15 | ||
16 | -- primitive functions on Smart_Pointer, | |
17 | function "+" is new Arith_Op ("+", "+"); | |
18 | function "-" is new Arith_Op ("-", "-"); | |
19 | function "*" is new Arith_Op ("*", "*"); | |
20 | function "/" is new Arith_Op ("/", "/"); | |
21 | ||
22 | function "<" is new Rel_Op ("<", "<"); | |
23 | function "<=" is new Rel_Op ("<=", "<="); | |
24 | function ">" is new Rel_Op (">", ">"); | |
25 | function ">=" is new Rel_Op (">=", ">="); | |
26 | ||
27 | ||
0571a45f CM |
28 | function Eval_As_Boolean (MH : Types.Mal_Handle) return Boolean is |
29 | use Types; | |
30 | Res : Boolean; | |
31 | begin | |
32 | case Deref (MH).Sym_Type is | |
33 | when Bool => | |
34 | Res := Deref_Bool (MH).Get_Bool; | |
8083b525 CM |
35 | when Nil => |
36 | Res := False; | |
0571a45f CM |
37 | -- when List => |
38 | -- declare | |
39 | -- L : List_Mal_Type; | |
40 | -- begin | |
41 | -- L := Deref_List (MH).all; | |
42 | -- Res := not Is_Null (L); | |
43 | -- end; | |
44 | when others => -- Everything else | |
45 | Res := True; | |
46 | end case; | |
47 | return Res; | |
48 | end Eval_As_Boolean; | |
49 | ||
50 | ||
1c28e560 | 51 | function Throw (Rest_Handle : Mal_Handle) |
f0727512 CM |
52 | return Types.Mal_Handle is |
53 | First_Param : Mal_Handle; | |
54 | Rest_List : Types.List_Mal_Type; | |
55 | begin | |
56 | Rest_List := Deref_List (Rest_Handle).all; | |
57 | First_Param := Car (Rest_List); | |
18e21187 | 58 | Types.Mal_Exception_Value := First_Param; |
f0727512 CM |
59 | raise Mal_Exception; |
60 | return First_Param; -- Keep the compiler happy. | |
61 | end Throw; | |
62 | ||
63 | ||
1c28e560 | 64 | function Is_True (Rest_Handle : Mal_Handle) |
f0727512 CM |
65 | return Types.Mal_Handle is |
66 | First_Param, Evaled_List : Mal_Handle; | |
67 | Rest_List : Types.List_Mal_Type; | |
68 | begin | |
69 | Rest_List := Deref_List (Rest_Handle).all; | |
70 | First_Param := Car (Rest_List); | |
71 | return New_Bool_Mal_Type | |
72 | (Deref (First_Param).Sym_Type = Bool and then | |
73 | Deref_Bool (First_Param).Get_Bool); | |
74 | end Is_True; | |
75 | ||
76 | ||
1c28e560 | 77 | function Is_False (Rest_Handle : Mal_Handle) |
f0727512 CM |
78 | return Types.Mal_Handle is |
79 | First_Param, Evaled_List : Mal_Handle; | |
80 | Rest_List : Types.List_Mal_Type; | |
81 | begin | |
82 | Rest_List := Deref_List (Rest_Handle).all; | |
83 | First_Param := Car (Rest_List); | |
84 | return New_Bool_Mal_Type | |
85 | (Deref (First_Param).Sym_Type = Bool and then | |
86 | not Deref_Bool (First_Param).Get_Bool); | |
87 | end Is_False; | |
88 | ||
89 | ||
1c28e560 | 90 | function Is_Nil (Rest_Handle : Mal_Handle) |
f0727512 CM |
91 | return Types.Mal_Handle is |
92 | First_Param, Evaled_List : Mal_Handle; | |
93 | Rest_List : Types.List_Mal_Type; | |
94 | begin | |
95 | Rest_List := Deref_List (Rest_Handle).all; | |
96 | First_Param := Car (Rest_List); | |
97 | return New_Bool_Mal_Type | |
8083b525 | 98 | (Deref (First_Param).Sym_Type = Nil); |
f0727512 CM |
99 | end Is_Nil; |
100 | ||
101 | ||
1c28e560 | 102 | function Meta (Rest_Handle : Mal_Handle) |
5b77d5f7 CM |
103 | return Types.Mal_Handle is |
104 | First_Param : Mal_Handle; | |
105 | Rest_List : Types.List_Mal_Type; | |
106 | begin | |
107 | Rest_List := Deref_List (Rest_Handle).all; | |
108 | First_Param := Car (Rest_List); | |
109 | return Deref (First_Param).Get_Meta; | |
110 | end Meta; | |
111 | ||
112 | ||
1c28e560 | 113 | function With_Meta (Rest_Handle : Mal_Handle) |
5b77d5f7 CM |
114 | return Types.Mal_Handle is |
115 | First_Param, Meta_Param, Res : Mal_Handle; | |
116 | Rest_List : Types.List_Mal_Type; | |
117 | begin | |
118 | Rest_List := Deref_List (Rest_Handle).all; | |
119 | First_Param := Car (Rest_List); | |
120 | Rest_List := Deref_List (Cdr (Rest_List)).all; | |
121 | Meta_Param := Car (Rest_List); | |
122 | Res := Copy (First_Param); | |
123 | Deref (Res).Set_Meta (Meta_Param); | |
124 | return Res; | |
125 | end With_Meta; | |
126 | ||
127 | ||
1c28e560 | 128 | function New_Atom (Rest_Handle : Mal_Handle) |
f88e4203 CM |
129 | return Types.Mal_Handle is |
130 | First_Param : Mal_Handle; | |
131 | Rest_List : Types.List_Mal_Type; | |
132 | begin | |
133 | Rest_List := Deref_List (Rest_Handle).all; | |
134 | First_Param := Car (Rest_List); | |
51fa7633 | 135 | return New_Atom_Mal_Type (First_Param); |
f88e4203 CM |
136 | end New_Atom; |
137 | ||
1c28e560 | 138 | function Is_Atom (Rest_Handle : Mal_Handle) |
f88e4203 CM |
139 | return Types.Mal_Handle is |
140 | First_Param, Evaled_List : Mal_Handle; | |
141 | Rest_List : Types.List_Mal_Type; | |
142 | begin | |
143 | Rest_List := Deref_List (Rest_Handle).all; | |
144 | First_Param := Car (Rest_List); | |
145 | return New_Bool_Mal_Type (Deref (First_Param).Sym_Type = Atom); | |
146 | end Is_Atom; | |
147 | ||
148 | ||
1c28e560 | 149 | function Deref_Atm (Rest_Handle : Mal_Handle) |
36b6dea5 CM |
150 | return Types.Mal_Handle is |
151 | First_Param : Mal_Handle; | |
152 | Rest_List : Types.List_Mal_Type; | |
153 | begin | |
154 | Rest_List := Deref_List (Rest_Handle).all; | |
155 | First_Param := Car (Rest_List); | |
156 | return Deref_Atom (First_Param).Get_Atom; | |
1c28e560 | 157 | end Deref_Atm; |
36b6dea5 CM |
158 | |
159 | ||
1c28e560 | 160 | function Reset (Rest_Handle : Mal_Handle) |
36b6dea5 CM |
161 | return Types.Mal_Handle is |
162 | First_Param, Atom_Param, New_Val : Mal_Handle; | |
163 | Rest_List : Types.List_Mal_Type; | |
164 | begin | |
165 | Rest_List := Deref_List (Rest_Handle).all; | |
166 | Atom_Param := Car (Rest_List); | |
167 | Rest_List := Deref_List (Cdr (Rest_List)).all; | |
168 | New_Val := Car (Rest_List); | |
169 | Deref_Atom (Atom_Param).Set_Atom (New_Val); | |
170 | return New_Val; | |
171 | end Reset; | |
172 | ||
173 | ||
1c28e560 | 174 | function Swap (Rest_Handle : Mal_Handle) |
36b6dea5 CM |
175 | return Types.Mal_Handle is |
176 | First_Param, Atom_Param, Atom_Val, New_Val : Mal_Handle; | |
177 | Rest_List : Types.List_Mal_Type; | |
178 | Rest_List_Class : Types.List_Class_Ptr; | |
0073c0a1 | 179 | Func_Param, Param_List : Mal_Handle; |
36b6dea5 CM |
180 | begin |
181 | Rest_List := Deref_List (Rest_Handle).all; | |
182 | Atom_Param := Car (Rest_List); | |
183 | Rest_List := Deref_List (Cdr (Rest_List)).all; | |
0073c0a1 CM |
184 | Func_Param := Car (Rest_List); |
185 | Param_List := Cdr (Rest_List); | |
36b6dea5 | 186 | |
0073c0a1 | 187 | Rest_List_Class := Deref_List_Class (Param_List); |
36b6dea5 CM |
188 | Param_List := Rest_List_Class.Duplicate; |
189 | Atom_Val := Deref_Atom (Atom_Param).Get_Atom; | |
190 | Param_List := Prepend (Atom_Val, Deref_List (Param_List).all); | |
0073c0a1 CM |
191 | case Deref (Func_Param).Sym_Type is |
192 | when Lambda => | |
18e21187 | 193 | New_Val := Deref_Lambda (Func_Param).Apply (Param_List); |
0073c0a1 | 194 | when Func => |
1c28e560 | 195 | New_Val := Deref_Func (Func_Param).Call_Func (Param_List); |
0073c0a1 CM |
196 | when others => raise Mal_Exception with "Swap with bad func"; |
197 | end case; | |
36b6dea5 CM |
198 | Deref_Atom (Atom_Param).Set_Atom (New_Val); |
199 | return New_Val; | |
200 | end Swap; | |
201 | ||
202 | ||
1c28e560 | 203 | function Is_List (Rest_Handle : Mal_Handle) |
0571a45f CM |
204 | return Types.Mal_Handle is |
205 | First_Param, Evaled_List : Mal_Handle; | |
206 | Rest_List : Types.List_Mal_Type; | |
207 | begin | |
208 | Rest_List := Deref_List (Rest_Handle).all; | |
209 | First_Param := Car (Rest_List); | |
210 | return New_Bool_Mal_Type | |
211 | (Deref (First_Param).Sym_Type = List and then | |
212 | Deref_List (First_Param).Get_List_Type = List_List); | |
213 | end Is_List; | |
214 | ||
215 | ||
1c28e560 | 216 | function Is_Vector (Rest_Handle : Mal_Handle) |
f0727512 CM |
217 | return Types.Mal_Handle is |
218 | First_Param, Evaled_List : Mal_Handle; | |
219 | Rest_List : Types.List_Mal_Type; | |
220 | begin | |
221 | Rest_List := Deref_List (Rest_Handle).all; | |
222 | First_Param := Car (Rest_List); | |
223 | return New_Bool_Mal_Type | |
224 | (Deref (First_Param).Sym_Type = List and then | |
225 | Deref_List (First_Param).Get_List_Type = Vector_List); | |
226 | end Is_Vector; | |
227 | ||
228 | ||
1c28e560 | 229 | function Is_Map (Rest_Handle : Mal_Handle) |
f0727512 CM |
230 | return Types.Mal_Handle is |
231 | First_Param, Evaled_List : Mal_Handle; | |
232 | Rest_List : Types.List_Mal_Type; | |
233 | begin | |
234 | Rest_List := Deref_List (Rest_Handle).all; | |
235 | First_Param := Car (Rest_List); | |
236 | return New_Bool_Mal_Type | |
237 | (Deref (First_Param).Sym_Type = List and then | |
238 | Deref_List (First_Param).Get_List_Type = Hashed_List); | |
239 | end Is_Map; | |
240 | ||
241 | ||
1c28e560 | 242 | function Is_Sequential (Rest_Handle : Mal_Handle) |
f0727512 CM |
243 | return Types.Mal_Handle is |
244 | First_Param, Evaled_List : Mal_Handle; | |
245 | Rest_List : Types.List_Mal_Type; | |
246 | begin | |
247 | Rest_List := Deref_List (Rest_Handle).all; | |
248 | First_Param := Car (Rest_List); | |
249 | return New_Bool_Mal_Type | |
250 | (Deref (First_Param).Sym_Type = List and then | |
251 | Deref_List (First_Param).Get_List_Type /= Hashed_List); | |
252 | end Is_Sequential; | |
253 | ||
254 | ||
1c28e560 | 255 | function Is_Empty (Rest_Handle : Mal_Handle) |
0571a45f CM |
256 | return Types.Mal_Handle is |
257 | First_Param, Evaled_List : Mal_Handle; | |
705f3d2c | 258 | List : List_Class_Ptr; |
0571a45f CM |
259 | Rest_List : Types.List_Mal_Type; |
260 | begin | |
261 | Rest_List := Deref_List (Rest_Handle).all; | |
262 | First_Param := Car (Rest_List); | |
705f3d2c CM |
263 | List := Deref_List_Class (First_Param); |
264 | return New_Bool_Mal_Type (Is_Null (List.all)); | |
0571a45f CM |
265 | end Is_Empty; |
266 | ||
267 | ||
268 | function Eval_As_List (MH : Types.Mal_Handle) return List_Mal_Type is | |
269 | begin | |
270 | case Deref (MH).Sym_Type is | |
8083b525 CM |
271 | when List => return Deref_List (MH).all; |
272 | when Nil => return Null_List (List_List); | |
0571a45f CM |
273 | when others => null; |
274 | end case; | |
18e21187 | 275 | raise Evaluation_Error with "Expecting a List"; |
0571a45f CM |
276 | return Null_List (List_List); |
277 | end Eval_As_List; | |
278 | ||
279 | ||
1c28e560 | 280 | function Count (Rest_Handle : Mal_Handle) |
0571a45f CM |
281 | return Types.Mal_Handle is |
282 | First_Param, Evaled_List : Mal_Handle; | |
705f3d2c | 283 | L : List_Mal_Type; |
0571a45f | 284 | Rest_List : Types.List_Mal_Type; |
705f3d2c | 285 | N : Natural; |
0571a45f CM |
286 | begin |
287 | Rest_List := Deref_List (Rest_Handle).all; | |
288 | First_Param := Car (Rest_List); | |
705f3d2c CM |
289 | if Deref (First_Param).Sym_Type = List and then |
290 | Deref_List (First_Param).Get_List_Type = Vector_List then | |
291 | N := Deref_List_Class (First_Param).Length; | |
292 | else | |
293 | L := Eval_As_List (First_Param); | |
294 | N := L.Length; | |
295 | end if; | |
296 | return New_Int_Mal_Type (N); | |
0571a45f CM |
297 | end Count; |
298 | ||
299 | ||
1c28e560 | 300 | function Cons (Rest_Handle : Mal_Handle) |
ebb6e9d3 CM |
301 | return Types.Mal_Handle is |
302 | Rest_List : Types.List_Mal_Type; | |
303 | First_Param, List_Handle : Mal_Handle; | |
304 | List : List_Mal_Type; | |
705f3d2c | 305 | List_Class : List_Class_Ptr; |
ebb6e9d3 CM |
306 | begin |
307 | Rest_List := Deref_List (Rest_Handle).all; | |
308 | First_Param := Car (Rest_List); | |
309 | List_Handle := Cdr (Rest_List); | |
310 | List := Deref_List (List_Handle).all; | |
311 | List_Handle := Car (List); | |
705f3d2c CM |
312 | List_Class := Deref_List_Class (List_Handle); |
313 | return Prepend (First_Param, List_Class.all); | |
ebb6e9d3 CM |
314 | end Cons; |
315 | ||
316 | ||
1c28e560 | 317 | function Concat (Rest_Handle : Mal_Handle) |
ebb6e9d3 CM |
318 | return Types.Mal_Handle is |
319 | Rest_List : Types.List_Mal_Type; | |
320 | begin | |
321 | Rest_List := Deref_List (Rest_Handle).all; | |
1c28e560 | 322 | return Types.Concat (Rest_List); |
ebb6e9d3 CM |
323 | end Concat; |
324 | ||
325 | ||
1c28e560 | 326 | function First (Rest_Handle : Mal_Handle) |
d836bcfc | 327 | return Types.Mal_Handle is |
705f3d2c CM |
328 | Rest_List : Types.List_Mal_Type; |
329 | First_List : Types.List_Class_Ptr; | |
d836bcfc CM |
330 | First_Param : Mal_Handle; |
331 | begin | |
332 | Rest_List := Deref_List (Rest_Handle).all; | |
333 | First_Param := Car (Rest_List); | |
8083b525 CM |
334 | if Deref (First_Param).Sym_Type = Nil then |
335 | return New_Nil_Mal_Type; | |
5660d35d | 336 | end if; |
705f3d2c CM |
337 | First_List := Deref_List_Class (First_Param); |
338 | if Is_Null (First_List.all) then | |
8083b525 | 339 | return New_Nil_Mal_Type; |
6d91af72 | 340 | else |
705f3d2c | 341 | return Types.Car (First_List.all); |
6d91af72 | 342 | end if; |
d836bcfc CM |
343 | end First; |
344 | ||
345 | ||
1c28e560 | 346 | function Rest (Rest_Handle : Mal_Handle) |
d836bcfc | 347 | return Types.Mal_Handle is |
705f3d2c CM |
348 | Rest_List : Types.List_Mal_Type; |
349 | First_Param, Container : Mal_Handle; | |
d836bcfc CM |
350 | begin |
351 | Rest_List := Deref_List (Rest_Handle).all; | |
352 | First_Param := Car (Rest_List); | |
8083b525 | 353 | if Deref (First_Param).Sym_Type = Nil then |
5660d35d CM |
354 | return New_List_Mal_Type (List_List); |
355 | end if; | |
705f3d2c CM |
356 | Container := Deref_List_Class (First_Param).Cdr; |
357 | return Deref_List_Class (Container).Duplicate; | |
d836bcfc CM |
358 | end Rest; |
359 | ||
360 | ||
1c28e560 | 361 | function Nth (Rest_Handle : Mal_Handle) |
6d91af72 | 362 | return Types.Mal_Handle is |
705f3d2c CM |
363 | -- Rest_List, First_List : Types.List_Mal_Type; |
364 | Rest_List : Types.List_Mal_Type; | |
365 | First_List : Types.List_Class_Ptr; | |
6d91af72 CM |
366 | First_Param, List_Handle, Num_Handle : Mal_Handle; |
367 | List : List_Mal_Type; | |
368 | Index : Types.Int_Mal_Type; | |
369 | begin | |
370 | Rest_List := Deref_List (Rest_Handle).all; | |
371 | First_Param := Car (Rest_List); | |
705f3d2c | 372 | First_List := Deref_List_Class (First_Param); |
6d91af72 CM |
373 | List_Handle := Cdr (Rest_List); |
374 | List := Deref_List (List_Handle).all; | |
375 | Num_Handle := Car (List); | |
376 | Index := Deref_Int (Num_Handle).all; | |
705f3d2c | 377 | return Types.Nth (First_List.all, Natural (Index.Get_Int_Val)); |
6d91af72 CM |
378 | end Nth; |
379 | ||
380 | ||
1c28e560 | 381 | function Apply (Rest_Handle : Mal_Handle) |
b5bad5ea CM |
382 | return Types.Mal_Handle is |
383 | ||
384 | Results_Handle, First_Param : Mal_Handle; | |
385 | Rest_List : List_Mal_Type; | |
386 | Results_List : List_Ptr; | |
387 | ||
388 | begin | |
389 | ||
390 | -- The rest of the line. | |
391 | Rest_List := Deref_List (Rest_Handle).all; | |
392 | First_Param := Car (Rest_List); | |
393 | Rest_List := Deref_List (Cdr (Rest_List)).all; | |
394 | ||
395 | Results_Handle := New_List_Mal_Type (List_List); | |
396 | Results_List := Deref_List (Results_Handle); | |
397 | ||
398 | -- The last item is a list or a vector which gets flattened so that | |
399 | -- (apply f (A B) C (D E)) becomes (f (A B) C D E) | |
400 | while not Is_Null (Rest_List) loop | |
401 | declare | |
402 | Part_Handle : Mal_Handle; | |
403 | begin | |
404 | Part_Handle := Car (Rest_List); | |
405 | Rest_List := Deref_List (Cdr (Rest_List)).all; | |
406 | ||
407 | -- Is Part_Handle the last item in the list? | |
408 | if Is_Null (Rest_List) then | |
409 | declare | |
410 | The_List : List_Class_Ptr; | |
411 | List_Item : Mal_Handle; | |
412 | Next_List : Mal_Handle; | |
413 | begin | |
414 | The_List := Deref_List_Class (Part_Handle); | |
415 | while not Is_Null (The_List.all) loop | |
416 | List_Item := Car (The_List.all); | |
417 | Append (Results_List.all, List_Item); | |
418 | Next_List := Cdr (The_List.all); | |
419 | The_List := Deref_List_Class (Next_List); | |
420 | end loop; | |
421 | end; | |
422 | else | |
423 | Append (Results_List.all, Part_Handle); | |
424 | end if; | |
425 | end; | |
426 | end loop; | |
c6b1e6e7 CM |
427 | |
428 | -- The apply part... | |
b5bad5ea | 429 | if Deref (First_Param).Sym_Type = Func then |
1c28e560 | 430 | return Call_Func (Deref_Func (First_Param).all, Results_Handle); |
b5bad5ea CM |
431 | elsif Deref (First_Param).Sym_Type = Lambda then |
432 | declare | |
433 | ||
434 | L : Lambda_Mal_Type; | |
435 | E : Envs.Env_Handle; | |
436 | Param_Names : List_Mal_Type; | |
437 | Res : Mal_Handle; | |
438 | ||
439 | begin | |
440 | ||
441 | L := Deref_Lambda (First_Param).all; | |
442 | E := Envs.New_Env (L.Get_Env); | |
443 | ||
444 | Param_Names := Deref_List (L.Get_Params).all; | |
445 | ||
446 | if Envs.Bind (E, Param_Names, Results_List.all) then | |
447 | ||
448 | return Eval_Callback.Eval.all (L.Get_Expr, E); | |
449 | ||
450 | else | |
451 | ||
452 | raise Mal_Exception with "Bind failed in Apply"; | |
453 | ||
454 | end if; | |
455 | ||
456 | end; | |
457 | ||
458 | else -- neither a Lambda or a Func | |
459 | raise Mal_Exception; | |
460 | end if; | |
461 | ||
b5bad5ea CM |
462 | end Apply; |
463 | ||
464 | ||
1c28e560 | 465 | function Map (Rest_Handle : Mal_Handle) |
c7b51393 CM |
466 | return Types.Mal_Handle is |
467 | ||
874db2ac | 468 | Rest_List, Results_List : List_Mal_Type; |
18e21187 | 469 | Func_Handle, List_Handle, Results_Handle : Mal_Handle; |
c7b51393 CM |
470 | |
471 | begin | |
472 | ||
473 | -- The rest of the line. | |
474 | Rest_List := Deref_List (Rest_Handle).all; | |
475 | ||
476 | Func_Handle := Car (Rest_List); | |
18e21187 | 477 | List_Handle := Nth (Rest_List, 1); |
c7b51393 CM |
478 | |
479 | Results_Handle := New_List_Mal_Type (List_List); | |
480 | Results_List := Deref_List (Results_Handle).all; | |
481 | ||
874db2ac | 482 | while not Is_Null (Deref_List_Class (List_Handle).all) loop |
18e21187 | 483 | |
c7b51393 CM |
484 | declare |
485 | Parts_Handle : Mal_Handle; | |
c7b51393 | 486 | begin |
18e21187 CM |
487 | Parts_Handle := |
488 | Make_New_List | |
489 | ((1 => Func_Handle, | |
490 | 2 => Make_New_List | |
b5bad5ea | 491 | ((1 => Car (Deref_List_Class (List_Handle).all))))); |
18e21187 | 492 | |
874db2ac | 493 | List_Handle := Cdr (Deref_List_Class (List_Handle).all); |
c7b51393 | 494 | |
c7b51393 CM |
495 | Append |
496 | (Results_List, | |
1c28e560 | 497 | Apply (Parts_Handle)); |
18e21187 | 498 | |
c7b51393 | 499 | end; |
18e21187 | 500 | |
c7b51393 | 501 | end loop; |
18e21187 | 502 | |
c7b51393 | 503 | return New_List_Mal_Type (Results_List); |
18e21187 | 504 | |
c7b51393 CM |
505 | end Map; |
506 | ||
507 | ||
1c28e560 | 508 | function Symbol (Rest_Handle : Mal_Handle) |
8021afae CM |
509 | return Types.Mal_Handle is |
510 | ||
511 | Sym_Handle, Res : Mal_Handle; | |
512 | Rest_List : List_Mal_Type; | |
513 | ||
514 | begin | |
515 | ||
516 | -- The rest of the line. | |
517 | Rest_List := Deref_List (Rest_Handle).all; | |
518 | ||
519 | Sym_Handle := Car (Rest_List); | |
520 | ||
521 | declare | |
522 | The_String : Mal_String := | |
523 | Deref_String (Sym_Handle).Get_String; | |
524 | begin | |
525 | ||
51fa7633 | 526 | Res := New_Symbol_Mal_Type |
8021afae CM |
527 | (The_String (The_String'First + 1 .. The_String'Last - 1)); |
528 | ||
529 | end; | |
530 | return Res; | |
531 | end Symbol; | |
532 | ||
533 | ||
1c28e560 | 534 | function Is_Symbol (Rest_Handle : Mal_Handle) |
8021afae CM |
535 | return Types.Mal_Handle is |
536 | ||
537 | Sym_Handle : Mal_Handle; | |
538 | Rest_List : List_Mal_Type; | |
2e3389c4 | 539 | Res : Boolean; |
8021afae CM |
540 | |
541 | begin | |
542 | Rest_List := Deref_List (Rest_Handle).all; | |
543 | Sym_Handle := Car (Rest_List); | |
51fa7633 CM |
544 | if Deref (Sym_Handle).Sym_Type = Sym then |
545 | Res := Deref_Sym (Sym_Handle).Get_Sym (1) /= ':'; | |
2e3389c4 CM |
546 | else |
547 | Res := False; | |
548 | end if; | |
549 | return New_Bool_Mal_Type (Res); | |
8021afae CM |
550 | end Is_Symbol; |
551 | ||
552 | ||
d2bb60d3 CM |
553 | function Is_String (Rest_Handle : Mal_Handle) return Types.Mal_Handle is |
554 | First_Param : Mal_Handle; | |
555 | begin | |
556 | First_Param := Car (Deref_List (Rest_Handle).all); | |
557 | return New_Bool_Mal_Type (Deref (First_Param).Sym_Type = Str); | |
558 | end Is_String; | |
559 | ||
560 | ||
1c28e560 | 561 | function Keyword (Rest_Handle : Mal_Handle) |
2e3389c4 CM |
562 | return Types.Mal_Handle is |
563 | ||
564 | Sym_Handle, Res : Mal_Handle; | |
565 | Rest_List : List_Mal_Type; | |
566 | ||
567 | begin | |
568 | ||
569 | -- The rest of the line. | |
570 | Rest_List := Deref_List (Rest_Handle).all; | |
571 | ||
572 | Sym_Handle := Car (Rest_List); | |
573 | ||
574 | declare | |
575 | The_String : Mal_String := | |
576 | Deref_String (Sym_Handle).Get_String; | |
577 | begin | |
578 | ||
51fa7633 | 579 | Res := New_Symbol_Mal_Type |
2e3389c4 CM |
580 | (':' & The_String (The_String'First + 1 .. The_String'Last - 1)); |
581 | ||
582 | end; | |
583 | return Res; | |
584 | end Keyword; | |
585 | ||
586 | ||
1c28e560 | 587 | function Is_Keyword (Rest_Handle : Mal_Handle) |
2e3389c4 CM |
588 | return Types.Mal_Handle is |
589 | ||
590 | Sym_Handle : Mal_Handle; | |
591 | Rest_List : List_Mal_Type; | |
592 | Res : Boolean; | |
593 | ||
594 | begin | |
595 | Rest_List := Deref_List (Rest_Handle).all; | |
596 | Sym_Handle := Car (Rest_List); | |
51fa7633 CM |
597 | if Deref (Sym_Handle).Sym_Type = Sym then |
598 | Res := Deref_Sym (Sym_Handle).Get_Sym (1) = ':'; | |
2e3389c4 CM |
599 | else |
600 | Res := False; | |
601 | end if; | |
602 | return New_Bool_Mal_Type (Res); | |
603 | end Is_Keyword; | |
604 | ||
605 | ||
1c28e560 | 606 | function New_List (Rest_Handle : Mal_Handle) |
0571a45f CM |
607 | return Types.Mal_Handle is |
608 | Rest_List : Types.List_Mal_Type; | |
609 | begin | |
610 | Rest_List := Deref_List (Rest_Handle).all; | |
611 | return New_List_Mal_Type (The_List => Rest_List); | |
612 | end New_List; | |
613 | ||
614 | ||
1c28e560 | 615 | function New_Vector (Rest_Handle : Mal_Handle) |
cca0b237 CM |
616 | return Types.Mal_Handle is |
617 | Rest_List : List_Mal_Type; | |
618 | Res : Mal_Handle; | |
705f3d2c | 619 | use Types.Vector; |
cca0b237 | 620 | begin |
705f3d2c | 621 | Res := New_Vector_Mal_Type; |
cca0b237 CM |
622 | Rest_List := Deref_List (Rest_Handle).all; |
623 | while not Is_Null (Rest_List) loop | |
705f3d2c | 624 | Deref_Vector (Res).Append (Car (Rest_List)); |
cca0b237 CM |
625 | Rest_List := Deref_List (Cdr (Rest_List)).all; |
626 | end loop; | |
627 | return Res; | |
628 | end New_Vector; | |
629 | ||
630 | ||
1c28e560 | 631 | function New_Map (Rest_Handle : Mal_Handle) |
5fa2b0cc CM |
632 | return Types.Mal_Handle is |
633 | Rest_List : List_Mal_Type; | |
634 | Res : Mal_Handle; | |
635 | begin | |
874db2ac | 636 | Res := Hash_Map.New_Hash_Map_Mal_Type; |
5fa2b0cc CM |
637 | Rest_List := Deref_List (Rest_Handle).all; |
638 | while not Is_Null (Rest_List) loop | |
874db2ac | 639 | Hash_Map.Deref_Hash (Res).Append (Car (Rest_List)); |
5fa2b0cc CM |
640 | Rest_List := Deref_List (Cdr (Rest_List)).all; |
641 | end loop; | |
642 | return Res; | |
643 | end New_Map; | |
644 | ||
645 | ||
1c28e560 | 646 | function Assoc (Rest_Handle : Mal_Handle) |
5fa2b0cc | 647 | return Types.Mal_Handle is |
874db2ac CM |
648 | Rest_List : Mal_Handle; |
649 | Map : Hash_Map.Hash_Map_Mal_Type; | |
5fa2b0cc | 650 | begin |
874db2ac CM |
651 | Rest_List := Rest_Handle; |
652 | Map := Hash_Map.Deref_Hash (Car (Deref_List (Rest_List).all)).all; | |
653 | Rest_List := Cdr (Deref_List (Rest_List).all); | |
654 | return Hash_Map.Assoc (Map, Rest_List); | |
655 | end Assoc; | |
5fa2b0cc | 656 | |
5fa2b0cc | 657 | |
1c28e560 | 658 | function Dis_Assoc (Rest_Handle : Mal_Handle) |
874db2ac CM |
659 | return Types.Mal_Handle is |
660 | Rest_List : Mal_Handle; | |
661 | Map : Hash_Map.Hash_Map_Mal_Type; | |
662 | begin | |
663 | Rest_List := Rest_Handle; | |
664 | Map := Hash_Map.Deref_Hash (Car (Deref_List (Rest_List).all)).all; | |
665 | Rest_List := Cdr (Deref_List (Rest_List).all); | |
666 | return Hash_Map.Dis_Assoc (Map, Rest_List); | |
667 | end Dis_Assoc; | |
5fa2b0cc CM |
668 | |
669 | ||
1c28e560 | 670 | function Get_Key (Rest_Handle : Mal_Handle) |
5fa2b0cc | 671 | return Types.Mal_Handle is |
874db2ac CM |
672 | Rest_List : List_Mal_Type; |
673 | Map : Hash_Map.Hash_Map_Mal_Type; | |
674 | Map_Param, Key : Mal_Handle; | |
93031830 | 675 | The_Sym : Sym_Types; |
5fa2b0cc CM |
676 | begin |
677 | ||
678 | Rest_List := Deref_List (Rest_Handle).all; | |
4daad7d8 | 679 | Map_Param := Car (Rest_List); |
93031830 | 680 | The_Sym := Deref (Map_Param).Sym_Type; |
8083b525 | 681 | if The_Sym = Sym or The_Sym = Nil then |
4daad7d8 CM |
682 | -- Either its nil or its some other atom |
683 | -- which makes no sense! | |
8083b525 | 684 | return New_Nil_Mal_Type; |
4daad7d8 CM |
685 | end if; |
686 | ||
687 | -- Assume a map from here on in. | |
874db2ac | 688 | Map := Hash_Map.Deref_Hash (Car (Rest_List)).all; |
5fa2b0cc CM |
689 | Rest_List := Deref_List (Cdr (Rest_List)).all; |
690 | Key := Car (Rest_List); | |
691 | ||
874db2ac CM |
692 | return Map.Get (Key); |
693 | ||
5fa2b0cc CM |
694 | end Get_Key; |
695 | ||
696 | ||
1c28e560 | 697 | function Contains_Key (Rest_Handle : Mal_Handle) |
4daad7d8 | 698 | return Types.Mal_Handle is |
874db2ac CM |
699 | Rest_List : List_Mal_Type; |
700 | Map : Hash_Map.Hash_Map_Mal_Type; | |
701 | Key : Mal_Handle; | |
4daad7d8 | 702 | begin |
4daad7d8 | 703 | Rest_List := Deref_List (Rest_Handle).all; |
874db2ac | 704 | Map := Hash_Map.Deref_Hash (Car (Rest_List)).all; |
4daad7d8 CM |
705 | Rest_List := Deref_List (Cdr (Rest_List)).all; |
706 | Key := Car (Rest_List); | |
874db2ac | 707 | return New_Bool_Mal_Type (Hash_Map.Contains (Map, Key)); |
4daad7d8 CM |
708 | end Contains_Key; |
709 | ||
710 | ||
1c28e560 | 711 | function All_Keys (Rest_Handle : Mal_Handle) |
4daad7d8 | 712 | return Types.Mal_Handle is |
874db2ac CM |
713 | Rest_List : List_Mal_Type; |
714 | Map : Hash_Map.Hash_Map_Mal_Type; | |
4daad7d8 | 715 | begin |
4daad7d8 | 716 | Rest_List := Deref_List (Rest_Handle).all; |
874db2ac CM |
717 | Map := Hash_Map.Deref_Hash (Car (Rest_List)).all; |
718 | return Hash_Map.All_Keys (Map); | |
4daad7d8 CM |
719 | end All_Keys; |
720 | ||
721 | ||
1c28e560 | 722 | function All_Values (Rest_Handle : Mal_Handle) |
4daad7d8 | 723 | return Types.Mal_Handle is |
874db2ac CM |
724 | Rest_List : List_Mal_Type; |
725 | Map : Hash_Map.Hash_Map_Mal_Type; | |
4daad7d8 | 726 | begin |
4daad7d8 | 727 | Rest_List := Deref_List (Rest_Handle).all; |
874db2ac CM |
728 | Map := Hash_Map.Deref_Hash (Car (Rest_List)).all; |
729 | return Hash_Map.All_Values (Map); | |
4daad7d8 CM |
730 | end All_Values; |
731 | ||
732 | ||
0571a45f CM |
733 | -- Take a list with two parameters and produce a single result |
734 | -- using the Op access-to-function parameter. | |
735 | function Reduce2 | |
1c28e560 | 736 | (Op : Binary_Func_Access; LH : Mal_Handle) |
0571a45f CM |
737 | return Mal_Handle is |
738 | Left, Right : Mal_Handle; | |
739 | L, Rest_List : List_Mal_Type; | |
740 | begin | |
741 | L := Deref_List (LH).all; | |
742 | Left := Car (L); | |
743 | Rest_List := Deref_List (Cdr (L)).all; | |
744 | Right := Car (Rest_List); | |
745 | return Op (Left, Right); | |
746 | end Reduce2; | |
747 | ||
748 | ||
1c28e560 | 749 | function Plus (Rest_Handle : Mal_Handle) |
0571a45f CM |
750 | return Types.Mal_Handle is |
751 | begin | |
1c28e560 | 752 | return Reduce2 ("+"'Access, Rest_Handle); |
0571a45f CM |
753 | end Plus; |
754 | ||
755 | ||
1c28e560 | 756 | function Minus (Rest_Handle : Mal_Handle) |
0571a45f CM |
757 | return Types.Mal_Handle is |
758 | begin | |
1c28e560 | 759 | return Reduce2 ("-"'Access, Rest_Handle); |
0571a45f CM |
760 | end Minus; |
761 | ||
762 | ||
1c28e560 | 763 | function Mult (Rest_Handle : Mal_Handle) |
0571a45f CM |
764 | return Types.Mal_Handle is |
765 | begin | |
1c28e560 | 766 | return Reduce2 ("*"'Access, Rest_Handle); |
0571a45f CM |
767 | end Mult; |
768 | ||
769 | ||
1c28e560 | 770 | function Divide (Rest_Handle : Mal_Handle) |
0571a45f CM |
771 | return Types.Mal_Handle is |
772 | begin | |
1c28e560 | 773 | return Reduce2 ("/"'Access, Rest_Handle); |
0571a45f CM |
774 | end Divide; |
775 | ||
776 | ||
1c28e560 | 777 | function LT (Rest_Handle : Mal_Handle) |
0571a45f CM |
778 | return Types.Mal_Handle is |
779 | begin | |
1c28e560 | 780 | return Reduce2 ("<"'Access, Rest_Handle); |
0571a45f CM |
781 | end LT; |
782 | ||
783 | ||
1c28e560 | 784 | function LTE (Rest_Handle : Mal_Handle) |
0571a45f CM |
785 | return Types.Mal_Handle is |
786 | begin | |
1c28e560 | 787 | return Reduce2 ("<="'Access, Rest_Handle); |
0571a45f CM |
788 | end LTE; |
789 | ||
790 | ||
1c28e560 | 791 | function GT (Rest_Handle : Mal_Handle) |
0571a45f CM |
792 | return Types.Mal_Handle is |
793 | begin | |
1c28e560 | 794 | return Reduce2 (">"'Access, Rest_Handle); |
0571a45f CM |
795 | end GT; |
796 | ||
797 | ||
1c28e560 | 798 | function GTE (Rest_Handle : Mal_Handle) |
0571a45f CM |
799 | return Types.Mal_Handle is |
800 | begin | |
1c28e560 | 801 | return Reduce2 (">="'Access, Rest_Handle); |
0571a45f CM |
802 | end GTE; |
803 | ||
804 | ||
1c28e560 | 805 | function EQ (Rest_Handle : Mal_Handle) |
0571a45f CM |
806 | return Types.Mal_Handle is |
807 | begin | |
1c28e560 | 808 | return Reduce2 (Types."="'Access, Rest_Handle); |
0571a45f CM |
809 | end EQ; |
810 | ||
811 | ||
1c28e560 | 812 | function Pr_Str (Rest_Handle : Mal_Handle) |
a974463a | 813 | return Types.Mal_Handle is |
a974463a CM |
814 | begin |
815 | return New_String_Mal_Type ('"' & Deref_List (Rest_Handle).Pr_Str & '"'); | |
816 | end Pr_Str; | |
817 | ||
818 | ||
1c28e560 | 819 | function Prn (Rest_Handle : Mal_Handle) |
a974463a | 820 | return Types.Mal_Handle is |
a974463a CM |
821 | begin |
822 | Ada.Text_IO.Put_Line (Deref_List (Rest_Handle).Pr_Str); | |
8083b525 | 823 | return New_Nil_Mal_Type; |
a974463a CM |
824 | end Prn; |
825 | ||
826 | ||
1c28e560 | 827 | function Println (Rest_Handle : Mal_Handle) |
a974463a | 828 | return Types.Mal_Handle is |
a974463a | 829 | begin |
d1967ba5 | 830 | Ada.Text_IO.Put_Line (Deref_List (Rest_Handle).Pr_Str (False)); |
8083b525 | 831 | return New_Nil_Mal_Type; |
a974463a CM |
832 | end Println; |
833 | ||
834 | ||
1c28e560 | 835 | function Str (Rest_Handle : Mal_Handle) |
a974463a | 836 | return Types.Mal_Handle is |
a974463a | 837 | begin |
d1967ba5 | 838 | return New_String_Mal_Type ('"' & Deref_List (Rest_Handle).Cat_Str (False) & '"'); |
a974463a CM |
839 | end Str; |
840 | ||
841 | ||
1c28e560 | 842 | function Read_String (Rest_Handle : Mal_Handle) |
8c49f5a7 CM |
843 | return Types.Mal_Handle is |
844 | Rest_List : Types.List_Mal_Type; | |
845 | First_Param : Mal_Handle; | |
846 | begin | |
847 | Rest_List := Deref_List (Rest_Handle).all; | |
848 | First_Param := Car (Rest_List); | |
849 | declare | |
850 | Str_Param : String := Deref_String (First_Param).Get_String; | |
851 | Unquoted_Str : String(1 .. Str_Param'Length-2) := | |
852 | Str_Param (Str_Param'First+1 .. Str_Param'Last-1); | |
853 | -- i.e. strip out the double-qoutes surrounding the string. | |
854 | begin | |
855 | return Reader.Read_Str (Unquoted_Str); | |
856 | end; | |
857 | end Read_String; | |
858 | ||
859 | ||
1c28e560 | 860 | function Read_Line (Rest_Handle : Mal_Handle) |
02c3208a CM |
861 | return Types.Mal_Handle is |
862 | Rest_List : Types.List_Mal_Type; | |
863 | First_Param : Mal_Handle; | |
864 | S : String (1..Reader.Max_Line_Len); | |
3428be48 | 865 | Last : Natural; |
02c3208a CM |
866 | begin |
867 | Rest_List := Deref_List (Rest_Handle).all; | |
868 | First_Param := Car (Rest_List); | |
869 | declare | |
870 | Prompt : String := Deref_String (First_Param).Get_String; | |
871 | begin | |
872 | -- Print the prompt, less the quote marks. | |
873 | Ada.Text_IO.Put (Prompt (2 .. Prompt'Last - 1)); | |
874 | end; | |
875 | Ada.Text_IO.Get_Line (S, Last); | |
876 | return New_String_Mal_Type ('"' & S (1 .. Last) & '"'); | |
877 | end Read_Line; | |
878 | ||
879 | ||
1c28e560 | 880 | function Slurp (Rest_Handle : Mal_Handle) |
8c49f5a7 CM |
881 | return Types.Mal_Handle is |
882 | Rest_List : Types.List_Mal_Type; | |
883 | First_Param : Mal_Handle; | |
884 | begin | |
885 | Rest_List := Deref_List (Rest_Handle).all; | |
886 | First_Param := Car (Rest_List); | |
887 | declare | |
888 | Str_Param : String := Deref_String (First_Param).Get_String; | |
889 | Unquoted_Str : String(1 .. Str_Param'Length-2) := | |
890 | Str_Param (Str_Param'First+1 .. Str_Param'Last-1); | |
891 | -- i.e. strip out the double-qoutes surrounding the string. | |
892 | use Ada.Text_IO; | |
893 | Fn : Ada.Text_IO.File_Type; | |
894 | Line_Str : String (1..Reader.Max_Line_Len); | |
3428be48 CM |
895 | File_Str : Ada.Strings.Unbounded.Unbounded_String := |
896 | Ada.Strings.Unbounded.To_Unbounded_String (""""); | |
8c49f5a7 CM |
897 | Last : Natural; |
898 | I : Natural := 0; | |
899 | begin | |
900 | Ada.Text_IO.Open (Fn, In_File, Unquoted_Str); | |
901 | while not End_Of_File (Fn) loop | |
902 | Get_Line (Fn, Line_Str, Last); | |
903 | if Last > 0 then | |
3428be48 CM |
904 | Ada.Strings.Unbounded.Append (File_Str, Line_Str (1 .. Last)); |
905 | Ada.Strings.Unbounded.Append (File_Str, Ada.Characters.Latin_1.LF); | |
8c49f5a7 CM |
906 | end if; |
907 | end loop; | |
908 | Ada.Text_IO.Close (Fn); | |
3428be48 CM |
909 | Ada.Strings.Unbounded.Append (File_Str, '"'); |
910 | return New_String_Mal_Type (Ada.Strings.Unbounded.To_String (File_Str)); | |
8c49f5a7 CM |
911 | end; |
912 | end Slurp; | |
913 | ||
914 | ||
1c28e560 | 915 | function Conj (Rest_Handle : Mal_Handle) |
a74b420d CM |
916 | return Types.Mal_Handle is |
917 | Rest_List : List_Mal_Type; | |
918 | First_Param, Res : Mal_Handle; | |
919 | begin | |
920 | Rest_List := Deref_List (Rest_Handle).all; | |
921 | First_Param := Car (Rest_List); | |
922 | Rest_List := Deref_List (Cdr (Rest_List)).all; | |
923 | ||
924 | -- Is this a List or a Vector? | |
925 | case Deref_List (First_Param).Get_List_Type is | |
926 | when List_List => | |
927 | Res := Copy (First_Param); | |
928 | while not Is_Null (Rest_List) loop | |
929 | Res := Prepend (To_List => Deref_List (Res).all, Op => Car (Rest_List)); | |
930 | Rest_List := Deref_List (Cdr (Rest_List)).all; | |
931 | end loop; | |
932 | return Res; | |
933 | when Vector_List => | |
934 | Res := Copy (First_Param); | |
935 | while not Is_Null (Rest_List) loop | |
936 | Vector.Append (Vector.Deref_Vector (Res).all, Car (Rest_List)); | |
937 | Rest_List := Deref_List (Cdr (Rest_List)).all; | |
938 | end loop; | |
939 | return Res; | |
940 | when Hashed_List => raise Mal_Exception with "Conj on Hashed_Map"; | |
941 | end case; | |
942 | end Conj; | |
943 | ||
944 | ||
316d5bbd CM |
945 | function Seq (Rest_Handle : Mal_Handle) |
946 | return Types.Mal_Handle is | |
947 | First_Param, Res : Mal_Handle; | |
948 | begin | |
949 | First_Param := Car (Deref_List (Rest_Handle).all); | |
950 | case Deref (First_Param).Sym_Type is | |
951 | when Nil => return First_Param; | |
952 | when List => | |
953 | case Deref_List (First_Param).Get_List_Type is | |
954 | when List_List => | |
955 | if Is_Null (Deref_List (First_Param).all) then | |
956 | return New_Nil_Mal_Type; | |
957 | else | |
958 | return First_Param; | |
959 | end if; | |
960 | when Vector_List => | |
961 | if Vector.Is_Null (Vector.Deref_Vector (First_Param).all) then | |
962 | return New_Nil_Mal_Type; | |
963 | else | |
964 | return Vector.Duplicate (Vector.Deref_Vector (First_Param).all); | |
965 | end if; | |
966 | when others => raise Mal_Exception; | |
967 | end case; | |
968 | when Str => | |
969 | declare | |
970 | Param_Str : String := Deref_String (First_Param).Get_String; | |
971 | String_Handle : Mal_Handle; | |
972 | L_Ptr : List_Ptr; | |
973 | begin | |
974 | if Param_Str'Length <= 2 then | |
975 | return New_Nil_Mal_Type; -- "" | |
976 | else | |
977 | Res := New_List_Mal_Type (List_List); | |
978 | L_Ptr := Deref_List (Res); | |
979 | for I in Param_Str'First+1 .. Param_Str'Last-1 loop | |
980 | String_Handle:= New_String_Mal_Type ('"' &Param_Str (I) & '"'); | |
981 | Append (L_Ptr.all, String_Handle); | |
982 | end loop; | |
983 | return Res; | |
984 | end if; | |
985 | end; | |
986 | when others => raise Mal_Exception; | |
987 | end case; | |
988 | end Seq; | |
989 | ||
990 | ||
66bf8260 CM |
991 | Start_Time : Ada.Calendar.Time := Ada.Calendar.Clock; |
992 | ||
1c28e560 | 993 | function Time_Ms (Rest_Handle : Mal_Handle) |
66bf8260 CM |
994 | return Types.Mal_Handle is |
995 | D : Duration; | |
996 | use Ada.Calendar; | |
997 | begin | |
998 | D := Clock - Start_Time; -- seconds | |
999 | D := D * 1000.0; -- milli-seconds | |
1000 | return New_Int_Mal_Type (Integer (D)); -- ms rounded to the nearest one | |
1001 | end Time_Ms; | |
1002 | ||
1003 | ||
b5bad5ea | 1004 | procedure Init (Repl_Env : Envs.Env_Handle) is |
0571a45f CM |
1005 | begin |
1006 | ||
b5bad5ea | 1007 | Envs.Set (Repl_Env, "*host-language*", Types.New_Symbol_Mal_Type ("ada")); |
8496c8bc | 1008 | |
b5bad5ea | 1009 | Envs.Set (Repl_Env, |
f0727512 CM |
1010 | "true?", |
1011 | New_Func_Mal_Type ("true?", Is_True'access)); | |
1012 | ||
b5bad5ea | 1013 | Envs.Set (Repl_Env, |
f0727512 CM |
1014 | "false?", |
1015 | New_Func_Mal_Type ("false?", Is_False'access)); | |
1016 | ||
b5bad5ea | 1017 | Envs.Set (Repl_Env, |
5b77d5f7 CM |
1018 | "meta", |
1019 | New_Func_Mal_Type ("meta", Meta'access)); | |
1020 | ||
b5bad5ea | 1021 | Envs.Set (Repl_Env, |
5b77d5f7 CM |
1022 | "with-meta", |
1023 | New_Func_Mal_Type ("with-meta", With_Meta'access)); | |
1024 | ||
b5bad5ea | 1025 | Envs.Set (Repl_Env, |
cca0b237 CM |
1026 | "nil?", |
1027 | New_Func_Mal_Type ("nil?", Is_Nil'access)); | |
1028 | ||
b5bad5ea | 1029 | Envs.Set (Repl_Env, |
f0727512 CM |
1030 | "throw", |
1031 | New_Func_Mal_Type ("throw", Throw'access)); | |
1032 | ||
b5bad5ea | 1033 | Envs.Set (Repl_Env, |
f88e4203 CM |
1034 | "atom", |
1035 | New_Func_Mal_Type ("atom", New_Atom'access)); | |
1036 | ||
b5bad5ea | 1037 | Envs.Set (Repl_Env, |
f88e4203 CM |
1038 | "atom?", |
1039 | New_Func_Mal_Type ("atom?", Is_Atom'access)); | |
1040 | ||
b5bad5ea | 1041 | Envs.Set (Repl_Env, |
36b6dea5 | 1042 | "deref", |
1c28e560 | 1043 | New_Func_Mal_Type ("deref", Deref_Atm'access)); |
36b6dea5 | 1044 | |
b5bad5ea | 1045 | Envs.Set (Repl_Env, |
36b6dea5 CM |
1046 | "reset!", |
1047 | New_Func_Mal_Type ("reset!", Reset'access)); | |
1048 | ||
b5bad5ea | 1049 | Envs.Set (Repl_Env, |
36b6dea5 CM |
1050 | "swap!", |
1051 | New_Func_Mal_Type ("swap!", Swap'access)); | |
1052 | ||
b5bad5ea | 1053 | Envs.Set (Repl_Env, |
cca0b237 CM |
1054 | "list", |
1055 | New_Func_Mal_Type ("list", New_List'access)); | |
f0727512 | 1056 | |
b5bad5ea | 1057 | Envs.Set (Repl_Env, |
0571a45f CM |
1058 | "list?", |
1059 | New_Func_Mal_Type ("list?", Is_List'access)); | |
1060 | ||
b5bad5ea | 1061 | Envs.Set (Repl_Env, |
cca0b237 CM |
1062 | "vector", |
1063 | New_Func_Mal_Type ("vector", New_Vector'access)); | |
1064 | ||
b5bad5ea | 1065 | Envs.Set (Repl_Env, |
f0727512 CM |
1066 | "vector?", |
1067 | New_Func_Mal_Type ("vector?", Is_Vector'access)); | |
1068 | ||
b5bad5ea | 1069 | Envs.Set (Repl_Env, |
5fa2b0cc CM |
1070 | "hash-map", |
1071 | New_Func_Mal_Type ("hash-map", New_Map'access)); | |
1072 | ||
b5bad5ea | 1073 | Envs.Set (Repl_Env, |
5fa2b0cc CM |
1074 | "assoc", |
1075 | New_Func_Mal_Type ("assoc", Assoc'access)); | |
1076 | ||
b5bad5ea | 1077 | Envs.Set (Repl_Env, |
874db2ac CM |
1078 | "dissoc", |
1079 | New_Func_Mal_Type ("dissoc", Dis_Assoc'access)); | |
1080 | ||
b5bad5ea | 1081 | Envs.Set (Repl_Env, |
5fa2b0cc CM |
1082 | "get", |
1083 | New_Func_Mal_Type ("get", Get_Key'access)); | |
1084 | ||
b5bad5ea | 1085 | Envs.Set (Repl_Env, |
4daad7d8 CM |
1086 | "keys", |
1087 | New_Func_Mal_Type ("keys", All_Keys'access)); | |
1088 | ||
b5bad5ea | 1089 | Envs.Set (Repl_Env, |
4daad7d8 CM |
1090 | "vals", |
1091 | New_Func_Mal_Type ("vals", All_Values'access)); | |
1092 | ||
b5bad5ea | 1093 | Envs.Set (Repl_Env, |
f0727512 CM |
1094 | "map?", |
1095 | New_Func_Mal_Type ("map?", Is_Map'access)); | |
1096 | ||
b5bad5ea | 1097 | Envs.Set (Repl_Env, |
4daad7d8 CM |
1098 | "contains?", |
1099 | New_Func_Mal_Type ("contains?", Contains_Key'access)); | |
1100 | ||
b5bad5ea | 1101 | Envs.Set (Repl_Env, |
f0727512 CM |
1102 | "sequential?", |
1103 | New_Func_Mal_Type ("sequential?", Is_Sequential'access)); | |
1104 | ||
b5bad5ea | 1105 | Envs.Set (Repl_Env, |
0571a45f CM |
1106 | "empty?", |
1107 | New_Func_Mal_Type ("empty?", Is_Empty'access)); | |
1108 | ||
b5bad5ea | 1109 | Envs.Set (Repl_Env, |
0571a45f CM |
1110 | "count", |
1111 | New_Func_Mal_Type ("count", Count'access)); | |
1112 | ||
b5bad5ea | 1113 | Envs.Set (Repl_Env, |
ebb6e9d3 CM |
1114 | "cons", |
1115 | New_Func_Mal_Type ("cons", Cons'access)); | |
1116 | ||
b5bad5ea | 1117 | Envs.Set (Repl_Env, |
ebb6e9d3 CM |
1118 | "concat", |
1119 | New_Func_Mal_Type ("concat", Concat'access)); | |
1120 | ||
b5bad5ea | 1121 | Envs.Set (Repl_Env, |
d836bcfc CM |
1122 | "first", |
1123 | New_Func_Mal_Type ("first", First'access)); | |
1124 | ||
b5bad5ea | 1125 | Envs.Set (Repl_Env, |
d836bcfc CM |
1126 | "rest", |
1127 | New_Func_Mal_Type ("rest", Rest'access)); | |
1128 | ||
b5bad5ea | 1129 | Envs.Set (Repl_Env, |
6d91af72 CM |
1130 | "nth", |
1131 | New_Func_Mal_Type ("nth", Nth'access)); | |
1132 | ||
b5bad5ea | 1133 | Envs.Set (Repl_Env, |
c7b51393 CM |
1134 | "map", |
1135 | New_Func_Mal_Type ("map", Map'access)); | |
1136 | ||
b5bad5ea | 1137 | Envs.Set (Repl_Env, |
f0727512 CM |
1138 | "apply", |
1139 | New_Func_Mal_Type ("apply", Apply'access)); | |
1140 | ||
b5bad5ea | 1141 | Envs.Set (Repl_Env, |
8021afae CM |
1142 | "symbol", |
1143 | New_Func_Mal_Type ("symbol", Symbol'access)); | |
1144 | ||
b5bad5ea | 1145 | Envs.Set (Repl_Env, |
8021afae CM |
1146 | "symbol?", |
1147 | New_Func_Mal_Type ("symbol?", Is_Symbol'access)); | |
1148 | ||
d2bb60d3 CM |
1149 | Envs.Set (Repl_Env, |
1150 | "string?", | |
1151 | New_Func_Mal_Type ("string?", Is_String'access)); | |
1152 | ||
b5bad5ea | 1153 | Envs.Set (Repl_Env, |
2e3389c4 CM |
1154 | "keyword", |
1155 | New_Func_Mal_Type ("keyword", Keyword'access)); | |
1156 | ||
b5bad5ea | 1157 | Envs.Set (Repl_Env, |
2e3389c4 CM |
1158 | "keyword?", |
1159 | New_Func_Mal_Type ("keyword?", Is_Keyword'access)); | |
1160 | ||
b5bad5ea | 1161 | Envs.Set (Repl_Env, |
a974463a CM |
1162 | "pr-str", |
1163 | New_Func_Mal_Type ("pr-str", Pr_Str'access)); | |
1164 | ||
b5bad5ea | 1165 | Envs.Set (Repl_Env, |
a974463a CM |
1166 | "str", |
1167 | New_Func_Mal_Type ("str", Str'access)); | |
1168 | ||
b5bad5ea | 1169 | Envs.Set (Repl_Env, |
a974463a CM |
1170 | "prn", |
1171 | New_Func_Mal_Type ("prn", Prn'access)); | |
1172 | ||
b5bad5ea | 1173 | Envs.Set (Repl_Env, |
a974463a CM |
1174 | "println", |
1175 | New_Func_Mal_Type ("println", Println'access)); | |
1176 | ||
b5bad5ea | 1177 | Envs.Set (Repl_Env, |
8c49f5a7 CM |
1178 | "read-string", |
1179 | New_Func_Mal_Type ("read-string", Read_String'access)); | |
1180 | ||
b5bad5ea | 1181 | Envs.Set (Repl_Env, |
02c3208a CM |
1182 | "readline", |
1183 | New_Func_Mal_Type ("readline", Read_Line'access)); | |
1184 | ||
b5bad5ea | 1185 | Envs.Set (Repl_Env, |
8c49f5a7 CM |
1186 | "slurp", |
1187 | New_Func_Mal_Type ("slurp", Slurp'access)); | |
1188 | ||
b5bad5ea | 1189 | Envs.Set (Repl_Env, |
a74b420d CM |
1190 | "conj", |
1191 | New_Func_Mal_Type ("conj", Conj'access)); | |
1192 | ||
316d5bbd CM |
1193 | Envs.Set (Repl_Env, |
1194 | "seq", | |
1195 | New_Func_Mal_Type ("seq", Seq'access)); | |
1196 | ||
66bf8260 CM |
1197 | Envs.Set (Repl_Env, |
1198 | "time-ms", | |
1199 | New_Func_Mal_Type ("time-ms", Time_Ms'access)); | |
1200 | ||
b5bad5ea | 1201 | Envs.Set (Repl_Env, |
0571a45f CM |
1202 | "+", |
1203 | New_Func_Mal_Type ("+", Plus'access)); | |
1204 | ||
b5bad5ea | 1205 | Envs.Set (Repl_Env, |
0571a45f CM |
1206 | "-", |
1207 | New_Func_Mal_Type ("-", Minus'access)); | |
1208 | ||
b5bad5ea | 1209 | Envs.Set (Repl_Env, |
0571a45f CM |
1210 | "*", |
1211 | New_Func_Mal_Type ("*", Mult'access)); | |
1212 | ||
b5bad5ea | 1213 | Envs.Set (Repl_Env, |
0571a45f CM |
1214 | "/", |
1215 | New_Func_Mal_Type ("/", Divide'access)); | |
1216 | ||
b5bad5ea | 1217 | Envs.Set (Repl_Env, |
0571a45f CM |
1218 | "<", |
1219 | New_Func_Mal_Type ("<", LT'access)); | |
1220 | ||
b5bad5ea | 1221 | Envs.Set (Repl_Env, |
0571a45f CM |
1222 | "<=", |
1223 | New_Func_Mal_Type ("<=", LTE'access)); | |
1224 | ||
b5bad5ea | 1225 | Envs.Set (Repl_Env, |
0571a45f CM |
1226 | ">", |
1227 | New_Func_Mal_Type (">", GT'access)); | |
1228 | ||
b5bad5ea | 1229 | Envs.Set (Repl_Env, |
0571a45f CM |
1230 | ">=", |
1231 | New_Func_Mal_Type (">=", GTE'access)); | |
1232 | ||
b5bad5ea | 1233 | Envs.Set (Repl_Env, |
0571a45f CM |
1234 | "=", |
1235 | New_Func_Mal_Type ("=", EQ'access)); | |
1236 | ||
1237 | end Init; | |
1238 | ||
1239 | ||
1240 | end Core; |