From e5dbcf6955aa6fe1d7c4049f0d0d493528b4cd9b Mon Sep 17 00:00:00 2001 From: Chung Leong Date: Sat, 1 Jun 2024 16:32:03 +0200 Subject: [PATCH] Upgraded Rollup examples to production version of Zigar --- .../demos/rollup/filter/package-lock.json | 24 ++--- .../demos/rollup/filter/package.json | 2 +- .../demos/rollup/filter/zig/sepia.zig | 99 ++++--------------- .../demos/rollup/hello/package-lock.json | 24 ++--- .../demos/rollup/hello/package.json | 2 +- .../demos/rollup/sha1/package-lock.json | 24 ++--- .../demos/rollup/sha1/package.json | 2 +- 7 files changed, 56 insertions(+), 121 deletions(-) diff --git a/rollup-plugin-zigar/demos/rollup/filter/package-lock.json b/rollup-plugin-zigar/demos/rollup/filter/package-lock.json index 6dd09fa4..8876e4fb 100644 --- a/rollup-plugin-zigar/demos/rollup/filter/package-lock.json +++ b/rollup-plugin-zigar/demos/rollup/filter/package-lock.json @@ -12,7 +12,7 @@ "@rollup/plugin-node-resolve": "^15.2.3", "http-server": "^14.1.1", "rollup": "^4.16.4", - "rollup-plugin-zigar": "^0.11.2-alpha.2" + "rollup-plugin-zigar": "^0.12.0" } }, "node_modules/@rollup/plugin-node-resolve": { @@ -867,13 +867,13 @@ } }, "node_modules/rollup-plugin-zigar": { - "version": "0.11.2-alpha.2", - "resolved": "https://registry.npmjs.org/rollup-plugin-zigar/-/rollup-plugin-zigar-0.11.2-alpha.2.tgz", - "integrity": "sha512-PUIUlewdGVG+Nh0yEu5asiysRUSIUJmpDP4PdjaWCUUliJYdvRVSNCSC8YLHKhvxmB7iXusieu8XPQFmu9Lhjg==", + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/rollup-plugin-zigar/-/rollup-plugin-zigar-0.12.0.tgz", + "integrity": "sha512-37f0vSK+p1+BqBgP5WPIw+svQghveYxUmnU8ZeuzIuPAYlxXVhsgWBjvnPwPX5z0EIe9Qa5HRW5sOMOth9qoWw==", "dev": true, "dependencies": { - "zigar-compiler": "^0.11.2-alpha.2", - "zigar-runtime": "^0.11.2-alpha.2" + "zigar-compiler": "^0.12.0", + "zigar-runtime": "^0.12.0" } }, "node_modules/safe-buffer": { @@ -984,15 +984,15 @@ } }, "node_modules/zigar-compiler": { - "version": "0.11.2-alpha.2", - "resolved": "https://registry.npmjs.org/zigar-compiler/-/zigar-compiler-0.11.2-alpha.2.tgz", - "integrity": "sha512-8F5EqaBm99MovpnLWP5+4iL/aeZAax0C/W9CXAD4jy8ZcmXa8B6ZEZNYcm/h+rX5srxaWnnatnjxE3yz/5X+dw==", + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/zigar-compiler/-/zigar-compiler-0.12.0.tgz", + "integrity": "sha512-gPZdL4eyKi6nwF2lI/RxtmR3hRuc4CJDON4nH9zaiJe4VSvLzkezJWLPEgtk/UumrKbXSJQdimI7vvlnHwLnZw==", "dev": true }, "node_modules/zigar-runtime": { - "version": "0.11.2-alpha.2", - "resolved": "https://registry.npmjs.org/zigar-runtime/-/zigar-runtime-0.11.2-alpha.2.tgz", - "integrity": "sha512-H6QJM4CJi7W8KiH3rUYgprpA1Sw0ePSWDWDxqbDfobpSS6yxyTd4iccS5bMfa3TXKTSEp1abVlojyraxcmKlXw==", + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/zigar-runtime/-/zigar-runtime-0.12.0.tgz", + "integrity": "sha512-Mn7KGSX6j0A5VPwiaZbA5mTozU7+hcIFfrhmNHhKKCWDy9i4rLVTgWxFoRg4e0jEMC93IPphZxmGswcWC9VgWA==", "dev": true } } diff --git a/rollup-plugin-zigar/demos/rollup/filter/package.json b/rollup-plugin-zigar/demos/rollup/filter/package.json index 60cded12..39617944 100644 --- a/rollup-plugin-zigar/demos/rollup/filter/package.json +++ b/rollup-plugin-zigar/demos/rollup/filter/package.json @@ -15,6 +15,6 @@ "@rollup/plugin-node-resolve": "^15.2.3", "http-server": "^14.1.1", "rollup": "^4.16.4", - "rollup-plugin-zigar": "^0.11.2-alpha.2" + "rollup-plugin-zigar": "^0.12.0" } } diff --git a/rollup-plugin-zigar/demos/rollup/filter/zig/sepia.zig b/rollup-plugin-zigar/demos/rollup/filter/zig/sepia.zig index 8bf4511a..08bdbff7 100644 --- a/rollup-plugin-zigar/demos/rollup/filter/zig/sepia.zig +++ b/rollup-plugin-zigar/demos/rollup/filter/zig/sepia.zig @@ -108,8 +108,7 @@ pub const kernel = struct { const ar = @typeInfo(@TypeOf(m1)).Array; var t1: @TypeOf(m1) = undefined; inline for (m1, 0..) |column, c| { - comptime var r = 0; - inline while (r < ar.len) : (r += 1) { + inline for (0..ar.len) |r| { t1[r][c] = column[r]; } } @@ -125,9 +124,6 @@ pub const Input = KernelInput(u8, kernel); pub const Output = KernelOutput(u8, kernel); pub const Parameters = KernelParameters(kernel); -// support both 0.11 and 0.12 -const enum_auto = if (@hasField(std.builtin.Type.ContainerLayout, "Auto")) .Auto else .auto; - pub fn createOutput(allocator: std.mem.Allocator, width: u32, height: u32, input: Input, params: Parameters) !Output { return createPartialOutput(allocator, width, height, 0, height, input, params); } @@ -207,37 +203,12 @@ pub fn Image(comptime T: type, comptime len: comptime_int, comptime writable: bo } fn pbPixelFromIntPixel(pixel: Pixel) FPixel { - const numerator: FPixel = switch (@hasDecl(std.math, "fabs")) { - // Zig 0.12.0 - false => switch (len) { - 1 => @floatFromInt(@shuffle(T, pixel, undefined, @Vector(1, i32){0})), - 2 => @floatFromInt(@shuffle(T, pixel, undefined, @Vector(2, i32){ 0, 3 })), - 3 => @floatFromInt(@shuffle(T, pixel, undefined, @Vector(3, i32){ 0, 1, 2 })), - 4 => @floatFromInt(pixel), - else => @compileError("Unsupported number of channels: " ++ len), - }, - // Zig 0.11.0 - true => switch (len) { - 1 => .{ - @floatFromInt(pixel[0]), - }, - 2 => .{ - @floatFromInt(pixel[0]), - @floatFromInt(pixel[3]), - }, - 3 => .{ - @floatFromInt(pixel[0]), - @floatFromInt(pixel[1]), - @floatFromInt(pixel[2]), - }, - 4 => .{ - @floatFromInt(pixel[0]), - @floatFromInt(pixel[1]), - @floatFromInt(pixel[2]), - @floatFromInt(pixel[3]), - }, - else => @compileError("Unsupported number of channels: " ++ len), - }, + const numerator: FPixel = switch (len) { + 1 => @floatFromInt(@shuffle(T, pixel, undefined, @Vector(1, i32){0})), + 2 => @floatFromInt(@shuffle(T, pixel, undefined, @Vector(2, i32){ 0, 3 })), + 3 => @floatFromInt(@shuffle(T, pixel, undefined, @Vector(3, i32){ 0, 1, 2 })), + 4 => @floatFromInt(pixel), + else => @compileError("Unsupported number of channels: " ++ len), }; const denominator: FPixel = @splat(@floatFromInt(std.math.maxInt(T))); return numerator / denominator; @@ -248,43 +219,12 @@ pub fn Image(comptime T: type, comptime len: comptime_int, comptime writable: bo const multiplier: FPixel = @splat(max); const product: FPixel = constrain(pixel * multiplier, 0, max); const maxAlpha: @Vector(1, f32) = .{std.math.maxInt(T)}; - return switch (@hasDecl(std.math, "fabs")) { - // Zig 0.12.0 - false => switch (len) { - 1 => @intFromFloat(@shuffle(f32, product, maxAlpha, @Vector(4, i32){ 0, 0, 0, -1 })), - 2 => @intFromFloat(@shuffle(f32, product, undefined, @Vector(4, i32){ 0, 0, 0, 1 })), - 3 => @intFromFloat(@shuffle(f32, product, maxAlpha, @Vector(4, i32){ 0, 1, 2, -1 })), - 4 => @intFromFloat(product), - else => @compileError("Unsupported number of channels: " ++ len), - }, - // Zig 0.11.0 - true => switch (len) { - 1 => .{ - @intFromFloat(product[0]), - @intFromFloat(product[0]), - @intFromFloat(product[0]), - maxAlpha[0], - }, - 2 => .{ - @intFromFloat(product[0]), - @intFromFloat(product[0]), - @intFromFloat(product[0]), - @intFromFloat(product[1]), - }, - 3 => .{ - @intFromFloat(product[0]), - @intFromFloat(product[1]), - @intFromFloat(product[2]), - maxAlpha[0], - }, - 4 => .{ - @intFromFloat(product[0]), - @intFromFloat(product[1]), - @intFromFloat(product[2]), - @intFromFloat(product[3]), - }, - else => @compileError("Unsupported number of channels: " ++ len), - }, + return switch (len) { + 1 => @intFromFloat(@shuffle(f32, product, maxAlpha, @Vector(4, i32){ 0, 0, 0, -1 })), + 2 => @intFromFloat(@shuffle(f32, product, undefined, @Vector(4, i32){ 0, 0, 0, 1 })), + 3 => @intFromFloat(@shuffle(f32, product, maxAlpha, @Vector(4, i32){ 0, 1, 2, -1 })), + 4 => @intFromFloat(product), + else => @compileError("Unsupported number of channels: " ++ len), }; } @@ -326,12 +266,7 @@ pub fn Image(comptime T: type, comptime len: comptime_int, comptime writable: bo const left_top: @Vector(2, f32) = .{ 0, 0 }; const bottom_right: @Vector(2, f32) = .{ @floatFromInt(self.width - 1), @floatFromInt(self.height - 1) }; if (@reduce(.And, coord >= left_top) and @reduce(.And, coord <= bottom_right)) { - const ic: @Vector(2, u32) = switch (@hasDecl(std.math, "fabs")) { - // Zig 0.12.0 - false => @intFromFloat(coord), - // Zig 0.11.0 - true => .{ @intFromFloat(coord[0]), @intFromFloat(coord[1]) }, - }; + const ic: @Vector(2, u32) = @intFromFloat(coord); return self.getPixel(ic[0], ic[1]); } else { return @splat(0); @@ -385,7 +320,7 @@ pub fn KernelInput(comptime T: type, comptime Kernel: type) type { } return @Type(.{ .Struct = .{ - .layout = enum_auto, + .layout = .auto, .fields = &struct_fields, .decls = &.{}, .is_tuple = false, @@ -410,7 +345,7 @@ pub fn KernelOutput(comptime T: type, comptime Kernel: type) type { } return @Type(.{ .Struct = .{ - .layout = enum_auto, + .layout = .auto, .fields = &struct_fields, .decls = &.{}, .is_tuple = false, @@ -444,7 +379,7 @@ pub fn KernelParameters(comptime Kernel: type) type { } return @Type(.{ .Struct = .{ - .layout = enum_auto, + .layout = .auto, .fields = &struct_fields, .decls = &.{}, .is_tuple = false, diff --git a/rollup-plugin-zigar/demos/rollup/hello/package-lock.json b/rollup-plugin-zigar/demos/rollup/hello/package-lock.json index 2fb86da6..2a707078 100644 --- a/rollup-plugin-zigar/demos/rollup/hello/package-lock.json +++ b/rollup-plugin-zigar/demos/rollup/hello/package-lock.json @@ -11,7 +11,7 @@ "devDependencies": { "@rollup/plugin-node-resolve": "^15.2.3", "rollup": "^4.13.0", - "rollup-plugin-zigar": "^0.11.2-alpha.2" + "rollup-plugin-zigar": "^0.12.0" } }, "node_modules/@rollup/plugin-node-resolve": { @@ -405,13 +405,13 @@ } }, "node_modules/rollup-plugin-zigar": { - "version": "0.11.2-alpha.2", - "resolved": "https://registry.npmjs.org/rollup-plugin-zigar/-/rollup-plugin-zigar-0.11.2-alpha.2.tgz", - "integrity": "sha512-PUIUlewdGVG+Nh0yEu5asiysRUSIUJmpDP4PdjaWCUUliJYdvRVSNCSC8YLHKhvxmB7iXusieu8XPQFmu9Lhjg==", + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/rollup-plugin-zigar/-/rollup-plugin-zigar-0.12.0.tgz", + "integrity": "sha512-37f0vSK+p1+BqBgP5WPIw+svQghveYxUmnU8ZeuzIuPAYlxXVhsgWBjvnPwPX5z0EIe9Qa5HRW5sOMOth9qoWw==", "dev": true, "dependencies": { - "zigar-compiler": "^0.11.2-alpha.2", - "zigar-runtime": "^0.11.2-alpha.2" + "zigar-compiler": "^0.12.0", + "zigar-runtime": "^0.12.0" } }, "node_modules/supports-preserve-symlinks-flag": { @@ -427,15 +427,15 @@ } }, "node_modules/zigar-compiler": { - "version": "0.11.2-alpha.2", - "resolved": "https://registry.npmjs.org/zigar-compiler/-/zigar-compiler-0.11.2-alpha.2.tgz", - "integrity": "sha512-8F5EqaBm99MovpnLWP5+4iL/aeZAax0C/W9CXAD4jy8ZcmXa8B6ZEZNYcm/h+rX5srxaWnnatnjxE3yz/5X+dw==", + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/zigar-compiler/-/zigar-compiler-0.12.0.tgz", + "integrity": "sha512-gPZdL4eyKi6nwF2lI/RxtmR3hRuc4CJDON4nH9zaiJe4VSvLzkezJWLPEgtk/UumrKbXSJQdimI7vvlnHwLnZw==", "dev": true }, "node_modules/zigar-runtime": { - "version": "0.11.2-alpha.2", - "resolved": "https://registry.npmjs.org/zigar-runtime/-/zigar-runtime-0.11.2-alpha.2.tgz", - "integrity": "sha512-H6QJM4CJi7W8KiH3rUYgprpA1Sw0ePSWDWDxqbDfobpSS6yxyTd4iccS5bMfa3TXKTSEp1abVlojyraxcmKlXw==", + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/zigar-runtime/-/zigar-runtime-0.12.0.tgz", + "integrity": "sha512-Mn7KGSX6j0A5VPwiaZbA5mTozU7+hcIFfrhmNHhKKCWDy9i4rLVTgWxFoRg4e0jEMC93IPphZxmGswcWC9VgWA==", "dev": true } } diff --git a/rollup-plugin-zigar/demos/rollup/hello/package.json b/rollup-plugin-zigar/demos/rollup/hello/package.json index 6e6b09d4..61f2f64f 100644 --- a/rollup-plugin-zigar/demos/rollup/hello/package.json +++ b/rollup-plugin-zigar/demos/rollup/hello/package.json @@ -13,6 +13,6 @@ "devDependencies": { "@rollup/plugin-node-resolve": "^15.2.3", "rollup": "^4.13.0", - "rollup-plugin-zigar": "^0.11.2-alpha.2" + "rollup-plugin-zigar": "^0.12.0" } } diff --git a/rollup-plugin-zigar/demos/rollup/sha1/package-lock.json b/rollup-plugin-zigar/demos/rollup/sha1/package-lock.json index 9c9676fc..80b5d248 100644 --- a/rollup-plugin-zigar/demos/rollup/sha1/package-lock.json +++ b/rollup-plugin-zigar/demos/rollup/sha1/package-lock.json @@ -11,7 +11,7 @@ "devDependencies": { "@rollup/plugin-node-resolve": "^15.2.3", "rollup": "^4.13.0", - "rollup-plugin-zigar": "^0.11.2-alpha.2" + "rollup-plugin-zigar": "^0.12.0" } }, "node_modules/@rollup/plugin-node-resolve": { @@ -405,13 +405,13 @@ } }, "node_modules/rollup-plugin-zigar": { - "version": "0.11.2-alpha.2", - "resolved": "https://registry.npmjs.org/rollup-plugin-zigar/-/rollup-plugin-zigar-0.11.2-alpha.2.tgz", - "integrity": "sha512-PUIUlewdGVG+Nh0yEu5asiysRUSIUJmpDP4PdjaWCUUliJYdvRVSNCSC8YLHKhvxmB7iXusieu8XPQFmu9Lhjg==", + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/rollup-plugin-zigar/-/rollup-plugin-zigar-0.12.0.tgz", + "integrity": "sha512-37f0vSK+p1+BqBgP5WPIw+svQghveYxUmnU8ZeuzIuPAYlxXVhsgWBjvnPwPX5z0EIe9Qa5HRW5sOMOth9qoWw==", "dev": true, "dependencies": { - "zigar-compiler": "^0.11.2-alpha.2", - "zigar-runtime": "^0.11.2-alpha.2" + "zigar-compiler": "^0.12.0", + "zigar-runtime": "^0.12.0" } }, "node_modules/supports-preserve-symlinks-flag": { @@ -427,15 +427,15 @@ } }, "node_modules/zigar-compiler": { - "version": "0.11.2-alpha.2", - "resolved": "https://registry.npmjs.org/zigar-compiler/-/zigar-compiler-0.11.2-alpha.2.tgz", - "integrity": "sha512-8F5EqaBm99MovpnLWP5+4iL/aeZAax0C/W9CXAD4jy8ZcmXa8B6ZEZNYcm/h+rX5srxaWnnatnjxE3yz/5X+dw==", + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/zigar-compiler/-/zigar-compiler-0.12.0.tgz", + "integrity": "sha512-gPZdL4eyKi6nwF2lI/RxtmR3hRuc4CJDON4nH9zaiJe4VSvLzkezJWLPEgtk/UumrKbXSJQdimI7vvlnHwLnZw==", "dev": true }, "node_modules/zigar-runtime": { - "version": "0.11.2-alpha.2", - "resolved": "https://registry.npmjs.org/zigar-runtime/-/zigar-runtime-0.11.2-alpha.2.tgz", - "integrity": "sha512-H6QJM4CJi7W8KiH3rUYgprpA1Sw0ePSWDWDxqbDfobpSS6yxyTd4iccS5bMfa3TXKTSEp1abVlojyraxcmKlXw==", + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/zigar-runtime/-/zigar-runtime-0.12.0.tgz", + "integrity": "sha512-Mn7KGSX6j0A5VPwiaZbA5mTozU7+hcIFfrhmNHhKKCWDy9i4rLVTgWxFoRg4e0jEMC93IPphZxmGswcWC9VgWA==", "dev": true } } diff --git a/rollup-plugin-zigar/demos/rollup/sha1/package.json b/rollup-plugin-zigar/demos/rollup/sha1/package.json index 84e736e3..30aa5feb 100644 --- a/rollup-plugin-zigar/demos/rollup/sha1/package.json +++ b/rollup-plugin-zigar/demos/rollup/sha1/package.json @@ -13,6 +13,6 @@ "devDependencies": { "@rollup/plugin-node-resolve": "^15.2.3", "rollup": "^4.13.0", - "rollup-plugin-zigar": "^0.11.2-alpha.2" + "rollup-plugin-zigar": "^0.12.0" } }