mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-21 23:12:03 -07:00
Replace compile_assert with #assert
This commit is contained in:
+4
-3
@@ -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();
|
||||
|
||||
@@ -328,7 +328,7 @@ miscellany :: proc() {
|
||||
*/
|
||||
|
||||
// assert(false)
|
||||
// compile_assert(false)
|
||||
// #assert(false)
|
||||
// panic("Panic message goes here")
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user