mirror of
https://github.com/avinal/xeus-basic.git
synced 2026-01-10 07:08:35 +05:30
add xbasic interpreter implementation
Signed-off-by: Avinal Kumar <avinal.xlvii@gmail.com>
This commit is contained in:
19
src/main.cc
Normal file
19
src/main.cc
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <memory>
|
||||
|
||||
#include "xbasic/xbasic_interpreter.hpp"
|
||||
#include "xeus/xkernel.hpp"
|
||||
#include "xeus/xkernel_configuration.hpp"
|
||||
int main(int argc, char const *argv[]) {
|
||||
// Load configuration file
|
||||
std::string file_name = (argc == 1) ? "connection.json" : argv[2];
|
||||
xeus::xconfiguration config = xeus::load_configuration(file_name);
|
||||
|
||||
// Create interpreter instance
|
||||
using interpreter_ptr = std::unique_ptr<xbasic::xbasic_interpreter>;
|
||||
interpreter_ptr interpreter = std::make_unique<xbasic::xbasic_interpreter>();
|
||||
|
||||
// Create kernel instance and start it
|
||||
xeus::xkernel kernel(config, xeus::get_user_name(), std::move(interpreter));
|
||||
kernel.start();
|
||||
return 0;
|
||||
}
|
||||
90
src/xbasic_interpreter.cpp
Normal file
90
src/xbasic_interpreter.cpp
Normal file
@@ -0,0 +1,90 @@
|
||||
#include "xbasic/xbasic_interpreter.hpp"
|
||||
|
||||
std::string basic::output = "";
|
||||
|
||||
namespace xbasic {
|
||||
|
||||
nl::json xbasic_interpreter::execute_request_impl(int execution_counter, const std::string &code,
|
||||
bool silent, bool store_history,
|
||||
nl::json user_expressions, bool allow_stdin) {
|
||||
auto ok = []() {
|
||||
nl::json result;
|
||||
result["status"] = "ok";
|
||||
return result;
|
||||
};
|
||||
|
||||
std::vector<std::string> traceback;
|
||||
auto handle_exception = [&](std::string what) {
|
||||
nl::json result;
|
||||
result["status"] = "error";
|
||||
result["ename"] = "Error";
|
||||
result["evalue"] = what;
|
||||
traceback.push_back((std::string)result["ename"] + ": " + what);
|
||||
publish_execution_error(result["ename"], result["evalue"], traceback);
|
||||
traceback.clear();
|
||||
return result;
|
||||
};
|
||||
|
||||
nl::json pub_data;
|
||||
try {
|
||||
if (code_runner.evaluate_line(code)) {
|
||||
pub_data["text/plain"] = code_runner.run();
|
||||
code_runner.clear_output();
|
||||
publish_execution_result(execution_counter, std::move(pub_data), nl::json::object());
|
||||
return ok();
|
||||
} else {
|
||||
throw(code_runner.get_error());
|
||||
}
|
||||
} catch (const std::exception &err) {
|
||||
return handle_exception(err.what());
|
||||
}
|
||||
return ok();
|
||||
}
|
||||
|
||||
nl::json xbasic_interpreter::complete_request_impl(const std::string &code, int cursor_pos) {
|
||||
nl::json result;
|
||||
result["status"] = "ok";
|
||||
return result;
|
||||
}
|
||||
|
||||
nl::json xbasic_interpreter::inspect_request_impl(const std::string &code, int cursor_pos,
|
||||
int detail_level) {
|
||||
nl::json result;
|
||||
result["status"] = "ok";
|
||||
return result;
|
||||
}
|
||||
|
||||
nl::json xbasic_interpreter::is_complete_request_impl(const std::string &code) {
|
||||
nl::json result;
|
||||
result["status"] = "complete";
|
||||
return result;
|
||||
}
|
||||
|
||||
void xbasic_interpreter::configure_impl() {}
|
||||
|
||||
nl::json xbasic_interpreter::kernel_info_request_impl() {
|
||||
nl::json info;
|
||||
info["implementation"] = "xbasic";
|
||||
info["implementation_version"] = "0.1.0";
|
||||
std::string banner = R"V0G0N(
|
||||
`7MM***Yy. db .M***by. `7MMF' .g8***bg.
|
||||
MM Yb ;MM: ,MI `Y MM .dP' `M
|
||||
`7M' `MF' MM .P ,V^MM. `MMb. MM dM' `
|
||||
`VA ,V' MMooon* ,M `MM `YMMNq. MM MM
|
||||
XMX MM `Y. AbmmmqMA . `MM MM MM.
|
||||
,V' VA. MM ,9 A' VML Mb dM MM `Mb. .'
|
||||
.AM. .MA..JMMonal.AMA. .AMMA.`*Ybmmd* .JMML. `*bMond^
|
||||
|
||||
xeus-basic: a Jupyter Kernel for BASIC Language
|
||||
xBASIC Version: 0.1.0")V0G0N";
|
||||
info["banner"] = banner;
|
||||
info["language_info"]["name"] = "basic";
|
||||
info["langauge_info"]["codemirror_mode"] = "vb";
|
||||
info["language_info"]["version"] = "0.1.0";
|
||||
info["language_info"]["mimetype"] = "text/x-vb";
|
||||
info["language_info"]["file_extension"] = ".bas";
|
||||
return info;
|
||||
}
|
||||
|
||||
void xbasic_interpreter::shutdown_request_impl() {}
|
||||
} // namespace xbasic
|
||||
Reference in New Issue
Block a user