Replace compile_assert with #assert

This commit is contained in:
gingerBill
2018-02-24 19:03:29 +00:00
parent b2461f7192
commit 35ba5771a5
17 changed files with 96 additions and 69 deletions
+4 -3
View File
@@ -101,13 +101,13 @@ general_stuff :: proc() {
// If the type expression is `struct`, `union`, `enum`, `proc`, or `bit_field`, the types will always been distinct.
Int32 :: i32;
compile_assert(Int32 == i32);
#assert(Int32 == i32);
My_Int32 :: distinct i32;
compile_assert(My_Int32 != i32);
#assert(My_Int32 != i32);
My_Struct :: struct{x: int};
compile_assert(My_Struct != struct{x: int});
#assert(My_Struct != struct{x: int});
}
}
@@ -760,6 +760,7 @@ complete_switch :: proc() {
}
}
main :: proc() {
when true {
general_stuff();
+1 -1
View File
@@ -328,7 +328,7 @@ miscellany :: proc() {
*/
// assert(false)
// compile_assert(false)
// #assert(false)
// panic("Panic message goes here")
}
+2 -2
View File
@@ -171,8 +171,8 @@ new_builtins :: proc() {
{
// Compile time assert
COND :: true;
compile_assert(COND);
// compile_assert(!COND)
#assert(COND);
// #assert(!COND)
// Runtime assert
x := true;
+2 -2
View File
@@ -43,7 +43,7 @@ syntax :: proc() {
Thing2 :: struct {x: f32, y: int, z: ^[]int};
// Slice interals are now just a `ptr+len+cap`
slice: []int; compile_assert(size_of(slice) == 3*size_of(int));
slice: []int; #assert(size_of(slice) == 3*size_of(int));
// Helper type - Help the reader understand what it is quicker
My_Int :: #type int;
@@ -218,7 +218,7 @@ loops :: proc() {
name := "你好,世界";
fmt.println(name);
for r in name {
compile_assert(type_of(r) == rune);
#assert(type_of(r) == rune);
fmt.printf("%r\n", r);
}
+3 -3
View File
@@ -24,7 +24,7 @@ when true {
* ..< and ... removed and replace with .. (half-closed range)
Changed:
* `compile_assert` and `assert` return the value of the condition for semantic reasons
* `#assert` and `assert` return the value of the condition for semantic reasons
* thread_local -> #thread_local
* #include -> #load
* Files only get checked if they are actually used
@@ -159,8 +159,8 @@ when true {
fmt.println(i);
}
compile_assert(size_of([vector 7]bool) >= size_of([7]bool));
compile_assert(size_of([vector 7]i32) >= size_of([7]i32));
#assert(size_of([vector 7]bool) >= size_of([7]bool));
#assert(size_of([vector 7]i32) >= size_of([7]i32));
// align_of([vector 7]i32) != align_of([7]i32) // this may be the case
}
+1 -1
View File
@@ -46,7 +46,7 @@ memory_copy :: proc(dst, src: rawptr, n: int) #inline {
}
v128b :: type {4}u32
compile_assert(align_of(v128b) == 16)
#assert(align_of(v128b) == 16)
d, s: ^byte = dst, src
+3 -3
View File
@@ -50,9 +50,9 @@ general_stuff :: proc() {
foo := Foo{123, 0.513, "A string"};
x, y, z := expand_to_tuple(foo);
fmt.println(x, y, z);
compile_assert(type_of(x) == int);
compile_assert(type_of(y) == f32);
compile_assert(type_of(z) == string);
#assert(type_of(x) == int);
#assert(type_of(y) == f32);
#assert(type_of(z) == string);
// By default, all variables are zeroed
+1 -1
View File
@@ -10,7 +10,7 @@ CANVAS_SCALE :: 3;
FRAME_TIME :: 1.0/30.0;
WINDOW_TITLE :: "Punity\x00";
_ :: compile_assert(CANVAS_WIDTH % 16 == 0);
#assert(CANVAS_WIDTH % 16 == 0);
WINDOW_WIDTH :: CANVAS_WIDTH * CANVAS_SCALE;