Add $T: typeid/[]$E; Deprecate T: type/[]$E

`type` as a keyword will soon be removed in favour of polymorphic names (identifiers) in procedures
This commit is contained in:
gingerBill
2018-09-02 16:33:54 +01:00
parent 220485a2d2
commit 11f5236434
6 changed files with 101 additions and 27 deletions
+7 -6
View File
@@ -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();