aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2018-08-26 15:10:23 +0100
committergingerBill <bill@gingerbill.org>2018-08-26 15:10:23 +0100
commite5735af6d6001a2a8b8df08d45ac1778dcc7b6f3 (patch)
tree78363f533306d293e0a384c83ee9dfb9f6373cdc
parenta6b0ae71b2795948976c74ca1e8fbf480b731f89 (diff)
Disable for in over cstring
-rw-r--r--src/check_stmt.cpp2
-rw-r--r--src/exact_value.cpp12
-rw-r--r--src/ir.cpp26
3 files changed, 34 insertions, 6 deletions
diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp
index 907754cbf..290f2384a 100644
--- a/src/check_stmt.cpp
+++ b/src/check_stmt.cpp
@@ -1389,7 +1389,7 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) {
Type *t = base_type(type_deref(operand.type));
switch (t->kind) {
case Type_Basic:
- if (is_type_string(t)) {
+ if (is_type_string(t) && t->Basic.kind != Basic_cstring) {
val0 = t_rune;
val1 = t_int;
add_package_dependency(ctx, "runtime", "__string_decode_rune");
diff --git a/src/exact_value.cpp b/src/exact_value.cpp
index 30d4fd649..fb392c831 100644
--- a/src/exact_value.cpp
+++ b/src/exact_value.cpp
@@ -141,6 +141,8 @@ ExactValue exact_value_integer_from_string(String const &string) {
return result;
}
+
+
f64 float_from_string(String string) {
isize i = 0;
u8 *str = string.text;
@@ -296,6 +298,16 @@ ExactValue exact_value_to_integer(ExactValue v) {
return r;
}
+i64 exact_value_to_i64(ExactValue v) {
+ v = exact_value_to_integer(v);
+ i64 result = 0;
+ if (v.kind == ExactValue_Integer) {
+ return big_int_to_i64(&v.value_integer);
+ }
+ return result;
+}
+
+
ExactValue exact_value_to_float(ExactValue v) {
switch (v.kind) {
case ExactValue_Integer:
diff --git a/src/ir.cpp b/src/ir.cpp
index 3992f1103..476a7fba0 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -4872,8 +4872,6 @@ irValue *ir_build_expr_internal(irProcedure *proc, Ast *expr) {
Ast *ue_expr = unparen_expr(ue->expr);
if (ue_expr->kind == Ast_TypeAssertion) {
gbAllocator a = ir_allocator();
-
-
GB_ASSERT(is_type_pointer(tv.type));
ast_node(ta, TypeAssertion, ue_expr);
@@ -4935,10 +4933,25 @@ irValue *ir_build_expr_internal(irProcedure *proc, Ast *expr) {
} else {
GB_PANIC("TODO(bill): type assertion %s", type_to_string(type));
}
-
+ } else if (ue_expr->kind == Ast_IndexExpr) {
+ #if 0
+ ast_node(ie, IndexExpr, ue_expr);
+ if (is_type_slice(ie->expr->tav.type)) {
+ auto tav = ie->index->tav;
+ if (tav.mode == Addressing_Constant) {
+ if (exact_value_to_i64(tav.value) == 0) {
+ irValue *s = ir_build_expr(proc, ie->expr);
+ if (is_type_pointer(ir_type(s))) {
+ s = ir_emit_load(proc, s);
+ }
+ return ir_slice_elem(proc, s);
+ }
+ }
+ }
+ #endif
}
- return ir_emit_ptr_offset(proc, ir_build_addr_ptr(proc, ue->expr), v_zero); // Make a copy of the pointer
+ return ir_build_addr_ptr(proc, ue->expr);
}
default:
return ir_emit_unary_arith(proc, ue->op.kind, ir_build_expr(proc, ue->expr), tv.type);
@@ -6455,6 +6468,7 @@ void ir_build_range_string(irProcedure *proc, irValue *expr, Type *val_type,
if (done_) *done_ = done;
}
+
void ir_build_range_interval(irProcedure *proc, AstBinaryExpr *node, Type *val_type,
irValue **val_, irValue **idx_, irBlock **loop_, irBlock **done_) {
// TODO(bill): How should the behaviour work for lower and upper bounds checking for iteration?
@@ -6988,10 +7002,12 @@ void ir_build_stmt_internal(irProcedure *proc, Ast *node) {
string = ir_emit_load(proc, string);
}
if (is_type_untyped(expr_type)) {
- irValue *s = ir_add_local_generated(proc, t_string);
+ irValue *s = ir_add_local_generated(proc, default_type(ir_type(string)));
ir_emit_store(proc, s, string);
string = ir_emit_load(proc, s);
}
+ Type *t = base_type(ir_type(string));
+ GB_ASSERT(!is_type_cstring(t));
ir_build_range_string(proc, string, val0_type, &val, &key, &loop, &done);
break;
}