-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscheme.h
More file actions
38 lines (32 loc) · 790 Bytes
/
scheme.h
File metadata and controls
38 lines (32 loc) · 790 Bytes
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
#pragma once
#include "parser.h"
#include <string>
#include <unordered_map>
#include <sstream>
#include <iostream>
class Scope {
public:
std::shared_ptr<Object> Lookup(const std::string& name);
std::unordered_map<std::string, std::shared_ptr<Object>> scope_;
std::shared_ptr<Scope> outer_scope_;
};
class Scheme {
public:
Scheme();
~Scheme();
std::shared_ptr<Object> EvaluateExpr(std::shared_ptr<Object> in);
private:
std::shared_ptr<Scope> global_scope_;
};
inline void PrintTo(const std::shared_ptr<Object>& obj, std::ostream* out) {
if (!obj) {
*out << "()";
return;
}
obj->PrintTo(out);
}
inline std::string Print(const std::shared_ptr<Object>& obj) {
std::stringstream ss;
PrintTo(obj, &ss);
return ss.str();
}