-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTypedValue.cpp
84 lines (65 loc) · 1.35 KB
/
TypedValue.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "TypedValue.h"
#include "FunctionPointer.h"
TypedValue::TypedValue(ValueType type)
: type(type)
{ }
bool TypedValue::is(ValueType type) const
{
return TypedValue::type == type;
}
ValueType TypedValue::getType() const
{
return type;
}
NumberValue::NumberValue(double value)
: TypedValue(ValueType::Number), value(value)
{ }
double NumberValue::getValue() const
{
return value;
}
void NumberValue::print(std::ostream & os) const
{
os << value;
}
BoolValue::BoolValue(bool value)
: TypedValue(ValueType::Bool), value(value)
{ }
bool BoolValue::getValue() const
{
return value;
}
void BoolValue::print(std::ostream & os) const
{
os << (value ? "true" : "false");
}
FunctionValue::FunctionValue(std::shared_ptr<FunctionPointer> value)
: TypedValue(ValueType::Function), value(value)
{ }
std::shared_ptr<FunctionPointer> FunctionValue::getValue() const
{
return value;
}
void FunctionValue::print(std::ostream & os) const
{
os << "function " << value->getSignature();
}
UndefinedValue::UndefinedValue()
: TypedValue(ValueType::Undefined)
{ }
void UndefinedValue::print(std::ostream & os) const
{
os << "undefined";
}
ErrorValue::ErrorValue()
: TypedValue(ValueType::Error)
{ }
void ErrorValue::print(std::ostream & os) const
{
os << "error";
}
std::ostream & operator<<(std::ostream & os, const TypedValue & other)
{
other.print(os);
return os;
}