12#ifndef ARK_COMPILER_COMPILER_HPP
13#define ARK_COMPILER_COMPILER_HPP
57 [[nodiscard]]
const bytecode_t& bytecode()
const noexcept;
78 void pushFileHeader() noexcept;
84 void pushSymAndValTables();
92 std::vector<internal::
Word>& page(const
int i) noexcept
95 return m_code_pages[i];
96 return m_temp_pages[-i - 1];
105 std::vector<internal::Word>*
page_ptr(
const int i)
noexcept
108 return &m_code_pages[i];
109 return &m_temp_pages[-i - 1];
118 static std::optional<std::size_t> getOperator(
const std::string& name)
noexcept;
126 static std::optional<std::size_t> getBuiltin(
const std::string& name)
noexcept;
134 static std::optional<internal::Instruction>
getSpecific(
const std::string& name)
noexcept
137 return internal::Instruction::LIST;
138 if (name ==
"append")
139 return internal::Instruction::APPEND;
140 if (name ==
"concat")
141 return internal::Instruction::CONCAT;
142 if (name ==
"append!")
143 return internal::Instruction::APPEND_IN_PLACE;
144 if (name ==
"concat!")
145 return internal::Instruction::CONCAT_IN_PLACE;
147 return internal::Instruction::POP_LIST;
149 return internal::Instruction::POP_LIST_IN_PLACE;
178 bool mayBeFromPlugin(
const std::string& name)
noexcept;
186 static void compilerWarning(
const std::string& message,
const internal::Node& node);
194 [[noreturn]]
static void throwCompilerError(
const std::string& message,
const internal::Node& node);
205 void compileExpression(
const internal::Node& x,
int p,
bool is_result_unused,
bool is_terminal,
const std::string& var_name =
"");
207 void compileSymbol(
const internal::Node& x,
int p,
bool is_result_unused);
209 void compileIf(
const internal::Node& x,
int p,
bool is_result_unused,
bool is_terminal,
const std::string& var_name);
210 void compileFunction(
const internal::Node& x,
int p,
bool is_result_unused,
const std::string& var_name);
214 void handleCalls(
const internal::Node& x,
int p,
bool is_result_unused,
bool is_terminal,
const std::string& var_name);
242 uint16_t addValue(std::size_t page_id,
const internal::Node& current);
249 void addDefinedSymbol(
const std::string& sym);
255 void checkForUndefinedSymbol();
263 std::string offerSuggestion(
const std::string& str)
const;
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.
Describe an instruction and its immediate argument.
The ArkScript bytecode compiler.
std::vector< std::vector< internal::Word > > m_code_pages
std::vector< internal::Word > * page_ptr(const int i) noexcept
helper functions to get a temp or finalized code page
std::vector< std::string > m_defined_symbols
std::vector< std::string > m_plugins
unsigned m_debug
the debug level of the compiler
std::vector< internal::ValTableElem > m_values
std::vector< std::vector< internal::Word > > m_temp_pages
we need temporary code pages for some compilations passes
static std::optional< internal::Instruction > getSpecific(const std::string &name) noexcept
Check if a symbol needs to be compiled to a specific instruction.
std::vector< internal::Node > m_symbols
Ark state to handle the dirty job of loading and compiling ArkScript code.
A node of an Abstract Syntax Tree for ArkScript.
Keyword
The different keywords available.
Instruction
The different bytecodes are stored here.
std::vector< uint8_t > bytecode_t