* add `@compileLog(...)` builtin function - Helps debug code running at compile time - See #240 * fix crash when there is an error on the start value of a slice * add implicit cast from int and float types to int and float literals if the value is known at compile time * make array concatenation work with slices in addition to arrays and c string literals * fix compile error message for something not having field access * fix crash when `@setDebugSafety()` was called from a function being evaluated at compile-time * fix compile-time evaluation of overflow math builtins. * avoid debug safety panic handler in builtin.o and compiler_rt.o since we use no debug safety in these modules anyway * add compiler_rt functions for division on ARM - Closes #254 * move default panic handler to std.debug so users can call it manually * std.io.printf supports a width in the format specifier
30 lines
686 B
Zig
30 lines
686 B
Zig
const assert = @import("std").debug.assert;
|
|
const mem = @import("std").mem;
|
|
const io = @import("std").io;
|
|
|
|
const ET = enum {
|
|
SINT: i32,
|
|
UINT: u32,
|
|
|
|
pub fn print(a: &const ET, buf: []u8) -> %usize {
|
|
return switch (*a) {
|
|
ET.SINT => |x| { io.bufPrintInt(buf, x, 10, false, 0) },
|
|
ET.UINT => |x| { io.bufPrintInt(buf, x, 10, false, 0) },
|
|
}
|
|
}
|
|
};
|
|
|
|
fn enumWithMembers() {
|
|
@setFnTest(this);
|
|
|
|
const a = ET.SINT { -42 };
|
|
const b = ET.UINT { 42 };
|
|
var buf: [20]u8 = undefined;
|
|
|
|
assert(%%a.print(buf) == 3);
|
|
assert(mem.eql(buf[0...3], "-42"));
|
|
|
|
assert(%%b.print(buf) == 2);
|
|
assert(mem.eql(buf[0...2], "42"));
|
|
}
|