feat(furc): introduce function call expression and call instruction
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
#include "furc/ast/node.hpp"
|
||||
#include "furc/ast/statement.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace furc {
|
||||
namespace ast {
|
||||
|
||||
@@ -16,6 +18,7 @@ enum class expression_node_t {
|
||||
Unaryop, /**< Unary operation expression */
|
||||
Binop, /**< Binary operation expression */
|
||||
VarAssign, /**< Variable assignment expression */
|
||||
FuncCall, /**< Function call expression. */
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -350,7 +353,55 @@ private:
|
||||
expression_node_p m_rhs;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Function call expression AST node.
|
||||
*/
|
||||
class function_call_expression_node final : public expression_node {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new function call expression AST node.
|
||||
*
|
||||
* @param location Node location.
|
||||
* @param func Left-hand-side expression.
|
||||
* @param args Function arguments.
|
||||
*/
|
||||
function_call_expression_node(struct location location,
|
||||
expression_node_p&& func,
|
||||
std::vector<expression_node_p>&& args)
|
||||
: expression_node(location), m_func(std::move(func)), m_args(std::move(args)) {}
|
||||
|
||||
/**
|
||||
* @brief Returns this node's left-hand-side expression.
|
||||
*
|
||||
* @return The left-hand-side expression.
|
||||
*/
|
||||
const expression_node_p& func() const { return m_func; }
|
||||
|
||||
/**
|
||||
* @brief Returns this node's argument expressions.
|
||||
*
|
||||
* @return The argument expressions.
|
||||
*/
|
||||
const std::vector<expression_node_p>& args() const { return m_args; }
|
||||
public:
|
||||
/**
|
||||
* @brief Returns this node's expression type.
|
||||
*
|
||||
* @return expression_node_t::FuncCall.
|
||||
*/
|
||||
expression_node_t expression_type() const override { return expression_node_t::FuncCall; }
|
||||
public:
|
||||
void accept(visitor& visitor) const override;
|
||||
|
||||
std::ostream& print(std::ostream& os) const override;
|
||||
protected:
|
||||
bool equal(const node& rhs) const override;
|
||||
private:
|
||||
expression_node_p m_func;
|
||||
std::vector<expression_node_p> m_args;
|
||||
};
|
||||
|
||||
} // namespace ast
|
||||
} // namespace furc
|
||||
|
||||
#endif // FURC_AST_EXPRESSION_HPP
|
||||
#endif // FURC_AST_EXPRESSION_HPP
|
||||
|
||||
@@ -151,6 +151,14 @@ using var_assign_expression_node_p =
|
||||
using var_assign_expression_node_r =
|
||||
node_r<var_assign_expression_node>; /**< Alias for var_assign_expression_node result */
|
||||
|
||||
class function_call_expression_node;
|
||||
|
||||
using function_call_expression_node_p =
|
||||
node_p<function_call_expression_node>; /**< Alias for a shared pointer to function_call_expression_node. */
|
||||
|
||||
using function_call_expression_node_r =
|
||||
node_r<function_call_expression_node>; /**< Alias for function_call_expression_node result. */
|
||||
|
||||
/**
|
||||
* @brief List of statements.
|
||||
*/
|
||||
|
||||
@@ -82,6 +82,14 @@ public:
|
||||
*/
|
||||
virtual void visit(const var_assign_expression_node& node) {}
|
||||
|
||||
/**
|
||||
* @brief Visit a function_call_expression_node.
|
||||
* @see function_call_expression_node
|
||||
*
|
||||
* @param node Node.
|
||||
*/
|
||||
virtual void visit(const function_call_expression_node& node) {}
|
||||
|
||||
/**
|
||||
* @brief Visit a function_declaration_node.
|
||||
* @see function_declaration_node
|
||||
|
||||
@@ -25,6 +25,7 @@ public:
|
||||
furlang::ir::mod&& move_module() { return std::move(m_module); }
|
||||
public:
|
||||
void visit(const ast::function_definition_node& funcDef) override;
|
||||
void visit(const ast::function_declaration_node& funcDecl) override;
|
||||
void visit(const ast::return_statement_node& returnStmt) override;
|
||||
void visit(const ast::if_statement_node& node) override;
|
||||
void visit(const ast::while_statement_node& node) override;
|
||||
@@ -35,6 +36,7 @@ public:
|
||||
void visit(const ast::unary_op_expression_node& node) override;
|
||||
void visit(const ast::binary_op_expression_node& node) override;
|
||||
void visit(const ast::var_assign_expression_node& node) override;
|
||||
void visit(const ast::function_call_expression_node& node) override;
|
||||
private:
|
||||
template <typename T, typename... Args>
|
||||
void push(Args&&... args) {
|
||||
@@ -45,7 +47,7 @@ private:
|
||||
|
||||
furlang::ir::block_index push_block(bool validate = true);
|
||||
private:
|
||||
furlang::ir::mod m_module;
|
||||
furlang::ir::mod m_module;
|
||||
std::unique_ptr<furlang::ir::function> m_currentFunction;
|
||||
std::shared_ptr<furlang::ir::block> m_currentBlock;
|
||||
ir_register m_registerCounter = 0;
|
||||
|
||||
Reference in New Issue
Block a user