Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite6762f9

Browse files
committed
Advance immediately upon evaluating a character
1 parent099bb1a commite6762f9

File tree

3 files changed

+41
-27
lines changed

3 files changed

+41
-27
lines changed

‎src/generic/stage2/logger.h

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ namespace logger {
77
staticconstexprconstchar * DASHES ="----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------";
88

99
staticconstexprconstbool LOG_ENABLED =false;
10-
staticconstexprconstint LOG_EVENT_LEN =30;
11-
staticconstexprconstint LOG_BUFFER_LEN =20;
12-
staticconstexprconstintLOG_DETAIL_LEN =50;
13-
staticconstexprconstint LOG_INDEX_LEN =10;
10+
staticconstexprconstint LOG_EVENT_LEN =20;
11+
staticconstexprconstint LOG_BUFFER_LEN =10;
12+
staticconstexprconstintLOG_SMALL_BUFFER_LEN =10;
13+
staticconstexprconstint LOG_INDEX_LEN =5;
1414

1515
staticint log_depth;// Not threadsafe. Log only.
1616

@@ -28,8 +28,8 @@ namespace logger {
2828
if (LOG_ENABLED) {
2929
log_depth =0;
3030
printf("\n");
31-
printf("| %-*s | %-*s | %*s | %*s | %*s | %-*s | %-*s |%-*s |\n", LOG_EVENT_LEN,"Event", LOG_BUFFER_LEN,"Buffer",4,"Curr",4,"Next",5,"Next#",5,"Tape#", LOG_DETAIL_LEN,"Detail", LOG_INDEX_LEN,"index");
32-
printf("|%.*s|%.*s|%.*s|%.*s|%.*s|%.*s|%.*s|%.*s|\n", LOG_EVENT_LEN+2, DASHES, LOG_BUFFER_LEN+2, DASHES,4+2, DASHES,4+2, DASHES,5+2, DASHES,5+2, DASHES, LOG_DETAIL_LEN+2, DASHES, LOG_INDEX_LEN+2, DASHES);
31+
printf("| %-*s | %-*s | %-*s | %-*s | %-*s |Detail |\n", LOG_EVENT_LEN,"Event", LOG_BUFFER_LEN,"Buffer",LOG_SMALL_BUFFER_LEN,"Next",5,"Next#",5,"Tape#");
32+
printf("|%.*s|%.*s|%.*s|%.*s|%.*s|--------|\n", LOG_EVENT_LEN+2, DASHES, LOG_BUFFER_LEN+2, DASHES,LOG_SMALL_BUFFER_LEN+2, DASHES,5+2, DASHES,5+2, DASHES);
3333
}
3434
}
3535

@@ -44,22 +44,35 @@ namespace logger {
4444
static really_inlinevoidlog_line(S &structurals,constchar *title_prefix,constchar *title,constchar *detail) {
4545
if (LOG_ENABLED) {
4646
printf("| %*s%s%-*s", log_depth*2,"", title_prefix, LOG_EVENT_LEN - log_depth*2 -int(strlen(title_prefix)), title);
47+
auto current_index = structurals.at_beginning() ?nullptr : structurals.next_structural-1;
48+
auto next_index = structurals.next_structural;
49+
auto current = current_index ? &structurals.buf[*current_index] : (constuint8_t*)"";
50+
auto next = &structurals.buf[*next_index];
4751
{
4852
// Print the next N characters in the buffer.
4953
printf("|");
5054
// Otherwise, print the characters starting from the buffer position.
5155
// Print spaces for unprintable or newline characters.
5256
for (int i=0;i<LOG_BUFFER_LEN;i++) {
53-
printf("%c",printable_char(structurals.current()[i]));
57+
printf("%c",printable_char(current[i]));
5458
}
5559
printf("");
60+
// Print the next N characters in the buffer.
61+
printf("|");
62+
// Otherwise, print the characters starting from the buffer position.
63+
// Print spaces for unprintable or newline characters.
64+
for (int i=0;i<LOG_SMALL_BUFFER_LEN;i++) {
65+
printf("%c",printable_char(next[i]));
66+
}
67+
printf("");
68+
}
69+
if (current_index) {
70+
printf("| %*u", LOG_INDEX_LEN, *current_index);
71+
}else {
72+
printf("| %-*s", LOG_INDEX_LEN,"");
5673
}
57-
printf("| %c",printable_char(structurals.current_char()));
58-
printf("| %c",printable_char(structurals.peek_next_char()));
59-
printf("| %5u", structurals.parser.structural_indexes[*(structurals.current_structural+1)]);
60-
printf("| %5u", structurals.next_tape_index());
61-
printf("| %-*s", LOG_DETAIL_LEN, detail);
62-
printf("| %*u", LOG_INDEX_LEN, *structurals.current_structural);
74+
printf("| %*u", LOG_INDEX_LEN, structurals.next_tape_index());
75+
printf("| %-s", detail);
6376
printf("|\n");
6477
}
6578
}

‎src/generic/stage2/structural_iterator.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,45 @@ namespace stage2 {
55
classstructural_iterator {
66
public:
77
constuint8_t*const buf;
8-
uint32_t *current_structural;
8+
uint32_t *next_structural;
99
dom_parser_implementation &parser;
1010

1111
// Start a structural
1212
really_inlinestructural_iterator(dom_parser_implementation &_parser,size_t start_structural_index)
1313
: buf{_parser.buf},
14-
current_structural{&_parser.structural_indexes[start_structural_index]},
14+
next_structural{&_parser.structural_indexes[start_structural_index]},
1515
parser{_parser} {
1616
}
1717
// Get the buffer position of the current structural character
1818
really_inlineconstuint8_t*current() {
19-
return &buf[*current_structural];
19+
return &buf[*(next_structural-1)];
2020
}
2121
// Get the current structural character
2222
really_inlinecharcurrent_char() {
23-
return buf[*current_structural];
23+
return buf[*(next_structural-1)];
2424
}
2525
// Get the next structural character without advancing
2626
really_inlinecharpeek_next_char() {
27-
return buf[*(current_structural+1)];
27+
return buf[*next_structural];
28+
}
29+
really_inlineconstuint8_t*peek() {
30+
return &buf[*next_structural];
2831
}
2932
really_inlineconstuint8_t*advance() {
30-
current_structural++;
31-
return &buf[*current_structural];
33+
return &buf[*(next_structural++)];
3234
}
3335
really_inlinecharadvance_char() {
34-
current_structural++;
35-
return buf[*current_structural];
36+
return buf[*(next_structural++)];
3637
}
3738
really_inlinesize_tremaining_len() {
38-
return parser.len - *current_structural;
39+
return parser.len - *(next_structural-1);
3940
}
4041

4142
really_inlineboolat_end() {
42-
returncurrent_structural == &parser.structural_indexes[parser.n_structural_indexes];
43+
returnnext_structural == &parser.structural_indexes[parser.n_structural_indexes];
4344
}
4445
really_inlineboolat_beginning() {
45-
returncurrent_structural == parser.structural_indexes.get();
46+
returnnext_structural == parser.structural_indexes.get();
4647
}
4748
};
4849

‎src/generic/stage2/structural_parser.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ struct structural_parser : structural_iterator {
238238

239239
WARN_UNUSED really_inline error_codefinish() {
240240
end_document();
241-
parser.next_structural_index =uint32_t(current_structural +1 - &parser.structural_indexes[0]);
241+
parser.next_structural_index =uint32_t(next_structural - &parser.structural_indexes[0]);
242242

243243
if (depth !=0) {
244244
log_error("Unclosed objects or arrays!");
@@ -279,7 +279,7 @@ WARN_UNUSED static really_inline error_code parse_structurals(dom_parser_impleme
279279
// Read first value
280280
//
281281
{
282-
switch (parser.current_char()) {
282+
switch (parser.advance_char()) {
283283
case'{': {
284284
if (parser.empty_object()) {goto document_end; }
285285
SIMDJSON_TRY( parser.start_object() );

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp