mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
new db
new database fift/func bugfixes
This commit is contained in:
parent
950e292264
commit
e30d98eb30
110 changed files with 6102 additions and 2075 deletions
|
@ -692,7 +692,7 @@ int VmState::step() {
|
|||
//VM_LOG(st) << "stack:"; stack->dump(VM_LOG(st));
|
||||
//VM_LOG(st) << "; cr0.refcnt = " << get_c0()->get_refcnt() - 1 << std::endl;
|
||||
if (stack_trace) {
|
||||
stack->dump(std::cerr);
|
||||
stack->dump(std::cerr, 3);
|
||||
}
|
||||
++steps;
|
||||
if (code->size()) {
|
||||
|
|
|
@ -74,7 +74,8 @@ int exec_dump_stack(VmState* st) {
|
|||
d = 255;
|
||||
}
|
||||
for (int i = d; i > 0; i--) {
|
||||
std::cerr << stack[i - 1].to_string() << " ";
|
||||
stack[i - 1].print_list(std::cerr);
|
||||
std::cerr << ' ';
|
||||
}
|
||||
std::cerr << std::endl;
|
||||
return 0;
|
||||
|
@ -85,7 +86,9 @@ int exec_dump_value(VmState* st, unsigned arg) {
|
|||
VM_LOG(st) << "execute DUMP s" << arg;
|
||||
Stack& stack = st->get_stack();
|
||||
if ((int)arg < stack.depth()) {
|
||||
std::cerr << "#DEBUG#: s" << arg << " = " << stack[arg].to_string() << std::endl;
|
||||
std::cerr << "#DEBUG#: s" << arg << " = ";
|
||||
stack[arg].print_list(std::cerr);
|
||||
std::cerr << std::endl;
|
||||
} else {
|
||||
std::cerr << "#DEBUG#: s" << arg << " is absent" << std::endl;
|
||||
}
|
||||
|
|
|
@ -793,8 +793,7 @@ std::tuple<Ref<CellSlice>, Ref<Cell>, bool> dict_lookup_set(Ref<Cell> dict, td::
|
|||
std::pair<Ref<Cell>, bool> pfx_dict_set(Ref<Cell> dict, td::ConstBitPtr key, int m, int n,
|
||||
const PrefixDictionary::store_value_func_t& store_val,
|
||||
Dictionary::SetMode mode) {
|
||||
std::cerr << "up to " << n << "-bit prefix code dictionary modification for " << m << "-bit key = " << key.to_hex(m)
|
||||
<< std::endl;
|
||||
// std::cerr << "up to " << n << "-bit prefix code dictionary modification for " << m << "-bit key = " << key.to_hex(m) << std::endl;
|
||||
if (m > n) {
|
||||
return std::make_pair(Ref<Cell>{}, false);
|
||||
}
|
||||
|
|
|
@ -45,6 +45,18 @@ const char* get_exception_msg(Excno exc_no) {
|
|||
}
|
||||
}
|
||||
|
||||
bool StackEntry::is_list(const StackEntry* se) {
|
||||
Ref<Tuple> tuple;
|
||||
while (!se->empty()) {
|
||||
tuple = se->as_tuple_range(2, 2);
|
||||
if (tuple.is_null()) {
|
||||
return false;
|
||||
}
|
||||
se = &tuple->at(1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static const char HEX_digits[] = "0123456789ABCDEF";
|
||||
|
||||
std::string str_to_hex(std::string data, std::string prefix) {
|
||||
|
@ -62,6 +74,12 @@ std::string StackEntry::to_string() const {
|
|||
return std::move(os).str();
|
||||
}
|
||||
|
||||
std::string StackEntry::to_lisp_string() const {
|
||||
std::ostringstream os;
|
||||
print_list(os);
|
||||
return std::move(os).str();
|
||||
}
|
||||
|
||||
void StackEntry::dump(std::ostream& os) const {
|
||||
switch (tp) {
|
||||
case t_null:
|
||||
|
@ -130,6 +148,12 @@ void StackEntry::print_list(std::ostream& os) const {
|
|||
break;
|
||||
case t_tuple: {
|
||||
const auto& tuple = *static_cast<Ref<Tuple>>(ref);
|
||||
if (is_list()) {
|
||||
os << '(';
|
||||
tuple[0].print_list(os);
|
||||
print_list_tail(os, &tuple[1]);
|
||||
break;
|
||||
}
|
||||
auto n = tuple.size();
|
||||
if (!n) {
|
||||
os << "[]";
|
||||
|
@ -137,7 +161,7 @@ void StackEntry::print_list(std::ostream& os) const {
|
|||
os << "[";
|
||||
tuple[0].print_list(os);
|
||||
os << "]";
|
||||
} else if (n != 2) {
|
||||
} else {
|
||||
os << "[";
|
||||
unsigned c = 0;
|
||||
for (const auto& entry : tuple) {
|
||||
|
@ -147,10 +171,6 @@ void StackEntry::print_list(std::ostream& os) const {
|
|||
entry.print_list(os);
|
||||
}
|
||||
os << ']';
|
||||
} else {
|
||||
os << '(';
|
||||
tuple[0].print_list(os);
|
||||
tuple[1].print_list_tail(os);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -159,26 +179,40 @@ void StackEntry::print_list(std::ostream& os) const {
|
|||
}
|
||||
}
|
||||
|
||||
void StackEntry::print_list_tail(std::ostream& os) const {
|
||||
switch (tp) {
|
||||
case t_null:
|
||||
os << ')';
|
||||
break;
|
||||
case t_tuple: {
|
||||
const auto& tuple = *static_cast<Ref<Tuple>>(ref);
|
||||
if (tuple.size() == 2) {
|
||||
os << ' ';
|
||||
tuple[0].print_list(os);
|
||||
tuple[1].print_list_tail(os);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// fall through
|
||||
default:
|
||||
void StackEntry::print_list_tail(std::ostream& os, const StackEntry* se) {
|
||||
Ref<Tuple> tuple;
|
||||
while (!se->empty()) {
|
||||
tuple = se->as_tuple_range(2, 2);
|
||||
if (tuple.is_null()) {
|
||||
os << " . ";
|
||||
print_list(os);
|
||||
os << ')';
|
||||
se->print_list(os);
|
||||
break;
|
||||
}
|
||||
os << ' ';
|
||||
tuple->at(0).print_list(os);
|
||||
se = &tuple->at(1);
|
||||
}
|
||||
os << ')';
|
||||
}
|
||||
|
||||
StackEntry StackEntry::make_list(std::vector<StackEntry>&& elems) {
|
||||
StackEntry tail;
|
||||
std::size_t n = elems.size();
|
||||
while (n > 0) {
|
||||
--n;
|
||||
tail = StackEntry{vm::make_tuple_ref(std::move(elems[n]), tail)};
|
||||
}
|
||||
return tail;
|
||||
}
|
||||
|
||||
StackEntry StackEntry::make_list(const std::vector<StackEntry>& elems) {
|
||||
StackEntry tail;
|
||||
std::size_t n = elems.size();
|
||||
while (n > 0) {
|
||||
--n;
|
||||
tail = StackEntry{vm::make_tuple_ref(elems[n], tail)};
|
||||
}
|
||||
return tail;
|
||||
}
|
||||
|
||||
StackEntry::StackEntry(Ref<Stack> stack_ref) : ref(std::move(stack_ref)), tp(t_stack) {
|
||||
|
@ -611,13 +645,21 @@ Ref<Stack> Stack::split_top(unsigned top_cnt, unsigned drop_cnt) {
|
|||
return new_stk;
|
||||
}
|
||||
|
||||
void Stack::dump(std::ostream& os, bool cr) const {
|
||||
void Stack::dump(std::ostream& os, int mode) const {
|
||||
os << " [ ";
|
||||
for (const auto& x : stack) {
|
||||
os << x.to_string() << ' ';
|
||||
if (mode & 2) {
|
||||
for (const auto& x : stack) {
|
||||
x.print_list(os);
|
||||
os << ' ';
|
||||
}
|
||||
} else {
|
||||
for (const auto& x : stack) {
|
||||
x.dump(os);
|
||||
os << ' ';
|
||||
}
|
||||
}
|
||||
os << "] ";
|
||||
if (cr) {
|
||||
if (mode & 1) {
|
||||
os << std::endl;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -142,6 +142,12 @@ class StackEntry {
|
|||
bool is(int wanted) const {
|
||||
return tp == wanted;
|
||||
}
|
||||
bool is_list() const {
|
||||
return is_list(this);
|
||||
}
|
||||
static bool is_list(const StackEntry& se) {
|
||||
return is_list(&se);
|
||||
}
|
||||
void swap(StackEntry& se) {
|
||||
ref.swap(se.ref);
|
||||
std::swap(tp, se.tp);
|
||||
|
@ -157,8 +163,9 @@ class StackEntry {
|
|||
}
|
||||
|
||||
private:
|
||||
static bool is_list(const StackEntry* se);
|
||||
template <typename T, Type tag>
|
||||
Ref<T> dynamic_as() const& {
|
||||
Ref<T> dynamic_as() const & {
|
||||
return tp == tag ? static_cast<Ref<T>>(ref) : td::Ref<T>{};
|
||||
}
|
||||
template <typename T, Type tag>
|
||||
|
@ -170,7 +177,7 @@ class StackEntry {
|
|||
return tp == tag ? static_cast<Ref<T>>(std::move(ref)) : td::Ref<T>{};
|
||||
}
|
||||
template <typename T, Type tag>
|
||||
Ref<T> as() const& {
|
||||
Ref<T> as() const & {
|
||||
return tp == tag ? Ref<T>{td::static_cast_ref(), ref} : td::Ref<T>{};
|
||||
}
|
||||
template <typename T, Type tag>
|
||||
|
@ -183,6 +190,8 @@ class StackEntry {
|
|||
}
|
||||
|
||||
public:
|
||||
static StackEntry make_list(std::vector<StackEntry>&& elems);
|
||||
static StackEntry make_list(const std::vector<StackEntry>& elems);
|
||||
template <typename T>
|
||||
static StackEntry maybe(Ref<T> ref) {
|
||||
if (ref.is_null()) {
|
||||
|
@ -191,31 +200,31 @@ class StackEntry {
|
|||
return ref;
|
||||
}
|
||||
}
|
||||
td::RefInt256 as_int() const& {
|
||||
td::RefInt256 as_int() const & {
|
||||
return as<td::CntInt256, t_int>();
|
||||
}
|
||||
td::RefInt256 as_int() && {
|
||||
return move_as<td::CntInt256, t_int>();
|
||||
}
|
||||
Ref<Cell> as_cell() const& {
|
||||
Ref<Cell> as_cell() const & {
|
||||
return as<Cell, t_cell>();
|
||||
}
|
||||
Ref<Cell> as_cell() && {
|
||||
return move_as<Cell, t_cell>();
|
||||
}
|
||||
Ref<CellBuilder> as_builder() const& {
|
||||
Ref<CellBuilder> as_builder() const & {
|
||||
return as<CellBuilder, t_builder>();
|
||||
}
|
||||
Ref<CellBuilder> as_builder() && {
|
||||
return move_as<CellBuilder, t_builder>();
|
||||
}
|
||||
Ref<CellSlice> as_slice() const& {
|
||||
Ref<CellSlice> as_slice() const & {
|
||||
return as<CellSlice, t_slice>();
|
||||
}
|
||||
Ref<CellSlice> as_slice() && {
|
||||
return move_as<CellSlice, t_slice>();
|
||||
}
|
||||
Ref<Continuation> as_cont() const&;
|
||||
Ref<Continuation> as_cont() const &;
|
||||
Ref<Continuation> as_cont() &&;
|
||||
Ref<Cnt<std::string>> as_string_ref() const {
|
||||
return as<Cnt<std::string>, t_string>();
|
||||
|
@ -230,16 +239,16 @@ class StackEntry {
|
|||
std::string as_bytes() const {
|
||||
return tp == t_bytes ? *as_bytes_ref() : "";
|
||||
}
|
||||
Ref<Box> as_box() const&;
|
||||
Ref<Box> as_box() const &;
|
||||
Ref<Box> as_box() &&;
|
||||
Ref<Tuple> as_tuple() const&;
|
||||
Ref<Tuple> as_tuple() const &;
|
||||
Ref<Tuple> as_tuple() &&;
|
||||
Ref<Tuple> as_tuple_range(unsigned max_len = 255, unsigned min_len = 0) const&;
|
||||
Ref<Tuple> as_tuple_range(unsigned max_len = 255, unsigned min_len = 0) const &;
|
||||
Ref<Tuple> as_tuple_range(unsigned max_len = 255, unsigned min_len = 0) &&;
|
||||
Ref<Atom> as_atom() const&;
|
||||
Ref<Atom> as_atom() const &;
|
||||
Ref<Atom> as_atom() &&;
|
||||
template <class T>
|
||||
Ref<T> as_object() const& {
|
||||
Ref<T> as_object() const & {
|
||||
return dynamic_as<T, t_object>();
|
||||
}
|
||||
template <class T>
|
||||
|
@ -248,8 +257,11 @@ class StackEntry {
|
|||
}
|
||||
void dump(std::ostream& os) const;
|
||||
void print_list(std::ostream& os) const;
|
||||
void print_list_tail(std::ostream& os) const;
|
||||
std::string to_string() const;
|
||||
std::string to_lisp_string() const;
|
||||
|
||||
private:
|
||||
static void print_list_tail(std::ostream& os, const StackEntry* se);
|
||||
};
|
||||
|
||||
inline void swap(StackEntry& se1, StackEntry& se2) {
|
||||
|
@ -490,7 +502,8 @@ class Stack : public td::CntObject {
|
|||
push(std::move(val));
|
||||
}
|
||||
}
|
||||
void dump(std::ostream& os, bool cr = true) const;
|
||||
// mode: +1 = add eoln, +2 = Lisp-style lists
|
||||
void dump(std::ostream& os, int mode = 1) const;
|
||||
};
|
||||
|
||||
} // namespace vm
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue