-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
langref improvements #22714
Open
mlugg
wants to merge
3
commits into
ziglang:master
Choose a base branch
from
mlugg:langref
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+314
−61
Open
langref improvements #22714
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//! Because this file contains fields, it is a type which is intended to be instantiated, and so | ||
//! is named in TitleCase instead of snake_case by convention. | ||
|
||
foo: u32, | ||
bar: u64, | ||
|
||
/// `@This()` can be used to refer to this struct type. In files with fields, is quite common to name the type | ||
/// here, so it can be easily referenced by other declarations. | ||
const TopLevelFields = @This(); | ||
|
||
pub fn init(val: u32) TopLevelFields { | ||
return .{ | ||
.foo = val, | ||
.bar = val * 10, | ||
}; | ||
} | ||
|
||
// syntax |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,20 @@ | ||||||
/// `std.start` imports this file using `@import("root")`, and uses this declaration as the program's | ||||||
/// user-provided entry point. It can return any of the following types: | ||||||
/// * `void` | ||||||
/// * `E!void`, for any error set `E` | ||||||
/// * `u8` | ||||||
/// * `E!u8`, for any error set `E` | ||||||
/// Returning a `void` value from this function will exit with code 0. | ||||||
/// Returning a `u8` value from this function with exit with the given status code. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
/// Returning an error value from this function will print an Error Return Trace and exit with code 1. | ||||||
pub fn main() void { | ||||||
std.debug.print("Hello, World!\n", .{}); | ||||||
} | ||||||
|
||||||
// If uncommented, this declaration would suppress the usual std.start logic, causing | ||||||
// the `main` declaration above to be ignored. | ||||||
//pub const _start = {}; | ||||||
|
||||||
const std = @import("std"); | ||||||
|
||||||
// exe=succeed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
pub export fn main(argc: c_int, argv: [*]const [*:0]const u8) c_int { | ||
const args = argv[0..@intCast(argc)]; | ||
std.debug.print("Hello! argv[0] is '{s}'\n", .{args[0]}); | ||
return 0; | ||
} | ||
|
||
const std = @import("std"); | ||
|
||
// exe=succeed | ||
// link_libc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
pub fn main() void { | ||
@setRuntimeSafety(true); | ||
var x: u8 = 255; | ||
// Let's overflow this integer! | ||
x += 1; | ||
} | ||
|
||
pub const panic = std.debug.FullPanic(myPanic); | ||
|
||
fn myPanic(msg: []const u8, first_trace_addr: ?usize) noreturn { | ||
_ = first_trace_addr; | ||
std.debug.print("Panic! {s}\n", .{msg}); | ||
std.process.exit(1); | ||
} | ||
|
||
const std = @import("std"); | ||
|
||
// exe=fail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/// The presence of this declaration allows the program to override certain behaviors of the standard library. | ||
/// For a full list of available options, see the documentation for `std.Options`. | ||
pub const std_options: std.Options = .{ | ||
// By default, in safe build modes, the standard library will attach a segfault handler to the program to | ||
// print a helpful stack trace if a segmentation fault occurs. Here, we can disable this, or even enable | ||
// it in unsafe build modes. | ||
.enable_segfault_handler = true, | ||
// This is the logging function used by `std.log`. | ||
.logFn = myLogFn, | ||
}; | ||
|
||
fn myLogFn( | ||
comptime level: std.log.Level, | ||
comptime scope: @Type(.enum_literal), | ||
comptime format: []const u8, | ||
args: anytype, | ||
) void { | ||
// We could do anything we want here! | ||
// ...but actually, let's just call the default implementation. | ||
std.log.defaultLog(level, scope, format, args); | ||
} | ||
|
||
const std = @import("std"); | ||
|
||
// syntax |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.