mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-19 00:38:14 +01:00
Add a mark method and type.
This commit is contained in:
1 parent
6a48794033
commit
fd5d44b3fc
13 files changed
+141
-77
No files matched your search
@@ -54,6 +54,12 @@ typedef struct {
|
||||
bool closed; // No further writes are expected.
|
||||
} 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:
|
||||
// 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
|
||||
|
||||
@@ -7,8 +7,8 @@ package cgen
|
||||
|
||||
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 " +
|
||||
"/ 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" +
|
||||
"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" +
|
||||
"/ 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;" +
|
||||
"\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 = "" +
|
||||
|
||||
@@ -148,6 +148,16 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
b.writes(")")
|
||||
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 pp == parenthesesMandatory {
|
||||
b.writeb('(')
|
||||
@@ -374,20 +384,21 @@ func (g *gen) writeCTypeName(b *buffer, n *a.TypeExpr, varNamePrefix string, var
|
||||
}
|
||||
|
||||
var cTypeNames = [...]string{
|
||||
t.KeyI8: "int8_t",
|
||||
t.KeyI16: "int16_t",
|
||||
t.KeyI32: "int32_t",
|
||||
t.KeyI64: "int64_t",
|
||||
t.KeyU8: "uint8_t",
|
||||
t.KeyU16: "uint16_t",
|
||||
t.KeyU32: "uint32_t",
|
||||
t.KeyU64: "uint64_t",
|
||||
t.KeyUsize: "size_t",
|
||||
t.KeyBool: "bool",
|
||||
t.KeyBuf1: "puffs_base_buf1",
|
||||
t.KeyBuf2: "puffs_base_buf2",
|
||||
t.KeyReader1: "puffs_base_reader1",
|
||||
t.KeyWriter1: "puffs_base_writer1",
|
||||
t.KeyI8: "int8_t",
|
||||
t.KeyI16: "int16_t",
|
||||
t.KeyI32: "int32_t",
|
||||
t.KeyI64: "int64_t",
|
||||
t.KeyU8: "uint8_t",
|
||||
t.KeyU16: "uint16_t",
|
||||
t.KeyU32: "uint32_t",
|
||||
t.KeyU64: "uint64_t",
|
||||
t.KeyUsize: "size_t",
|
||||
t.KeyBool: "bool",
|
||||
t.KeyBuf1: "puffs_base_buf1",
|
||||
t.KeyBuf1Mark: "puffs_base_buf1_mark",
|
||||
t.KeyReader1: "puffs_base_reader1",
|
||||
t.KeyWriter1: "puffs_base_writer1",
|
||||
t.KeyBuf2: "puffs_base_buf2",
|
||||
}
|
||||
|
||||
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 {
|
||||
callSuspendible := methodName != t.KeySlice
|
||||
callSuspendible := methodName != t.KeyMark && methodName != t.KeySlice
|
||||
// TODO: check that n.Args() is "(x:bar)".
|
||||
if n.ID0().Key() != t.KeyOpenParen || n.CallSuspendible() != callSuspendible || len(n.Args()) != nArgs {
|
||||
return false
|
||||
|
||||
Reference in new issue
Block a user