aboutsummaryrefslogtreecommitdiff
path: root/src/eval.c
blob: cc3da503b0c6f9eb783fc03adfcecd54119346f7 (plain)
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
/* This file is part of Gamma.
   Copyright (C) 2010 Sergey Poznyakoff

   Gamma is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3, or (at your option)
   any later version.

   Gamma is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with Gamma.  If not, see <http://www.gnu.org/licenses/>. */

#include "gamma-expat.h"


/* General-purpose eval handlers */

SCM
gamma_eval_catch_body(void *list)
{
	return scm_primitive_eval((SCM)list);
}

static SCM
eval_catch_handler (void *data, SCM tag, SCM throw_args)
{
	scm_handle_by_message_noexit("gamma", tag, throw_args);
	longjmp(*(jmp_buf*)data, 1);
}

struct scheme_exec_data {
	SCM (*handler) (void *data);
	void *data;
	SCM result;
};

static SCM
scheme_safe_exec_body (void *data)
{
	struct scheme_exec_data *ed = data;
	ed->result = ed->handler(ed->data);
	return SCM_BOOL_F;
}

int
gamma_safe_exec(SCM (*handler) (void *data), void *data, SCM *result)
{
	jmp_buf jmp_env;
	struct scheme_exec_data ed;
	
	if (setjmp(jmp_env))
		exit(70); /* EX_SOFTWARE */
	ed.handler = handler;
	ed.data = data;
	scm_internal_lazy_catch(SCM_BOOL_T,
				scheme_safe_exec_body, (void*)&ed,
				eval_catch_handler, &jmp_env);
	if (result)
		*result = ed.result;
	return 0;
}

char *
gamma_proc_name(SCM proc)
{
	return scm_to_locale_string(
		scm_symbol_to_string(scm_procedure_name(proc)));
}

Return to:

Send suggestions and report system problems to the System administrator.