aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2018-12-02 18:01:03 +0000
committergingerBill <bill@gingerbill.org>2018-12-02 18:01:03 +0000
commit28583bfff88ff1378a0e71030701071dcfd37462 (patch)
tree6d3594ed87f0e1a364f25589ee5c1d8aef820f4a /examples
parentb2df48dadbc3382fec81f9da0e42d5a0c7be7fff (diff)
Change procedure group syntax from `proc[]` to `proc{}`; deprecate `proc[]` (raises warning currently)
Diffstat (limited to 'examples')
-rw-r--r--examples/demo/demo.odin20
1 files changed, 8 insertions, 12 deletions
diff --git a/examples/demo/demo.odin b/examples/demo/demo.odin
index b1aa4e12d..9fc6db2a8 100644
--- a/examples/demo/demo.odin
+++ b/examples/demo/demo.odin
@@ -56,7 +56,7 @@ general_stuff :: proc() {
/*
* Remove *_val_of built-in procedures
* size_of, align_of, offset_of
- * type_of, type_info_of
+ * type_of, type_info_of, typeid_of
*/
{ // `expand_to_tuple` built-in procedure
@@ -108,6 +108,9 @@ general_stuff :: proc() {
My_Struct :: struct{x: int};
#assert(My_Struct != struct{x: int});
+
+ My_Struct2 :: My_Struct;
+ #assert(My_Struct2 == My_Struct);
}
{
@@ -213,6 +216,7 @@ union_type :: proc() {
case Monster:
if e.is_robot do fmt.println("Robotic");
if e.is_zombie do fmt.println("Grrrr!");
+ fmt.println("I'm a monster");
}
}
@@ -371,7 +375,6 @@ parametric_polymorphism :: proc() {
return make(T, len);
}
-
// Only allow types that are specializations of `Table`
allocate :: proc(table: ^$T/Table, capacity: int) {
c := context;
@@ -509,7 +512,7 @@ parametric_polymorphism :: proc() {
fmt.printf("Generating an array of type %v from the value %v of type %v\n",
typeid_of(type_of(res)), N, typeid_of(I));
for i in 0..N-1 {
- res[i] = i*i;
+ res[i] = T(i*i);
}
return;
}
@@ -666,11 +669,6 @@ using_enum :: proc() {
f2 := C;
fmt.println(f0, f1, f2);
fmt.println(len(Foo));
-
- // Non-comparsion operations are not allowed with enum
- // You must convert to an integer if you want to do this
- // x := f0 + f1;
- y := int(f0) + int(f1);
}
explicit_procedure_overloading :: proc() {
@@ -692,7 +690,7 @@ explicit_procedure_overloading :: proc() {
return x;
}
- add :: proc[add_ints, add_floats, add_numbers];
+ add :: proc{add_ints, add_floats, add_numbers};
add(int(1), int(2));
add(f32(1), f32(2));
@@ -738,7 +736,6 @@ complete_switch :: proc() {
}
}
-
cstring_example :: proc() {
W :: "Hellope";
X :: cstring(W);
@@ -801,7 +798,7 @@ bit_set_type :: proc() {
}
{
x: bit_set['A'..'Z'];
- assert(size_of(x) == size_of(u32));
+ #assert(size_of(x) == size_of(u32));
y: bit_set[0..8; u16];
fmt.println(typeid_of(type_of(x))); // bit_set[A..Z]
fmt.println(typeid_of(type_of(y))); // bit_set[0..8; u16]
@@ -820,7 +817,6 @@ bit_set_type :: proc() {
b := Letters{'A', 'B', 'C', 'D', 'F'};
c := Letters{'A', 'B'};
-
assert(a <= b); // 'a' is a subset of 'b'
assert(b >= a); // 'b' is a superset of 'a'
assert(a < b); // 'a' is a strict subset of 'b'