-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathyascm.h
100 lines (91 loc) · 2.4 KB
/
yascm.h
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
/*
* "yascm.h" yascm data types and external functions.
* Copyright (C) 2015 Hmgle <[email protected]>
*
* 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 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef _YASCM_H
#define _YASCM_H
#include <stdint.h>
#include <stdbool.h>
#include <assert.h>
#define debug_print(fmt, ...) \
do { \
fprintf(stderr, "debug_print: %s: %d: %s():" \
fmt "\n", __FILE__, __LINE__, __func__, \
##__VA_ARGS__); \
} while (0)
#define DIE(fmt, ...) \
do { \
debug_print(fmt, ##__VA_ARGS__); \
exit(-1); \
} while (0)
typedef enum {
FIXNUM,
FLOATNUM,
BOOL,
CHAR,
STRING,
PAIR,
SYMBOL,
KEYWORD,
PRIM,
COMPOUND_PROC,
ENV,
OTHER,
} object_type;
typedef struct object_s object;
typedef object *Primitive(object *env, object *args);
struct object_s {
object_type type;
union {
int64_t int_val; /* FIXNUM */
long double float_val; /* FLOATNUM */
bool bool_val; /* BOOL */
char char_val; /* CHAR */
char *string_val; /* STRING */
struct { /* PAIR */
object *car;
object *cdr;
};
struct { /* COMPOUND_PROC */
object *parameters;
object *body;
object *env;
};
struct { /* env frame */
object *vars;
object *up;
};
Primitive *func;
};
};
object *cons(object *car, object *cdr);
object *make_bool(bool val);
object *make_char(char val);
object *make_string(const char *val);
object *make_fixnum(int64_t val);
object *make_floatnum(long double val);
object *make_emptylist(void);
object *make_symbol(const char *name);
object *make_quote(object *obj);
object *make_function(object *parameters, object *body, object *env);
object *make_env(object *var, object *up);
object *eval(object *env, object *obj);
void object_print(const object *obj);
void eof_handle(void);
long double getval(object* val);
object *make_numval(long double val, object_type type);
object *make_numobj(object* val);
#endif