You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
1.1 KiB
75 lines
1.1 KiB
/* |
|
* Copyright (C) 2023 Riyyi |
|
* |
|
* SPDX-License-Identifier: MIT |
|
*/ |
|
|
|
#include <string> |
|
|
|
#include "ruc/file.h" |
|
|
|
#include "blaze/ast.h" |
|
#include "blaze/env/macro.h" |
|
#include "blaze/repl.h" |
|
#include "blaze/util.h" |
|
|
|
namespace blaze { |
|
|
|
void Environment::loadRepl() |
|
{ |
|
// REPL reader |
|
ADD_FUNCTION( |
|
"read-string", |
|
"", |
|
"", |
|
{ |
|
CHECK_ARG_COUNT_IS("read-string", SIZE(), 1); |
|
|
|
VALUE_CAST(node, String, (*begin)); |
|
std::string input = node->data(); |
|
|
|
return Repl::read(input); |
|
}); |
|
|
|
// Read file contents |
|
ADD_FUNCTION( |
|
"slurp", |
|
"", |
|
"", |
|
{ |
|
CHECK_ARG_COUNT_IS("slurp", SIZE(), 1); |
|
|
|
VALUE_CAST(node, String, (*begin)); |
|
std::string path = node->data(); |
|
|
|
auto file = ruc::File(path); |
|
|
|
return makePtr<String>(file.data()); |
|
}); |
|
|
|
// Prompt readline |
|
ADD_FUNCTION( |
|
"readline", |
|
"", |
|
"", |
|
{ |
|
CHECK_ARG_COUNT_IS("readline", SIZE(), 1); |
|
|
|
VALUE_CAST(prompt, String, (*begin)); |
|
|
|
return Repl::readline(prompt->data()); |
|
}); |
|
|
|
// REPL eval |
|
ADD_FUNCTION( |
|
"eval", |
|
"", |
|
"", |
|
{ |
|
CHECK_ARG_COUNT_IS("eval", SIZE(), 1); |
|
|
|
return Repl::eval(*begin, nullptr); |
|
}); |
|
} |
|
|
|
} // namespace blaze
|
|
|