| author | |
| committer | |
| log | bc81ddfea67db0b3756027e98cc00bb8fa903a20 |
| tree | 4264ce327d4dd2b7822854b25b48b5657decc369 |
| parent | 76f87cdd966f23106684bb38c127f6bd3f4e9fa3 |
Closes #62.19 files changed, 266 insertions(+), 396 deletions(-)
doc/langref.md+2-2| ... | @@ -386,7 +386,7 @@ Function Operation | ... | @@ -386,7 +386,7 @@ Function Operation |
| 386 | @shl_with_overflow(inline T: type, a: T, b: T, result: &T) -> bool *x = a << b | 386 | @shl_with_overflow(inline T: type, a: T, b: T, result: &T) -> bool *x = a << b |
| 387 | ``` | 387 | ``` |
| 388 | 388 | ||
| 389 | ### @memset(dest, c: u8, byte_count: isize) | 389 | ### @memset(dest, c: u8, byte_count: usize) |
| 390 | 390 | ||
| 391 | This function sets a region of memory to `c`. `dest` is a pointer. | 391 | This function sets a region of memory to `c`. `dest` is a pointer. |
| 392 | 392 | ||
| ... | @@ -398,7 +398,7 @@ level code will not use this function, instead using something like this: | ... | @@ -398,7 +398,7 @@ level code will not use this function, instead using something like this: |
| 398 | for (dest) |*b| *b = c; | 398 | for (dest) |*b| *b = c; |
| 399 | ``` | 399 | ``` |
| 400 | 400 | ||
| 401 | ### @memcpy(dest, source, byte_count: isize) | 401 | ### @memcpy(dest, source, byte_count: usize) |
| 402 | 402 | ||
| 403 | This function copies bytes from one region of memory to another. `dest` and | 403 | This function copies bytes from one region of memory to another. `dest` and |
| 404 | `source` are both pointers and must not overlap. | 404 | `source` are both pointers and must not overlap. |
src/analyze.cpp+17-17| ... | @@ -502,7 +502,7 @@ static void slice_type_common_init(CodeGen *g, TypeTableEntry *child_type, | ... | @@ -502,7 +502,7 @@ static void slice_type_common_init(CodeGen *g, TypeTableEntry *child_type, |
| 502 | entry->data.structure.fields[0].src_index = 0; | 502 | entry->data.structure.fields[0].src_index = 0; |
| 503 | entry->data.structure.fields[0].gen_index = 0; | 503 | entry->data.structure.fields[0].gen_index = 0; |
| 504 | entry->data.structure.fields[1].name = buf_create_from_str("len"); | 504 | entry->data.structure.fields[1].name = buf_create_from_str("len"); |
| 505 | entry->data.structure.fields[1].type_entry = g->builtin_types.entry_isize; | 505 | entry->data.structure.fields[1].type_entry = g->builtin_types.entry_usize; |
| 506 | entry->data.structure.fields[1].src_index = 1; | 506 | entry->data.structure.fields[1].src_index = 1; |
| 507 | entry->data.structure.fields[1].gen_index = 1; | 507 | entry->data.structure.fields[1].gen_index = 1; |
| 508 | } | 508 | } |
| ... | @@ -546,7 +546,7 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *child_type, bool is_c | ... | @@ -546,7 +546,7 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *child_type, bool is_c |
| 546 | 546 | ||
| 547 | if (child_type->zero_bits) { | 547 | if (child_type->zero_bits) { |
| 548 | LLVMTypeRef element_types[] = { | 548 | LLVMTypeRef element_types[] = { |
| 549 | g->builtin_types.entry_isize->type_ref, | 549 | g->builtin_types.entry_usize->type_ref, |
| 550 | }; | 550 | }; |
| 551 | LLVMStructSetBody(entry->type_ref, element_types, 1, false); | 551 | LLVMStructSetBody(entry->type_ref, element_types, 1, false); |
| 552 | 552 | ||
| ... | @@ -556,9 +556,9 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *child_type, bool is_c | ... | @@ -556,9 +556,9 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *child_type, bool is_c |
| 556 | entry->data.structure.fields[0].gen_index = -1; | 556 | entry->data.structure.fields[0].gen_index = -1; |
| 557 | entry->data.structure.fields[1].gen_index = 0; | 557 | entry->data.structure.fields[1].gen_index = 0; |
| 558 | 558 | ||
| 559 | TypeTableEntry *isize_type = g->builtin_types.entry_isize; | 559 | TypeTableEntry *usize_type = g->builtin_types.entry_usize; |
| 560 | uint64_t len_debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, isize_type->type_ref); | 560 | uint64_t len_debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, usize_type->type_ref); |
| 561 | uint64_t len_debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, isize_type->type_ref); | 561 | uint64_t len_debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, usize_type->type_ref); |
| 562 | uint64_t len_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, entry->type_ref, 0); | 562 | uint64_t len_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, entry->type_ref, 0); |
| 563 | 563 | ||
| 564 | uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, entry->type_ref); | 564 | uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, entry->type_ref); |
| ... | @@ -570,7 +570,7 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *child_type, bool is_c | ... | @@ -570,7 +570,7 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *child_type, bool is_c |
| 570 | len_debug_size_in_bits, | 570 | len_debug_size_in_bits, |
| 571 | len_debug_align_in_bits, | 571 | len_debug_align_in_bits, |
| 572 | len_offset_in_bits, | 572 | len_offset_in_bits, |
| 573 | 0, isize_type->di_type), | 573 | 0, usize_type->di_type), |
| 574 | }; | 574 | }; |
| 575 | LLVMZigDIType *replacement_di_type = LLVMZigCreateDebugStructType(g->dbuilder, | 575 | LLVMZigDIType *replacement_di_type = LLVMZigCreateDebugStructType(g->dbuilder, |
| 576 | compile_unit_scope, | 576 | compile_unit_scope, |
| ... | @@ -586,7 +586,7 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *child_type, bool is_c | ... | @@ -586,7 +586,7 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *child_type, bool is_c |
| 586 | unsigned element_count = 2; | 586 | unsigned element_count = 2; |
| 587 | LLVMTypeRef element_types[] = { | 587 | LLVMTypeRef element_types[] = { |
| 588 | pointer_type->type_ref, | 588 | pointer_type->type_ref, |
| 589 | g->builtin_types.entry_isize->type_ref, | 589 | g->builtin_types.entry_usize->type_ref, |
| 590 | }; | 590 | }; |
| 591 | LLVMStructSetBody(entry->type_ref, element_types, element_count, false); | 591 | LLVMStructSetBody(entry->type_ref, element_types, element_count, false); |
| 592 | 592 | ||
| ... | @@ -597,9 +597,9 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *child_type, bool is_c | ... | @@ -597,9 +597,9 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *child_type, bool is_c |
| 597 | uint64_t ptr_debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, pointer_type->type_ref); | 597 | uint64_t ptr_debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, pointer_type->type_ref); |
| 598 | uint64_t ptr_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, entry->type_ref, 0); | 598 | uint64_t ptr_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, entry->type_ref, 0); |
| 599 | 599 | ||
| 600 | TypeTableEntry *isize_type = g->builtin_types.entry_isize; | 600 | TypeTableEntry *usize_type = g->builtin_types.entry_usize; |
| 601 | uint64_t len_debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, isize_type->type_ref); | 601 | uint64_t len_debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, usize_type->type_ref); |
| 602 | uint64_t len_debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, isize_type->type_ref); | 602 | uint64_t len_debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, usize_type->type_ref); |
| 603 | uint64_t len_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, entry->type_ref, 1); | 603 | uint64_t len_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, entry->type_ref, 1); |
| 604 | 604 | ||
| 605 | uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, entry->type_ref); | 605 | uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, entry->type_ref); |
| ... | @@ -617,7 +617,7 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *child_type, bool is_c | ... | @@ -617,7 +617,7 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *child_type, bool is_c |
| 617 | len_debug_size_in_bits, | 617 | len_debug_size_in_bits, |
| 618 | len_debug_align_in_bits, | 618 | len_debug_align_in_bits, |
| 619 | len_offset_in_bits, | 619 | len_offset_in_bits, |
| 620 | 0, isize_type->di_type), | 620 | 0, usize_type->di_type), |
| 621 | }; | 621 | }; |
| 622 | LLVMZigDIType *replacement_di_type = LLVMZigCreateDebugStructType(g->dbuilder, | 622 | LLVMZigDIType *replacement_di_type = LLVMZigCreateDebugStructType(g->dbuilder, |
| 623 | compile_unit_scope, | 623 | compile_unit_scope, |
| ... | @@ -2817,10 +2817,10 @@ static TypeTableEntry *analyze_slice_expr(CodeGen *g, ImportTableEntry *import, | ... | @@ -2817,10 +2817,10 @@ static TypeTableEntry *analyze_slice_expr(CodeGen *g, ImportTableEntry *import, |
| 2817 | context->fn_entry->struct_val_expr_alloca_list.append(&node->data.slice_expr.resolved_struct_val_expr); | 2817 | context->fn_entry->struct_val_expr_alloca_list.append(&node->data.slice_expr.resolved_struct_val_expr); |
| 2818 | } | 2818 | } |
| 2819 | 2819 | ||
| 2820 | analyze_expression(g, import, context, g->builtin_types.entry_isize, node->data.slice_expr.start); | 2820 | analyze_expression(g, import, context, g->builtin_types.entry_usize, node->data.slice_expr.start); |
| 2821 | 2821 | ||
| 2822 | if (node->data.slice_expr.end) { | 2822 | if (node->data.slice_expr.end) { |
| 2823 | analyze_expression(g, import, context, g->builtin_types.entry_isize, node->data.slice_expr.end); | 2823 | analyze_expression(g, import, context, g->builtin_types.entry_usize, node->data.slice_expr.end); |
| 2824 | } | 2824 | } |
| 2825 | 2825 | ||
| 2826 | return return_type; | 2826 | return return_type; |
| ... | @@ -2853,7 +2853,7 @@ static TypeTableEntry *analyze_array_access_expr(CodeGen *g, ImportTableEntry *i | ... | @@ -2853,7 +2853,7 @@ static TypeTableEntry *analyze_array_access_expr(CodeGen *g, ImportTableEntry *i |
| 2853 | return_type = g->builtin_types.entry_invalid; | 2853 | return_type = g->builtin_types.entry_invalid; |
| 2854 | } | 2854 | } |
| 2855 | 2855 | ||
| 2856 | analyze_expression(g, import, context, g->builtin_types.entry_isize, node->data.array_access_expr.subscript); | 2856 | analyze_expression(g, import, context, g->builtin_types.entry_usize, node->data.array_access_expr.subscript); |
| 2857 | 2857 | ||
| 2858 | return return_type; | 2858 | return return_type; |
| 2859 | } | 2859 | } |
| ... | @@ -3912,7 +3912,7 @@ static TypeTableEntry *analyze_array_type(CodeGen *g, ImportTableEntry *import, | ... | @@ -3912,7 +3912,7 @@ static TypeTableEntry *analyze_array_type(CodeGen *g, ImportTableEntry *import, |
| 3912 | 3912 | ||
| 3913 | if (size_node) { | 3913 | if (size_node) { |
| 3914 | TypeTableEntry *size_type = analyze_expression(g, import, context, | 3914 | TypeTableEntry *size_type = analyze_expression(g, import, context, |
| 3915 | g->builtin_types.entry_isize, size_node); | 3915 | g->builtin_types.entry_usize, size_node); |
| 3916 | if (size_type->id == TypeTableEntryIdInvalid) { | 3916 | if (size_type->id == TypeTableEntryIdInvalid) { |
| 3917 | return g->builtin_types.entry_invalid; | 3917 | return g->builtin_types.entry_invalid; |
| 3918 | } | 3918 | } |
| ... | @@ -4042,10 +4042,10 @@ static TypeTableEntry *analyze_for_expr(CodeGen *g, ImportTableEntry *import, Bl | ... | @@ -4042,10 +4042,10 @@ static TypeTableEntry *analyze_for_expr(CodeGen *g, ImportTableEntry *import, Bl |
| 4042 | Buf *index_var_name = &index_var_node->data.symbol_expr.symbol; | 4042 | Buf *index_var_name = &index_var_node->data.symbol_expr.symbol; |
| 4043 | index_var_node->block_context = child_context; | 4043 | index_var_node->block_context = child_context; |
| 4044 | node->data.for_expr.index_var = add_local_var(g, index_var_node, import, child_context, index_var_name, | 4044 | node->data.for_expr.index_var = add_local_var(g, index_var_node, import, child_context, index_var_name, |
| 4045 | g->builtin_types.entry_isize, true, nullptr); | 4045 | g->builtin_types.entry_usize, true, nullptr); |
| 4046 | } else { | 4046 | } else { |
| 4047 | node->data.for_expr.index_var = add_local_var(g, node, import, child_context, nullptr, | 4047 | node->data.for_expr.index_var = add_local_var(g, node, import, child_context, nullptr, |
| 4048 | g->builtin_types.entry_isize, true, nullptr); | 4048 | g->builtin_types.entry_usize, true, nullptr); |
| 4049 | } | 4049 | } |
| 4050 | 4050 | ||
| 4051 | AstNode *for_body_node = node->data.for_expr.body; | 4051 | AstNode *for_body_node = node->data.for_expr.body; |
src/codegen.cpp+24-24| ... | @@ -413,7 +413,7 @@ static LLVMValueRef gen_err_name(CodeGen *g, AstNode *node) { | ... | @@ -413,7 +413,7 @@ static LLVMValueRef gen_err_name(CodeGen *g, AstNode *node) { |
| 413 | } | 413 | } |
| 414 | 414 | ||
| 415 | LLVMValueRef indices[] = { | 415 | LLVMValueRef indices[] = { |
| 416 | LLVMConstNull(g->builtin_types.entry_isize->type_ref), | 416 | LLVMConstNull(g->builtin_types.entry_usize->type_ref), |
| 417 | err_val, | 417 | err_val, |
| 418 | }; | 418 | }; |
| 419 | return LLVMBuildInBoundsGEP(g->builder, g->err_name_table, indices, 2, ""); | 419 | return LLVMBuildInBoundsGEP(g->builder, g->err_name_table, indices, 2, ""); |
| ... | @@ -937,7 +937,7 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) { | ... | @@ -937,7 +937,7 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) { |
| 937 | 937 | ||
| 938 | int len_index = wanted_type->data.structure.fields[1].gen_index; | 938 | int len_index = wanted_type->data.structure.fields[1].gen_index; |
| 939 | LLVMValueRef len_ptr = LLVMBuildStructGEP(g->builder, cast_expr->tmp_ptr, len_index, ""); | 939 | LLVMValueRef len_ptr = LLVMBuildStructGEP(g->builder, cast_expr->tmp_ptr, len_index, ""); |
| 940 | LLVMValueRef len_val = LLVMConstInt(g->builtin_types.entry_isize->type_ref, | 940 | LLVMValueRef len_val = LLVMConstInt(g->builtin_types.entry_usize->type_ref, |
| 941 | actual_type->data.array.len, false); | 941 | actual_type->data.array.len, false); |
| 942 | LLVMBuildStore(g->builder, len_val, len_ptr); | 942 | LLVMBuildStore(g->builder, len_val, len_ptr); |
| 943 | 943 | ||
| ... | @@ -978,13 +978,13 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) { | ... | @@ -978,13 +978,13 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) { |
| 978 | 978 | ||
| 979 | LLVMValueRef new_len; | 979 | LLVMValueRef new_len; |
| 980 | if (dest_size == 1) { | 980 | if (dest_size == 1) { |
| 981 | LLVMValueRef src_size_val = LLVMConstInt(g->builtin_types.entry_isize->type_ref, src_size, false); | 981 | LLVMValueRef src_size_val = LLVMConstInt(g->builtin_types.entry_usize->type_ref, src_size, false); |
| 982 | new_len = LLVMBuildMul(g->builder, src_len, src_size_val, ""); | 982 | new_len = LLVMBuildMul(g->builder, src_len, src_size_val, ""); |
| 983 | } else if (src_size == 1) { | 983 | } else if (src_size == 1) { |
| 984 | LLVMValueRef dest_size_val = LLVMConstInt(g->builtin_types.entry_isize->type_ref, dest_size, false); | 984 | LLVMValueRef dest_size_val = LLVMConstInt(g->builtin_types.entry_usize->type_ref, dest_size, false); |
| 985 | if (want_debug_safety(g, node)) { | 985 | if (want_debug_safety(g, node)) { |
| 986 | LLVMValueRef remainder_val = LLVMBuildURem(g->builder, src_len, dest_size_val, ""); | 986 | LLVMValueRef remainder_val = LLVMBuildURem(g->builder, src_len, dest_size_val, ""); |
| 987 | LLVMValueRef zero = LLVMConstNull(g->builtin_types.entry_isize->type_ref); | 987 | LLVMValueRef zero = LLVMConstNull(g->builtin_types.entry_usize->type_ref); |
| 988 | LLVMValueRef ok_bit = LLVMBuildICmp(g->builder, LLVMIntEQ, remainder_val, zero, ""); | 988 | LLVMValueRef ok_bit = LLVMBuildICmp(g->builder, LLVMIntEQ, remainder_val, zero, ""); |
| 989 | LLVMBasicBlockRef ok_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "SliceWidenOk"); | 989 | LLVMBasicBlockRef ok_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "SliceWidenOk"); |
| 990 | LLVMBasicBlockRef fail_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "SliceWidenFail"); | 990 | LLVMBasicBlockRef fail_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "SliceWidenFail"); |
| ... | @@ -1159,12 +1159,12 @@ static LLVMValueRef gen_array_elem_ptr(CodeGen *g, AstNode *source_node, LLVMVal | ... | @@ -1159,12 +1159,12 @@ static LLVMValueRef gen_array_elem_ptr(CodeGen *g, AstNode *source_node, LLVMVal |
| 1159 | 1159 | ||
| 1160 | if (array_type->id == TypeTableEntryIdArray) { | 1160 | if (array_type->id == TypeTableEntryIdArray) { |
| 1161 | if (want_debug_safety(g, source_node)) { | 1161 | if (want_debug_safety(g, source_node)) { |
| 1162 | LLVMValueRef end = LLVMConstInt(g->builtin_types.entry_isize->type_ref, | 1162 | LLVMValueRef end = LLVMConstInt(g->builtin_types.entry_usize->type_ref, |
| 1163 | array_type->data.array.len, false); | 1163 | array_type->data.array.len, false); |
| 1164 | add_bounds_check(g, source_node, subscript_value, LLVMIntEQ, nullptr, LLVMIntULT, end); | 1164 | add_bounds_check(g, source_node, subscript_value, LLVMIntEQ, nullptr, LLVMIntULT, end); |
| 1165 | } | 1165 | } |
| 1166 | LLVMValueRef indices[] = { | 1166 | LLVMValueRef indices[] = { |
| 1167 | LLVMConstNull(g->builtin_types.entry_isize->type_ref), | 1167 | LLVMConstNull(g->builtin_types.entry_usize->type_ref), |
| 1168 | subscript_value | 1168 | subscript_value |
| 1169 | }; | 1169 | }; |
| 1170 | set_debug_source_node(g, source_node); | 1170 | set_debug_source_node(g, source_node); |
| ... | @@ -1268,13 +1268,13 @@ static LLVMValueRef gen_slice_expr(CodeGen *g, AstNode *node) { | ... | @@ -1268,13 +1268,13 @@ static LLVMValueRef gen_slice_expr(CodeGen *g, AstNode *node) { |
| 1268 | if (node->data.slice_expr.end) { | 1268 | if (node->data.slice_expr.end) { |
| 1269 | end_val = gen_expr(g, node->data.slice_expr.end); | 1269 | end_val = gen_expr(g, node->data.slice_expr.end); |
| 1270 | } else { | 1270 | } else { |
| 1271 | end_val = LLVMConstInt(g->builtin_types.entry_isize->type_ref, array_type->data.array.len, false); | 1271 | end_val = LLVMConstInt(g->builtin_types.entry_usize->type_ref, array_type->data.array.len, false); |
| 1272 | } | 1272 | } |
| 1273 | 1273 | ||
| 1274 | if (want_debug_safety(g, node)) { | 1274 | if (want_debug_safety(g, node)) { |
| 1275 | add_bounds_check(g, node, start_val, LLVMIntEQ, nullptr, LLVMIntULE, end_val); | 1275 | add_bounds_check(g, node, start_val, LLVMIntEQ, nullptr, LLVMIntULE, end_val); |
| 1276 | if (node->data.slice_expr.end) { | 1276 | if (node->data.slice_expr.end) { |
| 1277 | LLVMValueRef array_end = LLVMConstInt(g->builtin_types.entry_isize->type_ref, | 1277 | LLVMValueRef array_end = LLVMConstInt(g->builtin_types.entry_usize->type_ref, |
| 1278 | array_type->data.array.len, false); | 1278 | array_type->data.array.len, false); |
| 1279 | add_bounds_check(g, node, end_val, LLVMIntEQ, nullptr, LLVMIntULE, array_end); | 1279 | add_bounds_check(g, node, end_val, LLVMIntEQ, nullptr, LLVMIntULE, array_end); |
| 1280 | } | 1280 | } |
| ... | @@ -1283,7 +1283,7 @@ static LLVMValueRef gen_slice_expr(CodeGen *g, AstNode *node) { | ... | @@ -1283,7 +1283,7 @@ static LLVMValueRef gen_slice_expr(CodeGen *g, AstNode *node) { |
| 1283 | set_debug_source_node(g, node); | 1283 | set_debug_source_node(g, node); |
| 1284 | LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, 0, ""); | 1284 | LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, 0, ""); |
| 1285 | LLVMValueRef indices[] = { | 1285 | LLVMValueRef indices[] = { |
| 1286 | LLVMConstNull(g->builtin_types.entry_isize->type_ref), | 1286 | LLVMConstNull(g->builtin_types.entry_usize->type_ref), |
| 1287 | start_val, | 1287 | start_val, |
| 1288 | }; | 1288 | }; |
| 1289 | LLVMValueRef slice_start_ptr = LLVMBuildInBoundsGEP(g->builder, array_ptr, indices, 2, ""); | 1289 | LLVMValueRef slice_start_ptr = LLVMBuildInBoundsGEP(g->builder, array_ptr, indices, 2, ""); |
| ... | @@ -1408,7 +1408,7 @@ static LLVMValueRef gen_field_access_expr(CodeGen *g, AstNode *node, bool is_lva | ... | @@ -1408,7 +1408,7 @@ static LLVMValueRef gen_field_access_expr(CodeGen *g, AstNode *node, bool is_lva |
| 1408 | if (struct_type->id == TypeTableEntryIdArray) { | 1408 | if (struct_type->id == TypeTableEntryIdArray) { |
| 1409 | Buf *name = &node->data.field_access_expr.field_name; | 1409 | Buf *name = &node->data.field_access_expr.field_name; |
| 1410 | assert(buf_eql_str(name, "len")); | 1410 | assert(buf_eql_str(name, "len")); |
| 1411 | return LLVMConstInt(g->builtin_types.entry_isize->type_ref, | 1411 | return LLVMConstInt(g->builtin_types.entry_usize->type_ref, |
| 1412 | struct_type->data.array.len, false); | 1412 | struct_type->data.array.len, false); |
| 1413 | } else if (struct_type->id == TypeTableEntryIdStruct || (struct_type->id == TypeTableEntryIdPointer && | 1413 | } else if (struct_type->id == TypeTableEntryIdStruct || (struct_type->id == TypeTableEntryIdPointer && |
| 1414 | struct_type->data.pointer.child_type->id == TypeTableEntryIdStruct)) | 1414 | struct_type->data.pointer.child_type->id == TypeTableEntryIdStruct)) |
| ... | @@ -2043,7 +2043,7 @@ static LLVMValueRef gen_struct_memcpy(CodeGen *g, AstNode *source_node, LLVMValu | ... | @@ -2043,7 +2043,7 @@ static LLVMValueRef gen_struct_memcpy(CodeGen *g, AstNode *source_node, LLVMValu |
| 2043 | LLVMValueRef src_ptr = LLVMBuildBitCast(g->builder, src, ptr_u8, ""); | 2043 | LLVMValueRef src_ptr = LLVMBuildBitCast(g->builder, src, ptr_u8, ""); |
| 2044 | LLVMValueRef dest_ptr = LLVMBuildBitCast(g->builder, dest, ptr_u8, ""); | 2044 | LLVMValueRef dest_ptr = LLVMBuildBitCast(g->builder, dest, ptr_u8, ""); |
| 2045 | 2045 | ||
| 2046 | TypeTableEntry *isize = g->builtin_types.entry_isize; | 2046 | TypeTableEntry *usize = g->builtin_types.entry_usize; |
| 2047 | uint64_t size_bytes = LLVMStoreSizeOfType(g->target_data_ref, type_entry->type_ref); | 2047 | uint64_t size_bytes = LLVMStoreSizeOfType(g->target_data_ref, type_entry->type_ref); |
| 2048 | uint64_t align_bytes = get_memcpy_align(g, type_entry); | 2048 | uint64_t align_bytes = get_memcpy_align(g, type_entry); |
| 2049 | assert(size_bytes > 0); | 2049 | assert(size_bytes > 0); |
| ... | @@ -2052,7 +2052,7 @@ static LLVMValueRef gen_struct_memcpy(CodeGen *g, AstNode *source_node, LLVMValu | ... | @@ -2052,7 +2052,7 @@ static LLVMValueRef gen_struct_memcpy(CodeGen *g, AstNode *source_node, LLVMValu |
| 2052 | LLVMValueRef params[] = { | 2052 | LLVMValueRef params[] = { |
| 2053 | dest_ptr, // dest pointer | 2053 | dest_ptr, // dest pointer |
| 2054 | src_ptr, // source pointer | 2054 | src_ptr, // source pointer |
| 2055 | LLVMConstInt(isize->type_ref, size_bytes, false), | 2055 | LLVMConstInt(usize->type_ref, size_bytes, false), |
| 2056 | LLVMConstInt(LLVMInt32Type(), align_bytes, false), | 2056 | LLVMConstInt(LLVMInt32Type(), align_bytes, false), |
| 2057 | LLVMConstNull(LLVMInt1Type()), // is volatile | 2057 | LLVMConstNull(LLVMInt1Type()), // is volatile |
| 2058 | }; | 2058 | }; |
| ... | @@ -2871,8 +2871,8 @@ static LLVMValueRef gen_container_init_expr(CodeGen *g, AstNode *node) { | ... | @@ -2871,8 +2871,8 @@ static LLVMValueRef gen_container_init_expr(CodeGen *g, AstNode *node) { |
| 2871 | LLVMValueRef elem_val = gen_expr(g, field_node); | 2871 | LLVMValueRef elem_val = gen_expr(g, field_node); |
| 2872 | 2872 | ||
| 2873 | LLVMValueRef indices[] = { | 2873 | LLVMValueRef indices[] = { |
| 2874 | LLVMConstNull(g->builtin_types.entry_isize->type_ref), | 2874 | LLVMConstNull(g->builtin_types.entry_usize->type_ref), |
| 2875 | LLVMConstInt(g->builtin_types.entry_isize->type_ref, i, false), | 2875 | LLVMConstInt(g->builtin_types.entry_usize->type_ref, i, false), |
| 2876 | }; | 2876 | }; |
| 2877 | set_debug_source_node(g, field_node); | 2877 | set_debug_source_node(g, field_node); |
| 2878 | LLVMValueRef elem_ptr = LLVMBuildInBoundsGEP(g->builder, tmp_array_ptr, indices, 2, ""); | 2878 | LLVMValueRef elem_ptr = LLVMBuildInBoundsGEP(g->builder, tmp_array_ptr, indices, 2, ""); |
| ... | @@ -2989,7 +2989,7 @@ static LLVMValueRef gen_for_expr(CodeGen *g, AstNode *node) { | ... | @@ -2989,7 +2989,7 @@ static LLVMValueRef gen_for_expr(CodeGen *g, AstNode *node) { |
| 2989 | VariableTableEntry *index_var = node->data.for_expr.index_var; | 2989 | VariableTableEntry *index_var = node->data.for_expr.index_var; |
| 2990 | assert(index_var); | 2990 | assert(index_var); |
| 2991 | LLVMValueRef index_ptr = index_var->value_ref; | 2991 | LLVMValueRef index_ptr = index_var->value_ref; |
| 2992 | LLVMValueRef one_const = LLVMConstInt(g->builtin_types.entry_isize->type_ref, 1, false); | 2992 | LLVMValueRef one_const = LLVMConstInt(g->builtin_types.entry_usize->type_ref, 1, false); |
| 2993 | 2993 | ||
| 2994 | LLVMBasicBlockRef cond_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "ForCond"); | 2994 | LLVMBasicBlockRef cond_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "ForCond"); |
| 2995 | LLVMBasicBlockRef body_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "ForBody"); | 2995 | LLVMBasicBlockRef body_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "ForBody"); |
| ... | @@ -3005,7 +3005,7 @@ static LLVMValueRef gen_for_expr(CodeGen *g, AstNode *node) { | ... | @@ -3005,7 +3005,7 @@ static LLVMValueRef gen_for_expr(CodeGen *g, AstNode *node) { |
| 3005 | LLVMValueRef len_val; | 3005 | LLVMValueRef len_val; |
| 3006 | TypeTableEntry *child_type; | 3006 | TypeTableEntry *child_type; |
| 3007 | if (array_type->id == TypeTableEntryIdArray) { | 3007 | if (array_type->id == TypeTableEntryIdArray) { |
| 3008 | len_val = LLVMConstInt(g->builtin_types.entry_isize->type_ref, | 3008 | len_val = LLVMConstInt(g->builtin_types.entry_usize->type_ref, |
| 3009 | array_type->data.array.len, false); | 3009 | array_type->data.array.len, false); |
| 3010 | child_type = array_type->data.array.child_type; | 3010 | child_type = array_type->data.array.child_type; |
| 3011 | } else if (array_type->id == TypeTableEntryIdStruct) { | 3011 | } else if (array_type->id == TypeTableEntryIdStruct) { |
| ... | @@ -3154,7 +3154,7 @@ static LLVMValueRef gen_var_decl_raw(CodeGen *g, AstNode *source_node, AstNodeVa | ... | @@ -3154,7 +3154,7 @@ static LLVMValueRef gen_var_decl_raw(CodeGen *g, AstNode *source_node, AstNodeVa |
| 3154 | } | 3154 | } |
| 3155 | } | 3155 | } |
| 3156 | if (!ignore_uninit && want_debug_safety(g, source_node)) { | 3156 | if (!ignore_uninit && want_debug_safety(g, source_node)) { |
| 3157 | TypeTableEntry *isize = g->builtin_types.entry_isize; | 3157 | TypeTableEntry *usize = g->builtin_types.entry_usize; |
| 3158 | uint64_t size_bytes = LLVMStoreSizeOfType(g->target_data_ref, variable->type->type_ref); | 3158 | uint64_t size_bytes = LLVMStoreSizeOfType(g->target_data_ref, variable->type->type_ref); |
| 3159 | uint64_t align_bytes = get_memcpy_align(g, variable->type); | 3159 | uint64_t align_bytes = get_memcpy_align(g, variable->type); |
| 3160 | 3160 | ||
| ... | @@ -3163,7 +3163,7 @@ static LLVMValueRef gen_var_decl_raw(CodeGen *g, AstNode *source_node, AstNodeVa | ... | @@ -3163,7 +3163,7 @@ static LLVMValueRef gen_var_decl_raw(CodeGen *g, AstNode *source_node, AstNodeVa |
| 3163 | LLVMTypeRef ptr_u8 = LLVMPointerType(LLVMInt8Type(), 0); | 3163 | LLVMTypeRef ptr_u8 = LLVMPointerType(LLVMInt8Type(), 0); |
| 3164 | LLVMValueRef fill_char = LLVMConstInt(LLVMInt8Type(), 0xaa, false); | 3164 | LLVMValueRef fill_char = LLVMConstInt(LLVMInt8Type(), 0xaa, false); |
| 3165 | LLVMValueRef dest_ptr = LLVMBuildBitCast(g->builder, variable->value_ref, ptr_u8, ""); | 3165 | LLVMValueRef dest_ptr = LLVMBuildBitCast(g->builder, variable->value_ref, ptr_u8, ""); |
| 3166 | LLVMValueRef byte_count = LLVMConstInt(isize->type_ref, size_bytes, false); | 3166 | LLVMValueRef byte_count = LLVMConstInt(usize->type_ref, size_bytes, false); |
| 3167 | LLVMValueRef align_in_bytes = LLVMConstInt(LLVMInt32Type(), align_bytes, false); | 3167 | LLVMValueRef align_in_bytes = LLVMConstInt(LLVMInt32Type(), align_bytes, false); |
| 3168 | LLVMValueRef params[] = { | 3168 | LLVMValueRef params[] = { |
| 3169 | dest_ptr, | 3169 | dest_ptr, |
| ... | @@ -3771,7 +3771,7 @@ static LLVMValueRef gen_test_fn_val(CodeGen *g, FnTableEntry *fn_entry) { | ... | @@ -3771,7 +3771,7 @@ static LLVMValueRef gen_test_fn_val(CodeGen *g, FnTableEntry *fn_entry) { |
| 3771 | LLVMSetGlobalConstant(str_global_val, true); | 3771 | LLVMSetGlobalConstant(str_global_val, true); |
| 3772 | LLVMSetUnnamedAddr(str_global_val, true); | 3772 | LLVMSetUnnamedAddr(str_global_val, true); |
| 3773 | 3773 | ||
| 3774 | LLVMValueRef len_val = LLVMConstInt(g->builtin_types.entry_isize->type_ref, buf_len(fn_name), false); | 3774 | LLVMValueRef len_val = LLVMConstInt(g->builtin_types.entry_usize->type_ref, buf_len(fn_name), false); |
| 3775 | 3775 | ||
| 3776 | LLVMTypeRef ptr_type = LLVMPointerType(g->builtin_types.entry_u8->type_ref, 0); | 3776 | LLVMTypeRef ptr_type = LLVMPointerType(g->builtin_types.entry_u8->type_ref, 0); |
| 3777 | LLVMValueRef name_fields[] = { | 3777 | LLVMValueRef name_fields[] = { |
| ... | @@ -3813,7 +3813,7 @@ static void generate_error_name_table(CodeGen *g) { | ... | @@ -3813,7 +3813,7 @@ static void generate_error_name_table(CodeGen *g) { |
| 3813 | 3813 | ||
| 3814 | LLVMValueRef fields[] = { | 3814 | LLVMValueRef fields[] = { |
| 3815 | LLVMConstBitCast(str_global, u8_ptr_type->type_ref), | 3815 | LLVMConstBitCast(str_global, u8_ptr_type->type_ref), |
| 3816 | LLVMConstInt(g->builtin_types.entry_isize->type_ref, buf_len(name), false), | 3816 | LLVMConstInt(g->builtin_types.entry_usize->type_ref, buf_len(name), false), |
| 3817 | }; | 3817 | }; |
| 3818 | values[i] = LLVMConstNamedStruct(str_type->type_ref, fields, 2); | 3818 | values[i] = LLVMConstNamedStruct(str_type->type_ref, fields, 2); |
| 3819 | } | 3819 | } |
| ... | @@ -3986,7 +3986,7 @@ static void do_code_gen(CodeGen *g) { | ... | @@ -3986,7 +3986,7 @@ static void do_code_gen(CodeGen *g) { |
| 3986 | LLVMSetGlobalConstant(test_fn_array_val, true); | 3986 | LLVMSetGlobalConstant(test_fn_array_val, true); |
| 3987 | LLVMSetUnnamedAddr(test_fn_array_val, true); | 3987 | LLVMSetUnnamedAddr(test_fn_array_val, true); |
| 3988 | 3988 | ||
| 3989 | LLVMValueRef len_val = LLVMConstInt(g->builtin_types.entry_isize->type_ref, g->test_fn_count, false); | 3989 | LLVMValueRef len_val = LLVMConstInt(g->builtin_types.entry_usize->type_ref, g->test_fn_count, false); |
| 3990 | LLVMTypeRef ptr_type = LLVMPointerType(LLVMTypeOf(test_fn_vals[0]), 0); | 3990 | LLVMTypeRef ptr_type = LLVMPointerType(LLVMTypeOf(test_fn_vals[0]), 0); |
| 3991 | LLVMValueRef fields[] = { | 3991 | LLVMValueRef fields[] = { |
| 3992 | LLVMConstBitCast(test_fn_array_val, ptr_type), | 3992 | LLVMConstBitCast(test_fn_array_val, ptr_type), |
| ... | @@ -4611,7 +4611,7 @@ static void define_builtin_fns(CodeGen *g) { | ... | @@ -4611,7 +4611,7 @@ static void define_builtin_fns(CodeGen *g) { |
| 4611 | builtin_fn->param_types = allocate<TypeTableEntry *>(builtin_fn->param_count); | 4611 | builtin_fn->param_types = allocate<TypeTableEntry *>(builtin_fn->param_count); |
| 4612 | builtin_fn->param_types[0] = nullptr; // manually checked later | 4612 | builtin_fn->param_types[0] = nullptr; // manually checked later |
| 4613 | builtin_fn->param_types[1] = nullptr; // manually checked later | 4613 | builtin_fn->param_types[1] = nullptr; // manually checked later |
| 4614 | builtin_fn->param_types[2] = g->builtin_types.entry_isize; | 4614 | builtin_fn->param_types[2] = g->builtin_types.entry_usize; |
| 4615 | builtin_fn->ref_count = 1; | 4615 | builtin_fn->ref_count = 1; |
| 4616 | 4616 | ||
| 4617 | LLVMTypeRef param_types[] = { | 4617 | LLVMTypeRef param_types[] = { |
| ... | @@ -4635,7 +4635,7 @@ static void define_builtin_fns(CodeGen *g) { | ... | @@ -4635,7 +4635,7 @@ static void define_builtin_fns(CodeGen *g) { |
| 4635 | builtin_fn->param_types = allocate<TypeTableEntry *>(builtin_fn->param_count); | 4635 | builtin_fn->param_types = allocate<TypeTableEntry *>(builtin_fn->param_count); |
| 4636 | builtin_fn->param_types[0] = nullptr; // manually checked later | 4636 | builtin_fn->param_types[0] = nullptr; // manually checked later |
| 4637 | builtin_fn->param_types[1] = g->builtin_types.entry_u8; | 4637 | builtin_fn->param_types[1] = g->builtin_types.entry_u8; |
| 4638 | builtin_fn->param_types[2] = g->builtin_types.entry_isize; | 4638 | builtin_fn->param_types[2] = g->builtin_types.entry_usize; |
| 4639 | builtin_fn->ref_count = 1; | 4639 | builtin_fn->ref_count = 1; |
| 4640 | 4640 | ||
| 4641 | LLVMTypeRef param_types[] = { | 4641 | LLVMTypeRef param_types[] = { |
std/bootstrap.zig+4-4| ... | @@ -10,7 +10,7 @@ const want_start_symbol = switch(@compile_var("os")) { | ... | @@ -10,7 +10,7 @@ const want_start_symbol = switch(@compile_var("os")) { |
| 10 | }; | 10 | }; |
| 11 | const want_main_symbol = !want_start_symbol; | 11 | const want_main_symbol = !want_start_symbol; |
| 12 | 12 | ||
| 13 | var argc: isize = undefined; | 13 | var argc: usize = undefined; |
| 14 | var argv: &&u8 = undefined; | 14 | var argv: &&u8 = undefined; |
| 15 | 15 | ||
| 16 | #attribute("naked") | 16 | #attribute("naked") |
| ... | @@ -18,11 +18,11 @@ var argv: &&u8 = undefined; | ... | @@ -18,11 +18,11 @@ var argv: &&u8 = undefined; |
| 18 | export fn _start() -> unreachable { | 18 | export fn _start() -> unreachable { |
| 19 | switch (@compile_var("arch")) { | 19 | switch (@compile_var("arch")) { |
| 20 | x86_64 => { | 20 | x86_64 => { |
| 21 | argc = asm("mov (%%rsp), %[argc]": [argc] "=r" (-> isize)); | 21 | argc = asm("mov (%%rsp), %[argc]": [argc] "=r" (-> usize)); |
| 22 | argv = asm("lea 0x8(%%rsp), %[argv]": [argv] "=r" (-> &&u8)); | 22 | argv = asm("lea 0x8(%%rsp), %[argv]": [argv] "=r" (-> &&u8)); |
| 23 | }, | 23 | }, |
| 24 | i386 => { | 24 | i386 => { |
| 25 | argc = asm("mov (%%esp), %[argc]": [argc] "=r" (-> isize)); | 25 | argc = asm("mov (%%esp), %[argc]": [argc] "=r" (-> usize)); |
| 26 | argv = asm("lea 0x4(%%esp), %[argv]": [argv] "=r" (-> &&u8)); | 26 | argv = asm("lea 0x4(%%esp), %[argv]": [argv] "=r" (-> &&u8)); |
| 27 | }, | 27 | }, |
| 28 | else => @compile_err("unsupported arch"), | 28 | else => @compile_err("unsupported arch"), |
| ... | @@ -46,7 +46,7 @@ fn call_main_and_exit() -> unreachable { | ... | @@ -46,7 +46,7 @@ fn call_main_and_exit() -> unreachable { |
| 46 | 46 | ||
| 47 | #condition(want_main_symbol) | 47 | #condition(want_main_symbol) |
| 48 | export fn main(c_argc: i32, c_argv: &&u8) -> i32 { | 48 | export fn main(c_argc: i32, c_argv: &&u8) -> i32 { |
| 49 | argc = c_argc; | 49 | argc = usize(c_argc); |
| 50 | argv = c_argv; | 50 | argv = c_argv; |
| 51 | call_main() %% return 1; | 51 | call_main() %% return 1; |
| 52 | return 0; | 52 | return 0; |
std/builtin.zig+4-4| ... | @@ -2,8 +2,8 @@ | ... | @@ -2,8 +2,8 @@ |
| 2 | // sometimes generates code that calls them. | 2 | // sometimes generates code that calls them. |
| 3 | 3 | ||
| 4 | #debug_safety(false) | 4 | #debug_safety(false) |
| 5 | export fn memset(dest: &u8, c: u8, n: isize) -> &u8 { | 5 | export fn memset(dest: &u8, c: u8, n: usize) -> &u8 { |
| 6 | var index: isize = 0; | 6 | var index: usize = 0; |
| 7 | while (index != n) { | 7 | while (index != n) { |
| 8 | dest[index] = c; | 8 | dest[index] = c; |
| 9 | index += 1; | 9 | index += 1; |
| ... | @@ -12,8 +12,8 @@ export fn memset(dest: &u8, c: u8, n: isize) -> &u8 { | ... | @@ -12,8 +12,8 @@ export fn memset(dest: &u8, c: u8, n: isize) -> &u8 { |
| 12 | } | 12 | } |
| 13 | 13 | ||
| 14 | #debug_safety(false) | 14 | #debug_safety(false) |
| 15 | export fn memcpy(noalias dest: &u8, noalias src: &const u8, n: isize) -> &u8 { | 15 | export fn memcpy(noalias dest: &u8, noalias src: &const u8, n: usize) -> &u8 { |
| 16 | var index: isize = 0; | 16 | var index: usize = 0; |
| 17 | while (index != n) { | 17 | while (index != n) { |
| 18 | dest[index] = src[index]; | 18 | dest[index] = src[index]; |
| 19 | index += 1; | 19 | index += 1; |
std/cstr.zig+3-3| ... | @@ -1,8 +1,8 @@ | ... | @@ -1,8 +1,8 @@ |
| 1 | // TODO fix https://github.com/andrewrk/zig/issues/140 | 1 | // TODO fix https://github.com/andrewrk/zig/issues/140 |
| 2 | // and then make this able to run at compile time | 2 | // and then make this able to run at compile time |
| 3 | #static_eval_enable(false) | 3 | #static_eval_enable(false) |
| 4 | pub fn len(ptr: &const u8) -> isize { | 4 | pub fn len(ptr: &const u8) -> usize { |
| 5 | var count: isize = 0; | 5 | var count: usize = 0; |
| 6 | while (ptr[count] != 0; count += 1) {} | 6 | while (ptr[count] != 0; count += 1) {} |
| 7 | return count; | 7 | return count; |
| 8 | } | 8 | } |
| ... | @@ -11,7 +11,7 @@ pub fn len(ptr: &const u8) -> isize { | ... | @@ -11,7 +11,7 @@ pub fn len(ptr: &const u8) -> isize { |
| 11 | // and then make this able to run at compile time | 11 | // and then make this able to run at compile time |
| 12 | #static_eval_enable(false) | 12 | #static_eval_enable(false) |
| 13 | pub fn cmp(a: &const u8, b: &const u8) -> i32 { | 13 | pub fn cmp(a: &const u8, b: &const u8) -> i32 { |
| 14 | var index: isize = 0; | 14 | var index: usize = 0; |
| 15 | while (a[index] == b[index] && a[index] != 0; index += 1) {} | 15 | while (a[index] == b[index] && a[index] != 0; index += 1) {} |
| 16 | return a[index] - b[index]; | 16 | return a[index] - b[index]; |
| 17 | } | 17 | } |
std/hash_map.zig+18-18| ... | @@ -12,10 +12,10 @@ pub inline fn HashMap(inline K: type, inline V: type, inline hash: fn(key: K)->u | ... | @@ -12,10 +12,10 @@ pub inline fn HashMap(inline K: type, inline V: type, inline hash: fn(key: K)->u |
| 12 | } | 12 | } |
| 13 | */ | 13 | */ |
| 14 | 14 | ||
| 15 | pub struct SmallHashMap(K: type, V: type, hash: fn(key: K)->u32, eql: fn(a: K, b: K)->bool, STATIC_SIZE: isize) { | 15 | pub struct SmallHashMap(K: type, V: type, hash: fn(key: K)->u32, eql: fn(a: K, b: K)->bool, STATIC_SIZE: usize) { |
| 16 | entries: []Entry, | 16 | entries: []Entry, |
| 17 | size: isize, | 17 | size: usize, |
| 18 | max_distance_from_start_index: isize, | 18 | max_distance_from_start_index: usize, |
| 19 | allocator: &Allocator, | 19 | allocator: &Allocator, |
| 20 | // if the hash map is small enough, we use linear search through these | 20 | // if the hash map is small enough, we use linear search through these |
| 21 | // entries instead of allocating memory | 21 | // entries instead of allocating memory |
| ... | @@ -27,7 +27,7 @@ pub struct SmallHashMap(K: type, V: type, hash: fn(key: K)->u32, eql: fn(a: K, b | ... | @@ -27,7 +27,7 @@ pub struct SmallHashMap(K: type, V: type, hash: fn(key: K)->u32, eql: fn(a: K, b |
| 27 | 27 | ||
| 28 | pub struct Entry { | 28 | pub struct Entry { |
| 29 | used: bool, | 29 | used: bool, |
| 30 | distance_from_start_index: isize, | 30 | distance_from_start_index: usize, |
| 31 | key: K, | 31 | key: K, |
| 32 | value: V, | 32 | value: V, |
| 33 | } | 33 | } |
| ... | @@ -35,9 +35,9 @@ pub struct SmallHashMap(K: type, V: type, hash: fn(key: K)->u32, eql: fn(a: K, b | ... | @@ -35,9 +35,9 @@ pub struct SmallHashMap(K: type, V: type, hash: fn(key: K)->u32, eql: fn(a: K, b |
| 35 | pub struct Iterator { | 35 | pub struct Iterator { |
| 36 | hm: &Self, | 36 | hm: &Self, |
| 37 | // how many items have we returned | 37 | // how many items have we returned |
| 38 | count: isize, | 38 | count: usize, |
| 39 | // iterator through the entry array | 39 | // iterator through the entry array |
| 40 | index: isize, | 40 | index: usize, |
| 41 | // used to detect concurrent modification | 41 | // used to detect concurrent modification |
| 42 | initial_modification_count: debug_u32, | 42 | initial_modification_count: debug_u32, |
| 43 | 43 | ||
| ... | @@ -117,7 +117,7 @@ pub struct SmallHashMap(K: type, V: type, hash: fn(key: K)->u32, eql: fn(a: K, b | ... | @@ -117,7 +117,7 @@ pub struct SmallHashMap(K: type, V: type, hash: fn(key: K)->u32, eql: fn(a: K, b |
| 117 | pub fn remove(hm: &Self, key: K) { | 117 | pub fn remove(hm: &Self, key: K) { |
| 118 | hm.increment_modification_count(); | 118 | hm.increment_modification_count(); |
| 119 | const start_index = hm.key_to_index(key); | 119 | const start_index = hm.key_to_index(key); |
| 120 | {var roll_over: isize = 0; while (roll_over <= hm.max_distance_from_start_index; roll_over += 1) { | 120 | {var roll_over: usize = 0; while (roll_over <= hm.max_distance_from_start_index; roll_over += 1) { |
| 121 | const index = (start_index + roll_over) % hm.entries.len; | 121 | const index = (start_index + roll_over) % hm.entries.len; |
| 122 | var entry = &hm.entries[index]; | 122 | var entry = &hm.entries[index]; |
| 123 | 123 | ||
| ... | @@ -151,7 +151,7 @@ pub struct SmallHashMap(K: type, V: type, hash: fn(key: K)->u32, eql: fn(a: K, b | ... | @@ -151,7 +151,7 @@ pub struct SmallHashMap(K: type, V: type, hash: fn(key: K)->u32, eql: fn(a: K, b |
| 151 | }; | 151 | }; |
| 152 | } | 152 | } |
| 153 | 153 | ||
| 154 | fn init_capacity(hm: &Self, capacity: isize) -> %void { | 154 | fn init_capacity(hm: &Self, capacity: usize) -> %void { |
| 155 | hm.entries = %return hm.allocator.alloc(Entry, capacity); | 155 | hm.entries = %return hm.allocator.alloc(Entry, capacity); |
| 156 | hm.size = 0; | 156 | hm.size = 0; |
| 157 | hm.max_distance_from_start_index = 0; | 157 | hm.max_distance_from_start_index = 0; |
| ... | @@ -170,8 +170,8 @@ pub struct SmallHashMap(K: type, V: type, hash: fn(key: K)->u32, eql: fn(a: K, b | ... | @@ -170,8 +170,8 @@ pub struct SmallHashMap(K: type, V: type, hash: fn(key: K)->u32, eql: fn(a: K, b |
| 170 | var key = orig_key; | 170 | var key = orig_key; |
| 171 | var value = orig_value; | 171 | var value = orig_value; |
| 172 | const start_index = hm.key_to_index(key); | 172 | const start_index = hm.key_to_index(key); |
| 173 | var roll_over: isize = 0; | 173 | var roll_over: usize = 0; |
| 174 | var distance_from_start_index: isize = 0; | 174 | var distance_from_start_index: usize = 0; |
| 175 | while (roll_over < hm.entries.len; {roll_over += 1; distance_from_start_index += 1}) { | 175 | while (roll_over < hm.entries.len; {roll_over += 1; distance_from_start_index += 1}) { |
| 176 | const index = (start_index + roll_over) % hm.entries.len; | 176 | const index = (start_index + roll_over) % hm.entries.len; |
| 177 | const entry = &hm.entries[index]; | 177 | const entry = &hm.entries[index]; |
| ... | @@ -180,7 +180,7 @@ pub struct SmallHashMap(K: type, V: type, hash: fn(key: K)->u32, eql: fn(a: K, b | ... | @@ -180,7 +180,7 @@ pub struct SmallHashMap(K: type, V: type, hash: fn(key: K)->u32, eql: fn(a: K, b |
| 180 | if (entry.distance_from_start_index < distance_from_start_index) { | 180 | if (entry.distance_from_start_index < distance_from_start_index) { |
| 181 | // robin hood to the rescue | 181 | // robin hood to the rescue |
| 182 | const tmp = *entry; | 182 | const tmp = *entry; |
| 183 | hm.max_distance_from_start_index = math.max(isize, | 183 | hm.max_distance_from_start_index = math.max(usize, |
| 184 | hm.max_distance_from_start_index, distance_from_start_index); | 184 | hm.max_distance_from_start_index, distance_from_start_index); |
| 185 | *entry = Entry { | 185 | *entry = Entry { |
| 186 | .used = true, | 186 | .used = true, |
| ... | @@ -201,7 +201,7 @@ pub struct SmallHashMap(K: type, V: type, hash: fn(key: K)->u32, eql: fn(a: K, b | ... | @@ -201,7 +201,7 @@ pub struct SmallHashMap(K: type, V: type, hash: fn(key: K)->u32, eql: fn(a: K, b |
| 201 | hm.size += 1; | 201 | hm.size += 1; |
| 202 | } | 202 | } |
| 203 | 203 | ||
| 204 | hm.max_distance_from_start_index = math.max(isize, distance_from_start_index, | 204 | hm.max_distance_from_start_index = math.max(usize, distance_from_start_index, |
| 205 | hm.max_distance_from_start_index); | 205 | hm.max_distance_from_start_index); |
| 206 | *entry = Entry { | 206 | *entry = Entry { |
| 207 | .used = true, | 207 | .used = true, |
| ... | @@ -216,7 +216,7 @@ pub struct SmallHashMap(K: type, V: type, hash: fn(key: K)->u32, eql: fn(a: K, b | ... | @@ -216,7 +216,7 @@ pub struct SmallHashMap(K: type, V: type, hash: fn(key: K)->u32, eql: fn(a: K, b |
| 216 | 216 | ||
| 217 | fn internal_get(hm: &Self, key: K) -> ?&Entry { | 217 | fn internal_get(hm: &Self, key: K) -> ?&Entry { |
| 218 | const start_index = hm.key_to_index(key); | 218 | const start_index = hm.key_to_index(key); |
| 219 | {var roll_over: isize = 0; while (roll_over <= hm.max_distance_from_start_index; roll_over += 1) { | 219 | {var roll_over: usize = 0; while (roll_over <= hm.max_distance_from_start_index; roll_over += 1) { |
| 220 | const index = (start_index + roll_over) % hm.entries.len; | 220 | const index = (start_index + roll_over) % hm.entries.len; |
| 221 | const entry = &hm.entries[index]; | 221 | const entry = &hm.entries[index]; |
| 222 | 222 | ||
| ... | @@ -226,8 +226,8 @@ pub struct SmallHashMap(K: type, V: type, hash: fn(key: K)->u32, eql: fn(a: K, b | ... | @@ -226,8 +226,8 @@ pub struct SmallHashMap(K: type, V: type, hash: fn(key: K)->u32, eql: fn(a: K, b |
| 226 | return null; | 226 | return null; |
| 227 | } | 227 | } |
| 228 | 228 | ||
| 229 | fn key_to_index(hm: &Self, key: K) -> isize { | 229 | fn key_to_index(hm: &Self, key: K) -> usize { |
| 230 | return isize(hash(key)) % hm.entries.len; | 230 | return usize(hash(key)) % hm.entries.len; |
| 231 | } | 231 | } |
| 232 | } | 232 | } |
| 233 | 233 | ||
| ... | @@ -239,15 +239,15 @@ var global_allocator = Allocator { | ... | @@ -239,15 +239,15 @@ var global_allocator = Allocator { |
| 239 | }; | 239 | }; |
| 240 | 240 | ||
| 241 | var some_mem: [200]u8 = undefined; | 241 | var some_mem: [200]u8 = undefined; |
| 242 | var some_mem_index: isize = 0; | 242 | var some_mem_index: usize = 0; |
| 243 | 243 | ||
| 244 | fn global_alloc(self: &Allocator, n: isize) -> %[]u8 { | 244 | fn global_alloc(self: &Allocator, n: usize) -> %[]u8 { |
| 245 | const result = some_mem[some_mem_index ... some_mem_index + n]; | 245 | const result = some_mem[some_mem_index ... some_mem_index + n]; |
| 246 | some_mem_index += n; | 246 | some_mem_index += n; |
| 247 | return result; | 247 | return result; |
| 248 | } | 248 | } |
| 249 | 249 | ||
| 250 | fn global_realloc(self: &Allocator, old_mem: []u8, new_size: isize) -> %[]u8 { | 250 | fn global_realloc(self: &Allocator, old_mem: []u8, new_size: usize) -> %[]u8 { |
| 251 | const result = %return global_alloc(self, new_size); | 251 | const result = %return global_alloc(self, new_size); |
| 252 | @memcpy(result.ptr, old_mem.ptr, old_mem.len); | 252 | @memcpy(result.ptr, old_mem.ptr, old_mem.len); |
| 253 | return result; | 253 | return result; |
std/io.zig+31-161| ... | @@ -59,9 +59,9 @@ pub const OpenCreate = 0b0100; | ... | @@ -59,9 +59,9 @@ pub const OpenCreate = 0b0100; |
| 59 | pub const OpenTruncate = 0b1000; | 59 | pub const OpenTruncate = 0b1000; |
| 60 | 60 | ||
| 61 | pub struct OutStream { | 61 | pub struct OutStream { |
| 62 | fd: isize, | 62 | fd: i32, |
| 63 | buffer: [buffer_size]u8, | 63 | buffer: [buffer_size]u8, |
| 64 | index: isize, | 64 | index: usize, |
| 65 | 65 | ||
| 66 | pub fn write_byte(os: &OutStream, b: u8) -> %void { | 66 | pub fn write_byte(os: &OutStream, b: u8) -> %void { |
| 67 | if (os.buffer.len == os.index) %return os.flush(); | 67 | if (os.buffer.len == os.index) %return os.flush(); |
| ... | @@ -69,13 +69,13 @@ pub struct OutStream { | ... | @@ -69,13 +69,13 @@ pub struct OutStream { |
| 69 | os.index += 1; | 69 | os.index += 1; |
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | pub fn write(os: &OutStream, bytes: []const u8) -> %isize { | 72 | pub fn write(os: &OutStream, bytes: []const u8) -> %usize { |
| 73 | var src_bytes_left = bytes.len; | 73 | var src_bytes_left = bytes.len; |
| 74 | var src_index: @typeof(bytes.len) = 0; | 74 | var src_index: @typeof(bytes.len) = 0; |
| 75 | const dest_space_left = os.buffer.len - os.index; | 75 | const dest_space_left = os.buffer.len - os.index; |
| 76 | 76 | ||
| 77 | while (src_bytes_left > 0) { | 77 | while (src_bytes_left > 0) { |
| 78 | const copy_amt = math.min(isize, dest_space_left, src_bytes_left); | 78 | const copy_amt = math.min(usize, dest_space_left, src_bytes_left); |
| 79 | @memcpy(&os.buffer[os.index], &bytes[src_index], copy_amt); | 79 | @memcpy(&os.buffer[os.index], &bytes[src_index], copy_amt); |
| 80 | os.index += copy_amt; | 80 | os.index += copy_amt; |
| 81 | if (os.index == os.buffer.len) { | 81 | if (os.index == os.buffer.len) { |
| ... | @@ -88,13 +88,13 @@ pub struct OutStream { | ... | @@ -88,13 +88,13 @@ pub struct OutStream { |
| 88 | 88 | ||
| 89 | /// Prints a byte buffer, flushes the buffer, then returns the number of | 89 | /// Prints a byte buffer, flushes the buffer, then returns the number of |
| 90 | /// bytes printed. The "f" is for "flush". | 90 | /// bytes printed. The "f" is for "flush". |
| 91 | pub fn printf(os: &OutStream, str: []const u8) -> %isize { | 91 | pub fn printf(os: &OutStream, str: []const u8) -> %usize { |
| 92 | const byte_count = %return os.write(str); | 92 | const byte_count = %return os.write(str); |
| 93 | %return os.flush(); | 93 | %return os.flush(); |
| 94 | return byte_count; | 94 | return byte_count; |
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | pub fn print_u64(os: &OutStream, x: u64) -> %isize { | 97 | pub fn print_u64(os: &OutStream, x: u64) -> %usize { |
| 98 | if (os.index + max_u64_base10_digits >= os.buffer.len) { | 98 | if (os.index + max_u64_base10_digits >= os.buffer.len) { |
| 99 | %return os.flush(); | 99 | %return os.flush(); |
| 100 | } | 100 | } |
| ... | @@ -104,7 +104,7 @@ pub struct OutStream { | ... | @@ -104,7 +104,7 @@ pub struct OutStream { |
| 104 | return amt_printed; | 104 | return amt_printed; |
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | pub fn print_i64(os: &OutStream, x: i64) -> %isize { | 107 | pub fn print_i64(os: &OutStream, x: i64) -> %usize { |
| 108 | if (os.index + max_u64_base10_digits >= os.buffer.len) { | 108 | if (os.index + max_u64_base10_digits >= os.buffer.len) { |
| 109 | %return os.flush(); | 109 | %return os.flush(); |
| 110 | } | 110 | } |
| ... | @@ -114,16 +114,6 @@ pub struct OutStream { | ... | @@ -114,16 +114,6 @@ pub struct OutStream { |
| 114 | return amt_printed; | 114 | return amt_printed; |
| 115 | } | 115 | } |
| 116 | 116 | ||
| 117 | pub fn print_f64(os: &OutStream, x: f64) -> %isize { | ||
| 118 | if (os.index + max_f64_digits >= os.buffer.len) { | ||
| 119 | %return os.flush(); | ||
| 120 | } | ||
| 121 | const amt_printed = buf_print_f64(os.buffer[os.index...], x, 4); | ||
| 122 | os.index += amt_printed; | ||
| 123 | |||
| 124 | return amt_printed; | ||
| 125 | } | ||
| 126 | |||
| 127 | pub fn flush(os: &OutStream) -> %void { | 117 | pub fn flush(os: &OutStream) -> %void { |
| 128 | const write_ret = linux.write(os.fd, &os.buffer[0], os.index); | 118 | const write_ret = linux.write(os.fd, &os.buffer[0], os.index); |
| 129 | const write_err = linux.get_errno(write_ret); | 119 | const write_err = linux.get_errno(write_ret); |
| ... | @@ -144,25 +134,27 @@ pub struct OutStream { | ... | @@ -144,25 +134,27 @@ pub struct OutStream { |
| 144 | } | 134 | } |
| 145 | 135 | ||
| 146 | pub fn close(os: &OutStream) -> %void { | 136 | pub fn close(os: &OutStream) -> %void { |
| 147 | const closed = linux.close(os.fd); | 137 | const close_ret = linux.close(os.fd); |
| 148 | if (closed < 0) { | 138 | const close_err = linux.get_errno(close_ret); |
| 149 | return switch (-closed) { | 139 | if (close_err > 0) { |
| 150 | errno.EIO => error.Io, | 140 | return switch (close_err) { |
| 141 | errno.EIO => error.Io, | ||
| 151 | errno.EBADF => error.BadFd, | 142 | errno.EBADF => error.BadFd, |
| 152 | errno.EINTR => error.SigInterrupt, | 143 | errno.EINTR => error.SigInterrupt, |
| 153 | else => error.Unexpected, | 144 | else => error.Unexpected, |
| 154 | } | 145 | } |
| 155 | } | 146 | } |
| 156 | } | 147 | } |
| 157 | } | 148 | } |
| 158 | 149 | ||
| 159 | pub struct InStream { | 150 | pub struct InStream { |
| 160 | fd: isize, | 151 | fd: i32, |
| 161 | 152 | ||
| 162 | pub fn open(path: []u8) -> %InStream { | 153 | pub fn open(path: []u8) -> %InStream { |
| 163 | const fd = linux.open(path, linux.O_LARGEFILE|linux.O_RDONLY, 0); | 154 | const fd = linux.open(path, linux.O_LARGEFILE|linux.O_RDONLY, 0); |
| 164 | if (fd < 0) { | 155 | const fd_err = linux.get_errno(fd); |
| 165 | return switch (-fd) { | 156 | if (fd_err > 0) { |
| 157 | return switch (fd_err) { | ||
| 166 | errno.EFAULT => unreachable{}, | 158 | errno.EFAULT => unreachable{}, |
| 167 | errno.EINVAL => unreachable{}, | 159 | errno.EINVAL => unreachable{}, |
| 168 | errno.EACCES => error.BadPerm, | 160 | errno.EACCES => error.BadPerm, |
| ... | @@ -183,13 +175,14 @@ pub struct InStream { | ... | @@ -183,13 +175,14 @@ pub struct InStream { |
| 183 | } | 175 | } |
| 184 | } | 176 | } |
| 185 | 177 | ||
| 186 | return InStream { .fd = fd, }; | 178 | return InStream { .fd = i32(fd), }; |
| 187 | } | 179 | } |
| 188 | 180 | ||
| 189 | pub fn read(is: &InStream, buf: []u8) -> %isize { | 181 | pub fn read(is: &InStream, buf: []u8) -> %usize { |
| 190 | const amt_read = linux.read(is.fd, &buf[0], buf.len); | 182 | const amt_read = linux.read(is.fd, &buf[0], buf.len); |
| 191 | if (amt_read < 0) { | 183 | const read_err = linux.get_errno(amt_read); |
| 192 | return switch (-amt_read) { | 184 | if (read_err > 0) { |
| 185 | return switch (read_err) { | ||
| 193 | errno.EINVAL => unreachable{}, | 186 | errno.EINVAL => unreachable{}, |
| 194 | errno.EFAULT => unreachable{}, | 187 | errno.EFAULT => unreachable{}, |
| 195 | errno.EBADF => error.BadFd, | 188 | errno.EBADF => error.BadFd, |
| ... | @@ -202,9 +195,10 @@ pub struct InStream { | ... | @@ -202,9 +195,10 @@ pub struct InStream { |
| 202 | } | 195 | } |
| 203 | 196 | ||
| 204 | pub fn close(is: &InStream) -> %void { | 197 | pub fn close(is: &InStream) -> %void { |
| 205 | const closed = linux.close(is.fd); | 198 | const close_ret = linux.close(is.fd); |
| 206 | if (closed < 0) { | 199 | const close_err = linux.get_errno(close_ret); |
| 207 | return switch (-closed) { | 200 | if (close_err > 0) { |
| 201 | return switch (close_err) { | ||
| 208 | errno.EIO => error.Io, | 202 | errno.EIO => error.Io, |
| 209 | errno.EBADF => error.BadFd, | 203 | errno.EBADF => error.BadFd, |
| 210 | errno.EINTR => error.SigInterrupt, | 204 | errno.EINTR => error.SigInterrupt, |
| ... | @@ -240,7 +234,7 @@ fn char_to_digit(c: u8, radix: u8) -> %u8 { | ... | @@ -240,7 +234,7 @@ fn char_to_digit(c: u8, radix: u8) -> %u8 { |
| 240 | return if (value >= radix) error.InvalidChar else value; | 234 | return if (value >= radix) error.InvalidChar else value; |
| 241 | } | 235 | } |
| 242 | 236 | ||
| 243 | pub fn buf_print_signed(inline T: type, out_buf: []u8, x: T) -> isize { | 237 | pub fn buf_print_signed(inline T: type, out_buf: []u8, x: T) -> usize { |
| 244 | const uint = @int_type(false, T.bit_count, false); | 238 | const uint = @int_type(false, T.bit_count, false); |
| 245 | if (x < 0) { | 239 | if (x < 0) { |
| 246 | out_buf[0] = '-'; | 240 | out_buf[0] = '-'; |
| ... | @@ -250,14 +244,14 @@ pub fn buf_print_signed(inline T: type, out_buf: []u8, x: T) -> isize { | ... | @@ -250,14 +244,14 @@ pub fn buf_print_signed(inline T: type, out_buf: []u8, x: T) -> isize { |
| 250 | } | 244 | } |
| 251 | } | 245 | } |
| 252 | 246 | ||
| 253 | pub fn buf_print_i64(out_buf: []u8, x: i64) -> isize { | 247 | pub fn buf_print_i64(out_buf: []u8, x: i64) -> usize { |
| 254 | buf_print_signed(i64, out_buf, x) | 248 | buf_print_signed(i64, out_buf, x) |
| 255 | } | 249 | } |
| 256 | 250 | ||
| 257 | pub fn buf_print_unsigned(inline T: type, out_buf: []u8, x: T) -> isize { | 251 | pub fn buf_print_unsigned(inline T: type, out_buf: []u8, x: T) -> usize { |
| 258 | var buf: [max_u64_base10_digits]u8 = undefined; | 252 | var buf: [max_u64_base10_digits]u8 = undefined; |
| 259 | var a = x; | 253 | var a = x; |
| 260 | var index: isize = buf.len; | 254 | var index: usize = buf.len; |
| 261 | 255 | ||
| 262 | while (true) { | 256 | while (true) { |
| 263 | const digit = a % 10; | 257 | const digit = a % 10; |
| ... | @@ -275,134 +269,10 @@ pub fn buf_print_unsigned(inline T: type, out_buf: []u8, x: T) -> isize { | ... | @@ -275,134 +269,10 @@ pub fn buf_print_unsigned(inline T: type, out_buf: []u8, x: T) -> isize { |
| 275 | return len; | 269 | return len; |
| 276 | } | 270 | } |
| 277 | 271 | ||
| 278 | pub fn buf_print_u64(out_buf: []u8, x: u64) -> isize { | 272 | pub fn buf_print_u64(out_buf: []u8, x: u64) -> usize { |
| 279 | buf_print_unsigned(u64, out_buf, x) | 273 | buf_print_unsigned(u64, out_buf, x) |
| 280 | } | 274 | } |
| 281 | 275 | ||
| 282 | pub fn buf_print_f64(out_buf: []u8, x: f64, decimals: isize) -> isize { | ||
| 283 | const numExpBits = 11; | ||
| 284 | const numRawSigBits = 52; // not including implicit 1 bit | ||
| 285 | const expBias = 1023; | ||
| 286 | |||
| 287 | var decs = decimals; | ||
| 288 | if (decs >= max_u64_base10_digits) { | ||
| 289 | decs = max_u64_base10_digits - 1; | ||
| 290 | } | ||
| 291 | |||
| 292 | if (x == math.f64_get_pos_inf()) { | ||
| 293 | const buf2 = "+Inf"; | ||
| 294 | @memcpy(&out_buf[0], &buf2[0], buf2.len); | ||
| 295 | return 4; | ||
| 296 | } else if (x == math.f64_get_neg_inf()) { | ||
| 297 | const buf2 = "-Inf"; | ||
| 298 | @memcpy(&out_buf[0], &buf2[0], buf2.len); | ||
| 299 | return 4; | ||
| 300 | } else if (math.f64_is_nan(x)) { | ||
| 301 | const buf2 = "NaN"; | ||
| 302 | @memcpy(&out_buf[0], &buf2[0], buf2.len); | ||
| 303 | return 3; | ||
| 304 | } | ||
| 305 | |||
| 306 | var buf: [max_f64_digits]u8 = undefined; | ||
| 307 | |||
| 308 | var len: isize = 0; | ||
| 309 | |||
| 310 | // 1 sign bit | ||
| 311 | // 11 exponent bits | ||
| 312 | // 52 significand bits (+ 1 implicit always non-zero bit) | ||
| 313 | |||
| 314 | const bits = math.f64_to_bits(x); | ||
| 315 | if (bits & (1 << 63) != 0) { | ||
| 316 | buf[0] = '-'; | ||
| 317 | len += 1; | ||
| 318 | } | ||
| 319 | |||
| 320 | const rexponent: i64 = i64((bits >> numRawSigBits) & ((1 << numExpBits) - 1)); | ||
| 321 | const exponent = rexponent - expBias - numRawSigBits; | ||
| 322 | |||
| 323 | if (rexponent == 0) { | ||
| 324 | buf[len] = '0'; | ||
| 325 | len += 1; | ||
| 326 | @memcpy(&out_buf[0], &buf[0], len); | ||
| 327 | return len; | ||
| 328 | } | ||
| 329 | |||
| 330 | const sig = (bits & ((1 << numRawSigBits) - 1)) | (1 << numRawSigBits); | ||
| 331 | |||
| 332 | if (exponent >= 0) { | ||
| 333 | // number is an integer | ||
| 334 | |||
| 335 | if (exponent >= 64 - 53) { | ||
| 336 | // use XeX form | ||
| 337 | |||
| 338 | // TODO support printing large floats | ||
| 339 | //len += buf_print_u64(buf[len...], sig << 10); | ||
| 340 | const str = "LARGEF64"; | ||
| 341 | @memcpy(&buf[len], &str[0], str.len); | ||
| 342 | len += str.len; | ||
| 343 | } else { | ||
| 344 | // use typical form | ||
| 345 | |||
| 346 | len += buf_print_u64(buf[len...], sig << u64(exponent)); | ||
| 347 | buf[len] = '.'; | ||
| 348 | len += 1; | ||
| 349 | |||
| 350 | var i: isize = 0; | ||
| 351 | while (i < decs) { | ||
| 352 | buf[len] = '0'; | ||
| 353 | len += 1; | ||
| 354 | i += 1; | ||
| 355 | } | ||
| 356 | } | ||
| 357 | } else { | ||
| 358 | // number is not an integer | ||
| 359 | |||
| 360 | // print out whole part | ||
| 361 | len += buf_print_u64(buf[len...], sig >> u64(-exponent)); | ||
| 362 | buf[len] = '.'; | ||
| 363 | len += 1; | ||
| 364 | |||
| 365 | // print out fractional part | ||
| 366 | // dec_num holds: fractional part * 10 ^ decs | ||
| 367 | var dec_num: u64 = 0; | ||
| 368 | |||
| 369 | var a: isize = 1; | ||
| 370 | var i: isize = 0; | ||
| 371 | while (i < decs + 5) { | ||
| 372 | a *= 10; | ||
| 373 | i += 1; | ||
| 374 | } | ||
| 375 | |||
| 376 | // create a mask: 1's for the fractional part, 0's for whole part | ||
| 377 | var masked_sig = sig & ((1 << u64(-exponent)) - 1); | ||
| 378 | i = -1; | ||
| 379 | while (i >= exponent) { | ||
| 380 | var bit_set = ((1 << u64(i-exponent)) & masked_sig) != 0; | ||
| 381 | |||
| 382 | if (bit_set) { | ||
| 383 | dec_num += usize(a) >> usize(-i); | ||
| 384 | } | ||
| 385 | |||
| 386 | i -= 1; | ||
| 387 | } | ||
| 388 | |||
| 389 | dec_num /= 100000; | ||
| 390 | |||
| 391 | len += decs; | ||
| 392 | |||
| 393 | i = len - 1; | ||
| 394 | while (i >= len - decs) { | ||
| 395 | buf[i] = '0' + u8(dec_num % 10); | ||
| 396 | dec_num /= 10; | ||
| 397 | i -= 1; | ||
| 398 | } | ||
| 399 | } | ||
| 400 | |||
| 401 | @memcpy(&out_buf[0], &buf[0], len); | ||
| 402 | |||
| 403 | len | ||
| 404 | } | ||
| 405 | |||
| 406 | #attribute("test") | 276 | #attribute("test") |
| 407 | fn parse_u64_digit_too_big() { | 277 | fn parse_u64_digit_too_big() { |
| 408 | parse_unsigned(u64, "123a", 10) %% |err| { | 278 | parse_unsigned(u64, "123a", 10) %% |err| { |
std/linux.zig+89-90| ... | @@ -221,66 +221,67 @@ pub const AF_VSOCK = PF_VSOCK; | ... | @@ -221,66 +221,67 @@ pub const AF_VSOCK = PF_VSOCK; |
| 221 | pub const AF_MAX = PF_MAX; | 221 | pub const AF_MAX = PF_MAX; |
| 222 | 222 | ||
| 223 | /// Get the errno from a syscall return value, or 0 for no error. | 223 | /// Get the errno from a syscall return value, or 0 for no error. |
| 224 | pub fn get_errno(r: isize) -> isize { | 224 | pub fn get_errno(r: usize) -> usize { |
| 225 | if (r > -4096 && r < 0) -r else 0 | 225 | const signed_r = *(&isize)(&r); |
| 226 | if (signed_r > -4096 && signed_r < 0) usize(-signed_r) else 0 | ||
| 226 | } | 227 | } |
| 227 | 228 | ||
| 228 | pub fn mmap(address: ?&u8, length: isize, prot: isize, flags: isize, fd: isize, offset: isize) -> isize { | 229 | pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, offset: usize) -> usize { |
| 229 | arch.syscall6(arch.SYS_mmap, isize(address), length, prot, flags, fd, offset) | 230 | arch.syscall6(arch.SYS_mmap, usize(address), length, prot, flags, usize(fd), offset) |
| 230 | } | 231 | } |
| 231 | 232 | ||
| 232 | pub fn munmap(address: &u8, length: isize) -> isize { | 233 | pub fn munmap(address: &u8, length: usize) -> usize { |
| 233 | arch.syscall2(arch.SYS_munmap, isize(address), length) | 234 | arch.syscall2(arch.SYS_munmap, usize(address), length) |
| 234 | } | 235 | } |
| 235 | 236 | ||
| 236 | pub fn read(fd: isize, buf: &u8, count: isize) -> isize { | 237 | pub fn read(fd: i32, buf: &u8, count: usize) -> usize { |
| 237 | arch.syscall3(arch.SYS_read, isize(fd), isize(buf), count) | 238 | arch.syscall3(arch.SYS_read, usize(fd), usize(buf), count) |
| 238 | } | 239 | } |
| 239 | 240 | ||
| 240 | pub fn write(fd: isize, buf: &const u8, count: isize) -> isize { | 241 | pub fn write(fd: i32, buf: &const u8, count: usize) -> usize { |
| 241 | arch.syscall3(arch.SYS_write, isize(fd), isize(buf), count) | 242 | arch.syscall3(arch.SYS_write, usize(fd), usize(buf), count) |
| 242 | } | 243 | } |
| 243 | 244 | ||
| 244 | pub fn open(path: []u8, flags: isize, perm: isize) -> isize { | 245 | pub fn open(path: []u8, flags: usize, perm: usize) -> usize { |
| 245 | var buf: [path.len + 1]u8 = undefined; | 246 | var buf: [path.len + 1]u8 = undefined; |
| 246 | @memcpy(&buf[0], &path[0], path.len); | 247 | @memcpy(&buf[0], &path[0], path.len); |
| 247 | buf[path.len] = 0; | 248 | buf[path.len] = 0; |
| 248 | arch.syscall3(arch.SYS_open, isize(&buf[0]), flags, perm) | 249 | arch.syscall3(arch.SYS_open, usize(&buf[0]), flags, perm) |
| 249 | } | 250 | } |
| 250 | 251 | ||
| 251 | pub fn create(path: []u8, perm: isize) -> isize { | 252 | pub fn create(path: []u8, perm: usize) -> usize { |
| 252 | var buf: [path.len + 1]u8 = undefined; | 253 | var buf: [path.len + 1]u8 = undefined; |
| 253 | @memcpy(&buf[0], &path[0], path.len); | 254 | @memcpy(&buf[0], &path[0], path.len); |
| 254 | buf[path.len] = 0; | 255 | buf[path.len] = 0; |
| 255 | arch.syscall2(arch.SYS_creat, isize(&buf[0]), perm) | 256 | arch.syscall2(arch.SYS_creat, usize(&buf[0]), perm) |
| 256 | } | 257 | } |
| 257 | 258 | ||
| 258 | pub fn openat(dirfd: isize, path: []u8, flags: isize, mode: isize) -> isize { | 259 | pub fn openat(dirfd: i32, path: []u8, flags: usize, mode: usize) -> usize { |
| 259 | var buf: [path.len + 1]u8 = undefined; | 260 | var buf: [path.len + 1]u8 = undefined; |
| 260 | @memcpy(&buf[0], &path[0], path.len); | 261 | @memcpy(&buf[0], &path[0], path.len); |
| 261 | buf[path.len] = 0; | 262 | buf[path.len] = 0; |
| 262 | arch.syscall4(arch.SYS_openat, dirfd, isize(&buf[0]), flags, mode) | 263 | arch.syscall4(arch.SYS_openat, usize(dirfd), usize(&buf[0]), flags, mode) |
| 263 | } | 264 | } |
| 264 | 265 | ||
| 265 | pub fn close(fd: isize) -> isize { | 266 | pub fn close(fd: i32) -> usize { |
| 266 | arch.syscall1(arch.SYS_close, fd) | 267 | arch.syscall1(arch.SYS_close, usize(fd)) |
| 267 | } | 268 | } |
| 268 | 269 | ||
| 269 | pub fn lseek(fd: isize, offset: isize, ref_pos: isize) -> isize { | 270 | pub fn lseek(fd: i32, offset: usize, ref_pos: usize) -> usize { |
| 270 | arch.syscall3(arch.SYS_lseek, fd, offset, ref_pos) | 271 | arch.syscall3(arch.SYS_lseek, usize(fd), offset, ref_pos) |
| 271 | } | 272 | } |
| 272 | 273 | ||
| 273 | pub fn exit(status: i32) -> unreachable { | 274 | pub fn exit(status: i32) -> unreachable { |
| 274 | arch.syscall1(arch.SYS_exit, isize(status)); | 275 | arch.syscall1(arch.SYS_exit, usize(status)); |
| 275 | unreachable{} | 276 | unreachable{} |
| 276 | } | 277 | } |
| 277 | 278 | ||
| 278 | pub fn getrandom(buf: &u8, count: isize, flags: u32) -> isize { | 279 | pub fn getrandom(buf: &u8, count: usize, flags: u32) -> usize { |
| 279 | arch.syscall3(arch.SYS_getrandom, isize(buf), count, isize(flags)) | 280 | arch.syscall3(arch.SYS_getrandom, usize(buf), count, usize(flags)) |
| 280 | } | 281 | } |
| 281 | 282 | ||
| 282 | pub fn kill(pid: i32, sig: i32) -> i32 { | 283 | pub fn kill(pid: i32, sig: i32) -> i32 { |
| 283 | i32(arch.syscall2(arch.SYS_kill, pid, sig)) | 284 | i32(arch.syscall2(arch.SYS_kill, usize(pid), usize(sig))) |
| 284 | } | 285 | } |
| 285 | 286 | ||
| 286 | const NSIG = 65; | 287 | const NSIG = 65; |
| ... | @@ -292,21 +293,21 @@ pub fn raise(sig: i32) -> i32 { | ... | @@ -292,21 +293,21 @@ pub fn raise(sig: i32) -> i32 { |
| 292 | var set: sigset_t = undefined; | 293 | var set: sigset_t = undefined; |
| 293 | block_app_signals(&set); | 294 | block_app_signals(&set); |
| 294 | const tid = i32(arch.syscall0(arch.SYS_gettid)); | 295 | const tid = i32(arch.syscall0(arch.SYS_gettid)); |
| 295 | const ret = i32(arch.syscall2(arch.SYS_tkill, tid, sig)); | 296 | const ret = i32(arch.syscall2(arch.SYS_tkill, usize(tid), usize(sig))); |
| 296 | restore_signals(&set); | 297 | restore_signals(&set); |
| 297 | return ret; | 298 | return ret; |
| 298 | } | 299 | } |
| 299 | 300 | ||
| 300 | fn block_all_signals(set: &sigset_t) { | 301 | fn block_all_signals(set: &sigset_t) { |
| 301 | arch.syscall4(arch.SYS_rt_sigprocmask, SIG_BLOCK, isize(&all_mask), isize(set), NSIG/8); | 302 | arch.syscall4(arch.SYS_rt_sigprocmask, SIG_BLOCK, usize(&all_mask), usize(set), NSIG/8); |
| 302 | } | 303 | } |
| 303 | 304 | ||
| 304 | fn block_app_signals(set: &sigset_t) { | 305 | fn block_app_signals(set: &sigset_t) { |
| 305 | arch.syscall4(arch.SYS_rt_sigprocmask, SIG_BLOCK, isize(&app_mask), isize(set), NSIG/8); | 306 | arch.syscall4(arch.SYS_rt_sigprocmask, SIG_BLOCK, usize(&app_mask), usize(set), NSIG/8); |
| 306 | } | 307 | } |
| 307 | 308 | ||
| 308 | fn restore_signals(set: &sigset_t) { | 309 | fn restore_signals(set: &sigset_t) { |
| 309 | arch.syscall4(arch.SYS_rt_sigprocmask, SIG_SETMASK, isize(set), 0, NSIG/8); | 310 | arch.syscall4(arch.SYS_rt_sigprocmask, SIG_SETMASK, usize(set), 0, NSIG/8); |
| 310 | } | 311 | } |
| 311 | 312 | ||
| 312 | 313 | ||
| ... | @@ -363,98 +364,96 @@ export struct ifreq { | ... | @@ -363,98 +364,96 @@ export struct ifreq { |
| 363 | } | 364 | } |
| 364 | */ | 365 | */ |
| 365 | 366 | ||
| 366 | pub fn getsockname(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> isize { | 367 | pub fn getsockname(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize { |
| 367 | arch.syscall3(arch.SYS_getsockname, fd, isize(addr), isize(len)) | 368 | arch.syscall3(arch.SYS_getsockname, usize(fd), usize(addr), usize(len)) |
| 368 | } | 369 | } |
| 369 | 370 | ||
| 370 | pub fn getpeername(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> isize { | 371 | pub fn getpeername(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize { |
| 371 | arch.syscall3(arch.SYS_getpeername, fd, isize(addr), isize(len)) | 372 | arch.syscall3(arch.SYS_getpeername, usize(fd), usize(addr), usize(len)) |
| 372 | } | 373 | } |
| 373 | 374 | ||
| 374 | pub fn socket(domain: i32, socket_type: i32, protocol: i32) -> isize { | 375 | pub fn socket(domain: i32, socket_type: i32, protocol: i32) -> usize { |
| 375 | arch.syscall3(arch.SYS_socket, domain, socket_type, protocol) | 376 | arch.syscall3(arch.SYS_socket, usize(domain), usize(socket_type), usize(protocol)) |
| 376 | } | 377 | } |
| 377 | 378 | ||
| 378 | pub fn setsockopt(fd: i32, level: i32, optname: i32, optval: &const u8, optlen: socklen_t) -> isize { | 379 | pub fn setsockopt(fd: i32, level: i32, optname: i32, optval: &const u8, optlen: socklen_t) -> usize { |
| 379 | arch.syscall5(arch.SYS_setsockopt, fd, level, optname, isize(optval), isize(optlen)) | 380 | arch.syscall5(arch.SYS_setsockopt, usize(fd), usize(level), usize(optname), usize(optval), usize(optlen)) |
| 380 | } | 381 | } |
| 381 | 382 | ||
| 382 | pub fn getsockopt(fd: i32, level: i32, optname: i32, noalias optval: &u8, noalias optlen: &socklen_t) -> isize { | 383 | pub fn getsockopt(fd: i32, level: i32, optname: i32, noalias optval: &u8, noalias optlen: &socklen_t) -> usize { |
| 383 | arch.syscall5(arch.SYS_getsockopt, fd, level, optname, isize(optval), isize(optlen)) | 384 | arch.syscall5(arch.SYS_getsockopt, usize(fd), usize(level), usize(optname), usize(optval), usize(optlen)) |
| 384 | } | 385 | } |
| 385 | 386 | ||
| 386 | pub fn sendmsg(fd: i32, msg: &const arch.msghdr, flags: i32) -> isize { | 387 | pub fn sendmsg(fd: i32, msg: &const arch.msghdr, flags: u32) -> usize { |
| 387 | arch.syscall3(arch.SYS_sendmsg, fd, isize(msg), flags) | 388 | arch.syscall3(arch.SYS_sendmsg, usize(fd), usize(msg), flags) |
| 388 | } | 389 | } |
| 389 | 390 | ||
| 390 | pub fn connect(fd: i32, addr: &const sockaddr, len: socklen_t) -> isize { | 391 | pub fn connect(fd: i32, addr: &const sockaddr, len: socklen_t) -> usize { |
| 391 | arch.syscall3(arch.SYS_connect, fd, isize(addr), isize(len)) | 392 | arch.syscall3(arch.SYS_connect, usize(fd), usize(addr), usize(len)) |
| 392 | } | 393 | } |
| 393 | 394 | ||
| 394 | pub fn recvmsg(fd: i32, msg: &arch.msghdr, flags: i32) -> isize { | 395 | pub fn recvmsg(fd: i32, msg: &arch.msghdr, flags: u32) -> usize { |
| 395 | arch.syscall3(arch.SYS_recvmsg, fd, isize(msg), flags) | 396 | arch.syscall3(arch.SYS_recvmsg, usize(fd), usize(msg), flags) |
| 396 | } | 397 | } |
| 397 | 398 | ||
| 398 | pub fn recvfrom(fd: i32, noalias buf: &u8, len: isize, flags: i32, | 399 | pub fn recvfrom(fd: i32, noalias buf: &u8, len: usize, flags: u32, |
| 399 | noalias addr: ?&sockaddr, noalias alen: ?&socklen_t) -> isize | 400 | noalias addr: ?&sockaddr, noalias alen: ?&socklen_t) -> usize |
| 400 | { | 401 | { |
| 401 | arch.syscall6(arch.SYS_recvfrom, fd, isize(buf), len, flags, isize(addr), isize(alen)) | 402 | arch.syscall6(arch.SYS_recvfrom, usize(fd), usize(buf), len, flags, usize(addr), usize(alen)) |
| 402 | } | 403 | } |
| 403 | 404 | ||
| 404 | pub fn shutdown(fd: i32, how: i32) -> isize { | 405 | pub fn shutdown(fd: i32, how: i32) -> usize { |
| 405 | arch.syscall2(arch.SYS_shutdown, fd, how) | 406 | arch.syscall2(arch.SYS_shutdown, usize(fd), usize(how)) |
| 406 | } | 407 | } |
| 407 | 408 | ||
| 408 | pub fn bind(fd: i32, addr: &const sockaddr, len: socklen_t) { | 409 | pub fn bind(fd: i32, addr: &const sockaddr, len: socklen_t) { |
| 409 | arch.syscall3(arch.SYS_bind, fd, isize(addr), isize(len)); | 410 | arch.syscall3(arch.SYS_bind, usize(fd), usize(addr), usize(len)); |
| 410 | } | 411 | } |
| 411 | 412 | ||
| 412 | pub fn listen(fd: i32, backlog: i32) -> isize { | 413 | pub fn listen(fd: i32, backlog: i32) -> usize { |
| 413 | arch.syscall2(arch.SYS_listen, fd, backlog) | 414 | arch.syscall2(arch.SYS_listen, usize(fd), usize(backlog)) |
| 414 | } | 415 | } |
| 415 | 416 | ||
| 416 | pub fn sendto(fd: i32, buf: &const u8, len: isize, flags: i32, addr: ?&const sockaddr, alen: socklen_t) -> isize { | 417 | pub fn sendto(fd: i32, buf: &const u8, len: usize, flags: u32, addr: ?&const sockaddr, alen: socklen_t) -> usize { |
| 417 | arch.syscall6(arch.SYS_sendto, fd, isize(buf), len, flags, isize(addr), isize(alen)) | 418 | arch.syscall6(arch.SYS_sendto, usize(fd), usize(buf), len, flags, usize(addr), usize(alen)) |
| 418 | } | 419 | } |
| 419 | 420 | ||
| 420 | pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) -> isize { | 421 | pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) -> usize { |
| 421 | arch.syscall4(arch.SYS_socketpair, domain, socket_type, protocol, isize(&fd[0])) | 422 | arch.syscall4(arch.SYS_socketpair, usize(domain), usize(socket_type), usize(protocol), usize(&fd[0])) |
| 422 | } | 423 | } |
| 423 | 424 | ||
| 424 | pub fn accept(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> isize { | 425 | pub fn accept(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize { |
| 425 | accept4(fd, addr, len, 0) | 426 | accept4(fd, addr, len, 0) |
| 426 | } | 427 | } |
| 427 | 428 | ||
| 428 | pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags: i32) -> isize { | 429 | pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags: u32) -> usize { |
| 429 | arch.syscall4(arch.SYS_accept4, fd, isize(addr), isize(len), flags) | 430 | arch.syscall4(arch.SYS_accept4, usize(fd), usize(addr), usize(len), flags) |
| 430 | } | 431 | } |
| 431 | 432 | ||
| 432 | /* | 433 | // pub error NameTooLong; |
| 433 | pub error NameTooLong; | 434 | // pub error SystemResources; |
| 434 | pub error SystemResources; | 435 | // pub error Io; |
| 435 | pub error Io; | 436 | // |
| 436 | 437 | // pub fn if_nametoindex(name: []u8) -> %u32 { | |
| 437 | pub fn if_nametoindex(name: []u8) -> %u32 { | 438 | // var ifr: ifreq = undefined; |
| 438 | var ifr: ifreq = undefined; | 439 | // |
| 439 | 440 | // if (name.len >= ifr.ifr_name.len) { | |
| 440 | if (name.len >= ifr.ifr_name.len) { | 441 | // return error.NameTooLong; |
| 441 | return error.NameTooLong; | 442 | // } |
| 442 | } | 443 | // |
| 443 | 444 | // const socket_ret = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0); | |
| 444 | const socket_ret = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0); | 445 | // const socket_err = get_errno(socket_ret); |
| 445 | const socket_err = get_errno(socket_ret); | 446 | // if (socket_err > 0) { |
| 446 | if (socket_err > 0) { | 447 | // return error.SystemResources; |
| 447 | return error.SystemResources; | 448 | // } |
| 448 | } | 449 | // const socket_fd = i32(socket_ret); |
| 449 | const socket_fd = i32(socket_ret); | 450 | // @memcpy(&ifr.ifr_name[0], &name[0], name.len); |
| 450 | @memcpy(&ifr.ifr_name[0], &name[0], name.len); | 451 | // ifr.ifr_name[name.len] = 0; |
| 451 | ifr.ifr_name[name.len] = 0; | 452 | // const ioctl_ret = ioctl(socket_fd, SIOCGIFINDEX, &ifr); |
| 452 | const ioctl_ret = ioctl(socket_fd, SIOCGIFINDEX, &ifr); | 453 | // close(socket_fd); |
| 453 | close(socket_fd); | 454 | // const ioctl_err = get_errno(ioctl_ret); |
| 454 | const ioctl_err = get_errno(ioctl_ret); | 455 | // if (ioctl_err > 0) { |
| 455 | if (ioctl_err > 0) { | 456 | // return error.Io; |
| 456 | return error.Io; | 457 | // } |
| 457 | } | 458 | // return ifr.ifr_ifindex; |
| 458 | return ifr.ifr_ifindex; | 459 | // } |
| 459 | } | ||
| 460 | */ |
std/linux_i386.zig+16-16| ... | @@ -419,39 +419,39 @@ pub const F_GETOWN_EX = 16; | ... | @@ -419,39 +419,39 @@ pub const F_GETOWN_EX = 16; |
| 419 | 419 | ||
| 420 | pub const F_GETOWNER_UIDS = 17; | 420 | pub const F_GETOWNER_UIDS = 17; |
| 421 | 421 | ||
| 422 | pub inline fn syscall0(number: isize) -> isize { | 422 | pub inline fn syscall0(number: usize) -> usize { |
| 423 | asm volatile ("int $0x80" | 423 | asm volatile ("int $0x80" |
| 424 | : [ret] "={eax}" (-> isize) | 424 | : [ret] "={eax}" (-> usize) |
| 425 | : [number] "{eax}" (number)) | 425 | : [number] "{eax}" (number)) |
| 426 | } | 426 | } |
| 427 | 427 | ||
| 428 | pub inline fn syscall1(number: isize, arg1: isize) -> isize { | 428 | pub inline fn syscall1(number: usize, arg1: usize) -> usize { |
| 429 | asm volatile ("int $0x80" | 429 | asm volatile ("int $0x80" |
| 430 | : [ret] "={eax}" (-> isize) | 430 | : [ret] "={eax}" (-> usize) |
| 431 | : [number] "{eax}" (number), | 431 | : [number] "{eax}" (number), |
| 432 | [arg1] "{ebx}" (arg1)) | 432 | [arg1] "{ebx}" (arg1)) |
| 433 | } | 433 | } |
| 434 | 434 | ||
| 435 | pub inline fn syscall2(number: isize, arg1: isize, arg2: isize) -> isize { | 435 | pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize { |
| 436 | asm volatile ("int $0x80" | 436 | asm volatile ("int $0x80" |
| 437 | : [ret] "={eax}" (-> isize) | 437 | : [ret] "={eax}" (-> usize) |
| 438 | : [number] "{eax}" (number), | 438 | : [number] "{eax}" (number), |
| 439 | [arg1] "{ebx}" (arg1), | 439 | [arg1] "{ebx}" (arg1), |
| 440 | [arg2] "{ecx}" (arg2)) | 440 | [arg2] "{ecx}" (arg2)) |
| 441 | } | 441 | } |
| 442 | 442 | ||
| 443 | pub inline fn syscall3(number: isize, arg1: isize, arg2: isize, arg3: isize) -> isize { | 443 | pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize { |
| 444 | asm volatile ("int $0x80" | 444 | asm volatile ("int $0x80" |
| 445 | : [ret] "={eax}" (-> isize) | 445 | : [ret] "={eax}" (-> usize) |
| 446 | : [number] "{eax}" (number), | 446 | : [number] "{eax}" (number), |
| 447 | [arg1] "{ebx}" (arg1), | 447 | [arg1] "{ebx}" (arg1), |
| 448 | [arg2] "{ecx}" (arg2), | 448 | [arg2] "{ecx}" (arg2), |
| 449 | [arg3] "{edx}" (arg3)) | 449 | [arg3] "{edx}" (arg3)) |
| 450 | } | 450 | } |
| 451 | 451 | ||
| 452 | pub inline fn syscall4(number: isize, arg1: isize, arg2: isize, arg3: isize, arg4: isize) -> isize { | 452 | pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) -> usize { |
| 453 | asm volatile ("int $0x80" | 453 | asm volatile ("int $0x80" |
| 454 | : [ret] "={eax}" (-> isize) | 454 | : [ret] "={eax}" (-> usize) |
| 455 | : [number] "{eax}" (number), | 455 | : [number] "{eax}" (number), |
| 456 | [arg1] "{ebx}" (arg1), | 456 | [arg1] "{ebx}" (arg1), |
| 457 | [arg2] "{ecx}" (arg2), | 457 | [arg2] "{ecx}" (arg2), |
| ... | @@ -459,11 +459,11 @@ pub inline fn syscall4(number: isize, arg1: isize, arg2: isize, arg3: isize, arg | ... | @@ -459,11 +459,11 @@ pub inline fn syscall4(number: isize, arg1: isize, arg2: isize, arg3: isize, arg |
| 459 | [arg4] "{esi}" (arg4)) | 459 | [arg4] "{esi}" (arg4)) |
| 460 | } | 460 | } |
| 461 | 461 | ||
| 462 | pub inline fn syscall5(number: isize, arg1: isize, arg2: isize, arg3: isize, | 462 | pub inline fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, |
| 463 | arg4: isize, arg5: isize) -> isize | 463 | arg4: usize, arg5: usize) -> usize |
| 464 | { | 464 | { |
| 465 | asm volatile ("int $0x80" | 465 | asm volatile ("int $0x80" |
| 466 | : [ret] "={eax}" (-> isize) | 466 | : [ret] "={eax}" (-> usize) |
| 467 | : [number] "{eax}" (number), | 467 | : [number] "{eax}" (number), |
| 468 | [arg1] "{ebx}" (arg1), | 468 | [arg1] "{ebx}" (arg1), |
| 469 | [arg2] "{ecx}" (arg2), | 469 | [arg2] "{ecx}" (arg2), |
| ... | @@ -472,11 +472,11 @@ pub inline fn syscall5(number: isize, arg1: isize, arg2: isize, arg3: isize, | ... | @@ -472,11 +472,11 @@ pub inline fn syscall5(number: isize, arg1: isize, arg2: isize, arg3: isize, |
| 472 | [arg5] "{edi}" (arg5)) | 472 | [arg5] "{edi}" (arg5)) |
| 473 | } | 473 | } |
| 474 | 474 | ||
| 475 | pub inline fn syscall6(number: isize, arg1: isize, arg2: isize, arg3: isize, | 475 | pub inline fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize, |
| 476 | arg4: isize, arg5: isize, arg6: isize) -> isize | 476 | arg4: usize, arg5: usize, arg6: usize) -> usize |
| 477 | { | 477 | { |
| 478 | asm volatile ("int $0x80" | 478 | asm volatile ("int $0x80" |
| 479 | : [ret] "={eax}" (-> isize) | 479 | : [ret] "={eax}" (-> usize) |
| 480 | : [number] "{eax}" (number), | 480 | : [number] "{eax}" (number), |
| 481 | [arg1] "{ebx}" (arg1), | 481 | [arg1] "{ebx}" (arg1), |
| 482 | [arg2] "{ecx}" (arg2), | 482 | [arg2] "{ecx}" (arg2), |
std/linux_x86_64.zig+15-15| ... | @@ -370,33 +370,33 @@ pub const F_GETOWN_EX = 16; | ... | @@ -370,33 +370,33 @@ pub const F_GETOWN_EX = 16; |
| 370 | 370 | ||
| 371 | pub const F_GETOWNER_UIDS = 17; | 371 | pub const F_GETOWNER_UIDS = 17; |
| 372 | 372 | ||
| 373 | pub inline fn syscall0(number: isize) -> isize { | 373 | pub inline fn syscall0(number: usize) -> usize { |
| 374 | asm volatile ("syscall" | 374 | asm volatile ("syscall" |
| 375 | : [ret] "={rax}" (-> isize) | 375 | : [ret] "={rax}" (-> usize) |
| 376 | : [number] "{rax}" (number) | 376 | : [number] "{rax}" (number) |
| 377 | : "rcx", "r11") | 377 | : "rcx", "r11") |
| 378 | } | 378 | } |
| 379 | 379 | ||
| 380 | pub inline fn syscall1(number: isize, arg1: isize) -> isize { | 380 | pub inline fn syscall1(number: usize, arg1: usize) -> usize { |
| 381 | asm volatile ("syscall" | 381 | asm volatile ("syscall" |
| 382 | : [ret] "={rax}" (-> isize) | 382 | : [ret] "={rax}" (-> usize) |
| 383 | : [number] "{rax}" (number), | 383 | : [number] "{rax}" (number), |
| 384 | [arg1] "{rdi}" (arg1) | 384 | [arg1] "{rdi}" (arg1) |
| 385 | : "rcx", "r11") | 385 | : "rcx", "r11") |
| 386 | } | 386 | } |
| 387 | 387 | ||
| 388 | pub inline fn syscall2(number: isize, arg1: isize, arg2: isize) -> isize { | 388 | pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize { |
| 389 | asm volatile ("syscall" | 389 | asm volatile ("syscall" |
| 390 | : [ret] "={rax}" (-> isize) | 390 | : [ret] "={rax}" (-> usize) |
| 391 | : [number] "{rax}" (number), | 391 | : [number] "{rax}" (number), |
| 392 | [arg1] "{rdi}" (arg1), | 392 | [arg1] "{rdi}" (arg1), |
| 393 | [arg2] "{rsi}" (arg2) | 393 | [arg2] "{rsi}" (arg2) |
| 394 | : "rcx", "r11") | 394 | : "rcx", "r11") |
| 395 | } | 395 | } |
| 396 | 396 | ||
| 397 | pub inline fn syscall3(number: isize, arg1: isize, arg2: isize, arg3: isize) -> isize { | 397 | pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize { |
| 398 | asm volatile ("syscall" | 398 | asm volatile ("syscall" |
| 399 | : [ret] "={rax}" (-> isize) | 399 | : [ret] "={rax}" (-> usize) |
| 400 | : [number] "{rax}" (number), | 400 | : [number] "{rax}" (number), |
| 401 | [arg1] "{rdi}" (arg1), | 401 | [arg1] "{rdi}" (arg1), |
| 402 | [arg2] "{rsi}" (arg2), | 402 | [arg2] "{rsi}" (arg2), |
| ... | @@ -404,9 +404,9 @@ pub inline fn syscall3(number: isize, arg1: isize, arg2: isize, arg3: isize) -> | ... | @@ -404,9 +404,9 @@ pub inline fn syscall3(number: isize, arg1: isize, arg2: isize, arg3: isize) -> |
| 404 | : "rcx", "r11") | 404 | : "rcx", "r11") |
| 405 | } | 405 | } |
| 406 | 406 | ||
| 407 | pub inline fn syscall4(number: isize, arg1: isize, arg2: isize, arg3: isize, arg4: isize) -> isize { | 407 | pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) -> usize { |
| 408 | asm volatile ("syscall" | 408 | asm volatile ("syscall" |
| 409 | : [ret] "={rax}" (-> isize) | 409 | : [ret] "={rax}" (-> usize) |
| 410 | : [number] "{rax}" (number), | 410 | : [number] "{rax}" (number), |
| 411 | [arg1] "{rdi}" (arg1), | 411 | [arg1] "{rdi}" (arg1), |
| 412 | [arg2] "{rsi}" (arg2), | 412 | [arg2] "{rsi}" (arg2), |
| ... | @@ -415,9 +415,9 @@ pub inline fn syscall4(number: isize, arg1: isize, arg2: isize, arg3: isize, arg | ... | @@ -415,9 +415,9 @@ pub inline fn syscall4(number: isize, arg1: isize, arg2: isize, arg3: isize, arg |
| 415 | : "rcx", "r11") | 415 | : "rcx", "r11") |
| 416 | } | 416 | } |
| 417 | 417 | ||
| 418 | pub inline fn syscall5(number: isize, arg1: isize, arg2: isize, arg3: isize, arg4: isize, arg5: isize) -> isize { | 418 | pub inline fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) -> usize { |
| 419 | asm volatile ("syscall" | 419 | asm volatile ("syscall" |
| 420 | : [ret] "={rax}" (-> isize) | 420 | : [ret] "={rax}" (-> usize) |
| 421 | : [number] "{rax}" (number), | 421 | : [number] "{rax}" (number), |
| 422 | [arg1] "{rdi}" (arg1), | 422 | [arg1] "{rdi}" (arg1), |
| 423 | [arg2] "{rsi}" (arg2), | 423 | [arg2] "{rsi}" (arg2), |
| ... | @@ -427,11 +427,11 @@ pub inline fn syscall5(number: isize, arg1: isize, arg2: isize, arg3: isize, arg | ... | @@ -427,11 +427,11 @@ pub inline fn syscall5(number: isize, arg1: isize, arg2: isize, arg3: isize, arg |
| 427 | : "rcx", "r11") | 427 | : "rcx", "r11") |
| 428 | } | 428 | } |
| 429 | 429 | ||
| 430 | pub inline fn syscall6(number: isize, arg1: isize, arg2: isize, arg3: isize, arg4: isize, | 430 | pub inline fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, |
| 431 | arg5: isize, arg6: isize) -> isize | 431 | arg5: usize, arg6: usize) -> usize |
| 432 | { | 432 | { |
| 433 | asm volatile ("syscall" | 433 | asm volatile ("syscall" |
| 434 | : [ret] "={rax}" (-> isize) | 434 | : [ret] "={rax}" (-> usize) |
| 435 | : [number] "{rax}" (number), | 435 | : [number] "{rax}" (number), |
| 436 | [arg1] "{rdi}" (arg1), | 436 | [arg1] "{rdi}" (arg1), |
| 437 | [arg2] "{rsi}" (arg2), | 437 | [arg2] "{rsi}" (arg2), |
std/list.zig+8-8| ... | @@ -6,11 +6,11 @@ pub inline fn List(inline T: type) -> type { | ... | @@ -6,11 +6,11 @@ pub inline fn List(inline T: type) -> type { |
| 6 | SmallList(T, 8) | 6 | SmallList(T, 8) |
| 7 | } | 7 | } |
| 8 | 8 | ||
| 9 | pub struct SmallList(T: type, STATIC_SIZE: isize) { | 9 | pub struct SmallList(T: type, STATIC_SIZE: usize) { |
| 10 | const Self = SmallList(T, STATIC_SIZE); | 10 | const Self = SmallList(T, STATIC_SIZE); |
| 11 | 11 | ||
| 12 | items: []T, | 12 | items: []T, |
| 13 | length: isize, | 13 | length: usize, |
| 14 | prealloc_items: [STATIC_SIZE]T, | 14 | prealloc_items: [STATIC_SIZE]T, |
| 15 | allocator: &Allocator, | 15 | allocator: &Allocator, |
| 16 | 16 | ||
| ... | @@ -33,7 +33,7 @@ pub struct SmallList(T: type, STATIC_SIZE: isize) { | ... | @@ -33,7 +33,7 @@ pub struct SmallList(T: type, STATIC_SIZE: isize) { |
| 33 | l.length = new_length; | 33 | l.length = new_length; |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | pub fn ensure_capacity(l: &Self, new_capacity: isize) -> %void { | 36 | pub fn ensure_capacity(l: &Self, new_capacity: usize) -> %void { |
| 37 | const old_capacity = l.items.len; | 37 | const old_capacity = l.items.len; |
| 38 | var better_capacity = old_capacity; | 38 | var better_capacity = old_capacity; |
| 39 | while (better_capacity < new_capacity) { | 39 | while (better_capacity < new_capacity) { |
| ... | @@ -58,15 +58,15 @@ var global_allocator = Allocator { | ... | @@ -58,15 +58,15 @@ var global_allocator = Allocator { |
| 58 | }; | 58 | }; |
| 59 | 59 | ||
| 60 | var some_mem: [200]u8 = undefined; | 60 | var some_mem: [200]u8 = undefined; |
| 61 | var some_mem_index: isize = 0; | 61 | var some_mem_index: usize = 0; |
| 62 | 62 | ||
| 63 | fn global_alloc(self: &Allocator, n: isize) -> %[]u8 { | 63 | fn global_alloc(self: &Allocator, n: usize) -> %[]u8 { |
| 64 | const result = some_mem[some_mem_index ... some_mem_index + n]; | 64 | const result = some_mem[some_mem_index ... some_mem_index + n]; |
| 65 | some_mem_index += n; | 65 | some_mem_index += n; |
| 66 | return result; | 66 | return result; |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | fn global_realloc(self: &Allocator, old_mem: []u8, new_size: isize) -> %[]u8 { | 69 | fn global_realloc(self: &Allocator, old_mem: []u8, new_size: usize) -> %[]u8 { |
| 70 | const result = %return global_alloc(self, new_size); | 70 | const result = %return global_alloc(self, new_size); |
| 71 | @memcpy(result.ptr, old_mem.ptr, old_mem.len); | 71 | @memcpy(result.ptr, old_mem.ptr, old_mem.len); |
| 72 | return result; | 72 | return result; |
| ... | @@ -81,11 +81,11 @@ fn basic_list_test() { | ... | @@ -81,11 +81,11 @@ fn basic_list_test() { |
| 81 | list.init(&global_allocator); | 81 | list.init(&global_allocator); |
| 82 | defer list.deinit(); | 82 | defer list.deinit(); |
| 83 | 83 | ||
| 84 | {var i: isize = 0; while (i < 10; i += 1) { | 84 | {var i: usize = 0; while (i < 10; i += 1) { |
| 85 | %%list.append(i32(i + 1)); | 85 | %%list.append(i32(i + 1)); |
| 86 | }} | 86 | }} |
| 87 | 87 | ||
| 88 | {var i: isize = 0; while (i < 10; i += 1) { | 88 | {var i: usize = 0; while (i < 10; i += 1) { |
| 89 | assert(list.items[i] == i32(i + 1)); | 89 | assert(list.items[i] == i32(i + 1)); |
| 90 | }} | 90 | }} |
| 91 | } | 91 | } |
std/mem.zig+7-7| ... | @@ -7,13 +7,13 @@ pub error NoMem; | ... | @@ -7,13 +7,13 @@ pub error NoMem; |
| 7 | 7 | ||
| 8 | pub type Context = u8; | 8 | pub type Context = u8; |
| 9 | pub struct Allocator { | 9 | pub struct Allocator { |
| 10 | alloc_fn: fn (self: &Allocator, n: isize) -> %[]u8, | 10 | alloc_fn: fn (self: &Allocator, n: usize) -> %[]u8, |
| 11 | realloc_fn: fn (self: &Allocator, old_mem: []u8, new_size: isize) -> %[]u8, | 11 | realloc_fn: fn (self: &Allocator, old_mem: []u8, new_size: usize) -> %[]u8, |
| 12 | free_fn: fn (self: &Allocator, mem: []u8), | 12 | free_fn: fn (self: &Allocator, mem: []u8), |
| 13 | context: ?&Context, | 13 | context: ?&Context, |
| 14 | 14 | ||
| 15 | /// Aborts the program if an allocation fails. | 15 | /// Aborts the program if an allocation fails. |
| 16 | fn checked_alloc(self: &Allocator, inline T: type, n: isize) -> []T { | 16 | fn checked_alloc(self: &Allocator, inline T: type, n: usize) -> []T { |
| 17 | alloc(self, T, n) %% |err| { | 17 | alloc(self, T, n) %% |err| { |
| 18 | // TODO var args printf | 18 | // TODO var args printf |
| 19 | %%io.stderr.write("allocation failure: "); | 19 | %%io.stderr.write("allocation failure: "); |
| ... | @@ -23,13 +23,13 @@ pub struct Allocator { | ... | @@ -23,13 +23,13 @@ pub struct Allocator { |
| 23 | } | 23 | } |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | fn alloc(self: &Allocator, inline T: type, n: isize) -> %[]T { | 26 | fn alloc(self: &Allocator, inline T: type, n: usize) -> %[]T { |
| 27 | const byte_count = %return math.mul_overflow(isize, @sizeof(T), n); | 27 | const byte_count = %return math.mul_overflow(usize, @sizeof(T), n); |
| 28 | ([]T)(%return self.alloc_fn(self, byte_count)) | 28 | ([]T)(%return self.alloc_fn(self, byte_count)) |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | fn realloc(self: &Allocator, inline T: type, old_mem: []T, n: isize) -> %[]T { | 31 | fn realloc(self: &Allocator, inline T: type, old_mem: []T, n: usize) -> %[]T { |
| 32 | const byte_count = %return math.mul_overflow(isize, @sizeof(T), n); | 32 | const byte_count = %return math.mul_overflow(usize, @sizeof(T), n); |
| 33 | ([]T)(%return self.realloc_fn(self, ([]u8)(old_mem), byte_count)) | 33 | ([]T)(%return self.realloc_fn(self, ([]u8)(old_mem), byte_count)) |
| 34 | } | 34 | } |
| 35 | 35 |
std/net.zig+1-1| ... | @@ -15,7 +15,7 @@ pub error BadFd; | ... | @@ -15,7 +15,7 @@ pub error BadFd; |
| 15 | struct Connection { | 15 | struct Connection { |
| 16 | socket_fd: i32, | 16 | socket_fd: i32, |
| 17 | 17 | ||
| 18 | pub fn send(c: Connection, buf: []const u8) -> %isize { | 18 | pub fn send(c: Connection, buf: []const u8) -> %usize { |
| 19 | const send_ret = linux.sendto(c.socket_fd, buf.ptr, buf.len, 0, null, 0); | 19 | const send_ret = linux.sendto(c.socket_fd, buf.ptr, buf.len, 0, null, 0); |
| 20 | const send_err = linux.get_errno(send_ret); | 20 | const send_err = linux.get_errno(send_ret); |
| 21 | switch (send_err) { | 21 | switch (send_err) { |
std/os.zig+4-3| ... | @@ -7,9 +7,10 @@ pub error Unexpected; | ... | @@ -7,9 +7,10 @@ pub error Unexpected; |
| 7 | pub fn get_random_bytes(buf: []u8) -> %void { | 7 | pub fn get_random_bytes(buf: []u8) -> %void { |
| 8 | switch (@compile_var("os")) { | 8 | switch (@compile_var("os")) { |
| 9 | linux => { | 9 | linux => { |
| 10 | const amt_got = linux.getrandom(buf.ptr, buf.len, 0); | 10 | const ret = linux.getrandom(buf.ptr, buf.len, 0); |
| 11 | if (amt_got < 0) { | 11 | const err = linux.get_errno(ret); |
| 12 | return switch (-amt_got) { | 12 | if (err > 0) { |
| 13 | return switch (err) { | ||
| 13 | errno.EINVAL => unreachable{}, | 14 | errno.EINVAL => unreachable{}, |
| 14 | errno.EFAULT => unreachable{}, | 15 | errno.EFAULT => unreachable{}, |
| 15 | errno.EINTR => error.SigInterrupt, | 16 | errno.EINTR => error.SigInterrupt, |
std/rand.zig+3-3| ... | @@ -4,7 +4,7 @@ const ARRAY_SIZE = 624; | ... | @@ -4,7 +4,7 @@ const ARRAY_SIZE = 624; |
| 4 | /// Use `init` to initialize this state. | 4 | /// Use `init` to initialize this state. |
| 5 | pub struct Rand { | 5 | pub struct Rand { |
| 6 | array: [ARRAY_SIZE]u32, | 6 | array: [ARRAY_SIZE]u32, |
| 7 | index: isize, | 7 | index: usize, |
| 8 | 8 | ||
| 9 | /// Initialize random state with the given seed. | 9 | /// Initialize random state with the given seed. |
| 10 | #static_eval_enable(false) | 10 | #static_eval_enable(false) |
| ... | @@ -12,7 +12,7 @@ pub struct Rand { | ... | @@ -12,7 +12,7 @@ pub struct Rand { |
| 12 | var r: Rand = undefined; | 12 | var r: Rand = undefined; |
| 13 | r.index = 0; | 13 | r.index = 0; |
| 14 | r.array[0] = seed; | 14 | r.array[0] = seed; |
| 15 | var i : isize = 1; | 15 | var i : usize = 1; |
| 16 | var prev_value: u64w = seed; | 16 | var prev_value: u64w = seed; |
| 17 | while (i < ARRAY_SIZE; i += 1) { | 17 | while (i < ARRAY_SIZE; i += 1) { |
| 18 | r.array[i] = @truncate(u32, (prev_value ^ (prev_value << 30)) * 0x6c078965 + u64w(i)); | 18 | r.array[i] = @truncate(u32, (prev_value ^ (prev_value << 30)) * 0x6c078965 + u64w(i)); |
| ... | @@ -91,7 +91,7 @@ pub struct Rand { | ... | @@ -91,7 +91,7 @@ pub struct Rand { |
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | // does not populate the remaining (buf.len % 4) bytes | 93 | // does not populate the remaining (buf.len % 4) bytes |
| 94 | fn get_bytes_aligned(r: &Rand, buf: []u8) -> isize { | 94 | fn get_bytes_aligned(r: &Rand, buf: []u8) -> usize { |
| 95 | var bytes_left = buf.len; | 95 | var bytes_left = buf.len; |
| 96 | while (bytes_left >= 4) { | 96 | while (bytes_left >= 4) { |
| 97 | *((&u32)(&buf[buf.len - bytes_left])) = r.get_u32(); | 97 | *((&u32)(&buf[buf.len - bytes_left])) = r.get_u32(); |
std/test_runner.zig+2-2| ... | @@ -11,9 +11,9 @@ pub fn run_tests() -> %void { | ... | @@ -11,9 +11,9 @@ pub fn run_tests() -> %void { |
| 11 | for (zig_test_fn_list) |test_fn, i| { | 11 | for (zig_test_fn_list) |test_fn, i| { |
| 12 | // TODO: print var args | 12 | // TODO: print var args |
| 13 | %%io.stderr.write("Test "); | 13 | %%io.stderr.write("Test "); |
| 14 | %%io.stderr.print_i64(i + 1); | 14 | %%io.stderr.print_u64(i + 1); |
| 15 | %%io.stderr.write("/"); | 15 | %%io.stderr.write("/"); |
| 16 | %%io.stderr.print_i64(zig_test_fn_list.len); | 16 | %%io.stderr.print_u64(zig_test_fn_list.len); |
| 17 | %%io.stderr.write(" "); | 17 | %%io.stderr.write(" "); |
| 18 | %%io.stderr.write(test_fn.name); | 18 | %%io.stderr.write(test_fn.name); |
| 19 | %%io.stderr.write("..."); | 19 | %%io.stderr.write("..."); |
test/run_tests.cpp+7-7| ... | @@ -466,7 +466,7 @@ pub fn main(args: [][]u8) -> %void { | ... | @@ -466,7 +466,7 @@ pub fn main(args: [][]u8) -> %void { |
| 466 | %%io.stdout.printf("\n"); | 466 | %%io.stdout.printf("\n"); |
| 467 | } | 467 | } |
| 468 | for (array) |item, index| { | 468 | for (array) |item, index| { |
| 469 | %%io.stdout.print_i64(index); | 469 | %%io.stdout.print_u64(index); |
| 470 | %%io.stdout.printf("\n"); | 470 | %%io.stdout.printf("\n"); |
| 471 | } | 471 | } |
| 472 | const unknown_size: []u8 = array; | 472 | const unknown_size: []u8 = array; |
| ... | @@ -475,7 +475,7 @@ pub fn main(args: [][]u8) -> %void { | ... | @@ -475,7 +475,7 @@ pub fn main(args: [][]u8) -> %void { |
| 475 | %%io.stdout.printf("\n"); | 475 | %%io.stdout.printf("\n"); |
| 476 | } | 476 | } |
| 477 | for (unknown_size) |item, index| { | 477 | for (unknown_size) |item, index| { |
| 478 | %%io.stdout.print_i64(index); | 478 | %%io.stdout.print_u64(index); |
| 479 | %%io.stdout.printf("\n"); | 479 | %%io.stdout.printf("\n"); |
| 480 | } | 480 | } |
| 481 | } | 481 | } |
| ... | @@ -497,7 +497,7 @@ export fn compare_fn(a: ?&const c_void, b: ?&const c_void) -> c_int { | ... | @@ -497,7 +497,7 @@ export fn compare_fn(a: ?&const c_void, b: ?&const c_void) -> c_int { |
| 497 | } | 497 | } |
| 498 | 498 | ||
| 499 | export fn main(args: c_int, argv: &&u8) -> c_int { | 499 | export fn main(args: c_int, argv: &&u8) -> c_int { |
| 500 | var array = []i32 { 1, 7, 3, 2, 0, 9, 4, 8, 6, 5 }; | 500 | var array = []u32 { 1, 7, 3, 2, 0, 9, 4, 8, 6, 5 }; |
| 501 | 501 | ||
| 502 | c.qsort((&c_void)(&array[0]), c_ulong(array.len), @sizeof(i32), compare_fn); | 502 | c.qsort((&c_void)(&array[0]), c_ulong(array.len), @sizeof(i32), compare_fn); |
| 503 | 503 | ||
| ... | @@ -816,7 +816,7 @@ fn f() { | ... | @@ -816,7 +816,7 @@ fn f() { |
| 816 | )SOURCE", 4, ".tmp_source.zig:4:5: error: use of undeclared identifier 'i'", | 816 | )SOURCE", 4, ".tmp_source.zig:4:5: error: use of undeclared identifier 'i'", |
| 817 | ".tmp_source.zig:4:7: error: use of undeclared identifier 'i'", | 817 | ".tmp_source.zig:4:7: error: use of undeclared identifier 'i'", |
| 818 | ".tmp_source.zig:5:8: error: array access of non-array", | 818 | ".tmp_source.zig:5:8: error: array access of non-array", |
| 819 | ".tmp_source.zig:5:9: error: expected type 'isize', got 'bool'"); | 819 | ".tmp_source.zig:5:9: error: expected type 'usize', got 'bool'"); |
| 820 | 820 | ||
| 821 | add_compile_fail_case("variadic functions only allowed in extern", R"SOURCE( | 821 | add_compile_fail_case("variadic functions only allowed in extern", R"SOURCE( |
| 822 | fn f(...) {} | 822 | fn f(...) {} |
| ... | @@ -1115,8 +1115,8 @@ fn a(x: i32) { | ... | @@ -1115,8 +1115,8 @@ fn a(x: i32) { |
| 1115 | struct Foo { | 1115 | struct Foo { |
| 1116 | y: [get()]u8, | 1116 | y: [get()]u8, |
| 1117 | } | 1117 | } |
| 1118 | var global_var: isize = 1; | 1118 | var global_var: usize = 1; |
| 1119 | fn get() -> isize { global_var } | 1119 | fn get() -> usize { global_var } |
| 1120 | )SOURCE", 1, ".tmp_source.zig:3:9: error: unable to evaluate constant expression"); | 1120 | )SOURCE", 1, ".tmp_source.zig:3:9: error: unable to evaluate constant expression"); |
| 1121 | 1121 | ||
| 1122 | 1122 | ||
| ... | @@ -1397,7 +1397,7 @@ pub fn main(args: [][]u8) { } | ... | @@ -1397,7 +1397,7 @@ pub fn main(args: [][]u8) { } |
| 1397 | 1397 | ||
| 1398 | 1398 | ||
| 1399 | add_compile_fail_case("invalid pointer for var type", R"SOURCE( | 1399 | add_compile_fail_case("invalid pointer for var type", R"SOURCE( |
| 1400 | extern fn ext() -> isize; | 1400 | extern fn ext() -> usize; |
| 1401 | var bytes: [ext()]u8 = undefined; | 1401 | var bytes: [ext()]u8 = undefined; |
| 1402 | fn f() { | 1402 | fn f() { |
| 1403 | for (bytes) |*b, i| { | 1403 | for (bytes) |*b, i| { |
test/self_hosted.zig+11-11| ... | @@ -96,16 +96,16 @@ fn mutable_local_variables() { | ... | @@ -96,16 +96,16 @@ fn mutable_local_variables() { |
| 96 | 96 | ||
| 97 | #attribute("test") | 97 | #attribute("test") |
| 98 | fn arrays() { | 98 | fn arrays() { |
| 99 | var array : [5]i32 = undefined; | 99 | var array : [5]u32 = undefined; |
| 100 | 100 | ||
| 101 | var i : i32 = 0; | 101 | var i : u32 = 0; |
| 102 | while (i < 5) { | 102 | while (i < 5) { |
| 103 | array[i] = i + 1; | 103 | array[i] = i + 1; |
| 104 | i = array[i]; | 104 | i = array[i]; |
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | i = 0; | 107 | i = 0; |
| 108 | var accumulator = i32(0); | 108 | var accumulator = u32(0); |
| 109 | while (i < 5) { | 109 | while (i < 5) { |
| 110 | accumulator += array[i]; | 110 | accumulator += array[i]; |
| 111 | 111 | ||
| ... | @@ -115,7 +115,7 @@ fn arrays() { | ... | @@ -115,7 +115,7 @@ fn arrays() { |
| 115 | assert(accumulator == 15); | 115 | assert(accumulator == 15); |
| 116 | assert(get_array_len(array) == 5); | 116 | assert(get_array_len(array) == 5); |
| 117 | } | 117 | } |
| 118 | fn get_array_len(a: []i32) -> isize { | 118 | fn get_array_len(a: []u32) -> usize { |
| 119 | a.len | 119 | a.len |
| 120 | } | 120 | } |
| 121 | 121 | ||
| ... | @@ -742,7 +742,7 @@ fn generic_malloc_free() { | ... | @@ -742,7 +742,7 @@ fn generic_malloc_free() { |
| 742 | } | 742 | } |
| 743 | const some_mem : [100]u8 = undefined; | 743 | const some_mem : [100]u8 = undefined; |
| 744 | #static_eval_enable(false) | 744 | #static_eval_enable(false) |
| 745 | fn mem_alloc(inline T: type, n: isize) -> %[]T { | 745 | fn mem_alloc(inline T: type, n: usize) -> %[]T { |
| 746 | return (&T)(&some_mem[0])[0...n]; | 746 | return (&T)(&some_mem[0])[0...n]; |
| 747 | } | 747 | } |
| 748 | fn mem_free(inline T: type, mem: []T) { } | 748 | fn mem_free(inline T: type, mem: []T) { } |
| ... | @@ -823,10 +823,10 @@ fn test_cast_undefined(x: []u8) {} | ... | @@ -823,10 +823,10 @@ fn test_cast_undefined(x: []u8) {} |
| 823 | #attribute("test") | 823 | #attribute("test") |
| 824 | fn cast_small_unsigned_to_larger_signed() { | 824 | fn cast_small_unsigned_to_larger_signed() { |
| 825 | assert(cast_small_unsigned_to_larger_signed_1(200) == i16(200)); | 825 | assert(cast_small_unsigned_to_larger_signed_1(200) == i16(200)); |
| 826 | assert(cast_small_unsigned_to_larger_signed_2(9999) == isize(9999)); | 826 | assert(cast_small_unsigned_to_larger_signed_2(9999) == i64(9999)); |
| 827 | } | 827 | } |
| 828 | fn cast_small_unsigned_to_larger_signed_1(x: u8) -> i16 { x } | 828 | fn cast_small_unsigned_to_larger_signed_1(x: u8) -> i16 { x } |
| 829 | fn cast_small_unsigned_to_larger_signed_2(x: u16) -> isize { x } | 829 | fn cast_small_unsigned_to_larger_signed_2(x: u16) -> i64 { x } |
| 830 | 830 | ||
| 831 | 831 | ||
| 832 | #attribute("test") | 832 | #attribute("test") |
| ... | @@ -834,7 +834,7 @@ fn implicit_cast_after_unreachable() { | ... | @@ -834,7 +834,7 @@ fn implicit_cast_after_unreachable() { |
| 834 | assert(outer() == 1234); | 834 | assert(outer() == 1234); |
| 835 | } | 835 | } |
| 836 | fn inner() -> i32 { 1234 } | 836 | fn inner() -> i32 { 1234 } |
| 837 | fn outer() -> isize { | 837 | fn outer() -> i64 { |
| 838 | return inner(); | 838 | return inner(); |
| 839 | } | 839 | } |
| 840 | 840 | ||
| ... | @@ -1029,7 +1029,7 @@ fn constant_expressions() { | ... | @@ -1029,7 +1029,7 @@ fn constant_expressions() { |
| 1029 | var array : [ARRAY_SIZE]u8 = undefined; | 1029 | var array : [ARRAY_SIZE]u8 = undefined; |
| 1030 | assert(@sizeof(@typeof(array)) == 20); | 1030 | assert(@sizeof(@typeof(array)) == 20); |
| 1031 | } | 1031 | } |
| 1032 | const ARRAY_SIZE : i8 = 20; | 1032 | const ARRAY_SIZE : u8 = 20; |
| 1033 | 1033 | ||
| 1034 | 1034 | ||
| 1035 | #attribute("test") | 1035 | #attribute("test") |
| ... | @@ -1315,7 +1315,7 @@ fn test_return_empty_struct_from_fn_noeval() -> EmptyStruct2 { | ... | @@ -1315,7 +1315,7 @@ fn test_return_empty_struct_from_fn_noeval() -> EmptyStruct2 { |
| 1315 | fn pass_slice_of_empty_struct_to_fn() { | 1315 | fn pass_slice_of_empty_struct_to_fn() { |
| 1316 | assert(test_pass_slice_of_empty_struct_to_fn([]EmptyStruct2{ EmptyStruct2{} }) == 1); | 1316 | assert(test_pass_slice_of_empty_struct_to_fn([]EmptyStruct2{ EmptyStruct2{} }) == 1); |
| 1317 | } | 1317 | } |
| 1318 | fn test_pass_slice_of_empty_struct_to_fn(slice: []EmptyStruct2) -> isize { | 1318 | fn test_pass_slice_of_empty_struct_to_fn(slice: []EmptyStruct2) -> usize { |
| 1319 | slice.len | 1319 | slice.len |
| 1320 | } | 1320 | } |
| 1321 | 1321 | ||
| ... | @@ -1555,7 +1555,7 @@ fn c_string_concatenation() { | ... | @@ -1555,7 +1555,7 @@ fn c_string_concatenation() { |
| 1555 | 1555 | ||
| 1556 | const len = cstr.len(b); | 1556 | const len = cstr.len(b); |
| 1557 | const len_with_null = len + 1; | 1557 | const len_with_null = len + 1; |
| 1558 | {var i: i32 = 0; while (i < len_with_null; i += 1) { | 1558 | {var i: u32 = 0; while (i < len_with_null; i += 1) { |
| 1559 | assert(a[i] == b[i]); | 1559 | assert(a[i] == b[i]); |
| 1560 | }} | 1560 | }} |
| 1561 | assert(a[len] == 0); | 1561 | assert(a[len] == 0); |