Remove vector type (will be replaced by something else in the future)

This commit is contained in:
gingerBill
2017-11-30 20:34:42 +00:00
parent e00d88d82e
commit 1a75dfe075
15 changed files with 41 additions and 704 deletions

View File

@@ -66,7 +66,6 @@ Type_Info_Array :: struct #ordered {
};
Type_Info_Dynamic_Array :: struct #ordered {elem: ^Type_Info, elem_size: int};
Type_Info_Slice :: struct #ordered {elem: ^Type_Info, elem_size: int};
Type_Info_Vector :: struct #ordered {elem: ^Type_Info, elem_size, count: int};
Type_Info_Tuple :: struct #ordered { // Only really used for procedures
types: []^Type_Info,
names: []string,
@@ -121,7 +120,6 @@ Type_Info :: struct #ordered {
Type_Info_Array,
Type_Info_Dynamic_Array,
Type_Info_Slice,
Type_Info_Vector,
Type_Info_Tuple,
Type_Info_Struct,
Type_Info_Union,
@@ -178,7 +176,7 @@ Context :: struct #ordered {
derived: any, // May be used for derived data types
}
DEFAULT_ALIGNMENT :: align_of([vector 4]f32);
DEFAULT_ALIGNMENT :: 2*align_of(rawptr);
__INITIAL_MAP_CAP :: 16;

View File

@@ -244,11 +244,6 @@ write_type :: proc(buf: ^String_Buffer, ti: ^Type_Info) {
case Type_Info_Slice:
write_string(buf, "[]");
write_type(buf, info.elem);
case Type_Info_Vector:
write_string(buf, "[vector ");
write_int(buf, i64(info.count), 10);
write_string(buf, "]");
write_type(buf, info.elem);
case Type_Info_Map:
write_string(buf, "map[");
@@ -815,17 +810,6 @@ fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) {
fmt_arg(fi, any{rawptr(data), info.elem}, verb);
}
case Type_Info_Vector:
write_byte(fi.buf, '<');
defer write_byte(fi.buf, '>');
for i in 0..info.count {
if i > 0 do write_string(fi.buf, ", ");
data := uintptr(v.data) + uintptr(i*info.elem_size);
fmt_value(fi, any{rawptr(data), info.elem}, verb);
}
case Type_Info_Map:
if verb != 'v' {
fmt_bad_verb(fi, verb);

View File

@@ -220,7 +220,7 @@ align_of_type_info :: proc(type_info: ^Type_Info) -> int {
}
WORD_SIZE :: size_of(int);
MAX_ALIGN :: size_of([vector 64]f64); // TODO(bill): Should these constants be builtin constants?
MAX_ALIGN :: 2*align_of(rawptr); // TODO(bill): Should these constants be builtin constants?
switch info in type_info.variant {
case Type_Info_Named:
return align_of_type_info(info.base);
@@ -246,11 +246,6 @@ align_of_type_info :: proc(type_info: ^Type_Info) -> int {
return WORD_SIZE;
case Type_Info_Slice:
return WORD_SIZE;
case Type_Info_Vector:
size := size_of_type_info(info.elem);
count := int(max(prev_pow2(i64(info.count)), 1));
total := size * count;
return clamp(total, 1, MAX_ALIGN);
case Type_Info_Tuple:
return type_info.align;
case Type_Info_Struct:
@@ -303,13 +298,6 @@ size_of_type_info :: proc(type_info: ^Type_Info) -> int {
return size_of(rawptr) + 2*size_of(int) + size_of(Allocator);
case Type_Info_Slice:
return 2*WORD_SIZE;
case Type_Info_Vector:
count := info.count;
if count == 0 do return 0;
size := size_of_type_info(info.elem);
align := align_of_type_info(info.elem);
alignment := align_formula(size, align);
return alignment*(count-1) + size;
case Type_Info_Struct:
return type_info.size;
case Type_Info_Union:

View File

@@ -78,12 +78,6 @@ are_types_identical :: proc(a, b: ^Type_Info) -> bool {
if !ok do return false;
return are_types_identical(x.elem, y.elem);
case Type_Info_Vector:
y, ok := b.variant.(Type_Info_Vector);
if !ok do return false;
if x.count != y.count do return false;
return are_types_identical(x.elem, y.elem);
case Type_Info_Tuple:
y, ok := b.variant.(Type_Info_Tuple);
if !ok do return false;
@@ -231,11 +225,6 @@ is_slice :: proc(info: ^Type_Info) -> bool {
_, ok := type_info_base(info).variant.(Type_Info_Slice);
return ok;
}
is_vector :: proc(info: ^Type_Info) -> bool {
if info == nil do return false;
_, ok := type_info_base(info).variant.(Type_Info_Vector);
return ok;
}
is_tuple :: proc(info: ^Type_Info) -> bool {
if info == nil do return false;
_, ok := type_info_base(info).variant.(Type_Info_Tuple);

View File

@@ -561,14 +561,6 @@ i64 check_distance_between_types(Checker *c, Operand *operand, Type *type) {
}
}
if (is_type_vector(dst)) {
Type *elem = base_vector_type(dst);
i64 distance = check_distance_between_types(c, operand, elem);
if (distance >= 0) {
return distance + 5;
}
}
#if defined(ALLOW_ARRAY_PROGRAMMING)
if (is_type_array(dst)) {
Type *elem = base_array_type(dst);
@@ -656,13 +648,9 @@ void check_assignment(Checker *c, Operand *operand, Type *type, String context_n
add_type_info_type(c, target_type);
}
if (target_type != nullptr && is_type_vector(target_type)) {
// NOTE(bill): continue to below
} else {
convert_to_typed(c, operand, target_type);
if (operand->mode == Addressing_Invalid) {
return;
}
convert_to_typed(c, operand, target_type);
if (operand->mode == Addressing_Invalid) {
return;
}
}
@@ -828,41 +816,6 @@ bool is_polymorphic_type_assignable(Checker *c, Type *poly, Type *source, bool c
}
}
return false;
case Type_Vector:
if (source->kind == Type_Vector) {
if (poly->Vector.generic_type && modify_type) {
Type *gt = poly->Vector.generic_type;
GB_ASSERT(gt->kind == Type_Generic);
Entity *e = scope_lookup_entity(gt->Generic.scope, gt->Generic.name);
GB_ASSERT(e != nullptr);
if (e->kind == Entity_TypeName) {
poly->Vector.generic_type = nullptr;
poly->Vector.count = source->Vector.count;
e->kind = Entity_Constant;
e->Constant.value = exact_value_i64(source->Vector.count);
e->type = t_untyped_integer;
} else if (e->kind == Entity_Constant) {
poly->Vector.generic_type = nullptr;
if (e->Constant.value.kind != ExactValue_Integer) {
return false;
}
i64 count = i128_to_i64(e->Constant.value.value_integer);
if (count != source->Vector.count) {
return false;
}
poly->Vector.count = source->Vector.count;
} else {
return false;
}
return is_polymorphic_type_assignable(c, poly->Vector.elem, source->Vector.elem, true, modify_type);
}
if (poly->Vector.count == source->Vector.count) {
return is_polymorphic_type_assignable(c, poly->Vector.elem, source->Vector.elem, true, modify_type);
}
}
return false;
case Type_DynamicArray:
if (source->kind == Type_DynamicArray) {
return is_polymorphic_type_assignable(c, poly->DynamicArray.elem, source->DynamicArray.elem, true, modify_type);
@@ -1132,7 +1085,7 @@ bool check_unary_op(Checker *c, Operand *o, Token op) {
return false;
}
// TODO(bill): Handle errors correctly
Type *type = base_type(base_vector_type(o->type));
Type *type = base_type(core_array_type(o->type));
gbString str = nullptr;
switch (op.kind) {
case Token_Add:
@@ -1168,7 +1121,7 @@ bool check_unary_op(Checker *c, Operand *o, Token op) {
bool check_binary_op(Checker *c, Operand *o, Token op) {
// TODO(bill): Handle errors correctly
Type *type = base_type(base_vector_type(o->type));
Type *type = base_type(core_array_type(o->type));
switch (op.kind) {
case Token_Sub:
case Token_SubEq:
@@ -1403,32 +1356,6 @@ void check_is_expressible(Checker *c, Operand *o, Type *type) {
}
}
bool check_is_expr_vector_index(Checker *c, AstNode *expr) {
// HACK(bill): Handle this correctly. Maybe with a custom AddressingMode
expr = unparen_expr(expr);
if (expr->kind == AstNode_IndexExpr) {
ast_node(ie, IndexExpr, expr);
Type *t = type_deref(type_of_expr(&c->info, ie->expr));
if (t != nullptr) {
return is_type_vector(t);
}
}
return false;
}
bool check_is_vector_elem(Checker *c, AstNode *expr) {
// HACK(bill): Handle this correctly. Maybe with a custom AddressingMode
expr = unparen_expr(expr);
if (expr->kind == AstNode_SelectorExpr) {
ast_node(se, SelectorExpr, expr);
Type *t = type_deref(type_of_expr(&c->info, se->expr));
if (t != nullptr && is_type_vector(t)) {
return true;
}
}
return false;
}
bool check_is_not_addressable(Checker *c, Operand *o) {
if (o->mode != Addressing_Variable) {
return true;
@@ -1436,12 +1363,6 @@ bool check_is_not_addressable(Checker *c, Operand *o) {
if (is_type_bit_field_value(o->type)) {
return true;
}
if (check_is_expr_vector_index(c, o->expr)) {
return true;
}
if (check_is_vector_elem(c, o->expr)) {
return true;
}
return false;
}
@@ -1474,7 +1395,7 @@ void check_unary_expr(Checker *c, Operand *o, Token op, AstNode *node) {
return;
}
if (o->mode == Addressing_Constant && !is_type_vector(o->type)) {
if (o->mode == Addressing_Constant) {
Type *type = base_type(o->type);
if (!is_type_constant_type(o->type)) {
gbString xt = type_to_string(o->type);
@@ -1603,11 +1524,7 @@ void check_comparison(Checker *c, Operand *x, Operand *y, TokenKind op) {
update_expr_type(c, y->expr, default_type(y->type), true);
}
if (is_type_vector(base_type(y->type))) {
x->type = make_type_vector(c->allocator, t_bool, base_type(y->type)->Vector.count);
} else {
x->type = t_untyped_bool;
}
x->type = t_untyped_bool;
}
}
@@ -1888,8 +1805,6 @@ void check_cast(Checker *c, Operand *x, Type *type) {
x->mode = Addressing_Value;
} else if (is_type_slice(type) && is_type_string(x->type)) {
x->mode = Addressing_Value;
} else if (!is_type_vector(x->type) && is_type_vector(type)) {
x->mode = Addressing_Value;
}
can_convert = true;
}
@@ -1955,14 +1870,7 @@ bool check_transmute(Checker *c, AstNode *node, Operand *o, Type *t) {
return true;
}
bool check_binary_array_vector_expr(Checker *c, Token op, Operand *x, Operand *y) {
if (is_type_vector(x->type) && !is_type_vector(y->type)) {
if (check_is_assignable_to(c, y, x->type)) {
if (check_binary_op(c, x, op)) {
return true;
}
}
}
bool check_binary_array_expr(Checker *c, Token op, Operand *x, Operand *y) {
if (is_type_array(x->type) && !is_type_array(y->type)) {
if (check_is_assignable_to(c, y, x->type)) {
if (check_binary_op(c, x, op)) {
@@ -2054,12 +1962,12 @@ void check_binary_expr(Checker *c, Operand *x, AstNode *node) {
return;
}
if (check_binary_array_vector_expr(c, op, x, y)) {
if (check_binary_array_expr(c, op, x, y)) {
x->mode = Addressing_Value;
x->type = x->type;
return;
}
if (check_binary_array_vector_expr(c, op, y, x)) {
if (check_binary_array_expr(c, op, y, x)) {
x->mode = Addressing_Value;
x->type = y->type;
return;
@@ -2333,19 +2241,6 @@ void convert_to_typed(Checker *c, Operand *operand, Type *target_type) {
}
break;
case Type_Vector: {
Type *elem = base_vector_type(t);
if (check_is_assignable_to(c, operand, elem)) {
operand->mode = Addressing_Value;
} else {
operand->mode = Addressing_Invalid;
convert_untyped_error(c, operand, target_type);
return;
}
break;
}
#if defined(ALLOW_ARRAY_PROGRAMMING)
case Type_Array: {
Type *elem = base_array_type(t);
@@ -2952,11 +2847,6 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
mode = Addressing_Constant;
value = exact_value_i64(at->Array.count);
type = t_untyped_integer;
} else if (is_type_vector(op_type) && id == BuiltinProc_len) {
Type *at = core_type(op_type);
mode = Addressing_Constant;
value = exact_value_i64(at->Vector.count);
type = t_untyped_integer;
} else if (is_type_slice(op_type)) {
mode = Addressing_Value;
} else if (is_type_dynamic_array(op_type)) {
@@ -3323,7 +3213,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
error(field_arg, "Expected an identifier for field argument");
return false;
}
if (is_type_array(type) || is_type_vector(type)) {
if (is_type_array(type)) {
error(field_arg, "Invalid type for 'offset_of'");
return false;
}
@@ -3422,29 +3312,19 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
case BuiltinProc_swizzle: {
// proc swizzle(v: [N]T, ...int) -> [M]T
// proc swizzle(v: [vector N]T, ...int) -> [vector M]T
Type *type = base_type(operand->type);
if (!is_type_vector(type) && !is_type_array(type)) {
if (!is_type_array(type)) {
gbString type_str = type_to_string(operand->type);
error(call,
"You can only 'swizzle' a vector or array, got '%s'",
"You can only 'swizzle' an array, got '%s'",
type_str);
gb_string_free(type_str);
return false;
}
Type *elem_type = nullptr;
i64 max_count = 0;
if (is_type_vector(type)) {
max_count = type->Vector.count;
elem_type = type->Vector.elem;
}
#if defined(ALLOW_ARRAY_PROGRAMMING)
else if (is_type_array(type)) {
max_count = type->Array.count;
elem_type = type->Array.elem;
}
#endif
i64 max_count = type->Array.count;
Type *elem_type = type->Array.elem;
i128 max_count128 = i128_from_i64(max_count);
i64 arg_count = 0;
for_array(i, ce->args) {
@@ -3481,14 +3361,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
return false;
}
if (is_type_vector(type)) {
operand->type = make_type_vector(c->allocator, elem_type, arg_count);
}
#if defined(ALLOW_ARRAY_PROGRAMMING)
else if (is_type_array(type)) {
operand->type = make_type_array(c->allocator, elem_type, arg_count);
}
#endif
operand->type = make_type_array(c->allocator, elem_type, arg_count);
operand->mode = Addressing_Value;
break;
@@ -3850,7 +3723,7 @@ break;
case BuiltinProc_abs: {
// proc abs(n: numeric) -> numeric
if (!is_type_numeric(operand->type) && !is_type_vector(operand->type)) {
if (!is_type_numeric(operand->type)) {
gbString type_str = type_to_string(operand->type);
error(call, "Expected a numeric type to 'abs', got '%s'", type_str);
gb_string_free(type_str);
@@ -5118,13 +4991,6 @@ bool check_set_index_data(Operand *o, Type *type, bool indirection, i64 *max_cou
o->type = t->Array.elem;
return true;
case Type_Vector:
*max_count = t->Vector.count;
check_set_mode_with_indirection(o, indirection);
o->type = t->Vector.elem;
return true;
case Type_Slice:
o->type = t->Slice.elem;
if (o->mode != Addressing_Immutable) {
@@ -5559,7 +5425,6 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
case Type_Slice:
case Type_Array:
case Type_Vector:
case Type_DynamicArray:
{
Type *elem_type = nullptr;
@@ -5568,10 +5433,6 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
if (t->kind == Type_Slice) {
elem_type = t->Slice.elem;
context_name = str_lit("slice literal");
} else if (t->kind == Type_Vector) {
elem_type = t->Vector.elem;
context_name = str_lit("vector literal");
max_type_count = t->Vector.count;
} else if (t->kind == Type_Array) {
elem_type = t->Array.elem;
context_name = str_lit("array literal");
@@ -5623,12 +5484,6 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
max = index;
}
if (t->kind == Type_Vector) {
if (t->Vector.count > 1 && gb_is_between(index, 2, t->Vector.count-1)) {
error(cl->elems[0], "Expected either 1 (broadcast) or %td elements in vector literal, got %td", t->Vector.count, index);
}
}
if (t->kind == Type_Array && is_to_be_determined_array_count) {
t->Array.count = max;
}
@@ -6128,7 +5983,6 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
case AstNode_PointerType:
case AstNode_ArrayType:
case AstNode_DynamicArrayType:
case AstNode_VectorType:
case AstNode_StructType:
case AstNode_UnionType:
// case AstNode_RawUnionType:
@@ -6418,13 +6272,6 @@ gbString write_expr_to_string(gbString str, AstNode *node) {
str = write_expr_to_string(str, at->elem);
case_end;
case_ast_node(vt, VectorType, node);
str = gb_string_appendc(str, "[vector ");
str = write_expr_to_string(str, vt->count);
str = gb_string_append_rune(str, ']');
str = write_expr_to_string(str, vt->elem);
case_end;
case_ast_node(mt, MapType, node);
str = gb_string_appendc(str, "map[");
str = write_expr_to_string(str, mt->key);

View File

@@ -606,13 +606,6 @@ void check_switch_stmt(Checker *c, AstNode *node, u32 mod_flags) {
token.string = str_lit("true");
x.expr = ast_ident(c->curr_ast_file, token);
}
if (is_type_vector(x.type)) {
gbString str = type_to_string(x.type);
error(x.expr, "Invalid switch expression type: %s", str);
gb_string_free(str);
return;
}
// NOTE(bill): Check for multiple defaults
AstNode *first_default = nullptr;
@@ -1483,11 +1476,6 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
val1 = t_int;
break;
case Type_Vector:
val0 = t->Vector.elem;
val1 = t_int;
break;
case Type_Map:
is_map = true;
val0 = t->Map.key;

View File

@@ -1667,7 +1667,6 @@ Type *type_to_abi_compat_param_type(gbAllocator a, Type *original_type) {
// Odin specific
case Type_Slice:
case Type_Array:
case Type_Vector:
case Type_DynamicArray:
case Type_Map:
case Type_Union:
@@ -1710,7 +1709,6 @@ Type *type_to_abi_compat_param_type(gbAllocator a, Type *original_type) {
// Odin specific
case Type_Slice:
case Type_Array:
case Type_Vector:
case Type_DynamicArray:
case Type_Map:
case Type_Union:
@@ -2237,31 +2235,6 @@ bool check_type_internal(Checker *c, AstNode *e, Type **type, Type *named_type)
return true;
case_end;
case_ast_node(vt, VectorType, e);
Operand o = {};
i64 count = check_array_count(c, &o, vt->count);
Type *generic_type = nullptr;
if (o.mode == Addressing_Type && o.type->kind == Type_Generic) {
generic_type = o.type;
}
if (count < 0) {
count = 0;
}
Type *elem = check_type(c, vt->elem);
Type *be = base_type(elem);
if (is_type_vector(be) || (!is_type_boolean(be) && !is_type_numeric(be) && be->kind != Type_Generic)) {
gbString err_str = type_to_string(elem);
error(vt->elem, "Vector element type must be numerical or a boolean, got '%s'", err_str);
gb_string_free(err_str);
}
*type = make_type_vector(c->allocator, elem, count, generic_type);
return true;
case_end;
case_ast_node(st, StructType, e);
*type = make_type_struct(c->allocator);
set_base_type(named_type, *type);

View File

@@ -1341,10 +1341,6 @@ void add_type_info_type(Checker *c, Type *t) {
add_type_info_type(c, make_type_pointer(c->allocator, bt->Slice.elem));
add_type_info_type(c, t_int);
break;
case Type_Vector:
add_type_info_type(c, bt->Vector.elem);
add_type_info_type(c, t_int);
break;
case Type_Enum:
add_type_info_type(c, bt->Enum.base_type);
@@ -1657,7 +1653,6 @@ void init_preload(Checker *c) {
t_type_info_array = find_core_type(c, str_lit("Type_Info_Array"));
t_type_info_dynamic_array = find_core_type(c, str_lit("Type_Info_Dynamic_Array"));
t_type_info_slice = find_core_type(c, str_lit("Type_Info_Slice"));
t_type_info_vector = find_core_type(c, str_lit("Type_Info_Vector"));
t_type_info_tuple = find_core_type(c, str_lit("Type_Info_Tuple"));
t_type_info_struct = find_core_type(c, str_lit("Type_Info_Struct"));
t_type_info_union = find_core_type(c, str_lit("Type_Info_Union"));
@@ -1678,7 +1673,6 @@ void init_preload(Checker *c) {
t_type_info_array_ptr = make_type_pointer(c->allocator, t_type_info_array);
t_type_info_dynamic_array_ptr = make_type_pointer(c->allocator, t_type_info_dynamic_array);
t_type_info_slice_ptr = make_type_pointer(c->allocator, t_type_info_slice);
t_type_info_vector_ptr = make_type_pointer(c->allocator, t_type_info_vector);
t_type_info_tuple_ptr = make_type_pointer(c->allocator, t_type_info_tuple);
t_type_info_struct_ptr = make_type_pointer(c->allocator, t_type_info_struct);
t_type_info_union_ptr = make_type_pointer(c->allocator, t_type_info_union);

View File

@@ -36,7 +36,7 @@ enum EntityFlag {
EntityFlag_Using = 1<<2,
EntityFlag_Field = 1<<3,
EntityFlag_Param = 1<<4,
EntityFlag_VectorElem = 1<<5,
EntityFlag_ArrayElem = 1<<5,
EntityFlag_Ellipsis = 1<<6,
EntityFlag_NoAlias = 1<<7,
EntityFlag_TypeField = 1<<8,
@@ -227,12 +227,12 @@ Entity *make_entity_field(gbAllocator a, Scope *scope, Token token, Type *type,
return entity;
}
Entity *make_entity_vector_elem(gbAllocator a, Scope *scope, Token token, Type *type, i32 field_src_index) {
Entity *make_entity_array_elem(gbAllocator a, Scope *scope, Token token, Type *type, i32 field_src_index) {
Entity *entity = make_entity_variable(a, scope, token, type, false);
entity->Variable.field_src_index = field_src_index;
entity->Variable.field_index = field_src_index;
entity->flags |= EntityFlag_Field;
entity->flags |= EntityFlag_VectorElem;
entity->flags |= EntityFlag_ArrayElem;
return entity;
}

View File

@@ -433,7 +433,6 @@ gb_global irValue *v_raw_nil = nullptr;
enum irAddrKind {
irAddr_Default,
// irAddr_Vector,
irAddr_Map,
irAddr_BitField,
};
@@ -451,9 +450,6 @@ struct irAddr {
i32 bit_field_value_index;
};
};
// union {
// struct { irValue *index; } Vector;
// };
};
irAddr ir_addr(irValue *addr) {
@@ -939,7 +935,7 @@ irValue *ir_instr_array_element_ptr(irProcedure *p, irValue *address, irValue *e
Type *t = ir_type(address);
GB_ASSERT_MSG(is_type_pointer(t), "%s", type_to_string(t));
t = base_type(type_deref(t));
GB_ASSERT(is_type_array(t) || is_type_vector(t));
GB_ASSERT(is_type_array(t));
Type *result_type = make_type_pointer(p->module->allocator, t->Array.elem);
@@ -2095,24 +2091,7 @@ irValue *ir_emit_unary_arith(irProcedure *proc, TokenKind op, irValue *x, Type *
GB_PANIC("This should be handled elsewhere");
break;
}
if (is_type_vector(ir_type(x))) {
ir_emit_comment(proc, str_lit("vector.arith.begin"));
// IMPORTANT TODO(bill): This is very wasteful with regards to stack memory
Type *tl = base_type(ir_type(x));
irValue *val = ir_address_from_load_or_generate_local(proc, x);
GB_ASSERT(is_type_vector(type));
Type *elem_type = base_vector_type(type);
irValue *res = ir_add_local_generated(proc, type);
for (i32 i = 0; i < tl->Vector.count; i++) {
irValue *e = ir_emit_load(proc, ir_emit_array_epi(proc, val, i));
irValue *z = ir_emit_unary_arith(proc, op, e, elem_type);
ir_emit_store(proc, ir_emit_array_epi(proc, res, i), z);
}
ir_emit_comment(proc, str_lit("vector.arith.end"));
return ir_emit_load(proc, res);
}
#if defined(ALLOW_ARRAY_PROGRAMMING)
if (is_type_array(ir_type(x))) {
ir_emit_comment(proc, str_lit("array.arith.begin"));
@@ -2143,28 +2122,6 @@ irValue *ir_emit_arith(irProcedure *proc, TokenKind op, irValue *left, irValue *
Type *t_left = ir_type(left);
Type *t_right = ir_type(right);
if (is_type_vector(t_left) || is_type_vector(t_right)) {
ir_emit_comment(proc, str_lit("vector.arith.begin"));
// IMPORTANT TODO(bill): This is very wasteful with regards to stack memory
left = ir_emit_conv(proc, left, type);
right = ir_emit_conv(proc, right, type);
irValue *lhs = ir_address_from_load_or_generate_local(proc, left);
irValue *rhs = ir_address_from_load_or_generate_local(proc, right);
GB_ASSERT(is_type_vector(type));
Type *elem_type = base_vector_type(type);
irValue *res = ir_add_local_generated(proc, type);
i64 count = base_type(type)->Vector.count;
for (i32 i = 0; i < count; i++) {
irValue *x = ir_emit_load(proc, ir_emit_array_epi(proc, lhs, i));
irValue *y = ir_emit_load(proc, ir_emit_array_epi(proc, rhs, i));
irValue *z = ir_emit_arith(proc, op, x, y, elem_type);
ir_emit_store(proc, ir_emit_array_epi(proc, res, i), z);
}
ir_emit_comment(proc, str_lit("vector.arith.end"));
return ir_emit_load(proc, res);
}
#if defined(ALLOW_ARRAY_PROGRAMMING)
if (is_type_array(t_left) || is_type_array(t_right)) {
ir_emit_comment(proc, str_lit("array.arith.begin"));
@@ -2446,31 +2403,6 @@ irValue *ir_emit_comp(irProcedure *proc, TokenKind op_kind, irValue *left, irVal
}
Type *result = t_bool;
if (is_type_vector(a)) {
result = make_type_vector(proc->module->allocator, t_bool, a->Vector.count);
}
if (is_type_vector(a)) {
ir_emit_comment(proc, str_lit("vector.comp.begin"));
Type *tl = base_type(a);
irValue *lhs = ir_address_from_load_or_generate_local(proc, left);
irValue *rhs = ir_address_from_load_or_generate_local(proc, right);
GB_ASSERT(is_type_vector(result));
Type *elem_type = base_vector_type(result);
irValue *res = ir_add_local_generated(proc, result);
for (i32 i = 0; i < tl->Vector.count; i++) {
irValue *x = ir_emit_load(proc, ir_emit_array_epi(proc, lhs, i));
irValue *y = ir_emit_load(proc, ir_emit_array_epi(proc, rhs, i));
irValue *z = ir_emit_comp(proc, op_kind, x, y);
ir_emit_store(proc, ir_emit_array_epi(proc, res, i), z);
}
ir_emit_comment(proc, str_lit("vector.comp.end"));
return ir_emit_load(proc, res);
}
#if defined(ALLOW_ARRAY_PROGRAMMING)
if (is_type_array(a)) {
ir_emit_comment(proc, str_lit("array.comp.begin"));
@@ -2553,7 +2485,7 @@ irValue *ir_emit_array_ep(irProcedure *proc, irValue *s, irValue *index) {
Type *t = ir_type(s);
GB_ASSERT(is_type_pointer(t));
Type *st = base_type(type_deref(t));
GB_ASSERT_MSG(is_type_array(st) || is_type_vector(st), "%s", type_to_string(st));
GB_ASSERT_MSG(is_type_array(st), "%s", type_to_string(st));
// NOTE(bill): For some weird legacy reason in LLVM, structure elements must be accessed as an i32
index = ir_emit_conv(proc, index, t_i32);
@@ -2755,8 +2687,6 @@ irValue *ir_emit_deep_field_gep(irProcedure *proc, irValue *e, Selection sel) {
e = ir_emit_struct_ep(proc, e, index);
} else if (type->kind == Type_DynamicArray) {
e = ir_emit_struct_ep(proc, e, index);
} else if (type->kind == Type_Vector) {
e = ir_emit_array_epi(proc, e, index);
} else if (type->kind == Type_Array) {
e = ir_emit_array_epi(proc, e, index);
} else if (type->kind == Type_Map) {
@@ -3261,19 +3191,6 @@ irValue *ir_emit_conv(irProcedure *proc, irValue *value, Type *t) {
return ir_emit_load(proc, slice);
}
if (is_type_vector(dst)) {
Type *dst_elem = dst->Vector.elem;
value = ir_emit_conv(proc, value, dst_elem);
irValue *v = ir_add_local_generated(proc, t);
isize index_count = dst->Vector.count;
for (i32 i = 0; i < index_count; i++) {
irValue *elem = ir_emit_array_epi(proc, v, i);
ir_emit_store(proc, elem, value);
}
return ir_emit_load(proc, v);
}
#if defined(ALLOW_ARRAY_PROGRAMMING)
if (is_type_array(dst)) {
Type *elem = dst->Array.elem;
@@ -3345,7 +3262,6 @@ bool ir_is_type_aggregate(Type *t) {
case Type_Pointer:
return false;
case Type_Vector:
case Type_Array:
case Type_Slice:
case Type_Struct:
@@ -4107,8 +4023,6 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv
return ir_string_len(proc, v);
} else if (is_type_array(t)) {
GB_PANIC("Array lengths are constant");
} else if (is_type_vector(t)) {
GB_PANIC("Vector lengths are constant");
} else if (is_type_slice(t)) {
return ir_slice_count(proc, v);
} else if (is_type_dynamic_array(t)) {
@@ -4135,8 +4049,6 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv
GB_PANIC("Unreachable");
} else if (is_type_array(t)) {
GB_PANIC("Array lengths are constant");
} else if (is_type_vector(t)) {
GB_PANIC("Unreachable");
} else if (is_type_slice(t)) {
return ir_slice_count(proc, v);
} else if (is_type_dynamic_array(t)) {
@@ -4777,20 +4689,11 @@ irValue *ir_build_expr(irProcedure *proc, AstNode *expr) {
#endif
if (tv.value.kind != ExactValue_Invalid) {
// NOTE(bill): Edge case
if (tv.value.kind != ExactValue_Compound &&
is_type_vector(tv.type)) {
Type *elem = core_array_or_vector_type(tv.type);
ExactValue value = convert_exact_value_for_type(tv.value, elem);
irValue *x = ir_add_module_constant(proc->module, elem, value);
return ir_emit_conv(proc, x, tv.type);
}
#if defined(ALLOW_ARRAY_PROGRAMMING)
// NOTE(bill): Edge case
if (tv.value.kind != ExactValue_Compound &&
is_type_array(tv.type)) {
Type *elem = core_array_or_vector_type(tv.type);
Type *elem = core_array_type(tv.type);
ExactValue value = convert_exact_value_for_type(tv.value, elem);
irValue *x = ir_add_module_constant(proc->module, elem, value);
return ir_emit_conv(proc, x, tv.type);
@@ -5014,16 +4917,6 @@ irValue *ir_build_expr(irProcedure *proc, AstNode *expr) {
case Token_CmpAnd:
case Token_CmpOr:
if (is_type_vector(type)) {
TokenKind op = {};
switch (be->op.kind) {
case Token_CmpAnd: op = Token_And; break;
case Token_CmpOr: op = Token_Or; break;
}
irValue *right = ir_build_expr(proc, be->right);
return ir_emit_arith(proc, op, left, right, type);
}
return ir_emit_logical_binary_expr(proc, expr);
default:
@@ -5533,27 +5426,6 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
irValue *using_addr = nullptr;
switch (t->kind) {
case Type_Vector: {
irValue *vector = nullptr;
if (using_addr != nullptr) {
vector = using_addr;
} else {
vector = ir_build_addr_ptr(proc, ie->expr);
if (deref) {
vector = ir_emit_load(proc, vector);
}
}
irValue *index = ir_emit_conv(proc, ir_build_expr(proc, ie->index), t_int);
irValue *elem = ir_emit_array_ep(proc, vector, index);
auto index_tv = type_and_value_of_expr(proc->module->info, ie->index);
if (index_tv.mode != Addressing_Constant) {
irValue *len = ir_const_int(a, t->Vector.count);
ir_emit_bounds_check(proc, ast_node_token(ie->index), index, len);
}
return ir_addr(elem);
break;
}
case Type_Array: {
irValue *array = nullptr;
if (using_addr != nullptr) {
@@ -5569,7 +5441,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
auto index_tv = type_and_value_of_expr(proc->module->info, ie->index);
if (index_tv.mode != Addressing_Constant) {
irValue *len = ir_const_int(a, t->Vector.count);
irValue *len = ir_const_int(a, t->Array.count);
ir_emit_bounds_check(proc, ast_node_token(ie->index), index, len);
}
return ir_addr(elem);
@@ -5761,7 +5633,6 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
Type *et = nullptr;
switch (bt->kind) {
case Type_Vector: et = bt->Vector.elem; break;
case Type_Array: et = bt->Array.elem; break;
case Type_Slice: et = bt->Slice.elem; break;
}
@@ -5775,31 +5646,6 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
switch (bt->kind) {
default: GB_PANIC("Unknown CompoundLit type: %s", type_to_string(type)); break;
case Type_Vector: {
if (cl->elems.count == 1 && bt->Vector.count > 1) {
isize index_count = bt->Vector.count;
irValue *elem_val = ir_build_expr(proc, cl->elems[0]);
for (isize i = 0; i < index_count; i++) {
ir_emit_store(proc, ir_emit_array_epi(proc, v, cast(i32)i), elem_val);
}
} else if (cl->elems.count > 0) {
ir_emit_store(proc, v, ir_add_module_constant(proc->module, type, exact_value_compound(expr)));
for_array(i, cl->elems) {
AstNode *elem = cl->elems[i];
if (ir_is_elem_const(proc->module, elem, et)) {
continue;
}
irValue *field_expr = ir_build_expr(proc, elem);
Type *t = ir_type(field_expr);
GB_ASSERT(t->kind != Type_Tuple);
irValue *ev = ir_emit_conv(proc, field_expr, et);
irValue *gep = ir_emit_array_epi(proc, v, cast(i32)i);
ir_emit_store(proc, gep, ev);
}
}
break;
}
case Type_Struct: {
// TODO(bill): "constant" '#raw_union's are not initialized constantly at the moment.
@@ -6291,9 +6137,6 @@ void ir_build_range_indexed(irProcedure *proc, irValue *expr, Type *val_type, ir
case Type_Array:
count = ir_const_int(proc->module->allocator, expr_type->Array.count);
break;
case Type_Vector:
count = ir_const_int(proc->module->allocator, expr_type->Vector.count);
break;
}
irValue *val = nullptr;
@@ -6333,10 +6176,6 @@ void ir_build_range_indexed(irProcedure *proc, irValue *expr, Type *val_type, ir
val = ir_emit_load(proc, ir_emit_array_ep(proc, expr, idx));
break;
}
case Type_Vector: {
val = ir_emit_load(proc, ir_emit_array_ep(proc, expr, idx));
break;
}
case Type_Slice: {
irValue *elem = ir_slice_elem(proc, expr);
val = ir_emit_load(proc, ir_emit_ptr_offset(proc, elem, idx));
@@ -7020,17 +6859,6 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
ir_build_range_indexed(proc, array, val0_type, count_ptr, &val, &key, &loop, &done);
break;
}
case Type_Vector: {
irValue *count_ptr = nullptr;
irValue *vector = ir_build_addr_ptr(proc, rs->expr);
if (is_type_pointer(type_deref(ir_type(vector)))) {
vector = ir_emit_load(proc, vector);
}
count_ptr = ir_add_local_generated(proc, t_int);
ir_emit_store(proc, count_ptr, ir_const_int(proc->module->allocator, et->Vector.count));
ir_build_range_indexed(proc, vector, val0_type, count_ptr, &val, &key, &loop, &done);
break;
}
case Type_DynamicArray: {
irValue *count_ptr = nullptr;
irValue *array = ir_build_addr_ptr(proc, rs->expr);
@@ -8023,18 +7851,6 @@ void ir_setup_type_info_data(irProcedure *proc) { // NOTE(bill): Setup type_info
ir_emit_store(proc, elem_size, ir_const_int(a, ez));
break;
}
case Type_Vector: {
ir_emit_comment(proc, str_lit("TypeInfoVector"));
tag = ir_emit_conv(proc, variant_ptr, t_type_info_vector_ptr);
irValue *gep = ir_get_type_info_ptr(proc, t->Vector.elem);
ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 0), gep);
isize ez = type_size_of(a, t->Vector.elem);
ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 1), ir_const_int(a, ez));
ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 2), ir_const_int(a, t->Vector.count));
break;
}
case Type_Proc: {
ir_emit_comment(proc, str_lit("TypeInfoProc"));
tag = ir_emit_conv(proc, variant_ptr, t_type_info_procedure_ptr);

View File

@@ -312,14 +312,6 @@ void ir_print_type(irFileBuffer *f, irModule *m, Type *t) {
ir_print_type(f, m, t->Array.elem);
ir_write_byte(f, ']');
return;
case Type_Vector: {
i64 align = type_align_of(heap_allocator(), t);
i64 count = t->Vector.count;
ir_fprintf(f, "{[0 x <%lld x i8>], [%lld x ", align, count);
ir_print_type(f, m, t->Vector.elem);
ir_fprintf(f, "]}");
return;
}
case Type_Slice:
ir_write_byte(f, '{');
ir_print_type(f, m, t->Slice.elem);
@@ -617,44 +609,6 @@ void ir_print_exact_value(irFileBuffer *f, irModule *m, ExactValue value, Type *
}
ir_write_byte(f, ']');
} else if (is_type_vector(type)) {
ast_node(cl, CompoundLit, value.value_compound);
isize elem_count = cl->elems.count;
if (elem_count == 0) {
ir_write_string(f, "zeroinitializer");
break;
}
i64 align = type_align_of(m->allocator, type);
i64 count = type->Vector.count;
Type *elem_type = type->Vector.elem;
ir_fprintf(f, "{[0 x <%lld x i8>] zeroinitializer, [%lld x ", align, count);
ir_print_type(f, m, elem_type);
ir_write_string(f, "][");
if (elem_count == 1 && type->Vector.count > 1) {
TypeAndValue tav = type_and_value_of_expr(m->info, cl->elems[0]);
GB_ASSERT(tav.mode != Addressing_Invalid);
for (isize i = 0; i < type->Vector.count; i++) {
if (i > 0) {
ir_write_string(f, str_lit(", "));
}
ir_print_compound_element(f, m, tav.value, elem_type);
}
} else {
for (isize i = 0; i < elem_count; i++) {
if (i > 0) {
ir_write_string(f, str_lit(", "));
}
TypeAndValue tav = type_and_value_of_expr(m->info, cl->elems[i]);
GB_ASSERT(tav.mode != Addressing_Invalid);
ir_print_compound_element(f, m, tav.value, elem_type);
}
}
ir_write_string(f, "]}");
} else if (is_type_struct(type)) {
gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&m->tmp_arena);
defer (gb_temp_arena_memory_end(tmp));
@@ -1018,10 +972,6 @@ void ir_print_instr(irFileBuffer *f, irModule *m, irValue *value) {
ir_write_string(f, str_lit(", "));
ir_print_type(f, m, t_int);
ir_write_string(f, " 0, ");
if (is_type_vector(type_deref(et))) {
ir_print_type(f, m, t_i32);
ir_write_string(f, " 1, ");
}
irValue *index =instr->ArrayElementPtr.elem_index;
Type *t = ir_type(index);
@@ -1230,9 +1180,6 @@ void ir_print_instr(irFileBuffer *f, irModule *m, irValue *value) {
irInstrUnaryOp *uo = &value->Instr.UnaryOp;
Type *type = base_type(ir_type(uo->expr));
Type *elem_type = type;
while (elem_type->kind == Type_Vector) {
elem_type = base_type(elem_type->Vector.elem);
}
ir_fprintf(f, "%%%d = ", value->index);
switch (uo->op) {
@@ -1280,7 +1227,6 @@ void ir_print_instr(irFileBuffer *f, irModule *m, irValue *value) {
irInstrBinaryOp *bo = &value->Instr.BinaryOp;
Type *type = base_type(ir_type(bo->left));
Type *elem_type = type;
GB_ASSERT_MSG(!is_type_vector(elem_type), type_to_string(elem_type));
ir_fprintf(f, "%%%d = ", value->index);

View File

@@ -436,11 +436,6 @@ AST_NODE_KIND(_TypeBegin, "", i32) \
Token token; \
AstNode *elem; \
}) \
AST_NODE_KIND(VectorType, "vector type", struct { \
Token token; \
AstNode *count; \
AstNode *elem; \
}) \
AST_NODE_KIND(StructType, "struct type", struct { \
Token token; \
Array<AstNode *> fields; \
@@ -621,7 +616,6 @@ Token ast_node_token(AstNode *node) {
case AstNode_PointerType: return node->PointerType.token;
case AstNode_ArrayType: return node->ArrayType.token;
case AstNode_DynamicArrayType: return node->DynamicArrayType.token;
case AstNode_VectorType: return node->VectorType.token;
case AstNode_StructType: return node->StructType.token;
case AstNode_UnionType: return node->UnionType.token;
case AstNode_EnumType: return node->EnumType.token;
@@ -879,10 +873,6 @@ AstNode *clone_ast_node(gbAllocator a, AstNode *node) {
case AstNode_DynamicArrayType:
n->DynamicArrayType.elem = clone_ast_node(a, n->DynamicArrayType.elem);
break;
case AstNode_VectorType:
n->VectorType.count = clone_ast_node(a, n->VectorType.count);
n->VectorType.elem = clone_ast_node(a, n->VectorType.elem);
break;
case AstNode_StructType:
n->StructType.fields = clone_ast_node_array(a, n->StructType.fields);
n->StructType.polymorphic_params = clone_ast_node(a, n->StructType.polymorphic_params);
@@ -1458,14 +1448,6 @@ AstNode *ast_dynamic_array_type(AstFile *f, Token token, AstNode *elem) {
return result;
}
AstNode *ast_vector_type(AstFile *f, Token token, AstNode *count, AstNode *elem) {
AstNode *result = make_ast_node(f, AstNode_VectorType);
result->VectorType.token = token;
result->VectorType.count = count;
result->VectorType.elem = elem;
return result;
}
AstNode *ast_struct_type(AstFile *f, Token token, Array<AstNode *> fields, isize field_count,
AstNode *polymorphic_params, bool is_packed, bool is_ordered, bool is_raw_union,
AstNode *align) {
@@ -2339,15 +2321,6 @@ AstNode *parse_operand(AstFile *f, bool lhs) {
if (f->curr_token.kind == Token_Ellipsis) {
count_expr = ast_unary_expr(f, expect_token(f, Token_Ellipsis), nullptr);
} else if (allow_token(f, Token_vector)) {
if (f->curr_token.kind != Token_CloseBracket) {
f->expr_level++;
count_expr = parse_expr(f, false);
f->expr_level--;
} else {
syntax_error(f->curr_token, "Vector type missing count");
}
is_vector = true;
} else if (allow_token(f, Token_dynamic)) {
expect_token(f, Token_CloseBracket);
return ast_dynamic_array_type(f, token, parse_type(f));
@@ -2357,9 +2330,6 @@ AstNode *parse_operand(AstFile *f, bool lhs) {
f->expr_level--;
}
expect_token(f, Token_CloseBracket);
if (is_vector) {
return ast_vector_type(f, token, count_expr, parse_type(f));
}
return ast_array_type(f, token, count_expr, parse_type(f));
} break;
@@ -2577,7 +2547,6 @@ bool is_literal_type(AstNode *node) {
case AstNode_Ident:
case AstNode_SelectorExpr:
case AstNode_ArrayType:
case AstNode_VectorType:
case AstNode_StructType:
case AstNode_UnionType:
case AstNode_EnumType:

View File

@@ -631,8 +631,6 @@ bool can_ssa_type(Type *t) {
switch (t->kind) {
case Type_Array:
return t->Array.count == 0;
case Type_Vector:
return s < 2*build_context.word_size;
case Type_DynamicArray:
return false;
@@ -793,12 +791,10 @@ ssaValue *ssa_emit_array_index(ssaProc *p, ssaValue *v, ssaValue *index) {
GB_ASSERT(v != nullptr);
GB_ASSERT(is_type_pointer(v->type));
Type *t = base_type(type_deref(v->type));
GB_ASSERT_MSG(is_type_array(t) || is_type_vector(t), "%s", type_to_string(t));
GB_ASSERT_MSG(is_type_array(t), "%s", type_to_string(t));
Type *elem_ptr = nullptr;
if (is_type_array(t)) {
elem_ptr = make_type_pointer(p->allocator, t->Array.elem);
} else if (is_type_vector(t)) {
elem_ptr = make_type_pointer(p->allocator, t->Vector.elem);
}
return ssa_new_value2(p, ssaOp_ArrayIndex, elem_ptr, v, index);
@@ -960,8 +956,6 @@ ssaValue *ssa_emit_deep_field_ptr_index(ssaProc *p, ssaValue *e, Selection sel)
e = ssa_emit_ptr_index(p, e, index);
} else if (type->kind == Type_DynamicArray) {
e = ssa_emit_ptr_index(p, e, index);
} else if (type->kind == Type_Vector) {
e = ssa_emit_array_index(p, e, ssa_const_int(p, t_int, index));
} else if (type->kind == Type_Array) {
e = ssa_emit_array_index(p, e, ssa_const_int(p, t_int, index));
} else if (type->kind == Type_Map) {
@@ -1386,31 +1380,6 @@ ssaValue *ssa_emit_comp(ssaProc *p, TokenKind op, ssaValue *x, ssaValue *y) {
}
Type *result = t_bool;
if (is_type_vector(a)) {
result = make_type_vector(p->allocator, t_bool, a->Vector.count);
}
if (is_type_vector(a)) {
ssa_emit_comment(p, str_lit("vector.comp.begin"));
Type *tl = base_type(a);
ssaValue *lhs = ssa_address_from_load_or_generate_local(p, x);
ssaValue *rhs = ssa_address_from_load_or_generate_local(p, y);
GB_ASSERT(is_type_vector(result));
Type *elem_type = base_type(result)->Vector.elem;
ssaAddr addr = ssa_add_local_generated(p, result);
for (i32 i = 0; i < tl->Vector.count; i++) {
ssaValue *index = ssa_const_int(p, t_int, i);
ssaValue *x = ssa_emit_load(p, ssa_emit_array_index(p, lhs, index));
ssaValue *y = ssa_emit_load(p, ssa_emit_array_index(p, rhs, index));
ssaValue *z = ssa_emit_comp(p, op, x, y);
ssa_emit_store(p, ssa_emit_array_index(p, addr.addr, index), z);
}
ssa_emit_comment(p, str_lit("vector.comp.end"));
return ssa_addr_load(p, addr);
}
return ssa_new_value2(p, ssa_determine_op(op, x->type), x->type, x, y);
}
@@ -1418,27 +1387,6 @@ ssaValue *ssa_emit_comp(ssaProc *p, TokenKind op, ssaValue *x, ssaValue *y) {
ssaValue *ssa_emit_unary_arith(ssaProc *p, TokenKind op, ssaValue *x, Type *type) {
if (is_type_vector(x->type)) {
ssa_emit_comment(p, str_lit("vector.arith.begin"));
// IMPORTANT TODO(bill): This is very wasteful with regards to stack memory
Type *tl = base_type(x->type);
ssaValue *val = ssa_address_from_load_or_generate_local(p, x);
GB_ASSERT(is_type_vector(type));
Type *elem_type = base_type(type)->Vector.elem;
ssaAddr res = ssa_add_local_generated(p, type);
for (i64 i = 0; i < tl->Vector.count; i++) {
ssaValue *index = ssa_const_int(p, t_int, i);
ssaValue *e = ssa_emit_load(p, ssa_emit_array_index(p, val, index));
ssaValue *z = ssa_emit_unary_arith(p, op, e, elem_type);
ssa_emit_store(p, ssa_emit_array_index(p, res.addr, index), z);
}
ssa_emit_comment(p, str_lit("vector.arith.end"));
return ssa_addr_load(p, res);
}
switch (op) {
case Token_Pointer: {
GB_PANIC("Token_Pointer should be handled elsewhere");
@@ -1481,9 +1429,7 @@ ssaValue *ssa_emit_unary_arith(ssaProc *p, TokenKind op, ssaValue *x, Type *type
return nullptr;
}
ssaValue *ssa_emit_arith(ssaProc *p, TokenKind op, ssaValue *x, ssaValue *y, Type *type) {
if (is_type_vector(x->type)) {
GB_PANIC("TODO(bill): ssa_emit_arith vector");
} else if (is_type_complex(x->type)) {
if (is_type_complex(x->type)) {
GB_PANIC("TODO(bill): ssa_emit_arith complex");
}

View File

@@ -105,7 +105,6 @@ TOKEN_KIND(Token__KeywordBegin, "_KeywordBegin"), \
TOKEN_KIND(Token_union, "union"), \
TOKEN_KIND(Token_enum, "enum"), \
TOKEN_KIND(Token_bit_field, "bit_field"), \
TOKEN_KIND(Token_vector, "vector"), \
TOKEN_KIND(Token_map, "map"), \
TOKEN_KIND(Token_static, "static"), \
TOKEN_KIND(Token_dynamic, "dynamic"), \

View File

@@ -107,11 +107,6 @@ struct TypeStruct {
Type *generic_type; \
}) \
TYPE_KIND(DynamicArray, struct { Type *elem; }) \
TYPE_KIND(Vector, struct { \
Type *elem; \
i64 count; \
Type *generic_type; \
}) \
TYPE_KIND(Slice, struct { Type *elem; }) \
TYPE_KIND(Struct, TypeStruct) \
TYPE_KIND(Enum, struct { \
@@ -212,7 +207,7 @@ struct Type {
// TODO(bill): Should I add extra information here specifying the kind of selection?
// e.g. field, constant, vector field, type field, etc.
// e.g. field, constant, array field, type field, etc.
struct Selection {
Entity * entity;
Array<i32> index;
@@ -356,7 +351,6 @@ gb_global Type *t_type_info_procedure = nullptr;
gb_global Type *t_type_info_array = nullptr;
gb_global Type *t_type_info_dynamic_array = nullptr;
gb_global Type *t_type_info_slice = nullptr;
gb_global Type *t_type_info_vector = nullptr;
gb_global Type *t_type_info_tuple = nullptr;
gb_global Type *t_type_info_struct = nullptr;
gb_global Type *t_type_info_union = nullptr;
@@ -378,7 +372,6 @@ gb_global Type *t_type_info_procedure_ptr = nullptr;
gb_global Type *t_type_info_array_ptr = nullptr;
gb_global Type *t_type_info_dynamic_array_ptr = nullptr;
gb_global Type *t_type_info_slice_ptr = nullptr;
gb_global Type *t_type_info_vector_ptr = nullptr;
gb_global Type *t_type_info_tuple_ptr = nullptr;
gb_global Type *t_type_info_struct_ptr = nullptr;
gb_global Type *t_type_info_union_ptr = nullptr;
@@ -506,14 +499,6 @@ Type *make_type_dynamic_array(gbAllocator a, Type *elem) {
return t;
}
Type *make_type_vector(gbAllocator a, Type *elem, i64 count, Type *generic_type = nullptr) {
Type *t = alloc_type(a, Type_Vector);
t->Vector.elem = elem;
t->Vector.count = count;
t->Vector.generic_type = generic_type;
return t;
}
Type *make_type_slice(gbAllocator a, Type *elem) {
Type *t = alloc_type(a, Type_Slice);
t->Array.elem = elem;
@@ -673,9 +658,6 @@ bool is_type_numeric(Type *t) {
return (t->Basic.flags & BasicFlag_Numeric) != 0;
}
// TODO(bill): Should this be here?
if (t->kind == Type_Vector) {
return is_type_numeric(t->Vector.elem);
}
#if defined(ALLOW_ARRAY_PROGRAMMING)
if (t->kind == Type_Array) {
return is_type_numeric(t->Array.elem);
@@ -714,8 +696,6 @@ bool is_type_ordered(Type *t) {
return (t->Basic.flags & BasicFlag_Ordered) != 0;
case Type_Pointer:
return true;
case Type_Vector:
return is_type_ordered(t->Vector.elem);
}
return false;
}
@@ -810,10 +790,6 @@ bool is_type_u8_slice(Type *t) {
}
return false;
}
bool is_type_vector(Type *t) {
t = base_type(t);
return t->kind == Type_Vector;
}
bool is_type_proc(Type *t) {
t = base_type(t);
return t->kind == Type_Proc;
@@ -822,13 +798,6 @@ bool is_type_poly_proc(Type *t) {
t = base_type(t);
return t->kind == Type_Proc && t->Proc.is_polymorphic;
}
Type *base_vector_type(Type *t) {
if (is_type_vector(t)) {
t = base_type(t);
return t->Vector.elem;
}
return t;
}
Type *base_array_type(Type *t) {
if (is_type_array(t)) {
t = base_type(t);
@@ -843,11 +812,10 @@ bool is_type_generic(Type *t) {
}
Type *core_array_or_vector_type(Type *t) {
Type *core_array_type(Type *t) {
for (;;) {
Type *prev = t;
t = base_array_type(t);
t = base_vector_type(t);
if (prev == t) break;
}
return t;
@@ -956,7 +924,6 @@ bool is_type_indexable(Type *t) {
return is_type_string(bt);
case Type_Array:
case Type_Slice:
case Type_Vector:
case Type_DynamicArray:
case Type_Map:
return true;
@@ -996,8 +963,6 @@ bool is_type_polymorphic(Type *t) {
return true;
}
return is_type_polymorphic(t->Array.elem);
case Type_Vector:
return is_type_polymorphic(t->Vector.elem);
case Type_DynamicArray:
return is_type_polymorphic(t->DynamicArray.elem);
case Type_Slice:
@@ -1124,8 +1089,6 @@ bool is_type_comparable(Type *t) {
return is_type_comparable(core_type(t));
case Type_Array:
return is_type_comparable(t->Array.elem);
case Type_Vector:
return is_type_comparable(t->Vector.elem);
case Type_Proc:
return true;
}
@@ -1167,12 +1130,6 @@ bool are_types_identical(Type *x, Type *y) {
}
break;
case Type_Vector:
if (y->kind == Type_Vector) {
return (x->Vector.count == y->Vector.count) && are_types_identical(x->Vector.elem, y->Vector.elem);
}
break;
case Type_Slice:
if (y->kind == Type_Slice) {
return are_types_identical(x->Slice.elem, y->Slice.elem);
@@ -1356,9 +1313,6 @@ bool is_type_cte_safe(Type *type) {
case Type_Map:
return false;
case Type_Vector: // NOTE(bill): This should always to be true but this is for sanity reasons
return is_type_cte_safe(type->Vector.elem);
case Type_Slice:
return false;
@@ -1620,26 +1574,26 @@ Selection lookup_field_with_selection(gbAllocator a, Type *type_, String field_n
}
return sel;
} else if (type->kind == Type_Vector) {
if (type->Vector.count <= 4 && !is_type_boolean(type->Vector.elem)) {
} else if (type->kind == Type_Array) {
if (type->Array.count <= 4) {
// HACK(bill): Memory leak
switch (type->Vector.count) {
#define _VECTOR_FIELD_CASE(_length, _name) \
switch (type->Array.count) {
#define _ARRAY_FIELD_CASE(_length, _name) \
case (_length): \
if (field_name == _name) { \
selection_add_index(&sel, (_length)-1); \
sel.entity = make_entity_vector_elem(a, nullptr, make_token_ident(str_lit(_name)), type->Vector.elem, (_length)-1); \
sel.entity = make_entity_array_elem(a, nullptr, make_token_ident(str_lit(_name)), type->Array.elem, (_length)-1); \
return sel; \
} \
/*fallthrough*/
_VECTOR_FIELD_CASE(4, "w");
_VECTOR_FIELD_CASE(3, "z");
_VECTOR_FIELD_CASE(2, "y");
_VECTOR_FIELD_CASE(1, "x");
_ARRAY_FIELD_CASE(4, "w");
_ARRAY_FIELD_CASE(3, "z");
_ARRAY_FIELD_CASE(2, "y");
_ARRAY_FIELD_CASE(1, "x");
default: break;
#undef _VECTOR_FIELD_CASE
#undef _ARRAY_FIELD_CASE
}
}
}
@@ -1890,18 +1844,6 @@ i64 type_align_of_internal(gbAllocator allocator, Type *t, TypePath *path) {
if (pop) type_path_pop(path);
return align;
}
case Type_Vector: {
Type *elem = t->Vector.elem;
bool pop = type_path_push(path, elem);
if (path->failure) {
return FAILURE_ALIGNMENT;
}
i64 size = type_size_of_internal(allocator, t->Vector.elem, path);
if (pop) type_path_pop(path);
i64 count = gb_max(prev_pow2(t->Vector.count), 1);
i64 total = size * count;
return gb_clamp(total, 1, build_context.max_align);
} break;
case Type_DynamicArray:
// data, count, capacity, allocator
@@ -2102,43 +2044,6 @@ i64 type_size_of_internal(gbAllocator allocator, Type *t, TypePath *path) {
return alignment*(count-1) + size;
} break;
case Type_Vector: {
#if 0
i64 count, bit_size, total_size_in_bits, total_size;
count = t->Vector.count;
if (count == 0) {
return 0;
}
bool pop = type_path_push(path, t->Vector.elem);
if (path->failure) {
return FAILURE_SIZE;
}
bit_size = 8*type_size_of_internal(allocator, t->Vector.elem, path);
if (pop) type_path_pop(path);
if (is_type_boolean(t->Vector.elem)) {
bit_size = 1; // NOTE(bill): LLVM can store booleans as 1 bit because a boolean _is_ an `i1`
// Silly LLVM spec
}
total_size_in_bits = bit_size * count;
total_size = (total_size_in_bits+7)/8;
return total_size;
#else
i64 count = t->Vector.count;
if (count == 0) {
return 0;
}
i64 elem_align = type_align_of_internal(allocator, t->Vector.elem, path);
if (path->failure) {
return FAILURE_SIZE;
}
i64 vector_align = type_align_of_internal(allocator, t, path);
i64 elem_size = type_size_of_internal(allocator, t->Vector.elem, path);
i64 alignment = align_formula(elem_size, elem_align);
return align_formula(alignment*(count-1) + elem_size, vector_align);
#endif
} break;
case Type_Slice: // ptr + len
return 2 * build_context.word_size;
@@ -2378,11 +2283,6 @@ gbString write_type_to_string(gbString str, Type *type) {
str = write_type_to_string(str, type->Array.elem);
break;
case Type_Vector:
str = gb_string_appendc(str, gb_bprintf("[vector %d]", cast(int)type->Vector.count));
str = write_type_to_string(str, type->Vector.elem);
break;
case Type_Slice:
str = gb_string_appendc(str, "[]");
str = write_type_to_string(str, type->Array.elem);