mirror of
https://github.com/ton-blockchain/ton
synced 2025-02-14 12:12:21 +00:00
Fix typos, UBs and warnings (#625)
This commit is contained in:
parent
5a47495d87
commit
0578cb4a42
19 changed files with 193 additions and 139 deletions
|
@ -68,7 +68,9 @@ void AdnlPeerPairImpl::alarm() {
|
|||
}
|
||||
if (retry_send_at_ && retry_send_at_.is_in_past()) {
|
||||
retry_send_at_ = td::Timestamp::never();
|
||||
send_messages_in(std::move(pending_messages_), false);
|
||||
auto messages = std::move(pending_messages_);
|
||||
pending_messages_.clear();
|
||||
send_messages_in(std::move(messages), true);
|
||||
}
|
||||
alarm_timestamp().relax(next_dht_query_at_);
|
||||
alarm_timestamp().relax(next_db_update_at_);
|
||||
|
@ -791,7 +793,9 @@ void AdnlPeerPairImpl::Conn::create_conn(td::actor::ActorId<AdnlPeerPairImpl> pe
|
|||
void AdnlPeerPairImpl::conn_change_state(AdnlConnectionIdShort id, bool ready) {
|
||||
if (ready) {
|
||||
if (pending_messages_.size() > 0) {
|
||||
send_messages_in(std::move(pending_messages_), true);
|
||||
auto messages = std::move(pending_messages_);
|
||||
pending_messages_.clear();
|
||||
send_messages_in(std::move(messages), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -624,6 +624,7 @@ void BlockDbImpl::get_block_by_id(ton::BlockId blk_id, bool need_data, td::Promi
|
|||
}
|
||||
}
|
||||
promise(it->second);
|
||||
return;
|
||||
}
|
||||
promise(td::Status::Error(-666, "block not found in database"));
|
||||
}
|
||||
|
@ -642,6 +643,7 @@ void BlockDbImpl::get_state_by_id(ton::BlockId blk_id, bool need_data, td::Promi
|
|||
}
|
||||
}
|
||||
promise(it->second);
|
||||
return;
|
||||
}
|
||||
if (zerostate.not_null() && blk_id == zerostate->blk.id) {
|
||||
LOG(DEBUG) << "get_state_by_id(): zerostate requested";
|
||||
|
@ -666,6 +668,7 @@ void BlockDbImpl::get_out_queue_info_by_id(ton::BlockId blk_id, td::Promise<td::
|
|||
if (it == state_info.end()) {
|
||||
promise(td::Status::Error(
|
||||
-666, std::string{"cannot obtain output queue info for block "} + blk_id.to_str() + " : cannot load state"));
|
||||
return;
|
||||
}
|
||||
if (it->second->data.is_null()) {
|
||||
LOG(DEBUG) << "loading data for state " << blk_id.to_str();
|
||||
|
@ -679,6 +682,7 @@ void BlockDbImpl::get_out_queue_info_by_id(ton::BlockId blk_id, td::Promise<td::
|
|||
if (it2 == block_info.end()) {
|
||||
promise(td::Status::Error(-666, std::string{"cannot obtain output queue info for block "} + blk_id.to_str() +
|
||||
" : cannot load block description"));
|
||||
return;
|
||||
}
|
||||
vm::StaticBagOfCellsDbLazy::Options options;
|
||||
auto res = vm::StaticBagOfCellsDbLazy::create(it->second->data.clone(), options);
|
||||
|
@ -707,10 +711,12 @@ void BlockDbImpl::get_out_queue_info_by_id(ton::BlockId blk_id, td::Promise<td::
|
|||
if (it->second->blk.root_hash != state_root->get_hash().bits()) {
|
||||
promise(td::Status::Error(
|
||||
-668, std::string{"state for block "} + blk_id.to_str() + " is invalid : state root hash mismatch"));
|
||||
return;
|
||||
}
|
||||
vm::CellSlice cs = vm::load_cell_slice(state_root);
|
||||
if (!cs.have(64, 1) || cs.prefetch_ulong(32) != 0x9023afde) {
|
||||
promise(td::Status::Error(-668, std::string{"state for block "} + blk_id.to_str() + " is invalid"));
|
||||
return;
|
||||
}
|
||||
auto out_queue_info = cs.prefetch_ref();
|
||||
promise(Ref<OutputQueueInfoDescr>{true, blk_id, it2->second->blk.root_hash.cbits(), state_root->get_hash().bits(),
|
||||
|
@ -758,6 +764,7 @@ void BlockDbImpl::save_new_block(ton::BlockIdExt id, td::BufferSlice data, int a
|
|||
auto save_res = save_db_file(id.file_hash, data, FMode::chk_if_exists | FMode::overwrite | FMode::chk_file_hash);
|
||||
if (save_res.is_error()) {
|
||||
promise(std::move(save_res));
|
||||
return;
|
||||
}
|
||||
auto sz = data.size();
|
||||
auto lev = bb.alloc<log::NewBlock>(id.id, id.root_hash, id.file_hash, data.size(), authority & 0xff);
|
||||
|
@ -780,6 +787,7 @@ void BlockDbImpl::save_new_state(ton::BlockIdExt id, td::BufferSlice data, int a
|
|||
auto save_res = save_db_file(id.file_hash, data, FMode::chk_if_exists | FMode::overwrite | FMode::chk_file_hash);
|
||||
if (save_res.is_error()) {
|
||||
promise(std::move(save_res));
|
||||
return;
|
||||
}
|
||||
auto sz = data.size();
|
||||
auto lev = bb.alloc<log::NewState>(id.id, id.root_hash, id.file_hash, data.size(), authority & 0xff);
|
||||
|
|
|
@ -486,7 +486,7 @@ void interpret_make_pop(vm::Stack& stack) {
|
|||
}
|
||||
|
||||
void interpret_is_string(vm::Stack& stack) {
|
||||
stack.push_bool(stack.pop().type() == vm::StackEntry::t_string);
|
||||
stack.push_bool(stack.pop_chk().type() == vm::StackEntry::t_string);
|
||||
}
|
||||
|
||||
int make_utf8_char(char buffer[4], int x) {
|
||||
|
@ -1285,7 +1285,7 @@ void interpret_atom_anon(vm::Stack& stack) {
|
|||
}
|
||||
|
||||
void interpret_is_atom(vm::Stack& stack) {
|
||||
stack.push_bool(stack.pop().is_atom());
|
||||
stack.push_bool(stack.pop_chk().is_atom());
|
||||
}
|
||||
|
||||
bool are_eqv(vm::StackEntry x, vm::StackEntry y) {
|
||||
|
@ -1307,11 +1307,13 @@ bool are_eqv(vm::StackEntry x, vm::StackEntry y) {
|
|||
}
|
||||
|
||||
void interpret_is_eqv(vm::Stack& stack) {
|
||||
stack.check_underflow(2);
|
||||
auto y = stack.pop(), x = stack.pop();
|
||||
stack.push_bool(are_eqv(std::move(x), std::move(y)));
|
||||
}
|
||||
|
||||
void interpret_is_eq(vm::Stack& stack) {
|
||||
stack.check_underflow(2);
|
||||
auto y = stack.pop(), x = stack.pop();
|
||||
stack.push_bool(x == y);
|
||||
}
|
||||
|
|
|
@ -158,9 +158,9 @@ void VarDescr::set_const(td::RefInt256 value) {
|
|||
} else if (s > 0) {
|
||||
val |= _NonZero | _Pos | _Finite;
|
||||
} else if (!s) {
|
||||
if (*int_const == 1) {
|
||||
val |= _Bit;
|
||||
}
|
||||
//if (*int_const == 1) {
|
||||
// val |= _Bit;
|
||||
//}
|
||||
val |= _Zero | _Neg | _Pos | _Finite | _Bool | _Bit;
|
||||
}
|
||||
if (val & _Finite) {
|
||||
|
|
|
@ -735,7 +735,7 @@ VarDescrList Op::fwd_analyze(VarDescrList values) {
|
|||
res.emplace_back(i);
|
||||
}
|
||||
AsmOpList tmp;
|
||||
func->compile(tmp, res, args); // abstract interpretation of res := f (args)
|
||||
func->compile(tmp, res, args, where); // abstract interpretation of res := f (args)
|
||||
int j = 0;
|
||||
for (var_idx_t i : left) {
|
||||
values.add_newval(i).set_value(res[j++]);
|
||||
|
|
|
@ -82,9 +82,10 @@ SymDef* define_builtin_const(std::string name, TypeExpr* const_type, Args&&... a
|
|||
define_builtin_func(name, TypeExpr::new_map(TypeExpr::new_unit(), const_type), std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
bool SymValAsmFunc::compile(AsmOpList& dest, std::vector<VarDescr>& out, std::vector<VarDescr>& in) const {
|
||||
bool SymValAsmFunc::compile(AsmOpList& dest, std::vector<VarDescr>& out, std::vector<VarDescr>& in,
|
||||
const SrcLocation& where) const {
|
||||
if (simple_compile) {
|
||||
return dest.append(simple_compile(out, in));
|
||||
return dest.append(simple_compile(out, in, where));
|
||||
} else if (ext_compile) {
|
||||
return ext_compile(dest, out, in);
|
||||
} else {
|
||||
|
@ -423,11 +424,14 @@ AsmOp push_const(td::RefInt256 x) {
|
|||
return AsmOp::IntConst(std::move(x));
|
||||
}
|
||||
|
||||
AsmOp compile_add(std::vector<VarDescr>& res, std::vector<VarDescr>& args) {
|
||||
AsmOp compile_add(std::vector<VarDescr>& res, std::vector<VarDescr>& args, const SrcLocation& where) {
|
||||
assert(res.size() == 1 && args.size() == 2);
|
||||
VarDescr &r = res[0], &x = args[0], &y = args[1];
|
||||
if (x.is_int_const() && y.is_int_const()) {
|
||||
r.set_const(x.int_const + y.int_const);
|
||||
if (!r.int_const->is_valid()) {
|
||||
throw src::ParseError(where, "integer overflow");
|
||||
}
|
||||
x.unused();
|
||||
y.unused();
|
||||
return push_const(r.int_const);
|
||||
|
@ -462,11 +466,14 @@ AsmOp compile_add(std::vector<VarDescr>& res, std::vector<VarDescr>& args) {
|
|||
return exec_op("ADD", 2);
|
||||
}
|
||||
|
||||
AsmOp compile_sub(std::vector<VarDescr>& res, std::vector<VarDescr>& args) {
|
||||
AsmOp compile_sub(std::vector<VarDescr>& res, std::vector<VarDescr>& args, const SrcLocation& where) {
|
||||
assert(res.size() == 1 && args.size() == 2);
|
||||
VarDescr &r = res[0], &x = args[0], &y = args[1];
|
||||
if (x.is_int_const() && y.is_int_const()) {
|
||||
r.set_const(x.int_const - y.int_const);
|
||||
if (!r.int_const->is_valid()) {
|
||||
throw src::ParseError(where, "integer overflow");
|
||||
}
|
||||
x.unused();
|
||||
y.unused();
|
||||
return push_const(r.int_const);
|
||||
|
@ -492,11 +499,14 @@ AsmOp compile_sub(std::vector<VarDescr>& res, std::vector<VarDescr>& args) {
|
|||
return exec_op("SUB", 2);
|
||||
}
|
||||
|
||||
AsmOp compile_negate(std::vector<VarDescr>& res, std::vector<VarDescr>& args) {
|
||||
AsmOp compile_negate(std::vector<VarDescr>& res, std::vector<VarDescr>& args, const SrcLocation& where) {
|
||||
assert(res.size() == 1 && args.size() == 1);
|
||||
VarDescr &r = res[0], &x = args[0];
|
||||
if (x.is_int_const()) {
|
||||
r.set_const(-x.int_const);
|
||||
if (!r.int_const->is_valid()) {
|
||||
throw src::ParseError(where, "integer overflow");
|
||||
}
|
||||
x.unused();
|
||||
return push_const(r.int_const);
|
||||
}
|
||||
|
@ -504,7 +514,7 @@ AsmOp compile_negate(std::vector<VarDescr>& res, std::vector<VarDescr>& args) {
|
|||
return exec_op("NEGATE", 1);
|
||||
}
|
||||
|
||||
AsmOp compile_and(std::vector<VarDescr>& res, std::vector<VarDescr>& args) {
|
||||
AsmOp compile_and(std::vector<VarDescr>& res, std::vector<VarDescr>& args, const SrcLocation& where) {
|
||||
assert(res.size() == 1 && args.size() == 2);
|
||||
VarDescr &r = res[0], &x = args[0], &y = args[1];
|
||||
if (x.is_int_const() && y.is_int_const()) {
|
||||
|
@ -517,7 +527,7 @@ AsmOp compile_and(std::vector<VarDescr>& res, std::vector<VarDescr>& args) {
|
|||
return exec_op("AND", 2);
|
||||
}
|
||||
|
||||
AsmOp compile_or(std::vector<VarDescr>& res, std::vector<VarDescr>& args) {
|
||||
AsmOp compile_or(std::vector<VarDescr>& res, std::vector<VarDescr>& args, const SrcLocation& where) {
|
||||
assert(res.size() == 1 && args.size() == 2);
|
||||
VarDescr &r = res[0], &x = args[0], &y = args[1];
|
||||
if (x.is_int_const() && y.is_int_const()) {
|
||||
|
@ -530,7 +540,7 @@ AsmOp compile_or(std::vector<VarDescr>& res, std::vector<VarDescr>& args) {
|
|||
return exec_op("OR", 2);
|
||||
}
|
||||
|
||||
AsmOp compile_xor(std::vector<VarDescr>& res, std::vector<VarDescr>& args) {
|
||||
AsmOp compile_xor(std::vector<VarDescr>& res, std::vector<VarDescr>& args, const SrcLocation& where) {
|
||||
assert(res.size() == 1 && args.size() == 2);
|
||||
VarDescr &r = res[0], &x = args[0], &y = args[1];
|
||||
if (x.is_int_const() && y.is_int_const()) {
|
||||
|
@ -543,7 +553,7 @@ AsmOp compile_xor(std::vector<VarDescr>& res, std::vector<VarDescr>& args) {
|
|||
return exec_op("XOR", 2);
|
||||
}
|
||||
|
||||
AsmOp compile_not(std::vector<VarDescr>& res, std::vector<VarDescr>& args) {
|
||||
AsmOp compile_not(std::vector<VarDescr>& res, std::vector<VarDescr>& args, const SrcLocation& where) {
|
||||
assert(res.size() == 1 && args.size() == 1);
|
||||
VarDescr &r = res[0], &x = args[0];
|
||||
if (x.is_int_const()) {
|
||||
|
@ -555,9 +565,12 @@ AsmOp compile_not(std::vector<VarDescr>& res, std::vector<VarDescr>& args) {
|
|||
return exec_op("NOT", 1);
|
||||
}
|
||||
|
||||
AsmOp compile_mul_internal(VarDescr& r, VarDescr& x, VarDescr& y) {
|
||||
AsmOp compile_mul_internal(VarDescr& r, VarDescr& x, VarDescr& y, const SrcLocation& where) {
|
||||
if (x.is_int_const() && y.is_int_const()) {
|
||||
r.set_const(x.int_const * y.int_const);
|
||||
if (!r.int_const->is_valid()) {
|
||||
throw src::ParseError(where, "integer overflow");
|
||||
}
|
||||
x.unused();
|
||||
y.unused();
|
||||
return push_const(r.int_const);
|
||||
|
@ -620,23 +633,23 @@ AsmOp compile_mul_internal(VarDescr& r, VarDescr& x, VarDescr& y) {
|
|||
return exec_op("MUL", 2);
|
||||
}
|
||||
|
||||
AsmOp compile_mul(std::vector<VarDescr>& res, std::vector<VarDescr>& args) {
|
||||
AsmOp compile_mul(std::vector<VarDescr>& res, std::vector<VarDescr>& args, const SrcLocation& where) {
|
||||
assert(res.size() == 1 && args.size() == 2);
|
||||
return compile_mul_internal(res[0], args[0], args[1]);
|
||||
return compile_mul_internal(res[0], args[0], args[1], where);
|
||||
}
|
||||
|
||||
AsmOp compile_lshift(std::vector<VarDescr>& res, std::vector<VarDescr>& args) {
|
||||
AsmOp compile_lshift(std::vector<VarDescr>& res, std::vector<VarDescr>& args, const SrcLocation& where) {
|
||||
assert(res.size() == 1 && args.size() == 2);
|
||||
VarDescr &r = res[0], &x = args[0], &y = args[1];
|
||||
if (y.is_int_const()) {
|
||||
auto yv = y.int_const->to_long();
|
||||
if (yv < 0 || yv > 256) {
|
||||
r.set_const_nan();
|
||||
x.unused();
|
||||
y.unused();
|
||||
return push_const(r.int_const);
|
||||
throw src::ParseError(where, "lshift argument is out of range");
|
||||
} else if (x.is_int_const()) {
|
||||
r.set_const(x.int_const << (int)yv);
|
||||
if (!r.int_const->is_valid()) {
|
||||
throw src::ParseError(where, "integer overflow");
|
||||
}
|
||||
x.unused();
|
||||
y.unused();
|
||||
return push_const(r.int_const);
|
||||
|
@ -661,22 +674,20 @@ AsmOp compile_lshift(std::vector<VarDescr>& res, std::vector<VarDescr>& args) {
|
|||
}
|
||||
if (xv == -1) {
|
||||
x.unused();
|
||||
return exec_op("NEGPOW2", 1);
|
||||
return exec_op("-1 PUSHINT SWAP LSHIFT", 1);
|
||||
}
|
||||
}
|
||||
return exec_op("LSHIFT", 2);
|
||||
}
|
||||
|
||||
AsmOp compile_rshift(std::vector<VarDescr>& res, std::vector<VarDescr>& args, int round_mode) {
|
||||
AsmOp compile_rshift(std::vector<VarDescr>& res, std::vector<VarDescr>& args, const SrcLocation& where,
|
||||
int round_mode) {
|
||||
assert(res.size() == 1 && args.size() == 2);
|
||||
VarDescr &r = res[0], &x = args[0], &y = args[1];
|
||||
if (y.is_int_const()) {
|
||||
auto yv = y.int_const->to_long();
|
||||
if (yv < 0 || yv > 256) {
|
||||
r.set_const_nan();
|
||||
x.unused();
|
||||
y.unused();
|
||||
return push_const(r.int_const);
|
||||
throw src::ParseError(where, "rshift argument is out of range");
|
||||
} else if (x.is_int_const()) {
|
||||
r.set_const(td::rshift(x.int_const, (int)yv, round_mode));
|
||||
x.unused();
|
||||
|
@ -699,9 +710,12 @@ AsmOp compile_rshift(std::vector<VarDescr>& res, std::vector<VarDescr>& args, in
|
|||
return exec_op(rshift, 2);
|
||||
}
|
||||
|
||||
AsmOp compile_div_internal(VarDescr& r, VarDescr& x, VarDescr& y, int round_mode) {
|
||||
AsmOp compile_div_internal(VarDescr& r, VarDescr& x, VarDescr& y, const SrcLocation& where, int round_mode) {
|
||||
if (x.is_int_const() && y.is_int_const()) {
|
||||
r.set_const(div(x.int_const, y.int_const, round_mode));
|
||||
if (!r.int_const->is_valid()) {
|
||||
throw src::ParseError(where, *y.int_const == 0 ? "division by zero" : "integer overflow");
|
||||
}
|
||||
x.unused();
|
||||
y.unused();
|
||||
return push_const(r.int_const);
|
||||
|
@ -709,10 +723,7 @@ AsmOp compile_div_internal(VarDescr& r, VarDescr& x, VarDescr& y, int round_mode
|
|||
r.val = emulate_div(x.val, y.val);
|
||||
if (y.is_int_const()) {
|
||||
if (*y.int_const == 0) {
|
||||
x.unused();
|
||||
y.unused();
|
||||
r.set_const(div(y.int_const, y.int_const));
|
||||
return push_const(r.int_const);
|
||||
throw src::ParseError(where, "division by zero");
|
||||
}
|
||||
if (*y.int_const == 1 && x.always_finite()) {
|
||||
y.unused();
|
||||
|
@ -739,16 +750,20 @@ AsmOp compile_div_internal(VarDescr& r, VarDescr& x, VarDescr& y, int round_mode
|
|||
return exec_op(op, 2);
|
||||
}
|
||||
|
||||
AsmOp compile_div(std::vector<VarDescr>& res, std::vector<VarDescr>& args, int round_mode) {
|
||||
AsmOp compile_div(std::vector<VarDescr>& res, std::vector<VarDescr>& args, const SrcLocation& where, int round_mode) {
|
||||
assert(res.size() == 1 && args.size() == 2);
|
||||
return compile_div_internal(res[0], args[0], args[1], round_mode);
|
||||
return compile_div_internal(res[0], args[0], args[1], where, round_mode);
|
||||
}
|
||||
|
||||
AsmOp compile_mod(std::vector<VarDescr>& res, std::vector<VarDescr>& args, int round_mode) {
|
||||
AsmOp compile_mod(std::vector<VarDescr>& res, std::vector<VarDescr>& args, const src::SrcLocation& where,
|
||||
int round_mode) {
|
||||
assert(res.size() == 1 && args.size() == 2);
|
||||
VarDescr &r = res[0], &x = args[0], &y = args[1];
|
||||
if (x.is_int_const() && y.is_int_const()) {
|
||||
r.set_const(mod(x.int_const, y.int_const, round_mode));
|
||||
if (!r.int_const->is_valid()) {
|
||||
throw src::ParseError(where, *y.int_const == 0 ? "division by zero" : "integer overflow");
|
||||
}
|
||||
x.unused();
|
||||
y.unused();
|
||||
return push_const(r.int_const);
|
||||
|
@ -756,10 +771,7 @@ AsmOp compile_mod(std::vector<VarDescr>& res, std::vector<VarDescr>& args, int r
|
|||
r.val = emulate_mod(x.val, y.val);
|
||||
if (y.is_int_const()) {
|
||||
if (*y.int_const == 0) {
|
||||
x.unused();
|
||||
y.unused();
|
||||
r.set_const(mod(y.int_const, y.int_const));
|
||||
return push_const(r.int_const);
|
||||
throw src::ParseError(where, "division by zero");
|
||||
}
|
||||
if ((*y.int_const == 1 || *y.int_const == -1) && x.always_finite()) {
|
||||
x.unused();
|
||||
|
@ -784,11 +796,15 @@ AsmOp compile_mod(std::vector<VarDescr>& res, std::vector<VarDescr>& args, int r
|
|||
return exec_op(op, 2);
|
||||
}
|
||||
|
||||
AsmOp compile_muldiv(std::vector<VarDescr>& res, std::vector<VarDescr>& args, int round_mode) {
|
||||
AsmOp compile_muldiv(std::vector<VarDescr>& res, std::vector<VarDescr>& args, const SrcLocation& where,
|
||||
int round_mode) {
|
||||
assert(res.size() == 1 && args.size() == 3);
|
||||
VarDescr &r = res[0], &x = args[0], &y = args[1], &z = args[2];
|
||||
if (x.is_int_const() && y.is_int_const() && z.is_int_const()) {
|
||||
r.set_const(muldiv(x.int_const, y.int_const, z.int_const, round_mode));
|
||||
if (!r.int_const->is_valid()) {
|
||||
throw src::ParseError(where, *z.int_const == 0 ? "division by zero" : "integer overflow");
|
||||
}
|
||||
x.unused();
|
||||
y.unused();
|
||||
z.unused();
|
||||
|
@ -806,24 +822,20 @@ AsmOp compile_muldiv(std::vector<VarDescr>& res, std::vector<VarDescr>& args, in
|
|||
r.val = emulate_div(emulate_mul(x.val, y.val), z.val);
|
||||
if (z.is_int_const()) {
|
||||
if (*z.int_const == 0) {
|
||||
x.unused();
|
||||
y.unused();
|
||||
z.unused();
|
||||
r.set_const(div(z.int_const, z.int_const));
|
||||
return push_const(r.int_const);
|
||||
throw src::ParseError(where, "division by zero");
|
||||
}
|
||||
if (*z.int_const == 1) {
|
||||
z.unused();
|
||||
return compile_mul_internal(r, x, y);
|
||||
return compile_mul_internal(r, x, y, where);
|
||||
}
|
||||
}
|
||||
if (y.is_int_const() && *y.int_const == 1) {
|
||||
y.unused();
|
||||
return compile_div_internal(r, x, z, round_mode);
|
||||
return compile_div_internal(r, x, z, where, round_mode);
|
||||
}
|
||||
if (x.is_int_const() && *x.int_const == 1) {
|
||||
x.unused();
|
||||
return compile_div_internal(r, y, z, round_mode);
|
||||
return compile_div_internal(r, y, z, where, round_mode);
|
||||
}
|
||||
if (z.is_int_const()) {
|
||||
int k = is_pos_pow2(z.int_const);
|
||||
|
@ -954,7 +966,7 @@ AsmOp compile_cmp_int(std::vector<VarDescr>& res, std::vector<VarDescr>& args, i
|
|||
return exec_op(cmp_names[mode], 2);
|
||||
}
|
||||
|
||||
AsmOp compile_throw(std::vector<VarDescr>& res, std::vector<VarDescr>& args) {
|
||||
AsmOp compile_throw(std::vector<VarDescr>& res, std::vector<VarDescr>& args, const SrcLocation&) {
|
||||
assert(res.empty() && args.size() == 1);
|
||||
VarDescr& x = args[0];
|
||||
if (x.is_int_const() && x.int_const->unsigned_fits_bits(11)) {
|
||||
|
@ -986,7 +998,7 @@ AsmOp compile_cond_throw(std::vector<VarDescr>& res, std::vector<VarDescr>& args
|
|||
}
|
||||
}
|
||||
|
||||
AsmOp compile_throw_arg(std::vector<VarDescr>& res, std::vector<VarDescr>& args) {
|
||||
AsmOp compile_throw_arg(std::vector<VarDescr>& res, std::vector<VarDescr>& args, const SrcLocation&) {
|
||||
assert(res.empty() && args.size() == 2);
|
||||
VarDescr &x = args[1];
|
||||
if (x.is_int_const() && x.int_const->unsigned_fits_bits(11)) {
|
||||
|
@ -1077,7 +1089,7 @@ AsmOp compile_fetch_slice(std::vector<VarDescr>& res, std::vector<VarDescr>& arg
|
|||
}
|
||||
|
||||
// <type> <type>_at(tuple t, int index) asm "INDEXVAR";
|
||||
AsmOp compile_tuple_at(std::vector<VarDescr>& res, std::vector<VarDescr>& args) {
|
||||
AsmOp compile_tuple_at(std::vector<VarDescr>& res, std::vector<VarDescr>& args, const SrcLocation&) {
|
||||
assert(args.size() == 2 && res.size() == 1);
|
||||
auto& y = args[1];
|
||||
if (y.is_int_const() && y.int_const >= 0 && y.int_const < 16) {
|
||||
|
@ -1088,7 +1100,7 @@ AsmOp compile_tuple_at(std::vector<VarDescr>& res, std::vector<VarDescr>& args)
|
|||
}
|
||||
|
||||
// int null?(X arg)
|
||||
AsmOp compile_is_null(std::vector<VarDescr>& res, std::vector<VarDescr>& args) {
|
||||
AsmOp compile_is_null(std::vector<VarDescr>& res, std::vector<VarDescr>& args, const SrcLocation&) {
|
||||
assert(args.size() == 1 && res.size() == 1);
|
||||
auto &x = args[0], &r = res[0];
|
||||
if (x.always_null() || x.always_not_null()) {
|
||||
|
@ -1149,21 +1161,21 @@ void define_builtins() {
|
|||
define_builtin_func("_-_", arith_bin_op, compile_sub);
|
||||
define_builtin_func("-_", arith_un_op, compile_negate);
|
||||
define_builtin_func("_*_", arith_bin_op, compile_mul);
|
||||
define_builtin_func("_/_", arith_bin_op, std::bind(compile_div, _1, _2, -1));
|
||||
define_builtin_func("_~/_", arith_bin_op, std::bind(compile_div, _1, _2, 0));
|
||||
define_builtin_func("_^/_", arith_bin_op, std::bind(compile_div, _1, _2, 1));
|
||||
define_builtin_func("_%_", arith_bin_op, std::bind(compile_mod, _1, _2, -1));
|
||||
define_builtin_func("_~%_", arith_bin_op, std::bind(compile_mod, _1, _2, 0));
|
||||
define_builtin_func("_^%_", arith_bin_op, std::bind(compile_mod, _1, _2, 1));
|
||||
define_builtin_func("_/_", arith_bin_op, std::bind(compile_div, _1, _2, _3, -1));
|
||||
define_builtin_func("_~/_", arith_bin_op, std::bind(compile_div, _1, _2, _3, 0));
|
||||
define_builtin_func("_^/_", arith_bin_op, std::bind(compile_div, _1, _2, _3, 1));
|
||||
define_builtin_func("_%_", arith_bin_op, std::bind(compile_mod, _1, _2, _3, -1));
|
||||
define_builtin_func("_~%_", arith_bin_op, std::bind(compile_mod, _1, _2, _3, 0));
|
||||
define_builtin_func("_^%_", arith_bin_op, std::bind(compile_mod, _1, _2, _3, 1));
|
||||
define_builtin_func("_/%_", TypeExpr::new_map(Int2, Int2), AsmOp::Custom("DIVMOD", 2, 2));
|
||||
define_builtin_func("divmod", TypeExpr::new_map(Int2, Int2), AsmOp::Custom("DIVMOD", 2, 2));
|
||||
define_builtin_func("~divmod", TypeExpr::new_map(Int2, Int2), AsmOp::Custom("DIVMOD", 2, 2));
|
||||
define_builtin_func("moddiv", TypeExpr::new_map(Int2, Int2), AsmOp::Custom("DIVMOD", 2, 2), {}, {1, 0});
|
||||
define_builtin_func("~moddiv", TypeExpr::new_map(Int2, Int2), AsmOp::Custom("DIVMOD", 2, 2), {}, {1, 0});
|
||||
define_builtin_func("_<<_", arith_bin_op, compile_lshift);
|
||||
define_builtin_func("_>>_", arith_bin_op, std::bind(compile_rshift, _1, _2, -1));
|
||||
define_builtin_func("_~>>_", arith_bin_op, std::bind(compile_rshift, _1, _2, 0));
|
||||
define_builtin_func("_^>>_", arith_bin_op, std::bind(compile_rshift, _1, _2, 1));
|
||||
define_builtin_func("_>>_", arith_bin_op, std::bind(compile_rshift, _1, _2, _3, -1));
|
||||
define_builtin_func("_~>>_", arith_bin_op, std::bind(compile_rshift, _1, _2, _3, 0));
|
||||
define_builtin_func("_^>>_", arith_bin_op, std::bind(compile_rshift, _1, _2, _3, 1));
|
||||
define_builtin_func("_&_", arith_bin_op, compile_and);
|
||||
define_builtin_func("_|_", arith_bin_op, compile_or);
|
||||
define_builtin_func("_^_", arith_bin_op, compile_xor);
|
||||
|
@ -1171,22 +1183,22 @@ void define_builtins() {
|
|||
define_builtin_func("^_+=_", arith_bin_op, compile_add);
|
||||
define_builtin_func("^_-=_", arith_bin_op, compile_sub);
|
||||
define_builtin_func("^_*=_", arith_bin_op, compile_mul);
|
||||
define_builtin_func("^_/=_", arith_bin_op, std::bind(compile_div, _1, _2, -1));
|
||||
define_builtin_func("^_~/=_", arith_bin_op, std::bind(compile_div, _1, _2, 0));
|
||||
define_builtin_func("^_^/=_", arith_bin_op, std::bind(compile_div, _1, _2, 1));
|
||||
define_builtin_func("^_%=_", arith_bin_op, std::bind(compile_mod, _1, _2, -1));
|
||||
define_builtin_func("^_~%=_", arith_bin_op, std::bind(compile_mod, _1, _2, 0));
|
||||
define_builtin_func("^_^%=_", arith_bin_op, std::bind(compile_mod, _1, _2, 1));
|
||||
define_builtin_func("^_/=_", arith_bin_op, std::bind(compile_div, _1, _2, _3, -1));
|
||||
define_builtin_func("^_~/=_", arith_bin_op, std::bind(compile_div, _1, _2, _3, 0));
|
||||
define_builtin_func("^_^/=_", arith_bin_op, std::bind(compile_div, _1, _2, _3, 1));
|
||||
define_builtin_func("^_%=_", arith_bin_op, std::bind(compile_mod, _1, _2, _3, -1));
|
||||
define_builtin_func("^_~%=_", arith_bin_op, std::bind(compile_mod, _1, _2, _3, 0));
|
||||
define_builtin_func("^_^%=_", arith_bin_op, std::bind(compile_mod, _1, _2, _3, 1));
|
||||
define_builtin_func("^_<<=_", arith_bin_op, compile_lshift);
|
||||
define_builtin_func("^_>>=_", arith_bin_op, std::bind(compile_rshift, _1, _2, -1));
|
||||
define_builtin_func("^_~>>=_", arith_bin_op, std::bind(compile_rshift, _1, _2, 0));
|
||||
define_builtin_func("^_^>>=_", arith_bin_op, std::bind(compile_rshift, _1, _2, 1));
|
||||
define_builtin_func("^_>>=_", arith_bin_op, std::bind(compile_rshift, _1, _2, _3, -1));
|
||||
define_builtin_func("^_~>>=_", arith_bin_op, std::bind(compile_rshift, _1, _2, _3, 0));
|
||||
define_builtin_func("^_^>>=_", arith_bin_op, std::bind(compile_rshift, _1, _2, _3, 1));
|
||||
define_builtin_func("^_&=_", arith_bin_op, compile_and);
|
||||
define_builtin_func("^_|=_", arith_bin_op, compile_or);
|
||||
define_builtin_func("^_^=_", arith_bin_op, compile_xor);
|
||||
define_builtin_func("muldiv", TypeExpr::new_map(Int3, Int), std::bind(compile_muldiv, _1, _2, -1));
|
||||
define_builtin_func("muldivr", TypeExpr::new_map(Int3, Int), std::bind(compile_muldiv, _1, _2, 0));
|
||||
define_builtin_func("muldivc", TypeExpr::new_map(Int3, Int), std::bind(compile_muldiv, _1, _2, 1));
|
||||
define_builtin_func("muldiv", TypeExpr::new_map(Int3, Int), std::bind(compile_muldiv, _1, _2, _3, -1));
|
||||
define_builtin_func("muldivr", TypeExpr::new_map(Int3, Int), std::bind(compile_muldiv, _1, _2, _3, 0));
|
||||
define_builtin_func("muldivc", TypeExpr::new_map(Int3, Int), std::bind(compile_muldiv, _1, _2, _3, 1));
|
||||
define_builtin_func("muldivmod", TypeExpr::new_map(Int3, Int2), AsmOp::Custom("MULDIVMOD", 3, 2));
|
||||
define_builtin_func("_==_", arith_bin_op, std::bind(compile_cmp_int, _1, _2, 2));
|
||||
define_builtin_func("_!=_", arith_bin_op, std::bind(compile_cmp_int, _1, _2, 5));
|
||||
|
@ -1232,16 +1244,18 @@ void define_builtins() {
|
|||
AsmOp::Custom("s0 DUMP", 1, 1), true);
|
||||
define_builtin_func("~strdump", TypeExpr::new_forall({X}, TypeExpr::new_map(X, TypeExpr::new_tensor({X, Unit}))),
|
||||
AsmOp::Custom("STRDUMP", 1, 1), true);
|
||||
define_builtin_func("run_method0", TypeExpr::new_map(Int, Unit),
|
||||
[](auto a, auto b, auto c) { return compile_run_method(a, b, c, 0, false); }, true);
|
||||
define_builtin_func("run_method1", TypeExpr::new_forall({X}, TypeExpr::new_map(TypeExpr::new_tensor({Int, X}), Unit)),
|
||||
[](auto a, auto b, auto c) { return compile_run_method(a, b, c, 1, false); }, {1, 0}, {}, true);
|
||||
define_builtin_func(
|
||||
"run_method0", TypeExpr::new_map(Int, Unit),
|
||||
[](AsmOpList& a, auto b, auto c) { return compile_run_method(a, b, c, 0, false); }, true);
|
||||
define_builtin_func(
|
||||
"run_method1", TypeExpr::new_forall({X}, TypeExpr::new_map(TypeExpr::new_tensor({Int, X}), Unit)),
|
||||
[](AsmOpList& a, auto b, auto c) { return compile_run_method(a, b, c, 1, false); }, {1, 0}, {}, true);
|
||||
define_builtin_func(
|
||||
"run_method2", TypeExpr::new_forall({X, Y}, TypeExpr::new_map(TypeExpr::new_tensor({Int, X, Y}), Unit)),
|
||||
[](auto a, auto b, auto c) { return compile_run_method(a, b, c, 2, false); }, {1, 2, 0}, {}, true);
|
||||
[](AsmOpList& a, auto b, auto c) { return compile_run_method(a, b, c, 2, false); }, {1, 2, 0}, {}, true);
|
||||
define_builtin_func(
|
||||
"run_method3", TypeExpr::new_forall({X, Y, Z}, TypeExpr::new_map(TypeExpr::new_tensor({Int, X, Y, Z}), Unit)),
|
||||
[](auto a, auto b, auto c) { return compile_run_method(a, b, c, 3, false); }, {1, 2, 3, 0}, {}, true);
|
||||
[](AsmOpList& a, auto b, auto c) { return compile_run_method(a, b, c, 3, false); }, {1, 2, 3, 0}, {}, true);
|
||||
}
|
||||
|
||||
} // namespace funC
|
||||
|
|
|
@ -276,7 +276,6 @@ bool Op::generate_code_step(Stack& stack) {
|
|||
stack.opt_show();
|
||||
stack.drop_vars_except(var_info);
|
||||
stack.opt_show();
|
||||
const auto& next_var_info = next->var_info;
|
||||
bool inline_func = stack.mode & Stack::_InlineFunc;
|
||||
switch (cl) {
|
||||
case _Nop:
|
||||
|
@ -291,7 +290,7 @@ bool Op::generate_code_step(Stack& stack) {
|
|||
return false;
|
||||
}
|
||||
case _IntConst: {
|
||||
auto p = next_var_info[left[0]];
|
||||
auto p = next->var_info[left[0]];
|
||||
if (!p || p->is_unused()) {
|
||||
return true;
|
||||
}
|
||||
|
@ -307,7 +306,7 @@ bool Op::generate_code_step(Stack& stack) {
|
|||
return true;
|
||||
}
|
||||
case _SliceConst: {
|
||||
auto p = next_var_info[left[0]];
|
||||
auto p = next->var_info[left[0]];
|
||||
if (!p || p->is_unused()) {
|
||||
return true;
|
||||
}
|
||||
|
@ -319,7 +318,7 @@ bool Op::generate_code_step(Stack& stack) {
|
|||
if (dynamic_cast<const SymValGlobVar*>(fun_ref->value)) {
|
||||
bool used = false;
|
||||
for (auto i : left) {
|
||||
auto p = next_var_info[i];
|
||||
auto p = next->var_info[i];
|
||||
if (p && !p->is_unused()) {
|
||||
used = true;
|
||||
}
|
||||
|
@ -339,7 +338,7 @@ bool Op::generate_code_step(Stack& stack) {
|
|||
return true;
|
||||
} else {
|
||||
assert(left.size() == 1);
|
||||
auto p = next_var_info[left[0]];
|
||||
auto p = next->var_info[left[0]];
|
||||
if (!p || p->is_unused() || disabled()) {
|
||||
return true;
|
||||
}
|
||||
|
@ -360,7 +359,7 @@ bool Op::generate_code_step(Stack& stack) {
|
|||
for (int i = 0; i < wr; i++) {
|
||||
args0.emplace_back(0);
|
||||
}
|
||||
func->compile(stack.o, res, args0); // compile res := f (args0)
|
||||
func->compile(stack.o, res, args0, where); // compile res := f (args0)
|
||||
} else {
|
||||
std::string name = sym::symbols.get_name(fun_ref->sym_idx);
|
||||
stack.o << AsmOp::Custom(name + " CALLDICT", (int)right.size(), (int)left.size());
|
||||
|
@ -377,7 +376,7 @@ bool Op::generate_code_step(Stack& stack) {
|
|||
active.reserve(left.size());
|
||||
for (std::size_t k = 0; k < left.size(); k++) {
|
||||
var_idx_t y = left[k]; // "y" = "x"
|
||||
auto p = next_var_info[y];
|
||||
auto p = next->var_info[y];
|
||||
active.push_back(p && !p->is_unused());
|
||||
}
|
||||
for (std::size_t k = 0; k < left.size(); k++) {
|
||||
|
@ -489,7 +488,7 @@ bool Op::generate_code_step(Stack& stack) {
|
|||
for (var_idx_t i : left) {
|
||||
res.emplace_back(i);
|
||||
}
|
||||
func->compile(stack.o, res, args); // compile res := f (args)
|
||||
func->compile(stack.o, res, args, where); // compile res := f (args)
|
||||
} else {
|
||||
auto fv = dynamic_cast<const SymValCodeFunc*>(fun_ref->value);
|
||||
std::string name = sym::symbols.get_name(fun_ref->sym_idx);
|
||||
|
|
|
@ -109,7 +109,7 @@ int main(int argc, char* const argv[]) {
|
|||
|
||||
std::unique_ptr<std::fstream> fs;
|
||||
if (!output_filename.empty()) {
|
||||
fs = std::make_unique<std::fstream>(output_filename, fs->trunc | fs->out);
|
||||
fs = std::make_unique<std::fstream>(output_filename, std::fstream::trunc | std::fstream::out);
|
||||
if (!fs->is_open()) {
|
||||
std::cerr << "failed to create output file " << output_filename << '\n';
|
||||
return 2;
|
||||
|
|
|
@ -505,7 +505,7 @@ class ListIterator {
|
|||
ptr = ptr->next.get();
|
||||
return *this;
|
||||
}
|
||||
ListIterator& operator++(int) {
|
||||
ListIterator operator++(int) {
|
||||
T* z = ptr;
|
||||
ptr = ptr->next.get();
|
||||
return ListIterator{z};
|
||||
|
@ -1631,11 +1631,11 @@ struct Stack {
|
|||
*
|
||||
*/
|
||||
|
||||
typedef std::function<AsmOp(std::vector<VarDescr>&, std::vector<VarDescr>&)> simple_compile_func_t;
|
||||
typedef std::function<AsmOp(std::vector<VarDescr>&, std::vector<VarDescr>&, const SrcLocation)> simple_compile_func_t;
|
||||
typedef std::function<bool(AsmOpList&, std::vector<VarDescr>&, std::vector<VarDescr>&)> compile_func_t;
|
||||
|
||||
inline simple_compile_func_t make_simple_compile(AsmOp op) {
|
||||
return [op](std::vector<VarDescr>& out, std::vector<VarDescr>& in) -> AsmOp { return op; };
|
||||
return [op](std::vector<VarDescr>& out, std::vector<VarDescr>& in, const SrcLocation&) -> AsmOp { return op; };
|
||||
}
|
||||
|
||||
inline compile_func_t make_ext_compile(std::vector<AsmOp> ops) {
|
||||
|
@ -1674,7 +1674,7 @@ struct SymValAsmFunc : SymValFunc {
|
|||
std::initializer_list<int> ret_order = {}, bool impure = false)
|
||||
: SymValFunc(-1, ft, arg_order, ret_order, impure), ext_compile(std::move(_compile)) {
|
||||
}
|
||||
bool compile(AsmOpList& dest, std::vector<VarDescr>& out, std::vector<VarDescr>& in) const;
|
||||
bool compile(AsmOpList& dest, std::vector<VarDescr>& out, std::vector<VarDescr>& in, const SrcLocation& where) const;
|
||||
};
|
||||
|
||||
// defined in builtins.cpp
|
||||
|
|
|
@ -487,7 +487,7 @@ Expr* parse_expr100(Lexer& lex, CodeBlob& code, bool nv) {
|
|||
Expr* res = new Expr{Expr::_Const, lex.cur().loc};
|
||||
res->flags = Expr::_IsRvalue;
|
||||
res->intval = td::string_to_int256(lex.cur().str);
|
||||
if (res->intval.is_null()) {
|
||||
if (res->intval.is_null() || !res->intval->signed_fits_bits(257)) {
|
||||
lex.cur().error_at("invalid integer constant `", "`");
|
||||
}
|
||||
res->e_type = TypeExpr::new_atomic(_Int);
|
||||
|
|
|
@ -289,7 +289,7 @@ struct MixedRadix {
|
|||
}
|
||||
|
||||
explicit operator long long() const {
|
||||
long long acc = 0.;
|
||||
unsigned long long acc = 0;
|
||||
for (int i = N - 1; i >= 0; --i) {
|
||||
acc = acc * mod[i] + a[i];
|
||||
}
|
||||
|
@ -903,7 +903,7 @@ struct ModArray {
|
|||
}
|
||||
for (; i < size; i++) {
|
||||
pow += 8;
|
||||
acc = (acc << 8) + arr[i];
|
||||
acc = (acc * 256) + arr[i];
|
||||
if (pow >= 56) {
|
||||
lshift_add(pow, acc);
|
||||
acc = pow = 0;
|
||||
|
|
|
@ -186,7 +186,7 @@ td::RefInt256 make_special_int(int x, BInt* ptr = nullptr, unsigned char bin[64]
|
|||
int acc = b, r = ord;
|
||||
for (int i = 63; i >= 0; --i) {
|
||||
if (r < 8) {
|
||||
acc += (a << r);
|
||||
acc += ((unsigned)a << r);
|
||||
r = 1024;
|
||||
}
|
||||
r -= 8;
|
||||
|
@ -215,7 +215,7 @@ int randexp(int max = 63, int min = 0) {
|
|||
}
|
||||
|
||||
void bin_add_small(unsigned char bin[64], long long val, int shift = 0) {
|
||||
val <<= shift & 7;
|
||||
val *= (1 << (shift & 7));
|
||||
for (int i = 63 - (shift >> 3); i >= 0 && val; --i) {
|
||||
val += bin[i];
|
||||
bin[i] = (unsigned char)val;
|
||||
|
|
|
@ -44,7 +44,7 @@ class DhtQuery : public td::actor::Actor {
|
|||
bool client_only_;
|
||||
|
||||
public:
|
||||
DhtQuery(DhtKeyId key, DhtMember::PrintId print_id, adnl::AdnlNodeIdShort src, DhtNodesList list, td::uint32 k,
|
||||
DhtQuery(DhtKeyId key, DhtMember::PrintId print_id, adnl::AdnlNodeIdShort src, td::uint32 k,
|
||||
td::uint32 a, td::int32 our_network_id, DhtNode self, bool client_only, td::actor::ActorId<DhtMember> node,
|
||||
td::actor::ActorId<adnl::Adnl> adnl)
|
||||
: key_(key)
|
||||
|
@ -57,7 +57,6 @@ class DhtQuery : public td::actor::Actor {
|
|||
, our_network_id_(our_network_id)
|
||||
, node_(node)
|
||||
, adnl_(adnl) {
|
||||
add_nodes(std::move(list));
|
||||
}
|
||||
DhtMember::PrintId print_id() const {
|
||||
return print_id_;
|
||||
|
@ -112,8 +111,9 @@ class DhtQueryFindNodes : public DhtQuery {
|
|||
td::uint32 k, td::uint32 a, td::int32 our_network_id, DhtNode self, bool client_only,
|
||||
td::actor::ActorId<DhtMember> node, td::actor::ActorId<adnl::Adnl> adnl,
|
||||
td::Promise<DhtNodesList> promise)
|
||||
: DhtQuery(key, print_id, src, std::move(list), k, a, our_network_id, std::move(self), client_only, node, adnl)
|
||||
: DhtQuery(key, print_id, src, k, a, our_network_id, std::move(self), client_only, node, adnl)
|
||||
, promise_(std::move(promise)) {
|
||||
add_nodes(std::move(list));
|
||||
}
|
||||
void send_one_query(adnl::AdnlNodeIdShort id) override;
|
||||
void on_result(td::Result<td::BufferSlice> R, adnl::AdnlNodeIdShort dst);
|
||||
|
@ -132,8 +132,9 @@ class DhtQueryFindValue : public DhtQuery {
|
|||
td::uint32 k, td::uint32 a, td::int32 our_network_id, DhtNode self, bool client_only,
|
||||
td::actor::ActorId<DhtMember> node, td::actor::ActorId<adnl::Adnl> adnl,
|
||||
td::Promise<DhtValue> promise)
|
||||
: DhtQuery(key, print_id, src, std::move(list), k, a, our_network_id, std::move(self), client_only, node, adnl)
|
||||
: DhtQuery(key, print_id, src, k, a, our_network_id, std::move(self), client_only, node, adnl)
|
||||
, promise_(std::move(promise)) {
|
||||
add_nodes(std::move(list));
|
||||
}
|
||||
void send_one_query(adnl::AdnlNodeIdShort id) override;
|
||||
void send_one_query_nodes(adnl::AdnlNodeIdShort id);
|
||||
|
@ -219,11 +220,12 @@ class DhtQueryRequestReversePing : public DhtQuery {
|
|||
td::uint32 a, td::int32 our_network_id, DhtNode self, bool client_only,
|
||||
td::actor::ActorId<DhtMember> node, td::actor::ActorId<adnl::Adnl> adnl,
|
||||
td::Promise<td::Unit> promise)
|
||||
: DhtQuery(DhtMember::get_reverse_connection_key(client).compute_key_id(), print_id, src, std::move(list), k, a,
|
||||
our_network_id, std::move(self), client_only, node, adnl)
|
||||
: DhtQuery(DhtMember::get_reverse_connection_key(client).compute_key_id(), print_id, src, k, a, our_network_id,
|
||||
std::move(self), client_only, node, adnl)
|
||||
, promise_(std::move(promise))
|
||||
, query_(create_serialize_tl_object<ton_api::dht_requestReversePing>(target.tl(), std::move(signature),
|
||||
client.bits256_value(), k)) {
|
||||
add_nodes(std::move(list));
|
||||
}
|
||||
void send_one_query(adnl::AdnlNodeIdShort id) override;
|
||||
void on_result(td::Result<td::BufferSlice> R, adnl::AdnlNodeIdShort dst);
|
||||
|
|
|
@ -170,8 +170,8 @@ TEST(Misc, TsList) {
|
|||
|
||||
TEST(Misc, TsListConcurrent) {
|
||||
td::TsList<ListData> root;
|
||||
td::vector<td::thread> threads;
|
||||
std::atomic<td::uint64> id{0};
|
||||
td::vector<td::thread> threads;
|
||||
for (std::size_t i = 0; i < 4; i++) {
|
||||
threads.emplace_back(
|
||||
[&] { do_run_list_test<td::TsListNode<ListData>, td::TsList<ListData>, td::TsListNode<ListData>>(root, id); });
|
||||
|
|
|
@ -34,6 +34,7 @@ int TD_TL_writer_hpp::get_additional_function_type(const std::string &additional
|
|||
std::vector<std::string> TD_TL_writer_hpp::get_additional_functions() const {
|
||||
std::vector<std::string> additional_functions;
|
||||
additional_functions.push_back("downcast_call");
|
||||
additional_functions.push_back("downcast_construct");
|
||||
return additional_functions;
|
||||
}
|
||||
|
||||
|
@ -202,24 +203,40 @@ std::string TD_TL_writer_hpp::gen_additional_proxy_function_begin(const std::str
|
|||
const tl::tl_type *type,
|
||||
const std::string &class_name, int arity,
|
||||
bool is_function) const {
|
||||
assert(function_name == "downcast_call");
|
||||
return "/**\n"
|
||||
" * Calls specified function object with the specified object downcasted to the most-derived type.\n"
|
||||
" * \\param[in] obj Object to pass as an argument to the function object.\n"
|
||||
" * \\param[in] func Function object to which the object will be passed.\n"
|
||||
" * \\returns whether function object call has happened. Should always return true for correct parameters.\n"
|
||||
" */\n"
|
||||
"template <class T>\n"
|
||||
"bool downcast_call(" +
|
||||
class_name +
|
||||
" &obj, const T &func) {\n"
|
||||
" switch (obj.get_id()) {\n";
|
||||
if (function_name == "downcast_call") {
|
||||
return "/**\n"
|
||||
" * Calls specified function object with the specified object downcasted to the most-derived type.\n"
|
||||
" * \\param[in] obj Object to pass as an argument to the function object.\n"
|
||||
" * \\param[in] func Function object to which the object will be passed.\n"
|
||||
" * \\returns whether function object call has happened. Should always return true for correct parameters.\n"
|
||||
" */\n"
|
||||
"template <class T>\n"
|
||||
"bool downcast_call(" +
|
||||
class_name +
|
||||
" &obj, const T &func) {\n"
|
||||
" switch (obj.get_id()) {\n";
|
||||
}
|
||||
if (function_name == "downcast_construct") {
|
||||
return "/**\n"
|
||||
"* Constructs tl_object_ptr with the object of the same type as the specified object, calls the specified "
|
||||
"function.\n"
|
||||
" * \\param[in] obj Object to get the type from.\n"
|
||||
" * \\param[in] func Function object to which the new object will be passed.\n"
|
||||
" * \\returns whether function object call has happened. Should always return true for correct parameters.\n"
|
||||
"*/"
|
||||
"template <class T>\n"
|
||||
"bool downcast_construct(" +
|
||||
class_name +
|
||||
" &obj, const T &func) {\n"
|
||||
"switch (obj.get_id()) {";
|
||||
}
|
||||
assert(false);
|
||||
}
|
||||
|
||||
std::string TD_TL_writer_hpp::gen_additional_proxy_function_case(const std::string &function_name,
|
||||
const tl::tl_type *type, const std::string &class_name,
|
||||
int arity) const {
|
||||
assert(function_name == "downcast_call");
|
||||
//assert(function_name == "downcast_call");
|
||||
assert(false);
|
||||
return "";
|
||||
}
|
||||
|
@ -227,18 +244,28 @@ std::string TD_TL_writer_hpp::gen_additional_proxy_function_case(const std::stri
|
|||
std::string TD_TL_writer_hpp::gen_additional_proxy_function_case(const std::string &function_name,
|
||||
const tl::tl_type *type, const tl::tl_combinator *t,
|
||||
int arity, bool is_function) const {
|
||||
assert(function_name == "downcast_call");
|
||||
return " case " + gen_class_name(t->name) +
|
||||
"::ID:\n"
|
||||
" func(static_cast<" +
|
||||
gen_class_name(t->name) +
|
||||
" &>(obj));\n"
|
||||
" return true;\n";
|
||||
if (function_name == "downcast_call") {
|
||||
return " case " + gen_class_name(t->name) +
|
||||
"::ID:\n"
|
||||
" func(static_cast<" +
|
||||
gen_class_name(t->name) +
|
||||
" &>(obj));\n"
|
||||
" return true;\n";
|
||||
}
|
||||
if (function_name == "downcast_construct") {
|
||||
return " case " + gen_class_name(t->name) +
|
||||
"::ID:\n"
|
||||
" func(create_tl_object<" +
|
||||
gen_class_name(t->name) +
|
||||
">());\n"
|
||||
" return true;\n";
|
||||
}
|
||||
assert(false);
|
||||
}
|
||||
|
||||
std::string TD_TL_writer_hpp::gen_additional_proxy_function_end(const std::string &function_name,
|
||||
const tl::tl_type *type, bool is_function) const {
|
||||
assert(function_name == "downcast_call");
|
||||
assert(function_name == "downcast_call" || function_name == "downcast_construct");
|
||||
return " default:\n"
|
||||
" return false;\n"
|
||||
" }\n"
|
||||
|
|
|
@ -277,8 +277,7 @@ std::enable_if_t<!std::is_constructible<T>::value, Status> from_json(ton::tl_obj
|
|||
|
||||
DowncastHelper<T> helper(constructor);
|
||||
Status status;
|
||||
bool ok = downcast_call(static_cast<T &>(helper), [&](auto &dummy) {
|
||||
auto result = ton::create_tl_object<std::decay_t<decltype(dummy)>>();
|
||||
bool ok = downcast_construct(static_cast<T &>(helper), [&](auto result) {
|
||||
status = from_json(*result, object);
|
||||
to = std::move(result);
|
||||
});
|
||||
|
|
|
@ -91,7 +91,7 @@ void CellDbIn::load_cell(RootHash hash, td::Promise<td::Ref<vm::DataCell>> promi
|
|||
}
|
||||
|
||||
void CellDbIn::store_cell(BlockIdExt block_id, td::Ref<vm::Cell> cell, td::Promise<td::Ref<vm::DataCell>> promise) {
|
||||
td::PerfWarningTimer{"storecell", 0.1};
|
||||
td::PerfWarningTimer timer{"storecell", 0.1};
|
||||
auto key_hash = get_key_hash(block_id);
|
||||
auto R = get_block(key_hash);
|
||||
// duplicate
|
||||
|
@ -194,7 +194,7 @@ void CellDbIn::gc_cont(BlockHandle handle) {
|
|||
}
|
||||
|
||||
void CellDbIn::gc_cont2(BlockHandle handle) {
|
||||
td::PerfWarningTimer{"gccell", 0.1};
|
||||
td::PerfWarningTimer timer{"gccell", 0.1};
|
||||
|
||||
auto FR = get_block(last_gc_);
|
||||
FR.ensure();
|
||||
|
|
|
@ -1050,9 +1050,9 @@ bool LiteQuery::make_state_root_proof(Ref<vm::Cell>& proof, Ref<vm::Cell> state_
|
|||
&& upd_cs.size_ext() == 0x20228)) {
|
||||
return fatal_error("invalid Merkle update in block");
|
||||
}
|
||||
auto upd_hash = upd_cs.prefetch_ref(1)->get_hash(0).bits();
|
||||
auto state_hash = state_root->get_hash().bits();
|
||||
if (upd_hash.compare(state_hash, 256)) {
|
||||
auto upd_hash = upd_cs.prefetch_ref(1)->get_hash(0);
|
||||
auto state_hash = state_root->get_hash();
|
||||
if (upd_hash != state_hash) {
|
||||
return fatal_error("cannot construct Merkle proof for given masterchain state because of hash mismatch");
|
||||
}
|
||||
if (!pb.extract_proof_to(proof)) {
|
||||
|
|
|
@ -67,11 +67,10 @@ void TokenManager::download_token_cleared(size_t download_size, td::uint32 prior
|
|||
}
|
||||
|
||||
void TokenManager::alarm() {
|
||||
for (auto it = pending_.begin(); it != pending_.end(); it++) {
|
||||
for (auto it = pending_.begin(); it != pending_.end();) {
|
||||
if (it->second.timeout.is_in_past()) {
|
||||
it->second.promise.set_error(td::Status::Error(ErrorCode::timeout, "timeout in wait download token"));
|
||||
auto it2 = it++;
|
||||
pending_.erase(it2);
|
||||
it = pending_.erase(it);
|
||||
} else {
|
||||
it++;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue