Add a "while.goto_foo true { etc }" to std/json

This commit is contained in:
Nigel Tao committed 2020-02-21 11:42:33 +11:00
1 parent c92c0f50e4
commit 93b09674a9
2 files changed
+125 -61

No files matched your search

+29 -20
View File
@@ -18584,6 +18584,7 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
v_expect = 3;
label_0_continue:;
while (true) {
while (true) {
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
@@ -18605,7 +18606,8 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
status = wuffs_base__make_status(wuffs_json__error__bad_input);
goto exit;
}
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
status =
wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
v_whitespace_length = 0;
goto label_0_continue;
@@ -18657,8 +18659,8 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
label_2_continue:;
while (true) {
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
status =
wuffs_base__make_status(wuffs_base__suspension__short_write);
status = wuffs_base__make_status(
wuffs_base__suspension__short_write);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3);
goto label_2_continue;
}
@@ -18678,8 +18680,8 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
wuffs_base__make_status(wuffs_json__error__bad_input);
goto exit;
}
status =
wuffs_base__make_status(wuffs_base__suspension__short_read);
status = wuffs_base__make_status(
wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4);
v_string_length = 0;
goto label_2_continue;
@@ -18709,13 +18711,16 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
goto exit;
}
} else if (v_c == 92) {
status = wuffs_base__make_status(wuffs_json__error__bad_input);
status =
wuffs_base__make_status(wuffs_json__error__bad_input);
goto exit;
}
if (v_string_length >= 65534) {
*iop_a_dst++ = wuffs_base__make_token(
(((uint64_t)(6291457)) << WUFFS_BASE__TOKEN__VALUE__SHIFT) |
(((uint64_t)(65535)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
(((uint64_t)(6291457))
<< WUFFS_BASE__TOKEN__VALUE__SHIFT) |
(((uint64_t)(65535))
<< WUFFS_BASE__TOKEN__LENGTH__SHIFT));
v_string_length = 0;
goto label_2_continue;
}
@@ -18739,6 +18744,7 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
v_expect = 8;
goto label_0_continue;
}
goto label_4_break;
} else if (v_c == 44) {
if (0 == (v_expect & 4)) {
status = wuffs_base__make_status(wuffs_json__error__bad_input);
@@ -18779,7 +18785,7 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
<< WUFFS_BASE__TOKEN__VALUE__SHIFT) |
(((uint64_t)(((uint64_t)(v_number_length))))
<< WUFFS_BASE__TOKEN__LENGTH__SHIFT));
goto label_4_break;
goto label_5_break;
}
while (v_number_length > 0) {
v_number_length -= 1;
@@ -18809,10 +18815,8 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
}
}
}
label_4_break:;
} else {
status = wuffs_base__make_status(wuffs_json__error__bad_input);
goto exit;
label_5_break:;
goto label_4_break;
}
} else if (v_c == 58) {
if (0 == (v_expect & 8)) {
@@ -18936,8 +18940,8 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
}
v_match = 2;
if (v_c == 110) {
v_match =
wuffs_base__io_reader__match7(iop_a_src, io2_a_src, 465676103172);
v_match = wuffs_base__io_reader__match7(iop_a_src, io2_a_src,
465676103172);
if (v_match == 0) {
*iop_a_dst++ = wuffs_base__make_token(
(((uint64_t)(4194337)) << WUFFS_BASE__TOKEN__VALUE__SHIFT) |
@@ -18948,6 +18952,7 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
goto exit;
}
(iop_a_src += 4, wuffs_base__make_empty_struct());
goto label_4_break;
}
} else if (v_c == 102) {
v_match = wuffs_base__io_reader__match7(iop_a_src, io2_a_src,
@@ -18962,10 +18967,11 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
goto exit;
}
(iop_a_src += 5, wuffs_base__make_empty_struct());
goto label_4_break;
}
} else if (v_c == 116) {
v_match =
wuffs_base__io_reader__match7(iop_a_src, io2_a_src, 435762131972);
v_match = wuffs_base__io_reader__match7(iop_a_src, io2_a_src,
435762131972);
if (v_match == 0) {
*iop_a_dst++ = wuffs_base__make_token(
(((uint64_t)(4194433)) << WUFFS_BASE__TOKEN__VALUE__SHIFT) |
@@ -18976,17 +18982,20 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
goto exit;
}
(iop_a_src += 4, wuffs_base__make_empty_struct());
goto label_4_break;
}
}
if (v_match == 1) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
status =
wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8);
goto label_0_continue;
} else if (v_match == 2) {
}
}
status = wuffs_base__make_status(wuffs_json__error__bad_input);
goto exit;
}
}
label_4_break:;
if (v_depth == 0) {
goto label_0_break;
}
+96 -41
View File
@@ -89,6 +89,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
expect = 0x03 // EXPECT_VALUE
while.outer true {
while.goto_parsed_a_leaf_value true {
if args.dst.available() <= 0 {
yield? base."$short write"
continue.outer
@@ -103,7 +104,9 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
{
if args.src.available() <= 0 {
if whitespace_length > 0 {
args.dst.write_fast_token!(value: 0, length: whitespace_length as base.u64)
args.dst.write_fast_token!(
value: 0,
length: whitespace_length as base.u64)
whitespace_length = 0
}
if args.src.is_closed() {
@@ -119,14 +122,18 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
break.ws
} else if (c <> 0x20) and (c <> 0x0A) and (c <> 0x09) and (c <> 0x0D) {
if whitespace_length > 0 {
args.dst.write_fast_token!(value: 0, length: whitespace_length as base.u64)
args.dst.write_fast_token!(
value: 0,
length: whitespace_length as base.u64)
}
return "#bad input"
}
args.src.skip32_fast!(actual: 1, worst_case: 1)
if whitespace_length >= 0xFFFE {
args.dst.write_fast_token!(value: 0, length: 0xFFFF)
args.dst.write_fast_token!(
value: 0,
length: 0xFFFF)
whitespace_length = 0
continue.outer
}
@@ -135,17 +142,19 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
// Emit whitespace.
if whitespace_length > 0 {
args.dst.write_fast_token!(value: 0, length: whitespace_length as base.u64)
args.dst.write_fast_token!(
value: 0,
length: whitespace_length as base.u64)
whitespace_length = 0
if args.dst.available() <= 0 {
continue.outer
}
}
// These assertions are redundant (the Wuffs compiler should already
// know these facts; deleting these assertions should still compile)
// but are listed explicitly to help guard against future edits to the
// code above inadvertently invalidating these assertions.
// These assertions are redundant (the Wuffs compiler should
// already know these facts; deleting these assertions should still
// compile) but are listed explicitly to guard against future edits
// to the code above inadvertently invalidating these assertions.
assert args.dst.available() > 0
assert args.src.available() > 0
@@ -157,7 +166,9 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
}
// The leading '"' is filler.
args.dst.write_fast_token!(value: 0, length: 1)
args.dst.write_fast_token!(
value: 0,
length: 1)
args.src.skip32_fast!(actual: 1, worst_case: 1)
while.string_loop true {
@@ -172,7 +183,9 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
{
if args.src.available() <= 0 {
if string_length > 0 {
args.dst.write_fast_token!(value: 0x60_0001, length: string_length as base.u64)
args.dst.write_fast_token!(
value: 0x60_0001,
length: string_length as base.u64)
string_length = 0
}
if args.src.is_closed() {
@@ -187,13 +200,17 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
if c <= 0x22 { // 0x22 is '"'.
if c == 0x22 { // 0x22 is '"'.
args.dst.write_fast_token!(value: 0x60_0000, length: string_length as base.u64)
args.dst.write_fast_token!(
value: 0x60_0000,
length: string_length as base.u64)
string_length = 0
break.string_loop
} else if c < 0x20 { // 0x20 is ' '.
if string_length > 0 {
args.dst.write_fast_token!(value: 0x60_0001, length: string_length as base.u64)
args.dst.write_fast_token!(
value: 0x60_0001,
length: string_length as base.u64)
string_length = 0
}
return "#bad input"
@@ -206,7 +223,9 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
}
if string_length >= 0xFFFE {
args.dst.write_fast_token!(value: 0x60_0001, length: 0xFFFF)
args.dst.write_fast_token!(
value: 0x60_0001,
length: 0xFFFF)
string_length = 0
continue.string_loop
}
@@ -217,20 +236,23 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
// The trailing '"' is filler.
while true {
if args.dst.available() > 0 {
args.dst.write_fast_token!(value: 0, length: 1)
args.dst.write_fast_token!(
value: 0,
length: 1)
break
}
yield? base."$short write"
}
// As above, expect must have contained EXPECT_STRING_VALUE. If
// it didn't also contain EXPECT_NON_STRING_VALUE then we were
// parsing an object key and the next token should be ':'.
// Otherwise, fall below to "We've just parsed a value".
// As above, expect must have contained
// EXPECT_STRING_VALUE. If it didn't also contain
// EXPECT_NON_STRING_VALUE then we were parsing an object
// key and the next token should be ':'.
if 0 == (expect & 0x01) { // 0x01 is EXPECT_NON_STRING_VALUE.
expect = 0x08 // 0x08 is EXPECT_COLON.
continue.outer
}
break.goto_parsed_a_leaf_value
// -------- END parse strings.
} else if c == 0x2C { // 0x2C is ','.
@@ -238,9 +260,12 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
return "#bad input"
}
args.src.skip32_fast!(actual: 1, worst_case: 1)
args.dst.write_fast_token!(value: 0, length: 1) // The ',' is filler.
// What's valid after a comma depends on whether or not we're
// in an array or an object.
// The ',' is filler.
args.dst.write_fast_token!(
value: 0,
length: 1)
// What's valid after a comma depends on whether or not
// we're in an array or an object.
if 0 == (expect & 0x10) { // 0x10 is EXPECT_CLOSE_BRACKET
expect = 0x02 // 0x02 is EXPECT_STRING_VALUE.
} else {
@@ -264,7 +289,9 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
}
number_length = number_length & 0x7F
if number_status == 0 {
args.dst.write_fast_token!(value: token_value, length: number_length as base.u64)
args.dst.write_fast_token!(
value: token_value,
length: number_length as base.u64)
break
}
@@ -290,10 +317,8 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
}
}
}
break.goto_parsed_a_leaf_value
// -------- END parse numbers.
} else {
return "#bad input"
}
} else if c == 0x3A { // 0x3A is ':'.
@@ -301,7 +326,10 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
return "#bad input"
}
args.src.skip32_fast!(actual: 1, worst_case: 1)
args.dst.write_fast_token!(value: 0, length: 1) // The ':' is filler.
// The ':' is filler.
args.dst.write_fast_token!(
value: 0,
length: 1)
expect = 0x03 // 0x03 is EXPECT_VALUE.
continue.outer
@@ -318,7 +346,9 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
depth += 1
args.src.skip32_fast!(actual: 1, worst_case: 1)
args.dst.write_fast_token!(value: 0x20_0011, length: 1)
args.dst.write_fast_token!(
value: 0x20_0011,
length: 1)
expect = 0x13 // 0x13 is (EXPECT_CLOSE_BRACKET | EXPECT_VALUE).
expect_after_value = 0x14 // 0x14 is (EXPECT_CLOSE_BRACKET | EXPECT_COMMA).
continue.outer
@@ -329,19 +359,25 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
}
args.src.skip32_fast!(actual: 1, worst_case: 1)
if depth <= 1 {
args.dst.write_fast_token!(value: 0x20_0012, length: 1)
args.dst.write_fast_token!(
value: 0x20_0012,
length: 1)
break.outer
}
depth -= 1
stack_byte = (depth - 1) / 32
stack_bit = (depth - 1) & 31
if 0 == (this.stack[stack_byte] & ((1 as base.u32) << stack_bit)) {
args.dst.write_fast_token!(value: 0x20_1012, length: 1)
args.dst.write_fast_token!(
value: 0x20_1012,
length: 1)
// 0x14 is (EXPECT_CLOSE_BRACKET | EXPECT_COMMA).
expect = 0x14
expect_after_value = 0x14
} else {
args.dst.write_fast_token!(value: 0x20_2012, length: 1)
args.dst.write_fast_token!(
value: 0x20_2012,
length: 1)
// 0x24 is (EXPECT_CLOSE_BRACE | EXPECT_COMMA).
expect = 0x24
expect_after_value = 0x24
@@ -361,7 +397,9 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
depth += 1
args.src.skip32_fast!(actual: 1, worst_case: 1)
args.dst.write_fast_token!(value: 0x20_0021, length: 1)
args.dst.write_fast_token!(
value: 0x20_0021,
length: 1)
expect = 0x22 // 0x22 is (EXPECT_CLOSE_BRACE | EXPECT_STRING_VALUE).
expect_after_value = 0x24 // 0x24 is (EXPECT_CLOSE_BRACE | EXPECT_COMMA).
continue.outer
@@ -372,19 +410,25 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
}
args.src.skip32_fast!(actual: 1, worst_case: 1)
if depth <= 1 {
args.dst.write_fast_token!(value: 0x20_0022, length: 1)
args.dst.write_fast_token!(
value: 0x20_0022,
length: 1)
break.outer
}
depth -= 1
stack_byte = (depth - 1) / 32
stack_bit = (depth - 1) & 31
if 0 == (this.stack[stack_byte] & ((1 as base.u32) << stack_bit)) {
args.dst.write_fast_token!(value: 0x20_1022, length: 1)
args.dst.write_fast_token!(
value: 0x20_1022,
length: 1)
// 0x14 is (EXPECT_CLOSE_BRACKET | EXPECT_COMMA).
expect = 0x14
expect_after_value = 0x14
} else {
args.dst.write_fast_token!(value: 0x20_2022, length: 1)
args.dst.write_fast_token!(
value: 0x20_2022,
length: 1)
// 0x24 is (EXPECT_CLOSE_BRACE | EXPECT_COMMA).
expect = 0x24
expect_after_value = 0x24
@@ -399,31 +443,40 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
if c == 0x6E { // 0x6E is 'n'.
match = args.src.match7(a: 0x6C_6C75_6E04) // 4 bytes "null".
if match == 0 {
args.dst.write_fast_token!(value: 0x40_0021, length: 4)
args.dst.write_fast_token!(
value: 0x40_0021,
length: 4)
if args.src.available() < 4 {
return "#internal error: inconsistent I/O"
}
args.src.skip32_fast!(actual: 4, worst_case: 4)
break.goto_parsed_a_leaf_value
}
} else if c == 0x66 { // 0x66 is 'f'.
match = args.src.match7(a: 0x6573_6C61_6605) // 5 bytes "false".
if match == 0 {
args.dst.write_fast_token!(value: 0x40_0041, length: 5)
args.dst.write_fast_token!(
value: 0x40_0041,
length: 5)
if args.src.available() < 5 {
return "#internal error: inconsistent I/O"
}
args.src.skip32_fast!(actual: 5, worst_case: 5)
break.goto_parsed_a_leaf_value
}
} else if c == 0x74 { // 0x74 is 't'.
match = args.src.match7(a: 0x65_7572_7404) // 4 bytes "true".
if match == 0 {
args.dst.write_fast_token!(value: 0x40_0081, length: 4)
args.dst.write_fast_token!(
value: 0x40_0081,
length: 4)
if args.src.available() < 4 {
return "#internal error: inconsistent I/O"
}
args.src.skip32_fast!(actual: 4, worst_case: 4)
break.goto_parsed_a_leaf_value
}
}
@@ -431,17 +484,19 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
if match == 1 {
yield? base."$short read"
continue.outer
} else if match == 2 {
return "#bad input"
}
}
// We've just parsed a value.
return "#bad input"
} // while.goto_parsed_a_leaf_value
// We've just parsed a leaf (non-container) value: literal (null,
// false, true), number or string.
if depth == 0 {
break.outer
}
expect = expect_after_value
}
} // while.outer
}
pri func decoder.decode_number!(src: base.io_reader) base.u32[..= 0x3FF] {