mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
updated fift + bugfixes
This commit is contained in:
parent
090e0c16eb
commit
ceaed40ac4
28 changed files with 530 additions and 108 deletions
|
@ -71,6 +71,7 @@ IntCtx::Savepoint::Savepoint(IntCtx& _ctx, std::string new_filename, std::string
|
|||
std::istream* new_input_stream)
|
||||
: ctx(_ctx)
|
||||
, old_line_no(_ctx.line_no)
|
||||
, old_need_line(_ctx.need_line)
|
||||
, old_filename(_ctx.filename)
|
||||
, old_current_dir(_ctx.currentd_dir)
|
||||
, old_input_stream(_ctx.input_stream)
|
||||
|
@ -87,6 +88,7 @@ IntCtx::Savepoint::Savepoint(IntCtx& _ctx, std::string new_filename, std::string
|
|||
|
||||
IntCtx::Savepoint::~Savepoint() {
|
||||
ctx.line_no = old_line_no;
|
||||
ctx.need_line = old_need_line;
|
||||
ctx.filename = old_filename;
|
||||
ctx.currentd_dir = old_current_dir;
|
||||
ctx.input_stream = old_input_stream;
|
||||
|
@ -99,6 +101,7 @@ bool IntCtx::load_next_line() {
|
|||
if (!std::getline(*input_stream, str)) {
|
||||
return false;
|
||||
}
|
||||
need_line = false;
|
||||
if (!str.empty() && str.back() == '\r') {
|
||||
str.pop_back();
|
||||
}
|
||||
|
@ -111,6 +114,7 @@ bool IntCtx::is_sb() const {
|
|||
}
|
||||
|
||||
td::Slice IntCtx::scan_word_to(char delim, bool err_endl) {
|
||||
load_next_line_ifreq();
|
||||
auto ptr = input_ptr;
|
||||
while (*ptr && *ptr != delim) {
|
||||
ptr++;
|
||||
|
@ -121,6 +125,7 @@ td::Slice IntCtx::scan_word_to(char delim, bool err_endl) {
|
|||
} else if (err_endl && delim) {
|
||||
throw IntError{std::string{"end delimiter `"} + delim + "` not found"};
|
||||
} else {
|
||||
need_line = true;
|
||||
std::swap(ptr, input_ptr);
|
||||
return td::Slice{ptr, input_ptr};
|
||||
}
|
||||
|
|
|
@ -68,6 +68,7 @@ struct IntCtx {
|
|||
int state{0};
|
||||
int include_depth{0};
|
||||
int line_no{0};
|
||||
bool need_line{true};
|
||||
std::string filename;
|
||||
std::string currentd_dir;
|
||||
std::istream* input_stream{nullptr};
|
||||
|
@ -116,6 +117,9 @@ struct IntCtx {
|
|||
}
|
||||
|
||||
bool load_next_line();
|
||||
bool load_next_line_ifreq() {
|
||||
return need_line && load_next_line();
|
||||
}
|
||||
|
||||
bool is_sb() const;
|
||||
|
||||
|
@ -126,6 +130,7 @@ struct IntCtx {
|
|||
class Savepoint {
|
||||
IntCtx& ctx;
|
||||
int old_line_no;
|
||||
bool old_need_line;
|
||||
std::string old_filename;
|
||||
std::string old_current_dir;
|
||||
std::istream* old_input_stream;
|
||||
|
|
|
@ -112,3 +112,7 @@ variable base
|
|||
{ bl word atom 1 'nop } ::_ `
|
||||
{ hole dup 1 { @ execute } does create } : recursive
|
||||
{ 0 { 1+ dup 1 ' $() does over (.) "$" swap $+ 0 (create) } rot times drop } : :$1..n
|
||||
{ 10 hold } : +cr
|
||||
{ 9 hold } : +tab
|
||||
{ "" swap { 0 word 2dup $cmp } { rot swap $+ +cr swap } while 2drop } : scan-until-word
|
||||
{ 0 word -trailing scan-until-word 1 'nop } ::_ $<<
|
||||
|
|
|
@ -33,12 +33,16 @@ recursive list-delete-range {
|
|||
} : list-find-opt
|
||||
// ( -- s i or 0 ) finds first option in cmdline args
|
||||
{ $* @ list-find-opt } : first-opt
|
||||
// ( s t -- ? ) checks whether short/long option s matches description t
|
||||
{ third $= } : short-option-matches
|
||||
' second : get-opt-flags
|
||||
' first : get-opt-exec
|
||||
// ( s t -- ? ) checks whether short/long option s matches description t
|
||||
{ third $= } : short-option-matches
|
||||
{ dup get-opt-flags 4 and 0= 3 + [] $=
|
||||
} : long-option-matches
|
||||
// ( t -- s -1 or 0 ) extracts help message from description
|
||||
{ dup get-opt-flags 4 and 0= 4 + over count over >
|
||||
{ [] true } { 2drop false } cond
|
||||
} : get-opt-help
|
||||
// ( s l -- t -1 or 0 ) finds short/long option s in list l
|
||||
{ swap 1 { swap short-option-matches } does assoc-gen
|
||||
} : lookup-short-option
|
||||
|
@ -47,37 +51,57 @@ recursive list-delete-range {
|
|||
// ( s -- s' null or s' s'' ) Splits long option --opt=arg at '='
|
||||
{ dup "=" $pos 1+ ?dup { tuck $| swap rot 1- $| drop swap } { null } cond
|
||||
} : split-longopt
|
||||
variable options-list
|
||||
// ( l -- i or 0 )
|
||||
// parses command line arguments according to option description list l
|
||||
// and returns index i of first incorrect option
|
||||
{ { first-opt dup 0= { true } {
|
||||
swap dup "--" $pfx? { // l i s
|
||||
{ options-list !
|
||||
{ first-opt dup 0= { true } {
|
||||
swap dup "--" $pfx? { // i s
|
||||
dup $len 2 = { drop dup 1 $*del.. 0 true } {
|
||||
split-longopt swap 3 pick
|
||||
lookup-long-option not { drop true } { // l i s' t f
|
||||
dup get-opt-exec swap get-opt-flags 3 and // l i s' e f'
|
||||
2 pick null? { dup 1 = } { dup 0= negate } cond // l i s' e f' f''
|
||||
split-longopt swap options-list @
|
||||
lookup-long-option not { drop true } { // i s' t f
|
||||
dup get-opt-exec swap get-opt-flags 3 and // i s' e f'
|
||||
2 pick null? { dup 1 = } { dup 0= negate } cond // i s' e f' f''
|
||||
dup 1 = { 2drop 2drop true } {
|
||||
{ drop nip over 1+ $() swap execute 2 $*del.. false } {
|
||||
' nip ifnot execute 1 $*del.. false
|
||||
} cond } cond } cond } cond } { // l i s
|
||||
} cond } cond } cond } cond } { // i s
|
||||
1 $| nip {
|
||||
dup $len 0= { drop 1 $*del.. false true } {
|
||||
1 $| swap 3 pick // l i s' s l
|
||||
lookup-short-option not { drop true true } { // l i s' t
|
||||
dup get-opt-exec swap get-opt-flags 3 and // l i s' e f'
|
||||
1 $| swap options-list @ // i s' s l
|
||||
lookup-short-option not { drop true true } { // i s' t
|
||||
dup get-opt-exec swap get-opt-flags 3 and // i s' e f'
|
||||
?dup 0= { execute false } {
|
||||
2 pick $len { drop execute "" false } {
|
||||
2 = { nip null swap execute "" false } { // l i e
|
||||
2 = { nip null swap execute "" false } { // i e
|
||||
nip over 1+ $() swap execute 2 $*del.. false true
|
||||
} cond } cond } cond } cond } cond } until
|
||||
} cond
|
||||
} cond } until nip
|
||||
} cond } until
|
||||
} : getopt
|
||||
// ( t -- ) Displays help message for one option
|
||||
{ dup get-opt-flags dup 4 and 2 pick third swap {
|
||||
."-" type ."/" over 3 [] type } {
|
||||
dup $len { dup "--" $pfx? { ."-" } ifnot type } {
|
||||
drop ."usage: " $0 type
|
||||
} cond } cond
|
||||
dup 3 and ?dup {
|
||||
2 = { ."[=<optarg>]" } { ."=<optarg>" } cond
|
||||
} if
|
||||
8 and { 9 emit } ifnot
|
||||
get-opt-help { type } { ."No help available" } cond cr
|
||||
} : show-opt-help
|
||||
// ( -- ) Displays options help message according to options-list
|
||||
{ options-list @ { dup null? not } {
|
||||
uncons swap show-opt-help
|
||||
} while drop
|
||||
} : show-options-help
|
||||
// ( l -- ) Parses options and throws an error on failure
|
||||
{ getopt ?dup { $() "cannot parse command line options near `" swap $+ +"`" abort } if
|
||||
{ getopt ?dup {
|
||||
$() "cannot parse command line options near `" swap $+ +"`"
|
||||
show-options-help abort } if
|
||||
} : run-getopt
|
||||
|
||||
anon constant opt-list-marker
|
||||
' opt-list-marker : begin-options
|
||||
{ opt-list-marker list-until-marker } : end-options
|
||||
|
@ -90,3 +114,7 @@ anon constant opt-list-marker
|
|||
{ 2 rot triple } dup : short-option-?arg : long-option-?arg
|
||||
{ 5 2swap 4 tuple } : short-long-option-arg
|
||||
{ 6 2swap 4 tuple } : short-long-option-?arg
|
||||
// ( o s -- s' ) Adds help message to option
|
||||
' , : option-help
|
||||
// ( s -- o ) Creates a generic help message
|
||||
{ 'nop 8 "" 3 roll 4 tuple } : generic-help
|
||||
|
|
|
@ -12,6 +12,8 @@ library TonUtil // TON Blockchain Fift Library
|
|||
|
||||
{ (number) 1- abort"integer expected" } : parse-int
|
||||
|
||||
{ over null? ' swap if drop } : replace-if-null
|
||||
|
||||
// Private key load/generate
|
||||
// ( fname -- pubkey privkey )
|
||||
{ dup ."Loading private key from file " type cr
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue