diff --git a/bootstrap/Compilation.zig b/bootstrap/Compilation.zig index 39ca4e2..e912026 100644 --- a/bootstrap/Compilation.zig +++ b/bootstrap/Compilation.zig @@ -1520,35 +1520,6 @@ pub const Builder = struct { _ = expected_type; // autofix unreachable; }, - .assert => { - assert(argument_node_list.len == 1); - const boolean = try builder.resolveRuntimeValue(unit, context, Type.Expect{ .type = .bool }, argument_node_list[0], .right); - switch (boolean.value) { - .@"comptime" => |ct| switch (ct) { - .bool => |value| switch (value) { - true => {}, - false => { - @panic("Assert failed at comptime"); - }, - }, - else => |t| @panic(@tagName(t)), - }, - .runtime => |instruction_index| { - const true_block = try builder.newBasicBlock(unit, context); - const false_block = try builder.newBasicBlock(unit, context); - - try builder.branch(unit, context, instruction_index, true_block, false_block); - - builder.current_basic_block = false_block; - try builder.buildTrap(unit, context); - - builder.current_basic_block = true_block; - }, - else => |t| @panic(@tagName(t)), - } - - return undefined; - }, .@"error" => { assert(argument_node_list.len == 1); // TODO: type diff --git a/bootstrap/backend/llvm.zig b/bootstrap/backend/llvm.zig index 6ec2aa5..11b071f 100644 --- a/bootstrap/backend/llvm.zig +++ b/bootstrap/backend/llvm.zig @@ -1180,7 +1180,7 @@ pub const LLVM = struct { for (sema_function_prototype.argument_types) |argument_type_index| { switch (unit.types.get(argument_type_index).*) { // TODO: ABI - .integer, .pointer, .@"enum", .@"struct", .slice => try parameter_types.append(context.allocator, try llvm.getType(unit, context, argument_type_index)), + .integer, .pointer, .@"enum", .@"struct", .slice, .bool, => try parameter_types.append(context.allocator, try llvm.getType(unit, context, argument_type_index)), else => |t| @panic(@tagName(t)), } // arg_types.appendAssumeCapacity(llvm_argument_type); @@ -2878,7 +2878,8 @@ pub fn codegen(unit: *Compilation.Unit, context: *const Compilation.Context) !vo switch (unit.types.get(argument_type_index).*) { .void, .noreturn, .type => unreachable, .comptime_int => unreachable, - .bool => unreachable, + .bool => {}, + // .bool => unreachable, .@"struct" => {}, .@"enum" => {}, .function => unreachable, diff --git a/lib/std/os.nat b/lib/std/os.nat index 3a8c4ec..433cc5e 100644 --- a/lib/std/os.nat +++ b/lib/std/os.nat @@ -1,5 +1,6 @@ const std = #import("std"); const Allocator = std.Allocator; +const assert = std.assert; const current = #import("builtin").os; const system = switch (current) { .linux => linux, @@ -192,7 +193,7 @@ const current_executable_path = fn(buffer: [:0]u8) ?[]u8 { } i += 1; } - #assert(i < buffer.len); + assert(i < buffer.len); return result[0..i]; } else { diff --git a/lib/std/std.nat b/lib/std/std.nat index 85960b9..10b95d3 100644 --- a/lib/std/std.nat +++ b/lib/std/std.nat @@ -30,7 +30,7 @@ const format_usize = fn(n: usize, buffer: &[65]u8) []u8 { index -= 1; const ch = '0' + digit; buffer[index] = ch; - #assert(buffer[index] == ch); + assert(buffer[index] == ch); absolute /= 10; if (absolute == 0) { @@ -44,7 +44,7 @@ const format_usize = fn(n: usize, buffer: &[65]u8) []u8 { const print_usize = fn(n: usize) void { var buffer: [65]u8 = undefined; const bytes = format_usize(n, buffer = buffer.&); - #assert(bytes.len < buffer.len); + assert(bytes.len < buffer.len); const file_descriptor = os.StdFileDescriptor.get(descriptor = .stdout); const file_writer = FileWriter{ .descriptor = file_descriptor, diff --git a/test/standalone/assert/main.nat b/test/standalone/assert/main.nat index 3962d69..93f3035 100644 --- a/test/standalone/assert/main.nat +++ b/test/standalone/assert/main.nat @@ -1,7 +1,10 @@ +const std = #import("std"); +const assert = std.assert; + const main = fn() s32 { - #assert(true); + assert(true); var a: s32 = 1; const is_not_one = a != 1; - #assert(!is_not_one); + assert(!is_not_one); return 0; } diff --git a/test/standalone/bit_struct/main.nat b/test/standalone/bit_struct/main.nat index 6b8e9da..dfa8c7f 100644 --- a/test/standalone/bit_struct/main.nat +++ b/test/standalone/bit_struct/main.nat @@ -1,3 +1,6 @@ +const std = #import("std"); +const assert = std.assert; + const BitStruct = struct(u8) { a: bool, b: bool, @@ -13,7 +16,7 @@ const main = fn () s32 { .d = 0, }; const bitcast_bs: u8 = #cast(bs); - #assert(bitcast_bs == 6); + assert(bitcast_bs == 6); const const_bs = BitStruct{ .a = true, @@ -22,6 +25,6 @@ const main = fn () s32 { .d = 0, }; const bitcast_const_bs: u8 = #cast(const_bs); - #assert(bitcast_const_bs == 5); + assert(bitcast_const_bs == 5); return 0; } diff --git a/test/standalone/bit_struct_call/main.nat b/test/standalone/bit_struct_call/main.nat index 2c99df8..fdec759 100644 --- a/test/standalone/bit_struct_call/main.nat +++ b/test/standalone/bit_struct_call/main.nat @@ -1,3 +1,6 @@ +const std = #import("std"); +const assert = std.assert; + const A = struct(u8) { a: u4, b: u4, @@ -21,8 +24,8 @@ const main = fn () s32 { }; const b = transform(a); - #assert(a.a == b.a); - #assert(a.b == b.b); + assert(a.a == b.a); + assert(a.b == b.b); return 0; } diff --git a/test/standalone/slice_len/main.nat b/test/standalone/slice_len/main.nat index 46edb2e..4cae0c7 100644 --- a/test/standalone/slice_len/main.nat +++ b/test/standalone/slice_len/main.nat @@ -1,8 +1,10 @@ +const std = #import("std"); +const assert = std.assert; const main = fn() s32 { var buffer: [65]u8 = undefined; const slice = foo(5, buffer.&); - #assert(slice.len + 5 == buffer.len); + assert(slice.len + 5 == buffer.len); const result: u32 = #cast(slice.len + 5 - buffer.len); return #cast(result); }