aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2017-10-29 17:00:54 +0000
committergingerBill <bill@gingerbill.org>2017-10-29 17:00:54 +0000
commitae24a8e5ae77111cae24cd8d710b63636b737283 (patch)
tree8e84ae6aaf163a2c8c1a835748aa3504f3f4948d /src
parentd2588f9d1da112b48f4a3f224b643bdd8f47f429 (diff)
Fix pointer arithmetic; remove suffix #tags for proc types
Diffstat (limited to 'src')
-rw-r--r--src/check_expr.cpp4
-rw-r--r--src/ir.cpp7
-rw-r--r--src/parser.cpp72
3 files changed, 17 insertions, 66 deletions
diff --git a/src/check_expr.cpp b/src/check_expr.cpp
index 02c4fbf64..c22d59da0 100644
--- a/src/check_expr.cpp
+++ b/src/check_expr.cpp
@@ -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;
}
diff --git a/src/ir.cpp b/src/ir.cpp
index ce868a280..b0a4985db 100644
--- a/src/ir.cpp
+++ b/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);
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));
diff --git a/src/parser.cpp b/src/parser.cpp
index 422612c4d..caeb3f95c 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -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;