-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.cpp
More file actions
36 lines (32 loc) · 967 Bytes
/
function.cpp
File metadata and controls
36 lines (32 loc) · 967 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
#include "function.h"
Object* EvalBoolValue(bool b) {
return (b) ? new Boolean{"#t"} : new Boolean{"#f"};
}
Object* CanEval(Object* obj, Scope* scope) {
if (dynamic_cast<Holder*>(obj) || dynamic_cast<Function*>(obj) || dynamic_cast<Symbol*>(obj) ||
dynamic_cast<Quote*>(obj)) {
return obj->Eval(scope);
}
return nullptr;
}
bool CheckAllNumbers(const std::vector<Object*>& args, Scope* scope,
std::vector<Object*>& eval_args) {
for (size_t i = 0; i != args.size(); ++i) {
if (auto eval_arg = CanEval(args[i], scope)) {
eval_args.push_back(eval_arg);
} else {
eval_args.push_back(args[i]);
}
if (!dynamic_cast<Number*>(eval_args[i])) {
return false;
}
}
return true;
}
bool MakeLogicOperation(bool is_and, bool cur, bool next) {
if (is_and) {
return cur && next;
} else {
return cur || next;
}
}