mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-25 00:55:11 +01:00
Add a mark method and type.
This commit is contained in:
1 parent
6a48794033
commit
fd5d44b3fc
13 files changed
+80
-16
No files matched your search
@@ -54,6 +54,12 @@ typedef struct {
|
|||||||
bool closed; // No further writes are expected.
|
bool closed; // No further writes are expected.
|
||||||
} puffs_base_buf1;
|
} puffs_base_buf1;
|
||||||
|
|
||||||
|
// puffs_base_buf1_mark marks a position (pointer + offset) in a
|
||||||
|
// puffs_base_buf1.
|
||||||
|
typedef struct {
|
||||||
|
uint8_t* ptr;
|
||||||
|
} puffs_base_buf1_mark;
|
||||||
|
|
||||||
// puffs_base_limit1 provides a limited view of a 1-dimensional byte stream:
|
// puffs_base_limit1 provides a limited view of a 1-dimensional byte stream:
|
||||||
// its first N bytes. That N can be greater than a buffer's current read or
|
// its first N bytes. That N can be greater than a buffer's current read or
|
||||||
// write capacity. N decreases naturally over time as bytes are read from or
|
// write capacity. N decreases naturally over time as bytes are read from or
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ package cgen
|
|||||||
|
|
||||||
const baseHeader = "" +
|
const baseHeader = "" +
|
||||||
"#ifndef PUFFS_BASE_HEADER_H\n#define PUFFS_BASE_HEADER_H\n\n// Use of this source code is governed by a BSD-style license that can be found\n// in the LICENSE file.\n\n#include <stdbool.h>\n#include <stdint.h>\n#include <string.h>\n\n// Puffs requires a word size of at least 32 bits because it assumes that\n// converting a u32 to usize will never overflow. For example, the size of a\n// decoded image is often represented, explicitly or implicitly in an image\n// file, as a u32, and it is convenient to compare that to a buffer size.\n//\n// Similarly, the word size is at most 64 bits because it assumes that\n// converting a usize to u64 will never overflow.\n#if __WORDSIZE < 32\n#error \"Puffs requires a word size of at least 32 bits\"\n#elif __WORDSIZE > 64\n#error \"Puffs requires a word size of at most 64 bits\"\n#endif\n\n// PUFFS_VERSION is the major.minor version number as a uint32. The major\n// number is the high 16 bits. The minor number is the low 16 bits.\n//\n// The intention is to bump the version number at least on every API " +
|
"#ifndef PUFFS_BASE_HEADER_H\n#define PUFFS_BASE_HEADER_H\n\n// Use of this source code is governed by a BSD-style license that can be found\n// in the LICENSE file.\n\n#include <stdbool.h>\n#include <stdint.h>\n#include <string.h>\n\n// Puffs requires a word size of at least 32 bits because it assumes that\n// converting a u32 to usize will never overflow. For example, the size of a\n// decoded image is often represented, explicitly or implicitly in an image\n// file, as a u32, and it is convenient to compare that to a buffer size.\n//\n// Similarly, the word size is at most 64 bits because it assumes that\n// converting a usize to u64 will never overflow.\n#if __WORDSIZE < 32\n#error \"Puffs requires a word size of at least 32 bits\"\n#elif __WORDSIZE > 64\n#error \"Puffs requires a word size of at most 64 bits\"\n#endif\n\n// PUFFS_VERSION is the major.minor version number as a uint32. The major\n// number is the high 16 bits. The minor number is the low 16 bits.\n//\n// The intention is to bump the version number at least on every API " +
|
||||||
"/ ABI\n// backwards incompatible change.\n//\n// For now, the API and ABI are simply unstable and can change at any time.\n//\n// TODO: don't hard code this in base-header.h.\n#define PUFFS_VERSION (0x00001)\n\n// puffs_base_slice_u8 is a 1-dimensional buffer (a pointer and length).\n//\n// A value with all fields NULL or zero is a valid, empty slice.\ntypedef struct {\n uint8_t* ptr;\n size_t len;\n} puffs_base_slice_u8;\n\n// puffs_base_buf1 is a 1-dimensional buffer (a pointer and length), plus\n// additional indexes into that buffer, plus an opened / closed flag.\n//\n// A value with all fields NULL or zero is a valid, empty buffer.\ntypedef struct {\n uint8_t* ptr; // Pointer.\n size_t len; // Length.\n size_t wi; // Write index. Invariant: wi <= len.\n size_t ri; // Read index. Invariant: ri <= wi.\n bool closed; // No further writes are expected.\n} puffs_base_buf1;\n\n// puffs_base_limit1 provides a limited view of a 1-dimensional byte stream:\n// its first N bytes. That N can be greater than a buffer's curr" +
|
"/ ABI\n// backwards incompatible change.\n//\n// For now, the API and ABI are simply unstable and can change at any time.\n//\n// TODO: don't hard code this in base-header.h.\n#define PUFFS_VERSION (0x00001)\n\n// puffs_base_slice_u8 is a 1-dimensional buffer (a pointer and length).\n//\n// A value with all fields NULL or zero is a valid, empty slice.\ntypedef struct {\n uint8_t* ptr;\n size_t len;\n} puffs_base_slice_u8;\n\n// puffs_base_buf1 is a 1-dimensional buffer (a pointer and length), plus\n// additional indexes into that buffer, plus an opened / closed flag.\n//\n// A value with all fields NULL or zero is a valid, empty buffer.\ntypedef struct {\n uint8_t* ptr; // Pointer.\n size_t len; // Length.\n size_t wi; // Write index. Invariant: wi <= len.\n size_t ri; // Read index. Invariant: ri <= wi.\n bool closed; // No further writes are expected.\n} puffs_base_buf1;\n\n// puffs_base_buf1_mark marks a position (pointer + offset) in a\n// puffs_base_buf1.\ntypedef struct {\n uint8_t* ptr;\n} puffs_base_buf1_mark;" +
|
||||||
"ent read or\n// write capacity. N decreases naturally over time as bytes are read from or\n// written to the stream.\n//\n// A value with all fields NULL or zero is a valid, unlimited view.\ntypedef struct puffs_base_limit1 {\n uint64_t* ptr_to_len; // Pointer to N.\n struct puffs_base_limit1* next; // Linked list of limits.\n} puffs_base_limit1;\n\ntypedef struct {\n puffs_base_buf1* buf;\n puffs_base_limit1 limit;\n} puffs_base_reader1;\n\ntypedef struct {\n puffs_base_buf1* buf;\n puffs_base_limit1 limit;\n} puffs_base_writer1;\n\n#endif // PUFFS_BASE_HEADER_H\n" +
|
"\n\n// puffs_base_limit1 provides a limited view of a 1-dimensional byte stream:\n// its first N bytes. That N can be greater than a buffer's current read or\n// write capacity. N decreases naturally over time as bytes are read from or\n// written to the stream.\n//\n// A value with all fields NULL or zero is a valid, unlimited view.\ntypedef struct puffs_base_limit1 {\n uint64_t* ptr_to_len; // Pointer to N.\n struct puffs_base_limit1* next; // Linked list of limits.\n} puffs_base_limit1;\n\ntypedef struct {\n puffs_base_buf1* buf;\n puffs_base_limit1 limit;\n} puffs_base_reader1;\n\ntypedef struct {\n puffs_base_buf1* buf;\n puffs_base_limit1 limit;\n} puffs_base_writer1;\n\n#endif // PUFFS_BASE_HEADER_H\n" +
|
||||||
""
|
""
|
||||||
|
|
||||||
const baseImpl = "" +
|
const baseImpl = "" +
|
||||||
|
|||||||
@@ -148,6 +148,16 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
|||||||
b.writes(")")
|
b.writes(")")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
if isInDst(g.tm, n, t.KeyMark, 0) {
|
||||||
|
if pp == parenthesesMandatory {
|
||||||
|
b.writeb('(')
|
||||||
|
}
|
||||||
|
b.writes("(puffs_base_buf1_mark){.ptr= a_dst.buf->ptr + a_dst.buf->wi}")
|
||||||
|
if pp == parenthesesMandatory {
|
||||||
|
b.writeb(')')
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
if isInDst(g.tm, n, t.KeySlice, 0) {
|
if isInDst(g.tm, n, t.KeySlice, 0) {
|
||||||
if pp == parenthesesMandatory {
|
if pp == parenthesesMandatory {
|
||||||
b.writeb('(')
|
b.writeb('(')
|
||||||
@@ -385,9 +395,10 @@ var cTypeNames = [...]string{
|
|||||||
t.KeyUsize: "size_t",
|
t.KeyUsize: "size_t",
|
||||||
t.KeyBool: "bool",
|
t.KeyBool: "bool",
|
||||||
t.KeyBuf1: "puffs_base_buf1",
|
t.KeyBuf1: "puffs_base_buf1",
|
||||||
t.KeyBuf2: "puffs_base_buf2",
|
t.KeyBuf1Mark: "puffs_base_buf1_mark",
|
||||||
t.KeyReader1: "puffs_base_reader1",
|
t.KeyReader1: "puffs_base_reader1",
|
||||||
t.KeyWriter1: "puffs_base_writer1",
|
t.KeyWriter1: "puffs_base_writer1",
|
||||||
|
t.KeyBuf2: "puffs_base_buf2",
|
||||||
}
|
}
|
||||||
|
|
||||||
var cOpNames = [256]string{
|
var cOpNames = [256]string{
|
||||||
|
|||||||
@@ -725,7 +725,7 @@ func isInSrc(tm *t.Map, n *a.Expr, methodName t.Key, nArgs int) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func isInDst(tm *t.Map, n *a.Expr, methodName t.Key, nArgs int) bool {
|
func isInDst(tm *t.Map, n *a.Expr, methodName t.Key, nArgs int) bool {
|
||||||
callSuspendible := methodName != t.KeySlice
|
callSuspendible := methodName != t.KeyMark && methodName != t.KeySlice
|
||||||
// TODO: check that n.Args() is "(x:bar)".
|
// TODO: check that n.Args() is "(x:bar)".
|
||||||
if n.ID0().Key() != t.KeyOpenParen || n.CallSuspendible() != callSuspendible || len(n.Args()) != nArgs {
|
if n.ID0().Key() != t.KeyOpenParen || n.CallSuspendible() != callSuspendible || len(n.Args()) != nArgs {
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -57,6 +57,12 @@ typedef struct {
|
|||||||
bool closed; // No further writes are expected.
|
bool closed; // No further writes are expected.
|
||||||
} puffs_base_buf1;
|
} puffs_base_buf1;
|
||||||
|
|
||||||
|
// puffs_base_buf1_mark marks a position (pointer + offset) in a
|
||||||
|
// puffs_base_buf1.
|
||||||
|
typedef struct {
|
||||||
|
uint8_t* ptr;
|
||||||
|
} puffs_base_buf1_mark;
|
||||||
|
|
||||||
// puffs_base_limit1 provides a limited view of a 1-dimensional byte stream:
|
// puffs_base_limit1 provides a limited view of a 1-dimensional byte stream:
|
||||||
// its first N bytes. That N can be greater than a buffer's current read or
|
// its first N bytes. That N can be greater than a buffer's current read or
|
||||||
// write capacity. N decreases naturally over time as bytes are read from or
|
// write capacity. N decreases naturally over time as bytes are read from or
|
||||||
@@ -171,7 +177,9 @@ typedef struct {
|
|||||||
|
|
||||||
struct {
|
struct {
|
||||||
uint32_t coro_susp_point;
|
uint32_t coro_susp_point;
|
||||||
|
puffs_base_buf1_mark v_m0;
|
||||||
puffs_flate_status v_z;
|
puffs_flate_status v_z;
|
||||||
|
puffs_base_buf1_mark v_m1;
|
||||||
puffs_base_slice_u8 v_written;
|
puffs_base_slice_u8 v_written;
|
||||||
} c_decode[1];
|
} c_decode[1];
|
||||||
struct {
|
struct {
|
||||||
@@ -595,7 +603,9 @@ puffs_flate_status puffs_flate_decoder_decode(puffs_flate_decoder* self,
|
|||||||
}
|
}
|
||||||
puffs_flate_status status = PUFFS_FLATE_STATUS_OK;
|
puffs_flate_status status = PUFFS_FLATE_STATUS_OK;
|
||||||
|
|
||||||
|
puffs_base_buf1_mark v_m0;
|
||||||
puffs_flate_status v_z;
|
puffs_flate_status v_z;
|
||||||
|
puffs_base_buf1_mark v_m1;
|
||||||
puffs_base_slice_u8 v_written;
|
puffs_base_slice_u8 v_written;
|
||||||
|
|
||||||
uint8_t* b_wptr_dst = NULL;
|
uint8_t* b_wptr_dst = NULL;
|
||||||
@@ -614,12 +624,15 @@ puffs_flate_status puffs_flate_decoder_decode(puffs_flate_decoder* self,
|
|||||||
|
|
||||||
uint32_t coro_susp_point = self->private_impl.c_decode[0].coro_susp_point;
|
uint32_t coro_susp_point = self->private_impl.c_decode[0].coro_susp_point;
|
||||||
if (coro_susp_point) {
|
if (coro_susp_point) {
|
||||||
|
v_m0 = self->private_impl.c_decode[0].v_m0;
|
||||||
v_z = self->private_impl.c_decode[0].v_z;
|
v_z = self->private_impl.c_decode[0].v_z;
|
||||||
|
v_m1 = self->private_impl.c_decode[0].v_m1;
|
||||||
v_written = ((puffs_base_slice_u8){});
|
v_written = ((puffs_base_slice_u8){});
|
||||||
}
|
}
|
||||||
switch (coro_susp_point) {
|
switch (coro_susp_point) {
|
||||||
PUFFS_COROUTINE_SUSPENSION_POINT(0);
|
PUFFS_COROUTINE_SUSPENSION_POINT(0);
|
||||||
|
|
||||||
|
v_m0 = ((puffs_base_buf1_mark){.ptr = a_dst.buf->ptr + a_dst.buf->wi});
|
||||||
PUFFS_COROUTINE_SUSPENSION_POINT(1);
|
PUFFS_COROUTINE_SUSPENSION_POINT(1);
|
||||||
if (a_dst.buf) {
|
if (a_dst.buf) {
|
||||||
size_t n = b_wptr_dst - (a_dst.buf->ptr + a_dst.buf->wi);
|
size_t n = b_wptr_dst - (a_dst.buf->ptr + a_dst.buf->wi);
|
||||||
@@ -647,6 +660,7 @@ puffs_flate_status puffs_flate_decoder_decode(puffs_flate_decoder* self,
|
|||||||
}
|
}
|
||||||
v_z = t_0;
|
v_z = t_0;
|
||||||
if (v_z > 0) {
|
if (v_z > 0) {
|
||||||
|
v_m1 = ((puffs_base_buf1_mark){.ptr = a_dst.buf->ptr + a_dst.buf->wi});
|
||||||
v_written = ((puffs_base_slice_u8){.ptr = a_dst.buf->ptr,
|
v_written = ((puffs_base_slice_u8){.ptr = a_dst.buf->ptr,
|
||||||
.len = b_wptr_dst - a_dst.buf->ptr});
|
.len = b_wptr_dst - a_dst.buf->ptr});
|
||||||
if (((uint64_t)(v_written.len)) >= 32768) {
|
if (((uint64_t)(v_written.len)) >= 32768) {
|
||||||
@@ -667,7 +681,9 @@ puffs_flate_status puffs_flate_decoder_decode(puffs_flate_decoder* self,
|
|||||||
goto suspend;
|
goto suspend;
|
||||||
suspend:
|
suspend:
|
||||||
self->private_impl.c_decode[0].coro_susp_point = coro_susp_point;
|
self->private_impl.c_decode[0].coro_susp_point = coro_susp_point;
|
||||||
|
self->private_impl.c_decode[0].v_m0 = v_m0;
|
||||||
self->private_impl.c_decode[0].v_z = v_z;
|
self->private_impl.c_decode[0].v_z = v_z;
|
||||||
|
self->private_impl.c_decode[0].v_m1 = v_m1;
|
||||||
self->private_impl.c_decode[0].v_written = ((puffs_base_slice_u8){});
|
self->private_impl.c_decode[0].v_written = ((puffs_base_slice_u8){});
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
|||||||
@@ -57,6 +57,12 @@ typedef struct {
|
|||||||
bool closed; // No further writes are expected.
|
bool closed; // No further writes are expected.
|
||||||
} puffs_base_buf1;
|
} puffs_base_buf1;
|
||||||
|
|
||||||
|
// puffs_base_buf1_mark marks a position (pointer + offset) in a
|
||||||
|
// puffs_base_buf1.
|
||||||
|
typedef struct {
|
||||||
|
uint8_t* ptr;
|
||||||
|
} puffs_base_buf1_mark;
|
||||||
|
|
||||||
// puffs_base_limit1 provides a limited view of a 1-dimensional byte stream:
|
// puffs_base_limit1 provides a limited view of a 1-dimensional byte stream:
|
||||||
// its first N bytes. That N can be greater than a buffer's current read or
|
// its first N bytes. That N can be greater than a buffer's current read or
|
||||||
// write capacity. N decreases naturally over time as bytes are read from or
|
// write capacity. N decreases naturally over time as bytes are read from or
|
||||||
|
|||||||
@@ -57,6 +57,12 @@ typedef struct {
|
|||||||
bool closed; // No further writes are expected.
|
bool closed; // No further writes are expected.
|
||||||
} puffs_base_buf1;
|
} puffs_base_buf1;
|
||||||
|
|
||||||
|
// puffs_base_buf1_mark marks a position (pointer + offset) in a
|
||||||
|
// puffs_base_buf1.
|
||||||
|
typedef struct {
|
||||||
|
uint8_t* ptr;
|
||||||
|
} puffs_base_buf1_mark;
|
||||||
|
|
||||||
// puffs_base_limit1 provides a limited view of a 1-dimensional byte stream:
|
// puffs_base_limit1 provides a limited view of a 1-dimensional byte stream:
|
||||||
// its first N bytes. That N can be greater than a buffer's current read or
|
// its first N bytes. That N can be greater than a buffer's current read or
|
||||||
// write capacity. N decreases naturally over time as bytes are read from or
|
// write capacity. N decreases naturally over time as bytes are read from or
|
||||||
@@ -171,7 +177,9 @@ typedef struct {
|
|||||||
|
|
||||||
struct {
|
struct {
|
||||||
uint32_t coro_susp_point;
|
uint32_t coro_susp_point;
|
||||||
|
puffs_base_buf1_mark v_m0;
|
||||||
puffs_flate_status v_z;
|
puffs_flate_status v_z;
|
||||||
|
puffs_base_buf1_mark v_m1;
|
||||||
puffs_base_slice_u8 v_written;
|
puffs_base_slice_u8 v_written;
|
||||||
} c_decode[1];
|
} c_decode[1];
|
||||||
struct {
|
struct {
|
||||||
|
|||||||
@@ -57,6 +57,12 @@ typedef struct {
|
|||||||
bool closed; // No further writes are expected.
|
bool closed; // No further writes are expected.
|
||||||
} puffs_base_buf1;
|
} puffs_base_buf1;
|
||||||
|
|
||||||
|
// puffs_base_buf1_mark marks a position (pointer + offset) in a
|
||||||
|
// puffs_base_buf1.
|
||||||
|
typedef struct {
|
||||||
|
uint8_t* ptr;
|
||||||
|
} puffs_base_buf1_mark;
|
||||||
|
|
||||||
// puffs_base_limit1 provides a limited view of a 1-dimensional byte stream:
|
// puffs_base_limit1 provides a limited view of a 1-dimensional byte stream:
|
||||||
// its first N bytes. That N can be greater than a buffer's current read or
|
// its first N bytes. That N can be greater than a buffer's current read or
|
||||||
// write capacity. N decreases naturally over time as bytes are read from or
|
// write capacity. N decreases naturally over time as bytes are read from or
|
||||||
|
|||||||
@@ -649,7 +649,7 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int,
|
|||||||
isInSrc(q.tm, n, t.KeySkip32, 1) ||
|
isInSrc(q.tm, n, t.KeySkip32, 1) ||
|
||||||
isInDst(q.tm, n, t.KeyWrite, 1) || isInDst(q.tm, n, t.KeyWriteU8, 1) ||
|
isInDst(q.tm, n, t.KeyWrite, 1) || isInDst(q.tm, n, t.KeyWriteU8, 1) ||
|
||||||
isInDst(q.tm, n, t.KeyCopyFrom32, 2) || isInDst(q.tm, n, t.KeyCopyHistory32, 2) ||
|
isInDst(q.tm, n, t.KeyCopyFrom32, 2) || isInDst(q.tm, n, t.KeyCopyHistory32, 2) ||
|
||||||
isInDst(q.tm, n, t.KeySlice, 0) ||
|
isInDst(q.tm, n, t.KeyMark, 0) || isInDst(q.tm, n, t.KeySlice, 0) ||
|
||||||
isThisMethod(q.tm, n, "decode_header", 1) || isThisMethod(q.tm, n, "decode_lsd", 1) ||
|
isThisMethod(q.tm, n, "decode_header", 1) || isThisMethod(q.tm, n, "decode_lsd", 1) ||
|
||||||
isThisMethod(q.tm, n, "decode_extension", 1) || isThisMethod(q.tm, n, "decode_id", 2) ||
|
isThisMethod(q.tm, n, "decode_extension", 1) || isThisMethod(q.tm, n, "decode_id", 2) ||
|
||||||
isThisMethod(q.tm, n, "decode_uncompressed", 2) || isThisMethod(q.tm, n, "decode_huffman", 2) ||
|
isThisMethod(q.tm, n, "decode_uncompressed", 2) || isThisMethod(q.tm, n, "decode_huffman", 2) ||
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ var (
|
|||||||
typeExprBool = a.NewTypeExpr(0, t.IDBool, nil, nil, nil)
|
typeExprBool = a.NewTypeExpr(0, t.IDBool, nil, nil, nil)
|
||||||
typeExprIdeal = a.NewTypeExpr(0, t.IDDoubleZ, nil, nil, nil)
|
typeExprIdeal = a.NewTypeExpr(0, t.IDDoubleZ, nil, nil, nil)
|
||||||
typeExprList = a.NewTypeExpr(0, t.IDDollar, nil, nil, nil)
|
typeExprList = a.NewTypeExpr(0, t.IDDollar, nil, nil, nil)
|
||||||
|
typeExprBuf1Mark = a.NewTypeExpr(0, t.IDBuf1Mark, nil, nil, nil)
|
||||||
typeExprStatus = a.NewTypeExpr(0, t.IDStatus, nil, nil, nil)
|
typeExprStatus = a.NewTypeExpr(0, t.IDStatus, nil, nil, nil)
|
||||||
typeExprU8 = a.NewTypeExpr(0, t.IDU8, nil, nil, nil)
|
typeExprU8 = a.NewTypeExpr(0, t.IDU8, nil, nil, nil)
|
||||||
typeExprU64 = a.NewTypeExpr(0, t.IDU64, nil, nil, nil)
|
typeExprU64 = a.NewTypeExpr(0, t.IDU64, nil, nil, nil)
|
||||||
|
|||||||
+5
-3
@@ -349,7 +349,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
|||||||
isInSrc(q.tm, n, t.KeySkip32, 1) ||
|
isInSrc(q.tm, n, t.KeySkip32, 1) ||
|
||||||
isInDst(q.tm, n, t.KeyWrite, 1) || isInDst(q.tm, n, t.KeyWriteU8, 1) ||
|
isInDst(q.tm, n, t.KeyWrite, 1) || isInDst(q.tm, n, t.KeyWriteU8, 1) ||
|
||||||
isInDst(q.tm, n, t.KeyCopyFrom32, 2) || isInDst(q.tm, n, t.KeyCopyHistory32, 2) ||
|
isInDst(q.tm, n, t.KeyCopyFrom32, 2) || isInDst(q.tm, n, t.KeyCopyHistory32, 2) ||
|
||||||
isInDst(q.tm, n, t.KeySlice, 0) ||
|
isInDst(q.tm, n, t.KeyMark, 0) || isInDst(q.tm, n, t.KeySlice, 0) ||
|
||||||
isThisMethod(q.tm, n, "decode_header", 1) || isThisMethod(q.tm, n, "decode_lsd", 1) ||
|
isThisMethod(q.tm, n, "decode_header", 1) || isThisMethod(q.tm, n, "decode_lsd", 1) ||
|
||||||
isThisMethod(q.tm, n, "decode_extension", 1) || isThisMethod(q.tm, n, "decode_id", 2) ||
|
isThisMethod(q.tm, n, "decode_extension", 1) || isThisMethod(q.tm, n, "decode_id", 2) ||
|
||||||
isThisMethod(q.tm, n, "decode_uncompressed", 2) || isThisMethod(q.tm, n, "decode_huffman", 2) ||
|
isThisMethod(q.tm, n, "decode_uncompressed", 2) || isThisMethod(q.tm, n, "decode_huffman", 2) ||
|
||||||
@@ -371,6 +371,8 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
|||||||
n.SetMType(typeExprPlaceholder32) // HACK.
|
n.SetMType(typeExprPlaceholder32) // HACK.
|
||||||
} else if isInSrc(q.tm, n, t.KeyReadU16BE, 0) || isInSrc(q.tm, n, t.KeyReadU16LE, 0) {
|
} else if isInSrc(q.tm, n, t.KeyReadU16BE, 0) || isInSrc(q.tm, n, t.KeyReadU16LE, 0) {
|
||||||
n.SetMType(typeExprPlaceholder16) // HACK.
|
n.SetMType(typeExprPlaceholder16) // HACK.
|
||||||
|
} else if isInDst(q.tm, n, t.KeyMark, 0) {
|
||||||
|
n.SetMType(typeExprBuf1Mark)
|
||||||
} else if isInDst(q.tm, n, t.KeySlice, 0) {
|
} else if isInDst(q.tm, n, t.KeySlice, 0) {
|
||||||
n.SetMType(typeExprSliceU8) // HACK.
|
n.SetMType(typeExprSliceU8) // HACK.
|
||||||
} else {
|
} else {
|
||||||
@@ -585,7 +587,7 @@ func isInSrc(tm *t.Map, n *a.Expr, methodName t.Key, nArgs int) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func isInDst(tm *t.Map, n *a.Expr, methodName t.Key, nArgs int) bool {
|
func isInDst(tm *t.Map, n *a.Expr, methodName t.Key, nArgs int) bool {
|
||||||
callSuspendible := methodName != t.KeySlice
|
callSuspendible := methodName != t.KeyMark && methodName != t.KeySlice
|
||||||
// TODO: check that n.Args() is "(x:bar)".
|
// TODO: check that n.Args() is "(x:bar)".
|
||||||
if n.ID0().Key() != t.KeyOpenParen || n.CallSuspendible() != callSuspendible || len(n.Args()) != nArgs {
|
if n.ID0().Key() != t.KeyOpenParen || n.CallSuspendible() != callSuspendible || len(n.Args()) != nArgs {
|
||||||
return false
|
return false
|
||||||
@@ -950,7 +952,7 @@ swtch:
|
|||||||
// TODO: reject. You can only refine numeric types.
|
// TODO: reject. You can only refine numeric types.
|
||||||
}
|
}
|
||||||
if name := n.Name().Key(); name == t.KeyBool || name == t.KeyStatus ||
|
if name := n.Name().Key(); name == t.KeyBool || name == t.KeyStatus ||
|
||||||
name == t.KeyReader1 || name == t.KeyWriter1 {
|
name == t.KeyBuf1Mark || name == t.KeyReader1 || name == t.KeyWriter1 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
for _, s := range q.c.structs {
|
for _, s := range q.c.structs {
|
||||||
|
|||||||
+14
-8
@@ -232,9 +232,10 @@ const (
|
|||||||
KeyUsize = Key(IDUsize >> KeyShift)
|
KeyUsize = Key(IDUsize >> KeyShift)
|
||||||
KeyBool = Key(IDBool >> KeyShift)
|
KeyBool = Key(IDBool >> KeyShift)
|
||||||
KeyBuf1 = Key(IDBuf1 >> KeyShift)
|
KeyBuf1 = Key(IDBuf1 >> KeyShift)
|
||||||
KeyBuf2 = Key(IDBuf2 >> KeyShift)
|
KeyBuf1Mark = Key(IDBuf1Mark >> KeyShift)
|
||||||
KeyReader1 = Key(IDReader1 >> KeyShift)
|
KeyReader1 = Key(IDReader1 >> KeyShift)
|
||||||
KeyWriter1 = Key(IDWriter1 >> KeyShift)
|
KeyWriter1 = Key(IDWriter1 >> KeyShift)
|
||||||
|
KeyBuf2 = Key(IDBuf2 >> KeyShift)
|
||||||
KeyStatus = Key(IDStatus >> KeyShift)
|
KeyStatus = Key(IDStatus >> KeyShift)
|
||||||
|
|
||||||
KeyUnderscore = Key(IDUnderscore >> KeyShift)
|
KeyUnderscore = Key(IDUnderscore >> KeyShift)
|
||||||
@@ -270,6 +271,7 @@ const (
|
|||||||
KeySkip32 = Key(IDSkip32 >> KeyShift)
|
KeySkip32 = Key(IDSkip32 >> KeyShift)
|
||||||
KeySkip64 = Key(IDSkip64 >> KeyShift)
|
KeySkip64 = Key(IDSkip64 >> KeyShift)
|
||||||
KeyCopyHistory32 = Key(IDCopyHistory32 >> KeyShift)
|
KeyCopyHistory32 = Key(IDCopyHistory32 >> KeyShift)
|
||||||
|
KeyMark = Key(IDMark >> KeyShift)
|
||||||
KeySlice = Key(IDSlice >> KeyShift)
|
KeySlice = Key(IDSlice >> KeyShift)
|
||||||
KeyLength = Key(IDLength >> KeyShift)
|
KeyLength = Key(IDLength >> KeyShift)
|
||||||
KeyPrefix = Key(IDPrefix >> KeyShift)
|
KeyPrefix = Key(IDPrefix >> KeyShift)
|
||||||
@@ -410,10 +412,11 @@ const (
|
|||||||
IDUsize = ID(0x98<<KeyShift | FlagsIdent | FlagsImplicitSemicolon | FlagsNumType)
|
IDUsize = ID(0x98<<KeyShift | FlagsIdent | FlagsImplicitSemicolon | FlagsNumType)
|
||||||
IDBool = ID(0x99<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
IDBool = ID(0x99<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||||
IDBuf1 = ID(0x9A<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
IDBuf1 = ID(0x9A<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||||
IDBuf2 = ID(0x9B<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
IDBuf1Mark = ID(0x9B<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||||
IDReader1 = ID(0x9C<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
IDReader1 = ID(0x9C<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||||
IDWriter1 = ID(0x9D<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
IDWriter1 = ID(0x9D<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||||
IDStatus = ID(0x9E<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
IDBuf2 = ID(0x9E<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||||
|
IDStatus = ID(0x9F<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||||
|
|
||||||
IDUnderscore = ID(0xA0<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
IDUnderscore = ID(0xA0<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||||
IDThis = ID(0xA1<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
IDThis = ID(0xA1<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||||
@@ -448,10 +451,11 @@ const (
|
|||||||
IDSkip32 = ID(0xC6<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
IDSkip32 = ID(0xC6<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||||
IDSkip64 = ID(0xC7<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
IDSkip64 = ID(0xC7<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||||
IDCopyHistory32 = ID(0xC8<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
IDCopyHistory32 = ID(0xC8<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||||
IDSlice = ID(0xC9<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
IDMark = ID(0xC9<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||||
IDLength = ID(0xCA<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
IDSlice = ID(0xCA<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||||
IDPrefix = ID(0xCB<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
IDLength = ID(0xCB<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||||
IDSuffix = ID(0xCC<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
IDPrefix = ID(0xCC<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||||
|
IDSuffix = ID(0xCD<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||||
)
|
)
|
||||||
|
|
||||||
// The IDXFoo IDs are not returned by the tokenizer. They are used by the
|
// The IDXFoo IDs are not returned by the tokenizer. They are used by the
|
||||||
@@ -610,9 +614,10 @@ var builtInsByKey = [nBuiltInKeys]struct {
|
|||||||
KeyUsize: {"usize", IDUsize},
|
KeyUsize: {"usize", IDUsize},
|
||||||
KeyBool: {"bool", IDBool},
|
KeyBool: {"bool", IDBool},
|
||||||
KeyBuf1: {"buf1", IDBuf1},
|
KeyBuf1: {"buf1", IDBuf1},
|
||||||
KeyBuf2: {"buf2", IDBuf2},
|
KeyBuf1Mark: {"buf1_mark", IDBuf1Mark},
|
||||||
KeyReader1: {"reader1", IDReader1},
|
KeyReader1: {"reader1", IDReader1},
|
||||||
KeyWriter1: {"writer1", IDWriter1},
|
KeyWriter1: {"writer1", IDWriter1},
|
||||||
|
KeyBuf2: {"buf2", IDBuf2},
|
||||||
KeyStatus: {"status", IDStatus},
|
KeyStatus: {"status", IDStatus},
|
||||||
|
|
||||||
KeyUnderscore: {"_", IDUnderscore},
|
KeyUnderscore: {"_", IDUnderscore},
|
||||||
@@ -648,6 +653,7 @@ var builtInsByKey = [nBuiltInKeys]struct {
|
|||||||
KeySkip32: {"skip32", IDSkip32},
|
KeySkip32: {"skip32", IDSkip32},
|
||||||
KeySkip64: {"skip64", IDSkip64},
|
KeySkip64: {"skip64", IDSkip64},
|
||||||
KeyCopyHistory32: {"copy_history32", IDCopyHistory32},
|
KeyCopyHistory32: {"copy_history32", IDCopyHistory32},
|
||||||
|
KeyMark: {"mark", IDMark},
|
||||||
KeySlice: {"slice", IDSlice},
|
KeySlice: {"slice", IDSlice},
|
||||||
KeyLength: {"length", IDLength},
|
KeyLength: {"length", IDLength},
|
||||||
KeyPrefix: {"prefix", IDPrefix},
|
KeyPrefix: {"prefix", IDPrefix},
|
||||||
|
|||||||
@@ -104,8 +104,10 @@ pub struct decoder?(
|
|||||||
)
|
)
|
||||||
|
|
||||||
pub func decoder.decode?(dst writer1, src reader1)() {
|
pub func decoder.decode?(dst writer1, src reader1)() {
|
||||||
|
var m0 buf1_mark = in.dst.mark()
|
||||||
var z status = try this.decode_blocks?(dst:in.dst, src:in.src)
|
var z status = try this.decode_blocks?(dst:in.dst, src:in.src)
|
||||||
if z.is_suspension() {
|
if z.is_suspension() {
|
||||||
|
var m1 buf1_mark = in.dst.mark()
|
||||||
// TODO: add some way to specify the bounds of the slice.
|
// TODO: add some way to specify the bounds of the slice.
|
||||||
//
|
//
|
||||||
// TODO: should "slice" be "slice!", as the return value lets you
|
// TODO: should "slice" be "slice!", as the return value lets you
|
||||||
|
|||||||
Reference in new issue
Block a user