Token导航 LogoToken导航TokenDH.com
开发只读github未标认证来源可访问许可证需确认审计通过

zig-comptime锯齿形补偿时间

Agent Skill

zig-comptime 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

1,608

周安装

67

GitHub Stars

80

下载量

536
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:zig-comptime(锯齿形补偿时间)
来源仓库:https://github.com/mohitmishra786/low-level-dev-skills
仓库路径:skills/zig-comptime
安装命令:
npx skills add https://github.com/mohitmishra786/low-level-dev-skills --skill zig-comptime
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/mohitmishra786/low-level-dev-skills --skill zig-comptime

简介

zig-comptime 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。

  • 可结合来源仓库、安装命令和原始 README 继续核验具体用法。
  • 安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。
  • 适用于开发类任务,支持多宿主环境集成。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

Zig comptime

Purpose

Guide agents through Zig's comptime system: compile-time function evaluation, comptime type parameters, generics via anytype, type reflection with @typeInfo, and metaprogramming patterns that replace C++ templates and macros.

Triggers

  • "How does comptime work in Zig?"
  • "How do I write a generic function in Zig?"
  • "How do I use @typeInfo for reflection?"
  • "How do I generate code at compile time in Zig?"
  • "How does anytype work in Zig?"
  • "How do Zig generics compare to C++ templates?"

Workflow

1. comptime basics

// comptime keyword forces compile-time evaluation
const x: comptime_int = 42;         // comptime integer (arbitrary precision)
const y: comptime_float = 3.14159;  // comptime float (arbitrary precision)

// comptime block — runs at compile time
comptime {
    const val = fibonacci(20);       // computed at compile time
    std.debug.assert(val == 6765);   // compile-time assertion
}

// comptime parameter — caller must provide a comptime-known value
fn makeArray(comptime T: type, comptime n: usize) [n]T {
    return [_]T{0} ** n;             // array of n zeros of type T
}

const arr = makeArray(f32, 8);      // [8]f32 computed at compile time

2. Generic functions with comptime type parameters

const std = @import("std");

// Generic max function — T must be comptime-known
fn max(comptime T: type, a: T, b: T) T {
    return if (a > b) a else b;
}

// Usage: T is inferred from arguments or specified explicitly
const r1 = max(i32, 3, 7);          // 7
const r2 = max(f64, 2.5, 1.8);     // 2.5

// Generic Stack data structure
fn Stack(comptime T: type) type {
    return struct {
        items: []T,
        top: usize,
        allocator: std.mem.Allocator,

        const Self = @This();

        pub fn init(allocator: std.mem.Allocator) !Self {
            return Self{
                .items = try allocator.alloc(T, 64),
                .top = 0,
                .allocator = allocator,
            };
        }

        pub fn push(self: *Self, value: T) void {
            self.items[self.top] = value;
            self.top += 1;
        }

        pub fn pop(self: *Self) ?T {
            if (self.top == 0) return null;
            self.top -= 1;
            return self.items[self.top];
        }

        pub fn deinit(self: *Self) void {
            self.allocator.free(self.items);
        }
    };
}

// Usage: Stack(i32) and Stack(f64) are distinct types
var int_stack = try Stack(i32).init(allocator);
defer int_stack.deinit();
int_stack.push(42);

3. anytype — duck-typed comptime parameters

anytype accepts any type and the compiler infers it at the call site:

// anytype: function works for any type with .len field
fn printLength(thing: anytype) void {
    std.debug.print("Length: {}\n", .{thing.len});
}

printLength("hello");                // string literal — works
printLength([_]u8{1, 2, 3});        // array — works
printLength(std.ArrayList(u32){});   // ArrayList — works

// anytype with comptime checks for better errors
fn serialize(writer: anytype, value: anytype) !void {
    // Verify writer has write method at comptime
    if (!@hasDecl(@TypeOf(writer), "write")) {
        @compileError("writer must have a write method");
    }
    try writer.write(std.mem.asBytes(&value));
}

// anytype in struct methods (used throughout std library)
pub fn format(
    self: MyType,
    comptime fmt: []const u8,
    options: std.fmt.FormatOptions,
    writer: anytype,    // any writer: file, buffer, etc.
) !void {
    try writer.print("{} {}", .{self.x, self.y});
}

4. Type reflection with @typeInfo

@typeInfo returns a tagged union describing a type's structure at comptime:

const std = @import("std");
const TypeInfo = std.builtin.Type;

fn printTypeInfo(comptime T: type) void {
    const info = @typeInfo(T);
    switch (info) {
        .Int => |i| std.debug.print("Int: {} bits, {s}\n",
            .{i.bits, @tagName(i.signedness)}),
        .Float => |f| std.debug.print("Float: {} bits\n", .{f.bits}),
        .Struct => |s| {
            std.debug.print("Struct with {} fields:\n", .{s.fields.len});
            inline for (s.fields) |field| {
                std.debug.print("  {s}: {}\n", .{field.name, field.type});
            }
        },
        .Enum => |e| {
            std.debug.print("Enum with {} values:\n", .{e.fields.len});
            inline for (e.fields) |field| {
                std.debug.print("  {s} = {}\n", .{field.name, field.value});
            }
        },
        .Optional => |o| std.debug.print("Optional({s})\n", .{@typeName(o.child)}),
        .Array => |a| std.debug.print("[{}]{s}\n", .{a.len, @typeName(a.child)}),
        else => std.debug.print("Other type: {s}\n", .{@typeName(T)}),
    }
}

// Usage at comptime
comptime { printTypeInfo(u32); }   // Int: 32 bits, unsigned
comptime { printTypeInfo(f64); }   // Float: 64 bits

5. Comptime-generated code patterns

// Generate a lookup table at comptime
const sin_table = blk: {
    const N = 256;
    var table: [N]f32 = undefined;
    @setEvalBranchQuota(10000);     // increase for expensive comptime eval
    for (0..N) |i| {
        const angle = @as(f32, @floatFromInt(i)) * (2.0 * std.math.pi / N);
        table[i] = @sin(angle);
    }
    break :blk table;
};

// Comptime string processing
fn upperCase(comptime s: []const u8) [s.len]u8 {
    var result: [s.len]u8 = undefined;
    for (s, 0..) |c, i| {
        result[i] = std.ascii.toUpper(c);
    }
    return result;
}
const HELLO = upperCase("hello");  // computed at compile time

// Structural typing: accept any struct with specific fields
fn area(shape: anytype) f64 {
    const T = @TypeOf(shape);
    if (@hasField(T, "width") and @hasField(T, "height")) {
        return @as(f64, shape.width) * @as(f64, shape.height);
    } else if (@hasField(T, "radius")) {
        return std.math.pi * @as(f64, shape.radius) * @as(f64, shape.radius);
    } else {
        @compileError("shape must have width+height or radius fields");
    }
}

6. comptime vs C++ templates comparison

FeatureC++ templatesZig comptime
Syntaxtemplate<typename T>fn foo(comptime T: type)
Error messagesCryptic instantiation stacksClear, at definition point
Specializationtemplate<> class Foo<int>if (T == i32) {...} with inline if
SFINAEComplex enable_if@hasDecl, @hasField, @compileError
Variadictemplate<typename... Ts>anytype, tuples, inline for
Compile timeCan be very slowExplicit, bounded by @setEvalBranchQuota
ValuesRequires constexprAny expression can be comptime
MacrosSeparate #define systemComptime functions replace most macros

7. Common comptime patterns

// Pattern: compile error for unsupported types
fn serializeInt(comptime T: type, value: T) []const u8 {
    if (@typeInfo(T) != .Int) {
        @compileError("serializeInt requires an integer type, got: " ++ @typeName(T));
    }
    // ...
}

// Pattern: conditional compilation
const is_debug = @import("builtin").mode == .Debug;
if (comptime is_debug) {
    // included only in debug builds
    validateInvariant(self);
}

// Pattern: inline for over comptime-known slice
const fields = std.meta.fields(MyStruct);
inline for (fields) |field| {
    // field.name, field.type available at comptime
    std.debug.print("{s}\n", .{field.name});
}

Related skills

  • Use skills/zig/zig-testing for comptime assertions and testing comptime code
  • Use skills/zig/zig-build-system for comptime-based build.zig configuration
  • Use skills/compilers/cpp-templates for C++ template equivalent patterns

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

34.11%
按下载量换算183

Claude

28.99%
按下载量换算155

Cursor

18.09%
按下载量换算97

Gemini CLI

9%
按下载量换算48

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

只读

该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills