ArkScript
A small, fast, functional and scripting language for video games
Repl.hpp
Go to the documentation of this file.
1/**
2 * @file Repl.hpp
3 * @author Alexandre Plateau ([email protected])
4 * @brief ArkScript REPL - Read Eval Print Loop
5 * @version 1.0
6 * @date 2020-10-27
7 *
8 * @copyright Copyright (c) 2020-2024
9 *
10 */
11
12#ifndef ARK_REPL_REPL_HPP
13#define ARK_REPL_REPL_HPP
14
15#include <string>
16#include <optional>
17
18#include <Ark/VM/VM.hpp>
19#include <Ark/VM/State.hpp>
20
21#include <replxx.hxx>
22
23namespace Ark
24{
25 class Repl
26 {
27 public:
28 /**
29 * @brief Construct a new Repl object
30 *
31 * @param lib_env search path for the std library
32 */
33 explicit Repl(const std::vector<std::filesystem::path>& lib_env);
34
35 /**
36 * @brief Start the REPL
37 *
38 */
39 int run();
40
41 private:
42 replxx::Replxx m_repl;
43 unsigned m_line_count;
44 std::string m_code;
46
48 std::vector<std::filesystem::path> m_lib_env;
52
53 /**
54 * @brief Configure replxx
55 */
56 void cuiSetup();
57
58 /**
59 * @brief Get a line via replxx and handle commands
60 * @param continuation if the prompt needs to be modified because a code block isn't entirely closed, set to true
61 * @return
62 */
63 std::optional<std::string> getLine(bool continuation);
64 std::optional<std::string> getCodeBlock();
65 };
66}
67
68#endif
State used by the virtual machine: it loads the bytecode, can compile it if needed,...
The ArkScript virtual machine.
bool m_has_init_vm
Definition: Repl.hpp:51
State m_state
Definition: Repl.hpp:49
int run()
Start the REPL.
Definition: Repl.cpp:19
std::string m_code
Definition: Repl.hpp:44
void cuiSetup()
Configure replxx.
Definition: Repl.cpp:67
bool m_running
Definition: Repl.hpp:45
replxx::Replxx m_repl
Definition: Repl.hpp:42
std::optional< std::string > getCodeBlock()
Definition: Repl.cpp:161
int m_old_ip
Definition: Repl.hpp:47
VM m_vm
Definition: Repl.hpp:50
unsigned m_line_count
Definition: Repl.hpp:43
std::optional< std::string > getLine(bool continuation)
Get a line via replxx and handle commands.
Definition: Repl.cpp:99
std::vector< std::filesystem::path > m_lib_env
Definition: Repl.hpp:48
Ark state to handle the dirty job of loading and compiling ArkScript code.
Definition: State.hpp:31
The ArkScript virtual machine, executing ArkScript bytecode.
Definition: VM.hpp:41
Definition: Builtins.hpp:21