From 82bf1eb7a1ae54f0bb52fdb8fdcd89fdaab683f0 Mon Sep 17 00:00:00 2001
From: Andrew Kelley
{#syntax#}@alignCast(comptime alignment: u29, ptr: var) var{#endsyntax#}
+ + {#syntax#}ptr{#endsyntax#} can be {#syntax#}*T{#endsyntax#}, {#syntax#}fn(){#endsyntax#}, {#syntax#}?*T{#endsyntax#}, + {#syntax#}?fn(){#endsyntax#}, or {#syntax#}[]T{#endsyntax#}. It returns the same type as {#syntax#}ptr{#endsyntax#} + except with the alignment adjusted to the new value. +
+A {#link|pointer alignment safety check|Incorrect Pointer Alignment#} is added + to the generated code to make sure the pointer is aligned as promised.
+ + {#header_close#} + {#header_open|@alignOf#} +{#syntax#}@alignOf(comptime T: type) comptime_int{#endsyntax#}
+ + This function returns the number of bytes that this type should be aligned to + for the current target to match the C ABI. When the child type of a pointer has + this alignment, the alignment can be omitted from the type. +
+{#syntax#}const assert = @import("std").debug.assert;
+comptime {
+ assert(*u32 == *align(@alignOf(u32)) u32);
+}{#endsyntax#}
+ + The result is a target-specific compile time constant. It is guaranteed to be + less than or equal to {#link|@sizeOf(T)|@sizeOf#}. +
+ {#see_also|Alignment#} + {#header_close#} {#header_open|@ArgType#}{#syntax#}@ArgType(comptime T: type, comptime n: usize) type{#endsyntax#}
@@ -5241,6 +5269,7 @@ fn seq(c: u8) void { Works at compile-time if {#syntax#}value{#endsyntax#} is known at compile time. It's a compile error to bitcast a struct to a scalar type of the same size since structs have undefined layout. However if the struct is packed then it works.
{#header_close#} + {#header_open|@bitOffsetOf#}{#syntax#}@bitOffsetOf(comptime T: type, comptime field_name: [] const u8) comptime_int{#endsyntax#}
@@ -5253,52 +5282,6 @@ fn seq(c: u8) void {
{#see_also|@byteOffsetOf#} {#header_close#} - {#header_open|@breakpoint#} -{#syntax#}@breakpoint(){#endsyntax#}
- - This function inserts a platform-specific debug trap instruction which causes - debuggers to break there. -
-- This function is only valid within function scope. -
- - {#header_close#} - {#header_open|@byteOffsetOf#} -{#syntax#}@byteOffsetOf(comptime T: type, comptime field_name: [] const u8) comptime_int{#endsyntax#}
- - Returns the byte offset of a field relative to its containing struct. -
- {#see_also|@bitOffsetOf#} - {#header_close#} - {#header_open|@alignCast#} -{#syntax#}@alignCast(comptime alignment: u29, ptr: var) var{#endsyntax#}
- - {#syntax#}ptr{#endsyntax#} can be {#syntax#}*T{#endsyntax#}, {#syntax#}fn(){#endsyntax#}, {#syntax#}?*T{#endsyntax#}, - {#syntax#}?fn(){#endsyntax#}, or {#syntax#}[]T{#endsyntax#}. It returns the same type as {#syntax#}ptr{#endsyntax#} - except with the alignment adjusted to the new value. -
-A {#link|pointer alignment safety check|Incorrect Pointer Alignment#} is added - to the generated code to make sure the pointer is aligned as promised.
- - {#header_close#} - {#header_open|@alignOf#} -{#syntax#}@alignOf(comptime T: type) comptime_int{#endsyntax#}
- - This function returns the number of bytes that this type should be aligned to - for the current target to match the C ABI. When the child type of a pointer has - this alignment, the alignment can be omitted from the type. -
-{#syntax#}const assert = @import("std").debug.assert;
-comptime {
- assert(*u32 == *align(@alignOf(u32)) u32);
-}{#endsyntax#}
- - The result is a target-specific compile time constant. It is guaranteed to be - less than or equal to {#link|@sizeOf(T)|@sizeOf#}. -
- {#see_also|Alignment#} - {#header_close#} {#header_open|@boolToInt#}{#syntax#}@boolToInt(value: bool) u1{#endsyntax#}
@@ -5312,6 +5295,18 @@ comptime {
{#header_close#}
+ {#header_open|@breakpoint#}
+ {#syntax#}@breakpoint(){#endsyntax#}
+ + This function inserts a platform-specific debug trap instruction which causes + debuggers to break there. +
++ This function is only valid within function scope. +
+ + {#header_close#} + {#header_open|@bswap#}{#syntax#}@bswap(comptime T: type, value: T) T{#endsyntax#}
{#syntax#}T{#endsyntax#} must be an integer type with bit count evenly divisible by 8.
@@ -5321,6 +5316,14 @@ comptime { {#header_close#} + {#header_open|@byteOffsetOf#} +{#syntax#}@byteOffsetOf(comptime T: type, comptime field_name: [] const u8) comptime_int{#endsyntax#}
+ + Returns the byte offset of a field relative to its containing struct. +
+ {#see_also|@bitOffsetOf#} + {#header_close#} + {#header_open|@bytesToSlice#}{#syntax#}@bytesToSlice(comptime Element: type, bytes: []u8) []Element{#endsyntax#}
@@ -5387,17 +5390,7 @@ comptime {
{#see_also|Import from C Header File|@cImport|@cDefine|@cUndef#} {#header_close#} - {#header_open|@cUndef#} -{#syntax#}@cUndef(comptime name: []u8){#endsyntax#}
- - This function can only occur inside {#syntax#}@cImport{#endsyntax#}. -
-
- This appends #undef $name to the {#syntax#}@cImport{#endsyntax#}
- temporary buffer.
-
{#syntax#}@clz(x: T) U{#endsyntax#}
@@ -5413,6 +5406,7 @@ comptime {
{#see_also|@ctz|@popCount#} {#header_close#} + {#header_open|@cmpxchgStrong#}{#syntax#}@cmpxchgStrong(comptime T: type, ptr: *T, expected_value: T, new_value: T, success_order: AtomicOrder, fail_order: AtomicOrder) ?T{#endsyntax#}
@@ -5468,6 +5462,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
{#syntax#}@typeOf(ptr).alignment{#endsyntax#} must be {#syntax#}>= @sizeOf(T).{#endsyntax#}
{#see_also|Compile Variables|cmpxchgStrong#} {#header_close#} + {#header_open|@compileError#}{#syntax#}@compileError(comptime msg: []u8){#endsyntax#}
@@ -5480,6 +5475,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val and {#syntax#}comptime{#endsyntax#} functions.
{#header_close#} + {#header_open|@compileLog#}{#syntax#}@compileLog(args: ...){#endsyntax#}
@@ -5534,6 +5530,7 @@ test "main" { } {#code_end#} {#header_close#} + {#header_open|@ctz#}
{#syntax#}@ctz(x: T) U{#endsyntax#}
@@ -5549,6 +5546,19 @@ test "main" {
{#see_also|@clz|@popCount#} {#header_close#} + + {#header_open|@cUndef#} +{#syntax#}@cUndef(comptime name: []u8){#endsyntax#}
+ + This function can only occur inside {#syntax#}@cImport{#endsyntax#}. +
+
+ This appends #undef $name to the {#syntax#}@cImport{#endsyntax#}
+ temporary buffer.
+
{#syntax#}@divExact(numerator: T, denominator: T) T{#endsyntax#}
@@ -5615,14 +5625,6 @@ test "main" { {#see_also|@intToEnum#} {#header_close#} - {#header_open|@errSetCast#} -
{#syntax#}@errSetCast(comptime T: DestType, value: var) DestType{#endsyntax#}
- - Converts an error value from one error set to another error set. Attempting to convert an error - which is not in the destination error set results in safety-protected {#link|Undefined Behavior#}. -
- {#header_close#} - {#header_open|@errorName#}{#syntax#}@errorName(err: anyerror) []const u8{#endsyntax#}
@@ -5665,6 +5667,14 @@ test "main" { {#see_also|@intToError#} {#header_close#} + {#header_open|@errSetCast#} +
{#syntax#}@errSetCast(comptime T: DestType, value: var) DestType{#endsyntax#}
+ + Converts an error value from one error set to another error set. Attempting to convert an error + which is not in the destination error set results in safety-protected {#link|Undefined Behavior#}. +
+ {#header_close#} + {#header_open|@export#}{#syntax#}@export(comptime name: []const u8, target: var, linkage: builtin.GlobalLinkage) []const u8{#endsyntax#}
@@ -5733,6 +5743,7 @@ test "main" { This function is only valid within function scope.
{#header_close#} + {#header_open|@handle#}{#syntax#}@handle(){#endsyntax#}
@@ -5743,6 +5754,7 @@ test "main" { This function is only valid within an async function scope.
{#header_close#} + {#header_open|@import#}{#syntax#}@import(comptime path: []u8) (namespace){#endsyntax#}
@@ -5763,6 +5775,7 @@ test "main" { {#see_also|Compile Variables|@embedFile#} {#header_close#} + {#header_open|@inlineCall#}
{#syntax#}@inlineCall(function: X, args: ...) Y{#endsyntax#}
@@ -5842,6 +5855,7 @@ fn add(a: i32, b: i32) i32 { return a + b; } bit count for an integer type is {#syntax#}65535{#endsyntax#}.
{#header_close#} + {#header_open|@memberCount#}{#syntax#}@memberCount(comptime T: type) comptime_int{#endsyntax#}
@@ -5868,6 +5882,7 @@ fn add(a: i32, b: i32) i32 { return a + b; }
{#syntax#}@memberType(comptime T: type, comptime index: usize) type{#endsyntax#}
Returns the field type of a struct or union.
{#header_close#} + {#header_open|@memcpy#}{#syntax#}@memcpy(noalias dest: [*]u8, noalias source: [*]const u8, byte_count: usize){#endsyntax#}
@@ -5886,6 +5901,7 @@ fn add(a: i32, b: i32) i32 { return a + b; }
{#syntax#}const mem = @import("std").mem;
mem.copy(u8, dest[0...byte_count], source[0...byte_count]);{#endsyntax#}
{#header_close#}
+
{#header_open|@memset#}
{#syntax#}@memset(dest: [*]u8, c: u8, byte_count: usize){#endsyntax#}
@@ -5903,6 +5919,7 @@ mem.copy(u8, dest[0...byte_count], source[0...byte_count]);{#endsyntax#}
{#syntax#}const mem = @import("std").mem;
mem.set(u8, dest, c);{#endsyntax#}
{#header_close#}
+
{#header_open|@mod#}
{#syntax#}@mod(numerator: T, denominator: T) T{#endsyntax#}
@@ -5916,6 +5933,7 @@ mem.set(u8, dest, c);{#endsyntax#}
For a function that returns an error code, see {#syntax#}@import("std").math.mod{#endsyntax#}.
{#see_also|@rem#} {#header_close#} + {#header_open|@mulWithOverflow#}{#syntax#}@mulWithOverflow(comptime T: type, a: T, b: T, result: *T) bool{#endsyntax#}
@@ -5924,6 +5942,7 @@ mem.set(u8, dest, c);{#endsyntax#} If no overflow or underflow occurs, returns {#syntax#}false{#endsyntax#}.
{#header_close#} + {#header_open|@newStackCall#}{#syntax#}@newStackCall(new_stack: []u8, function: var, args: ...) var{#endsyntax#}
@@ -5960,6 +5979,7 @@ fn targetFunction(x: i32) usize { } {#code_end#} {#header_close#} + {#header_open|@noInlineCall#}
{#syntax#}@noInlineCall(function: var, args: ...) var{#endsyntax#}
@@ -5982,6 +6002,7 @@ fn add(a: i32, b: i32) i32 {
{#see_also|@inlineCall#} {#header_close#} + {#header_open|@OpaqueType#}{#syntax#}@OpaqueType() type{#endsyntax#}
@@ -6005,6 +6026,7 @@ test "call foo" { } {#code_end#} {#header_close#} + {#header_open|@panic#}
{#syntax#}@panic(message: []const u8) noreturn{#endsyntax#}
@@ -6021,6 +6043,7 @@ test "call foo" { {#see_also|Root Source File#} {#header_close#} + {#header_open|@popCount#}
{#syntax#}@popCount(integer: var) var{#endsyntax#}
Counts the number of bits set in an integer.
@@ -6031,12 +6054,14 @@ test "call foo" { {#see_also|@ctz|@clz#} {#header_close#} + {#header_open|@ptrCast#}{#syntax#}@ptrCast(comptime DestType: type, value: var) DestType{#endsyntax#}
Converts a pointer of one type to a pointer of another type.
{#header_close#} + {#header_open|@ptrToInt#}{#syntax#}@ptrToInt(value: var) usize{#endsyntax#}
@@ -6051,6 +6076,7 @@ test "call foo" {
To convert the other way, use {#link|@intToPtr#}
{#header_close#} + {#header_open|@rem#}{#syntax#}@rem(numerator: T, denominator: T) T{#endsyntax#}
@@ -6064,6 +6090,7 @@ test "call foo" {
For a function that returns an error code, see {#syntax#}@import("std").math.rem{#endsyntax#}.
{#see_also|@mod#} {#header_close#} + {#header_open|@returnAddress#}{#syntax#}@returnAddress(){#endsyntax#}
@@ -6084,19 +6111,14 @@ test "call foo" { Ensures that a function will have a stack alignment of at least {#syntax#}alignment{#endsyntax#} bytes.
{#header_close#} + {#header_open|@setCold#}{#syntax#}@setCold(is_cold: bool){#endsyntax#}
Tells the optimizer that a function is rarely called.
{#header_close#} - {#header_open|@setRuntimeSafety#} -{#syntax#}@setRuntimeSafety(safety_on: bool){#endsyntax#}
- - Sets whether runtime safety checks are on for the scope that contains the function call. -
- {#header_close#} {#header_open|@setEvalBranchQuota#}{#syntax#}@setEvalBranchQuota(new_quota: usize){#endsyntax#}
@@ -6131,6 +6153,7 @@ test "foo" { {#see_also|comptime#} {#header_close#} + {#header_open|@setFloatMode#}
{#syntax#}@setFloatMode(mode: @import("builtin").FloatMode){#endsyntax#}
@@ -6165,6 +6188,7 @@ pub const FloatMode = enum {
{#see_also|Floating Point Operations#} {#header_close#} + {#header_open|@setGlobalLinkage#}{#syntax#}@setGlobalLinkage(global_variable_name, comptime linkage: GlobalLinkage){#endsyntax#}
@@ -6172,6 +6196,15 @@ pub const FloatMode = enum {
{#see_also|Compile Variables#} {#header_close#} + + {#header_open|@setRuntimeSafety#} +{#syntax#}@setRuntimeSafety(safety_on: bool){#endsyntax#}
+ + Sets whether runtime safety checks are on for the scope that contains the function call. +
+ + {#header_close#} + {#header_open|@shlExact#}{#syntax#}@shlExact(value: T, shift_amt: Log2T) T{#endsyntax#}
@@ -6184,6 +6217,7 @@ pub const FloatMode = enum {
{#see_also|@shrExact|@shlWithOverflow#} {#header_close#} + {#header_open|@shlWithOverflow#}{#syntax#}@shlWithOverflow(comptime T: type, a: T, shift_amt: Log2T, result: *T) bool{#endsyntax#}
@@ -6197,6 +6231,7 @@ pub const FloatMode = enum {
{#see_also|@shlExact|@shrExact#} {#header_close#} + {#header_open|@shrExact#}{#syntax#}@shrExact(value: T, shift_amt: Log2T) T{#endsyntax#}
@@ -6238,6 +6273,7 @@ pub const FloatMode = enum { This is a low-level intrinsic. Most code can use {#syntax#}std.math.sqrt{#endsyntax#} instead.
{#header_close#} + {#header_open|@subWithOverflow#}{#syntax#}@subWithOverflow(comptime T: type, a: T, b: T, result: *T) bool{#endsyntax#}
@@ -6246,12 +6282,14 @@ pub const FloatMode = enum { If no overflow or underflow occurs, returns {#syntax#}false{#endsyntax#}.
{#header_close#} + {#header_open|@tagName#}{#syntax#}@tagName(value: var) []const u8{#endsyntax#}
Converts an enum value or union value to a slice of bytes representing the name.
{#header_close#} + {#header_open|@TagType#}{#syntax#}@TagType(T: type) type{#endsyntax#}
@@ -6261,6 +6299,7 @@ pub const FloatMode = enum { For a union, returns the enum type that is used to store the tag value.
{#header_close#} + {#header_open|@This#}{#syntax#}@This() type{#endsyntax#}
@@ -6296,6 +6335,7 @@ fn List(comptime T: type) type { #1047 for details.
{#header_close#} + {#header_open|@truncate#}{#syntax#}@truncate(comptime T: type, integer) T{#endsyntax#}
@@ -6320,6 +6360,7 @@ const b: u8 = @truncate(u8, a);
{#header_close#} + {#header_open|@typeId#}{#syntax#}@typeId(comptime T: type) @import("builtin").TypeId{#endsyntax#}
@@ -6354,6 +6395,7 @@ pub const TypeId = enum { }; {#code_end#} {#header_close#} + {#header_open|@typeInfo#}
{#syntax#}@typeInfo(comptime T: type) @import("builtin").TypeInfo{#endsyntax#}
@@ -6536,6 +6578,7 @@ pub const TypeInfo = union(TypeId) { }; {#code_end#} {#header_close#} + {#header_open|@typeName#}
{#syntax#}@typeName(T: type) []u8{#endsyntax#}
@@ -6543,6 +6586,7 @@ pub const TypeInfo = union(TypeId) {
{#header_close#} + {#header_open|@typeOf#}{#syntax#}@typeOf(expression) type{#endsyntax#}
@@ -6552,6 +6596,7 @@ pub const TypeInfo = union(TypeId) { {#header_close#} {#header_close#} + {#header_open|Build Mode#}
Zig has four build modes: -- cgit v1.2.3