summaryrefslogtreecommitdiff
path: root/evaluate.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'evaluate.cpp')
-rw-r--r--evaluate.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/evaluate.cpp b/evaluate.cpp
new file mode 100644
index 0000000..c73d59a
--- /dev/null
+++ b/evaluate.cpp
@@ -0,0 +1,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){
+ ;
+}