Merge branch 'main' into check_output_len

This commit is contained in:
Chris Boesch 2023-01-21 14:41:35 +01:00 committed by GitHub
commit 68af87518f
9 changed files with 63 additions and 60 deletions

View file

@ -10,7 +10,7 @@ Ziglings is intended for programmers of all experience levels. No
specific language knowledge is expected. Anyone who can install specific language knowledge is expected. Anyone who can install
the current Zig snapshot, setup a copy of Ziglings, and knows the current Zig snapshot, setup a copy of Ziglings, and knows
common language building blocks (if/then/else, loops, and common language building blocks (if/then/else, loops, and
functions) is ready or Ziglings. functions) is ready for Ziglings.
Ziglings is intended to be completely self-contained. If you Ziglings is intended to be completely self-contained. If you
can't solve an exercise from the information you've gleaned so can't solve an exercise from the information you've gleaned so

View file

@ -41,7 +41,7 @@ Verify the installation and build number of `zig` like so:
```bash ```bash
$ zig version $ zig version
0.10.0-dev.3978+xxxxxxxxx 0.11.0-dev.1302+xxxxxxxxx
``` ```
Clone this repository with Git: Clone this repository with Git:
@ -61,8 +61,8 @@ $ zig build
The Zig language is under very active development. In order to be current, The Zig language is under very active development. In order to be current,
Ziglings tracks **development** builds of the Zig compiler rather than Ziglings tracks **development** builds of the Zig compiler rather than
versioned **release** builds. The last stable release was `0.9.1`, but Ziglings versioned **release** builds. The last stable release was `0.10.0`, but Ziglings
needs a dev build with pre-release version "0.10.0" and a build number at least needs a dev build with pre-release version "0.11.0" and a build number at least
as high as that shown in the example version check above. as high as that shown in the example version check above.
It is likely that you'll download a build which is _greater_ than the minimum. It is likely that you'll download a build which is _greater_ than the minimum.
@ -81,6 +81,8 @@ about input:
### Version Changes ### Version Changes
Version-0.11.0-dev.1302+d813cef42
* *2023-01-14* zig 0.11.0-dev.1302 - changes in `@addWithOverflow` (now returns a tuple) and `@typeInfo`; temporary disabled async functionality
* *2022-09-09* zig 0.10.0-dev.3978 - change in `NativeTargetInfo.detect` in build * *2022-09-09* zig 0.10.0-dev.3978 - change in `NativeTargetInfo.detect` in build
* *2022-09-06* zig 0.10.0-dev.3880 - Ex 074 correctly fails again: comptime array len * *2022-09-06* zig 0.10.0-dev.3880 - Ex 074 correctly fails again: comptime array len
* *2022-08-29* zig 0.10.0-dev.3685 - `@typeName()` output change, stage1 req. for async * *2022-08-29* zig 0.10.0-dev.3685 - `@typeName()` output change, stage1 req. for async
@ -160,6 +162,7 @@ Core Language
* [x] Quoted identifiers @"" * [x] Quoted identifiers @""
* [x] Anonymous structs/tuples/lists * [x] Anonymous structs/tuples/lists
* [ ] Async <--- IN PROGRESS! * [ ] Async <--- IN PROGRESS!
* [ ] Interfaces
## Contributing ## Contributing

View file

@ -418,47 +418,48 @@ const exercises = [_]Exercise{
.main_file = "083_anonymous_lists.zig", .main_file = "083_anonymous_lists.zig",
.output = "I say hello!", .output = "I say hello!",
}, },
.{ // disabled because of https://github.com/ratfactor/ziglings/issues/163
.main_file = "084_async.zig", // .{
.output = "foo() A\nfoo() B", // .main_file = "084_async.zig",
.hint = "Read the facts. Use the facts.", // .output = "foo() A",
.@"async" = true, // .hint = "Read the facts. Use the facts.",
}, // .@"async" = true,
.{ // },
.main_file = "085_async2.zig", // .{
.output = "Hello async!", // .main_file = "085_async2.zig",
.@"async" = true, // .output = "Hello async!",
}, // .@"async" = true,
.{ // },
.main_file = "086_async3.zig", // .{
.output = "5 4 3 2 1", // .main_file = "086_async3.zig",
.@"async" = true, // .output = "5 4 3 2 1",
}, // .@"async" = true,
.{ // },
.main_file = "087_async4.zig", // .{
.output = "1 2 3 4 5", // .main_file = "087_async4.zig",
.@"async" = true, // .output = "1 2 3 4 5",
}, // .@"async" = true,
.{ // },
.main_file = "088_async5.zig", // .{
.output = "Example Title.", // .main_file = "088_async5.zig",
.@"async" = true, // .output = "Example Title.",
}, // .@"async" = true,
.{ // },
.main_file = "089_async6.zig", // .{
.output = ".com: Example Title, .org: Example Title.", // .main_file = "089_async6.zig",
.@"async" = true, // .output = ".com: Example Title, .org: Example Title.",
}, // .@"async" = true,
.{ // },
.main_file = "090_async7.zig", // .{
.output = "beef? BEEF!", // .main_file = "090_async7.zig",
.@"async" = true, // .output = "beef? BEEF!",
}, // .@"async" = true,
.{ // },
.main_file = "091_async8.zig", // .{
.output = "ABCDEF", // .main_file = "091_async8.zig",
.@"async" = true, // .output = "ABCDEF",
}, // .@"async" = true,
// },
}; };
/// Check the zig version to make sure it can compile the examples properly. /// Check the zig version to make sure it can compile the examples properly.
@ -713,9 +714,10 @@ const ZiglingStep = struct {
zig_args.append("build-exe") catch unreachable; zig_args.append("build-exe") catch unreachable;
// Enable the stage 1 compiler if using the async feature // Enable the stage 1 compiler if using the async feature
if (self.exercise.@"async") { // disabled because of https://github.com/ratfactor/ziglings/issues/163
zig_args.append("-fstage1") catch unreachable; // if (self.exercise.@"async") {
} // zig_args.append("-fstage1") catch unreachable;
// }
if (builder.color != .auto) { if (builder.color != .auto) {
zig_args.append("--color") catch unreachable; zig_args.append("--color") catch unreachable;

View file

@ -17,7 +17,7 @@ pub fn main() void {
var num: u8 = 1; var num: u8 = 1;
var more_nums = [_]u8{ 1, 1, 1, 1 }; var more_nums = [_]u8{ 1, 1, 1, 1 };
// Let's pass a reference to num to our function and print it: // Let's pass the num reference to our function and print it:
makeFive(&num); makeFive(&num);
std.debug.print("num: {}, ", .{num}); std.debug.print("num: {}, ", .{num});

View file

@ -1,7 +1,7 @@
// //
// Zig has support for IEEE-754 floating-point numbers in these // Zig has support for IEEE-754 floating-point numbers in these
// specific sizes: f16, f32, f64, f128. Floating point literals // specific sizes: f16, f32, f64, f80, and f128. Floating point
// may be writen in scientific notation: // literals may be written in scientific notation:
// //
// const a1: f32 = 1200.0; // 1,200 // const a1: f32 = 1200.0; // 1,200
// const a2: f32 = 1.2e+3; // 1,200 // const a2: f32 = 1.2e+3; // 1,200

View file

@ -38,14 +38,12 @@ pub fn main() void {
// Let's try it with a tiny 4-bit integer size to make it clear: // Let's try it with a tiny 4-bit integer size to make it clear:
const a: u4 = 0b1101; const a: u4 = 0b1101;
const b: u4 = 0b0101; const b: u4 = 0b0101;
var my_result: u4 = undefined; const my_result = @addWithOverflow(a, b);
var overflowed: bool = undefined;
overflowed = @addWithOverflow(u4, a, b, &my_result);
// Check out our fancy formatting! b:0>4 means, "print // Check out our fancy formatting! b:0>4 means, "print
// as a binary number, zero-pad right-aligned four digits." // as a binary number, zero-pad right-aligned four digits."
// The print() below will produce: "1101 + 0101 = 0010 (true)". // The print() below will produce: "1101 + 0101 = 0010 (true)".
print("{b:0>4} + {b:0>4} = {b:0>4} ({})", .{ a, b, my_result, overflowed }); print("{b:0>4} + {b:0>4} = {b:0>4} ({s})", .{ a, b, my_result[0], if (my_result[1] == 1) "true" else "false" });
// Let's make sense of this answer. The value of 'b' in decimal is 5. // Let's make sense of this answer. The value of 'b' in decimal is 5.
// Let's add 5 to 'a' but go one by one and see where it overflows: // Let's add 5 to 'a' but go one by one and see where it overflows:

View file

@ -100,7 +100,7 @@ pub fn main() void {
// //
// pub const StructField = struct { // pub const StructField = struct {
// name: []const u8, // name: []const u8,
// field_type: type, // type: type,
// default_value: anytype, // default_value: anytype,
// is_comptime: bool, // is_comptime: bool,
// alignment: comptime_int, // alignment: comptime_int,

View file

@ -41,7 +41,7 @@ pub fn main() void {
const fields = @typeInfo(Narcissus).Struct.fields; const fields = @typeInfo(Narcissus).Struct.fields;
??? { ??? {
if (field.field_type != void) { if (field.type != void) {
print(" {s}", .{field.name}); print(" {s}", .{field.name});
} }
} }

View file

@ -4,8 +4,8 @@
// //
// .{ // .{
// false, // false,
// @as(u32, 15); // @as(u32, 15),
// @as(i64, 67.12); // @as(f64, 67.12)
// } // }
// //
// We call these "tuples", which is a term used by many // We call these "tuples", which is a term used by many
@ -96,7 +96,7 @@ fn printTuple(tuple: anytype) void {
// //
// pub const StructField = struct { // pub const StructField = struct {
// name: []const u8, // name: []const u8,
// field_type: type, // type: type,
// default_value: anytype, // default_value: anytype,
// is_comptime: bool, // is_comptime: bool,
// alignment: comptime_int, // alignment: comptime_int,