![]() |
ArkScript
A small, fast, functional and scripting language for video games
|
Ark state to handle the dirty job of loading and compiling ArkScript code. More...
#include <State.hpp>
Public Member Functions | |
State (const std::vector< std::filesystem::path > &libenv={}) noexcept | |
Construct a new State object. | |
bool | feed (const std::string &bytecode_filename) |
Feed the state by giving it the path to an existing bytecode file. | |
bool | feed (const bytecode_t &bytecode) |
Feed the state with ArkScript bytecode. | |
bool | doFile (const std::string &file, uint16_t features=DefaultFeatures) |
Compile a file, and use the resulting bytecode. | |
bool | doString (const std::string &code, uint16_t features=DefaultFeatures) |
Compile a string (representing ArkScript code) and store resulting bytecode in m_bytecode. | |
void | loadFunction (const std::string &name, Value::ProcType function) noexcept |
Register a function in the virtual machine. | |
void | setArgs (const std::vector< std::string > &args) noexcept |
Set the script arguments in sys:args. | |
void | setDebug (unsigned level) noexcept |
Set the debug level. | |
void | setLibDirs (const std::vector< std::filesystem::path > &libenv) noexcept |
Set the std search paths. | |
void | reset () noexcept |
Reset State (all member variables related to execution) | |
Private Member Functions | |
void | configure (const BytecodeReader &bcr) |
Called to configure the state (set the bytecode, debug level, call the compiler...) | |
bool | compile (const std::string &file, const std::string &output, uint16_t features) const |
Reads and compiles code of file. | |
Static Private Member Functions | |
static void | throwStateError (const std::string &message) |
Private Attributes | |
unsigned | m_debug_level |
bytecode_t | m_bytecode |
std::vector< std::filesystem::path > | m_libenv |
std::string | m_filename |
std::vector< std::string > | m_symbols |
std::vector< Value > | m_constants |
std::vector< bytecode_t > | m_pages |
std::unordered_map< std::string, Value > | m_binded |
Friends | |
class | VM |
class | internal::Closure |
class | Repl |
Ark state to handle the dirty job of loading and compiling ArkScript code.
|
explicitnoexcept |
|
private |
Reads and compiles code of file.
file | the path of file code to compile |
output | set path of .arkc file |
features | compiler features to enable/disable |
Definition at line 54 of file State.cpp.
References Ark::Welder::computeASTFromFile(), Ark::Welder::generateBytecode(), m_binded, m_debug_level, m_libenv, Ark::Welder::registerSymbol(), and Ark::Welder::saveBytecodeToFile().
Referenced by doFile().
|
private |
Called to configure the state (set the bytecode, debug level, call the compiler...)
bcr | reference to a pre-fed bytecode reader |
Definition at line 142 of file State.cpp.
References ARK_VERSION, ARK_VERSION_MAJOR, Ark::BytecodeReader::code(), m_bytecode, m_constants, m_pages, m_symbols, Ark::BytecodeReader::sha256(), Ark::BytecodeReader::symbols(), throwStateError(), Ark::BytecodeReader::values(), and Ark::BytecodeReader::version().
Referenced by feed().
bool Ark::State::doFile | ( | const std::string & | file, |
uint16_t | features = DefaultFeatures ) |
Compile a file, and use the resulting bytecode.
file | path to an ArkScript code file |
features | compiler features to enable/disable |
Definition at line 72 of file State.cpp.
References ARK_CACHE_DIRNAME, Ark::BytecodeReader::checkMagic(), compile(), Ark::BytecodeReader::feed(), feed(), Ark::Utils::fileExists(), m_filename, and Ark::Utils::readFileAsBytes().
Referenced by main().
bool Ark::State::doString | ( | const std::string & | code, |
uint16_t | features = DefaultFeatures ) |
Compile a string (representing ArkScript code) and store resulting bytecode in m_bytecode.
code | the ArkScript code |
features | compiler features to enable/disable |
Definition at line 103 of file State.cpp.
References Ark::Welder::bytecode(), Ark::Welder::computeASTFromString(), feed(), Ark::Welder::generateBytecode(), m_binded, m_debug_level, m_libenv, and Ark::Welder::registerSymbol().
Referenced by main().
bool Ark::State::feed | ( | const bytecode_t & | bytecode | ) |
Feed the state with ArkScript bytecode.
bytecode |
Definition at line 33 of file State.cpp.
References Ark::BytecodeReader::checkMagic(), configure(), Ark::BytecodeReader::feed(), and m_bytecode.
bool Ark::State::feed | ( | const std::string & | bytecode_filename | ) |
Feed the state by giving it the path to an existing bytecode file.
bytecode_filename |
Definition at line 25 of file State.cpp.
References feed(), Ark::Utils::fileExists(), and Ark::Utils::readFileAsBytes().
Referenced by doFile(), doString(), and feed().
|
noexcept |
|
noexcept |
|
noexcept |
Set the script arguments in sys:args.
args |
Definition at line 121 of file State.cpp.
References ARK_PLATFORM_NAME, Ark::List, Ark::Value::list(), Ark::internal::Language::SysArgs, and Ark::internal::Language::SysPlatform.
Referenced by main().
|
noexcept |
|
noexcept |
|
inlinestaticprivate |
Definition at line 137 of file State.hpp.
Referenced by configure().
|
friend |
|
private |
Definition at line 154 of file State.hpp.
Referenced by compile(), doString(), Ark::VM::init(), and reset().
|
private |
Definition at line 144 of file State.hpp.
Referenced by configure(), and feed().
|
private |
Definition at line 150 of file State.hpp.
Referenced by configure(), Ark::VM::loadPlugin(), reset(), and Ark::VM::safeRun().
|
private |
Definition at line 142 of file State.hpp.
Referenced by compile(), and doString().
|
private |
Definition at line 146 of file State.hpp.
Referenced by doFile(), and Ark::VM::loadPlugin().
|
private |
Definition at line 145 of file State.hpp.
Referenced by compile(), doString(), and Ark::VM::loadPlugin().
|
private |
Definition at line 151 of file State.hpp.
Referenced by configure(), reset(), and Ark::VM::safeRun().
|
private |
Definition at line 149 of file State.hpp.
Referenced by configure(), Ark::VM::forceReloadPlugins(), Ark::internal::Closure::hasFieldEndingWith(), Ark::VM::init(), Ark::VM::loadPlugin(), reset(), and Ark::VM::safeRun().