11#ifndef ARK_COMPILER_LOWERER_ASTLOWERER_HPP
12#define ARK_COMPILER_LOWERER_ASTLOWERER_HPP
57 void addToTables(
const std::vector<std::string>& symbols,
const std::vector<ValTableElem>& constants);
64 void offsetPagesBy(std::size_t offset);
71 void process(
Node& ast);
78 [[nodiscard]]
const std::vector<IR::Block>& intermediateRepresentation()
const noexcept;
85 [[nodiscard]]
const std::vector<std::string>& symbols()
const noexcept;
92 [[nodiscard]]
const std::vector<ValTableElem>& values()
const noexcept;
106 std::size_t m_start_page_at_offset = 0;
115 InvalidNodeNoReturnValue,
116 InvalidNodeInOperatorNoReturnValue,
117 InvalidNodeInTailCallNoReturnValue
124 m_code_pages.emplace_back();
125 return Page { .index = m_start_page_at_offset + m_code_pages.size() - 1u, .is_temp =
false };
128 m_temp_pages.emplace_back();
129 return Page { .index = m_temp_pages.size() - 1u, .is_temp =
true };
141 return m_code_pages[page.index - m_start_page_at_offset];
142 return m_temp_pages[page.index];
153 return !m_opened_vars.empty() && m_opened_vars.top() == name;
162 static std::optional<Instruction> getOperator(
const std::string& name)
noexcept;
170 static std::optional<uint16_t> getBuiltin(
const std::string& name)
noexcept;
178 static std::optional<Instruction> getListInstruction(
const std::string& name)
noexcept;
186 static bool isBreakpoint(
const Node& node);
194 static bool nodeProducesOutput(
const Node& node);
202 static bool isUnaryInst(
Instruction inst)
noexcept;
210 static bool isTernaryInst(
Instruction inst)
noexcept;
218 static bool isRepeatableOperation(
Instruction inst)
noexcept;
226 void warning(
const std::string& message,
const Node& node);
234 [[noreturn]]
static void buildAndThrowError(
const std::string& message,
const Node& node);
243 static void makeError(
ErrorKind kind,
const Node& node,
const std::string& additional_ctx);
253 void compileExpression(
Node& x, Page p,
bool is_result_unused,
bool is_terminal);
255 void compileSymbol(
const Node& x, Page p,
bool is_result_unused,
bool can_use_ref);
256 void compileListInstruction(
Node& x, Page p,
bool is_result_unused);
257 void compileApplyInstruction(
Node& x, Page p,
bool is_result_unused);
258 void compileIf(
Node& x, Page p,
bool is_result_unused,
bool is_terminal);
259 void compileFunction(
Node& x, Page p,
bool is_result_unused);
260 void compileLetMutSet(
Keyword n,
Node& x, Page p,
bool is_result_unused);
261 void compileWhile(
Node& x, Page p);
262 void compilePluginImport(
const Node& x, Page p);
263 void pushFunctionCallArguments(
Node& call, Page p,
bool is_tail_call);
264 void handleCalls(
Node& x, Page p,
bool is_result_unused,
bool is_terminal);
265 void handleShortcircuit(
Node& x, Page p);
267 bool handleFunctionCall(
Node& x, Page p,
bool is_terminal);
276 uint16_t addSymbol(
const Node& sym);
285 uint16_t addValue(
const Node& x);
295 uint16_t addValue(std::size_t page_id,
const Node& current);
An entity in the IR is a bundle of information.
The different instructions used by the compiler and virtual machine.
AST node used by the parser, optimizer and compiler.
Interface for a compiler pass.
The basic value type handled by the compiler.
The ArkScript AST to IR compiler.
std::vector< ValTableElem > m_values
std::vector< IR::Block > m_temp_pages
we need temporary code pages for some compilations passes
Page createNewCodePage(const bool temp=false) noexcept
std::vector< IR::Block > m_code_pages
std::vector< std::string > m_symbols
LocalsLocator m_locals_locator
std::stack< std::string > m_opened_vars
stack of vars we are currently declaring
bool isFunctionCallingItself(const std::string &name) noexcept
Check if we are in a recursive self call.
IR::Block & page(const Page page) noexcept
helper functions to get a temp or finalized code page
A node of an Abstract Syntax Tree for ArkScript.
An interface to describe compiler passes.
std::vector< Entity > Block
Keyword
The different keywords available.
Instruction
The different bytecodes are stored here.