From 8a81f8aa1388331624e4c073e2534d3a987a7d9a Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sat, 19 Nov 2016 01:39:51 -0500 Subject: IR: implement compileVar builtin and more * implicit array to slice cast * fix if statements at global scope * implement array type IR --- src/eval.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/eval.cpp') diff --git a/src/eval.cpp b/src/eval.cpp index ee25720425..602401e68d 100644 --- a/src/eval.cpp +++ b/src/eval.cpp @@ -318,8 +318,23 @@ void eval_const_expr_implicit_cast(CastOp cast_op, // can't do it break; case CastOpToUnknownSizeArray: - zig_panic("TODO compile time implicit to unknown size array"); - break; + { + assert(other_type->id == TypeTableEntryIdArray); + assert(other_val->data.x_array.size == other_type->data.array.len); + + const_val->data.x_struct.fields = allocate(2); + ConstExprValue *ptr_field = &const_val->data.x_struct.fields[slice_ptr_index]; + ConstExprValue *len_field = &const_val->data.x_struct.fields[slice_len_index]; + + ptr_field->special = ConstValSpecialStatic; + ptr_field->data.x_ptr.base_ptr = other_val; + + len_field->special = ConstValSpecialStatic; + bignum_init_unsigned(&len_field->data.x_bignum, other_type->data.array.len); + + const_val->special = ConstValSpecialStatic; + break; + } case CastOpMaybeWrap: const_val->data.x_maybe = other_val; const_val->special = ConstValSpecialStatic; -- cgit v1.2.3