1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

integrating the existing state of TON Storage / TON Payments / CPS Fift development branches

This commit is contained in:
ton 2020-05-27 22:10:46 +04:00
parent 040df63c98
commit 4e2624459b
153 changed files with 10760 additions and 1695 deletions

View file

@ -37,25 +37,18 @@ td::Result<int> Fift::interpret_file(std::string fname, std::string current_dir,
return td::Status::Error("cannot locate file `" + fname + "`");
}
auto file = r_file.move_as_ok();
IntCtx ctx;
std::stringstream ss(file.data);
ctx.input_stream = &ss;
ctx.filename = td::PathView(file.path).file_name().str();
ctx.currentd_dir = td::PathView(file.path).parent_dir().str();
ctx.include_depth = is_interactive ? 0 : 1;
return do_interpret(ctx);
IntCtx ctx{ss, td::PathView(file.path).file_name().str(), td::PathView(file.path).parent_dir().str(),
(int)!is_interactive};
return do_interpret(ctx, is_interactive);
}
td::Result<int> Fift::interpret_istream(std::istream& stream, std::string current_dir, bool is_interactive) {
IntCtx ctx;
ctx.input_stream = &stream;
ctx.filename = "stdin";
ctx.currentd_dir = current_dir;
ctx.include_depth = is_interactive ? 0 : 1;
return do_interpret(ctx);
IntCtx ctx{stream, "stdin", current_dir, (int)!is_interactive};
return do_interpret(ctx, is_interactive);
}
td::Result<int> Fift::do_interpret(IntCtx& ctx) {
td::Result<int> Fift::do_interpret(IntCtx& ctx, bool is_interactive) {
ctx.ton_db = &config_.ton_db;
ctx.source_lookup = &config_.source_lookup;
ctx.dictionary = &config_.dictionary;
@ -64,13 +57,26 @@ td::Result<int> Fift::do_interpret(IntCtx& ctx) {
if (!ctx.output_stream) {
return td::Status::Error("Cannot run interpreter without output_stream");
}
try {
return funny_interpret_loop(ctx);
} catch (fift::IntError ab) {
return td::Status::Error(ab.msg);
} catch (fift::Quit q) {
return q.res;
while (true) {
auto res = ctx.run(td::make_ref<InterpretCont>());
if (res.is_error()) {
res = ctx.add_error_loc(res.move_as_error());
if (config_.show_backtrace) {
std::ostringstream os;
ctx.print_error_backtrace(os);
LOG(ERROR) << os.str();
}
if (is_interactive) {
LOG(ERROR) << res.move_as_error().message();
ctx.top_ctx();
ctx.clear_error();
ctx.stack.clear();
ctx.load_next_line();
continue;
}
}
return res;
}
return 0;
}
} // namespace fift