authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-07-26 20:40:11-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-07-26 20:40:11-07:00
logbc81ddfea67db0b3756027e98cc00bb8fa903a20
tree4264ce327d4dd2b7822854b25b48b5657decc369
parent76f87cdd966f23106684bb38c127f6bd3f4e9fa3

unsigned integers for sizes of things

Closes #62.

19 files changed, 266 insertions(+), 396 deletions(-)

doc/langref.md+2-2
......@@ -386,7 +386,7 @@ Function Operation
386386@shl_with_overflow(inline T: type, a: T, b: T, result: &T) -> bool *x = a << b
387387```
388388
389### @memset(dest, c: u8, byte_count: isize)
389### @memset(dest, c: u8, byte_count: usize)
390390
391391This function sets a region of memory to `c`. `dest` is a pointer.
392392
......@@ -398,7 +398,7 @@ level code will not use this function, instead using something like this:
398398for (dest) |*b| *b = c;
399399```
400400
401### @memcpy(dest, source, byte_count: isize)
401### @memcpy(dest, source, byte_count: usize)
402402
403403This function copies bytes from one region of memory to another. `dest` and
404404`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,
502502 entry->data.structure.fields[0].src_index = 0;
503503 entry->data.structure.fields[0].gen_index = 0;
504504 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;
506506 entry->data.structure.fields[1].src_index = 1;
507507 entry->data.structure.fields[1].gen_index = 1;
508508}
......@@ -546,7 +546,7 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *child_type, bool is_c
546546
547547 if (child_type->zero_bits) {
548548 LLVMTypeRef element_types[] = {
549 g->builtin_types.entry_isize->type_ref,
549 g->builtin_types.entry_usize->type_ref,
550550 };
551551 LLVMStructSetBody(entry->type_ref, element_types, 1, false);
552552
......@@ -556,9 +556,9 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *child_type, bool is_c
556556 entry->data.structure.fields[0].gen_index = -1;
557557 entry->data.structure.fields[1].gen_index = 0;
558558
559 TypeTableEntry *isize_type = g->builtin_types.entry_isize;
560 uint64_t len_debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, isize_type->type_ref);
561 uint64_t len_debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, isize_type->type_ref);
559 TypeTableEntry *usize_type = g->builtin_types.entry_usize;
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, usize_type->type_ref);
562562 uint64_t len_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, entry->type_ref, 0);
563563
564564 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
570570 len_debug_size_in_bits,
571571 len_debug_align_in_bits,
572572 len_offset_in_bits,
573 0, isize_type->di_type),
573 0, usize_type->di_type),
574574 };
575575 LLVMZigDIType *replacement_di_type = LLVMZigCreateDebugStructType(g->dbuilder,
576576 compile_unit_scope,
......@@ -586,7 +586,7 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *child_type, bool is_c
586586 unsigned element_count = 2;
587587 LLVMTypeRef element_types[] = {
588588 pointer_type->type_ref,
589 g->builtin_types.entry_isize->type_ref,
589 g->builtin_types.entry_usize->type_ref,
590590 };
591591 LLVMStructSetBody(entry->type_ref, element_types, element_count, false);
592592
......@@ -597,9 +597,9 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *child_type, bool is_c
597597 uint64_t ptr_debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, pointer_type->type_ref);
598598 uint64_t ptr_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, entry->type_ref, 0);
599599
600 TypeTableEntry *isize_type = g->builtin_types.entry_isize;
601 uint64_t len_debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, isize_type->type_ref);
602 uint64_t len_debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, isize_type->type_ref);
600 TypeTableEntry *usize_type = g->builtin_types.entry_usize;
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, usize_type->type_ref);
603603 uint64_t len_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, entry->type_ref, 1);
604604
605605 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
617617 len_debug_size_in_bits,
618618 len_debug_align_in_bits,
619619 len_offset_in_bits,
620 0, isize_type->di_type),
620 0, usize_type->di_type),
621621 };
622622 LLVMZigDIType *replacement_di_type = LLVMZigCreateDebugStructType(g->dbuilder,
623623 compile_unit_scope,
......@@ -2817,10 +2817,10 @@ static TypeTableEntry *analyze_slice_expr(CodeGen *g, ImportTableEntry *import,
28172817 context->fn_entry->struct_val_expr_alloca_list.append(&node->data.slice_expr.resolved_struct_val_expr);
28182818 }
28192819
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);
28212821
28222822 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);
28242824 }
28252825
28262826 return return_type;
......@@ -2853,7 +2853,7 @@ static TypeTableEntry *analyze_array_access_expr(CodeGen *g, ImportTableEntry *i
28532853 return_type = g->builtin_types.entry_invalid;
28542854 }
28552855
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);
28572857
28582858 return return_type;
28592859}
......@@ -3912,7 +3912,7 @@ static TypeTableEntry *analyze_array_type(CodeGen *g, ImportTableEntry *import,
39123912
39133913 if (size_node) {
39143914 TypeTableEntry *size_type = analyze_expression(g, import, context,
3915 g->builtin_types.entry_isize, size_node);
3915 g->builtin_types.entry_usize, size_node);
39163916 if (size_type->id == TypeTableEntryIdInvalid) {
39173917 return g->builtin_types.entry_invalid;
39183918 }
......@@ -4042,10 +4042,10 @@ static TypeTableEntry *analyze_for_expr(CodeGen *g, ImportTableEntry *import, Bl
40424042 Buf *index_var_name = &index_var_node->data.symbol_expr.symbol;
40434043 index_var_node->block_context = child_context;
40444044 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);
40464046 } else {
40474047 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);
40494049 }
40504050
40514051 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) {
413413 }
414414
415415 LLVMValueRef indices[] = {
416 LLVMConstNull(g->builtin_types.entry_isize->type_ref),
416 LLVMConstNull(g->builtin_types.entry_usize->type_ref),
417417 err_val,
418418 };
419419 return LLVMBuildInBoundsGEP(g->builder, g->err_name_table, indices, 2, "");
......@@ -937,7 +937,7 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) {
937937
938938 int len_index = wanted_type->data.structure.fields[1].gen_index;
939939 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,
941941 actual_type->data.array.len, false);
942942 LLVMBuildStore(g->builder, len_val, len_ptr);
943943
......@@ -978,13 +978,13 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) {
978978
979979 LLVMValueRef new_len;
980980 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);
982982 new_len = LLVMBuildMul(g->builder, src_len, src_size_val, "");
983983 } 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);
985985 if (want_debug_safety(g, node)) {
986986 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);
988988 LLVMValueRef ok_bit = LLVMBuildICmp(g->builder, LLVMIntEQ, remainder_val, zero, "");
989989 LLVMBasicBlockRef ok_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "SliceWidenOk");
990990 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
11591159
11601160 if (array_type->id == TypeTableEntryIdArray) {
11611161 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,
11631163 array_type->data.array.len, false);
11641164 add_bounds_check(g, source_node, subscript_value, LLVMIntEQ, nullptr, LLVMIntULT, end);
11651165 }
11661166 LLVMValueRef indices[] = {
1167 LLVMConstNull(g->builtin_types.entry_isize->type_ref),
1167 LLVMConstNull(g->builtin_types.entry_usize->type_ref),
11681168 subscript_value
11691169 };
11701170 set_debug_source_node(g, source_node);
......@@ -1268,13 +1268,13 @@ static LLVMValueRef gen_slice_expr(CodeGen *g, AstNode *node) {
12681268 if (node->data.slice_expr.end) {
12691269 end_val = gen_expr(g, node->data.slice_expr.end);
12701270 } 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);
12721272 }
12731273
12741274 if (want_debug_safety(g, node)) {
12751275 add_bounds_check(g, node, start_val, LLVMIntEQ, nullptr, LLVMIntULE, end_val);
12761276 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,
12781278 array_type->data.array.len, false);
12791279 add_bounds_check(g, node, end_val, LLVMIntEQ, nullptr, LLVMIntULE, array_end);
12801280 }
......@@ -1283,7 +1283,7 @@ static LLVMValueRef gen_slice_expr(CodeGen *g, AstNode *node) {
12831283 set_debug_source_node(g, node);
12841284 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, 0, "");
12851285 LLVMValueRef indices[] = {
1286 LLVMConstNull(g->builtin_types.entry_isize->type_ref),
1286 LLVMConstNull(g->builtin_types.entry_usize->type_ref),
12871287 start_val,
12881288 };
12891289 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
14081408 if (struct_type->id == TypeTableEntryIdArray) {
14091409 Buf *name = &node->data.field_access_expr.field_name;
14101410 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,
14121412 struct_type->data.array.len, false);
14131413 } else if (struct_type->id == TypeTableEntryIdStruct || (struct_type->id == TypeTableEntryIdPointer &&
14141414 struct_type->data.pointer.child_type->id == TypeTableEntryIdStruct))
......@@ -2043,7 +2043,7 @@ static LLVMValueRef gen_struct_memcpy(CodeGen *g, AstNode *source_node, LLVMValu
20432043 LLVMValueRef src_ptr = LLVMBuildBitCast(g->builder, src, ptr_u8, "");
20442044 LLVMValueRef dest_ptr = LLVMBuildBitCast(g->builder, dest, ptr_u8, "");
20452045
2046 TypeTableEntry *isize = g->builtin_types.entry_isize;
2046 TypeTableEntry *usize = g->builtin_types.entry_usize;
20472047 uint64_t size_bytes = LLVMStoreSizeOfType(g->target_data_ref, type_entry->type_ref);
20482048 uint64_t align_bytes = get_memcpy_align(g, type_entry);
20492049 assert(size_bytes > 0);
......@@ -2052,7 +2052,7 @@ static LLVMValueRef gen_struct_memcpy(CodeGen *g, AstNode *source_node, LLVMValu
20522052 LLVMValueRef params[] = {
20532053 dest_ptr, // dest pointer
20542054 src_ptr, // source pointer
2055 LLVMConstInt(isize->type_ref, size_bytes, false),
2055 LLVMConstInt(usize->type_ref, size_bytes, false),
20562056 LLVMConstInt(LLVMInt32Type(), align_bytes, false),
20572057 LLVMConstNull(LLVMInt1Type()), // is volatile
20582058 };
......@@ -2871,8 +2871,8 @@ static LLVMValueRef gen_container_init_expr(CodeGen *g, AstNode *node) {
28712871 LLVMValueRef elem_val = gen_expr(g, field_node);
28722872
28732873 LLVMValueRef indices[] = {
2874 LLVMConstNull(g->builtin_types.entry_isize->type_ref),
2875 LLVMConstInt(g->builtin_types.entry_isize->type_ref, i, false),
2874 LLVMConstNull(g->builtin_types.entry_usize->type_ref),
2875 LLVMConstInt(g->builtin_types.entry_usize->type_ref, i, false),
28762876 };
28772877 set_debug_source_node(g, field_node);
28782878 LLVMValueRef elem_ptr = LLVMBuildInBoundsGEP(g->builder, tmp_array_ptr, indices, 2, "");
......@@ -2989,7 +2989,7 @@ static LLVMValueRef gen_for_expr(CodeGen *g, AstNode *node) {
29892989 VariableTableEntry *index_var = node->data.for_expr.index_var;
29902990 assert(index_var);
29912991 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);
29932993
29942994 LLVMBasicBlockRef cond_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "ForCond");
29952995 LLVMBasicBlockRef body_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "ForBody");
......@@ -3005,7 +3005,7 @@ static LLVMValueRef gen_for_expr(CodeGen *g, AstNode *node) {
30053005 LLVMValueRef len_val;
30063006 TypeTableEntry *child_type;
30073007 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,
30093009 array_type->data.array.len, false);
30103010 child_type = array_type->data.array.child_type;
30113011 } else if (array_type->id == TypeTableEntryIdStruct) {
......@@ -3154,7 +3154,7 @@ static LLVMValueRef gen_var_decl_raw(CodeGen *g, AstNode *source_node, AstNodeVa
31543154 }
31553155 }
31563156 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;
31583158 uint64_t size_bytes = LLVMStoreSizeOfType(g->target_data_ref, variable->type->type_ref);
31593159 uint64_t align_bytes = get_memcpy_align(g, variable->type);
31603160
......@@ -3163,7 +3163,7 @@ static LLVMValueRef gen_var_decl_raw(CodeGen *g, AstNode *source_node, AstNodeVa
31633163 LLVMTypeRef ptr_u8 = LLVMPointerType(LLVMInt8Type(), 0);
31643164 LLVMValueRef fill_char = LLVMConstInt(LLVMInt8Type(), 0xaa, false);
31653165 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);
31673167 LLVMValueRef align_in_bytes = LLVMConstInt(LLVMInt32Type(), align_bytes, false);
31683168 LLVMValueRef params[] = {
31693169 dest_ptr,
......@@ -3771,7 +3771,7 @@ static LLVMValueRef gen_test_fn_val(CodeGen *g, FnTableEntry *fn_entry) {
37713771 LLVMSetGlobalConstant(str_global_val, true);
37723772 LLVMSetUnnamedAddr(str_global_val, true);
37733773
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);
37753775
37763776 LLVMTypeRef ptr_type = LLVMPointerType(g->builtin_types.entry_u8->type_ref, 0);
37773777 LLVMValueRef name_fields[] = {
......@@ -3813,7 +3813,7 @@ static void generate_error_name_table(CodeGen *g) {
38133813
38143814 LLVMValueRef fields[] = {
38153815 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),
38173817 };
38183818 values[i] = LLVMConstNamedStruct(str_type->type_ref, fields, 2);
38193819 }
......@@ -3986,7 +3986,7 @@ static void do_code_gen(CodeGen *g) {
39863986 LLVMSetGlobalConstant(test_fn_array_val, true);
39873987 LLVMSetUnnamedAddr(test_fn_array_val, true);
39883988
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);
39903990 LLVMTypeRef ptr_type = LLVMPointerType(LLVMTypeOf(test_fn_vals[0]), 0);
39913991 LLVMValueRef fields[] = {
39923992 LLVMConstBitCast(test_fn_array_val, ptr_type),
......@@ -4611,7 +4611,7 @@ static void define_builtin_fns(CodeGen *g) {
46114611 builtin_fn->param_types = allocate<TypeTableEntry *>(builtin_fn->param_count);
46124612 builtin_fn->param_types[0] = nullptr; // manually checked later
46134613 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;
46154615 builtin_fn->ref_count = 1;
46164616
46174617 LLVMTypeRef param_types[] = {
......@@ -4635,7 +4635,7 @@ static void define_builtin_fns(CodeGen *g) {
46354635 builtin_fn->param_types = allocate<TypeTableEntry *>(builtin_fn->param_count);
46364636 builtin_fn->param_types[0] = nullptr; // manually checked later
46374637 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;
46394639 builtin_fn->ref_count = 1;
46404640
46414641 LLVMTypeRef param_types[] = {
std/bootstrap.zig+4-4
......@@ -10,7 +10,7 @@ const want_start_symbol = switch(@compile_var("os")) {
1010};
1111const want_main_symbol = !want_start_symbol;
1212
13var argc: isize = undefined;
13var argc: usize = undefined;
1414var argv: &&u8 = undefined;
1515
1616#attribute("naked")
......@@ -18,11 +18,11 @@ var argv: &&u8 = undefined;
1818export fn _start() -> unreachable {
1919 switch (@compile_var("arch")) {
2020 x86_64 => {
21 argc = asm("mov (%%rsp), %[argc]": [argc] "=r" (-> isize));
21 argc = asm("mov (%%rsp), %[argc]": [argc] "=r" (-> usize));
2222 argv = asm("lea 0x8(%%rsp), %[argv]": [argv] "=r" (-> &&u8));
2323 },
2424 i386 => {
25 argc = asm("mov (%%esp), %[argc]": [argc] "=r" (-> isize));
25 argc = asm("mov (%%esp), %[argc]": [argc] "=r" (-> usize));
2626 argv = asm("lea 0x4(%%esp), %[argv]": [argv] "=r" (-> &&u8));
2727 },
2828 else => @compile_err("unsupported arch"),
......@@ -46,7 +46,7 @@ fn call_main_and_exit() -> unreachable {
4646
4747#condition(want_main_symbol)
4848export fn main(c_argc: i32, c_argv: &&u8) -> i32 {
49 argc = c_argc;
49 argc = usize(c_argc);
5050 argv = c_argv;
5151 call_main() %% return 1;
5252 return 0;
std/builtin.zig+4-4
......@@ -2,8 +2,8 @@
22// sometimes generates code that calls them.
33
44#debug_safety(false)
5export fn memset(dest: &u8, c: u8, n: isize) -> &u8 {
6 var index: isize = 0;
5export fn memset(dest: &u8, c: u8, n: usize) -> &u8 {
6 var index: usize = 0;
77 while (index != n) {
88 dest[index] = c;
99 index += 1;
......@@ -12,8 +12,8 @@ export fn memset(dest: &u8, c: u8, n: isize) -> &u8 {
1212}
1313
1414#debug_safety(false)
15export fn memcpy(noalias dest: &u8, noalias src: &const u8, n: isize) -> &u8 {
16 var index: isize = 0;
15export fn memcpy(noalias dest: &u8, noalias src: &const u8, n: usize) -> &u8 {
16 var index: usize = 0;
1717 while (index != n) {
1818 dest[index] = src[index];
1919 index += 1;
std/cstr.zig+3-3
......@@ -1,8 +1,8 @@
11// TODO fix https://github.com/andrewrk/zig/issues/140
22// and then make this able to run at compile time
33#static_eval_enable(false)
4pub fn len(ptr: &const u8) -> isize {
5 var count: isize = 0;
4pub fn len(ptr: &const u8) -> usize {
5 var count: usize = 0;
66 while (ptr[count] != 0; count += 1) {}
77 return count;
88}
......@@ -11,7 +11,7 @@ pub fn len(ptr: &const u8) -> isize {
1111// and then make this able to run at compile time
1212#static_eval_enable(false)
1313pub fn cmp(a: &const u8, b: &const u8) -> i32 {
14 var index: isize = 0;
14 var index: usize = 0;
1515 while (a[index] == b[index] && a[index] != 0; index += 1) {}
1616 return a[index] - b[index];
1717}
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
1212}
1313*/
1414
15pub struct SmallHashMap(K: type, V: type, hash: fn(key: K)->u32, eql: fn(a: K, b: K)->bool, STATIC_SIZE: isize) {
15pub struct SmallHashMap(K: type, V: type, hash: fn(key: K)->u32, eql: fn(a: K, b: K)->bool, STATIC_SIZE: usize) {
1616 entries: []Entry,
17 size: isize,
18 max_distance_from_start_index: isize,
17 size: usize,
18 max_distance_from_start_index: usize,
1919 allocator: &Allocator,
2020 // if the hash map is small enough, we use linear search through these
2121 // 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
2727
2828 pub struct Entry {
2929 used: bool,
30 distance_from_start_index: isize,
30 distance_from_start_index: usize,
3131 key: K,
3232 value: V,
3333 }
......@@ -35,9 +35,9 @@ pub struct SmallHashMap(K: type, V: type, hash: fn(key: K)->u32, eql: fn(a: K, b
3535 pub struct Iterator {
3636 hm: &Self,
3737 // how many items have we returned
38 count: isize,
38 count: usize,
3939 // iterator through the entry array
40 index: isize,
40 index: usize,
4141 // used to detect concurrent modification
4242 initial_modification_count: debug_u32,
4343
......@@ -117,7 +117,7 @@ pub struct SmallHashMap(K: type, V: type, hash: fn(key: K)->u32, eql: fn(a: K, b
117117 pub fn remove(hm: &Self, key: K) {
118118 hm.increment_modification_count();
119119 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) {
121121 const index = (start_index + roll_over) % hm.entries.len;
122122 var entry = &hm.entries[index];
123123
......@@ -151,7 +151,7 @@ pub struct SmallHashMap(K: type, V: type, hash: fn(key: K)->u32, eql: fn(a: K, b
151151 };
152152 }
153153
154 fn init_capacity(hm: &Self, capacity: isize) -> %void {
154 fn init_capacity(hm: &Self, capacity: usize) -> %void {
155155 hm.entries = %return hm.allocator.alloc(Entry, capacity);
156156 hm.size = 0;
157157 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
170170 var key = orig_key;
171171 var value = orig_value;
172172 const start_index = hm.key_to_index(key);
173 var roll_over: isize = 0;
174 var distance_from_start_index: isize = 0;
173 var roll_over: usize = 0;
174 var distance_from_start_index: usize = 0;
175175 while (roll_over < hm.entries.len; {roll_over += 1; distance_from_start_index += 1}) {
176176 const index = (start_index + roll_over) % hm.entries.len;
177177 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
180180 if (entry.distance_from_start_index < distance_from_start_index) {
181181 // robin hood to the rescue
182182 const tmp = *entry;
183 hm.max_distance_from_start_index = math.max(isize,
183 hm.max_distance_from_start_index = math.max(usize,
184184 hm.max_distance_from_start_index, distance_from_start_index);
185185 *entry = Entry {
186186 .used = true,
......@@ -201,7 +201,7 @@ pub struct SmallHashMap(K: type, V: type, hash: fn(key: K)->u32, eql: fn(a: K, b
201201 hm.size += 1;
202202 }
203203
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,
205205 hm.max_distance_from_start_index);
206206 *entry = Entry {
207207 .used = true,
......@@ -216,7 +216,7 @@ pub struct SmallHashMap(K: type, V: type, hash: fn(key: K)->u32, eql: fn(a: K, b
216216
217217 fn internal_get(hm: &Self, key: K) -> ?&Entry {
218218 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) {
220220 const index = (start_index + roll_over) % hm.entries.len;
221221 const entry = &hm.entries[index];
222222
......@@ -226,8 +226,8 @@ pub struct SmallHashMap(K: type, V: type, hash: fn(key: K)->u32, eql: fn(a: K, b
226226 return null;
227227 }
228228
229 fn key_to_index(hm: &Self, key: K) -> isize {
230 return isize(hash(key)) % hm.entries.len;
229 fn key_to_index(hm: &Self, key: K) -> usize {
230 return usize(hash(key)) % hm.entries.len;
231231 }
232232}
233233
......@@ -239,15 +239,15 @@ var global_allocator = Allocator {
239239};
240240
241241var some_mem: [200]u8 = undefined;
242var some_mem_index: isize = 0;
242var some_mem_index: usize = 0;
243243
244fn global_alloc(self: &Allocator, n: isize) -> %[]u8 {
244fn global_alloc(self: &Allocator, n: usize) -> %[]u8 {
245245 const result = some_mem[some_mem_index ... some_mem_index + n];
246246 some_mem_index += n;
247247 return result;
248248}
249249
250fn global_realloc(self: &Allocator, old_mem: []u8, new_size: isize) -> %[]u8 {
250fn global_realloc(self: &Allocator, old_mem: []u8, new_size: usize) -> %[]u8 {
251251 const result = %return global_alloc(self, new_size);
252252 @memcpy(result.ptr, old_mem.ptr, old_mem.len);
253253 return result;
std/io.zig+31-161
......@@ -59,9 +59,9 @@ pub const OpenCreate = 0b0100;
5959pub const OpenTruncate = 0b1000;
6060
6161pub struct OutStream {
62 fd: isize,
62 fd: i32,
6363 buffer: [buffer_size]u8,
64 index: isize,
64 index: usize,
6565
6666 pub fn write_byte(os: &OutStream, b: u8) -> %void {
6767 if (os.buffer.len == os.index) %return os.flush();
......@@ -69,13 +69,13 @@ pub struct OutStream {
6969 os.index += 1;
7070 }
7171
72 pub fn write(os: &OutStream, bytes: []const u8) -> %isize {
72 pub fn write(os: &OutStream, bytes: []const u8) -> %usize {
7373 var src_bytes_left = bytes.len;
7474 var src_index: @typeof(bytes.len) = 0;
7575 const dest_space_left = os.buffer.len - os.index;
7676
7777 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);
7979 @memcpy(&os.buffer[os.index], &bytes[src_index], copy_amt);
8080 os.index += copy_amt;
8181 if (os.index == os.buffer.len) {
......@@ -88,13 +88,13 @@ pub struct OutStream {
8888
8989 /// Prints a byte buffer, flushes the buffer, then returns the number of
9090 /// 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 {
9292 const byte_count = %return os.write(str);
9393 %return os.flush();
9494 return byte_count;
9595 }
9696
97 pub fn print_u64(os: &OutStream, x: u64) -> %isize {
97 pub fn print_u64(os: &OutStream, x: u64) -> %usize {
9898 if (os.index + max_u64_base10_digits >= os.buffer.len) {
9999 %return os.flush();
100100 }
......@@ -104,7 +104,7 @@ pub struct OutStream {
104104 return amt_printed;
105105 }
106106
107 pub fn print_i64(os: &OutStream, x: i64) -> %isize {
107 pub fn print_i64(os: &OutStream, x: i64) -> %usize {
108108 if (os.index + max_u64_base10_digits >= os.buffer.len) {
109109 %return os.flush();
110110 }
......@@ -114,16 +114,6 @@ pub struct OutStream {
114114 return amt_printed;
115115 }
116116
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
127117 pub fn flush(os: &OutStream) -> %void {
128118 const write_ret = linux.write(os.fd, &os.buffer[0], os.index);
129119 const write_err = linux.get_errno(write_ret);
......@@ -144,25 +134,27 @@ pub struct OutStream {
144134 }
145135
146136 pub fn close(os: &OutStream) -> %void {
147 const closed = linux.close(os.fd);
148 if (closed < 0) {
149 return switch (-closed) {
150 errno.EIO => error.Io,
137 const close_ret = linux.close(os.fd);
138 const close_err = linux.get_errno(close_ret);
139 if (close_err > 0) {
140 return switch (close_err) {
141 errno.EIO => error.Io,
151142 errno.EBADF => error.BadFd,
152143 errno.EINTR => error.SigInterrupt,
153 else => error.Unexpected,
144 else => error.Unexpected,
154145 }
155146 }
156147 }
157148}
158149
159150pub struct InStream {
160 fd: isize,
151 fd: i32,
161152
162153 pub fn open(path: []u8) -> %InStream {
163154 const fd = linux.open(path, linux.O_LARGEFILE|linux.O_RDONLY, 0);
164 if (fd < 0) {
165 return switch (-fd) {
155 const fd_err = linux.get_errno(fd);
156 if (fd_err > 0) {
157 return switch (fd_err) {
166158 errno.EFAULT => unreachable{},
167159 errno.EINVAL => unreachable{},
168160 errno.EACCES => error.BadPerm,
......@@ -183,13 +175,14 @@ pub struct InStream {
183175 }
184176 }
185177
186 return InStream { .fd = fd, };
178 return InStream { .fd = i32(fd), };
187179 }
188180
189 pub fn read(is: &InStream, buf: []u8) -> %isize {
181 pub fn read(is: &InStream, buf: []u8) -> %usize {
190182 const amt_read = linux.read(is.fd, &buf[0], buf.len);
191 if (amt_read < 0) {
192 return switch (-amt_read) {
183 const read_err = linux.get_errno(amt_read);
184 if (read_err > 0) {
185 return switch (read_err) {
193186 errno.EINVAL => unreachable{},
194187 errno.EFAULT => unreachable{},
195188 errno.EBADF => error.BadFd,
......@@ -202,9 +195,10 @@ pub struct InStream {
202195 }
203196
204197 pub fn close(is: &InStream) -> %void {
205 const closed = linux.close(is.fd);
206 if (closed < 0) {
207 return switch (-closed) {
198 const close_ret = linux.close(is.fd);
199 const close_err = linux.get_errno(close_ret);
200 if (close_err > 0) {
201 return switch (close_err) {
208202 errno.EIO => error.Io,
209203 errno.EBADF => error.BadFd,
210204 errno.EINTR => error.SigInterrupt,
......@@ -240,7 +234,7 @@ fn char_to_digit(c: u8, radix: u8) -> %u8 {
240234 return if (value >= radix) error.InvalidChar else value;
241235}
242236
243pub fn buf_print_signed(inline T: type, out_buf: []u8, x: T) -> isize {
237pub fn buf_print_signed(inline T: type, out_buf: []u8, x: T) -> usize {
244238 const uint = @int_type(false, T.bit_count, false);
245239 if (x < 0) {
246240 out_buf[0] = '-';
......@@ -250,14 +244,14 @@ pub fn buf_print_signed(inline T: type, out_buf: []u8, x: T) -> isize {
250244 }
251245}
252246
253pub fn buf_print_i64(out_buf: []u8, x: i64) -> isize {
247pub fn buf_print_i64(out_buf: []u8, x: i64) -> usize {
254248 buf_print_signed(i64, out_buf, x)
255249}
256250
257pub fn buf_print_unsigned(inline T: type, out_buf: []u8, x: T) -> isize {
251pub fn buf_print_unsigned(inline T: type, out_buf: []u8, x: T) -> usize {
258252 var buf: [max_u64_base10_digits]u8 = undefined;
259253 var a = x;
260 var index: isize = buf.len;
254 var index: usize = buf.len;
261255
262256 while (true) {
263257 const digit = a % 10;
......@@ -275,134 +269,10 @@ pub fn buf_print_unsigned(inline T: type, out_buf: []u8, x: T) -> isize {
275269 return len;
276270}
277271
278pub fn buf_print_u64(out_buf: []u8, x: u64) -> isize {
272pub fn buf_print_u64(out_buf: []u8, x: u64) -> usize {
279273 buf_print_unsigned(u64, out_buf, x)
280274}
281275
282pub 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
406276#attribute("test")
407277fn parse_u64_digit_too_big() {
408278 parse_unsigned(u64, "123a", 10) %% |err| {
std/linux.zig+89-90
......@@ -221,66 +221,67 @@ pub const AF_VSOCK = PF_VSOCK;
221221pub const AF_MAX = PF_MAX;
222222
223223/// Get the errno from a syscall return value, or 0 for no error.
224pub fn get_errno(r: isize) -> isize {
225 if (r > -4096 && r < 0) -r else 0
224pub fn get_errno(r: usize) -> usize {
225 const signed_r = *(&isize)(&r);
226 if (signed_r > -4096 && signed_r < 0) usize(-signed_r) else 0
226227}
227228
228pub fn mmap(address: ?&u8, length: isize, prot: isize, flags: isize, fd: isize, offset: isize) -> isize {
229 arch.syscall6(arch.SYS_mmap, isize(address), length, prot, flags, fd, offset)
229pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, offset: usize) -> usize {
230 arch.syscall6(arch.SYS_mmap, usize(address), length, prot, flags, usize(fd), offset)
230231}
231232
232pub fn munmap(address: &u8, length: isize) -> isize {
233 arch.syscall2(arch.SYS_munmap, isize(address), length)
233pub fn munmap(address: &u8, length: usize) -> usize {
234 arch.syscall2(arch.SYS_munmap, usize(address), length)
234235}
235236
236pub fn read(fd: isize, buf: &u8, count: isize) -> isize {
237 arch.syscall3(arch.SYS_read, isize(fd), isize(buf), count)
237pub fn read(fd: i32, buf: &u8, count: usize) -> usize {
238 arch.syscall3(arch.SYS_read, usize(fd), usize(buf), count)
238239}
239240
240pub fn write(fd: isize, buf: &const u8, count: isize) -> isize {
241 arch.syscall3(arch.SYS_write, isize(fd), isize(buf), count)
241pub fn write(fd: i32, buf: &const u8, count: usize) -> usize {
242 arch.syscall3(arch.SYS_write, usize(fd), usize(buf), count)
242243}
243244
244pub fn open(path: []u8, flags: isize, perm: isize) -> isize {
245pub fn open(path: []u8, flags: usize, perm: usize) -> usize {
245246 var buf: [path.len + 1]u8 = undefined;
246247 @memcpy(&buf[0], &path[0], path.len);
247248 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)
249250}
250251
251pub fn create(path: []u8, perm: isize) -> isize {
252pub fn create(path: []u8, perm: usize) -> usize {
252253 var buf: [path.len + 1]u8 = undefined;
253254 @memcpy(&buf[0], &path[0], path.len);
254255 buf[path.len] = 0;
255 arch.syscall2(arch.SYS_creat, isize(&buf[0]), perm)
256 arch.syscall2(arch.SYS_creat, usize(&buf[0]), perm)
256257}
257258
258pub fn openat(dirfd: isize, path: []u8, flags: isize, mode: isize) -> isize {
259pub fn openat(dirfd: i32, path: []u8, flags: usize, mode: usize) -> usize {
259260 var buf: [path.len + 1]u8 = undefined;
260261 @memcpy(&buf[0], &path[0], path.len);
261262 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)
263264}
264265
265pub fn close(fd: isize) -> isize {
266 arch.syscall1(arch.SYS_close, fd)
266pub fn close(fd: i32) -> usize {
267 arch.syscall1(arch.SYS_close, usize(fd))
267268}
268269
269pub fn lseek(fd: isize, offset: isize, ref_pos: isize) -> isize {
270 arch.syscall3(arch.SYS_lseek, fd, offset, ref_pos)
270pub fn lseek(fd: i32, offset: usize, ref_pos: usize) -> usize {
271 arch.syscall3(arch.SYS_lseek, usize(fd), offset, ref_pos)
271272}
272273
273274pub fn exit(status: i32) -> unreachable {
274 arch.syscall1(arch.SYS_exit, isize(status));
275 arch.syscall1(arch.SYS_exit, usize(status));
275276 unreachable{}
276277}
277278
278pub fn getrandom(buf: &u8, count: isize, flags: u32) -> isize {
279 arch.syscall3(arch.SYS_getrandom, isize(buf), count, isize(flags))
279pub fn getrandom(buf: &u8, count: usize, flags: u32) -> usize {
280 arch.syscall3(arch.SYS_getrandom, usize(buf), count, usize(flags))
280281}
281282
282283pub 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)))
284285}
285286
286287const NSIG = 65;
......@@ -292,21 +293,21 @@ pub fn raise(sig: i32) -> i32 {
292293 var set: sigset_t = undefined;
293294 block_app_signals(&set);
294295 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)));
296297 restore_signals(&set);
297298 return ret;
298299}
299300
300301fn 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);
302303}
303304
304305fn 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);
306307}
307308
308309fn 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);
310311}
311312
312313
......@@ -363,98 +364,96 @@ export struct ifreq {
363364}
364365*/
365366
366pub fn getsockname(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> isize {
367 arch.syscall3(arch.SYS_getsockname, fd, isize(addr), isize(len))
367pub fn getsockname(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize {
368 arch.syscall3(arch.SYS_getsockname, usize(fd), usize(addr), usize(len))
368369}
369370
370pub fn getpeername(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> isize {
371 arch.syscall3(arch.SYS_getpeername, fd, isize(addr), isize(len))
371pub fn getpeername(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize {
372 arch.syscall3(arch.SYS_getpeername, usize(fd), usize(addr), usize(len))
372373}
373374
374pub fn socket(domain: i32, socket_type: i32, protocol: i32) -> isize {
375 arch.syscall3(arch.SYS_socket, domain, socket_type, protocol)
375pub fn socket(domain: i32, socket_type: i32, protocol: i32) -> usize {
376 arch.syscall3(arch.SYS_socket, usize(domain), usize(socket_type), usize(protocol))
376377}
377378
378pub fn setsockopt(fd: i32, level: i32, optname: i32, optval: &const u8, optlen: socklen_t) -> isize {
379 arch.syscall5(arch.SYS_setsockopt, fd, level, optname, isize(optval), isize(optlen))
379pub fn setsockopt(fd: i32, level: i32, optname: i32, optval: &const u8, optlen: socklen_t) -> usize {
380 arch.syscall5(arch.SYS_setsockopt, usize(fd), usize(level), usize(optname), usize(optval), usize(optlen))
380381}
381382
382pub fn getsockopt(fd: i32, level: i32, optname: i32, noalias optval: &u8, noalias optlen: &socklen_t) -> isize {
383 arch.syscall5(arch.SYS_getsockopt, fd, level, optname, isize(optval), isize(optlen))
383pub fn getsockopt(fd: i32, level: i32, optname: i32, noalias optval: &u8, noalias optlen: &socklen_t) -> usize {
384 arch.syscall5(arch.SYS_getsockopt, usize(fd), usize(level), usize(optname), usize(optval), usize(optlen))
384385}
385386
386pub fn sendmsg(fd: i32, msg: &const arch.msghdr, flags: i32) -> isize {
387 arch.syscall3(arch.SYS_sendmsg, fd, isize(msg), flags)
387pub fn sendmsg(fd: i32, msg: &const arch.msghdr, flags: u32) -> usize {
388 arch.syscall3(arch.SYS_sendmsg, usize(fd), usize(msg), flags)
388389}
389390
390pub fn connect(fd: i32, addr: &const sockaddr, len: socklen_t) -> isize {
391 arch.syscall3(arch.SYS_connect, fd, isize(addr), isize(len))
391pub fn connect(fd: i32, addr: &const sockaddr, len: socklen_t) -> usize {
392 arch.syscall3(arch.SYS_connect, usize(fd), usize(addr), usize(len))
392393}
393394
394pub fn recvmsg(fd: i32, msg: &arch.msghdr, flags: i32) -> isize {
395 arch.syscall3(arch.SYS_recvmsg, fd, isize(msg), flags)
395pub fn recvmsg(fd: i32, msg: &arch.msghdr, flags: u32) -> usize {
396 arch.syscall3(arch.SYS_recvmsg, usize(fd), usize(msg), flags)
396397}
397398
398pub fn recvfrom(fd: i32, noalias buf: &u8, len: isize, flags: i32,
399 noalias addr: ?&sockaddr, noalias alen: ?&socklen_t) -> isize
399pub fn recvfrom(fd: i32, noalias buf: &u8, len: usize, flags: u32,
400 noalias addr: ?&sockaddr, noalias alen: ?&socklen_t) -> usize
400401{
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))
402403}
403404
404pub fn shutdown(fd: i32, how: i32) -> isize {
405 arch.syscall2(arch.SYS_shutdown, fd, how)
405pub fn shutdown(fd: i32, how: i32) -> usize {
406 arch.syscall2(arch.SYS_shutdown, usize(fd), usize(how))
406407}
407408
408409pub 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));
410411}
411412
412pub fn listen(fd: i32, backlog: i32) -> isize {
413 arch.syscall2(arch.SYS_listen, fd, backlog)
413pub fn listen(fd: i32, backlog: i32) -> usize {
414 arch.syscall2(arch.SYS_listen, usize(fd), usize(backlog))
414415}
415416
416pub fn sendto(fd: i32, buf: &const u8, len: isize, flags: i32, addr: ?&const sockaddr, alen: socklen_t) -> isize {
417 arch.syscall6(arch.SYS_sendto, fd, isize(buf), len, flags, isize(addr), isize(alen))
417pub fn sendto(fd: i32, buf: &const u8, len: usize, flags: u32, addr: ?&const sockaddr, alen: socklen_t) -> usize {
418 arch.syscall6(arch.SYS_sendto, usize(fd), usize(buf), len, flags, usize(addr), usize(alen))
418419}
419420
420pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) -> isize {
421 arch.syscall4(arch.SYS_socketpair, domain, socket_type, protocol, isize(&fd[0]))
421pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) -> usize {
422 arch.syscall4(arch.SYS_socketpair, usize(domain), usize(socket_type), usize(protocol), usize(&fd[0]))
422423}
423424
424pub fn accept(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> isize {
425pub fn accept(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize {
425426 accept4(fd, addr, len, 0)
426427}
427428
428pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags: i32) -> isize {
429 arch.syscall4(arch.SYS_accept4, fd, isize(addr), isize(len), flags)
430}
431
432/*
433pub error NameTooLong;
434pub error SystemResources;
435pub error Io;
436
437pub fn if_nametoindex(name: []u8) -> %u32 {
438 var ifr: ifreq = undefined;
439
440 if (name.len >= ifr.ifr_name.len) {
441 return error.NameTooLong;
442 }
443
444 const socket_ret = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0);
445 const socket_err = get_errno(socket_ret);
446 if (socket_err > 0) {
447 return error.SystemResources;
448 }
449 const socket_fd = i32(socket_ret);
450 @memcpy(&ifr.ifr_name[0], &name[0], name.len);
451 ifr.ifr_name[name.len] = 0;
452 const ioctl_ret = ioctl(socket_fd, SIOCGIFINDEX, &ifr);
453 close(socket_fd);
454 const ioctl_err = get_errno(ioctl_ret);
455 if (ioctl_err > 0) {
456 return error.Io;
457 }
458 return ifr.ifr_ifindex;
459}
460*/
429pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags: u32) -> usize {
430 arch.syscall4(arch.SYS_accept4, usize(fd), usize(addr), usize(len), flags)
431}
432
433// pub error NameTooLong;
434// pub error SystemResources;
435// pub error Io;
436//
437// pub fn if_nametoindex(name: []u8) -> %u32 {
438// var ifr: ifreq = undefined;
439//
440// if (name.len >= ifr.ifr_name.len) {
441// return error.NameTooLong;
442// }
443//
444// const socket_ret = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0);
445// const socket_err = get_errno(socket_ret);
446// if (socket_err > 0) {
447// return error.SystemResources;
448// }
449// const socket_fd = i32(socket_ret);
450// @memcpy(&ifr.ifr_name[0], &name[0], name.len);
451// ifr.ifr_name[name.len] = 0;
452// const ioctl_ret = ioctl(socket_fd, SIOCGIFINDEX, &ifr);
453// close(socket_fd);
454// const ioctl_err = get_errno(ioctl_ret);
455// if (ioctl_err > 0) {
456// return error.Io;
457// }
458// return ifr.ifr_ifindex;
459// }
std/linux_i386.zig+16-16
......@@ -419,39 +419,39 @@ pub const F_GETOWN_EX = 16;
419419
420420pub const F_GETOWNER_UIDS = 17;
421421
422pub inline fn syscall0(number: isize) -> isize {
422pub inline fn syscall0(number: usize) -> usize {
423423 asm volatile ("int $0x80"
424 : [ret] "={eax}" (-> isize)
424 : [ret] "={eax}" (-> usize)
425425 : [number] "{eax}" (number))
426426}
427427
428pub inline fn syscall1(number: isize, arg1: isize) -> isize {
428pub inline fn syscall1(number: usize, arg1: usize) -> usize {
429429 asm volatile ("int $0x80"
430 : [ret] "={eax}" (-> isize)
430 : [ret] "={eax}" (-> usize)
431431 : [number] "{eax}" (number),
432432 [arg1] "{ebx}" (arg1))
433433}
434434
435pub inline fn syscall2(number: isize, arg1: isize, arg2: isize) -> isize {
435pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize {
436436 asm volatile ("int $0x80"
437 : [ret] "={eax}" (-> isize)
437 : [ret] "={eax}" (-> usize)
438438 : [number] "{eax}" (number),
439439 [arg1] "{ebx}" (arg1),
440440 [arg2] "{ecx}" (arg2))
441441}
442442
443pub inline fn syscall3(number: isize, arg1: isize, arg2: isize, arg3: isize) -> isize {
443pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize {
444444 asm volatile ("int $0x80"
445 : [ret] "={eax}" (-> isize)
445 : [ret] "={eax}" (-> usize)
446446 : [number] "{eax}" (number),
447447 [arg1] "{ebx}" (arg1),
448448 [arg2] "{ecx}" (arg2),
449449 [arg3] "{edx}" (arg3))
450450}
451451
452pub inline fn syscall4(number: isize, arg1: isize, arg2: isize, arg3: isize, arg4: isize) -> isize {
452pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) -> usize {
453453 asm volatile ("int $0x80"
454 : [ret] "={eax}" (-> isize)
454 : [ret] "={eax}" (-> usize)
455455 : [number] "{eax}" (number),
456456 [arg1] "{ebx}" (arg1),
457457 [arg2] "{ecx}" (arg2),
......@@ -459,11 +459,11 @@ pub inline fn syscall4(number: isize, arg1: isize, arg2: isize, arg3: isize, arg
459459 [arg4] "{esi}" (arg4))
460460}
461461
462pub inline fn syscall5(number: isize, arg1: isize, arg2: isize, arg3: isize,
463 arg4: isize, arg5: isize) -> isize
462pub inline fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize,
463 arg4: usize, arg5: usize) -> usize
464464{
465465 asm volatile ("int $0x80"
466 : [ret] "={eax}" (-> isize)
466 : [ret] "={eax}" (-> usize)
467467 : [number] "{eax}" (number),
468468 [arg1] "{ebx}" (arg1),
469469 [arg2] "{ecx}" (arg2),
......@@ -472,11 +472,11 @@ pub inline fn syscall5(number: isize, arg1: isize, arg2: isize, arg3: isize,
472472 [arg5] "{edi}" (arg5))
473473}
474474
475pub inline fn syscall6(number: isize, arg1: isize, arg2: isize, arg3: isize,
476 arg4: isize, arg5: isize, arg6: isize) -> isize
475pub inline fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize,
476 arg4: usize, arg5: usize, arg6: usize) -> usize
477477{
478478 asm volatile ("int $0x80"
479 : [ret] "={eax}" (-> isize)
479 : [ret] "={eax}" (-> usize)
480480 : [number] "{eax}" (number),
481481 [arg1] "{ebx}" (arg1),
482482 [arg2] "{ecx}" (arg2),
std/linux_x86_64.zig+15-15
......@@ -370,33 +370,33 @@ pub const F_GETOWN_EX = 16;
370370
371371pub const F_GETOWNER_UIDS = 17;
372372
373pub inline fn syscall0(number: isize) -> isize {
373pub inline fn syscall0(number: usize) -> usize {
374374 asm volatile ("syscall"
375 : [ret] "={rax}" (-> isize)
375 : [ret] "={rax}" (-> usize)
376376 : [number] "{rax}" (number)
377377 : "rcx", "r11")
378378}
379379
380pub inline fn syscall1(number: isize, arg1: isize) -> isize {
380pub inline fn syscall1(number: usize, arg1: usize) -> usize {
381381 asm volatile ("syscall"
382 : [ret] "={rax}" (-> isize)
382 : [ret] "={rax}" (-> usize)
383383 : [number] "{rax}" (number),
384384 [arg1] "{rdi}" (arg1)
385385 : "rcx", "r11")
386386}
387387
388pub inline fn syscall2(number: isize, arg1: isize, arg2: isize) -> isize {
388pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize {
389389 asm volatile ("syscall"
390 : [ret] "={rax}" (-> isize)
390 : [ret] "={rax}" (-> usize)
391391 : [number] "{rax}" (number),
392392 [arg1] "{rdi}" (arg1),
393393 [arg2] "{rsi}" (arg2)
394394 : "rcx", "r11")
395395}
396396
397pub inline fn syscall3(number: isize, arg1: isize, arg2: isize, arg3: isize) -> isize {
397pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize {
398398 asm volatile ("syscall"
399 : [ret] "={rax}" (-> isize)
399 : [ret] "={rax}" (-> usize)
400400 : [number] "{rax}" (number),
401401 [arg1] "{rdi}" (arg1),
402402 [arg2] "{rsi}" (arg2),
......@@ -404,9 +404,9 @@ pub inline fn syscall3(number: isize, arg1: isize, arg2: isize, arg3: isize) ->
404404 : "rcx", "r11")
405405}
406406
407pub inline fn syscall4(number: isize, arg1: isize, arg2: isize, arg3: isize, arg4: isize) -> isize {
407pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) -> usize {
408408 asm volatile ("syscall"
409 : [ret] "={rax}" (-> isize)
409 : [ret] "={rax}" (-> usize)
410410 : [number] "{rax}" (number),
411411 [arg1] "{rdi}" (arg1),
412412 [arg2] "{rsi}" (arg2),
......@@ -415,9 +415,9 @@ pub inline fn syscall4(number: isize, arg1: isize, arg2: isize, arg3: isize, arg
415415 : "rcx", "r11")
416416}
417417
418pub inline fn syscall5(number: isize, arg1: isize, arg2: isize, arg3: isize, arg4: isize, arg5: isize) -> isize {
418pub inline fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) -> usize {
419419 asm volatile ("syscall"
420 : [ret] "={rax}" (-> isize)
420 : [ret] "={rax}" (-> usize)
421421 : [number] "{rax}" (number),
422422 [arg1] "{rdi}" (arg1),
423423 [arg2] "{rsi}" (arg2),
......@@ -427,11 +427,11 @@ pub inline fn syscall5(number: isize, arg1: isize, arg2: isize, arg3: isize, arg
427427 : "rcx", "r11")
428428}
429429
430pub inline fn syscall6(number: isize, arg1: isize, arg2: isize, arg3: isize, arg4: isize,
431 arg5: isize, arg6: isize) -> isize
430pub inline fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize,
431 arg5: usize, arg6: usize) -> usize
432432{
433433 asm volatile ("syscall"
434 : [ret] "={rax}" (-> isize)
434 : [ret] "={rax}" (-> usize)
435435 : [number] "{rax}" (number),
436436 [arg1] "{rdi}" (arg1),
437437 [arg2] "{rsi}" (arg2),
std/list.zig+8-8
......@@ -6,11 +6,11 @@ pub inline fn List(inline T: type) -> type {
66 SmallList(T, 8)
77}
88
9pub struct SmallList(T: type, STATIC_SIZE: isize) {
9pub struct SmallList(T: type, STATIC_SIZE: usize) {
1010 const Self = SmallList(T, STATIC_SIZE);
1111
1212 items: []T,
13 length: isize,
13 length: usize,
1414 prealloc_items: [STATIC_SIZE]T,
1515 allocator: &Allocator,
1616
......@@ -33,7 +33,7 @@ pub struct SmallList(T: type, STATIC_SIZE: isize) {
3333 l.length = new_length;
3434 }
3535
36 pub fn ensure_capacity(l: &Self, new_capacity: isize) -> %void {
36 pub fn ensure_capacity(l: &Self, new_capacity: usize) -> %void {
3737 const old_capacity = l.items.len;
3838 var better_capacity = old_capacity;
3939 while (better_capacity < new_capacity) {
......@@ -58,15 +58,15 @@ var global_allocator = Allocator {
5858};
5959
6060var some_mem: [200]u8 = undefined;
61var some_mem_index: isize = 0;
61var some_mem_index: usize = 0;
6262
63fn global_alloc(self: &Allocator, n: isize) -> %[]u8 {
63fn global_alloc(self: &Allocator, n: usize) -> %[]u8 {
6464 const result = some_mem[some_mem_index ... some_mem_index + n];
6565 some_mem_index += n;
6666 return result;
6767}
6868
69fn global_realloc(self: &Allocator, old_mem: []u8, new_size: isize) -> %[]u8 {
69fn global_realloc(self: &Allocator, old_mem: []u8, new_size: usize) -> %[]u8 {
7070 const result = %return global_alloc(self, new_size);
7171 @memcpy(result.ptr, old_mem.ptr, old_mem.len);
7272 return result;
......@@ -81,11 +81,11 @@ fn basic_list_test() {
8181 list.init(&global_allocator);
8282 defer list.deinit();
8383
84 {var i: isize = 0; while (i < 10; i += 1) {
84 {var i: usize = 0; while (i < 10; i += 1) {
8585 %%list.append(i32(i + 1));
8686 }}
8787
88 {var i: isize = 0; while (i < 10; i += 1) {
88 {var i: usize = 0; while (i < 10; i += 1) {
8989 assert(list.items[i] == i32(i + 1));
9090 }}
9191}
std/mem.zig+7-7
......@@ -7,13 +7,13 @@ pub error NoMem;
77
88pub type Context = u8;
99pub struct Allocator {
10 alloc_fn: fn (self: &Allocator, n: isize) -> %[]u8,
11 realloc_fn: fn (self: &Allocator, old_mem: []u8, new_size: isize) -> %[]u8,
10 alloc_fn: fn (self: &Allocator, n: usize) -> %[]u8,
11 realloc_fn: fn (self: &Allocator, old_mem: []u8, new_size: usize) -> %[]u8,
1212 free_fn: fn (self: &Allocator, mem: []u8),
1313 context: ?&Context,
1414
1515 /// 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 {
1717 alloc(self, T, n) %% |err| {
1818 // TODO var args printf
1919 %%io.stderr.write("allocation failure: ");
......@@ -23,13 +23,13 @@ pub struct Allocator {
2323 }
2424 }
2525
26 fn alloc(self: &Allocator, inline T: type, n: isize) -> %[]T {
27 const byte_count = %return math.mul_overflow(isize, @sizeof(T), n);
26 fn alloc(self: &Allocator, inline T: type, n: usize) -> %[]T {
27 const byte_count = %return math.mul_overflow(usize, @sizeof(T), n);
2828 ([]T)(%return self.alloc_fn(self, byte_count))
2929 }
3030
31 fn realloc(self: &Allocator, inline T: type, old_mem: []T, n: isize) -> %[]T {
32 const byte_count = %return math.mul_overflow(isize, @sizeof(T), n);
31 fn realloc(self: &Allocator, inline T: type, old_mem: []T, n: usize) -> %[]T {
32 const byte_count = %return math.mul_overflow(usize, @sizeof(T), n);
3333 ([]T)(%return self.realloc_fn(self, ([]u8)(old_mem), byte_count))
3434 }
3535
std/net.zig+1-1
......@@ -15,7 +15,7 @@ pub error BadFd;
1515struct Connection {
1616 socket_fd: i32,
1717
18 pub fn send(c: Connection, buf: []const u8) -> %isize {
18 pub fn send(c: Connection, buf: []const u8) -> %usize {
1919 const send_ret = linux.sendto(c.socket_fd, buf.ptr, buf.len, 0, null, 0);
2020 const send_err = linux.get_errno(send_ret);
2121 switch (send_err) {
std/os.zig+4-3
......@@ -7,9 +7,10 @@ pub error Unexpected;
77pub fn get_random_bytes(buf: []u8) -> %void {
88 switch (@compile_var("os")) {
99 linux => {
10 const amt_got = linux.getrandom(buf.ptr, buf.len, 0);
11 if (amt_got < 0) {
12 return switch (-amt_got) {
10 const ret = linux.getrandom(buf.ptr, buf.len, 0);
11 const err = linux.get_errno(ret);
12 if (err > 0) {
13 return switch (err) {
1314 errno.EINVAL => unreachable{},
1415 errno.EFAULT => unreachable{},
1516 errno.EINTR => error.SigInterrupt,
std/rand.zig+3-3
......@@ -4,7 +4,7 @@ const ARRAY_SIZE = 624;
44/// Use `init` to initialize this state.
55pub struct Rand {
66 array: [ARRAY_SIZE]u32,
7 index: isize,
7 index: usize,
88
99 /// Initialize random state with the given seed.
1010 #static_eval_enable(false)
......@@ -12,7 +12,7 @@ pub struct Rand {
1212 var r: Rand = undefined;
1313 r.index = 0;
1414 r.array[0] = seed;
15 var i : isize = 1;
15 var i : usize = 1;
1616 var prev_value: u64w = seed;
1717 while (i < ARRAY_SIZE; i += 1) {
1818 r.array[i] = @truncate(u32, (prev_value ^ (prev_value << 30)) * 0x6c078965 + u64w(i));
......@@ -91,7 +91,7 @@ pub struct Rand {
9191 }
9292
9393 // 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 {
9595 var bytes_left = buf.len;
9696 while (bytes_left >= 4) {
9797 *((&u32)(&buf[buf.len - bytes_left])) = r.get_u32();
std/test_runner.zig+2-2
......@@ -11,9 +11,9 @@ pub fn run_tests() -> %void {
1111 for (zig_test_fn_list) |test_fn, i| {
1212 // TODO: print var args
1313 %%io.stderr.write("Test ");
14 %%io.stderr.print_i64(i + 1);
14 %%io.stderr.print_u64(i + 1);
1515 %%io.stderr.write("/");
16 %%io.stderr.print_i64(zig_test_fn_list.len);
16 %%io.stderr.print_u64(zig_test_fn_list.len);
1717 %%io.stderr.write(" ");
1818 %%io.stderr.write(test_fn.name);
1919 %%io.stderr.write("...");
test/run_tests.cpp+7-7
......@@ -466,7 +466,7 @@ pub fn main(args: [][]u8) -> %void {
466466 %%io.stdout.printf("\n");
467467 }
468468 for (array) |item, index| {
469 %%io.stdout.print_i64(index);
469 %%io.stdout.print_u64(index);
470470 %%io.stdout.printf("\n");
471471 }
472472 const unknown_size: []u8 = array;
......@@ -475,7 +475,7 @@ pub fn main(args: [][]u8) -> %void {
475475 %%io.stdout.printf("\n");
476476 }
477477 for (unknown_size) |item, index| {
478 %%io.stdout.print_i64(index);
478 %%io.stdout.print_u64(index);
479479 %%io.stdout.printf("\n");
480480 }
481481}
......@@ -497,7 +497,7 @@ export fn compare_fn(a: ?&const c_void, b: ?&const c_void) -> c_int {
497497}
498498
499499export 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 };
501501
502502 c.qsort((&c_void)(&array[0]), c_ulong(array.len), @sizeof(i32), compare_fn);
503503
......@@ -816,7 +816,7 @@ fn f() {
816816 )SOURCE", 4, ".tmp_source.zig:4:5: error: use of undeclared identifier 'i'",
817817 ".tmp_source.zig:4:7: error: use of undeclared identifier 'i'",
818818 ".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'");
820820
821821 add_compile_fail_case("variadic functions only allowed in extern", R"SOURCE(
822822fn f(...) {}
......@@ -1115,8 +1115,8 @@ fn a(x: i32) {
11151115struct Foo {
11161116 y: [get()]u8,
11171117}
1118var global_var: isize = 1;
1119fn get() -> isize { global_var }
1118var global_var: usize = 1;
1119fn get() -> usize { global_var }
11201120 )SOURCE", 1, ".tmp_source.zig:3:9: error: unable to evaluate constant expression");
11211121
11221122
......@@ -1397,7 +1397,7 @@ pub fn main(args: [][]u8) { }
13971397
13981398
13991399 add_compile_fail_case("invalid pointer for var type", R"SOURCE(
1400extern fn ext() -> isize;
1400extern fn ext() -> usize;
14011401var bytes: [ext()]u8 = undefined;
14021402fn f() {
14031403 for (bytes) |*b, i| {
test/self_hosted.zig+11-11
......@@ -96,16 +96,16 @@ fn mutable_local_variables() {
9696
9797#attribute("test")
9898fn arrays() {
99 var array : [5]i32 = undefined;
99 var array : [5]u32 = undefined;
100100
101 var i : i32 = 0;
101 var i : u32 = 0;
102102 while (i < 5) {
103103 array[i] = i + 1;
104104 i = array[i];
105105 }
106106
107107 i = 0;
108 var accumulator = i32(0);
108 var accumulator = u32(0);
109109 while (i < 5) {
110110 accumulator += array[i];
111111
......@@ -115,7 +115,7 @@ fn arrays() {
115115 assert(accumulator == 15);
116116 assert(get_array_len(array) == 5);
117117}
118fn get_array_len(a: []i32) -> isize {
118fn get_array_len(a: []u32) -> usize {
119119 a.len
120120}
121121
......@@ -742,7 +742,7 @@ fn generic_malloc_free() {
742742}
743743const some_mem : [100]u8 = undefined;
744744#static_eval_enable(false)
745fn mem_alloc(inline T: type, n: isize) -> %[]T {
745fn mem_alloc(inline T: type, n: usize) -> %[]T {
746746 return (&T)(&some_mem[0])[0...n];
747747}
748748fn mem_free(inline T: type, mem: []T) { }
......@@ -823,10 +823,10 @@ fn test_cast_undefined(x: []u8) {}
823823#attribute("test")
824824fn cast_small_unsigned_to_larger_signed() {
825825 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));
827827}
828828fn cast_small_unsigned_to_larger_signed_1(x: u8) -> i16 { x }
829fn cast_small_unsigned_to_larger_signed_2(x: u16) -> isize { x }
829fn cast_small_unsigned_to_larger_signed_2(x: u16) -> i64 { x }
830830
831831
832832#attribute("test")
......@@ -834,7 +834,7 @@ fn implicit_cast_after_unreachable() {
834834 assert(outer() == 1234);
835835}
836836fn inner() -> i32 { 1234 }
837fn outer() -> isize {
837fn outer() -> i64 {
838838 return inner();
839839}
840840
......@@ -1029,7 +1029,7 @@ fn constant_expressions() {
10291029 var array : [ARRAY_SIZE]u8 = undefined;
10301030 assert(@sizeof(@typeof(array)) == 20);
10311031}
1032const ARRAY_SIZE : i8 = 20;
1032const ARRAY_SIZE : u8 = 20;
10331033
10341034
10351035#attribute("test")
......@@ -1315,7 +1315,7 @@ fn test_return_empty_struct_from_fn_noeval() -> EmptyStruct2 {
13151315fn pass_slice_of_empty_struct_to_fn() {
13161316 assert(test_pass_slice_of_empty_struct_to_fn([]EmptyStruct2{ EmptyStruct2{} }) == 1);
13171317}
1318fn test_pass_slice_of_empty_struct_to_fn(slice: []EmptyStruct2) -> isize {
1318fn test_pass_slice_of_empty_struct_to_fn(slice: []EmptyStruct2) -> usize {
13191319 slice.len
13201320}
13211321
......@@ -1555,7 +1555,7 @@ fn c_string_concatenation() {
15551555
15561556 const len = cstr.len(b);
15571557 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) {
15591559 assert(a[i] == b[i]);
15601560 }}
15611561 assert(a[len] == 0);