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 (uint16_t options=DefaultFeatures, const std::vector< std::string > &libpath={}) 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 &filename) |
Compile a file, and use the resulting bytecode. | |
bool | doString (const std::string &code) |
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::string > &libenv) noexcept |
Set the std search paths. | |
void | reset () noexcept |
Reset State (all member variables related to execution) | |
Private Member Functions | |
void | configure () |
Called to configure the state (set the bytecode, debug level, call the compiler...) | |
bool | compile (const std::string &file, const std::string &output) |
Reads and compiles code of file. | |
void | throwStateError (const std::string &message) |
Private Attributes | |
unsigned | m_debug_level |
bytecode_t | m_bytecode |
std::vector< std::string > | m_libenv |
std::string | m_filename |
uint16_t | m_options |
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.
|
noexcept |
Construct a new State object.
options | the options for the virtual machine, compiler, and parser |
libpath | a list of search paths for the std library |
Definition at line 18 of file State.cpp.
References Ark::Utils::canonicalRelPath(), Ark::Utils::fileExists(), and Ark::Utils::splitString().
|
private |
Reads and compiles code of file.
file | the path of file code to compile |
output | set path of .arkc file |
Definition at line 79 of file State.cpp.
References Ark::Compiler::compile(), Ark::Compiler::feed(), m_binded, m_debug_level, Ark::Compiler::m_defined_symbols, m_libenv, m_options, Ark::Utils::readFile(), and Ark::Compiler::saveTo().
Referenced by doFile().
|
private |
Called to configure the state (set the bytecode, debug level, call the compiler...)
Definition at line 201 of file State.cpp.
References ARK_VERSION_MAJOR, ARK_VERSION_STR, m_bytecode, m_constants, m_pages, m_symbols, and throwStateError().
Referenced by feed().
bool Ark::State::doFile | ( | const std::string & | filename | ) |
Compile a file, and use the resulting bytecode.
filename | path to an ArkScript code file |
Definition at line 109 of file State.cpp.
References ARK_CACHE_DIRNAME, compile(), feed(), Ark::BytecodeReader::feed(), Ark::Utils::fileExists(), Ark::Utils::getFilenameFromPath(), m_filename, and Ark::BytecodeReader::timestamp().
Referenced by main().
bool Ark::State::doString | ( | const std::string & | code | ) |
Compile a string (representing ArkScript code) and store resulting bytecode in m_bytecode.
code | the ArkScript code |
Definition at line 151 of file State.cpp.
References Ark::Compiler::bytecode(), Ark::Compiler::compile(), feed(), Ark::Compiler::feed(), m_binded, m_debug_level, Ark::Compiler::m_defined_symbols, m_libenv, and m_options.
Referenced by main(), and Ark::Repl::run().
bool Ark::State::feed | ( | const bytecode_t & | bytecode | ) |
Feed the state with ArkScript bytecode.
bytecode |
Definition at line 62 of file State.cpp.
References configure(), 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 42 of file State.cpp.
References Ark::BytecodeReader::bytecode(), configure(), Ark::BytecodeReader::feed(), and m_bytecode.
Referenced by doFile(), and doString().
|
noexcept |
|
noexcept |
Reset State (all member variables related to execution)
Definition at line 342 of file State.cpp.
References m_binded, m_constants, m_pages, and m_symbols.
Referenced by Ark::Repl::run().
|
noexcept |
Set the script arguments in sys:args.
args |
Definition at line 181 of file State.cpp.
References ARK_PLATFORM_NAME, Ark::List, and Ark::Value::push_back().
Referenced by main().
|
noexcept |
Set the debug level.
level | between 0 (nothing) and 3 (maximum verbosity) |
Definition at line 191 of file State.cpp.
Referenced by main(), and Ark::Repl::run().
|
noexcept |
|
inlineprivate |
Definition at line 133 of file State.hpp.
Referenced by configure().
|
friend |
|
private |
Definition at line 151 of file State.hpp.
Referenced by compile(), doString(), Ark::VM::init(), and reset().
|
private |
Definition at line 140 of file State.hpp.
Referenced by configure(), and feed().
|
private |
Definition at line 147 of file State.hpp.
Referenced by configure(), Ark::VM::loadPlugin(), reset(), and Ark::VM::safeRun().
|
private |
Definition at line 138 of file State.hpp.
Referenced by compile(), doString(), and Ark::VM::safeRun().
|
private |
Definition at line 142 of file State.hpp.
Referenced by doFile(), and Ark::VM::loadPlugin().
|
private |
Definition at line 141 of file State.hpp.
Referenced by compile(), doString(), and Ark::VM::loadPlugin().
|
private |
Definition at line 143 of file State.hpp.
Referenced by compile(), and doString().
|
private |
Definition at line 148 of file State.hpp.
Referenced by configure(), reset(), and Ark::VM::safeRun().
|
private |
Definition at line 146 of file State.hpp.
Referenced by configure(), Ark::VM::init(), Ark::VM::loadPlugin(), reset(), and Ark::VM::safeRun().