From 6f132a74e26d2b737fca852050e900f85f72d0ad Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Mon, 2 Oct 2017 14:02:13 +1100 Subject: [PATCH] Remove the 'mark' concept, no longer necessary. --- cmd/puffs-c/internal/cgen/base-header.h | 6 -- cmd/puffs-c/internal/cgen/base-impl.h | 14 ---- cmd/puffs-c/internal/cgen/data.go | 11 ++- cmd/puffs-c/internal/cgen/expr.go | 39 ++++----- cmd/puffs-c/internal/cgen/statement.go | 6 +- gen/c/std/flate.c | 20 ----- gen/c/std/gif.c | 20 ----- gen/h/std/flate.h | 6 -- gen/h/std/gif.h | 6 -- lang/ast/ast.go | 2 +- lang/check/bounds.go | 2 +- lang/check/check.go | 15 ++-- lang/check/type.go | 8 +- lang/token/list.go | 104 +++++++++++------------- 14 files changed, 83 insertions(+), 176 deletions(-) diff --git a/cmd/puffs-c/internal/cgen/base-header.h b/cmd/puffs-c/internal/cgen/base-header.h index e33bc8c9..e3fd8cd1 100644 --- a/cmd/puffs-c/internal/cgen/base-header.h +++ b/cmd/puffs-c/internal/cgen/base-header.h @@ -54,12 +54,6 @@ 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 diff --git a/cmd/puffs-c/internal/cgen/base-impl.h b/cmd/puffs-c/internal/cgen/base-impl.h index 8f524a5f..8f531fc6 100644 --- a/cmd/puffs-c/internal/cgen/base-impl.h +++ b/cmd/puffs-c/internal/cgen/base-impl.h @@ -79,20 +79,6 @@ static inline puffs_base_slice_u8 puffs_base_make_slice_u8_from_ints( return ((puffs_base_slice_u8){}); } -static inline puffs_base_slice_u8 puffs_base_make_slice_u8_from_ptrs( - uint8_t* start, - uint8_t* mark0, - uint8_t* mark1, - uint8_t* end) { - if ((start <= mark0) && (mark0 <= mark1) && (mark1 <= end)) { - return ((puffs_base_slice_u8){ - .ptr = mark0, - .len = mark1 - mark0, - }); - } - return ((puffs_base_slice_u8){}); -} - static inline puffs_base_slice_u8 puffs_base_make_slice_u8_subslice_i( puffs_base_slice_u8 s, uint64_t i) { diff --git a/cmd/puffs-c/internal/cgen/data.go b/cmd/puffs-c/internal/cgen/data.go index aa66903f..a9e2e801 100644 --- a/cmd/puffs-c/internal/cgen/data.go +++ b/cmd/puffs-c/internal/cgen/data.go @@ -7,17 +7,16 @@ 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 \n#include \n#include \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_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" + + "/ 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" + "" const baseImpl = "" + "#ifndef PUFFS_BASE_IMPL_H\n#define PUFFS_BASE_IMPL_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#define PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(x) (void)(x)\n\n// Use switch cases for coroutine suspension points, similar to the technique\n// in https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html\n//\n// We use a trivial macro instead of an explicit assignment and case statement\n// so that clang-format doesn't get confused by the unusual \"case\"s.\n#define PUFFS_COROUTINE_SUSPENSION_POINT(n) \\\n coro_susp_point = n; \\\n case n:\n\n// Clang also defines \"__GNUC__\".\n#if defined(__GNUC__)\n#define PUFFS_LIKELY(expr) (__builtin_expect(!!(expr), 1))\n#define PUFFS_UNLIKELY(expr) (__builtin_expect(!!(expr), 0))\n// Declare the printf prototype. The generated code shouldn't need this at all,\n// but it's useful for manual printf debugging.\nextern int printf(const char* __restrict __format, ...);\n#else\n#define PUFFS_LIKELY(expr) (expr)\n#de" + "fine PUFFS_UNLIKELY(expr) (expr)\n#endif\n\n// ---------------- Static Inline Functions\n//\n// The helpers below are functions, instead of macros, because their arguments\n// can be an expression that we shouldn't evaluate more than once.\n//\n// They are in base-impl.h and hence copy/pasted into every generated C file,\n// instead of being in some \"base.c\" file, since a design goal is that users of\n// the generated C code can often just #include a single .c file, such as\n// \"gif.c\", without having to additionally include or otherwise build and link\n// a \"base.c\" file.\n//\n// They are static, so that linking multiple puffs .o files won't complain about\n// duplicate function definitions.\n//\n// They are explicitly marked inline, even if modern compilers don't use the\n// inline attribute to guide optimizations such as inlining, to avoid the\n// -Wunused-function warning, and we like to compile with -Wall -Werror.\n\nstatic inline uint16_t puffs_base_load_u16be(uint8_t* p) {\n return ((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1" + - "]) << 0);\n}\n\nstatic inline uint16_t puffs_base_load_u16le(uint8_t* p) {\n return ((uint16_t)(p[0]) << 0) | ((uint16_t)(p[1]) << 8);\n}\n\nstatic inline uint32_t puffs_base_load_u32be(uint8_t* p) {\n return ((uint32_t)(p[0]) << 24) | ((uint32_t)(p[1]) << 16) |\n ((uint32_t)(p[2]) << 8) | ((uint32_t)(p[3]) << 0);\n}\n\nstatic inline uint32_t puffs_base_load_u32le(uint8_t* p) {\n return ((uint32_t)(p[0]) << 0) | ((uint32_t)(p[1]) << 8) |\n ((uint32_t)(p[2]) << 16) | ((uint32_t)(p[3]) << 24);\n}\n\nstatic inline puffs_base_slice_u8 puffs_base_make_slice_u8_from_ints(\n uint8_t* start,\n uint64_t i,\n uint64_t j,\n uint64_t k) {\n if ((i <= j) && (j <= k) && (k <= SIZE_MAX)) {\n return ((puffs_base_slice_u8){\n .ptr = start + i,\n .len = j - i,\n });\n }\n return ((puffs_base_slice_u8){});\n}\n\nstatic inline puffs_base_slice_u8 puffs_base_make_slice_u8_from_ptrs(\n uint8_t* start,\n uint8_t* mark0,\n uint8_t* mark1,\n uint8_t* end) {\n if ((start <= mark0) && (mark0 <= mark1) && " + - "(mark1 <= end)) {\n return ((puffs_base_slice_u8){\n .ptr = mark0,\n .len = mark1 - mark0,\n });\n }\n return ((puffs_base_slice_u8){});\n}\n\nstatic inline puffs_base_slice_u8 puffs_base_make_slice_u8_subslice_i(\n puffs_base_slice_u8 s,\n uint64_t i) {\n if ((i <= SIZE_MAX) && (i <= s.len)) {\n return ((puffs_base_slice_u8){\n .ptr = s.ptr + i,\n .len = s.len - i,\n });\n }\n return ((puffs_base_slice_u8){});\n}\n\nstatic inline puffs_base_slice_u8 puffs_base_make_slice_u8_subslice_j(\n puffs_base_slice_u8 s,\n uint64_t j) {\n if ((j <= SIZE_MAX) && (j <= s.len)) {\n return ((puffs_base_slice_u8){.ptr = s.ptr, .len = j});\n }\n return ((puffs_base_slice_u8){});\n}\n\nstatic inline puffs_base_slice_u8 puffs_base_make_slice_u8_subslice_ij(\n puffs_base_slice_u8 s,\n uint64_t i,\n uint64_t j) {\n if ((i <= j) && (j <= SIZE_MAX) && (j <= s.len)) {\n return ((puffs_base_slice_u8){\n .ptr = s.ptr + i,\n .len = j - i,\n });\n }\n return ((puffs_base_slice_u8){" + - "});\n}\n\n// puffs_base_slice_u8_prefix returns up to the first n bytes of s.\nstatic inline puffs_base_slice_u8 puffs_base_slice_u8_prefix(\n puffs_base_slice_u8 s,\n uint64_t n) {\n if ((uint64_t)(s.len) > n) {\n s.len = n;\n }\n return s;\n}\n\n// puffs_base_slice_u8_suffix returns up to the last n bytes of s.\nstatic inline puffs_base_slice_u8 puffs_base_slice_u8_suffix(\n puffs_base_slice_u8 s,\n uint64_t n) {\n if ((uint64_t)(s.len) > n) {\n s.ptr += (uint64_t)(s.len) - n;\n s.len = n;\n }\n return s;\n}\n\n// puffs_base_slice_u8_copy_from calls memmove(dst.ptr, src.ptr, n) where n is\n// the minimum of dst.len and src.len.\n//\n// Passing a puffs_base_slice_u8 with all fields NULL or zero (a valid, empty\n// slice) is valid and results in a no-op.\nstatic inline uint64_t puffs_base_slice_u8_copy_from(puffs_base_slice_u8 dst,\n puffs_base_slice_u8 src) {\n size_t n = dst.len < src.len ? dst.len : src.len;\n if (n > 0) {\n memmove(dst.ptr, src.ptr, n);\n " + - " }\n return n;\n}\n\n#endif // PUFFS_BASE_IMPL_H\n" + + "]) << 0);\n}\n\nstatic inline uint16_t puffs_base_load_u16le(uint8_t* p) {\n return ((uint16_t)(p[0]) << 0) | ((uint16_t)(p[1]) << 8);\n}\n\nstatic inline uint32_t puffs_base_load_u32be(uint8_t* p) {\n return ((uint32_t)(p[0]) << 24) | ((uint32_t)(p[1]) << 16) |\n ((uint32_t)(p[2]) << 8) | ((uint32_t)(p[3]) << 0);\n}\n\nstatic inline uint32_t puffs_base_load_u32le(uint8_t* p) {\n return ((uint32_t)(p[0]) << 0) | ((uint32_t)(p[1]) << 8) |\n ((uint32_t)(p[2]) << 16) | ((uint32_t)(p[3]) << 24);\n}\n\nstatic inline puffs_base_slice_u8 puffs_base_make_slice_u8_from_ints(\n uint8_t* start,\n uint64_t i,\n uint64_t j,\n uint64_t k) {\n if ((i <= j) && (j <= k) && (k <= SIZE_MAX)) {\n return ((puffs_base_slice_u8){\n .ptr = start + i,\n .len = j - i,\n });\n }\n return ((puffs_base_slice_u8){});\n}\n\nstatic inline puffs_base_slice_u8 puffs_base_make_slice_u8_subslice_i(\n puffs_base_slice_u8 s,\n uint64_t i) {\n if ((i <= SIZE_MAX) && (i <= s.len)) {\n return ((puffs_base_slice_u8){\n " + + " .ptr = s.ptr + i,\n .len = s.len - i,\n });\n }\n return ((puffs_base_slice_u8){});\n}\n\nstatic inline puffs_base_slice_u8 puffs_base_make_slice_u8_subslice_j(\n puffs_base_slice_u8 s,\n uint64_t j) {\n if ((j <= SIZE_MAX) && (j <= s.len)) {\n return ((puffs_base_slice_u8){.ptr = s.ptr, .len = j});\n }\n return ((puffs_base_slice_u8){});\n}\n\nstatic inline puffs_base_slice_u8 puffs_base_make_slice_u8_subslice_ij(\n puffs_base_slice_u8 s,\n uint64_t i,\n uint64_t j) {\n if ((i <= j) && (j <= SIZE_MAX) && (j <= s.len)) {\n return ((puffs_base_slice_u8){\n .ptr = s.ptr + i,\n .len = j - i,\n });\n }\n return ((puffs_base_slice_u8){});\n}\n\n// puffs_base_slice_u8_prefix returns up to the first n bytes of s.\nstatic inline puffs_base_slice_u8 puffs_base_slice_u8_prefix(\n puffs_base_slice_u8 s,\n uint64_t n) {\n if ((uint64_t)(s.len) > n) {\n s.len = n;\n }\n return s;\n}\n\n// puffs_base_slice_u8_suffix returns up to the last n bytes of s.\nstatic inline puffs_base_slice_u8 puff" + + "s_base_slice_u8_suffix(\n puffs_base_slice_u8 s,\n uint64_t n) {\n if ((uint64_t)(s.len) > n) {\n s.ptr += (uint64_t)(s.len) - n;\n s.len = n;\n }\n return s;\n}\n\n// puffs_base_slice_u8_copy_from calls memmove(dst.ptr, src.ptr, n) where n is\n// the minimum of dst.len and src.len.\n//\n// Passing a puffs_base_slice_u8 with all fields NULL or zero (a valid, empty\n// slice) is valid and results in a no-op.\nstatic inline uint64_t puffs_base_slice_u8_copy_from(puffs_base_slice_u8 dst,\n puffs_base_slice_u8 src) {\n size_t n = dst.len < src.len ? dst.len : src.len;\n if (n > 0) {\n memmove(dst.ptr, src.ptr, n);\n }\n return n;\n}\n\n#endif // PUFFS_BASE_IMPL_H\n" + "" type template_args_short_read struct { diff --git a/cmd/puffs-c/internal/cgen/expr.go b/cmd/puffs-c/internal/cgen/expr.go index d81f5bd6..90ce84d8 100644 --- a/cmd/puffs-c/internal/cgen/expr.go +++ b/cmd/puffs-c/internal/cgen/expr.go @@ -148,16 +148,6 @@ 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.printf("(puffs_base_buf1_mark){.ptr= %swptr_dst}", bPrefix) - if pp == parenthesesMandatory { - b.writeb(')') - } - return nil - } if isInDst(g.tm, n, t.KeySlice, 0) { b.printf("((puffs_base_slice_u8){ .ptr = %swstart_dst, .len = %swptr_dst - %swstart_dst, })", bPrefix, bPrefix, bPrefix) @@ -452,21 +442,20 @@ 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.KeyBuf1Mark: "puffs_base_buf1_mark", - t.KeyReader1: "puffs_base_reader1", - t.KeyWriter1: "puffs_base_writer1", - t.KeyBuf2: "puffs_base_buf2", + 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.KeyReader1: "puffs_base_reader1", + t.KeyWriter1: "puffs_base_writer1", + t.KeyBuf2: "puffs_base_buf2", } var cOpNames = [256]string{ diff --git a/cmd/puffs-c/internal/cgen/statement.go b/cmd/puffs-c/internal/cgen/statement.go index 0c5872ac..9263df7d 100644 --- a/cmd/puffs-c/internal/cgen/statement.go +++ b/cmd/puffs-c/internal/cgen/statement.go @@ -454,8 +454,8 @@ func (g *gen) writeCallSuspendibles(b *buffer, n *a.Expr, depth uint32) error { // TODO: it's not a BAD_ARGUMENT if we can copy from the sliding window. // // TODO: %s%s.buf->ptr might be a NULL pointer dereference. In any - // case, we need to compare the (resumed) distance against a mark, not - // against the beginning of the dst buffer. + // case, we need to compare the (resumed) distance against the + // b_wstart_dst pointer, not against the beginning of the dst buffer. b.printf("if (PUFFS_UNLIKELY((%s%d == 0) || (%s%d > (%swptr_%s - %s%s.buf->ptr)))) { "+ "status = %sERROR_BAD_ARGUMENT; goto exit; }\n", tPrefix, temp0, tPrefix, temp0, bPrefix, wName, aPrefix, wName, g.PKGPREFIX) @@ -709,7 +709,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.KeyMark && methodName != t.KeySlice + callSuspendible := 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 diff --git a/gen/c/std/flate.c b/gen/c/std/flate.c index 9501f604..6043df2e 100644 --- a/gen/c/std/flate.c +++ b/gen/c/std/flate.c @@ -57,12 +57,6 @@ 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 @@ -368,20 +362,6 @@ static inline puffs_base_slice_u8 puffs_base_make_slice_u8_from_ints( return ((puffs_base_slice_u8){}); } -static inline puffs_base_slice_u8 puffs_base_make_slice_u8_from_ptrs( - uint8_t* start, - uint8_t* mark0, - uint8_t* mark1, - uint8_t* end) { - if ((start <= mark0) && (mark0 <= mark1) && (mark1 <= end)) { - return ((puffs_base_slice_u8){ - .ptr = mark0, - .len = mark1 - mark0, - }); - } - return ((puffs_base_slice_u8){}); -} - static inline puffs_base_slice_u8 puffs_base_make_slice_u8_subslice_i( puffs_base_slice_u8 s, uint64_t i) { diff --git a/gen/c/std/gif.c b/gen/c/std/gif.c index e7492b0d..3b97c386 100644 --- a/gen/c/std/gif.c +++ b/gen/c/std/gif.c @@ -57,12 +57,6 @@ 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 @@ -338,20 +332,6 @@ static inline puffs_base_slice_u8 puffs_base_make_slice_u8_from_ints( return ((puffs_base_slice_u8){}); } -static inline puffs_base_slice_u8 puffs_base_make_slice_u8_from_ptrs( - uint8_t* start, - uint8_t* mark0, - uint8_t* mark1, - uint8_t* end) { - if ((start <= mark0) && (mark0 <= mark1) && (mark1 <= end)) { - return ((puffs_base_slice_u8){ - .ptr = mark0, - .len = mark1 - mark0, - }); - } - return ((puffs_base_slice_u8){}); -} - static inline puffs_base_slice_u8 puffs_base_make_slice_u8_subslice_i( puffs_base_slice_u8 s, uint64_t i) { diff --git a/gen/h/std/flate.h b/gen/h/std/flate.h index 944b33ba..19df3a0b 100644 --- a/gen/h/std/flate.h +++ b/gen/h/std/flate.h @@ -57,12 +57,6 @@ 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 diff --git a/gen/h/std/gif.h b/gen/h/std/gif.h index 08129cb9..74ba42a7 100644 --- a/gen/h/std/gif.h +++ b/gen/h/std/gif.h @@ -57,12 +57,6 @@ 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 diff --git a/lang/ast/ast.go b/lang/ast/ast.go index fb718f34..601bd682 100644 --- a/lang/ast/ast.go +++ b/lang/ast/ast.go @@ -519,7 +519,7 @@ func (n *TypeExpr) HasPointers() bool { case 0: // TODO: add t.KeyReader1, after figuring out how limit's should really work. switch n.id1.Key() { - case t.KeyBuf1, t.KeyBuf1Mark, t.KeyWriter1, t.KeyBuf2: + case t.KeyBuf1, t.KeyWriter1, t.KeyBuf2: return true } case t.KeyPtr, t.KeyNptr, t.KeyColon: diff --git a/lang/check/bounds.go b/lang/check/bounds.go index 0a10593b..17ae7867 100644 --- a/lang/check/bounds.go +++ b/lang/check/bounds.go @@ -654,7 +654,7 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int, 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.KeyCopyFrom32, 2) || isInDst(q.tm, n, t.KeyCopyHistory32, 2) || - isInDst(q.tm, n, t.KeyMark, 0) || isInDst(q.tm, n, t.KeySlice, 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_extension", 1) || isThisMethod(q.tm, n, "decode_id", 2) || isThisMethod(q.tm, n, "decode_uncompressed", 2) || isThisMethod(q.tm, n, "decode_huffman", 2) || diff --git a/lang/check/check.go b/lang/check/check.go index 47e2404d..776c4da9 100644 --- a/lang/check/check.go +++ b/lang/check/check.go @@ -56,14 +56,13 @@ func trimQuotes(s string) string { // typeExprFoo is an *ast.Node MType (implicit type). var ( - typeExprBool = a.NewTypeExpr(0, t.IDBool, nil, nil, nil) - typeExprIdeal = a.NewTypeExpr(0, t.IDDoubleZ, 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) - typeExprU8 = a.NewTypeExpr(0, t.IDU8, nil, nil, nil) - typeExprU64 = a.NewTypeExpr(0, t.IDU64, nil, nil, nil) - typeExprSliceU8 = a.NewTypeExpr(t.IDColon, 0, nil, nil, typeExprU8) + typeExprBool = a.NewTypeExpr(0, t.IDBool, nil, nil, nil) + typeExprIdeal = a.NewTypeExpr(0, t.IDDoubleZ, nil, nil, nil) + typeExprList = a.NewTypeExpr(0, t.IDDollar, nil, nil, nil) + typeExprStatus = a.NewTypeExpr(0, t.IDStatus, nil, nil, nil) + typeExprU8 = a.NewTypeExpr(0, t.IDU8, nil, nil, nil) + typeExprU64 = a.NewTypeExpr(0, t.IDU64, nil, nil, nil) + typeExprSliceU8 = a.NewTypeExpr(t.IDColon, 0, nil, nil, typeExprU8) // TODO: delete this. typeExprPlaceholder = a.NewTypeExpr(0, t.IDU8, nil, nil, nil) diff --git a/lang/check/type.go b/lang/check/type.go index 461a67ed..a3cf9b7f 100644 --- a/lang/check/type.go +++ b/lang/check/type.go @@ -354,7 +354,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error { 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.KeyCopyFrom32, 2) || isInDst(q.tm, n, t.KeyCopyHistory32, 2) || - isInDst(q.tm, n, t.KeyMark, 0) || isInDst(q.tm, n, t.KeySlice, 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_extension", 1) || isThisMethod(q.tm, n, "decode_id", 2) || isThisMethod(q.tm, n, "decode_uncompressed", 2) || isThisMethod(q.tm, n, "decode_huffman", 2) || @@ -376,8 +376,6 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error { n.SetMType(typeExprPlaceholder32) // HACK. } else if isInSrc(q.tm, n, t.KeyReadU16BE, 0) || isInSrc(q.tm, n, t.KeyReadU16LE, 0) { 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) { n.SetMType(typeExprSliceU8) // HACK. } else { @@ -593,7 +591,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.KeyMark && methodName != t.KeySlice + callSuspendible := 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 @@ -958,7 +956,7 @@ swtch: // TODO: reject. You can only refine numeric types. } if name := n.Name().Key(); name == t.KeyBool || name == t.KeyStatus || - name == t.KeyBuf1Mark || name == t.KeyReader1 || name == t.KeyWriter1 { + name == t.KeyReader1 || name == t.KeyWriter1 { break } for _, s := range q.c.structs { diff --git a/lang/token/list.go b/lang/token/list.go index 38eee462..3fe311e4 100644 --- a/lang/token/list.go +++ b/lang/token/list.go @@ -231,22 +231,21 @@ const ( KeyTrue = Key(IDTrue >> KeyShift) KeyZero = Key(IDZero >> KeyShift) - KeyI8 = Key(IDI8 >> KeyShift) - KeyI16 = Key(IDI16 >> KeyShift) - KeyI32 = Key(IDI32 >> KeyShift) - KeyI64 = Key(IDI64 >> KeyShift) - KeyU8 = Key(IDU8 >> KeyShift) - KeyU16 = Key(IDU16 >> KeyShift) - KeyU32 = Key(IDU32 >> KeyShift) - KeyU64 = Key(IDU64 >> KeyShift) - KeyUsize = Key(IDUsize >> KeyShift) - KeyBool = Key(IDBool >> KeyShift) - KeyBuf1 = Key(IDBuf1 >> KeyShift) - KeyBuf1Mark = Key(IDBuf1Mark >> KeyShift) - KeyReader1 = Key(IDReader1 >> KeyShift) - KeyWriter1 = Key(IDWriter1 >> KeyShift) - KeyBuf2 = Key(IDBuf2 >> KeyShift) - KeyStatus = Key(IDStatus >> KeyShift) + KeyI8 = Key(IDI8 >> KeyShift) + KeyI16 = Key(IDI16 >> KeyShift) + KeyI32 = Key(IDI32 >> KeyShift) + KeyI64 = Key(IDI64 >> KeyShift) + KeyU8 = Key(IDU8 >> KeyShift) + KeyU16 = Key(IDU16 >> KeyShift) + KeyU32 = Key(IDU32 >> KeyShift) + KeyU64 = Key(IDU64 >> KeyShift) + KeyUsize = Key(IDUsize >> KeyShift) + KeyBool = Key(IDBool >> KeyShift) + KeyBuf1 = Key(IDBuf1 >> KeyShift) + KeyReader1 = Key(IDReader1 >> KeyShift) + KeyWriter1 = Key(IDWriter1 >> KeyShift) + KeyBuf2 = Key(IDBuf2 >> KeyShift) + KeyStatus = Key(IDStatus >> KeyShift) KeyUnderscore = Key(IDUnderscore >> KeyShift) KeyThis = Key(IDThis >> KeyShift) @@ -281,7 +280,6 @@ const ( KeySkip32 = Key(IDSkip32 >> KeyShift) KeySkip64 = Key(IDSkip64 >> KeyShift) KeyCopyHistory32 = Key(IDCopyHistory32 >> KeyShift) - KeyMark = Key(IDMark >> KeyShift) KeySlice = Key(IDSlice >> KeyShift) KeyLength = Key(IDLength >> KeyShift) KeyPrefix = Key(IDPrefix >> KeyShift) @@ -411,22 +409,21 @@ const ( IDTrue = ID(0x81<