diff options
| author | gingerBill <bill@gingerbill.org> | 2018-09-02 16:33:54 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2018-09-02 16:33:54 +0100 |
| commit | 11f5236434ca08ae034a195639c8ed377e125015 (patch) | |
| tree | ae295c53970f5a187d2d4f2fc7cf2ac9d8f1c04e /examples | |
| parent | 220485a2d2cd180e7ff2a15bab66c867c06b05d7 (diff) | |
Add `$T: typeid/[]$E`; Deprecate `T: type/[]$E`
`type` as a keyword will soon be removed in favour of polymorphic names (identifiers) in procedures
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/demo/demo.odin | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/examples/demo/demo.odin b/examples/demo/demo.odin index ed26b9664..2f3e9340e 100644 --- a/examples/demo/demo.odin +++ b/examples/demo/demo.odin @@ -187,7 +187,7 @@ union_type :: proc() { } // See `parametric_polymorphism` procedure for details - new_entity :: proc(T: type) -> ^Entity { + new_entity :: proc($T: typeid) -> ^Entity { t := new(T); t.derived = t^; return t; @@ -231,7 +231,7 @@ union_type :: proc() { } // See `parametric_polymorphism` procedure for details - new_entity :: proc(T: type) -> ^Entity { + new_entity :: proc($T: typeid) -> ^Entity { t := new(Entity); t.derived = T{entity = t}; return t; @@ -318,7 +318,7 @@ parametric_polymorphism :: proc() { fmt.printf("b: %T = %v\n", b, b); // This is how `new` is implemented - alloc_type :: proc(T: type) -> ^T { + alloc_type :: proc($T: typeid) -> ^T { t := cast(^T)alloc(size_of(T), align_of(T)); t^ = T{}; // Use default initialization value return t; @@ -341,21 +341,21 @@ parametric_polymorphism :: proc() { { // Polymorphic Types and Type Specialization - Table_Slot :: struct(Key, Value: type) { + Table_Slot :: struct(Key, Value: typeid) { occupied: bool, hash: u32, key: Key, value: Value, } TABLE_SIZE_MIN :: 32; - Table :: struct(Key, Value: type) { + Table :: struct(Key, Value: typeid) { count: int, allocator: mem.Allocator, slots: []Table_Slot(Key, Value), } // Only allow types that are specializations of a (polymorphic) slice - make_slice :: proc(T: type/[]$E, len: int) -> T { + make_slice :: proc($T: typeid/[]$E, len: int) -> T { return make(T, len); } @@ -767,6 +767,7 @@ bit_set_type :: proc() { } } + main :: proc() { when true { general_stuff(); |