aboutsummaryrefslogtreecommitdiffstats
path: root/src/bootstrap/primitives.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bootstrap/primitives.c')
-rw-r--r--src/bootstrap/primitives.c126
1 files changed, 126 insertions, 0 deletions
diff --git a/src/bootstrap/primitives.c b/src/bootstrap/primitives.c
index 485799d..f6b354e 100644
--- a/src/bootstrap/primitives.c
+++ b/src/bootstrap/primitives.c
@@ -92,6 +92,10 @@ eval(Object *root) {
92 return obj_nil; 92 return obj_nil;
93} 93}
94 94
95//
96// Arithmetic procedures.
97//
98
95Object * 99Object *
96proc_add(Object *args) { 100proc_add(Object *args) {
97 // Extract first parameter. 101 // Extract first parameter.
@@ -213,6 +217,40 @@ proc_div(Object *args) {
213} 217}
214 218
215Object * 219Object *
220proc_mod(Object *args) {
221 // Extract first parameter.
222 Object *car = eval(args->car);
223 if (car == NULL) {
224 fprintf(stderr, "error: not enough arguments\n");
225 return obj_nil;
226 }
227 args = args->cdr;
228 ssize_t tot = car->fixnum;
229
230 while (args->type == OBJ_TYPE_PAIR) {
231 Object *car = eval(args->car);
232 if (car == NULL) {
233 car = obj_nil;
234 }
235 if (car->type != OBJ_TYPE_FIXNUM) {
236 fprintf(stderr, "error: div not supported for type %d\n", car->type);
237 return obj_nil;
238 }
239 if (car->fixnum == 0) {
240 fprintf(stderr, "error: division by zero\n");
241 return obj_nil;
242 }
243 tot %= car->fixnum;
244 args = args->cdr;
245 }
246 return make_fixnum(tot);
247}
248
249//
250// Display/Evaluation procedues.
251//
252
253Object *
216proc_display(Object *args) { 254proc_display(Object *args) {
217 if (args == NULL) { 255 if (args == NULL) {
218 return obj_nil; 256 return obj_nil;
@@ -256,6 +294,10 @@ proc_print(Object *args) {
256 return NULL; 294 return NULL;
257} 295}
258 296
297//
298// Type info procedures.
299//
300
259Object * 301Object *
260proc_is_boolean(Object *args) { 302proc_is_boolean(Object *args) {
261 Object *obj = NULL; 303 Object *obj = NULL;
@@ -268,6 +310,46 @@ proc_is_boolean(Object *args) {
268} 310}
269 311
270Object * 312Object *
313proc_is_null(Object *args) {
314 // TODO: stub
315 return NULL;
316}
317
318Object *
319proc_is_symbol(Object *args) {
320 // TODO: stub
321 return NULL;
322}
323
324Object *
325proc_is_string(Object *args) {
326 // TODO: stub
327 return NULL;
328}
329
330Object *
331proc_is_fixnum(Object *args) {
332 // TODO: stub
333 return NULL;
334}
335
336Object *
337proc_is_pair(Object *args) {
338 // TODO: stub
339 return NULL;
340}
341
342Object *
343proc_is_procedure(Object *args) {
344 // TODO: stub
345 return NULL;
346}
347
348//
349// Boolean/conditional procedures.
350//
351
352Object *
271proc_not(Object *args) { 353proc_not(Object *args) {
272 if (args->type == OBJ_TYPE_PAIR) { 354 if (args->type == OBJ_TYPE_PAIR) {
273 return eval(args->car) == obj_false ? obj_true : obj_false; 355 return eval(args->car) == obj_false ? obj_true : obj_false;
@@ -522,4 +604,48 @@ proc_num_equal(Object *args) {
522 return obj_true; 604 return obj_true;
523} 605}
524 606
607//
608// List operation procedures.
609//
610
611Object *
612proc_car(Object *args) {
613 // TODO: stub
614 return NULL;
615}
616
617Object *
618proc_cdr(Object *args) {
619 // TODO: stub
620 return NULL;
621}
622
623Object *
624proc_cons(Object *args) {
625 // TODO: stub
626 return NULL;
627}
628
629Object *
630proc_list(Object *args) {
631 // TODO: stub
632 return NULL;
633}
634
635//
636// Polymorphic procedures.
637//
638
639Object *
640proc_equal(Object *args) {
641 // TODO: stub
642 return NULL;
643}
644
525// TODO: fixnum left/right shift, mask, invert 645// TODO: fixnum left/right shift, mask, invert
646// TODO: implement and test missing procedures
647// TODO: properly implement nested environments
648// TODO: implement support for quotes and semi-quotes
649// TODO: LAMBDA
650// TODO: let
651// TODO: better error handling?