From ab1d1ecba4f2562a8b81d887d08370d5fcf0921d Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 29 Jan 2023 20:58:52 +0200 Subject: [IPL/T] Added current progress of implementing functions --- .../Transpiler/src/Value/Function/Funcall.cpp | 0 .../Transpiler/src/Value/Function/Funcall.h | 21 +++++++++++++++++++++ .../Transpiler/src/Value/Function/UserFunction.cpp | 14 ++++++++++++++ .../Transpiler/src/Value/Function/UserFunction.h | 16 ++++++++++++++++ .../Transpiler/src/Value/Name.cpp | 17 +++++++++++++++++ .../Transpiler/src/Value/Name.h | 20 ++++++++++++++++++++ .../Transpiler/src/Value/Value.h | 1 + 7 files changed, 89 insertions(+) create mode 100644 Year 2/Implementation of Programming Languages/Transpiler/src/Value/Function/Funcall.cpp create mode 100644 Year 2/Implementation of Programming Languages/Transpiler/src/Value/Function/Funcall.h create mode 100644 Year 2/Implementation of Programming Languages/Transpiler/src/Value/Function/UserFunction.cpp create mode 100644 Year 2/Implementation of Programming Languages/Transpiler/src/Value/Name.cpp create mode 100644 Year 2/Implementation of Programming Languages/Transpiler/src/Value/Name.h (limited to 'Year 2/Implementation of Programming Languages/Transpiler/src/Value') 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 new file mode 100644 index 0000000..e69de29 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 new file mode 100644 index 0000000..5afc51d --- /dev/null +++ b/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Function/Funcall.h @@ -0,0 +1,21 @@ +#ifndef VALUE_FUNCALL +#define VALUE_FUNCALL + +#include +#include "../Value.h" + +class Funcall : public Value { + std::string funName; + std::deque args; +public: + const std::string& get_funname() const; + const std::deque& get_args() const; + + std::string Visit(LLVMVisitor& visitor) const override; + T_Primitive RetType() const override; + + Funcall(std::string funName, std::deque args); + ~Funcall() 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 new file mode 100644 index 0000000..a9841d3 --- /dev/null +++ b/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Function/UserFunction.cpp @@ -0,0 +1,14 @@ +#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 args, std::deque 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 index e69de29..17cf931 100644 --- 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 @@ -0,0 +1,16 @@ +#ifndef VALUE_USERFUNCTION +#define VALUE_USERFUNCTION + +#include +#include "Function.h" + +class UserFunction : public Function { + std::deque body; + +public: + std::string Visit(LLVMVisitor& visitor) const override; + T_Primitive RetType() const override; + UserFunction(std::string name, std::deque args, std::deque body); +}; + +#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 new file mode 100644 index 0000000..52094b9 --- /dev/null +++ b/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Name.cpp @@ -0,0 +1,17 @@ +#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 { + 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 new file mode 100644 index 0000000..b242c06 --- /dev/null +++ b/Year 2/Implementation of Programming Languages/Transpiler/src/Value/Name.h @@ -0,0 +1,20 @@ +#ifndef VALUE_NAME +#define VALUE_NAME + +#include +#include "Value.h" + +class Name : public Value { + std::string val; + +public: + const std::string& get_value() const; + + std::string Visit(LLVMVisitor& visitor) const override; + T_Primitive RetType() const override; + + Name(std::string); + ~Name() override = default; +}; + +#endif 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 0147515..a675d13 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 @@ -9,6 +9,7 @@ class Value { public: enum T_Primitive { T_void, + T_name, T_integer, T_float, }; -- cgit v1.3.1-26-gb76a