Repl+Env+Example: Load global outer environment in Repl::init
This commit is contained in:
+15
-6
@@ -21,6 +21,13 @@
|
||||
|
||||
namespace blaze {
|
||||
|
||||
static auto cleanup(int signal) -> void
|
||||
{
|
||||
print("\033[0m\n");
|
||||
Repl::cleanup();
|
||||
std::exit(signal);
|
||||
}
|
||||
|
||||
auto main(int argc, char* argv[]) -> int
|
||||
{
|
||||
bool dump_lexer = false;
|
||||
@@ -39,17 +46,17 @@ auto main(int argc, char* argv[]) -> int
|
||||
arg_parser.addArgument(arguments, "arguments", nullptr, nullptr, ruc::ArgParser::Required::No);
|
||||
arg_parser.parse(argc, argv);
|
||||
|
||||
Repl::init();
|
||||
|
||||
// Signal callbacks
|
||||
std::signal(SIGINT, cleanup);
|
||||
std::signal(SIGTERM, cleanup);
|
||||
|
||||
// Set settings
|
||||
g_outer_env->set("*DUMP-LEXER*", makePtr<Constant>(dump_lexer));
|
||||
g_outer_env->set("*DUMP-READER*", makePtr<Constant>(dump_reader));
|
||||
g_outer_env->set("*PRETTY-PRINT*", makePtr<Constant>(pretty_print));
|
||||
|
||||
// Signal callbacks
|
||||
std::signal(SIGINT, Repl::cleanup);
|
||||
std::signal(SIGTERM, Repl::cleanup);
|
||||
|
||||
Environment::loadFunctions();
|
||||
Environment::installFunctions(g_outer_env);
|
||||
Repl::makeArgv(g_outer_env, arguments);
|
||||
|
||||
if (arguments.size() > 0) {
|
||||
@@ -73,6 +80,8 @@ auto main(int argc, char* argv[]) -> int
|
||||
print("\033[0m");
|
||||
}
|
||||
|
||||
Repl::cleanup();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Vendored
+3
@@ -79,6 +79,9 @@ EnvironmentPtr Environment::create(const ValuePtr lambda, ValueVector&& argument
|
||||
|
||||
void Environment::loadFunctions()
|
||||
{
|
||||
s_function_parts.clear();
|
||||
s_lambdas.clear();
|
||||
|
||||
loadCollectionAccess();
|
||||
loadCollectionConstructor();
|
||||
loadCollectionModify();
|
||||
|
||||
+10
-4
@@ -25,12 +25,18 @@
|
||||
namespace blaze {
|
||||
|
||||
Readline g_readline;
|
||||
EnvironmentPtr g_outer_env = Environment::create();
|
||||
EnvironmentPtr g_outer_env;
|
||||
|
||||
auto Repl::cleanup(int signal) -> void
|
||||
auto Repl::init() -> void
|
||||
{
|
||||
::print("\033[0m\n");
|
||||
std::exit(signal);
|
||||
g_outer_env = Environment::create();
|
||||
Environment::loadFunctions();
|
||||
Environment::installFunctions(g_outer_env);
|
||||
}
|
||||
|
||||
auto Repl::cleanup() -> void
|
||||
{
|
||||
g_outer_env = nullptr;
|
||||
}
|
||||
|
||||
auto Repl::readline(const std::string& prompt) -> ValuePtr
|
||||
|
||||
+3
-1
@@ -17,7 +17,9 @@ namespace blaze {
|
||||
|
||||
class Repl {
|
||||
public:
|
||||
static auto cleanup(int signal) -> void;
|
||||
static auto init() -> void;
|
||||
static auto cleanup() -> void;
|
||||
|
||||
static auto eval(ValuePtr ast, EnvironmentPtr env) -> ValuePtr;
|
||||
static auto makeArgv(EnvironmentPtr env, std::vector<std::string> arguments) -> void;
|
||||
static auto print(ValuePtr value) -> std::string;
|
||||
|
||||
Reference in New Issue
Block a user