-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlval.hpp
133 lines (83 loc) · 2.44 KB
/
lval.hpp
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#ifndef LVAL_HPP
#define LVAL_HPP
#include <iostream>
#include <list>
#include <string>
#include "builtin.hpp"
#include "mpc.h"
enum class lval_type {
integer,
decimal,
number,
boolean,
symbol,
cname,
string,
func,
macro,
command,
sexpr,
qexpr,
error
};
std::ostream &operator<<(std::ostream &os, const lval_type &type);
struct lenv;
struct lval {
lval_type type;
long integ;
double dec;
bool boolean;
std::string err;
std::string sym;
std::string str;
lbuiltin builtin;
lenv *env;
lval *formals;
lval *body;
using cell_type = std::list<lval *>;
cell_type cells;
using iter = cell_type::iterator;
explicit lval(lval_type type);
explicit lval(long num);
explicit lval(double num);
explicit lval(bool boolean);
explicit lval(std::string str);
lval(const lval &other);
explicit lval(const lval *const other);
static lval *symbol(std::string err);
static lval *cname(std::string err);
static lval *error(std::string err);
static lval *function(lbuiltin fun);
static lval *function(lval *formals, lval *body);
static lval *macro(lbuiltin fun);
static lval *macro(lval *formals, lval *body);
static lval *command(lbuiltin fun);
static lval *sexpr();
static lval *sexpr(std::initializer_list<lval *> cells);
static lval *qexpr();
static lval *qexpr(std::initializer_list<lval *> cells);
~lval();
bool is_number() const;
double get_number() const;
lval *pop(const iter &it);
lval *pop(size_t i);
lval *pop_first();
lval *call(lenv *e, lval *a);
static lval *take(lval *v, const iter &it);
static lval *take(lval *v, size_t i);
static lval *take_first(lval *v);
static lval *read_integer(mpc_ast_t *t);
static lval *read_decimal(mpc_ast_t *t);
static lval *read_string(mpc_ast_t *t);
static lval *read(mpc_ast_t *t);
static lval *eval(lenv *e, lval *v);
static lval *eval_sexpr(lenv *e, lval *v);
static lval *eval_qexpr(lenv *e, lval *v);
static lval *eval_cells(lenv *e, lval *v);
friend std::ostream &operator<<(std::ostream &os, const lval &value);
std::ostream &print_expr(std::ostream &os, char open, char close) const;
std::ostream &print_str(std::ostream &os) const;
bool operator==(const lval &other) const;
bool operator!=(const lval &other) const;
};
#endif // LVAL_HPP