Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Implementation of Programming Languages / Transpiler / src / Value
diff options
context:
space:
mode:
Commit4d359b9c16b01847b26d6827e137f680c65969f2 (patch)
Author
 Syndamia <kamen@syndamia.com>
2023-02-07 20:06:31 +0200
Committer
 Syndamia <kamen@syndamia.com>
2023-02-07 20:06:31 +0200
Files2af4cf7c92237f1a55550cd8866e8bcb0b51b87c /Year 2/Implementation of Programming Languages/Transpiler/src/Value
uni-projects-4d359b9c16b01847b26d6827e137f680c65969f2.tar
uni-projects-4d359b9c16b01847b26d6827e137f680c65969f2.tar.gz
uni-projects-4d359b9c16b01847b26d6827e137f680c65969f2.zip
Parent38c4a1355cb573d47c3e26f83ca8e916b62c80d1 (diff)
[IPL/T] Overhauled how functions are handled, added list type
18 files changed, 58 insertions, 126 deletions
-rw-r--r--Year 2/Implementation of Programming Languages/Transpiler/src/Value/Casting.h0
-rw-r--r--Year 2/Implementation of Programming Languages/Transpiler/src/Value/Float.cpp6
-rw-r--r--Year 2/Implementation of Programming Languages/Transpiler/src/Value/Float.h3
-rw-r--r--Year 2/Implementation of Programming Languages/Transpiler/src/Value/Function/BuiltInFunction.cpp14
-rw-r--r--Year 2/Implementation of Programming Languages/Transpiler/src/Value/Function/BuiltInFunction.h13
-rw-r--r--Year 2/Implementation of Programming Languages/Transpiler/src/Value/Function/Funcall.cpp16
-rw-r--r--Year 2/Implementation of Programming Languages/Transpiler/src/Value/Function/Funcall.h11
-rw-r--r--Year 2/Implementation of Programming Languages/Transpiler/src/Value/Function/Function.cpp12
-rw-r--r--Year 2/Implementation of Programming Languages/Transpiler/src/Value/Function/Function.h21
-rw-r--r--Year 2/Implementation of Programming Languages/Transpiler/src/Value/Function/UserFunction.cpp14
-rw-r--r--Year 2/Implementation of Programming Languages/Transpiler/src/Value/Function/UserFunction.h16
-rw-r--r--Year 2/Implementation of Programming Languages/Transpiler/src/Value/Integer.cpp6
-rw-r--r--Year 2/Implementation of Programming Languages/Transpiler/src/Value/Integer.h3
-rw-r--r--Year 2/Implementation of Programming Languages/Transpiler/src/Value/List.cpp12
-rw-r--r--Year 2/Implementation of Programming Languages/Transpiler/src/Value/List.h17
-rw-r--r--Year 2/Implementation of Programming Languages/Transpiler/src/Value/Name.cpp7
-rw-r--r--Year 2/Implementation of Programming Languages/Transpiler/src/Value/Name.h3
-rw-r--r--Year 2/Implementation of Programming Languages/Transpiler/src/Value/Value.h10
diff --git a/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Casting.h b/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Casting.h
deleted file mode 100644
index e69de29..0000000
--- a/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Casting.h
+++ /dev/null
diff --git a/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Float.cpp b/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Float.cpp
index 91268d7..d3a3c04 100644
--- a/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Float.cpp
+++ b/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Float.cpp
@@ -1,14 +1,10 @@
#include "Float.h"
#include "../LLVMVisitor/LLVMVisitor.h"
-std::string Float::Visit(LLVMVisitor& visitor) const {
+LLVMRet Float::Visit(LLVMVisitor& visitor) const {
return visitor.Visit(*this);
}
-Value::T_Primitive Float::RetType() const {
- return Value::T_float;
-}
-
const double& Float::get_value() const {
return this->value;
}
diff --git a/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Float.h b/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Float.h
index 0f47be1..b87fd18 100644
--- a/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Float.h
+++ b/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Float.h
@@ -6,8 +6,7 @@
class Float : public Value {
double value;
public:
- std::string Visit(LLVMVisitor& visitor) const override;
- T_Primitive RetType() const override;
+ LLVMRet Visit(LLVMVisitor& visitor) const override;
const double& get_value() const;
Float(double value);
diff --git a/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Function/BuiltInFunction.cpp b/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Function/BuiltInFunction.cpp
deleted file mode 100644
index 954c8da..0000000
--- a/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Function/BuiltInFunction.cpp
+++ /dev/null
@@ -1,14 +0,0 @@
-#include "BuiltInFunction.h"
-#include "../../LLVMVisitor/LLVMVisitor.h"
-
-std::string BuiltInFunction::Visit(LLVMVisitor& visitor) const {
- return visitor.Visit(*this);
-}
-
-Value::T_Primitive BuiltInFunction::RetType() const {
- if (args.empty())
- return T_void;
- return args.front()->RetType();
-}
-
-BuiltInFunction::BuiltInFunction(std::string name, std::deque<Value*> args) : Function(name, args) {}
diff --git a/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Function/BuiltInFunction.h b/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Function/BuiltInFunction.h
deleted file mode 100644
index c4ea301..0000000
--- a/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Function/BuiltInFunction.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#ifndef VALUE_ADDFUNCTION
-#define VALUE_ADDFUNCTION
-
-#include "Function.h"
-
-class BuiltInFunction : public Function {
-public:
- std::string Visit(LLVMVisitor& visitor) const override;
- T_Primitive RetType() const override;
- BuiltInFunction(std::string name, std::deque<Value*> args);
-};
-
-#endif
diff --git a/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Function/Funcall.cpp b/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Function/Funcall.cpp
index e69de29..df88001 100644
--- a/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Function/Funcall.cpp
+++ b/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Function/Funcall.cpp
@@ -0,0 +1,16 @@
+#include "Funcall.h"
+#include "../../LLVMVisitor/LLVMVisitor.h"
+
+const std::string& Funcall::get_funname() const {
+ return funName;
+}
+
+const std::vector<Value*>& Funcall::get_args() const {
+ return args;
+}
+
+LLVMRet Funcall::Visit(LLVMVisitor& visitor) const {
+ return visitor.Visit(*this);
+}
+
+Funcall::Funcall(std::string funName, std::vector<Value*> args) : funName(funName), args(args) {}
diff --git a/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Function/Funcall.h b/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Function/Funcall.h
index 5afc51d..30dda60 100644
--- a/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Function/Funcall.h
+++ b/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Function/Funcall.h
@@ -1,20 +1,19 @@
#ifndef VALUE_FUNCALL
#define VALUE_FUNCALL
-#include <deque>
+#include <vector>
#include "../Value.h"
class Funcall : public Value {
std::string funName;
- std::deque<Value*> args;
+ std::vector<Value*> args;
public:
const std::string& get_funname() const;
- const std::deque<Value*>& get_args() const;
+ const std::vector<Value*>& get_args() const;
- std::string Visit(LLVMVisitor& visitor) const override;
- T_Primitive RetType() const override;
+ LLVMRet Visit(LLVMVisitor& visitor) const override;
- Funcall(std::string funName, std::deque<Value*> args);
+ Funcall(std::string funName, std::vector<Value*> args);
~Funcall() override = default;
};
diff --git a/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Function/Function.cpp b/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Function/Function.cpp
deleted file mode 100644
index 9e35eab..0000000
--- a/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Function/Function.cpp
+++ /dev/null
@@ -1,12 +0,0 @@
-#include "Function.h"
-#include "../../LLVMVisitor/LLVMVisitor.h"
-
-const std::string& Function::get_name() const {
- return name;
-}
-
-const std::deque<Value*> Function::get_args() const {
- return args;
-}
-
-Function::Function(std::string name, std::deque<Value*> args) : name(name), args(args) {}
diff --git a/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Function/Function.h b/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Function/Function.h
deleted file mode 100644
index 34e3ea1..0000000
--- a/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Function/Function.h
+++ /dev/null
@@ -1,21 +0,0 @@
-#ifndef VALUE_FUNCTION
-#define VALUE_FUNCTION
-
-#include <string>
-#include <deque>
-#include "../Value.h"
-
-class Function : public Value {
-protected:
- std::string name;
- std::deque<Value*> args;
-
-public:
- const std::string& get_name() const;
- const std::deque<Value*> get_args() const;
-
- Function(std::string name, std::deque<Value*> args);
- ~Function() override = default;
-};
-
-#endif
diff --git a/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Function/UserFunction.cpp b/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Function/UserFunction.cpp
deleted file mode 100644
index a9841d3..0000000
--- a/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Function/UserFunction.cpp
+++ /dev/null
@@ -1,14 +0,0 @@
-#include "UserFunction.h"
-#include "../../LLVMVisitor/LLVMVisitor.h"
-
-std::string UserFunction::Visit(LLVMVisitor& visitor) const {
- return visitor.Visit(*this);
-}
-
-Value::T_Primitive UserFunction::RetType() const {
- if (body.empty())
- return T_void;
- return body.back()->RetType();
-}
-
-UserFunction::UserFunction(std::string name, std::deque<Value*> args, std::deque<Function*> body) : Function(name, args), body(body) {}
diff --git a/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Function/UserFunction.h b/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Function/UserFunction.h
deleted file mode 100644
index 17cf931..0000000
--- a/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Function/UserFunction.h
+++ /dev/null
@@ -1,16 +0,0 @@
-#ifndef VALUE_USERFUNCTION
-#define VALUE_USERFUNCTION
-
-#include <deque>
-#include "Function.h"
-
-class UserFunction : public Function {
- std::deque<Function*> body;
-
-public:
- std::string Visit(LLVMVisitor& visitor) const override;
- T_Primitive RetType() const override;
- UserFunction(std::string name, std::deque<Value*> args, std::deque<Function*> body);
-};
-
-#endif
diff --git a/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Integer.cpp b/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Integer.cpp
index 01bbe54..6fb7b73 100644
--- a/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Integer.cpp
+++ b/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Integer.cpp
@@ -1,14 +1,10 @@
#include "Integer.h"
#include "../LLVMVisitor/LLVMVisitor.h"
-std::string Integer::Visit(LLVMVisitor& visitor) const {
+LLVMRet Integer::Visit(LLVMVisitor& visitor) const {
return visitor.Visit(*this);
}
-Value::T_Primitive Integer::RetType() const {
- return Value::T_integer;
-}
-
const int& Integer::get_value() const {
return this->value;
}
diff --git a/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Integer.h b/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Integer.h
index 4a84c31..86aafb9 100644
--- a/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Integer.h
+++ b/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Integer.h
@@ -6,8 +6,7 @@
class Integer : public Value {
int value;
public:
- std::string Visit(LLVMVisitor& visitor) const override;
- T_Primitive RetType() const override;
+ LLVMRet Visit(LLVMVisitor& visitor) const override;
const int& get_value() const;
Integer(int value);
diff --git a/Year 2/Implementation of Programming Languages/Transpiler/src/Value/List.cpp b/Year 2/Implementation of Programming Languages/Transpiler/src/Value/List.cpp
new file mode 100644
index 0000000..63a7e01
--- /dev/null
+++ b/Year 2/Implementation of Programming Languages/Transpiler/src/Value/List.cpp
@@ -0,0 +1,12 @@
+#include "List.h"
+#include "../LLVMVisitor/LLVMVisitor.h"
+
+LLVMRet List::Visit(LLVMVisitor& visitor) const {
+ return visitor.Visit(*this);
+}
+
+const std::vector<Value*>& List::get_value() const {
+ return vals;
+}
+
+List::List(std::vector<Value*> val) : vals(val) {}
diff --git a/Year 2/Implementation of Programming Languages/Transpiler/src/Value/List.h b/Year 2/Implementation of Programming Languages/Transpiler/src/Value/List.h
new file mode 100644
index 0000000..770b87b
--- /dev/null
+++ b/Year 2/Implementation of Programming Languages/Transpiler/src/Value/List.h
@@ -0,0 +1,17 @@
+#ifndef VALUE_LIST
+#define VALUE_LIST
+
+#include <vector>
+#include "Value.h"
+
+class List : public Value {
+ std::vector<Value*> vals;
+public:
+ LLVMRet Visit(LLVMVisitor& visitor) const override;
+ const std::vector<Value*>& get_value() const;
+
+ List(std::vector<Value*> val);
+ ~List() override = default;
+};
+
+#endif
diff --git a/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Name.cpp b/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Name.cpp
index 52094b9..cd92df3 100644
--- a/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Name.cpp
+++ b/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Name.cpp
@@ -1,17 +1,12 @@
#include "Name.h"
-#include "Value.h"
#include "../LLVMVisitor/LLVMVisitor.h"
const std::string& Name::get_value() const {
return val;
}
-std::string Name::Visit(LLVMVisitor& visitor) const {
+LLVMRet Name::Visit(LLVMVisitor& visitor) const {
return visitor.Visit(*this);
}
-Value::T_Primitive Name::RetType() const {
- return T_name;
-}
-
Name::Name(std::string val) : val(val) {}
diff --git a/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Name.h b/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Name.h
index b242c06..b0e0693 100644
--- a/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Name.h
+++ b/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Name.h
@@ -10,8 +10,7 @@ class Name : public Value {
public:
const std::string& get_value() const;
- std::string Visit(LLVMVisitor& visitor) const override;
- T_Primitive RetType() const override;
+ LLVMRet Visit(LLVMVisitor& visitor) const override;
Name(std::string);
~Name() override = default;
diff --git a/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Value.h b/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Value.h
index a675d13..dd5dc2a 100644
--- a/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Value.h
+++ b/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Value.h
@@ -4,17 +4,11 @@
#include <string>
class LLVMVisitor;
+struct LLVMRet;
class Value {
public:
- enum T_Primitive {
- T_void,
- T_name,
- T_integer,
- T_float,
- };
- virtual std::string Visit(LLVMVisitor& visitor) const = 0;
- virtual T_Primitive RetType() const = 0;
+ virtual LLVMRet Visit(LLVMVisitor& visitor) const = 0;
virtual ~Value() {};
};