| author | |
| committer | |
| log | 5a919dd82d798c489219ea60a59f1c0ea3fc3956 |
| tree | 4fd8ca25bfa73d842b803353a8aa80a510072829 |
| parent | 10d2f08d376a302bd79e87d17c06922d3145a939 |
| parent | 99153ac0aa390f01091308073b39947c45851ae6 |
15 files changed, 683 insertions(+), 387 deletions(-)
CMakeLists.txt+1-1| ... | @@ -556,7 +556,7 @@ set(ZIG_STD_FILES | ... | @@ -556,7 +556,7 @@ set(ZIG_STD_FILES |
| 556 | "net.zig" | 556 | "net.zig" |
| 557 | "os/child_process.zig" | 557 | "os/child_process.zig" |
| 558 | "os/darwin.zig" | 558 | "os/darwin.zig" |
| 559 | "os/darwin_errno.zig" | 559 | "os/darwin/errno.zig" |
| 560 | "os/epoch.zig" | 560 | "os/epoch.zig" |
| 561 | "os/file.zig" | 561 | "os/file.zig" |
| 562 | "os/get_app_data_dir.zig" | 562 | "os/get_app_data_dir.zig" |
README.md+1-1| ... | @@ -70,7 +70,7 @@ that counts as "freestanding" for the purposes of this table. | ... | @@ -70,7 +70,7 @@ that counts as "freestanding" for the purposes of this table. |
| 70 | 70 | ||
| 71 | ## Community | 71 | ## Community |
| 72 | 72 | ||
| 73 | * IRC: `#zig` on Freenode. | 73 | * IRC: `#zig` on Freenode ([Channel Logs](https://irclog.whitequark.org/zig/)). |
| 74 | * Reddit: [/r/zig](https://www.reddit.com/r/zig) | 74 | * Reddit: [/r/zig](https://www.reddit.com/r/zig) |
| 75 | * Email list: [ziglang@googlegroups.com](https://groups.google.com/forum/#!forum/ziglang) | 75 | * Email list: [ziglang@googlegroups.com](https://groups.google.com/forum/#!forum/ziglang) |
| 76 | 76 |
src-self-hosted/ir.zig+1-2| ... | @@ -2172,8 +2172,7 @@ const Analyze = struct { | ... | @@ -2172,8 +2172,7 @@ const Analyze = struct { |
| 2172 | break :fits true; | 2172 | break :fits true; |
| 2173 | } | 2173 | } |
| 2174 | if (dest_type.cast(Type.Int)) |int| { | 2174 | if (dest_type.cast(Type.Int)) |int| { |
| 2175 | break :fits (from_int.positive or from_int.eqZero() or int.key.is_signed) and | 2175 | break :fits from_int.fitsInTwosComp(int.key.is_signed, int.key.bit_count); |
| 2176 | int.key.bit_count >= from_int.bitcount(); | ||
| 2177 | } | 2176 | } |
| 2178 | break :cast; | 2177 | break :cast; |
| 2179 | }; | 2178 | }; |
src/codegen.cpp+31| ... | @@ -60,6 +60,33 @@ PackageTableEntry *new_anonymous_package(void) { | ... | @@ -60,6 +60,33 @@ PackageTableEntry *new_anonymous_package(void) { |
| 60 | return new_package("", ""); | 60 | return new_package("", ""); |
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | static const char *symbols_that_llvm_depends_on[] = { | ||
| 64 | "memcpy", | ||
| 65 | "memset", | ||
| 66 | "sqrt", | ||
| 67 | "powi", | ||
| 68 | "sin", | ||
| 69 | "cos", | ||
| 70 | "pow", | ||
| 71 | "exp", | ||
| 72 | "exp2", | ||
| 73 | "log", | ||
| 74 | "log10", | ||
| 75 | "log2", | ||
| 76 | "fma", | ||
| 77 | "fabs", | ||
| 78 | "minnum", | ||
| 79 | "maxnum", | ||
| 80 | "copysign", | ||
| 81 | "floor", | ||
| 82 | "ceil", | ||
| 83 | "trunc", | ||
| 84 | "rint", | ||
| 85 | "nearbyint", | ||
| 86 | "round", | ||
| 87 | // TODO probably all of compiler-rt needs to go here | ||
| 88 | }; | ||
| 89 | |||
| 63 | CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out_type, BuildMode build_mode, | 90 | CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out_type, BuildMode build_mode, |
| 64 | Buf *zig_lib_dir) | 91 | Buf *zig_lib_dir) |
| 65 | { | 92 | { |
| ... | @@ -94,6 +121,10 @@ CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out | ... | @@ -94,6 +121,10 @@ CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out |
| 94 | g->want_h_file = (out_type == OutTypeObj || out_type == OutTypeLib); | 121 | g->want_h_file = (out_type == OutTypeObj || out_type == OutTypeLib); |
| 95 | buf_resize(&g->global_asm, 0); | 122 | buf_resize(&g->global_asm, 0); |
| 96 | 123 | ||
| 124 | for (size_t i = 0; i < array_length(symbols_that_llvm_depends_on); i += 1) { | ||
| 125 | g->external_prototypes.put(buf_create_from_str(symbols_that_llvm_depends_on[i]), nullptr); | ||
| 126 | } | ||
| 127 | |||
| 97 | if (root_src_path) { | 128 | if (root_src_path) { |
| 98 | Buf *src_basename = buf_alloc(); | 129 | Buf *src_basename = buf_alloc(); |
| 99 | Buf *src_dir = buf_alloc(); | 130 | Buf *src_dir = buf_alloc(); |
src/ir.cpp+59-25| ... | @@ -2961,16 +2961,34 @@ static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_sco | ... | @@ -2961,16 +2961,34 @@ static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_sco |
| 2961 | results[ReturnKindUnconditional] = 0; | 2961 | results[ReturnKindUnconditional] = 0; |
| 2962 | results[ReturnKindError] = 0; | 2962 | results[ReturnKindError] = 0; |
| 2963 | 2963 | ||
| 2964 | while (inner_scope != outer_scope) { | 2964 | Scope *scope = inner_scope; |
| 2965 | assert(inner_scope); | ||
| 2966 | if (inner_scope->id == ScopeIdDefer) { | ||
| 2967 | AstNode *defer_node = inner_scope->source_node; | ||
| 2968 | assert(defer_node->type == NodeTypeDefer); | ||
| 2969 | ReturnKind defer_kind = defer_node->data.defer.kind; | ||
| 2970 | results[defer_kind] += 1; | ||
| 2971 | 2965 | ||
| 2966 | while (scope != outer_scope) { | ||
| 2967 | assert(scope); | ||
| 2968 | switch (scope->id) { | ||
| 2969 | case ScopeIdDefer: { | ||
| 2970 | AstNode *defer_node = scope->source_node; | ||
| 2971 | assert(defer_node->type == NodeTypeDefer); | ||
| 2972 | ReturnKind defer_kind = defer_node->data.defer.kind; | ||
| 2973 | results[defer_kind] += 1; | ||
| 2974 | scope = scope->parent; | ||
| 2975 | continue; | ||
| 2976 | } | ||
| 2977 | case ScopeIdDecls: | ||
| 2978 | case ScopeIdFnDef: | ||
| 2979 | return; | ||
| 2980 | case ScopeIdBlock: | ||
| 2981 | case ScopeIdVarDecl: | ||
| 2982 | case ScopeIdLoop: | ||
| 2983 | case ScopeIdSuspend: | ||
| 2984 | case ScopeIdCompTime: | ||
| 2985 | scope = scope->parent; | ||
| 2986 | continue; | ||
| 2987 | case ScopeIdDeferExpr: | ||
| 2988 | case ScopeIdCImport: | ||
| 2989 | case ScopeIdCoroPrelude: | ||
| 2990 | zig_unreachable(); | ||
| 2972 | } | 2991 | } |
| 2973 | inner_scope = inner_scope->parent; | ||
| 2974 | } | 2992 | } |
| 2975 | } | 2993 | } |
| 2976 | 2994 | ||
| ... | @@ -2986,27 +3004,43 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o | ... | @@ -2986,27 +3004,43 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o |
| 2986 | if (!scope) | 3004 | if (!scope) |
| 2987 | return is_noreturn; | 3005 | return is_noreturn; |
| 2988 | 3006 | ||
| 2989 | if (scope->id == ScopeIdDefer) { | 3007 | switch (scope->id) { |
| 2990 | AstNode *defer_node = scope->source_node; | 3008 | case ScopeIdDefer: { |
| 2991 | assert(defer_node->type == NodeTypeDefer); | 3009 | AstNode *defer_node = scope->source_node; |
| 2992 | ReturnKind defer_kind = defer_node->data.defer.kind; | 3010 | assert(defer_node->type == NodeTypeDefer); |
| 2993 | if (defer_kind == ReturnKindUnconditional || | 3011 | ReturnKind defer_kind = defer_node->data.defer.kind; |
| 2994 | (gen_error_defers && defer_kind == ReturnKindError)) | 3012 | if (defer_kind == ReturnKindUnconditional || |
| 2995 | { | 3013 | (gen_error_defers && defer_kind == ReturnKindError)) |
| 2996 | AstNode *defer_expr_node = defer_node->data.defer.expr; | 3014 | { |
| 2997 | Scope *defer_expr_scope = defer_node->data.defer.expr_scope; | 3015 | AstNode *defer_expr_node = defer_node->data.defer.expr; |
| 2998 | IrInstruction *defer_expr_value = ir_gen_node(irb, defer_expr_node, defer_expr_scope); | 3016 | Scope *defer_expr_scope = defer_node->data.defer.expr_scope; |
| 2999 | if (defer_expr_value != irb->codegen->invalid_instruction) { | 3017 | IrInstruction *defer_expr_value = ir_gen_node(irb, defer_expr_node, defer_expr_scope); |
| 3000 | if (defer_expr_value->value.type != nullptr && defer_expr_value->value.type->id == TypeTableEntryIdUnreachable) { | 3018 | if (defer_expr_value != irb->codegen->invalid_instruction) { |
| 3001 | is_noreturn = true; | 3019 | if (defer_expr_value->value.type != nullptr && defer_expr_value->value.type->id == TypeTableEntryIdUnreachable) { |
| 3002 | } else { | 3020 | is_noreturn = true; |
| 3003 | ir_mark_gen(ir_build_check_statement_is_void(irb, defer_expr_scope, defer_expr_node, defer_expr_value)); | 3021 | } else { |
| 3022 | ir_mark_gen(ir_build_check_statement_is_void(irb, defer_expr_scope, defer_expr_node, defer_expr_value)); | ||
| 3023 | } | ||
| 3004 | } | 3024 | } |
| 3005 | } | 3025 | } |
| 3026 | scope = scope->parent; | ||
| 3027 | continue; | ||
| 3006 | } | 3028 | } |
| 3007 | 3029 | case ScopeIdDecls: | |
| 3030 | case ScopeIdFnDef: | ||
| 3031 | return is_noreturn; | ||
| 3032 | case ScopeIdBlock: | ||
| 3033 | case ScopeIdVarDecl: | ||
| 3034 | case ScopeIdLoop: | ||
| 3035 | case ScopeIdSuspend: | ||
| 3036 | case ScopeIdCompTime: | ||
| 3037 | scope = scope->parent; | ||
| 3038 | continue; | ||
| 3039 | case ScopeIdDeferExpr: | ||
| 3040 | case ScopeIdCImport: | ||
| 3041 | case ScopeIdCoroPrelude: | ||
| 3042 | zig_unreachable(); | ||
| 3008 | } | 3043 | } |
| 3009 | scope = scope->parent; | ||
| 3010 | } | 3044 | } |
| 3011 | return is_noreturn; | 3045 | return is_noreturn; |
| 3012 | } | 3046 | } |
std/c/darwin.zig+1-1| ... | @@ -30,7 +30,7 @@ pub extern "c" fn sysctl(name: [*]c_int, namelen: c_uint, oldp: ?*c_void, oldlen | ... | @@ -30,7 +30,7 @@ pub extern "c" fn sysctl(name: [*]c_int, namelen: c_uint, oldp: ?*c_void, oldlen |
| 30 | pub extern "c" fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int; | 30 | pub extern "c" fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int; |
| 31 | pub extern "c" fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) c_int; | 31 | pub extern "c" fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) c_int; |
| 32 | 32 | ||
| 33 | pub use @import("../os/darwin_errno.zig"); | 33 | pub use @import("../os/darwin/errno.zig"); |
| 34 | 34 | ||
| 35 | pub const _errno = __error; | 35 | pub const _errno = __error; |
| 36 | 36 |
std/event/tcp.zig+2-1| ... | @@ -125,8 +125,9 @@ pub async fn connect(loop: *Loop, _address: *const std.net.Address) !std.os.File | ... | @@ -125,8 +125,9 @@ pub async fn connect(loop: *Loop, _address: *const std.net.Address) !std.os.File |
| 125 | test "listen on a port, send bytes, receive bytes" { | 125 | test "listen on a port, send bytes, receive bytes" { |
| 126 | if (builtin.os != builtin.Os.linux) { | 126 | if (builtin.os != builtin.Os.linux) { |
| 127 | // TODO build abstractions for other operating systems | 127 | // TODO build abstractions for other operating systems |
| 128 | return; | 128 | return error.SkipZigTest; |
| 129 | } | 129 | } |
| 130 | |||
| 130 | const MyServer = struct { | 131 | const MyServer = struct { |
| 131 | tcp_server: Server, | 132 | tcp_server: Server, |
| 132 | 133 |
std/math/big/int.zig+134-12| ... | @@ -116,13 +116,63 @@ pub const Int = struct { | ... | @@ -116,13 +116,63 @@ pub const Int = struct { |
| 116 | return !r.isOdd(); | 116 | return !r.isOdd(); |
| 117 | } | 117 | } |
| 118 | 118 | ||
| 119 | fn bitcount(self: Int) usize { | 119 | // Returns the number of bits required to represent the absolute value of self. |
| 120 | const u_bit_count = (self.len - 1) * Limb.bit_count + (Limb.bit_count - @clz(self.limbs[self.len - 1])); | 120 | fn bitCountAbs(self: Int) usize { |
| 121 | return @boolToInt(!self.positive) + u_bit_count; | 121 | return (self.len - 1) * Limb.bit_count + (Limb.bit_count - @clz(self.limbs[self.len - 1])); |
| 122 | } | 122 | } |
| 123 | 123 | ||
| 124 | // Returns the number of bits required to represent the integer in twos-complement form. | ||
| 125 | // | ||
| 126 | // If the integer is negative the value returned is the number of bits needed by a signed | ||
| 127 | // integer to represent the value. If positive the value is the number of bits for an | ||
| 128 | // unsigned integer. Any unsigned integer will fit in the signed integer with bitcount | ||
| 129 | // one greater than the returned value. | ||
| 130 | // | ||
| 131 | // e.g. -127 returns 8 as it will fit in an i8. 127 returns 7 since it fits in a u7. | ||
| 132 | fn bitCountTwosComp(self: Int) usize { | ||
| 133 | var bits = self.bitCountAbs(); | ||
| 134 | |||
| 135 | // If the entire value has only one bit set (e.g. 0b100000000) then the negation in twos | ||
| 136 | // complement requires one less bit. | ||
| 137 | if (!self.positive) block: { | ||
| 138 | bits += 1; | ||
| 139 | |||
| 140 | if (@popCount(self.limbs[self.len - 1]) == 1) { | ||
| 141 | for (self.limbs[0 .. self.len - 1]) |limb| { | ||
| 142 | if (@popCount(limb) != 0) { | ||
| 143 | break :block; | ||
| 144 | } | ||
| 145 | } | ||
| 146 | |||
| 147 | bits -= 1; | ||
| 148 | } | ||
| 149 | } | ||
| 150 | |||
| 151 | return bits; | ||
| 152 | } | ||
| 153 | |||
| 154 | pub fn fitsInTwosComp(self: Int, is_signed: bool, bit_count: usize) bool { | ||
| 155 | if (self.eqZero()) { | ||
| 156 | return true; | ||
| 157 | } | ||
| 158 | if (!is_signed and !self.positive) { | ||
| 159 | return false; | ||
| 160 | } | ||
| 161 | |||
| 162 | const req_bits = self.bitCountTwosComp() + @boolToInt(self.positive and is_signed); | ||
| 163 | return bit_count >= req_bits; | ||
| 164 | } | ||
| 165 | |||
| 166 | pub fn fits(self: Int, comptime T: type) bool { | ||
| 167 | return self.fitsInTwosComp(T.is_signed, T.bit_count); | ||
| 168 | } | ||
| 169 | |||
| 170 | // Returns the approximate size of the integer in the given base. Negative values accomodate for | ||
| 171 | // the minus sign. This is used for determining the number of characters needed to print the | ||
| 172 | // value. It is inexact and will exceed the given value by 1-2 digits. | ||
| 124 | pub fn sizeInBase(self: Int, base: usize) usize { | 173 | pub fn sizeInBase(self: Int, base: usize) usize { |
| 125 | return (self.bitcount() / math.log2(base)) + 1; | 174 | const bit_count = usize(@boolToInt(!self.positive)) + self.bitCountAbs(); |
| 175 | return (bit_count / math.log2(base)) + 1; | ||
| 126 | } | 176 | } |
| 127 | 177 | ||
| 128 | pub fn set(self: *Int, value: var) Allocator.Error!void { | 178 | pub fn set(self: *Int, value: var) Allocator.Error!void { |
| ... | @@ -190,9 +240,9 @@ pub const Int = struct { | ... | @@ -190,9 +240,9 @@ pub const Int = struct { |
| 190 | pub fn to(self: Int, comptime T: type) ConvertError!T { | 240 | pub fn to(self: Int, comptime T: type) ConvertError!T { |
| 191 | switch (@typeId(T)) { | 241 | switch (@typeId(T)) { |
| 192 | TypeId.Int => { | 242 | TypeId.Int => { |
| 193 | const UT = if (T.is_signed) @IntType(false, T.bit_count - 1) else T; | 243 | const UT = @IntType(false, T.bit_count); |
| 194 | 244 | ||
| 195 | if (self.bitcount() > 8 * @sizeOf(UT)) { | 245 | if (self.bitCountTwosComp() > T.bit_count) { |
| 196 | return error.TargetTooSmall; | 246 | return error.TargetTooSmall; |
| 197 | } | 247 | } |
| 198 | 248 | ||
| ... | @@ -209,9 +259,17 @@ pub const Int = struct { | ... | @@ -209,9 +259,17 @@ pub const Int = struct { |
| 209 | } | 259 | } |
| 210 | 260 | ||
| 211 | if (!T.is_signed) { | 261 | if (!T.is_signed) { |
| 212 | return if (self.positive) r else error.NegativeIntoUnsigned; | 262 | return if (self.positive) @intCast(T, r) else error.NegativeIntoUnsigned; |
| 213 | } else { | 263 | } else { |
| 214 | return if (self.positive) @intCast(T, r) else -@intCast(T, r); | 264 | if (self.positive) { |
| 265 | return @intCast(T, r); | ||
| 266 | } else { | ||
| 267 | if (math.cast(T, r)) |ok| { | ||
| 268 | return -ok; | ||
| 269 | } else |_| { | ||
| 270 | return @minValue(T); | ||
| 271 | } | ||
| 272 | } | ||
| 215 | } | 273 | } |
| 216 | }, | 274 | }, |
| 217 | else => { | 275 | else => { |
| ... | @@ -1137,24 +1195,88 @@ test "big.int bitcount + sizeInBase" { | ... | @@ -1137,24 +1195,88 @@ test "big.int bitcount + sizeInBase" { |
| 1137 | var a = try Int.init(al); | 1195 | var a = try Int.init(al); |
| 1138 | 1196 | ||
| 1139 | try a.set(0b100); | 1197 | try a.set(0b100); |
| 1140 | debug.assert(a.bitcount() == 3); | 1198 | debug.assert(a.bitCountAbs() == 3); |
| 1141 | debug.assert(a.sizeInBase(2) >= 3); | 1199 | debug.assert(a.sizeInBase(2) >= 3); |
| 1142 | debug.assert(a.sizeInBase(10) >= 1); | 1200 | debug.assert(a.sizeInBase(10) >= 1); |
| 1143 | 1201 | ||
| 1202 | a.negate(); | ||
| 1203 | debug.assert(a.bitCountAbs() == 3); | ||
| 1204 | debug.assert(a.sizeInBase(2) >= 4); | ||
| 1205 | debug.assert(a.sizeInBase(10) >= 2); | ||
| 1206 | |||
| 1144 | try a.set(0xffffffff); | 1207 | try a.set(0xffffffff); |
| 1145 | debug.assert(a.bitcount() == 32); | 1208 | debug.assert(a.bitCountAbs() == 32); |
| 1146 | debug.assert(a.sizeInBase(2) >= 32); | 1209 | debug.assert(a.sizeInBase(2) >= 32); |
| 1147 | debug.assert(a.sizeInBase(10) >= 10); | 1210 | debug.assert(a.sizeInBase(10) >= 10); |
| 1148 | 1211 | ||
| 1149 | try a.shiftLeft(a, 5000); | 1212 | try a.shiftLeft(a, 5000); |
| 1150 | debug.assert(a.bitcount() == 5032); | 1213 | debug.assert(a.bitCountAbs() == 5032); |
| 1151 | debug.assert(a.sizeInBase(2) >= 5032); | 1214 | debug.assert(a.sizeInBase(2) >= 5032); |
| 1152 | a.positive = false; | 1215 | a.positive = false; |
| 1153 | 1216 | ||
| 1154 | debug.assert(a.bitcount() == 5033); | 1217 | debug.assert(a.bitCountAbs() == 5032); |
| 1155 | debug.assert(a.sizeInBase(2) >= 5033); | 1218 | debug.assert(a.sizeInBase(2) >= 5033); |
| 1156 | } | 1219 | } |
| 1157 | 1220 | ||
| 1221 | test "big.int bitcount/to" { | ||
| 1222 | var a = try Int.init(al); | ||
| 1223 | |||
| 1224 | try a.set(0); | ||
| 1225 | debug.assert(a.bitCountTwosComp() == 0); | ||
| 1226 | |||
| 1227 | // TODO: stack smashing | ||
| 1228 | // debug.assert((try a.to(u0)) == 0); | ||
| 1229 | // TODO: sigsegv | ||
| 1230 | // debug.assert((try a.to(i0)) == 0); | ||
| 1231 | |||
| 1232 | try a.set(-1); | ||
| 1233 | debug.assert(a.bitCountTwosComp() == 1); | ||
| 1234 | debug.assert((try a.to(i1)) == -1); | ||
| 1235 | |||
| 1236 | try a.set(-8); | ||
| 1237 | debug.assert(a.bitCountTwosComp() == 4); | ||
| 1238 | debug.assert((try a.to(i4)) == -8); | ||
| 1239 | |||
| 1240 | try a.set(127); | ||
| 1241 | debug.assert(a.bitCountTwosComp() == 7); | ||
| 1242 | debug.assert((try a.to(u7)) == 127); | ||
| 1243 | |||
| 1244 | try a.set(-128); | ||
| 1245 | debug.assert(a.bitCountTwosComp() == 8); | ||
| 1246 | debug.assert((try a.to(i8)) == -128); | ||
| 1247 | |||
| 1248 | try a.set(-129); | ||
| 1249 | debug.assert(a.bitCountTwosComp() == 9); | ||
| 1250 | debug.assert((try a.to(i9)) == -129); | ||
| 1251 | } | ||
| 1252 | |||
| 1253 | test "big.int fits" { | ||
| 1254 | var a = try Int.init(al); | ||
| 1255 | |||
| 1256 | try a.set(0); | ||
| 1257 | debug.assert(a.fits(u0)); | ||
| 1258 | debug.assert(a.fits(i0)); | ||
| 1259 | |||
| 1260 | try a.set(255); | ||
| 1261 | debug.assert(!a.fits(u0)); | ||
| 1262 | debug.assert(!a.fits(u1)); | ||
| 1263 | debug.assert(!a.fits(i8)); | ||
| 1264 | debug.assert(a.fits(u8)); | ||
| 1265 | debug.assert(a.fits(u9)); | ||
| 1266 | debug.assert(a.fits(i9)); | ||
| 1267 | |||
| 1268 | try a.set(-128); | ||
| 1269 | debug.assert(!a.fits(i7)); | ||
| 1270 | debug.assert(a.fits(i8)); | ||
| 1271 | debug.assert(a.fits(i9)); | ||
| 1272 | debug.assert(!a.fits(u9)); | ||
| 1273 | |||
| 1274 | try a.set(0x1ffffffffeeeeeeee); | ||
| 1275 | debug.assert(!a.fits(u32)); | ||
| 1276 | debug.assert(!a.fits(u64)); | ||
| 1277 | debug.assert(a.fits(u65)); | ||
| 1278 | } | ||
| 1279 | |||
| 1158 | test "big.int string set" { | 1280 | test "big.int string set" { |
| 1159 | var a = try Int.init(al); | 1281 | var a = try Int.init(al); |
| 1160 | try a.setString(10, "120317241209124781241290847124"); | 1282 | try a.setString(10, "120317241209124781241290847124"); |
std/os/darwin.zig+87-1| ... | @@ -2,7 +2,7 @@ const std = @import("../index.zig"); | ... | @@ -2,7 +2,7 @@ const std = @import("../index.zig"); |
| 2 | const c = std.c; | 2 | const c = std.c; |
| 3 | const assert = std.debug.assert; | 3 | const assert = std.debug.assert; |
| 4 | 4 | ||
| 5 | pub use @import("darwin_errno.zig"); | 5 | pub use @import("darwin/errno.zig"); |
| 6 | 6 | ||
| 7 | pub const PATH_MAX = 1024; | 7 | pub const PATH_MAX = 1024; |
| 8 | 8 | ||
| ... | @@ -482,6 +482,92 @@ pub const NOTE_MACH_CONTINUOUS_TIME = 0x00000080; | ... | @@ -482,6 +482,92 @@ pub const NOTE_MACH_CONTINUOUS_TIME = 0x00000080; |
| 482 | /// data is mach absolute time units | 482 | /// data is mach absolute time units |
| 483 | pub const NOTE_MACHTIME = 0x00000100; | 483 | pub const NOTE_MACHTIME = 0x00000100; |
| 484 | 484 | ||
| 485 | pub const AF_UNSPEC: c_int = 0; | ||
| 486 | pub const AF_LOCAL: c_int = 1; | ||
| 487 | pub const AF_UNIX: c_int = AF_LOCAL; | ||
| 488 | pub const AF_INET: c_int = 2; | ||
| 489 | pub const AF_SYS_CONTROL: c_int = 2; | ||
| 490 | pub const AF_IMPLINK: c_int = 3; | ||
| 491 | pub const AF_PUP: c_int = 4; | ||
| 492 | pub const AF_CHAOS: c_int = 5; | ||
| 493 | pub const AF_NS: c_int = 6; | ||
| 494 | pub const AF_ISO: c_int = 7; | ||
| 495 | pub const AF_OSI: c_int = AF_ISO; | ||
| 496 | pub const AF_ECMA: c_int = 8; | ||
| 497 | pub const AF_DATAKIT: c_int = 9; | ||
| 498 | pub const AF_CCITT: c_int = 10; | ||
| 499 | pub const AF_SNA: c_int = 11; | ||
| 500 | pub const AF_DECnet: c_int = 12; | ||
| 501 | pub const AF_DLI: c_int = 13; | ||
| 502 | pub const AF_LAT: c_int = 14; | ||
| 503 | pub const AF_HYLINK: c_int = 15; | ||
| 504 | pub const AF_APPLETALK: c_int = 16; | ||
| 505 | pub const AF_ROUTE: c_int = 17; | ||
| 506 | pub const AF_LINK: c_int = 18; | ||
| 507 | pub const AF_XTP: c_int = 19; | ||
| 508 | pub const AF_COIP: c_int = 20; | ||
| 509 | pub const AF_CNT: c_int = 21; | ||
| 510 | pub const AF_RTIP: c_int = 22; | ||
| 511 | pub const AF_IPX: c_int = 23; | ||
| 512 | pub const AF_SIP: c_int = 24; | ||
| 513 | pub const AF_PIP: c_int = 25; | ||
| 514 | pub const AF_ISDN: c_int = 28; | ||
| 515 | pub const AF_E164: c_int = AF_ISDN; | ||
| 516 | pub const AF_KEY: c_int = 29; | ||
| 517 | pub const AF_INET6: c_int = 30; | ||
| 518 | pub const AF_NATM: c_int = 31; | ||
| 519 | pub const AF_SYSTEM: c_int = 32; | ||
| 520 | pub const AF_NETBIOS: c_int = 33; | ||
| 521 | pub const AF_PPP: c_int = 34; | ||
| 522 | pub const AF_MAX: c_int = 40; | ||
| 523 | |||
| 524 | pub const PF_UNSPEC: c_int = AF_UNSPEC; | ||
| 525 | pub const PF_LOCAL: c_int = AF_LOCAL; | ||
| 526 | pub const PF_UNIX: c_int = PF_LOCAL; | ||
| 527 | pub const PF_INET: c_int = AF_INET; | ||
| 528 | pub const PF_IMPLINK: c_int = AF_IMPLINK; | ||
| 529 | pub const PF_PUP: c_int = AF_PUP; | ||
| 530 | pub const PF_CHAOS: c_int = AF_CHAOS; | ||
| 531 | pub const PF_NS: c_int = AF_NS; | ||
| 532 | pub const PF_ISO: c_int = AF_ISO; | ||
| 533 | pub const PF_OSI: c_int = AF_ISO; | ||
| 534 | pub const PF_ECMA: c_int = AF_ECMA; | ||
| 535 | pub const PF_DATAKIT: c_int = AF_DATAKIT; | ||
| 536 | pub const PF_CCITT: c_int = AF_CCITT; | ||
| 537 | pub const PF_SNA: c_int = AF_SNA; | ||
| 538 | pub const PF_DECnet: c_int = AF_DECnet; | ||
| 539 | pub const PF_DLI: c_int = AF_DLI; | ||
| 540 | pub const PF_LAT: c_int = AF_LAT; | ||
| 541 | pub const PF_HYLINK: c_int = AF_HYLINK; | ||
| 542 | pub const PF_APPLETALK: c_int = AF_APPLETALK; | ||
| 543 | pub const PF_ROUTE: c_int = AF_ROUTE; | ||
| 544 | pub const PF_LINK: c_int = AF_LINK; | ||
| 545 | pub const PF_XTP: c_int = AF_XTP; | ||
| 546 | pub const PF_COIP: c_int = AF_COIP; | ||
| 547 | pub const PF_CNT: c_int = AF_CNT; | ||
| 548 | pub const PF_SIP: c_int = AF_SIP; | ||
| 549 | pub const PF_IPX: c_int = AF_IPX; | ||
| 550 | pub const PF_RTIP: c_int = AF_RTIP; | ||
| 551 | pub const PF_PIP: c_int = AF_PIP; | ||
| 552 | pub const PF_ISDN: c_int = AF_ISDN; | ||
| 553 | pub const PF_KEY: c_int = AF_KEY; | ||
| 554 | pub const PF_INET6: c_int = AF_INET6; | ||
| 555 | pub const PF_NATM: c_int = AF_NATM; | ||
| 556 | pub const PF_SYSTEM: c_int = AF_SYSTEM; | ||
| 557 | pub const PF_NETBIOS: c_int = AF_NETBIOS; | ||
| 558 | pub const PF_PPP: c_int = AF_PPP; | ||
| 559 | pub const PF_MAX: c_int = AF_MAX; | ||
| 560 | |||
| 561 | pub const SYSPROTO_EVENT: c_int = 1; | ||
| 562 | pub const SYSPROTO_CONTROL: c_int = 2; | ||
| 563 | |||
| 564 | pub const SOCK_STREAM: c_int = 1; | ||
| 565 | pub const SOCK_DGRAM: c_int = 2; | ||
| 566 | pub const SOCK_RAW: c_int = 3; | ||
| 567 | pub const SOCK_RDM: c_int = 4; | ||
| 568 | pub const SOCK_SEQPACKET: c_int = 5; | ||
| 569 | pub const SOCK_MAXADDRLEN: c_int = 255; | ||
| 570 | |||
| 485 | fn wstatus(x: i32) i32 { | 571 | fn wstatus(x: i32) i32 { |
| 486 | return x & 0o177; | 572 | return x & 0o177; |
| 487 | } | 573 | } |
std/os/darwin/errno.zig created+328| ... | @@ -0,0 +1,328 @@ | ||
| 1 | /// Operation not permitted | ||
| 2 | pub const EPERM = 1; | ||
| 3 | |||
| 4 | /// No such file or directory | ||
| 5 | pub const ENOENT = 2; | ||
| 6 | |||
| 7 | /// No such process | ||
| 8 | pub const ESRCH = 3; | ||
| 9 | |||
| 10 | /// Interrupted system call | ||
| 11 | pub const EINTR = 4; | ||
| 12 | |||
| 13 | /// Input/output error | ||
| 14 | pub const EIO = 5; | ||
| 15 | |||
| 16 | /// Device not configured | ||
| 17 | pub const ENXIO = 6; | ||
| 18 | |||
| 19 | /// Argument list too long | ||
| 20 | pub const E2BIG = 7; | ||
| 21 | |||
| 22 | /// Exec format error | ||
| 23 | pub const ENOEXEC = 8; | ||
| 24 | |||
| 25 | /// Bad file descriptor | ||
| 26 | pub const EBADF = 9; | ||
| 27 | |||
| 28 | /// No child processes | ||
| 29 | pub const ECHILD = 10; | ||
| 30 | |||
| 31 | /// Resource deadlock avoided | ||
| 32 | pub const EDEADLK = 11; | ||
| 33 | |||
| 34 | /// Cannot allocate memory | ||
| 35 | pub const ENOMEM = 12; | ||
| 36 | |||
| 37 | /// Permission denied | ||
| 38 | pub const EACCES = 13; | ||
| 39 | |||
| 40 | /// Bad address | ||
| 41 | pub const EFAULT = 14; | ||
| 42 | |||
| 43 | /// Block device required | ||
| 44 | pub const ENOTBLK = 15; | ||
| 45 | |||
| 46 | /// Device / Resource busy | ||
| 47 | pub const EBUSY = 16; | ||
| 48 | |||
| 49 | /// File exists | ||
| 50 | pub const EEXIST = 17; | ||
| 51 | |||
| 52 | /// Cross-device link | ||
| 53 | pub const EXDEV = 18; | ||
| 54 | |||
| 55 | /// Operation not supported by device | ||
| 56 | pub const ENODEV = 19; | ||
| 57 | |||
| 58 | /// Not a directory | ||
| 59 | pub const ENOTDIR = 20; | ||
| 60 | |||
| 61 | /// Is a directory | ||
| 62 | pub const EISDIR = 21; | ||
| 63 | |||
| 64 | /// Invalid argument | ||
| 65 | pub const EINVAL = 22; | ||
| 66 | |||
| 67 | /// Too many open files in system | ||
| 68 | pub const ENFILE = 23; | ||
| 69 | |||
| 70 | /// Too many open files | ||
| 71 | pub const EMFILE = 24; | ||
| 72 | |||
| 73 | /// Inappropriate ioctl for device | ||
| 74 | pub const ENOTTY = 25; | ||
| 75 | |||
| 76 | /// Text file busy | ||
| 77 | pub const ETXTBSY = 26; | ||
| 78 | |||
| 79 | /// File too large | ||
| 80 | pub const EFBIG = 27; | ||
| 81 | |||
| 82 | /// No space left on device | ||
| 83 | pub const ENOSPC = 28; | ||
| 84 | |||
| 85 | /// Illegal seek | ||
| 86 | pub const ESPIPE = 29; | ||
| 87 | |||
| 88 | /// Read-only file system | ||
| 89 | pub const EROFS = 30; | ||
| 90 | |||
| 91 | /// Too many links | ||
| 92 | pub const EMLINK = 31; | ||
| 93 | /// Broken pipe | ||
| 94 | |||
| 95 | // math software | ||
| 96 | pub const EPIPE = 32; | ||
| 97 | |||
| 98 | /// Numerical argument out of domain | ||
| 99 | pub const EDOM = 33; | ||
| 100 | /// Result too large | ||
| 101 | |||
| 102 | // non-blocking and interrupt i/o | ||
| 103 | pub const ERANGE = 34; | ||
| 104 | |||
| 105 | /// Resource temporarily unavailable | ||
| 106 | pub const EAGAIN = 35; | ||
| 107 | |||
| 108 | /// Operation would block | ||
| 109 | pub const EWOULDBLOCK = EAGAIN; | ||
| 110 | |||
| 111 | /// Operation now in progress | ||
| 112 | pub const EINPROGRESS = 36; | ||
| 113 | /// Operation already in progress | ||
| 114 | |||
| 115 | // ipc/network software -- argument errors | ||
| 116 | pub const EALREADY = 37; | ||
| 117 | |||
| 118 | /// Socket operation on non-socket | ||
| 119 | pub const ENOTSOCK = 38; | ||
| 120 | |||
| 121 | /// Destination address required | ||
| 122 | pub const EDESTADDRREQ = 39; | ||
| 123 | |||
| 124 | /// Message too long | ||
| 125 | pub const EMSGSIZE = 40; | ||
| 126 | |||
| 127 | /// Protocol wrong type for socket | ||
| 128 | pub const EPROTOTYPE = 41; | ||
| 129 | |||
| 130 | /// Protocol not available | ||
| 131 | pub const ENOPROTOOPT = 42; | ||
| 132 | |||
| 133 | /// Protocol not supported | ||
| 134 | pub const EPROTONOSUPPORT = 43; | ||
| 135 | |||
| 136 | /// Socket type not supported | ||
| 137 | pub const ESOCKTNOSUPPORT = 44; | ||
| 138 | |||
| 139 | /// Operation not supported | ||
| 140 | pub const ENOTSUP = 45; | ||
| 141 | |||
| 142 | /// Protocol family not supported | ||
| 143 | pub const EPFNOSUPPORT = 46; | ||
| 144 | |||
| 145 | /// Address family not supported by protocol family | ||
| 146 | pub const EAFNOSUPPORT = 47; | ||
| 147 | |||
| 148 | /// Address already in use | ||
| 149 | pub const EADDRINUSE = 48; | ||
| 150 | /// Can't assign requested address | ||
| 151 | |||
| 152 | // ipc/network software -- operational errors | ||
| 153 | pub const EADDRNOTAVAIL = 49; | ||
| 154 | |||
| 155 | /// Network is down | ||
| 156 | pub const ENETDOWN = 50; | ||
| 157 | |||
| 158 | /// Network is unreachable | ||
| 159 | pub const ENETUNREACH = 51; | ||
| 160 | |||
| 161 | /// Network dropped connection on reset | ||
| 162 | pub const ENETRESET = 52; | ||
| 163 | |||
| 164 | /// Software caused connection abort | ||
| 165 | pub const ECONNABORTED = 53; | ||
| 166 | |||
| 167 | /// Connection reset by peer | ||
| 168 | pub const ECONNRESET = 54; | ||
| 169 | |||
| 170 | /// No buffer space available | ||
| 171 | pub const ENOBUFS = 55; | ||
| 172 | |||
| 173 | /// Socket is already connected | ||
| 174 | pub const EISCONN = 56; | ||
| 175 | |||
| 176 | /// Socket is not connected | ||
| 177 | pub const ENOTCONN = 57; | ||
| 178 | |||
| 179 | /// Can't send after socket shutdown | ||
| 180 | pub const ESHUTDOWN = 58; | ||
| 181 | |||
| 182 | /// Too many references: can't splice | ||
| 183 | pub const ETOOMANYREFS = 59; | ||
| 184 | |||
| 185 | /// Operation timed out | ||
| 186 | pub const ETIMEDOUT = 60; | ||
| 187 | |||
| 188 | /// Connection refused | ||
| 189 | pub const ECONNREFUSED = 61; | ||
| 190 | |||
| 191 | /// Too many levels of symbolic links | ||
| 192 | pub const ELOOP = 62; | ||
| 193 | |||
| 194 | /// File name too long | ||
| 195 | pub const ENAMETOOLONG = 63; | ||
| 196 | |||
| 197 | /// Host is down | ||
| 198 | pub const EHOSTDOWN = 64; | ||
| 199 | |||
| 200 | /// No route to host | ||
| 201 | pub const EHOSTUNREACH = 65; | ||
| 202 | /// Directory not empty | ||
| 203 | |||
| 204 | // quotas & mush | ||
| 205 | pub const ENOTEMPTY = 66; | ||
| 206 | |||
| 207 | /// Too many processes | ||
| 208 | pub const EPROCLIM = 67; | ||
| 209 | |||
| 210 | /// Too many users | ||
| 211 | pub const EUSERS = 68; | ||
| 212 | /// Disc quota exceeded | ||
| 213 | |||
| 214 | // Network File System | ||
| 215 | pub const EDQUOT = 69; | ||
| 216 | |||
| 217 | /// Stale NFS file handle | ||
| 218 | pub const ESTALE = 70; | ||
| 219 | |||
| 220 | /// Too many levels of remote in path | ||
| 221 | pub const EREMOTE = 71; | ||
| 222 | |||
| 223 | /// RPC struct is bad | ||
| 224 | pub const EBADRPC = 72; | ||
| 225 | |||
| 226 | /// RPC version wrong | ||
| 227 | pub const ERPCMISMATCH = 73; | ||
| 228 | |||
| 229 | /// RPC prog. not avail | ||
| 230 | pub const EPROGUNAVAIL = 74; | ||
| 231 | |||
| 232 | /// Program version wrong | ||
| 233 | pub const EPROGMISMATCH = 75; | ||
| 234 | |||
| 235 | /// Bad procedure for program | ||
| 236 | pub const EPROCUNAVAIL = 76; | ||
| 237 | |||
| 238 | /// No locks available | ||
| 239 | pub const ENOLCK = 77; | ||
| 240 | |||
| 241 | /// Function not implemented | ||
| 242 | pub const ENOSYS = 78; | ||
| 243 | |||
| 244 | /// Inappropriate file type or format | ||
| 245 | pub const EFTYPE = 79; | ||
| 246 | |||
| 247 | /// Authentication error | ||
| 248 | pub const EAUTH = 80; | ||
| 249 | /// Need authenticator | ||
| 250 | |||
| 251 | // Intelligent device errors | ||
| 252 | pub const ENEEDAUTH = 81; | ||
| 253 | |||
| 254 | /// Device power is off | ||
| 255 | pub const EPWROFF = 82; | ||
| 256 | |||
| 257 | /// Device error, e.g. paper out | ||
| 258 | pub const EDEVERR = 83; | ||
| 259 | /// Value too large to be stored in data type | ||
| 260 | |||
| 261 | // Program loading errors | ||
| 262 | pub const EOVERFLOW = 84; | ||
| 263 | |||
| 264 | /// Bad executable | ||
| 265 | pub const EBADEXEC = 85; | ||
| 266 | |||
| 267 | /// Bad CPU type in executable | ||
| 268 | pub const EBADARCH = 86; | ||
| 269 | |||
| 270 | /// Shared library version mismatch | ||
| 271 | pub const ESHLIBVERS = 87; | ||
| 272 | |||
| 273 | /// Malformed Macho file | ||
| 274 | pub const EBADMACHO = 88; | ||
| 275 | |||
| 276 | /// Operation canceled | ||
| 277 | pub const ECANCELED = 89; | ||
| 278 | |||
| 279 | /// Identifier removed | ||
| 280 | pub const EIDRM = 90; | ||
| 281 | |||
| 282 | /// No message of desired type | ||
| 283 | pub const ENOMSG = 91; | ||
| 284 | |||
| 285 | /// Illegal byte sequence | ||
| 286 | pub const EILSEQ = 92; | ||
| 287 | |||
| 288 | /// Attribute not found | ||
| 289 | pub const ENOATTR = 93; | ||
| 290 | |||
| 291 | /// Bad message | ||
| 292 | pub const EBADMSG = 94; | ||
| 293 | |||
| 294 | /// Reserved | ||
| 295 | pub const EMULTIHOP = 95; | ||
| 296 | |||
| 297 | /// No message available on STREAM | ||
| 298 | pub const ENODATA = 96; | ||
| 299 | |||
| 300 | /// Reserved | ||
| 301 | pub const ENOLINK = 97; | ||
| 302 | |||
| 303 | /// No STREAM resources | ||
| 304 | pub const ENOSR = 98; | ||
| 305 | |||
| 306 | /// Not a STREAM | ||
| 307 | pub const ENOSTR = 99; | ||
| 308 | |||
| 309 | /// Protocol error | ||
| 310 | pub const EPROTO = 100; | ||
| 311 | |||
| 312 | /// STREAM ioctl timeout | ||
| 313 | pub const ETIME = 101; | ||
| 314 | |||
| 315 | /// No such policy registered | ||
| 316 | pub const ENOPOLICY = 103; | ||
| 317 | |||
| 318 | /// State not recoverable | ||
| 319 | pub const ENOTRECOVERABLE = 104; | ||
| 320 | |||
| 321 | /// Previous owner died | ||
| 322 | pub const EOWNERDEAD = 105; | ||
| 323 | |||
| 324 | /// Interface output queue is full | ||
| 325 | pub const EQFULL = 106; | ||
| 326 | |||
| 327 | /// Must be equal largest errno | ||
| 328 | pub const ELAST = 106; | ||
std/os/darwin_errno.zig deleted-328| ... | @@ -1,328 +0,0 @@ | ||
| 1 | /// Operation not permitted | ||
| 2 | pub const EPERM = 1; | ||
| 3 | |||
| 4 | /// No such file or directory | ||
| 5 | pub const ENOENT = 2; | ||
| 6 | |||
| 7 | /// No such process | ||
| 8 | pub const ESRCH = 3; | ||
| 9 | |||
| 10 | /// Interrupted system call | ||
| 11 | pub const EINTR = 4; | ||
| 12 | |||
| 13 | /// Input/output error | ||
| 14 | pub const EIO = 5; | ||
| 15 | |||
| 16 | /// Device not configured | ||
| 17 | pub const ENXIO = 6; | ||
| 18 | |||
| 19 | /// Argument list too long | ||
| 20 | pub const E2BIG = 7; | ||
| 21 | |||
| 22 | /// Exec format error | ||
| 23 | pub const ENOEXEC = 8; | ||
| 24 | |||
| 25 | /// Bad file descriptor | ||
| 26 | pub const EBADF = 9; | ||
| 27 | |||
| 28 | /// No child processes | ||
| 29 | pub const ECHILD = 10; | ||
| 30 | |||
| 31 | /// Resource deadlock avoided | ||
| 32 | pub const EDEADLK = 11; | ||
| 33 | |||
| 34 | /// Cannot allocate memory | ||
| 35 | pub const ENOMEM = 12; | ||
| 36 | |||
| 37 | /// Permission denied | ||
| 38 | pub const EACCES = 13; | ||
| 39 | |||
| 40 | /// Bad address | ||
| 41 | pub const EFAULT = 14; | ||
| 42 | |||
| 43 | /// Block device required | ||
| 44 | pub const ENOTBLK = 15; | ||
| 45 | |||
| 46 | /// Device / Resource busy | ||
| 47 | pub const EBUSY = 16; | ||
| 48 | |||
| 49 | /// File exists | ||
| 50 | pub const EEXIST = 17; | ||
| 51 | |||
| 52 | /// Cross-device link | ||
| 53 | pub const EXDEV = 18; | ||
| 54 | |||
| 55 | /// Operation not supported by device | ||
| 56 | pub const ENODEV = 19; | ||
| 57 | |||
| 58 | /// Not a directory | ||
| 59 | pub const ENOTDIR = 20; | ||
| 60 | |||
| 61 | /// Is a directory | ||
| 62 | pub const EISDIR = 21; | ||
| 63 | |||
| 64 | /// Invalid argument | ||
| 65 | pub const EINVAL = 22; | ||
| 66 | |||
| 67 | /// Too many open files in system | ||
| 68 | pub const ENFILE = 23; | ||
| 69 | |||
| 70 | /// Too many open files | ||
| 71 | pub const EMFILE = 24; | ||
| 72 | |||
| 73 | /// Inappropriate ioctl for device | ||
| 74 | pub const ENOTTY = 25; | ||
| 75 | |||
| 76 | /// Text file busy | ||
| 77 | pub const ETXTBSY = 26; | ||
| 78 | |||
| 79 | /// File too large | ||
| 80 | pub const EFBIG = 27; | ||
| 81 | |||
| 82 | /// No space left on device | ||
| 83 | pub const ENOSPC = 28; | ||
| 84 | |||
| 85 | /// Illegal seek | ||
| 86 | pub const ESPIPE = 29; | ||
| 87 | |||
| 88 | /// Read-only file system | ||
| 89 | pub const EROFS = 30; | ||
| 90 | |||
| 91 | /// Too many links | ||
| 92 | pub const EMLINK = 31; | ||
| 93 | /// Broken pipe | ||
| 94 | |||
| 95 | // math software | ||
| 96 | pub const EPIPE = 32; | ||
| 97 | |||
| 98 | /// Numerical argument out of domain | ||
| 99 | pub const EDOM = 33; | ||
| 100 | /// Result too large | ||
| 101 | |||
| 102 | // non-blocking and interrupt i/o | ||
| 103 | pub const ERANGE = 34; | ||
| 104 | |||
| 105 | /// Resource temporarily unavailable | ||
| 106 | pub const EAGAIN = 35; | ||
| 107 | |||
| 108 | /// Operation would block | ||
| 109 | pub const EWOULDBLOCK = EAGAIN; | ||
| 110 | |||
| 111 | /// Operation now in progress | ||
| 112 | pub const EINPROGRESS = 36; | ||
| 113 | /// Operation already in progress | ||
| 114 | |||
| 115 | // ipc/network software -- argument errors | ||
| 116 | pub const EALREADY = 37; | ||
| 117 | |||
| 118 | /// Socket operation on non-socket | ||
| 119 | pub const ENOTSOCK = 38; | ||
| 120 | |||
| 121 | /// Destination address required | ||
| 122 | pub const EDESTADDRREQ = 39; | ||
| 123 | |||
| 124 | /// Message too long | ||
| 125 | pub const EMSGSIZE = 40; | ||
| 126 | |||
| 127 | /// Protocol wrong type for socket | ||
| 128 | pub const EPROTOTYPE = 41; | ||
| 129 | |||
| 130 | /// Protocol not available | ||
| 131 | pub const ENOPROTOOPT = 42; | ||
| 132 | |||
| 133 | /// Protocol not supported | ||
| 134 | pub const EPROTONOSUPPORT = 43; | ||
| 135 | |||
| 136 | /// Socket type not supported | ||
| 137 | pub const ESOCKTNOSUPPORT = 44; | ||
| 138 | |||
| 139 | /// Operation not supported | ||
| 140 | pub const ENOTSUP = 45; | ||
| 141 | |||
| 142 | /// Protocol family not supported | ||
| 143 | pub const EPFNOSUPPORT = 46; | ||
| 144 | |||
| 145 | /// Address family not supported by protocol family | ||
| 146 | pub const EAFNOSUPPORT = 47; | ||
| 147 | |||
| 148 | /// Address already in use | ||
| 149 | pub const EADDRINUSE = 48; | ||
| 150 | /// Can't assign requested address | ||
| 151 | |||
| 152 | // ipc/network software -- operational errors | ||
| 153 | pub const EADDRNOTAVAIL = 49; | ||
| 154 | |||
| 155 | /// Network is down | ||
| 156 | pub const ENETDOWN = 50; | ||
| 157 | |||
| 158 | /// Network is unreachable | ||
| 159 | pub const ENETUNREACH = 51; | ||
| 160 | |||
| 161 | /// Network dropped connection on reset | ||
| 162 | pub const ENETRESET = 52; | ||
| 163 | |||
| 164 | /// Software caused connection abort | ||
| 165 | pub const ECONNABORTED = 53; | ||
| 166 | |||
| 167 | /// Connection reset by peer | ||
| 168 | pub const ECONNRESET = 54; | ||
| 169 | |||
| 170 | /// No buffer space available | ||
| 171 | pub const ENOBUFS = 55; | ||
| 172 | |||
| 173 | /// Socket is already connected | ||
| 174 | pub const EISCONN = 56; | ||
| 175 | |||
| 176 | /// Socket is not connected | ||
| 177 | pub const ENOTCONN = 57; | ||
| 178 | |||
| 179 | /// Can't send after socket shutdown | ||
| 180 | pub const ESHUTDOWN = 58; | ||
| 181 | |||
| 182 | /// Too many references: can't splice | ||
| 183 | pub const ETOOMANYREFS = 59; | ||
| 184 | |||
| 185 | /// Operation timed out | ||
| 186 | pub const ETIMEDOUT = 60; | ||
| 187 | |||
| 188 | /// Connection refused | ||
| 189 | pub const ECONNREFUSED = 61; | ||
| 190 | |||
| 191 | /// Too many levels of symbolic links | ||
| 192 | pub const ELOOP = 62; | ||
| 193 | |||
| 194 | /// File name too long | ||
| 195 | pub const ENAMETOOLONG = 63; | ||
| 196 | |||
| 197 | /// Host is down | ||
| 198 | pub const EHOSTDOWN = 64; | ||
| 199 | |||
| 200 | /// No route to host | ||
| 201 | pub const EHOSTUNREACH = 65; | ||
| 202 | /// Directory not empty | ||
| 203 | |||
| 204 | // quotas & mush | ||
| 205 | pub const ENOTEMPTY = 66; | ||
| 206 | |||
| 207 | /// Too many processes | ||
| 208 | pub const EPROCLIM = 67; | ||
| 209 | |||
| 210 | /// Too many users | ||
| 211 | pub const EUSERS = 68; | ||
| 212 | /// Disc quota exceeded | ||
| 213 | |||
| 214 | // Network File System | ||
| 215 | pub const EDQUOT = 69; | ||
| 216 | |||
| 217 | /// Stale NFS file handle | ||
| 218 | pub const ESTALE = 70; | ||
| 219 | |||
| 220 | /// Too many levels of remote in path | ||
| 221 | pub const EREMOTE = 71; | ||
| 222 | |||
| 223 | /// RPC struct is bad | ||
| 224 | pub const EBADRPC = 72; | ||
| 225 | |||
| 226 | /// RPC version wrong | ||
| 227 | pub const ERPCMISMATCH = 73; | ||
| 228 | |||
| 229 | /// RPC prog. not avail | ||
| 230 | pub const EPROGUNAVAIL = 74; | ||
| 231 | |||
| 232 | /// Program version wrong | ||
| 233 | pub const EPROGMISMATCH = 75; | ||
| 234 | |||
| 235 | /// Bad procedure for program | ||
| 236 | pub const EPROCUNAVAIL = 76; | ||
| 237 | |||
| 238 | /// No locks available | ||
| 239 | pub const ENOLCK = 77; | ||
| 240 | |||
| 241 | /// Function not implemented | ||
| 242 | pub const ENOSYS = 78; | ||
| 243 | |||
| 244 | /// Inappropriate file type or format | ||
| 245 | pub const EFTYPE = 79; | ||
| 246 | |||
| 247 | /// Authentication error | ||
| 248 | pub const EAUTH = 80; | ||
| 249 | /// Need authenticator | ||
| 250 | |||
| 251 | // Intelligent device errors | ||
| 252 | pub const ENEEDAUTH = 81; | ||
| 253 | |||
| 254 | /// Device power is off | ||
| 255 | pub const EPWROFF = 82; | ||
| 256 | |||
| 257 | /// Device error, e.g. paper out | ||
| 258 | pub const EDEVERR = 83; | ||
| 259 | /// Value too large to be stored in data type | ||
| 260 | |||
| 261 | // Program loading errors | ||
| 262 | pub const EOVERFLOW = 84; | ||
| 263 | |||
| 264 | /// Bad executable | ||
| 265 | pub const EBADEXEC = 85; | ||
| 266 | |||
| 267 | /// Bad CPU type in executable | ||
| 268 | pub const EBADARCH = 86; | ||
| 269 | |||
| 270 | /// Shared library version mismatch | ||
| 271 | pub const ESHLIBVERS = 87; | ||
| 272 | |||
| 273 | /// Malformed Macho file | ||
| 274 | pub const EBADMACHO = 88; | ||
| 275 | |||
| 276 | /// Operation canceled | ||
| 277 | pub const ECANCELED = 89; | ||
| 278 | |||
| 279 | /// Identifier removed | ||
| 280 | pub const EIDRM = 90; | ||
| 281 | |||
| 282 | /// No message of desired type | ||
| 283 | pub const ENOMSG = 91; | ||
| 284 | |||
| 285 | /// Illegal byte sequence | ||
| 286 | pub const EILSEQ = 92; | ||
| 287 | |||
| 288 | /// Attribute not found | ||
| 289 | pub const ENOATTR = 93; | ||
| 290 | |||
| 291 | /// Bad message | ||
| 292 | pub const EBADMSG = 94; | ||
| 293 | |||
| 294 | /// Reserved | ||
| 295 | pub const EMULTIHOP = 95; | ||
| 296 | |||
| 297 | /// No message available on STREAM | ||
| 298 | pub const ENODATA = 96; | ||
| 299 | |||
| 300 | /// Reserved | ||
| 301 | pub const ENOLINK = 97; | ||
| 302 | |||
| 303 | /// No STREAM resources | ||
| 304 | pub const ENOSR = 98; | ||
| 305 | |||
| 306 | /// Not a STREAM | ||
| 307 | pub const ENOSTR = 99; | ||
| 308 | |||
| 309 | /// Protocol error | ||
| 310 | pub const EPROTO = 100; | ||
| 311 | |||
| 312 | /// STREAM ioctl timeout | ||
| 313 | pub const ETIME = 101; | ||
| 314 | |||
| 315 | /// No such policy registered | ||
| 316 | pub const ENOPOLICY = 103; | ||
| 317 | |||
| 318 | /// State not recoverable | ||
| 319 | pub const ENOTRECOVERABLE = 104; | ||
| 320 | |||
| 321 | /// Previous owner died | ||
| 322 | pub const EOWNERDEAD = 105; | ||
| 323 | |||
| 324 | /// Interface output queue is full | ||
| 325 | pub const EQFULL = 106; | ||
| 326 | |||
| 327 | /// Must be equal largest errno | ||
| 328 | pub const ELAST = 106; | ||
std/os/file.zig+5-11| ... | @@ -15,7 +15,7 @@ pub const File = struct { | ... | @@ -15,7 +15,7 @@ pub const File = struct { |
| 15 | /// The OS-specific file descriptor or file handle. | 15 | /// The OS-specific file descriptor or file handle. |
| 16 | handle: os.FileHandle, | 16 | handle: os.FileHandle, |
| 17 | 17 | ||
| 18 | const OpenError = os.WindowsOpenError || os.PosixOpenError; | 18 | pub const OpenError = os.WindowsOpenError || os.PosixOpenError; |
| 19 | 19 | ||
| 20 | /// `path` needs to be copied in memory to add a null terminating byte, hence the allocator. | 20 | /// `path` needs to be copied in memory to add a null terminating byte, hence the allocator. |
| 21 | /// Call close to clean up. | 21 | /// Call close to clean up. |
| ... | @@ -239,7 +239,7 @@ pub const File = struct { | ... | @@ -239,7 +239,7 @@ pub const File = struct { |
| 239 | }, | 239 | }, |
| 240 | Os.windows => { | 240 | Os.windows => { |
| 241 | var pos: windows.LARGE_INTEGER = undefined; | 241 | var pos: windows.LARGE_INTEGER = undefined; |
| 242 | if (windows.SetFilePointerEx(self.handle, 0, *pos, windows.FILE_CURRENT) == 0) { | 242 | if (windows.SetFilePointerEx(self.handle, 0, &pos, windows.FILE_CURRENT) == 0) { |
| 243 | const err = windows.GetLastError(); | 243 | const err = windows.GetLastError(); |
| 244 | return switch (err) { | 244 | return switch (err) { |
| 245 | windows.ERROR.INVALID_PARAMETER => error.BadFd, | 245 | windows.ERROR.INVALID_PARAMETER => error.BadFd, |
| ... | @@ -248,13 +248,7 @@ pub const File = struct { | ... | @@ -248,13 +248,7 @@ pub const File = struct { |
| 248 | } | 248 | } |
| 249 | 249 | ||
| 250 | assert(pos >= 0); | 250 | assert(pos >= 0); |
| 251 | if (@sizeOf(@typeOf(pos)) > @sizeOf(usize)) { | 251 | return math.cast(usize, pos) catch error.FilePosLargerThanPointerRange; |
| 252 | if (pos > @maxValue(usize)) { | ||
| 253 | return error.FilePosLargerThanPointerRange; | ||
| 254 | } | ||
| 255 | } | ||
| 256 | |||
| 257 | return usize(pos); | ||
| 258 | }, | 252 | }, |
| 259 | else => @compileError("unsupported OS"), | 253 | else => @compileError("unsupported OS"), |
| 260 | } | 254 | } |
| ... | @@ -286,7 +280,7 @@ pub const File = struct { | ... | @@ -286,7 +280,7 @@ pub const File = struct { |
| 286 | Unexpected, | 280 | Unexpected, |
| 287 | }; | 281 | }; |
| 288 | 282 | ||
| 289 | fn mode(self: *File) ModeError!os.FileMode { | 283 | pub fn mode(self: *File) ModeError!os.FileMode { |
| 290 | if (is_posix) { | 284 | if (is_posix) { |
| 291 | var stat: posix.Stat = undefined; | 285 | var stat: posix.Stat = undefined; |
| 292 | const err = posix.getErrno(posix.fstat(self.handle, &stat)); | 286 | const err = posix.getErrno(posix.fstat(self.handle, &stat)); |
| ... | @@ -361,7 +355,7 @@ pub const File = struct { | ... | @@ -361,7 +355,7 @@ pub const File = struct { |
| 361 | 355 | ||
| 362 | pub const WriteError = os.WindowsWriteError || os.PosixWriteError; | 356 | pub const WriteError = os.WindowsWriteError || os.PosixWriteError; |
| 363 | 357 | ||
| 364 | fn write(self: *File, bytes: []const u8) WriteError!void { | 358 | pub fn write(self: *File, bytes: []const u8) WriteError!void { |
| 365 | if (is_posix) { | 359 | if (is_posix) { |
| 366 | try os.posixWrite(self.handle, bytes); | 360 | try os.posixWrite(self.handle, bytes); |
| 367 | } else if (is_windows) { | 361 | } else if (is_windows) { |
std/os/index.zig+1-1| ... | @@ -11,7 +11,7 @@ const os = this; | ... | @@ -11,7 +11,7 @@ const os = this; |
| 11 | test "std.os" { | 11 | test "std.os" { |
| 12 | _ = @import("child_process.zig"); | 12 | _ = @import("child_process.zig"); |
| 13 | _ = @import("darwin.zig"); | 13 | _ = @import("darwin.zig"); |
| 14 | _ = @import("darwin_errno.zig"); | 14 | _ = @import("darwin/errno.zig"); |
| 15 | _ = @import("get_user_id.zig"); | 15 | _ = @import("get_user_id.zig"); |
| 16 | _ = @import("linux/index.zig"); | 16 | _ = @import("linux/index.zig"); |
| 17 | _ = @import("path.zig"); | 17 | _ = @import("path.zig"); |
std/special/test_runner.zig+17-3| ... | @@ -5,11 +5,25 @@ const test_fn_list = builtin.__zig_test_fn_slice; | ... | @@ -5,11 +5,25 @@ const test_fn_list = builtin.__zig_test_fn_slice; |
| 5 | const warn = std.debug.warn; | 5 | const warn = std.debug.warn; |
| 6 | 6 | ||
| 7 | pub fn main() !void { | 7 | pub fn main() !void { |
| 8 | var ok_count: usize = 0; | ||
| 9 | var skip_count: usize = 0; | ||
| 8 | for (test_fn_list) |test_fn, i| { | 10 | for (test_fn_list) |test_fn, i| { |
| 9 | warn("Test {}/{} {}...", i + 1, test_fn_list.len, test_fn.name); | 11 | warn("Test {}/{} {}...", i + 1, test_fn_list.len, test_fn.name); |
| 10 | 12 | ||
| 11 | try test_fn.func(); | 13 | if (test_fn.func()) |_| { |
| 12 | 14 | ok_count += 1; | |
| 13 | warn("OK\n"); | 15 | warn("OK\n"); |
| 16 | } else |err| switch (err) { | ||
| 17 | error.SkipZigTest => { | ||
| 18 | skip_count += 1; | ||
| 19 | warn("SKIP\n"); | ||
| 20 | }, | ||
| 21 | else => return err, | ||
| 22 | } | ||
| 23 | } | ||
| 24 | if (ok_count == test_fn_list.len) { | ||
| 25 | warn("All tests passed.\n"); | ||
| 26 | } else { | ||
| 27 | warn("{} passed; {} skipped.\n", ok_count, skip_count); | ||
| 14 | } | 28 | } |
| 15 | } | 29 | } |
test/cases/defer.zig+15| ... | @@ -61,3 +61,18 @@ test "defer and labeled break" { | ... | @@ -61,3 +61,18 @@ test "defer and labeled break" { |
| 61 | 61 | ||
| 62 | assert(i == 1); | 62 | assert(i == 1); |
| 63 | } | 63 | } |
| 64 | |||
| 65 | test "errdefer does not apply to fn inside fn" { | ||
| 66 | if (testNestedFnErrDefer()) |_| @panic("expected error") else |e| assert(e == error.Bad); | ||
| 67 | } | ||
| 68 | |||
| 69 | fn testNestedFnErrDefer() error!void { | ||
| 70 | var a: i32 = 0; | ||
| 71 | errdefer a += 1; | ||
| 72 | const S = struct { | ||
| 73 | fn baz() error { | ||
| 74 | return error.Bad; | ||
| 75 | } | ||
| 76 | }; | ||
| 77 | return S.baz(); | ||
| 78 | } |