1 /* -*-comment-start: "//";comment-end:""-*-
2 * Mes --- Maxwell Equations of Software
3 * Copyright © 2016,2017,2018 Jan Nieuwenhuizen <janneke@gnu.org>
5 * This file is part of Mes.
7 * Mes is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or (at
10 * your option) any later version.
12 * Mes is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Mes. If not, see <http://www.gnu.org/licenses/>.
22 SCM fdisplay_ (SCM, int, int);
25 display_helper (SCM x, int cont, char* sep, int fd, int write_p)
28 if (g_depth == 0) return cell_unspecified;
29 g_depth = g_depth - 1;
36 fputc (VALUE (x), fd);
41 fputs ("#<closure ", fd);
42 display_helper (CDR (x), cont, "", fd, 0);
48 fputs ("#<procedure ", fd);
50 if (FUNCTION (x).name != 0)
51 p = FUNCTION (x).name;
54 fputs (itoa (CDR (x)), fd);
62 fputs ("#<macro ", fd);
63 display_helper (CDR (x), cont, "", fd, 0);
69 fputs (itoa (VALUE (x)), fd);
74 if (!cont) fputs ("(", fd);
75 if (CAR (x) == cell_circular)
76 fputs ("*circ* . #-1#", fd);
79 if (x && x != cell_nil) fdisplay_ (CAR (x), fd, write_p);
80 if (CDR (x) && TYPE (CDR (x)) == TPAIR)
81 display_helper (CDR (x), 1, " ", fd, write_p);
82 else if (CDR (x) && CDR (x) != cell_nil)
84 if (TYPE (CDR (x)) != TPAIR)
86 fdisplay_ (CDR (x), fd, write_p);
89 if (!cont) fputs (")", fd);
96 if (write_p && TYPE (x) == TSTRING) fputc ('"', fd);
98 while (t && t != cell_nil)
100 fputc (VALUE (CAR (t)), fd);
103 if (write_p && TYPE (x) == TSTRING) fputc ('"', fd);
109 fputs (itoa (TYPE (x)), fd);
111 fputs (itoa (x), fd);
123 return display_helper (x, 0, "", g_stdout, 0);
127 display_error_ (SCM x)
130 return display_helper (x, 0, "", STDERR, 0);
134 display_port_ (SCM x, SCM p)
136 assert (TYPE (p) == TNUMBER);
137 return fdisplay_ (x, VALUE (p), 0);
144 return display_helper (x, 0, "", g_stdout, 1);
148 write_port_ (SCM x, SCM p)
150 assert (TYPE (p) == TNUMBER);
151 return fdisplay_ (x, VALUE (p), 1);
155 fdisplay_ (SCM x, int fd, int write_p) ///((internal))
158 return display_helper (x, 0, "", fd, write_p);
162 exit_ (SCM x) ///((name . "exit"))
164 assert (TYPE (x) == TNUMBER);
169 xassq (SCM x, SCM a) ///for speed in core only
171 while (a != cell_nil && x != CDAR (a)) a = CDR (a);
172 return a != cell_nil ? CAR (a) : cell_f;