authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-04-10 03:00:19-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-04-10 03:00:19-04:00
log34eff503265834172f89a8635e49e9f4d124db51
treed18cc0735ffcbe09dabb9ec3a7f32a7bbc20b1a9
parent0e77b0ac8936b0f09deb23733fe5a772869a64e6

fix for loops not working at compile-time

closes #315

2 files changed, 16 insertions(+), 2 deletions(-)

src/ir.cpp+1-2
...@@ -8212,10 +8212,9 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,...@@ -8212,10 +8212,9 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
8212 bool comptime_var_mem = ir_get_var_is_comptime(var);8212 bool comptime_var_mem = ir_get_var_is_comptime(var);
82138213
8214 ConstExprValue *mem_slot = nullptr;8214 ConstExprValue *mem_slot = nullptr;
8215 FnTableEntry *fn_entry = scope_fn_entry(var->parent_scope);
8216 if (var->value->special == ConstValSpecialStatic) {8215 if (var->value->special == ConstValSpecialStatic) {
8217 mem_slot = var->value;8216 mem_slot = var->value;
8218 } else if (fn_entry) {8217 } else {
8219 // TODO once the analyze code is fully ported over to IR we won't need this SIZE_MAX thing.8218 // TODO once the analyze code is fully ported over to IR we won't need this SIZE_MAX thing.
8220 if (var->mem_slot_index != SIZE_MAX && (comptime_var_mem || var->gen_is_const))8219 if (var->mem_slot_index != SIZE_MAX && (comptime_var_mem || var->gen_is_const))
8221 mem_slot = &ira->exec_context.mem_slot_list[var->mem_slot_index];8220 mem_slot = &ira->exec_context.mem_slot_list[var->mem_slot_index];
test/cases/eval.zig+15
...@@ -299,3 +299,18 @@ const Foo = struct {...@@ -299,3 +299,18 @@ const Foo = struct {
299299
300var foo_contents = Foo { .name = "a", };300var foo_contents = Foo { .name = "a", };
301const foo_ref = &foo_contents;301const foo_ref = &foo_contents;
302
303
304
305test "create global array with for loop" {
306 assert(global_array[5] == 5 * 5);
307 assert(global_array[9] == 9 * 9);
308}
309
310const global_array = {
311 var result: [10]usize = undefined;
312 for (result) |*item, index| {
313 *item = index * index;
314 }
315 result
316};