mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
Add namespaces to Fift (#641)
* Add fift-based disassembler * Fift improvements: namespaces, hashmaps, flow controls * Fift: add lib with better block structuring and more * Minor changes in fift HashMap + tests (#643) * Minor changes in fift HashMap * Add tests for extended fift --------- Co-authored-by: OmicronTau <omicron@ton.org> Co-authored-by: Tolya <1449561+tolya-yanot@users.noreply.github.com> Co-authored-by: SpyCheese <mikle98@yandex.ru>
This commit is contained in:
parent
4590ed381b
commit
865ebfce8d
31 changed files with 2323 additions and 699 deletions
|
@ -18,8 +18,8 @@
|
|||
*/
|
||||
#pragma once
|
||||
|
||||
#include "crypto/vm/db/TonDb.h" // FIXME
|
||||
#include "crypto/vm/stack.hpp"
|
||||
#include "crypto/vm/box.hpp"
|
||||
#include "crypto/common/bitstring.h"
|
||||
|
||||
#include "td/utils/Status.h"
|
||||
|
@ -32,6 +32,11 @@
|
|||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
namespace vm {
|
||||
class TonDbImpl; // from crypto/vm/db/TonDb.h
|
||||
using TonDb = std::unique_ptr<TonDbImpl>;
|
||||
} // namespace vm
|
||||
|
||||
namespace fift {
|
||||
class Dictionary;
|
||||
class SourceLookup;
|
||||
|
@ -68,71 +73,36 @@ class CharClassifier {
|
|||
}
|
||||
};
|
||||
|
||||
struct IntCtx {
|
||||
vm::Stack stack;
|
||||
Ref<FiftCont> next, exc_handler;
|
||||
Ref<FiftCont> exc_cont, exc_next;
|
||||
int state{0};
|
||||
struct ParseCtx {
|
||||
int include_depth{0};
|
||||
int line_no{0};
|
||||
int exit_code{0};
|
||||
td::Status error;
|
||||
bool need_line{true};
|
||||
std::string filename;
|
||||
std::string currentd_dir;
|
||||
std::istream* input_stream{nullptr};
|
||||
std::unique_ptr<std::istream> input_stream_holder;
|
||||
std::ostream* output_stream{nullptr};
|
||||
std::ostream* error_stream{nullptr};
|
||||
|
||||
vm::TonDb* ton_db{nullptr};
|
||||
Dictionary* dictionary{nullptr};
|
||||
SourceLookup* source_lookup{nullptr};
|
||||
int* now{nullptr};
|
||||
std::string word;
|
||||
|
||||
private:
|
||||
std::string str;
|
||||
const char* input_ptr = nullptr;
|
||||
|
||||
class Savepoint {
|
||||
IntCtx& ctx;
|
||||
int old_line_no;
|
||||
bool old_need_line;
|
||||
bool restored{false};
|
||||
std::string old_filename;
|
||||
std::string old_current_dir;
|
||||
std::istream* old_input_stream;
|
||||
std::unique_ptr<std::istream> old_input_stream_holder;
|
||||
std::string old_curline;
|
||||
std::ptrdiff_t old_curpos;
|
||||
std::string old_word;
|
||||
|
||||
public:
|
||||
Savepoint(IntCtx& _ctx, std::string new_filename, std::string new_current_dir,
|
||||
std::unique_ptr<std::istream> new_input_stream);
|
||||
bool restore(IntCtx& _ctx);
|
||||
};
|
||||
|
||||
std::vector<Savepoint> ctx_save_stack;
|
||||
|
||||
public:
|
||||
IntCtx() = default;
|
||||
IntCtx(std::istream& _istream, std::string _filename, std::string _curdir = "", int _depth = 0)
|
||||
ParseCtx() = default;
|
||||
ParseCtx(std::istream& _istream, std::string _filename, std::string _curdir = "", int _depth = 0)
|
||||
: include_depth(_depth)
|
||||
, filename(std::move(_filename))
|
||||
, currentd_dir(std::move(_curdir))
|
||||
, input_stream(&_istream) {
|
||||
}
|
||||
|
||||
operator vm::Stack&() {
|
||||
return stack;
|
||||
ParseCtx(std::unique_ptr<std::istream> _istream_ptr, std::string _filename, std::string _curdir = "", int _depth = 0)
|
||||
: include_depth(_depth)
|
||||
, filename(std::move(_filename))
|
||||
, currentd_dir(std::move(_curdir))
|
||||
, input_stream(_istream_ptr.get())
|
||||
, input_stream_holder(std::move(_istream_ptr)) {
|
||||
}
|
||||
|
||||
bool enter_ctx(std::string new_filename, std::string new_current_dir, std::unique_ptr<std::istream> new_input_stream);
|
||||
bool leave_ctx();
|
||||
bool top_ctx();
|
||||
|
||||
td::Slice scan_word_to(char delim, bool err_endl = true);
|
||||
td::Slice scan_word();
|
||||
td::Slice scan_word_ext(const CharClassifier& classifier);
|
||||
|
@ -165,6 +135,50 @@ struct IntCtx {
|
|||
|
||||
bool is_sb() const;
|
||||
|
||||
std::ostream& show_context(std::ostream& os) const;
|
||||
};
|
||||
|
||||
struct IntCtx {
|
||||
vm::Stack stack;
|
||||
Ref<FiftCont> next, exc_handler;
|
||||
Ref<FiftCont> exc_cont, exc_next;
|
||||
int state{0};
|
||||
int exit_code{0};
|
||||
td::Status error;
|
||||
|
||||
std::unique_ptr<ParseCtx> parser;
|
||||
std::vector<std::unique_ptr<ParseCtx>> parser_save_stack;
|
||||
|
||||
std::ostream* output_stream{nullptr}; // move to OutCtx?
|
||||
std::ostream* error_stream{nullptr};
|
||||
|
||||
vm::TonDb* ton_db{nullptr};
|
||||
SourceLookup* source_lookup{nullptr};
|
||||
int* now{nullptr};
|
||||
|
||||
Dictionary dictionary, main_dictionary, context;
|
||||
|
||||
public:
|
||||
IntCtx() = default;
|
||||
IntCtx(std::istream& _istream, std::string _filename, std::string _curdir = "", int _depth = 0) {
|
||||
parser = std::make_unique<ParseCtx>(_istream, _filename, _curdir, _depth);
|
||||
}
|
||||
IntCtx(std::unique_ptr<std::istream> _istream, std::string _filename, std::string _curdir = "", int _depth = 0) {
|
||||
parser = std::make_unique<ParseCtx>(std::move(_istream), _filename, _curdir, _depth);
|
||||
}
|
||||
|
||||
bool enter_ctx(std::unique_ptr<ParseCtx> new_ctx);
|
||||
bool enter_ctx(std::string new_filename, std::string new_current_dir, std::unique_ptr<std::istream> new_input_stream);
|
||||
bool leave_ctx();
|
||||
bool top_ctx();
|
||||
int include_depth() const {
|
||||
return parser ? parser->include_depth : -1;
|
||||
}
|
||||
|
||||
operator vm::Stack &() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
void clear() {
|
||||
state = 0;
|
||||
stack.clear();
|
||||
|
@ -194,6 +208,6 @@ struct IntCtx {
|
|||
td::Result<int> run(Ref<FiftCont> cont);
|
||||
};
|
||||
|
||||
td::StringBuilder& operator<<(td::StringBuilder& os, const IntCtx& ctx);
|
||||
std::ostream& operator<<(std::ostream& os, const IntCtx& ctx);
|
||||
td::StringBuilder& operator<<(td::StringBuilder& os, const ParseCtx& ctx);
|
||||
std::ostream& operator<<(std::ostream& os, const ParseCtx& ctx);
|
||||
} // namespace fift
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue