-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobject.cpp
37 lines (29 loc) · 1.06 KB
/
object.cpp
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
//
// Created by 23766 on 2024/10/7.
//
#include "object.h"
Integer::Integer(int64_t val) : value(val) {}
Integer::~Integer() = default;
Boolean_obj::Boolean_obj(bool value) : value(value) {}
Boolean_obj::~Boolean_obj() = default ;
ReturnValue::ReturnValue(std::unique_ptr<Object> parm) : value(std::move(parm)){}
ReturnValue::~ReturnValue() = default;
Error::Error(std::string msg) : message(msg){}
Error::~Error() = default;
Environment::Environment(std::unique_ptr<Environment> new_env):store(std::map<std::string,std::unique_ptr<Object>>()),outer(std::move(new_env)) {}
Environment::~Environment() = default;
std::pair<std::unique_ptr<Object>, bool> Environment::Get(std::string name) {
auto item = store.find(name);
if (item != store.end()){
return {std::move(item->second), true};
}
if ( outer != nullptr ) {
return outer->Get(name);
}
return {nullptr, false};
}
void Environment::Set(std::string name, std::unique_ptr<Object> val) {
store[name] = std::move(val);
}
Function::Function() = default;
Function::~Function() = default;