2
0
Эх сурвалжийг харах

Fix error printing for basic directives

Ginger Bill 8 жил өмнө
parent
commit
0c22081e5f

+ 1 - 0
core/_preload.odin

@@ -39,6 +39,7 @@ Type_Info_Record :: struct #ordered {
 Type_Info :: union {
 	size:  int,
 	align: int,
+
 	Named{name: string, base: ^Type_Info},
 	Integer{signed: bool},
 	Float{},

+ 4 - 0
core/os_windows.odin

@@ -210,6 +210,10 @@ read_entire_file :: proc(name: string) -> ([]byte, bool) {
 		return nil, false;
 	}
 
+	if length == 0 {
+		return nil, true;
+	}
+
 	data := make([]byte, length);
 	if data == nil {
 		return nil, false;

+ 10 - 2
src/check_expr.c

@@ -2366,9 +2366,9 @@ bool check_is_castable_to(Checker *c, Operand *operand, Type *y) {
 		return true;
 	}
 	if (is_type_string(src) && is_type_u8_slice(dst)) {
-		if (is_type_typed(src)) {
+		// if (is_type_typed(src)) {
 			return true;
-		}
+		// }
 	}
 
 	// proc <-> proc
@@ -2404,6 +2404,8 @@ void check_cast(Checker *c, Operand *x, Type *type) {
 	} else if (check_is_castable_to(c, x, type)) {
 		if (x->mode != Addressing_Constant) {
 			x->mode = Addressing_Value;
+		} else if (is_type_slice(type) && is_type_string(x->type)) {
+			x->mode = Addressing_Value;
 		}
 		can_convert = true;
 	}
@@ -4935,6 +4937,7 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
 		check_ident(c, o, node, NULL, type_hint, false);
 	case_end;
 
+
 	case_ast_node(bl, BasicLit, node);
 		Type *t = t_invalid;
 		switch (bl->kind) {
@@ -5929,6 +5932,11 @@ gbString write_expr_to_string(gbString str, AstNode *node) {
 		str = string_append_token(str, *bl);
 	case_end;
 
+	case_ast_node(bd, BasicDirective, node);
+		str = gb_string_appendc(str, "#");
+		str = gb_string_append_length(str, bd->name.text, bd->name.len);
+	case_end;
+
 	case_ast_node(pl, ProcLit, node);
 		str = write_expr_to_string(str, pl->type);
 	case_end;

+ 3 - 2
src/checker.c

@@ -1521,10 +1521,11 @@ void check_collect_entities(Checker *c, AstNodeArray nodes, bool is_file_scope)
 
 					AstNode *up_init = unparen_expr(init);
 					if (up_init != NULL && is_ast_node_type(up_init)) {
+						AstNode *type = up_init;
 						e = make_entity_type_name(c->allocator, d->scope, name->Ident, NULL);
 						// TODO(bill): What if vd->type != NULL??? How to handle this case?
-						d->type_expr = init;
-						d->init_expr = init;
+						d->type_expr = type;
+						d->init_expr = type;
 					} else if (up_init != NULL && up_init->kind == AstNode_Alias) {
 						error_node(up_init, "#alias declarations are not yet supported");
 						continue;

+ 3 - 1
src/entity.c

@@ -75,7 +75,9 @@ struct Entity {
 			bool is_immutable;
 			bool is_thread_local;
 		} Variable;
-		i32 TypeName;
+		struct {
+			bool is_type_alias;
+		} TypeName;
 		struct {
 			bool         is_foreign;
 			String       foreign_name;

+ 16 - 16
src/tokenizer.c

@@ -64,18 +64,18 @@ TOKEN_KIND(Token__ComparisonBegin, "_ComparisonBegin"), \
 	TOKEN_KIND(Token_GtEq,  ">="), \
 TOKEN_KIND(Token__ComparisonEnd, "_ComparisonEnd"), \
 \
-	TOKEN_KIND(Token_OpenParen,     "("), \
-	TOKEN_KIND(Token_CloseParen,    ")"), \
-	TOKEN_KIND(Token_OpenBracket,   "["), \
-	TOKEN_KIND(Token_CloseBracket,  "]"), \
-	TOKEN_KIND(Token_OpenBrace,     "{"), \
-	TOKEN_KIND(Token_CloseBrace,    "}"), \
-	TOKEN_KIND(Token_Colon,         ":"), \
-	TOKEN_KIND(Token_Semicolon,     ";"), \
-	TOKEN_KIND(Token_Period,        "."), \
-	TOKEN_KIND(Token_Comma,         ","), \
-	TOKEN_KIND(Token_Ellipsis,      ".."), \
-	/* TOKEN_KIND(Token_HalfOpenRange, "..<"), */ \
+	TOKEN_KIND(Token_OpenParen,     "("),   \
+	TOKEN_KIND(Token_CloseParen,    ")"),   \
+	TOKEN_KIND(Token_OpenBracket,   "["),   \
+	TOKEN_KIND(Token_CloseBracket,  "]"),   \
+	TOKEN_KIND(Token_OpenBrace,     "{"),   \
+	TOKEN_KIND(Token_CloseBrace,    "}"),   \
+	TOKEN_KIND(Token_Colon,         ":"),   \
+	TOKEN_KIND(Token_Semicolon,     ";"),   \
+	TOKEN_KIND(Token_Period,        "."),   \
+	TOKEN_KIND(Token_Comma,         ","),   \
+	TOKEN_KIND(Token_Ellipsis,      ".."),  \
+	TOKEN_KIND(Token_HalfOpenRange, "..<"), \
 TOKEN_KIND(Token__OperatorEnd, "_OperatorEnd"), \
 \
 TOKEN_KIND(Token__KeywordBegin, "_KeywordBegin"), \
@@ -870,10 +870,10 @@ Token tokenizer_get_token(Tokenizer *t) {
 			if (t->curr_rune == '.') { // Could be an ellipsis
 				advance_to_next_rune(t);
 				token.kind = Token_Ellipsis;
-				// if (t->curr_rune == '<') {
-					// advance_to_next_rune(t);
-					// token.kind = Token_HalfOpenRange;
-				// }
+				if (t->curr_rune == '<') {
+					advance_to_next_rune(t);
+					token.kind = Token_HalfOpenRange;
+				}
 			}
 			break;