Disable for in over cstring

This commit is contained in:
gingerBill
2018-08-26 15:10:23 +01:00
parent a6b0ae71b2
commit e5735af6d6
3 changed files with 34 additions and 6 deletions
+1 -1
View File
@@ -1389,7 +1389,7 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) {
Type *t = base_type(type_deref(operand.type)); Type *t = base_type(type_deref(operand.type));
switch (t->kind) { switch (t->kind) {
case Type_Basic: case Type_Basic:
if (is_type_string(t)) { if (is_type_string(t) && t->Basic.kind != Basic_cstring) {
val0 = t_rune; val0 = t_rune;
val1 = t_int; val1 = t_int;
add_package_dependency(ctx, "runtime", "__string_decode_rune"); add_package_dependency(ctx, "runtime", "__string_decode_rune");
+12
View File
@@ -141,6 +141,8 @@ ExactValue exact_value_integer_from_string(String const &string) {
return result; return result;
} }
f64 float_from_string(String string) { f64 float_from_string(String string) {
isize i = 0; isize i = 0;
u8 *str = string.text; u8 *str = string.text;
@@ -296,6 +298,16 @@ ExactValue exact_value_to_integer(ExactValue v) {
return r; 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) { ExactValue exact_value_to_float(ExactValue v) {
switch (v.kind) { switch (v.kind) {
case ExactValue_Integer: case ExactValue_Integer:
+21 -5
View File
@@ -4872,8 +4872,6 @@ irValue *ir_build_expr_internal(irProcedure *proc, Ast *expr) {
Ast *ue_expr = unparen_expr(ue->expr); Ast *ue_expr = unparen_expr(ue->expr);
if (ue_expr->kind == Ast_TypeAssertion) { if (ue_expr->kind == Ast_TypeAssertion) {
gbAllocator a = ir_allocator(); gbAllocator a = ir_allocator();
GB_ASSERT(is_type_pointer(tv.type)); GB_ASSERT(is_type_pointer(tv.type));
ast_node(ta, TypeAssertion, ue_expr); ast_node(ta, TypeAssertion, ue_expr);
@@ -4935,10 +4933,25 @@ irValue *ir_build_expr_internal(irProcedure *proc, Ast *expr) {
} else { } else {
GB_PANIC("TODO(bill): type assertion %s", type_to_string(type)); 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: default:
return ir_emit_unary_arith(proc, ue->op.kind, ir_build_expr(proc, ue->expr), tv.type); 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; if (done_) *done_ = done;
} }
void ir_build_range_interval(irProcedure *proc, AstBinaryExpr *node, Type *val_type, void ir_build_range_interval(irProcedure *proc, AstBinaryExpr *node, Type *val_type,
irValue **val_, irValue **idx_, irBlock **loop_, irBlock **done_) { irValue **val_, irValue **idx_, irBlock **loop_, irBlock **done_) {
// TODO(bill): How should the behaviour work for lower and upper bounds checking for iteration? // 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); string = ir_emit_load(proc, string);
} }
if (is_type_untyped(expr_type)) { 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); ir_emit_store(proc, s, string);
string = ir_emit_load(proc, s); 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); ir_build_range_string(proc, string, val0_type, &val, &key, &loop, &done);
break; break;
} }