-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecd.hh
54 lines (42 loc) · 1.42 KB
/
secd.hh
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
#pragma once
#include <iostream>
#include <string>
#include <vector>
class Data;
class SECD {
public:
SECD(size_t memory_limit);
~SECD();
size_t memory() const;
// Reader/Printer Sections 11.3,5
Data *getexp(std::istream &is);
Data *getexplist(std::istream &is);
void putexp(Data *e, std::ostream &os) const;
// VM execution Section 11.8
Data *exec(Data *fn, Data *args);
private:
// Memory handling Section 12.2
void gc();
Data *getNextCell();
// Cell constructors Section 11.1
Data *symbol(std::string s);
Data *number(int n);
Data *cons(Data *a, Data *b);
// Reader utilities Sections 11.3-4
struct Token {
enum class TokenType { ALPHANUMERIC, NUMERIC, DELIMITER, ENDFILE } type;
std::string value;
};
Data *getexp(const Token &token, std::istream &is);
Data *getexplist(std::istream &is, Data *next_car);
static Token gettoken(std::istream &is);
// Machine state Section 11.8
Data *s, *e, *c, *d;
Data *w, *t, *f, *nil;
bool running;
// Memory pool Section 12.1
std::vector<Data *> data;
Data *free_list;
// String store Section 12.3
std::vector<std::string> strings;
};