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:
parent
040df63c98
commit
4e2624459b
153 changed files with 10760 additions and 1695 deletions
|
@ -22,9 +22,11 @@
|
|||
#include <map>
|
||||
|
||||
#include "IntCtx.h"
|
||||
#include "Continuation.h"
|
||||
|
||||
namespace fift {
|
||||
using td::Ref;
|
||||
|
||||
/*
|
||||
*
|
||||
* WORD CLASSES
|
||||
|
@ -34,66 +36,49 @@ using td::Ref;
|
|||
typedef std::function<void(vm::Stack&)> StackWordFunc;
|
||||
typedef std::function<void(IntCtx&)> CtxWordFunc;
|
||||
|
||||
class WordDef : public td::CntObject {
|
||||
public:
|
||||
WordDef() = default;
|
||||
virtual ~WordDef() override = default;
|
||||
virtual Ref<WordDef> run_tail(IntCtx& ctx) const = 0;
|
||||
void run(IntCtx& ctx) const;
|
||||
virtual bool is_list() const {
|
||||
return false;
|
||||
}
|
||||
virtual long long list_size() const {
|
||||
return -1;
|
||||
}
|
||||
virtual const std::vector<Ref<WordDef>>* get_list() const {
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
class StackWord : public WordDef {
|
||||
class StackWord : public FiftCont {
|
||||
StackWordFunc f;
|
||||
|
||||
public:
|
||||
StackWord(StackWordFunc _f) : f(std::move(_f)) {
|
||||
}
|
||||
~StackWord() override = default;
|
||||
Ref<WordDef> run_tail(IntCtx& ctx) const override;
|
||||
Ref<FiftCont> run_tail(IntCtx& ctx) const override;
|
||||
};
|
||||
|
||||
class CtxWord : public WordDef {
|
||||
class CtxWord : public FiftCont {
|
||||
CtxWordFunc f;
|
||||
|
||||
public:
|
||||
CtxWord(CtxWordFunc _f) : f(std::move(_f)) {
|
||||
}
|
||||
~CtxWord() override = default;
|
||||
Ref<WordDef> run_tail(IntCtx& ctx) const override;
|
||||
Ref<FiftCont> run_tail(IntCtx& ctx) const override;
|
||||
};
|
||||
|
||||
typedef std::function<Ref<WordDef>(IntCtx&)> CtxTailWordFunc;
|
||||
typedef std::function<Ref<FiftCont>(IntCtx&)> CtxTailWordFunc;
|
||||
|
||||
class CtxTailWord : public WordDef {
|
||||
class CtxTailWord : public FiftCont {
|
||||
CtxTailWordFunc f;
|
||||
|
||||
public:
|
||||
CtxTailWord(CtxTailWordFunc _f) : f(std::move(_f)) {
|
||||
}
|
||||
~CtxTailWord() override = default;
|
||||
Ref<WordDef> run_tail(IntCtx& ctx) const override;
|
||||
Ref<FiftCont> run_tail(IntCtx& ctx) const override;
|
||||
};
|
||||
|
||||
class WordList : public WordDef {
|
||||
std::vector<Ref<WordDef>> list;
|
||||
class WordList : public FiftCont {
|
||||
std::vector<Ref<FiftCont>> list;
|
||||
|
||||
public:
|
||||
~WordList() override = default;
|
||||
WordList() = default;
|
||||
WordList(std::vector<Ref<WordDef>>&& _list);
|
||||
WordList(const std::vector<Ref<WordDef>>& _list);
|
||||
WordList& push_back(Ref<WordDef> word_def);
|
||||
WordList& push_back(WordDef& wd);
|
||||
Ref<WordDef> run_tail(IntCtx& ctx) const override;
|
||||
WordList(std::vector<Ref<FiftCont>>&& _list);
|
||||
WordList(const std::vector<Ref<FiftCont>>& _list);
|
||||
WordList& push_back(Ref<FiftCont> word_def);
|
||||
WordList& push_back(FiftCont& wd);
|
||||
Ref<FiftCont> run_tail(IntCtx& ctx) const override;
|
||||
void close();
|
||||
bool is_list() const override {
|
||||
return true;
|
||||
|
@ -101,43 +86,73 @@ class WordList : public WordDef {
|
|||
long long list_size() const override {
|
||||
return (long long)list.size();
|
||||
}
|
||||
const std::vector<Ref<WordDef>>* get_list() const override {
|
||||
return &list;
|
||||
std::size_t size() const {
|
||||
return list.size();
|
||||
}
|
||||
WordList& append(const std::vector<Ref<WordDef>>& other);
|
||||
const Ref<FiftCont>& at(std::size_t idx) const {
|
||||
return list.at(idx);
|
||||
}
|
||||
const Ref<FiftCont>* get_list() const override {
|
||||
return list.data();
|
||||
}
|
||||
WordList& append(const std::vector<Ref<FiftCont>>& other);
|
||||
WordList& append(const Ref<FiftCont>* begin, const Ref<FiftCont>* end);
|
||||
WordList* make_copy() const override {
|
||||
return new WordList(list);
|
||||
}
|
||||
bool dump(std::ostream& os, const IntCtx& ctx) const override;
|
||||
};
|
||||
|
||||
class ListCont : public FiftCont {
|
||||
Ref<FiftCont> next;
|
||||
Ref<WordList> list;
|
||||
std::size_t pos;
|
||||
|
||||
public:
|
||||
ListCont(Ref<FiftCont> nxt, Ref<WordList> wl, std::size_t p = 0) : next(std::move(nxt)), list(std::move(wl)), pos(p) {
|
||||
}
|
||||
~ListCont() override = default;
|
||||
Ref<FiftCont> run_tail(IntCtx& ctx) const override;
|
||||
Ref<FiftCont> run_modify(IntCtx& ctx) override;
|
||||
Ref<FiftCont> up() const override {
|
||||
return next;
|
||||
}
|
||||
bool dump(std::ostream& os, const IntCtx& ctx) const override;
|
||||
};
|
||||
|
||||
class DictEntry {
|
||||
Ref<WordDef> def;
|
||||
Ref<FiftCont> def;
|
||||
bool active;
|
||||
|
||||
public:
|
||||
DictEntry() = delete;
|
||||
DictEntry(const DictEntry& ref) = default;
|
||||
DictEntry(DictEntry&& ref) = default;
|
||||
DictEntry(Ref<WordDef> _def, bool _act = false);
|
||||
DictEntry(Ref<FiftCont> _def, bool _act = false) : def(std::move(_def)), active(_act) {
|
||||
}
|
||||
DictEntry(StackWordFunc func);
|
||||
DictEntry(CtxWordFunc func, bool _act = false);
|
||||
DictEntry(CtxTailWordFunc func, bool _act = false);
|
||||
//DictEntry(const std::vector<Ref<WordDef>>& word_list);
|
||||
//DictEntry(std::vector<Ref<WordDef>>&& word_list);
|
||||
//DictEntry(const std::vector<Ref<FiftCont>>& word_list);
|
||||
//DictEntry(std::vector<Ref<FiftCont>>&& word_list);
|
||||
DictEntry& operator=(const DictEntry&) = default;
|
||||
DictEntry& operator=(DictEntry&&) = default;
|
||||
Ref<WordDef> get_def() const&;
|
||||
Ref<WordDef> get_def() &&;
|
||||
void operator()(IntCtx& ctx) const;
|
||||
bool is_active() const;
|
||||
~DictEntry() = default;
|
||||
Ref<FiftCont> get_def() const& {
|
||||
return def;
|
||||
}
|
||||
Ref<FiftCont> get_def() && {
|
||||
return std::move(def);
|
||||
}
|
||||
bool is_active() const {
|
||||
return active;
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
DictEntry::DictEntry(const std::vector<Ref<WordDef>>& word_list) : def(Ref<WordList>{true, word_list}) {
|
||||
DictEntry::DictEntry(const std::vector<Ref<FiftCont>>& word_list) : def(Ref<WordList>{true, word_list}) {
|
||||
}
|
||||
|
||||
DictEntry::DictEntry(std::vector<Ref<WordDef>>&& word_list) : def(Ref<WordList>{true, std::move(word_list)}) {
|
||||
DictEntry::DictEntry(std::vector<Ref<FiftCont>>&& word_list) : def(Ref<WordList>{true, std::move(word_list)}) {
|
||||
}
|
||||
*/
|
||||
|
||||
|
@ -156,7 +171,10 @@ class Dictionary {
|
|||
void def_stack_word(std::string name, StackWordFunc func);
|
||||
void def_word(std::string name, DictEntry word);
|
||||
void undef_word(td::Slice name);
|
||||
|
||||
bool lookup_def(const FiftCont* cont, std::string* word_ptr = nullptr) const;
|
||||
bool lookup_def(Ref<FiftCont> cont, std::string* word_ptr = nullptr) const {
|
||||
return lookup_def(cont.get(), word_ptr);
|
||||
}
|
||||
auto begin() const {
|
||||
return words_.begin();
|
||||
}
|
||||
|
@ -164,7 +182,7 @@ class Dictionary {
|
|||
return words_.end();
|
||||
}
|
||||
|
||||
static Ref<WordDef> nop_word_def;
|
||||
static Ref<FiftCont> nop_word_def;
|
||||
|
||||
private:
|
||||
std::map<std::string, DictEntry, std::less<>> words_;
|
||||
|
@ -176,7 +194,7 @@ class Dictionary {
|
|||
*
|
||||
*/
|
||||
|
||||
Ref<WordDef> pop_exec_token(vm::Stack& stack);
|
||||
Ref<FiftCont> pop_exec_token(vm::Stack& stack);
|
||||
Ref<WordList> pop_word_list(vm::Stack& stack);
|
||||
void push_argcount(vm::Stack& stack, int args);
|
||||
} // namespace fift
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue