mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-31 11:50:07 +00:00
#foreign_library; vector fields (x, y, z, w) for count <= 4
This commit is contained in:
@@ -1047,7 +1047,7 @@ void check_parsed_files(Checker *c) {
|
||||
case_ast_node(id, ImportDecl, decl);
|
||||
// NOTE(bill): Handle later
|
||||
case_end;
|
||||
case_ast_node(fsl, ForeignSystemLibrary, decl);
|
||||
case_ast_node(fsl, ForeignLibrary, decl);
|
||||
// NOTE(bill): ignore
|
||||
case_end;
|
||||
|
||||
|
||||
+15
-5
@@ -29,11 +29,12 @@ String const entity_strings[] = {
|
||||
};
|
||||
|
||||
enum EntityFlag : u32 {
|
||||
EntityFlag_Visited = 1<<0,
|
||||
EntityFlag_Used = 1<<1,
|
||||
EntityFlag_Anonymous = 1<<2,
|
||||
EntityFlag_Field = 1<<3,
|
||||
EntityFlag_Param = 1<<4,
|
||||
EntityFlag_Visited = 1<<0,
|
||||
EntityFlag_Used = 1<<1,
|
||||
EntityFlag_Anonymous = 1<<2,
|
||||
EntityFlag_Field = 1<<3,
|
||||
EntityFlag_Param = 1<<4,
|
||||
EntityFlag_VectorElem = 1<<5,
|
||||
};
|
||||
|
||||
struct Entity {
|
||||
@@ -141,6 +142,15 @@ 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 *entity = make_entity_variable(a, scope, token, type);
|
||||
entity->Variable.field_src_index = field_src_index;
|
||||
entity->Variable.field_index = field_src_index;
|
||||
entity->flags |= EntityFlag_Field;
|
||||
entity->flags |= EntityFlag_VectorElem;
|
||||
return entity;
|
||||
}
|
||||
|
||||
Entity *make_entity_procedure(gbAllocator a, Scope *scope, Token token, Type *signature_type) {
|
||||
Entity *entity = alloc_entity(a, Entity_Procedure, scope, token, signature_type);
|
||||
return entity;
|
||||
|
||||
+20
-3
@@ -1429,9 +1429,22 @@ b32 check_is_expr_vector_index(Checker *c, AstNode *expr) {
|
||||
expr = unparen_expr(expr);
|
||||
if (expr->kind == AstNode_IndexExpr) {
|
||||
ast_node(ie, IndexExpr, expr);
|
||||
Type *t = type_of_expr(&c->info, ie->expr);
|
||||
Type *t = type_deref(type_of_expr(&c->info, ie->expr));
|
||||
if (t != NULL) {
|
||||
return is_type_vector(base_type(t));
|
||||
return is_type_vector(t);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
b32 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 != NULL && is_type_vector(t)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@@ -1443,7 +1456,8 @@ void check_unary_expr(Checker *c, Operand *o, Token op, AstNode *node) {
|
||||
switch (op.kind) {
|
||||
case Token_Pointer: { // Pointer address
|
||||
if (o->mode != Addressing_Variable ||
|
||||
check_is_expr_vector_index(c, o->expr)) {
|
||||
check_is_expr_vector_index(c, o->expr) ||
|
||||
check_is_vector_elem(c, o->expr)) {
|
||||
ast_node(ue, UnaryExpr, node);
|
||||
gbString str = expr_to_string(ue->expr);
|
||||
defer (gb_string_free(str));
|
||||
@@ -3666,6 +3680,9 @@ ExprKind check__expr_base(Checker *c, Operand *o, AstNode *node, Type *type_hint
|
||||
switch (t->kind) {
|
||||
case Type_Record: {
|
||||
if (!is_type_struct(t)) {
|
||||
if (cl->elems.count != 0) {
|
||||
error(ast_node_token(node), "Illegal compound literal");
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (cl->elems.count == 0) {
|
||||
|
||||
@@ -438,8 +438,8 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) {
|
||||
isize lhs_count = as->lhs.count;
|
||||
isize rhs_count = operands.count;
|
||||
|
||||
isize operand_index = 0;
|
||||
for_array(i, operands) {
|
||||
isize operand_count = gb_min(as->lhs.count, operands.count);
|
||||
for (isize i = 0; i < operand_count; i++) {
|
||||
AstNode *lhs = as->lhs[i];
|
||||
check_assignment_variable(c, &operands[i], lhs);
|
||||
}
|
||||
|
||||
+24
-1
@@ -908,6 +908,28 @@ Selection lookup_field(gbAllocator a, Type *type_, String field_name, b32 is_typ
|
||||
sel.entity = make_entity_constant(a, NULL, make_token_ident(count_str), t_int, make_exact_value_integer(type->Vector.count));
|
||||
return sel;
|
||||
}
|
||||
if (type->Vector.count <= 4 && !is_type_boolean(type->Vector.elem)) {
|
||||
// HACK(bill): Memory leak
|
||||
switch (type->Vector.count) {
|
||||
#define _VECTOR_FIELD(_name, length) \
|
||||
case (length): \
|
||||
if (field_name == _name) { \
|
||||
selection_add_index(&sel, (length)-1); \
|
||||
sel.entity = make_entity_field(a, NULL, make_token_ident(make_string(_name)), type->Vector.elem, false, (length)-1); \
|
||||
return sel; \
|
||||
} \
|
||||
/*fallthrough*/
|
||||
|
||||
_VECTOR_FIELD("w", 4);
|
||||
_VECTOR_FIELD("z", 3);
|
||||
_VECTOR_FIELD("y", 2);
|
||||
_VECTOR_FIELD("x", 1);
|
||||
case 0: break;
|
||||
|
||||
#undef _VECTOR_FIELD
|
||||
}
|
||||
}
|
||||
|
||||
} else if (type->kind == Type_Slice) {
|
||||
String data_str = make_string("data");
|
||||
String count_str = make_string("count");
|
||||
@@ -1059,7 +1081,8 @@ i64 type_align_of(BaseTypeSizes s, gbAllocator allocator, Type *t) {
|
||||
switch (t->Record.kind) {
|
||||
case TypeRecord_Struct:
|
||||
if (t->Record.field_count > 0) {
|
||||
if (!t->Record.struct_is_ordered) {
|
||||
// TODO(bill): What is this supposed to be?
|
||||
if (t->Record.struct_is_packed) {
|
||||
i64 max = s.word_size;
|
||||
for (isize i = 1; i < t->Record.field_count; i++) {
|
||||
// NOTE(bill): field zero is null
|
||||
|
||||
Reference in New Issue
Block a user