diff --git a/CMakeLists.txt b/CMakeLists.txt index 95796385ca..8aa6dff6a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -201,29 +201,29 @@ else() COMPILE_FLAGS ${ZIG_LLD_COMPILE_FLAGS} LINK_FLAGS " " ) - target_include_directories(embedded_lld_lib PUBLIC + target_include_directories(embedded_lld_lib PRIVATE "${CMAKE_SOURCE_DIR}/deps/lld/include" "${CMAKE_SOURCE_DIR}/deps/lld-prebuilt" ) - target_include_directories(embedded_lld_elf PUBLIC + target_include_directories(embedded_lld_elf PRIVATE "${CMAKE_SOURCE_DIR}/deps/lld/ELF" "${CMAKE_SOURCE_DIR}/deps/lld/include" "${CMAKE_SOURCE_DIR}/deps/lld-prebuilt/ELF" "${CMAKE_SOURCE_DIR}/deps/lld-prebuilt" ) - target_include_directories(embedded_lld_coff PUBLIC + target_include_directories(embedded_lld_coff PRIVATE "${CMAKE_SOURCE_DIR}/deps/lld/COFF" "${CMAKE_SOURCE_DIR}/deps/lld/include" "${CMAKE_SOURCE_DIR}/deps/lld-prebuilt/COFF" "${CMAKE_SOURCE_DIR}/deps/lld-prebuilt" ) - target_include_directories(embedded_lld_mingw PUBLIC + target_include_directories(embedded_lld_mingw PRIVATE "${CMAKE_SOURCE_DIR}/deps/lld/MinGW" "${CMAKE_SOURCE_DIR}/deps/lld/include" "${CMAKE_SOURCE_DIR}/deps/lld-prebuilt/MinGW" "${CMAKE_SOURCE_DIR}/deps/lld-prebuilt" ) - target_include_directories(embedded_lld_wasm PUBLIC + target_include_directories(embedded_lld_wasm PRIVATE "${CMAKE_SOURCE_DIR}/deps/lld/wasm" "${CMAKE_SOURCE_DIR}/deps/lld/include" "${CMAKE_SOURCE_DIR}/deps/lld-prebuilt/wasm" @@ -482,10 +482,10 @@ set(ZIG_STD_FILES "os/darwin_errno.zig" "os/get_user_id.zig" "os/index.zig" - "os/linux.zig" - "os/linux_errno.zig" - "os/linux_i386.zig" - "os/linux_x86_64.zig" + "os/linux/index.zig" + "os/linux/errno.zig" + "os/linux/i386.zig" + "os/linux/x86_64.zig" "os/path.zig" "os/windows/error.zig" "os/windows/index.zig" diff --git a/doc/langref.html.in b/doc/langref.html.in index 3a2398ef05..29a40c86a5 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -36,25 +36,47 @@ code { font-size: 12pt; } - @media screen and (min-width: 28.75em) { + pre > code { + display: block; + overflow: auto; + } + .table-wrapper { + width: 100%; + overflow-y: auto; + } + /* Desktop */ + @media screen and (min-width: 56.25em) { #nav { width: 20em; height: 100%; - overflow-y: scroll; position: fixed; + overflow-y: scroll; left: 0; top: 0; + padding-left: 1em; } #contents { - max-width: 50em; + max-width: 60em; padding-left: 22em; + padding: 1em; + padding-left: 24em; + } + } + /* Mobile */ + @media screen and (max-width: 56.25em) { + body, code { + font-size: small; + } + #nav { + border-bottom: 1px solid grey; } }
{#header_open|Introduction#} @@ -112,16 +134,6 @@ pub fn main() void {

{#see_also|Values|@import|Errors|Root Source File#} {#header_close#} - {#header_open|Source Encoding#} -

Zig source code is encoded in UTF-8. An invalid UTF-8 byte sequence results in a compile error.

-

Throughout all zig source code (including in comments), some codepoints are never allowed:

- -

The codepoint U+000a (LF) (which is encoded as the single-byte value 0x0a) is the line terminator character. This character always terminates a line of zig source code (except possbly the last line of the file).

-

For some discussion on the rationale behind these design decisions, see issue #663

- {#header_close#} {#header_open|Values#} {#code_begin|exe|values#} const std = @import("std"); @@ -173,6 +185,7 @@ pub fn main() %void { } {#code_end#} {#header_open|Primitive Types#} +
@@ -398,9 +411,11 @@ pub fn main() %void { an error code
+
{#see_also|Integers|Floats|void|Errors#} {#header_close#} {#header_open|Primitive Values#} +
@@ -427,6 +442,7 @@ pub fn main() %void { refers to the thing in immediate scope
+
{#see_also|Nullables|this#} {#header_close#} {#header_open|String Literals#} @@ -451,6 +467,7 @@ test "string literals" { {#code_end#} {#see_also|Arrays|Zig Test#} {#header_open|Escape Sequences#} +
@@ -497,6 +514,7 @@ test "string literals" { hexadecimal 24-bit Unicode character code UTF-8 encoded (6 digits)
+

Note that the maximum valid Unicode point is 0x10ffff.

{#header_close#} {#header_open|Multiline String Literals#} @@ -674,6 +692,7 @@ pub fn main() %void { {#header_close#} {#header_open|Operators#} {#header_open|Table of Operators#} +
@@ -1246,6 +1265,7 @@ const ptr = &x;
+
{#header_close#} {#header_open|Precedence#}
x() x[] x.y
@@ -2755,6 +2775,16 @@ test "implicitly cast to const pointer" {
       use the C calling convention may pass structs and unions by value.
       

{#header_close#} + {#header_open|Function Reflection#} + {#code_begin|test#} +const assert = @import("std").debug.assert; + +test "fn reflection" { + assert(@typeOf(assert).ReturnType == void); + assert(@typeOf(assert).is_var_args == false); +} + {#code_end#} + {#header_close#} {#header_close#} {#header_open|Errors#}

@@ -2968,6 +2998,31 @@ fn createFoo(param: i32) %Foo { {#see_also|defer|if|switch#} + {#header_open|Error Union Type#} +

An error union is created by putting a % in front of a type. + You can use compile-time reflection to access the child type of an error union:

+ {#code_begin|test#} +const assert = @import("std").debug.assert; + +error SomeError; + +test "error union" { + var foo: %i32 = undefined; + + // Implicitly cast from child type of an error union: + foo = 1234; + + // Implicitly cast from an error set: + foo = error.SomeError; + + // Use compile-time reflection to access the child type of an error union: + comptime assert(@typeOf(foo).Child == i32); +} + {#code_end#} + {#header_close#} + {#header_open|Error Set Type#} +

TODO

+ {#header_close#} {#header_close#} {#header_open|Nullables#}

@@ -3069,6 +3124,24 @@ fn doAThing(nullable_foo: ?&Foo) void { The optimizer can sometimes make better decisions knowing that pointer arguments cannot be null.

+ {#header_open|Nullable Type#} +

A nullable is created by putting ? in front of a type. You can use compile-time + reflection to access the child type of a nullable:

+ {#code_begin|test#} +const assert = @import("std").debug.assert; + +test "nullable type" { + // Declare a nullable and implicitly cast from null: + var foo: ?i32 = null; + + // Implicitly cast from child type of a nullable + foo = 1234; + + // Use compile-time reflection to access the child type of the nullable: + comptime assert(@typeOf(foo).Child == i32); +} + {#code_end#} + {#header_close#} {#header_close#} {#header_open|Casting#}

TODO: explain implicit vs explicit casting

@@ -3804,6 +3877,17 @@ comptime { @cInclude, @cDefine, and @cUndef work within this expression, appending to a temporary buffer which is then parsed as C code.

+

+ Usually you should only have one @cImport in your entire application, because it saves the compiler + from invoking clang multiple times, and prevents inline functions from being duplicated. +

+

+ Reasons for having multiple @cImport expressions would be: +

+
    +
  • To avoid a symbol collision, for example if foo.h and bar.h both #define CONNECTION_COUNT
  • +
  • To analyze the C code with different preprocessor defines
  • +
{#see_also|Import from C Header File|@cInclude|@cDefine|@cUndef#} {#header_close#} {#header_open|@cInclude#} @@ -4133,17 +4217,28 @@ fn add(a: i32, b: i32) i32 { return a + b; } {#header_open|@memberCount#}
@memberCount(comptime T: type) -> (number literal)

- This function returns the number of enum values in an enum type. + This function returns the number of members in a struct, enum, or union type.

The result is a compile time constant.

+

+ It does not include functions, variables, or constants. +

{#header_close#} {#header_open|@memberName#} -

TODO

+
@memberName(comptime T: type, comptime index: usize) -> [N]u8
+

Returns the field name of a struct, union, or enum.

+

+ The result is a compile time constant. +

+

+ It does not include functions, variables, or constants. +

{#header_close#} {#header_open|@memberType#} -

TODO

+
@memberType(comptime T: type, comptime index: usize) -> type
+

Returns the field type of a struct or union.

{#header_close#} {#header_open|@memcpy#}
@memcpy(noalias dest: &u8, noalias source: &const u8, byte_count: usize)
@@ -5533,6 +5628,16 @@ fn readU32Be() u32 {}

{#header_close#} {#header_close#} + {#header_open|Source Encoding#} +

Zig source code is encoded in UTF-8. An invalid UTF-8 byte sequence results in a compile error.

+

Throughout all zig source code (including in comments), some codepoints are never allowed:

+
    +
  • Ascii control characters, except for U+000a (LF): U+0000 - U+0009, U+000b - U+0001f, U+007f. (Note that Windows line endings (CRLF) are not allowed, and hard tabs are not allowed.)
  • +
  • Non-Ascii Unicode line endings: U+0085 (NEL), U+2028 (LS), U+2029 (PS).
  • +
+

The codepoint U+000a (LF) (which is encoded as the single-byte value 0x0a) is the line terminator character. This character always terminates a line of zig source code (except possbly the last line of the file).

+

For some discussion on the rationale behind these design decisions, see issue #663

+ {#header_close#} {#header_open|Grammar#}
Root = many(TopLevelItem) EOF
 
@@ -5701,9 +5806,6 @@ ContainerDecl = option("extern" | "packed")
         
  • Together we serve end users.
  • {#header_close#} - {#header_open|TODO#} -

    TODO: document changes from a31b23c46ba2a8c28df01adc1aa0b4d878b9a5cf (compile time reflection additions)

    - {#header_close#}