-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy patheval.c
66 lines (58 loc) · 2.05 KB
/
eval.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
/**
* Copyright (C) 2023-2025 by Massimiliano Ghilardi
*
* This program 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 2 of the License, or
* (at your option) any later version.
*/
#include "eval.h"
#include "containers/containers.h" /* schemesh_Sstring_utf8b() */
#include <stddef.h> /* NULL */
#include <string.h> /* strlen() */
static ptr top_level_value(const char symbol_name[]) {
return Stop_level_value(Sstring_to_symbol(symbol_name));
}
/**
* call global Scheme procedure with no arguments.
* Return the resulting Scheme value.
*/
ptr schemesh_call0(const char symbol_name[]) {
return Scall0(top_level_value(symbol_name));
}
/**
* call global Scheme procedure having specified symbol name
* passing a single Scheme argument to it.
* Return the resulting Scheme value.
*/
ptr schemesh_call1(const char symbol_name[], ptr arg) {
return Scall1(top_level_value(symbol_name), arg);
}
/**
* call global Scheme procedure having specified symbol name
* passing two Scheme arguments to it.
* Return the resulting Scheme value.
*/
ptr schemesh_call2(const char symbol_name[], ptr arg1, ptr arg2) {
return Scall2(top_level_value(symbol_name), arg1, arg2);
}
/**
* call global Scheme procedure having specified symbol name
* passing three Scheme arguments to it.
* Return the resulting Scheme value.
*/
ptr schemesh_call3(const char symbol_name[], ptr arg1, ptr arg2, ptr arg3) {
return Scall3(top_level_value(symbol_name), arg1, arg2, arg3);
}
/**
* call Scheme (eval (read (open-string-input-port str))) on a C string
* and return the resulting Scheme value.
* Cannot use (sh-eval) because it may be called before loading libschemesh.
*/
ptr schemesh_eval(const char str[]) {
/* this must work even if libschemesh is not loaded -> cannot use (sh-eval...) */
return schemesh_call1(
"eval",
schemesh_call1("read",
schemesh_call1("open-string-input-port", schemesh_Sstring_utf8b(str, -1))));
}