Browse Source

Revised exercises due to the changes of Zig version 0.11.0-dev.3853

Chris Boesch 2 years ago
parent
commit
a5a36337e8

+ 4 - 3
README.md

@@ -45,7 +45,7 @@ Verify the installation and build number of `zig` like so:
 
 
 ```
 ```
 $ zig version
 $ zig version
-0.11.0-dev.3747+xxxxxxxxx
+0.11.0-dev.3853+xxxxxxxxx
 ```
 ```
 
 
 Clone this repository with Git:
 Clone this repository with Git:
@@ -90,7 +90,8 @@ that if you update one, you may need to also update the other.
 ### Version Changes
 ### Version Changes
 
 
 Version-0.11.0-dev.3747+7b5bd3a93
 Version-0.11.0-dev.3747+7b5bd3a93
-* *2023-05-25* zig 0.11.0-dev.3747 - `@enumToInt` is now `@intFromEnum` and `@intToFloat` is now `@floatFromInt`
+* *2023-06-26* zig 0.11.0-dev.3853 - removal of destination type from all cast builtins
+* *2023-06-20* zig 0.11.0-dev.3747 - `@enumToInt` is now `@intFromEnum` and `@intToFloat` is now `@floatFromInt`
 * *2023-05-25* zig 0.11.0-dev.3295 - `std.debug.TTY` is now `std.io.tty`
 * *2023-05-25* zig 0.11.0-dev.3295 - `std.debug.TTY` is now `std.io.tty`
 * *2023-04-30* zig 0.11.0-dev.2704 - use of the new `std.Build.ExecutableOptions.link_libc` field
 * *2023-04-30* zig 0.11.0-dev.2704 - use of the new `std.Build.ExecutableOptions.link_libc` field
 * *2023-04-12* zig 0.11.0-dev.2560 - changes in `std.Build` - remove run() and install()
 * *2023-04-12* zig 0.11.0-dev.2560 - changes in `std.Build` - remove run() and install()
@@ -211,7 +212,7 @@ Zig Standard Library
 
 
 * [X] String formatting
 * [X] String formatting
 * [X] Testing
 * [X] Testing
-* [ ] Tokenization
+* [X] Tokenization
 
 
 ## Contributing
 ## Contributing
 
 

+ 1 - 1
build.zig

@@ -104,7 +104,7 @@ pub fn build(b: *Build) !void {
             const WINAPI = std.os.windows.WINAPI;
             const WINAPI = std.os.windows.WINAPI;
             const DWORD = std.os.windows.DWORD;
             const DWORD = std.os.windows.DWORD;
             const ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004;
             const ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004;
-            const STD_ERROR_HANDLE = @bitCast(DWORD, @as(i32, -12));
+            const STD_ERROR_HANDLE: DWORD = @bitCast(@as(i32, -12));
             extern "kernel32" fn GetStdHandle(id: DWORD) callconv(WINAPI) ?*anyopaque;
             extern "kernel32" fn GetStdHandle(id: DWORD) callconv(WINAPI) ?*anyopaque;
             extern "kernel32" fn GetConsoleMode(console: ?*anyopaque, out_mode: *DWORD) callconv(WINAPI) u32;
             extern "kernel32" fn GetConsoleMode(console: ?*anyopaque, out_mode: *DWORD) callconv(WINAPI) u32;
             extern "kernel32" fn SetConsoleMode(console: ?*anyopaque, mode: DWORD) callconv(WINAPI) u32;
             extern "kernel32" fn SetConsoleMode(console: ?*anyopaque, mode: DWORD) callconv(WINAPI) u32;

+ 2 - 1
exercises/016_for2.zig

@@ -29,7 +29,8 @@ pub fn main() void {
         // Note that we convert the usize i to a u32 with
         // Note that we convert the usize i to a u32 with
         // @intCast(), a builtin function just like @import().
         // @intCast(), a builtin function just like @import().
         // We'll learn about these properly in a later exercise.
         // We'll learn about these properly in a later exercise.
-        const place_value = std.math.pow(u32, 2, @intCast(u32, i));
+        const i_u32: u32 = @intCast(i);
+        const place_value = std.math.pow(u32, 2, i_u32);
         value += place_value * bit;
         value += place_value * bit;
     }
     }
 
 

+ 1 - 1
exercises/058_quiz7.zig

@@ -429,7 +429,7 @@ fn printTrip(trip: []?TripItem) void {
     // We convert the usize length to a u8 with @intCast(), a
     // We convert the usize length to a u8 with @intCast(), a
     // builtin function just like @import().  We'll learn about
     // builtin function just like @import().  We'll learn about
     // these properly in a later exercise.
     // these properly in a later exercise.
-    var i: u8 = @intCast(u8, trip.len);
+    var i: u8 = @intCast(trip.len);
 
 
     while (i > 0) {
     while (i > 0) {
         i -= 1;
         i -= 1;

+ 1 - 1
exercises/069_comptime4.zig

@@ -47,7 +47,7 @@ fn makeSequence(comptime T: type, ??? size: usize) [???]T {
     var i: usize = 0;
     var i: usize = 0;
 
 
     while (i < size) : (i += 1) {
     while (i < size) : (i += 1) {
-        sequence[i] = @intCast(T, i) + 1;
+        sequence[i] = @as(T, @intCast(i)) + 1;
     }
     }
 
 
     return sequence;
     return sequence;

+ 1 - 1
exercises/075_quiz8.zig

@@ -204,7 +204,7 @@ pub fn main() void {
 }
 }
 
 
 fn printTrip(trip: []?TripItem) void {
 fn printTrip(trip: []?TripItem) void {
-    var i: u8 = @intCast(u8, trip.len);
+    var i: u8 = @intCast(trip.len);
 
 
     while (i > 0) {
     while (i > 0) {
         i -= 1;
         i -= 1;

+ 2 - 1
exercises/096_memory_allocation.zig

@@ -45,7 +45,8 @@ fn runningAverage(arr: []const f64, avg: []f64) void {
 
 
     for (0.., arr) |index, val| {
     for (0.., arr) |index, val| {
         sum += val;
         sum += val;
-        avg[index] = sum / @floatFromInt(f64, index + 1);
+        const f_index: f64 = @floatFromInt(index + 1);
+        avg[index] = sum / f_index;
     }
     }
 }
 }
 
 

+ 1 - 1
exercises/098_bit_manipulation2.zig

@@ -53,7 +53,7 @@ fn isPangram(str: []const u8) bool {
             // and are numbered sequentially, we simply subtract the
             // and are numbered sequentially, we simply subtract the
             // first letter (in this case the 'a') from the character
             // first letter (in this case the 'a') from the character
             // found, and thus get the position of the desired bit
             // found, and thus get the position of the desired bit
-            bits |= @as(u32, 1) << @truncate(u5, ascii.toLower(c) - 'a');
+            bits |= @as(u32, 1) << @truncate(ascii.toLower(c) - 'a');
         }
         }
     }
     }
     // last we return the comparison if all 26 bits are set,
     // last we return the comparison if all 26 bits are set,

+ 1 - 1
patches/patches/078_sentinels3.patch

@@ -1,4 +1,4 @@
 24c24
 24c24
 <     const printable: [*:0]const u8 = ???;
 <     const printable: [*:0]const u8 = ???;
 ---
 ---
->     const printable: [*:0]const u8 = @ptrCast([*:0]const u8, data);
+>     const printable: [*:0]const u8 = @ptrCast(data);

+ 1 - 1
patches/patches/096_memory_allocation.patch

@@ -1,4 +1,4 @@
-66c66
+67c67
 <     var avg: []f64 = ???;
 <     var avg: []f64 = ???;
 ---
 ---
 >     var avg: []f64 = try allocator.alloc(f64, arr.len);
 >     var avg: []f64 = try allocator.alloc(f64, arr.len);

+ 1 - 1
src/compat.zig

@@ -15,7 +15,7 @@ const print = if (@hasDecl(debug, "print")) debug.print else debug.warn;
 // When changing this version, be sure to also update README.md in two places:
 // When changing this version, be sure to also update README.md in two places:
 //     1) Getting Started
 //     1) Getting Started
 //     2) Version Changes
 //     2) Version Changes
-const needed_version_str = "0.11.0-dev.3747";
+const needed_version_str = "0.11.0-dev.3853";
 
 
 fn isCompatible() bool {
 fn isCompatible() bool {
     if (!@hasDecl(builtin, "zig_version") or !@hasDecl(std, "SemanticVersion")) {
     if (!@hasDecl(builtin, "zig_version") or !@hasDecl(std, "SemanticVersion")) {