qse/ase/lsp/print.c

122 lines
3.2 KiB
C
Raw Normal View History

2005-02-04 15:39:11 +00:00
/*
2005-05-28 13:34:26 +00:00
* $Id: print.c,v 1.5 2005-05-28 13:34:26 bacon Exp $
2005-02-04 15:39:11 +00:00
*/
2005-05-28 13:34:26 +00:00
#include <xp/lsp/lisp.h>
2005-02-04 15:39:11 +00:00
void xp_lisp_print_debug (xp_lisp_obj_t* obj)
{
2005-02-04 16:00:37 +00:00
switch (XP_LISP_TYPE(obj)) {
case XP_LISP_OBJ_NIL:
2005-02-04 16:23:34 +00:00
xp_printf (XP_TEXT("nil"));
2005-02-04 15:39:11 +00:00
break;
2005-02-04 16:00:37 +00:00
case XP_LISP_OBJ_TRUE:
2005-02-04 16:23:34 +00:00
xp_printf (XP_TEXT("t"));
2005-02-04 15:39:11 +00:00
break;
2005-02-04 16:00:37 +00:00
case XP_LISP_OBJ_INT:
2005-02-04 16:23:34 +00:00
xp_printf (XP_TEXT("%d"), XP_LISP_IVALUE(obj));
2005-02-04 15:39:11 +00:00
break;
2005-02-04 16:00:37 +00:00
case XP_LISP_OBJ_FLOAT:
2005-02-04 16:23:34 +00:00
xp_printf (XP_TEXT("%f"), XP_LISP_FVALUE(obj));
2005-02-04 15:39:11 +00:00
break;
2005-02-04 16:00:37 +00:00
case XP_LISP_OBJ_SYMBOL:
2005-02-04 16:23:34 +00:00
xp_printf (XP_TEXT("%s"), XP_LISP_SYMVALUE(obj));
2005-02-04 15:39:11 +00:00
break;
2005-02-04 16:00:37 +00:00
case XP_LISP_OBJ_STRING:
2005-02-04 16:23:34 +00:00
xp_printf (XP_TEXT("%s"), XP_LISP_STRVALUE(obj));
2005-02-04 15:39:11 +00:00
break;
2005-02-04 16:00:37 +00:00
case XP_LISP_OBJ_CONS:
2005-02-04 15:39:11 +00:00
{
xp_lisp_obj_t* p = obj;
2005-02-04 16:23:34 +00:00
xp_printf (XP_TEXT("("));
2005-02-04 15:39:11 +00:00
do {
2005-02-04 16:00:37 +00:00
xp_lisp_print_debug (XP_LISP_CAR(p));
p = XP_LISP_CDR(p);
if (XP_LISP_TYPE(p) != XP_LISP_OBJ_NIL) {
2005-02-04 16:23:34 +00:00
xp_printf (XP_TEXT(" "));
2005-02-04 16:00:37 +00:00
if (XP_LISP_TYPE(p) != XP_LISP_OBJ_CONS) {
2005-02-04 16:23:34 +00:00
xp_printf (XP_TEXT(". "));
2005-02-04 15:39:11 +00:00
xp_lisp_print_debug (p);
}
}
2005-02-04 16:00:37 +00:00
} while (XP_LISP_TYPE(p) != XP_LISP_OBJ_NIL && XP_LISP_TYPE(p) == XP_LISP_OBJ_CONS);
2005-02-04 16:23:34 +00:00
xp_printf (XP_TEXT(")"));
2005-02-04 15:39:11 +00:00
}
break;
2005-02-04 16:00:37 +00:00
case XP_LISP_OBJ_FUNC:
2005-02-04 16:23:34 +00:00
xp_printf (XP_TEXT("func"));
2005-02-04 15:39:11 +00:00
break;
2005-02-04 16:00:37 +00:00
case XP_LISP_OBJ_MACRO:
2005-02-04 16:23:34 +00:00
xp_printf (XP_TEXT("macro"));
2005-02-04 15:39:11 +00:00
break;
2005-02-04 16:00:37 +00:00
case XP_LISP_OBJ_PRIM:
2005-02-04 16:23:34 +00:00
xp_printf (XP_TEXT("prim"));
2005-02-04 15:39:11 +00:00
break;
default:
2005-02-04 16:23:34 +00:00
xp_printf (XP_TEXT("unknown object type: %d"), XP_LISP_TYPE(obj));
2005-02-04 15:39:11 +00:00
}
}
void xp_lisp_print (xp_lisp_t* lsp, xp_lisp_obj_t* obj)
{
2005-02-04 16:00:37 +00:00
switch (XP_LISP_TYPE(obj)) {
case XP_LISP_OBJ_NIL:
2005-02-04 16:23:34 +00:00
xp_fprintf (lsp->outstream,XP_TEXT("nil"));
2005-02-04 15:39:11 +00:00
break;
2005-02-04 16:00:37 +00:00
case XP_LISP_OBJ_TRUE:
2005-02-04 16:23:34 +00:00
xp_fprintf (lsp->outstream,XP_TEXT("t"));
2005-02-04 15:39:11 +00:00
break;
2005-02-04 16:00:37 +00:00
case XP_LISP_OBJ_INT:
2005-02-14 14:37:50 +00:00
if (xp_sizeof(xp_lisp_int_t) == xp_sizeof(int)) {
xp_fprintf (lsp->outstream,XP_TEXT("%d"), XP_LISP_IVALUE(obj));
}
else if (xp_sizeof(xp_lisp_int_t) == xp_sizeof(long)) {
xp_fprintf (lsp->outstream,XP_TEXT("%ld"), XP_LISP_IVALUE(obj));
}
else if (xp_sizeof(xp_lisp_int_t) == xp_sizeof(long long)) {
xp_fprintf (lsp->outstream,XP_TEXT("%lld"), XP_LISP_IVALUE(obj));
}
2005-02-04 15:39:11 +00:00
break;
2005-02-04 16:00:37 +00:00
case XP_LISP_OBJ_FLOAT:
2005-02-04 16:23:34 +00:00
xp_fprintf (lsp->outstream,XP_TEXT("%f"), XP_LISP_FVALUE(obj));
2005-02-04 15:39:11 +00:00
break;
2005-02-04 16:00:37 +00:00
case XP_LISP_OBJ_SYMBOL:
2005-02-04 16:23:34 +00:00
xp_fprintf (lsp->outstream,XP_TEXT("%s"), XP_LISP_SYMVALUE(obj));
2005-02-04 15:39:11 +00:00
break;
2005-02-04 16:00:37 +00:00
case XP_LISP_OBJ_STRING:
2005-02-04 16:23:34 +00:00
xp_fprintf (lsp->outstream,XP_TEXT("\"%s\""), XP_LISP_STRVALUE(obj));
2005-02-04 15:39:11 +00:00
break;
2005-02-04 16:00:37 +00:00
case XP_LISP_OBJ_CONS:
2005-02-04 15:39:11 +00:00
{
xp_lisp_obj_t* p = obj;
2005-02-04 16:23:34 +00:00
xp_fprintf (lsp->outstream,XP_TEXT("("));
2005-02-04 15:39:11 +00:00
do {
2005-02-04 16:00:37 +00:00
xp_lisp_print (lsp, XP_LISP_CAR(p));
p = XP_LISP_CDR(p);
2005-02-04 15:39:11 +00:00
if (p != lsp->mem->nil) {
2005-02-04 16:23:34 +00:00
xp_fprintf (lsp->outstream,XP_TEXT(" "));
2005-02-04 16:00:37 +00:00
if (XP_LISP_TYPE(p) != XP_LISP_OBJ_CONS) {
2005-02-04 16:23:34 +00:00
xp_fprintf (lsp->outstream,XP_TEXT(". "));
2005-02-04 15:39:11 +00:00
xp_lisp_print (lsp, p);
}
}
2005-02-04 16:00:37 +00:00
} while (p != lsp->mem->nil && XP_LISP_TYPE(p) == XP_LISP_OBJ_CONS);
2005-02-04 16:23:34 +00:00
xp_fprintf (lsp->outstream,XP_TEXT(")"));
2005-02-04 15:39:11 +00:00
}
break;
2005-02-04 16:00:37 +00:00
case XP_LISP_OBJ_FUNC:
2005-02-04 16:23:34 +00:00
xp_fprintf (lsp->outstream,XP_TEXT("func"));
2005-02-04 15:39:11 +00:00
break;
2005-02-04 16:00:37 +00:00
case XP_LISP_OBJ_MACRO:
2005-02-04 16:23:34 +00:00
xp_fprintf (lsp->outstream,XP_TEXT("macro"));
2005-02-04 15:39:11 +00:00
break;
2005-02-04 16:00:37 +00:00
case XP_LISP_OBJ_PRIM:
2005-02-04 16:23:34 +00:00
xp_fprintf (lsp->outstream,XP_TEXT("prim"));
2005-02-04 15:39:11 +00:00
break;
default:
2005-02-04 16:00:37 +00:00
xp_fprintf (lsp->outstream,
2005-02-04 16:23:34 +00:00
XP_TEXT("unknown object type: %d"), XP_LISP_TYPE(obj));
2005-02-04 15:39:11 +00:00
}
}