mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-17 11:22:22 -07:00
Fix pointer arithmetic; remove suffix #tags for proc types
This commit is contained in:
+1
-1
@@ -268,7 +268,7 @@ dlopen :: inline proc(filename: string, flags: int) -> rawptr {
|
||||
free(cstr);
|
||||
return handle;
|
||||
}
|
||||
dlsym :: inline proc(handle: rawptr, symbol: string) -> (proc() #cc_c) {
|
||||
dlsym :: inline proc(handle: rawptr, symbol: string) -> rawptr {
|
||||
assert(handle != nil);
|
||||
cstr := strings.new_c_string(symbol);
|
||||
proc_handle := _unix_dlsym(handle, cstr);
|
||||
|
||||
+2
-2
@@ -3239,7 +3239,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
|
||||
|
||||
|
||||
case BuiltinProc_offset_of: {
|
||||
// proc offset_of(Type, field) -> untyped int
|
||||
// proc offset_of(Type, field) -> uintptr
|
||||
Operand op = {};
|
||||
Type *bt = check_type(c, ce->args[0]);
|
||||
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->value = exact_value_i64(type_offset_of_from_selection(c->allocator, type, sel));
|
||||
operand->type = t_untyped_integer;
|
||||
operand->type = t_uintptr;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
+4
-3
@@ -2195,8 +2195,8 @@ irValue *ir_emit_arith(irProcedure *proc, TokenKind op, irValue *left, irValue *
|
||||
Type *ptr_type = base_type(t_left);
|
||||
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 *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);
|
||||
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));
|
||||
}
|
||||
|
||||
// Pointer <-> int
|
||||
// Pointer <-> uintptr
|
||||
if (is_type_pointer(src) && is_type_uintptr(dst)) {
|
||||
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("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));
|
||||
|
||||
+11
-61
@@ -2094,12 +2094,9 @@ bool is_foreign_name_valid(String name) {
|
||||
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);
|
||||
|
||||
ProcCallingConvention cc = ProcCC_Invalid;
|
||||
if (calling_convention) cc = *calling_convention;
|
||||
|
||||
while (f->curr_token.kind == Token_Hash) {
|
||||
AstNode *tag_expr = parse_tag_expr(f, nullptr);
|
||||
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(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
|
||||
}
|
||||
|
||||
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)) {
|
||||
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) {
|
||||
// syntax_error(token, "A procedure type cannot have tags");
|
||||
syntax_error(token, "A procedure type cannot have tags");
|
||||
}
|
||||
|
||||
return type;
|
||||
@@ -3317,13 +3268,12 @@ AstNode *parse_proc_type(AstFile *f, Token proc_token) {
|
||||
} else {
|
||||
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);
|
||||
|
||||
u64 tags = 0;
|
||||
parse_proc_tags(f, &tags, &cc);
|
||||
parse_proc_tags(f, &tags);
|
||||
|
||||
bool is_generic = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user