12#ifndef ARK_COMPILER_COMPILER_HPP
13#define ARK_COMPILER_COMPILER_HPP
52 void feed(
const std::string& code,
const std::string& filename =
ARK_NO_NAME_FILE);
65 void saveTo(
const std::string& file);
95 void pushFileHeader() noexcept;
101 void pushSymAndValTables();
109 inline std::vector<uint8_t>& page(
int i) noexcept
112 return m_code_pages[i];
113 return m_temp_pages[-i - 1];
122 inline std::vector<uint8_t>*
page_ptr(
int i)
noexcept
125 return &m_code_pages[i];
126 return &m_temp_pages[-i - 1];
129 inline void setNumberAt(
int p, std::size_t at_inst, std::size_t number)
131 page(p)[at_inst] = (number & 0xff00) >> 8;
132 page(p)[at_inst + 1] = number & 0x00ff;
143 std::size_t countArkObjects(
const std::vector<internal::Node>& lst)
noexcept;
151 std::optional<std::size_t> isOperator(
const std::string& name)
noexcept;
159 std::optional<std::size_t> isBuiltin(
const std::string& name)
noexcept;
167 inline std::optional<internal::Instruction>
isSpecific(
const std::string& name)
noexcept
170 return internal::Instruction::LIST;
171 else if (name ==
"append")
172 return internal::Instruction::APPEND;
173 else if (name ==
"concat")
174 return internal::Instruction::CONCAT;
175 else if (name ==
"append!")
176 return internal::Instruction::APPEND_IN_PLACE;
177 else if (name ==
"concat!")
178 return internal::Instruction::CONCAT_IN_PLACE;
179 else if (name ==
"pop")
180 return internal::Instruction::POP_LIST;
181 else if (name ==
"pop!")
182 return internal::Instruction::POP_LIST_IN_PLACE;
212 bool mayBeFromPlugin(
const std::string& name)
noexcept;
220 [[noreturn]]
void throwCompilerError(
const std::string& message,
const internal::Node& node);
228 void compilerWarning(
const std::string& message,
const internal::Node& node);
239 void _compile(
const internal::Node& x,
int p,
bool produces_result,
bool is_terminal,
const std::string& var_name =
"");
241 void compileSymbol(
const internal::Node& x,
int p,
bool produces_result);
243 void compileIf(
const internal::Node& x,
int p,
bool produces_result,
bool is_terminal,
const std::string& var_name);
244 void compileFunction(
const internal::Node& x,
int p,
bool produces_result,
const std::string& var_name);
247 void compileQuote(
const internal::Node& x,
int p,
bool produces_result,
bool is_terminal,
const std::string& var_name);
250 void handleCalls(
const internal::Node& x,
int p,
bool produces_result,
bool is_terminal,
const std::string& var_name);
259 void putValue(
const internal::Node& x,
int p,
bool produces_result);
287 uint16_t addValue(std::size_t page_id,
const internal::Node& current);
294 void addDefinedSymbol(
const std::string& sym);
300 void checkForUndefinedSymbol();
308 void pushNumber(uint16_t n, std::vector<uint8_t>* page =
nullptr) noexcept;
316 std::
string offerSuggestion(const std::
string& str);
The different instructions used by the compiler and virtual machine.
AST node used by the parser, optimizer and compiler.
Optimizes a given ArkScript AST.
Parses a token stream into an AST by using the Ark::Node.
The basic value type handled by the compiler.
The ArkScript bytecode compiler.
std::optional< internal::Instruction > isSpecific(const std::string &name) noexcept
Check if a symbol needs to be compiled to a specific instruction.
std::vector< std::vector< uint8_t > > m_temp_pages
we need temporary code pages for some compilations passes
std::vector< std::string > m_defined_symbols
internal::Optimizer m_optimizer
std::vector< std::string > m_plugins
unsigned m_debug
the debug level of the compiler
std::vector< internal::ValTableElem > m_values
internal::Parser m_parser
std::vector< uint8_t > * page_ptr(int i) noexcept
helper functions to get a temp or finalized code page
void setNumberAt(int p, std::size_t at_inst, std::size_t number)
std::vector< internal::Node > m_symbols
std::vector< std::vector< uint8_t > > m_code_pages
Ark state to handle the dirty job of loading and compiling ArkScript code.
A node of an Abstract Syntax Tree for ArkScript.
The ArkScript AST optimizer.
The parser is responsible of constructing the Abstract Syntax Tree from a token list.
Keyword
The different keywords available.
Instruction
The different bytecodes are stored here.
constexpr uint16_t DefaultFeatures
std::vector< uint8_t > bytecode_t