summaryrefslogtreecommitdiff
path: root/evaluate.cpp
blob: c73d59a864f4f0e48d6b572a97de31b37edc482a (plain)
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
#include <map>
#include <cassert>
#include "evaluate.h"

using namespace std;


Value::Value(double numval)
	:type(Type::number),numval(numval){}
Value::Value(const string &strval)
	:type(Type::string),strval(strval){}
Value::Value(const Scope &scope)
	:type(Type::scope),scope(scope){}


namespace A {
	map<Value*,int> collection;

	template <typename ...Args>
	Value* ref_create(Args... args){
		Value *value=new Value(args...);
		return ref(value);
	}

	Value* ref(Value *value){
		auto it=collection.find(value);
		if(it==collection.end()){
			collection.emplace(value,1);
		} else {
			it->second++;
		}
		return value;
	}

	void unref(Value *value){
		auto it=collection.find(value);
		assert(it!=collection.end());
		if(it->second==1){
			delete value;
			collection.erase(it);
		} else {
			it->second--;
		}
	}
}


void evaluateSTL(const StatementList &stl){
	;
}