Browse Source

Fix pointer arithmetic; remove suffix #tags for proc types

gingerBill 7 years ago
parent
commit
ae24a8e5ae
4 changed files with 18 additions and 67 deletions
  1. 1 1
      core/os_x.odin
  2. 2 2
      src/check_expr.cpp
  3. 4 3
      src/ir.cpp
  4. 11 61
      src/parser.cpp

+ 1 - 1
core/os_x.odin

@@ -268,7 +268,7 @@ dlopen :: inline proc(filename: string, flags: int) -> rawptr {
 	free(cstr);
 	free(cstr);
 	return handle;
 	return handle;
 }
 }
-dlsym :: inline proc(handle: rawptr, symbol: string) -> (proc() #cc_c) {
+dlsym :: inline proc(handle: rawptr, symbol: string) -> rawptr {
 	assert(handle != nil);
 	assert(handle != nil);
 	cstr := strings.new_c_string(symbol);
 	cstr := strings.new_c_string(symbol);
 	proc_handle := _unix_dlsym(handle, cstr);
 	proc_handle := _unix_dlsym(handle, cstr);

+ 2 - 2
src/check_expr.cpp

@@ -3239,7 +3239,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
 
 
 
 
 	case BuiltinProc_offset_of: {
 	case BuiltinProc_offset_of: {
-		// proc offset_of(Type, field) -> untyped int
+		// proc offset_of(Type, field) -> uintptr
 		Operand op = {};
 		Operand op = {};
 		Type *bt = check_type(c, ce->args[0]);
 		Type *bt = check_type(c, ce->args[0]);
 		Type *type = base_type(bt);
 		Type *type = base_type(bt);
@@ -3279,7 +3279,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
 
 
 		operand->mode = Addressing_Constant;
 		operand->mode = Addressing_Constant;
 		operand->value = exact_value_i64(type_offset_of_from_selection(c->allocator, type, sel));
 		operand->value = exact_value_i64(type_offset_of_from_selection(c->allocator, type, sel));
-		operand->type  = t_untyped_integer;
+		operand->type  = t_uintptr;
 
 
 		break;
 		break;
 	}
 	}

+ 4 - 3
src/ir.cpp

@@ -2195,8 +2195,8 @@ irValue *ir_emit_arith(irProcedure *proc, TokenKind op, irValue *left, irValue *
 			Type *ptr_type = base_type(t_left);
 			Type *ptr_type = base_type(t_left);
 			GB_ASSERT(!is_type_rawptr(ptr_type));
 			GB_ASSERT(!is_type_rawptr(ptr_type));
 			irValue *elem_size = ir_const_int(m->allocator, type_size_of(m->allocator, ptr_type->Pointer.elem));
 			irValue *elem_size = ir_const_int(m->allocator, type_size_of(m->allocator, ptr_type->Pointer.elem));
-			irValue *x = ir_emit_conv(proc, left, type);
-			irValue *y = ir_emit_conv(proc, right, type);
+			irValue *x = ir_emit_conv(proc, ir_emit_conv(proc, left, t_uintptr), type);
+			irValue *y = ir_emit_conv(proc, ir_emit_conv(proc, right, t_uintptr), type);
 			irValue *diff = ir_emit_arith(proc, op, x, y, type);
 			irValue *diff = ir_emit_arith(proc, op, x, y, type);
 			return ir_emit_arith(proc, Token_Quo, diff, elem_size, type);
 			return ir_emit_arith(proc, Token_Quo, diff, elem_size, type);
 		}
 		}
@@ -3027,7 +3027,7 @@ irValue *ir_emit_conv(irProcedure *proc, irValue *value, Type *t) {
 		return ir_emit(proc, ir_instr_conv(proc, kind, value, src_type, t));
 		return ir_emit(proc, ir_instr_conv(proc, kind, value, src_type, t));
 	}
 	}
 
 
-	// Pointer <-> int
+	// Pointer <-> uintptr
 	if (is_type_pointer(src) && is_type_uintptr(dst)) {
 	if (is_type_pointer(src) && is_type_uintptr(dst)) {
 		return ir_emit_ptr_to_uintptr(proc, value, t);
 		return ir_emit_ptr_to_uintptr(proc, value, t);
 	}
 	}
@@ -3185,6 +3185,7 @@ irValue *ir_emit_conv(irProcedure *proc, irValue *value, Type *t) {
 	}
 	}
 
 
 
 
+
 	gb_printf_err("ir_emit_conv: src -> dst\n");
 	gb_printf_err("ir_emit_conv: src -> dst\n");
 	gb_printf_err("Not Identical %s != %s\n", type_to_string(src_type), type_to_string(t));
 	gb_printf_err("Not Identical %s != %s\n", type_to_string(src_type), type_to_string(t));
 	gb_printf_err("Not Identical %s != %s\n", type_to_string(src), type_to_string(dst));
 	gb_printf_err("Not Identical %s != %s\n", type_to_string(src), type_to_string(dst));

+ 11 - 61
src/parser.cpp

@@ -2094,12 +2094,9 @@ bool is_foreign_name_valid(String name) {
 	return true;
 	return true;
 }
 }
 
 
-void parse_proc_tags(AstFile *f, u64 *tags, ProcCallingConvention *calling_convention) {
+void parse_proc_tags(AstFile *f, u64 *tags) {
 	GB_ASSERT(tags != nullptr);
 	GB_ASSERT(tags != nullptr);
 
 
-	ProcCallingConvention cc = ProcCC_Invalid;
-	if (calling_convention) cc = *calling_convention;
-
 	while (f->curr_token.kind == Token_Hash) {
 	while (f->curr_token.kind == Token_Hash) {
 		AstNode *tag_expr = parse_tag_expr(f, nullptr);
 		AstNode *tag_expr = parse_tag_expr(f, nullptr);
 		ast_node(te, TagExpr, tag_expr);
 		ast_node(te, TagExpr, tag_expr);
@@ -2114,59 +2111,13 @@ void parse_proc_tags(AstFile *f, u64 *tags, ProcCallingConvention *calling_conve
 		ELSE_IF_ADD_TAG(require_results)
 		ELSE_IF_ADD_TAG(require_results)
 		ELSE_IF_ADD_TAG(bounds_check)
 		ELSE_IF_ADD_TAG(bounds_check)
 		ELSE_IF_ADD_TAG(no_bounds_check)
 		ELSE_IF_ADD_TAG(no_bounds_check)
-		else if (tag_name == "cc_odin") {
-			if (cc == ProcCC_Invalid) {
-				cc = ProcCC_Odin;
-			} else {
-				syntax_error(tag_expr, "Multiple calling conventions for procedure type");
-			}
-		} else if (tag_name == "cc_contextless") {
-			if (cc == ProcCC_Invalid) {
-				cc = ProcCC_Contextless;
-			} else {
-				syntax_error(tag_expr, "Multiple calling conventions for procedure type");
-			}
-		} else if (tag_name == "cc_c") {
-			if (cc == ProcCC_Invalid) {
-				cc = ProcCC_C;
-			} else {
-				syntax_error(tag_expr, "Multiple calling conventions for procedure type");
-			}
-		} else if (tag_name == "cc_std") {
-			if (cc == ProcCC_Invalid) {
-				cc = ProcCC_Std;
-			} else {
-				syntax_error(tag_expr, "Multiple calling conventions for procedure type");
-			}
-		} else if (tag_name == "cc_fast") {
-			if (cc == ProcCC_Invalid) {
-				cc = ProcCC_Fast;
-			} else {
-				syntax_error(tag_expr, "Multiple calling conventions for procedure type");
-			}
-		} else {
-			syntax_error(tag_expr, "Unknown procedure tag #%.*s\n", LIT(tag_name));
+		else {
+			syntax_error(tag_expr, "Unknown procedure type tag #%.*s", LIT(tag_name));
 		}
 		}
 
 
 		#undef ELSE_IF_ADD_TAG
 		#undef ELSE_IF_ADD_TAG
 	}
 	}
 
 
-	if (cc == ProcCC_Invalid) {
-		if (f->in_foreign_block) {
-			cc = ProcCC_C;
-		} else {
-			cc = ProcCC_Odin;
-		}
-	}
-
-	if (calling_convention) {
-		*calling_convention = cc;
-	}
-
-	if ((*tags & ProcTag_inline) && (*tags & ProcTag_no_inline)) {
-		syntax_error(f->curr_token, "You cannot apply both #inline and #no_inline to a procedure");
-	}
-
 	if ((*tags & ProcTag_bounds_check) && (*tags & ProcTag_no_bounds_check)) {
 	if ((*tags & ProcTag_bounds_check) && (*tags & ProcTag_no_bounds_check)) {
 		syntax_error(f->curr_token, "You cannot apply both #bounds_check and #no_bounds_check to a procedure");
 		syntax_error(f->curr_token, "You cannot apply both #bounds_check and #no_bounds_check to a procedure");
 	}
 	}
@@ -2358,7 +2309,7 @@ AstNode *parse_operand(AstFile *f, bool lhs) {
 		}
 		}
 
 
 		if (tags != 0) {
 		if (tags != 0) {
-			// syntax_error(token, "A procedure type cannot have tags");
+			syntax_error(token, "A procedure type cannot have tags");
 		}
 		}
 
 
 		return type;
 		return type;
@@ -3317,13 +3268,12 @@ AstNode *parse_proc_type(AstFile *f, Token proc_token) {
 		} else {
 		} else {
 			syntax_error(token, "Unknown procedure tag #%.*s\n", LIT(conv));
 			syntax_error(token, "Unknown procedure tag #%.*s\n", LIT(conv));
 		}
 		}
-
-		if (cc == ProcCC_Invalid) {
-			if (f->in_foreign_block) {
-				cc = ProcCC_C;
-			} else {
-				cc = ProcCC_Odin;
-			}
+	}
+	if (cc == ProcCC_Invalid) {
+		if (f->in_foreign_block) {
+			cc = ProcCC_C;
+		} else {
+			cc = ProcCC_Odin;
 		}
 		}
 	}
 	}
 
 
@@ -3334,7 +3284,7 @@ AstNode *parse_proc_type(AstFile *f, Token proc_token) {
 	results = parse_results(f);
 	results = parse_results(f);
 
 
 	u64 tags = 0;
 	u64 tags = 0;
-	parse_proc_tags(f, &tags, &cc);
+	parse_proc_tags(f, &tags);
 
 
 	bool is_generic = false;
 	bool is_generic = false;