authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-05-05 17:19:01-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-05-05 17:19:01-07:00
log094336f07cdf42f2f79df5b190ccc0139412cfbc
treee74c6dcc8f3f4a72aee44ffcca1e6ca68d7dd4d1
parentdedde0d790a60522e073d78ce6bbb0714d50d7aa

add integer wrapping

see #46

7 files changed, 155 insertions(+), 78 deletions(-)

doc/langref.md+19-9
......@@ -181,19 +181,26 @@ x{}
181181Type name C equivalent Description
182182
183183i8 int8_t signed 8-bit integer
184u8 uint8_t unsigned 8-bit integer
184u8 (none) unsigned 8-bit integer
185185i16 int16_t signed 16-bit integer
186u16 uint16_t unsigned 16-bit integer
186u16 (none) unsigned 16-bit integer
187187i32 int32_t signed 32-bit integer
188u32 uint32_t unsigned 32-bit integer
188u32 (none) unsigned 32-bit integer
189189i64 int64_t signed 64-bit integer
190u64 uint64_t unsigned 64-bit integer
191
192f32 float 32-bit IEE754 floating point
193f64 double 64-bit IEE754 floating point
194
190u64 (none) unsigned 64-bit integer
195191isize intptr_t signed pointer sized integer
196usize uintptr_t unsigned pointer sized integer
192usize (none) unsigned pointer sized integer
193
194i8w (none) wrapping signed 8-bit integer
195u8w uint8_t wrapping unsigned 8-bit integer
196i16w (none) wrapping signed 16-bit integer
197u16w uint16_t wrapping unsigned 16-bit integer
198i32w (none) wrapping signed 32-bit integer
199u32w uint32_t wrapping unsigned 32-bit integer
200i64w (none) wrapping signed 64-bit integer
201u64w uint64_t wrapping unsigned 64-bit integer
202isizew (none) wrapping signed pointer sized integer
203usizew uintptr_t wrapping unsigned pointer sized integer
197204
198205c_short short for ABI compatibility with C
199206c_ushort unsigned short for ABI compatibility with C
......@@ -205,6 +212,9 @@ c_longlong long long for ABI compatibility with C
205212c_ulonglong unsigned long long for ABI compatibility with C
206213c_long_double long double for ABI compatibility with C
207214c_void void for ABI compatibility with C
215
216f32 float 32-bit IEE754 floating point
217f64 double 64-bit IEE754 floating point
208218```
209219
210220### Boolean Type
doc/vim/syntax/zig.vim+3-1
......@@ -15,7 +15,9 @@ syn keyword zigRepeat while for
1515
1616syn keyword zigConstant null undefined
1717syn keyword zigKeyword fn use
18syn keyword zigType bool i8 u8 i16 u16 i32 u32 i64 u64 isize usize f32 f64 void unreachable type error
18syn keyword zigType bool f32 f64 void unreachable type error
19syn keyword zigType i8 u8 i16 u16 i32 u32 i64 u64 isize usize
20syn keyword zigType i8w u8w i16w u16w i32w u32w i64w u64w isizew usizew
1921syn keyword zigType c_short c_ushort c_int c_uint c_long c_ulong c_longlong c_ulonglong
2022
2123syn keyword zigBoolean true false
src/all_types.hpp+3-2
......@@ -846,8 +846,9 @@ struct TypeTableEntryPointer {
846846};
847847
848848struct TypeTableEntryInt {
849 bool is_signed;
850849 int bit_count;
850 bool is_signed;
851 bool is_wrapping;
851852};
852853
853854struct TypeTableEntryFloat {
......@@ -1157,7 +1158,7 @@ struct CodeGen {
11571158
11581159 struct {
11591160 TypeTableEntry *entry_bool;
1160 TypeTableEntry *entry_int[2][4]; // [signed,unsigned][8,16,32,64]
1161 TypeTableEntry *entry_int[2][2][4]; // [signed,unsigned][wrapping,nonwrapping][8,16,32,64]
11611162 TypeTableEntry *entry_c_int[CIntTypeCount];
11621163 TypeTableEntry *entry_c_long_double;
11631164 TypeTableEntry *entry_c_void;
src/analyze.cpp+5-5
......@@ -206,7 +206,7 @@ static bool type_is_complete(TypeTableEntry *type_entry) {
206206}
207207
208208TypeTableEntry *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x) {
209 return get_int_type(g, false, bits_needed_for_unsigned(x));
209 return get_int_type(g, false, false, bits_needed_for_unsigned(x));
210210}
211211
212212static TypeTableEntry *get_generic_fn_type(CodeGen *g, AstNode *decl_node) {
......@@ -6453,7 +6453,7 @@ bool is_node_void_expr(AstNode *node) {
64536453 return false;
64546454}
64556455
6456TypeTableEntry **get_int_type_ptr(CodeGen *g, bool is_signed, int size_in_bits) {
6456TypeTableEntry **get_int_type_ptr(CodeGen *g, bool is_signed, bool is_wrapping, int size_in_bits) {
64576457 int index;
64586458 if (size_in_bits == 8) {
64596459 index = 0;
......@@ -6466,11 +6466,11 @@ TypeTableEntry **get_int_type_ptr(CodeGen *g, bool is_signed, int size_in_bits)
64666466 } else {
64676467 zig_unreachable();
64686468 }
6469 return &g->builtin_types.entry_int[is_signed ? 0 : 1][index];
6469 return &g->builtin_types.entry_int[is_signed ? 0 : 1][is_wrapping ? 0 : 1][index];
64706470}
64716471
6472TypeTableEntry *get_int_type(CodeGen *g, bool is_signed, int size_in_bits) {
6473 return *get_int_type_ptr(g, is_signed, size_in_bits);
6472TypeTableEntry *get_int_type(CodeGen *g, bool is_signed, bool is_wrapping, int size_in_bits) {
6473 return *get_int_type_ptr(g, is_signed, is_wrapping, size_in_bits);
64746474}
64756475
64766476TypeTableEntry **get_c_int_type_ptr(CodeGen *g, CIntType c_int_type) {
src/analyze.hpp+2-2
......@@ -18,8 +18,8 @@ TypeTableEntry *get_pointer_to_type(CodeGen *g, TypeTableEntry *child_type, bool
1818BlockContext *new_block_context(AstNode *node, BlockContext *parent);
1919Expr *get_resolved_expr(AstNode *node);
2020bool is_node_void_expr(AstNode *node);
21TypeTableEntry **get_int_type_ptr(CodeGen *g, bool is_signed, int size_in_bits);
22TypeTableEntry *get_int_type(CodeGen *g, bool is_signed, int size_in_bits);
21TypeTableEntry **get_int_type_ptr(CodeGen *g, bool is_signed, bool is_wrapping, int size_in_bits);
22TypeTableEntry *get_int_type(CodeGen *g, bool is_signed, bool is_wrapping, int size_in_bits);
2323TypeTableEntry **get_c_int_type_ptr(CodeGen *g, CIntType c_int_type);
2424TypeTableEntry *get_c_int_type(CodeGen *g, CIntType c_int_type);
2525TypeTableEntry *get_typedecl_type(CodeGen *g, const char *name, TypeTableEntry *child_type);
src/codegen.cpp+120-55
......@@ -338,6 +338,11 @@ static bool want_debug_safety(CodeGen *g, AstNode *node) {
338338 return !g->is_release_build && !node->block_context->safety_off;
339339}
340340
341static void gen_debug_safety_crash(CodeGen *g) {
342 LLVMBuildCall(g->builder, g->trap_fn_val, nullptr, 0, "");
343 LLVMBuildUnreachable(g->builder);
344}
345
341346static void add_bounds_check(CodeGen *g, AstNode *source_node, LLVMValueRef target_val,
342347 LLVMIntPredicate lower_pred, LLVMValueRef lower_value,
343348 LLVMIntPredicate upper_pred, LLVMValueRef upper_value)
......@@ -362,8 +367,7 @@ static void add_bounds_check(CodeGen *g, AstNode *source_node, LLVMValueRef targ
362367 LLVMBuildCondBr(g->builder, lower_ok_val, lower_ok_block, bounds_check_fail_block);
363368
364369 LLVMPositionBuilderAtEnd(g->builder, bounds_check_fail_block);
365 LLVMBuildCall(g->builder, g->trap_fn_val, nullptr, 0, "");
366 LLVMBuildUnreachable(g->builder);
370 gen_debug_safety_crash(g);
367371
368372 if (upper_value) {
369373 LLVMPositionBuilderAtEnd(g->builder, lower_ok_block);
......@@ -1369,8 +1373,7 @@ static LLVMValueRef gen_prefix_op_expr(CodeGen *g, AstNode *node) {
13691373 LLVMBuildCondBr(g->builder, cond_val, ok_block, err_block);
13701374
13711375 LLVMPositionBuilderAtEnd(g->builder, err_block);
1372 LLVMBuildCall(g->builder, g->trap_fn_val, nullptr, 0, "");
1373 LLVMBuildUnreachable(g->builder);
1376 gen_debug_safety_crash(g);
13741377
13751378 LLVMPositionBuilderAtEnd(g->builder, ok_block);
13761379 }
......@@ -1408,8 +1411,7 @@ static LLVMValueRef gen_prefix_op_expr(CodeGen *g, AstNode *node) {
14081411 LLVMBuildCondBr(g->builder, cond_val, ok_block, null_block);
14091412
14101413 LLVMPositionBuilderAtEnd(g->builder, null_block);
1411 LLVMBuildCall(g->builder, g->trap_fn_val, nullptr, 0, "");
1412 LLVMBuildUnreachable(g->builder);
1414 gen_debug_safety_crash(g);
14131415
14141416 LLVMPositionBuilderAtEnd(g->builder, ok_block);
14151417 }
......@@ -1429,6 +1431,28 @@ static LLVMValueRef gen_prefix_op_expr(CodeGen *g, AstNode *node) {
14291431 zig_unreachable();
14301432}
14311433
1434static LLVMValueRef gen_overflow_op(CodeGen *g, TypeTableEntry *type_entry, AddSubMul op,
1435 LLVMValueRef val1, LLVMValueRef val2)
1436{
1437 LLVMValueRef fn_val = get_int_overflow_fn(g, type_entry, op);
1438 LLVMValueRef params[] = {
1439 val1,
1440 val2,
1441 };
1442 LLVMValueRef result_struct = LLVMBuildCall(g->builder, fn_val, params, 2, "");
1443 LLVMValueRef result = LLVMBuildExtractValue(g->builder, result_struct, 0, "");
1444 LLVMValueRef overflow_bit = LLVMBuildExtractValue(g->builder, result_struct, 1, "");
1445 LLVMBasicBlockRef fail_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "OverflowFail");
1446 LLVMBasicBlockRef ok_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "OverflowOk");
1447 LLVMBuildCondBr(g->builder, overflow_bit, fail_block, ok_block);
1448
1449 LLVMPositionBuilderAtEnd(g->builder, fail_block);
1450 gen_debug_safety_crash(g);
1451
1452 LLVMPositionBuilderAtEnd(g->builder, ok_block);
1453 return result;
1454}
1455
14321456static LLVMValueRef gen_arithmetic_bin_op(CodeGen *g, AstNode *source_node,
14331457 LLVMValueRef val1, LLVMValueRef val2,
14341458 TypeTableEntry *op1_type, TypeTableEntry *op2_type,
......@@ -1469,24 +1493,54 @@ static LLVMValueRef gen_arithmetic_bin_op(CodeGen *g, AstNode *source_node,
14691493 set_debug_source_node(g, source_node);
14701494 if (op1_type->id == TypeTableEntryIdFloat) {
14711495 return LLVMBuildFAdd(g->builder, val1, val2, "");
1496 } else if (op1_type->id == TypeTableEntryIdInt) {
1497 if (op1_type->data.integral.is_wrapping) {
1498 return LLVMBuildAdd(g->builder, val1, val2, "");
1499 } else if (want_debug_safety(g, source_node)) {
1500 return gen_overflow_op(g, op1_type, AddSubMulAdd, val1, val2);
1501 } else if (op1_type->data.integral.is_signed) {
1502 return LLVMBuildNSWAdd(g->builder, val1, val2, "");
1503 } else {
1504 return LLVMBuildNUWAdd(g->builder, val1, val2, "");
1505 }
14721506 } else {
1473 return LLVMBuildAdd(g->builder, val1, val2, "");
1507 zig_unreachable();
14741508 }
14751509 case BinOpTypeSub:
14761510 case BinOpTypeAssignMinus:
14771511 set_debug_source_node(g, source_node);
14781512 if (op1_type->id == TypeTableEntryIdFloat) {
14791513 return LLVMBuildFSub(g->builder, val1, val2, "");
1514 } else if (op1_type->id == TypeTableEntryIdInt) {
1515 if (op1_type->data.integral.is_wrapping) {
1516 return LLVMBuildSub(g->builder, val1, val2, "");
1517 } else if (want_debug_safety(g, source_node)) {
1518 return gen_overflow_op(g, op1_type, AddSubMulSub, val1, val2);
1519 } else if (op1_type->data.integral.is_signed) {
1520 return LLVMBuildNSWSub(g->builder, val1, val2, "");
1521 } else {
1522 return LLVMBuildNUWSub(g->builder, val1, val2, "");
1523 }
14801524 } else {
1481 return LLVMBuildSub(g->builder, val1, val2, "");
1525 zig_unreachable();
14821526 }
14831527 case BinOpTypeMult:
14841528 case BinOpTypeAssignTimes:
14851529 set_debug_source_node(g, source_node);
14861530 if (op1_type->id == TypeTableEntryIdFloat) {
14871531 return LLVMBuildFMul(g->builder, val1, val2, "");
1532 } else if (op1_type->id == TypeTableEntryIdInt) {
1533 if (op1_type->data.integral.is_wrapping) {
1534 return LLVMBuildMul(g->builder, val1, val2, "");
1535 } else if (want_debug_safety(g, source_node)) {
1536 return gen_overflow_op(g, op1_type, AddSubMulMul, val1, val2);
1537 } else if (op1_type->data.integral.is_signed) {
1538 return LLVMBuildNSWMul(g->builder, val1, val2, "");
1539 } else {
1540 return LLVMBuildNUWMul(g->builder, val1, val2, "");
1541 }
14881542 } else {
1489 return LLVMBuildMul(g->builder, val1, val2, "");
1543 zig_unreachable();
14901544 }
14911545 case BinOpTypeDiv:
14921546 case BinOpTypeAssignDiv:
......@@ -2472,9 +2526,10 @@ static LLVMValueRef gen_container_init_expr(CodeGen *g, AstNode *node) {
24722526 assert(node->data.container_init_expr.entries.length == 0);
24732527 set_debug_source_node(g, node);
24742528 if (want_debug_safety(g, node)) {
2475 LLVMBuildCall(g->builder, g->trap_fn_val, nullptr, 0, "");
2529 gen_debug_safety_crash(g);
2530 } else {
2531 LLVMBuildUnreachable(g->builder);
24762532 }
2477 LLVMBuildUnreachable(g->builder);
24782533 return nullptr;
24792534 } else if (type_entry->id == TypeTableEntryIdVoid) {
24802535 assert(node->data.container_init_expr.entries.length == 0);
......@@ -2983,7 +3038,7 @@ static LLVMValueRef gen_switch_expr(CodeGen *g, AstNode *node) {
29833038 set_debug_source_node(g, prong_expr);
29843039 LLVMBuildBr(g->builder, end_block);
29853040 incoming_values.append(prong_val);
2986 incoming_blocks.append(prong_block);
3041 incoming_blocks.append(LLVMGetInsertBlock(g->builder));
29873042 }
29883043 }
29893044
......@@ -2991,9 +3046,10 @@ static LLVMValueRef gen_switch_expr(CodeGen *g, AstNode *node) {
29913046 LLVMPositionBuilderAtEnd(g->builder, else_block);
29923047 set_debug_source_node(g, node);
29933048 if (want_debug_safety(g, node)) {
2994 LLVMBuildCall(g->builder, g->trap_fn_val, nullptr, 0, "");
3049 gen_debug_safety_crash(g);
3050 } else {
3051 LLVMBuildUnreachable(g->builder);
29953052 }
2996 LLVMBuildUnreachable(g->builder);
29973053 }
29983054
29993055 if (end_unreachable) {
......@@ -3776,6 +3832,18 @@ static const CIntTypeInfo c_int_type_infos[] = {
37763832 {CIntTypeULongLong, "c_ulonglong", false},
37773833};
37783834
3835struct SignWrap {
3836 bool is_signed;
3837 bool is_wrapping;
3838};
3839
3840static const SignWrap sign_wrap_list[] = {
3841 {false, false},
3842 {false, true},
3843 {true, false},
3844 {true, true},
3845};
3846
37793847static void define_builtin_types(CodeGen *g) {
37803848 {
37813849 // if this type is anywhere in the AST, we should never hit codegen.
......@@ -3812,17 +3880,20 @@ static void define_builtin_types(CodeGen *g) {
38123880 g->builtin_types.entry_undef = entry;
38133881 }
38143882
3815 for (int i = 0; i < array_length(int_sizes_in_bits); i += 1) {
3816 int size_in_bits = int_sizes_in_bits[i];
3817 bool is_signed = true;
3818 for (;;) {
3883 for (int int_size_i = 0; int_size_i < array_length(int_sizes_in_bits); int_size_i += 1) {
3884 int size_in_bits = int_sizes_in_bits[int_size_i];
3885 for (int sign_wrap_i = 0; sign_wrap_i < array_length(sign_wrap_list); sign_wrap_i += 1) {
3886 bool is_signed = sign_wrap_list[sign_wrap_i].is_signed;
3887 bool is_wrapping = sign_wrap_list[sign_wrap_i].is_wrapping;
3888
38193889 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdInt);
38203890 entry->type_ref = LLVMIntType(size_in_bits);
38213891 entry->deep_const = true;
38223892
38233893 const char u_or_i = is_signed ? 'i' : 'u';
3894 const char *w_or_none = is_wrapping ? "w" : "";
38243895 buf_resize(&entry->name, 0);
3825 buf_appendf(&entry->name, "%c%d", u_or_i, size_in_bits);
3896 buf_appendf(&entry->name, "%c%d%s", u_or_i, size_in_bits, w_or_none);
38263897
38273898 unsigned dwarf_tag;
38283899 if (is_signed) {
......@@ -3844,16 +3915,11 @@ static void define_builtin_types(CodeGen *g) {
38443915 entry->di_type = LLVMZigCreateDebugBasicType(g->dbuilder, buf_ptr(&entry->name),
38453916 debug_size_in_bits, debug_align_in_bits, dwarf_tag);
38463917 entry->data.integral.is_signed = is_signed;
3918 entry->data.integral.is_wrapping = is_wrapping;
38473919 entry->data.integral.bit_count = size_in_bits;
38483920 g->primitive_type_table.put(&entry->name, entry);
38493921
3850 get_int_type_ptr(g, is_signed, size_in_bits)[0] = entry;
3851
3852 if (!is_signed) {
3853 break;
3854 } else {
3855 is_signed = false;
3856 }
3922 get_int_type_ptr(g, is_signed, is_wrapping, size_in_bits)[0] = entry;
38573923 }
38583924 }
38593925
......@@ -3875,6 +3941,7 @@ static void define_builtin_types(CodeGen *g) {
38753941 debug_align_in_bits,
38763942 is_signed ? LLVMZigEncoding_DW_ATE_signed() : LLVMZigEncoding_DW_ATE_unsigned());
38773943 entry->data.integral.is_signed = is_signed;
3944 entry->data.integral.is_wrapping = !is_signed;
38783945 entry->data.integral.bit_count = size_in_bits;
38793946 g->primitive_type_table.put(&entry->name, entry);
38803947
......@@ -3895,29 +3962,22 @@ static void define_builtin_types(CodeGen *g) {
38953962 g->builtin_types.entry_bool = entry;
38963963 g->primitive_type_table.put(&entry->name, entry);
38973964 }
3898 {
3899 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdInt);
3900 entry->deep_const = true;
3901 entry->type_ref = LLVMIntType(g->pointer_size_bytes * 8);
3902 buf_init_from_str(&entry->name, "isize");
3903 entry->data.integral.is_signed = true;
3904 entry->data.integral.bit_count = g->pointer_size_bytes * 8;
39053965
3906 uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, entry->type_ref);
3907 uint64_t debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, entry->type_ref);
3908 entry->di_type = LLVMZigCreateDebugBasicType(g->dbuilder, buf_ptr(&entry->name),
3909 debug_size_in_bits,
3910 debug_align_in_bits,
3911 LLVMZigEncoding_DW_ATE_signed());
3912 g->builtin_types.entry_isize = entry;
3913 g->primitive_type_table.put(&entry->name, entry);
3914 }
3915 {
3966 for (int sign_wrap_i = 0; sign_wrap_i < array_length(sign_wrap_list); sign_wrap_i += 1) {
3967 bool is_signed = sign_wrap_list[sign_wrap_i].is_signed;
3968 bool is_wrapping = sign_wrap_list[sign_wrap_i].is_wrapping;
3969
39163970 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdInt);
39173971 entry->deep_const = true;
39183972 entry->type_ref = LLVMIntType(g->pointer_size_bytes * 8);
3919 buf_init_from_str(&entry->name, "usize");
3920 entry->data.integral.is_signed = false;
3973
3974 const char u_or_i = is_signed ? 'i' : 'u';
3975 const char *w_or_none = is_wrapping ? "w" : "";
3976 buf_resize(&entry->name, 0);
3977 buf_appendf(&entry->name, "%csize%s", u_or_i, w_or_none);
3978
3979 entry->data.integral.is_signed = is_signed;
3980 entry->data.integral.is_wrapping = is_wrapping;
39213981 entry->data.integral.bit_count = g->pointer_size_bytes * 8;
39223982
39233983 uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, entry->type_ref);
......@@ -3925,9 +3985,14 @@ static void define_builtin_types(CodeGen *g) {
39253985 entry->di_type = LLVMZigCreateDebugBasicType(g->dbuilder, buf_ptr(&entry->name),
39263986 debug_size_in_bits,
39273987 debug_align_in_bits,
3928 LLVMZigEncoding_DW_ATE_unsigned());
3929 g->builtin_types.entry_usize = entry;
3988 is_signed ? LLVMZigEncoding_DW_ATE_signed() : LLVMZigEncoding_DW_ATE_unsigned());
39303989 g->primitive_type_table.put(&entry->name, entry);
3990
3991 if (is_signed && !is_wrapping) {
3992 g->builtin_types.entry_isize = entry;
3993 } else if (!is_signed && !is_wrapping) {
3994 g->builtin_types.entry_usize = entry;
3995 }
39313996 }
39323997 {
39333998 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdFloat);
......@@ -4009,14 +4074,14 @@ static void define_builtin_types(CodeGen *g) {
40094074 g->primitive_type_table.put(&entry->name, entry);
40104075 }
40114076
4012 g->builtin_types.entry_u8 = get_int_type(g, false, 8);
4013 g->builtin_types.entry_u16 = get_int_type(g, false, 16);
4014 g->builtin_types.entry_u32 = get_int_type(g, false, 32);
4015 g->builtin_types.entry_u64 = get_int_type(g, false, 64);
4016 g->builtin_types.entry_i8 = get_int_type(g, true, 8);
4017 g->builtin_types.entry_i16 = get_int_type(g, true, 16);
4018 g->builtin_types.entry_i32 = get_int_type(g, true, 32);
4019 g->builtin_types.entry_i64 = get_int_type(g, true, 64);
4077 g->builtin_types.entry_u8 = get_int_type(g, false, false, 8);
4078 g->builtin_types.entry_u16 = get_int_type(g, false, false, 16);
4079 g->builtin_types.entry_u32 = get_int_type(g, false, false, 32);
4080 g->builtin_types.entry_u64 = get_int_type(g, false, false, 64);
4081 g->builtin_types.entry_i8 = get_int_type(g, true, false, 8);
4082 g->builtin_types.entry_i16 = get_int_type(g, true, false, 16);
4083 g->builtin_types.entry_i32 = get_int_type(g, true, false, 32);
4084 g->builtin_types.entry_i64 = get_int_type(g, true, false, 64);
40204085
40214086 {
40224087 g->builtin_types.entry_c_void = get_typedecl_type(g, "c_void", g->builtin_types.entry_u8);
std/rand.zig+3-4
......@@ -13,11 +13,10 @@ pub struct Rand {
1313 r.index = 0;
1414 r.array[0] = seed;
1515 var i : isize = 1;
16 var prev_value: u64 = seed;
17 while (i < ARRAY_SIZE) {
18 r.array[i] = u32((prev_value ^ (prev_value << 30)) * 0x6c078965 + u32(i));
16 var prev_value: u64w = seed;
17 while (i < ARRAY_SIZE; i += 1) {
18 r.array[i] = u32((prev_value ^ (prev_value << 30)) * 0x6c078965 + u64w(i));
1919 prev_value = r.array[i];
20 i += 1;
2120 }
2221 return r;
2322 }