-
Notifications
You must be signed in to change notification settings - Fork 1
/
scheme_error.c
108 lines (94 loc) · 2.59 KB
/
scheme_error.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
libscheme
Copyright (c) 1994 Brent Benson
All rights reserved.
Permission is hereby granted, without written agreement and without
license or royalty fees, to use, copy, modify, and distribute this
software and its documentation for any purpose, provided that the
above copyright notice and the following two paragraphs appear in
all copies of this software.
IN NO EVENT SHALL BRENT BENSON BE LIABLE TO ANY PARTY FOR DIRECT,
INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF BRENT
BENSON HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
BRENT BENSON SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT
NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER
IS ON AN "AS IS" BASIS, AND BRENT BENSON HAS NO OBLIGATION TO
PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
MODIFICATIONS.
*/
#include "scheme.h"
#include <stdio.h>
/* globals */
jmp_buf scheme_error_buf;
/* locals */
static Scheme_Value error (int argc, Scheme_Value argv[]);
static Scheme_Value scheme_exit (int argc, Scheme_Value argv[]);
void
scheme_init_error (Scheme_Env *env)
{
scheme_add_prim ("error", error, env);
scheme_add_prim ("exit", scheme_exit, env);
}
SCHEME_FUN_NORETURN
void
scheme_signal_error (char *msg, ...)
{
va_list args;
va_start (args, msg);
/* fprintf (stderr, "error: "); */
vfprintf (stderr, msg, args);
fprintf (stderr, "\n");
va_end (args);
longjmp (scheme_error_buf, 1);
}
void
scheme_warning (char *msg, ...)
{
va_list args;
va_start (args, msg);
vfprintf (stderr, msg, args);
fprintf (stderr, "\n");
va_end (args);
}
static Scheme_Value
error (int argc, Scheme_Value argv[])
{
int i;
SCHEME_ASSERT ((argc > 0), "error: wrong number of args");
SCHEME_ASSERT (SCHEME_STRINGP (argv[0]), "error: first arg must be a string");
fprintf (stderr, "error: %s:", SCHEME_STR_VAL (argv[0]));
for ( i=1; i<argc ; ++i )
{
scheme_write (argv[i], scheme_stderr_port);
}
fprintf (stderr, "\n");
longjmp (scheme_error_buf, 1);
}
void
scheme_default_handler (void)
{
if (setjmp (scheme_error_buf))
{
abort ();
}
}
static Scheme_Value
scheme_exit (int argc, Scheme_Value argv[])
{
int status;
SCHEME_ASSERT ((argc == 0) || (argc == 1),
"exit: wrong number of arguments");
if (argc == 1)
{
SCHEME_ASSERT (SCHEME_INTP (argv[0]),
"exit: arg must be an integer");
status = SCHEME_INT_VAL (argv[0]);
}
else
{
status = 0;
}
exit (status);
}