2013-10-10 04:48:01 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "picrin.h"
|
2013-10-15 00:21:40 -04:00
|
|
|
#include "picrin/proc.h"
|
2013-10-10 04:48:01 -04:00
|
|
|
|
2013-10-17 04:57:27 -04:00
|
|
|
static void
|
|
|
|
write(pic_state *pic, pic_value obj)
|
2013-10-10 04:48:01 -04:00
|
|
|
{
|
|
|
|
switch (pic_type(obj)) {
|
|
|
|
case PIC_TT_NIL:
|
|
|
|
printf("()");
|
|
|
|
break;
|
2013-10-16 00:17:01 -04:00
|
|
|
case PIC_TT_BOOL:
|
|
|
|
if (pic_true_p(obj))
|
|
|
|
printf("#t");
|
|
|
|
else
|
|
|
|
printf("#f");
|
|
|
|
break;
|
2013-10-10 04:48:01 -04:00
|
|
|
case PIC_TT_PAIR:
|
|
|
|
printf("(");
|
2013-10-17 04:57:27 -04:00
|
|
|
write(pic, pic_car(pic, obj));
|
2013-10-10 04:48:01 -04:00
|
|
|
printf(" . ");
|
2013-10-17 04:57:27 -04:00
|
|
|
write(pic, pic_cdr(pic, obj));
|
2013-10-10 04:48:01 -04:00
|
|
|
printf(")");
|
|
|
|
break;
|
|
|
|
case PIC_TT_SYMBOL:
|
|
|
|
printf("%s", pic_symbol_ptr(obj)->name);
|
|
|
|
break;
|
2013-10-15 07:05:12 -04:00
|
|
|
case PIC_TT_FLOAT:
|
2013-10-15 08:14:33 -04:00
|
|
|
printf("%g", pic_float(obj));
|
2013-10-11 11:15:46 -04:00
|
|
|
break;
|
2013-10-12 01:40:01 -04:00
|
|
|
case PIC_TT_UNDEF:
|
|
|
|
printf("#<undef>");
|
|
|
|
break;
|
2013-10-14 04:35:01 -04:00
|
|
|
case PIC_TT_PROC:
|
|
|
|
printf("#<proc %p>", pic_proc_ptr(obj));
|
|
|
|
break;
|
2013-10-10 04:48:01 -04:00
|
|
|
}
|
|
|
|
}
|
2013-10-15 08:14:33 -04:00
|
|
|
|
2013-10-17 04:57:27 -04:00
|
|
|
void
|
|
|
|
pic_debug(pic_state *pic, pic_value obj)
|
|
|
|
{
|
|
|
|
write(pic, obj);
|
|
|
|
}
|
|
|
|
|
2013-10-15 08:14:33 -04:00
|
|
|
static pic_value
|
|
|
|
pic_port_write(pic_state *pic)
|
|
|
|
{
|
|
|
|
pic_value v;
|
|
|
|
|
|
|
|
pic_get_args(pic, "o", &v);
|
2013-10-17 04:57:27 -04:00
|
|
|
write(pic, v);
|
2013-10-16 00:24:08 -04:00
|
|
|
return pic_false_value();
|
2013-10-15 08:14:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static pic_value
|
|
|
|
pic_port_newline(pic_state *pic)
|
|
|
|
{
|
|
|
|
puts("");
|
2013-10-16 00:24:08 -04:00
|
|
|
return pic_false_value();
|
2013-10-15 08:14:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pic_init_port(pic_state *pic)
|
|
|
|
{
|
|
|
|
pic_defun(pic, "write", pic_port_write);
|
|
|
|
pic_defun(pic, "newline", pic_port_newline);
|
|
|
|
}
|
|
|
|
|