11#ifndef ARK_COMPILER_LOWERER_ASTLOWERER_HPP
12#define ARK_COMPILER_LOWERER_ASTLOWERER_HPP
52 void process(
Node& ast);
59 [[nodiscard]]
const std::vector<IR::Block>& intermediateRepresentation()
const noexcept;
66 [[nodiscard]]
const std::vector<std::string>& symbols()
const noexcept;
73 [[nodiscard]]
const std::vector<ValTableElem>& values()
const noexcept;
103 return m_code_pages[page.index];
104 return m_temp_pages[page.index];
113 static std::optional<Instruction> getOperator(
const std::string& name)
noexcept;
121 static std::optional<uint16_t> getBuiltin(
const std::string& name)
noexcept;
129 static std::optional<Instruction> getListInstruction(
const std::string& name)
noexcept;
137 static bool nodeProducesOutput(
const Node& node);
146 static bool isUnaryInst(
Instruction inst)
noexcept;
155 static bool isTernaryInst(
Instruction inst)
noexcept;
163 static void warning(
const std::string& message,
const Node& node);
171 [[noreturn]]
static void buildAndThrowError(
const std::string& message,
const Node& node);
181 void compileExpression(
Node& x, Page p,
bool is_result_unused,
bool is_terminal);
183 void compileSymbol(
Node& x, Page p,
bool is_result_unused);
184 void compileListInstruction(
Node& x, Page p,
bool is_result_unused);
185 void compileIf(
Node& x, Page p,
bool is_result_unused,
bool is_terminal);
186 void compileFunction(
Node& x, Page p,
bool is_result_unused);
188 void compileWhile(
Node& x, Page p);
189 void compilePluginImport(
Node& x, Page p);
190 void pushFunctionCallArguments(
Node& call, Page p,
bool is_tail_call);
191 void handleCalls(
Node& x, Page p,
bool is_result_unused,
bool is_terminal);
200 uint16_t addSymbol(
const Node& sym);
209 uint16_t addValue(
const Node& x);
219 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.
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
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
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.
std::vector< Entity > Block
Keyword
The different keywords available.
Instruction
The different bytecodes are stored here.