From 92a8bc46416cfbbed495734448c8c73a3c3ce24c Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Mon, 11 Jun 2018 08:05:12 +1000 Subject: [PATCH] Add a base.utility type --- cmd/wuffs-c/internal/cgen/base/base-public.h | 5 +++++ cmd/wuffs-c/internal/cgen/data.go | 2 +- gen/c/base.c | 5 +++++ gen/c/std/adler32.c | 5 +++++ gen/c/std/crc32.c | 5 +++++ gen/c/std/deflate.c | 5 +++++ gen/c/std/gif.c | 6 ++++++ gen/c/std/gzip.c | 5 +++++ gen/c/std/lzw.c | 5 +++++ gen/c/std/zlib.c | 5 +++++ gen/h/std/adler32.h | 5 +++++ gen/h/std/crc32.h | 5 +++++ gen/h/std/deflate.h | 5 +++++ gen/h/std/gif.h | 6 ++++++ gen/h/std/gzip.h | 5 +++++ gen/h/std/lzw.h | 5 +++++ gen/h/std/zlib.h | 5 +++++ lang/builtin/builtin.go | 1 + lang/check/resolve.go | 2 ++ lang/token/list.go | 2 ++ std/gif/decode_gif.wuffs | 1 + 21 files changed, 89 insertions(+), 1 deletion(-) diff --git a/cmd/wuffs-c/internal/cgen/base/base-public.h b/cmd/wuffs-c/internal/cgen/base/base-public.h index 37aff608..2bb060ca 100644 --- a/cmd/wuffs-c/internal/cgen/base/base-public.h +++ b/cmd/wuffs-c/internal/cgen/base/base-public.h @@ -52,6 +52,11 @@ typedef struct { } wuffs_base__empty_struct; +// wuffs_base__utility is a placeholder receiver type. It enables what Java +// calls static methods, as opposed to regular methods. +typedef struct { +} wuffs_base__utility; + // -------- // A status code is either zero (OK), positive (a recoverable suspension or diff --git a/cmd/wuffs-c/internal/cgen/data.go b/cmd/wuffs-c/internal/cgen/data.go index 245a5e8a..f287efde 100644 --- a/cmd/wuffs-c/internal/cgen/data.go +++ b/cmd/wuffs-c/internal/cgen/data.go @@ -19,7 +19,7 @@ package cgen const basePublicH = "" + "#ifndef WUFFS_BASE_PUBLIC_H\n#define WUFFS_BASE_PUBLIC_H\n\n// Copyright 2017 The Wuffs Authors.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#include \n#include \n#include \n\n// Wuffs assumes that:\n// - converting a uint32_t to a size_t will never overflow.\n// - converting a size_t to a uint64_t will never overflow.\n#if (__WORDSIZE != 32) && (__WORDSIZE != 64)\n#error \"Wuffs requires a word size of either 32 or 64 bits\"\n#endif\n\n// WUFFS_VERSION is the major.minor.patch version, " + "as per https://semver.org/,\n// as a uint64_t. The major number is the high 32 bits. The minor number is the\n// middle 16 bits. The patch number is the low 16 bits. The version extension\n// (such as \"\", \"beta\" or \"rc.1\") is part of the string representation (such as\n// \"1.2.3-beta\") but not the uint64_t representation.\n//\n// All three of major, minor and patch being zero means that this is a\n// work-in-progress version, not a release version, and has no backwards or\n// forwards compatibility guarantees.\n//\n// !! Some code generation programs can override WUFFS_VERSION.\n#define WUFFS_VERSION ((uint64_t)0)\n#define WUFFS_VERSION_MAJOR ((uint64_t)0)\n#define WUFFS_VERSION_MINOR ((uint64_t)0)\n#define WUFFS_VERSION_PATCH ((uint64_t)0)\n#define WUFFS_VERSION_EXTENSION \"\"\n#define WUFFS_VERSION_STRING \"0.0.0\"\n\n// wuffs_base__empty_struct is used when a Wuffs function returns an empty\n// struct. In C, if a function f returns void, you can't say \"x = f()\", but in\n// Wuffs, if a function g returns empty, you can say \"y = g(" + - ")\".\ntypedef struct {\n} wuffs_base__empty_struct;\n\n" + + ")\".\ntypedef struct {\n} wuffs_base__empty_struct;\n\n// wuffs_base__utility is a placeholder receiver type. It enables what Java\n// calls static methods, as opposed to regular methods.\ntypedef struct {\n} wuffs_base__utility;\n\n" + "" + "// --------\n\n// A status code is either zero (OK), positive (a recoverable suspension or\n// pause in processing) or negative (a non-recoverable error). Its bits:\n// - bit 31 (the sign bit) indicates unrecoverable-ness: an error.\n// - bits 30 .. 24 are a package-namespaced numeric code\n// - bits 23 .. 21 are reserved.\n// - bits 20 .. 0 are the packageid (a namespace) as a base38 value.\n//\n// Do not manipulate these bits directly; they are private implementation\n// details. Use methods such as wuffs_base__status__is_error instead.\ntypedef int32_t wuffs_base__status;\n\n// !! INSERT wuffs_base__status names.\n\nstatic inline bool wuffs_base__status__is_error(wuffs_base__status s) {\n return s < 0;\n}\n\nstatic inline bool wuffs_base__status__is_ok(wuffs_base__status s) {\n return s == 0;\n}\n\nstatic inline bool wuffs_base__status__is_suspension(wuffs_base__status s) {\n return s > 0;\n}\n\nconst char* wuffs_base__status__string(wuffs_base__status s);\n\n" + "" + diff --git a/gen/c/base.c b/gen/c/base.c index e0936b1b..9aabbcad 100644 --- a/gen/c/base.c +++ b/gen/c/base.c @@ -66,6 +66,11 @@ typedef struct { } wuffs_base__empty_struct; +// wuffs_base__utility is a placeholder receiver type. It enables what Java +// calls static methods, as opposed to regular methods. +typedef struct { +} wuffs_base__utility; + // -------- // A status code is either zero (OK), positive (a recoverable suspension or diff --git a/gen/c/std/adler32.c b/gen/c/std/adler32.c index 26423dfd..42ff6ef6 100644 --- a/gen/c/std/adler32.c +++ b/gen/c/std/adler32.c @@ -55,6 +55,11 @@ typedef struct { } wuffs_base__empty_struct; +// wuffs_base__utility is a placeholder receiver type. It enables what Java +// calls static methods, as opposed to regular methods. +typedef struct { +} wuffs_base__utility; + // -------- // A status code is either zero (OK), positive (a recoverable suspension or diff --git a/gen/c/std/crc32.c b/gen/c/std/crc32.c index 17ee7f8f..34f79233 100644 --- a/gen/c/std/crc32.c +++ b/gen/c/std/crc32.c @@ -55,6 +55,11 @@ typedef struct { } wuffs_base__empty_struct; +// wuffs_base__utility is a placeholder receiver type. It enables what Java +// calls static methods, as opposed to regular methods. +typedef struct { +} wuffs_base__utility; + // -------- // A status code is either zero (OK), positive (a recoverable suspension or diff --git a/gen/c/std/deflate.c b/gen/c/std/deflate.c index 8c56b58e..b02bb981 100644 --- a/gen/c/std/deflate.c +++ b/gen/c/std/deflate.c @@ -55,6 +55,11 @@ typedef struct { } wuffs_base__empty_struct; +// wuffs_base__utility is a placeholder receiver type. It enables what Java +// calls static methods, as opposed to regular methods. +typedef struct { +} wuffs_base__utility; + // -------- // A status code is either zero (OK), positive (a recoverable suspension or diff --git a/gen/c/std/gif.c b/gen/c/std/gif.c index bfe6ea59..021a7a6a 100644 --- a/gen/c/std/gif.c +++ b/gen/c/std/gif.c @@ -55,6 +55,11 @@ typedef struct { } wuffs_base__empty_struct; +// wuffs_base__utility is a placeholder receiver type. It enables what Java +// calls static methods, as opposed to regular methods. +typedef struct { +} wuffs_base__utility; + // -------- // A status code is either zero (OK), positive (a recoverable suspension or @@ -1414,6 +1419,7 @@ typedef struct { uint32_t f_uncompressed_wi; uint8_t f_uncompressed[4096]; uint8_t f_palettes[2][1024]; + wuffs_base__utility f_util; wuffs_lzw__decoder f_lzw; struct { diff --git a/gen/c/std/gzip.c b/gen/c/std/gzip.c index c79499ef..c91472c7 100644 --- a/gen/c/std/gzip.c +++ b/gen/c/std/gzip.c @@ -55,6 +55,11 @@ typedef struct { } wuffs_base__empty_struct; +// wuffs_base__utility is a placeholder receiver type. It enables what Java +// calls static methods, as opposed to regular methods. +typedef struct { +} wuffs_base__utility; + // -------- // A status code is either zero (OK), positive (a recoverable suspension or diff --git a/gen/c/std/lzw.c b/gen/c/std/lzw.c index 9fdf21ec..b1bc1c27 100644 --- a/gen/c/std/lzw.c +++ b/gen/c/std/lzw.c @@ -55,6 +55,11 @@ typedef struct { } wuffs_base__empty_struct; +// wuffs_base__utility is a placeholder receiver type. It enables what Java +// calls static methods, as opposed to regular methods. +typedef struct { +} wuffs_base__utility; + // -------- // A status code is either zero (OK), positive (a recoverable suspension or diff --git a/gen/c/std/zlib.c b/gen/c/std/zlib.c index 9eba21ad..0642a60a 100644 --- a/gen/c/std/zlib.c +++ b/gen/c/std/zlib.c @@ -55,6 +55,11 @@ typedef struct { } wuffs_base__empty_struct; +// wuffs_base__utility is a placeholder receiver type. It enables what Java +// calls static methods, as opposed to regular methods. +typedef struct { +} wuffs_base__utility; + // -------- // A status code is either zero (OK), positive (a recoverable suspension or diff --git a/gen/h/std/adler32.h b/gen/h/std/adler32.h index b90df042..2278cd60 100644 --- a/gen/h/std/adler32.h +++ b/gen/h/std/adler32.h @@ -55,6 +55,11 @@ typedef struct { } wuffs_base__empty_struct; +// wuffs_base__utility is a placeholder receiver type. It enables what Java +// calls static methods, as opposed to regular methods. +typedef struct { +} wuffs_base__utility; + // -------- // A status code is either zero (OK), positive (a recoverable suspension or diff --git a/gen/h/std/crc32.h b/gen/h/std/crc32.h index 90a78b0c..85bed6a5 100644 --- a/gen/h/std/crc32.h +++ b/gen/h/std/crc32.h @@ -55,6 +55,11 @@ typedef struct { } wuffs_base__empty_struct; +// wuffs_base__utility is a placeholder receiver type. It enables what Java +// calls static methods, as opposed to regular methods. +typedef struct { +} wuffs_base__utility; + // -------- // A status code is either zero (OK), positive (a recoverable suspension or diff --git a/gen/h/std/deflate.h b/gen/h/std/deflate.h index 82b47493..b0ccc4b9 100644 --- a/gen/h/std/deflate.h +++ b/gen/h/std/deflate.h @@ -55,6 +55,11 @@ typedef struct { } wuffs_base__empty_struct; +// wuffs_base__utility is a placeholder receiver type. It enables what Java +// calls static methods, as opposed to regular methods. +typedef struct { +} wuffs_base__utility; + // -------- // A status code is either zero (OK), positive (a recoverable suspension or diff --git a/gen/h/std/gif.h b/gen/h/std/gif.h index d4c0d138..9a1701a3 100644 --- a/gen/h/std/gif.h +++ b/gen/h/std/gif.h @@ -55,6 +55,11 @@ typedef struct { } wuffs_base__empty_struct; +// wuffs_base__utility is a placeholder receiver type. It enables what Java +// calls static methods, as opposed to regular methods. +typedef struct { +} wuffs_base__utility; + // -------- // A status code is either zero (OK), positive (a recoverable suspension or @@ -1414,6 +1419,7 @@ typedef struct { uint32_t f_uncompressed_wi; uint8_t f_uncompressed[4096]; uint8_t f_palettes[2][1024]; + wuffs_base__utility f_util; wuffs_lzw__decoder f_lzw; struct { diff --git a/gen/h/std/gzip.h b/gen/h/std/gzip.h index 4c8e587f..d83cb940 100644 --- a/gen/h/std/gzip.h +++ b/gen/h/std/gzip.h @@ -55,6 +55,11 @@ typedef struct { } wuffs_base__empty_struct; +// wuffs_base__utility is a placeholder receiver type. It enables what Java +// calls static methods, as opposed to regular methods. +typedef struct { +} wuffs_base__utility; + // -------- // A status code is either zero (OK), positive (a recoverable suspension or diff --git a/gen/h/std/lzw.h b/gen/h/std/lzw.h index 9f225221..06539a22 100644 --- a/gen/h/std/lzw.h +++ b/gen/h/std/lzw.h @@ -55,6 +55,11 @@ typedef struct { } wuffs_base__empty_struct; +// wuffs_base__utility is a placeholder receiver type. It enables what Java +// calls static methods, as opposed to regular methods. +typedef struct { +} wuffs_base__utility; + // -------- // A status code is either zero (OK), positive (a recoverable suspension or diff --git a/gen/h/std/zlib.h b/gen/h/std/zlib.h index 347c5252..0bafa9f6 100644 --- a/gen/h/std/zlib.h +++ b/gen/h/std/zlib.h @@ -55,6 +55,11 @@ typedef struct { } wuffs_base__empty_struct; +// wuffs_base__utility is a placeholder receiver type. It enables what Java +// calls static methods, as opposed to regular methods. +typedef struct { +} wuffs_base__utility; + // -------- // A status code is either zero (OK), positive (a recoverable suspension or diff --git a/lang/builtin/builtin.go b/lang/builtin/builtin.go index d680e136..98470df0 100644 --- a/lang/builtin/builtin.go +++ b/lang/builtin/builtin.go @@ -79,6 +79,7 @@ var Types = []string{ "empty_struct", "bool", + "utility", "rect_ie_u32", "rect_ii_u32", diff --git a/lang/check/resolve.go b/lang/check/resolve.go index f5cd1dd3..465a7218 100644 --- a/lang/check/resolve.go +++ b/lang/check/resolve.go @@ -47,6 +47,7 @@ var ( typeExprEmptyStruct = a.NewTypeExpr(0, t.IDBase, t.IDEmptyStruct, nil, nil, nil) typeExprBool = a.NewTypeExpr(0, t.IDBase, t.IDBool, nil, nil, nil) + typeExprUtility = a.NewTypeExpr(0, t.IDBase, t.IDUtility, nil, nil, nil) typeExprRectIEU32 = a.NewTypeExpr(0, t.IDBase, t.IDRectIEU32, nil, nil, nil) typeExprRectIIU32 = a.NewTypeExpr(0, t.IDBase, t.IDRectIIU32, nil, nil, nil) @@ -72,6 +73,7 @@ var builtInTypeMap = typeMap{ t.IDEmptyStruct: typeExprEmptyStruct, t.IDBool: typeExprBool, + t.IDUtility: typeExprUtility, t.IDRectIEU32: typeExprRectIEU32, t.IDRectIIU32: typeExprRectIIU32, diff --git a/lang/token/list.go b/lang/token/list.go index a7743e01..e4f37f84 100644 --- a/lang/token/list.go +++ b/lang/token/list.go @@ -397,6 +397,7 @@ const ( IDEmptyStruct = ID(0x100) IDBool = ID(0x101) + IDUtility = ID(0x102) IDRectIEU32 = ID(0x108) IDRectIIU32 = ID(0x109) @@ -624,6 +625,7 @@ var builtInsByID = [nBuiltInIDs]string{ IDEmptyStruct: "empty_struct", IDBool: "bool", + IDUtility: "utility", IDRectIEU32: "rect_ie_u32", IDRectIIU32: "rect_ii_u32", diff --git a/std/gif/decode_gif.wuffs b/std/gif/decode_gif.wuffs index 90f24590..d7a09709 100644 --- a/std/gif/decode_gif.wuffs +++ b/std/gif/decode_gif.wuffs @@ -97,6 +97,7 @@ pub struct decoder?( // palettes[0] and palettes[1] are the Global and Local Color Table. palettes array[2] array[4 * 256] base.u8, + util base.utility, lzw lzw.decoder, )