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

updated func/fift

- updated func/fift
- updated liteclient/liteserver
- bugfixes
This commit is contained in:
ton 2019-12-29 12:14:12 +03:00
parent d41ce55305
commit acf16718e6
45 changed files with 1360 additions and 185 deletions

View file

@ -633,6 +633,88 @@ void init_words_custom(fift::Dictionary& d) {
d.def_stack_word("isWorkchainDescr? ", interpret_is_workchain_descr);
}
tlb::TypenameLookup tlb_dict;
// ( S -- T -1 or 0 ) Looks up TLB type by name
void interpret_tlb_type_lookup(vm::Stack& stack) {
auto ptr = tlb_dict.lookup(stack.pop_string());
if (ptr) {
stack.push_make_object<tlb::TlbTypeHolder>(ptr);
}
stack.push_bool(ptr);
}
td::Ref<tlb::TlbTypeHolder> pop_tlb_type(vm::Stack& stack) {
auto res = stack.pop_object<tlb::TlbTypeHolder>();
if (res.is_null()) {
throw vm::VmError{vm::Excno::type_chk, "not a TLB type"};
}
return res;
}
// ( T -- S ) Gets TLB type name
void interpret_tlb_type_name(vm::Stack& stack) {
stack.push_string((*pop_tlb_type(stack))->get_type_name());
}
// ( T -- ) Prints TLB type name
void interpret_print_tlb_type(vm::Stack& stack) {
std::cout << (*pop_tlb_type(stack))->get_type_name();
}
// ( s T -- ) Dumps (part of) slice s as a value of TLB type T
void interpret_tlb_dump_as(vm::Stack& stack) {
auto tp = pop_tlb_type(stack);
(*tp)->print(std::cout, stack.pop_cellslice());
}
// ( s T -- s' S -1 or 0 )
// Detects prefix of slice s that is a value of TLB type T, returns the remainder as s', and prints the value into String S.
void interpret_tlb_dump_to_str(vm::Stack& stack) {
auto tp = pop_tlb_type(stack);
auto cs = stack.pop_cellslice();
std::ostringstream os;
bool ok = (*tp)->print_skip(os, cs.write());
if (ok) {
stack.push(std::move(cs));
stack.push_string(os.str());
}
stack.push_bool(ok);
}
// ( s T -- s' -1 or 0 ) Skips the only prefix of slice s that can be a value of TLB type T
void interpret_tlb_skip(vm::Stack& stack) {
auto tp = pop_tlb_type(stack);
auto cs = stack.pop_cellslice();
bool ok = (*tp)->skip(cs.write());
if (ok) {
stack.push(std::move(cs));
}
stack.push_bool(ok);
}
// ( s T -- s' -1 or 0 ) Checks whether a prefix of slice s is a valid value of TLB type T, and skips it
void interpret_tlb_validate_skip(vm::Stack& stack) {
auto tp = pop_tlb_type(stack);
auto cs = stack.pop_cellslice();
bool ok = (*tp)->validate_skip(cs.write());
if (ok) {
stack.push(std::move(cs));
}
stack.push_bool(ok);
}
void init_words_tlb(fift::Dictionary& d) {
tlb_dict.register_types(block::gen::register_simple_types);
d.def_stack_word("tlb-type-lookup ", interpret_tlb_type_lookup);
d.def_stack_word("tlb-type-name ", interpret_tlb_type_name);
d.def_stack_word("tlb. ", interpret_print_tlb_type);
d.def_stack_word("tlb-dump-as ", interpret_tlb_dump_as);
d.def_stack_word("(tlb-dump-str?) ", interpret_tlb_dump_to_str);
d.def_stack_word("tlb-skip ", interpret_tlb_skip);
d.def_stack_word("tlb-validate-skip ", interpret_tlb_validate_skip);
}
void usage(const char* progname) {
std::cerr
<< "Creates initial state for a TON blockchain, using configuration defined by Fift-language source files\n";
@ -739,6 +821,7 @@ int main(int argc, char* const argv[]) {
fift::init_words_vm(config.dictionary);
fift::init_words_ton(config.dictionary);
init_words_custom(config.dictionary);
init_words_tlb(config.dictionary);
if (script_mode) {
fift::import_cmdline_args(config.dictionary, source_list.empty() ? "" : source_list[0], argc - optind,