-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnvironment.h
More file actions
37 lines (25 loc) · 1.02 KB
/
Environment.h
File metadata and controls
37 lines (25 loc) · 1.02 KB
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
#pragma once
#include "Symbol.h"
#include <unordered_map>
class SValue;
class Environment
{
public:
Environment( Environment* parent = nullptr );
/// Gets a copy of the value for the given symbol.
// Copy is stored in v.
SValue* get( const Symbol& s, SValue* v ) const;
/// Define a symbol with a given value. A copy of the value is stored.
void set( const Symbol& s, const SValue& v );
/// Defines the symbol at the root. A copy of the value is stored.
void rootSet( const Symbol& s, const SValue& v );
Environment* parent = nullptr;
private:
friend std::ostream& operator<<( std::ostream& o, const Environment& e );
// If we want to use a map, then the SValues must be stored as shared_ptr. (or other indirection that supports copy).
// This is because map can modify the internal buffer and do copies.
//
// If using a vector to store, we could use unique_ptr
std::unordered_map< Symbol, std::shared_ptr< SValue >, SymbolHash > env;
};
std::ostream& operator<<( std::ostream& o, const Environment& e );