feat(IR): improve IR functions

Add access specifiers and parameter counts to furlang's IR functions.
This commit is contained in:
2026-06-28 13:16:31 +02:00
parent 7b609f87c9
commit 8466902281
5 changed files with 135 additions and 34 deletions
+42 -12
View File
@@ -3,12 +3,25 @@
#include "furlang/ir/block.hpp"
#include <cstdint>
#include <memory>
#include <type_traits>
#include <vector>
namespace furlang {
namespace ir {
enum class function_t : std::uint8_t {
Normal = 0,
Import,
Native,
};
enum class function_access_t : std::uint8_t {
Public = 0,
Private,
};
/**
* @brief IR function.
*
@@ -22,18 +35,11 @@ public:
/**
* @brief Construct a new IR function.
*
* @param name Name to copy.
* @param name Name to forward.
*/
function(const std::string& name)
: m_name(name) {}
/**
* @brief Construct a new IR function.
*
* @param name Name to move.
*/
function(std::string&& name)
: m_name(std::move(name)) {}
template <typename StringFwd, typename = std::enable_if_t<std::is_constructible_v<std::string, StringFwd>>>
function(StringFwd&& name, function_access_t access, std::uint32_t paramCount, function_t type = function_t::Normal)
: m_name(std::forward<StringFwd>(name)), m_access(access), m_paramCount(paramCount), m_type(type) {}
public:
/**
* @brief Returns this function's name.
@@ -42,6 +48,27 @@ public:
*/
const std::string& name() const { return m_name; }
/**
* @brief Returns the function's access.
*
* @return The access.
*/
function_access_t access() const { return m_access; }
/**
* @brief Returns this function's parameter count.
*
* @return The parameter count.
*/
std::uint32_t param_count() const { return m_paramCount; }
/**
* @brief Returns this function's type.
*
* @return The type.
*/
function_t type() const { return m_type; }
/**
* @brief Pushes and returns a new IR block.
*
@@ -57,10 +84,13 @@ public:
const std::vector<value_type>& blocks() const { return m_blocks; }
private:
std::string m_name;
function_access_t m_access;
function_t m_type;
std::uint32_t m_paramCount;
std::vector<value_type> m_blocks;
};
} // namespace ir
} // namespace furlang
#endif // FURLANG_IR_FUNCTION_HPP
#endif // FURLANG_IR_FUNCTION_HPP