| author | |
| committer | |
| log | 5c094d7390a7225f942032992b6070dcb6b9f761 |
| tree | 9edaf26aabc9a5117828e1af4cd2f5d3bab47c91 |
| parent | b6a679c0edd74d996bd0c1769cf4b161b4d42c4d |
...the exports of std.
closes #35611 files changed, 201 insertions(+), 188 deletions(-)
CMakeLists.txt+1-1| ... | @@ -196,6 +196,7 @@ install(TARGETS zig DESTINATION bin) | ... | @@ -196,6 +196,7 @@ install(TARGETS zig DESTINATION bin) |
| 196 | 196 | ||
| 197 | install(FILES ${C_HEADERS} DESTINATION ${C_HEADERS_DEST}) | 197 | install(FILES ${C_HEADERS} DESTINATION ${C_HEADERS_DEST}) |
| 198 | 198 | ||
| 199 | install(FILES "${CMAKE_SOURCE_DIR}/std/array_list.zig" DESTINATION "${ZIG_STD_DEST}") | ||
| 199 | install(FILES "${CMAKE_SOURCE_DIR}/std/base64.zig" DESTINATION "${ZIG_STD_DEST}") | 200 | install(FILES "${CMAKE_SOURCE_DIR}/std/base64.zig" DESTINATION "${ZIG_STD_DEST}") |
| 200 | install(FILES "${CMAKE_SOURCE_DIR}/std/buf_map.zig" DESTINATION "${ZIG_STD_DEST}") | 201 | install(FILES "${CMAKE_SOURCE_DIR}/std/buf_map.zig" DESTINATION "${ZIG_STD_DEST}") |
| 201 | install(FILES "${CMAKE_SOURCE_DIR}/std/buf_set.zig" DESTINATION "${ZIG_STD_DEST}") | 202 | install(FILES "${CMAKE_SOURCE_DIR}/std/buf_set.zig" DESTINATION "${ZIG_STD_DEST}") |
| ... | @@ -216,7 +217,6 @@ install(FILES "${CMAKE_SOURCE_DIR}/std/hash_map.zig" DESTINATION "${ZIG_STD_DEST | ... | @@ -216,7 +217,6 @@ install(FILES "${CMAKE_SOURCE_DIR}/std/hash_map.zig" DESTINATION "${ZIG_STD_DEST |
| 216 | install(FILES "${CMAKE_SOURCE_DIR}/std/index.zig" DESTINATION "${ZIG_STD_DEST}") | 217 | install(FILES "${CMAKE_SOURCE_DIR}/std/index.zig" DESTINATION "${ZIG_STD_DEST}") |
| 217 | install(FILES "${CMAKE_SOURCE_DIR}/std/io.zig" DESTINATION "${ZIG_STD_DEST}") | 218 | install(FILES "${CMAKE_SOURCE_DIR}/std/io.zig" DESTINATION "${ZIG_STD_DEST}") |
| 218 | install(FILES "${CMAKE_SOURCE_DIR}/std/linked_list.zig" DESTINATION "${ZIG_STD_DEST}") | 219 | install(FILES "${CMAKE_SOURCE_DIR}/std/linked_list.zig" DESTINATION "${ZIG_STD_DEST}") |
| 219 | install(FILES "${CMAKE_SOURCE_DIR}/std/list.zig" DESTINATION "${ZIG_STD_DEST}") | ||
| 220 | install(FILES "${CMAKE_SOURCE_DIR}/std/math.zig" DESTINATION "${ZIG_STD_DEST}") | 220 | install(FILES "${CMAKE_SOURCE_DIR}/std/math.zig" DESTINATION "${ZIG_STD_DEST}") |
| 221 | install(FILES "${CMAKE_SOURCE_DIR}/std/mem.zig" DESTINATION "${ZIG_STD_DEST}") | 221 | install(FILES "${CMAKE_SOURCE_DIR}/std/mem.zig" DESTINATION "${ZIG_STD_DEST}") |
| 222 | install(FILES "${CMAKE_SOURCE_DIR}/std/net.zig" DESTINATION "${ZIG_STD_DEST}") | 222 | install(FILES "${CMAKE_SOURCE_DIR}/std/net.zig" DESTINATION "${ZIG_STD_DEST}") |
std/array_list.zig created+91| ... | @@ -0,0 +1,91 @@ | ||
| 1 | const debug = @import("debug.zig"); | ||
| 2 | const assert = debug.assert; | ||
| 3 | const mem = @import("mem.zig"); | ||
| 4 | const Allocator = mem.Allocator; | ||
| 5 | |||
| 6 | pub fn ArrayList(comptime T: type) -> type{ | ||
| 7 | struct { | ||
| 8 | const Self = this; | ||
| 9 | |||
| 10 | /// Use toSlice instead of slicing this directly, because if you don't | ||
| 11 | /// specify the end position of the slice, this will potentially give | ||
| 12 | /// you uninitialized memory. | ||
| 13 | items: []T, | ||
| 14 | len: usize, | ||
| 15 | allocator: &Allocator, | ||
| 16 | |||
| 17 | pub fn init(allocator: &Allocator) -> Self { | ||
| 18 | Self { | ||
| 19 | .items = []T{}, | ||
| 20 | .len = 0, | ||
| 21 | .allocator = allocator, | ||
| 22 | } | ||
| 23 | } | ||
| 24 | |||
| 25 | pub fn deinit(l: &Self) { | ||
| 26 | l.allocator.free(l.items); | ||
| 27 | } | ||
| 28 | |||
| 29 | pub fn toSlice(l: &Self) -> []T { | ||
| 30 | return l.items[0...l.len]; | ||
| 31 | } | ||
| 32 | |||
| 33 | pub fn toSliceConst(l: &const Self) -> []const T { | ||
| 34 | return l.items[0...l.len]; | ||
| 35 | } | ||
| 36 | |||
| 37 | pub fn append(l: &Self, item: &const T) -> %void { | ||
| 38 | const new_item_ptr = %return l.addOne(); | ||
| 39 | *new_item_ptr = *item; | ||
| 40 | } | ||
| 41 | |||
| 42 | pub fn resize(l: &Self, new_len: usize) -> %void { | ||
| 43 | %return l.ensureCapacity(new_len); | ||
| 44 | l.len = new_len; | ||
| 45 | } | ||
| 46 | |||
| 47 | pub fn resizeDown(l: &Self, new_len: usize) { | ||
| 48 | assert(new_len <= l.len); | ||
| 49 | l.len = new_len; | ||
| 50 | } | ||
| 51 | |||
| 52 | pub fn ensureCapacity(l: &Self, new_capacity: usize) -> %void { | ||
| 53 | var better_capacity = l.items.len; | ||
| 54 | if (better_capacity >= new_capacity) return; | ||
| 55 | while (true) { | ||
| 56 | better_capacity += better_capacity / 2 + 8; | ||
| 57 | if (better_capacity >= new_capacity) break; | ||
| 58 | } | ||
| 59 | l.items = %return l.allocator.realloc(T, l.items, better_capacity); | ||
| 60 | } | ||
| 61 | |||
| 62 | pub fn addOne(l: &Self) -> %&T { | ||
| 63 | const new_length = l.len + 1; | ||
| 64 | %return l.ensureCapacity(new_length); | ||
| 65 | const result = &l.items[l.len]; | ||
| 66 | l.len = new_length; | ||
| 67 | return result; | ||
| 68 | } | ||
| 69 | |||
| 70 | pub fn pop(self: &Self) -> T { | ||
| 71 | self.len -= 1; | ||
| 72 | return self.items[self.len]; | ||
| 73 | } | ||
| 74 | } | ||
| 75 | } | ||
| 76 | |||
| 77 | test "basic ArrayList test" { | ||
| 78 | var list = ArrayList(i32).init(&debug.global_allocator); | ||
| 79 | defer list.deinit(); | ||
| 80 | |||
| 81 | {var i: usize = 0; while (i < 10) : (i += 1) { | ||
| 82 | %%list.append(i32(i + 1)); | ||
| 83 | }} | ||
| 84 | |||
| 85 | {var i: usize = 0; while (i < 10) : (i += 1) { | ||
| 86 | assert(list.items[i] == i32(i + 1)); | ||
| 87 | }} | ||
| 88 | |||
| 89 | assert(list.pop() == 10); | ||
| 90 | assert(list.len == 9); | ||
| 91 | } | ||
std/buffer.zig+3-3| ... | @@ -2,11 +2,11 @@ const debug = @import("debug.zig"); | ... | @@ -2,11 +2,11 @@ const debug = @import("debug.zig"); |
| 2 | const mem = @import("mem.zig"); | 2 | const mem = @import("mem.zig"); |
| 3 | const Allocator = mem.Allocator; | 3 | const Allocator = mem.Allocator; |
| 4 | const assert = debug.assert; | 4 | const assert = debug.assert; |
| 5 | const List = @import("list.zig").List; | 5 | const ArrayList = @import("array_list.zig").ArrayList; |
| 6 | 6 | ||
| 7 | /// A buffer that allocates memory and maintains a null byte at the end. | 7 | /// A buffer that allocates memory and maintains a null byte at the end. |
| 8 | pub const Buffer = struct { | 8 | pub const Buffer = struct { |
| 9 | list: List(u8), | 9 | list: ArrayList(u8), |
| 10 | 10 | ||
| 11 | /// Must deinitialize with deinit. | 11 | /// Must deinitialize with deinit. |
| 12 | pub fn init(allocator: &Allocator, m: []const u8) -> %Buffer { | 12 | pub fn init(allocator: &Allocator, m: []const u8) -> %Buffer { |
| ... | @@ -29,7 +29,7 @@ pub const Buffer = struct { | ... | @@ -29,7 +29,7 @@ pub const Buffer = struct { |
| 29 | /// * ::resize | 29 | /// * ::resize |
| 30 | pub fn initNull(allocator: &Allocator) -> Buffer { | 30 | pub fn initNull(allocator: &Allocator) -> Buffer { |
| 31 | Buffer { | 31 | Buffer { |
| 32 | .list = List(u8).init(allocator), | 32 | .list = ArrayList(u8).init(allocator), |
| 33 | } | 33 | } |
| 34 | } | 34 | } |
| 35 | 35 |
std/build.zig+38-38| ... | @@ -3,7 +3,7 @@ const io = @import("io.zig"); | ... | @@ -3,7 +3,7 @@ const io = @import("io.zig"); |
| 3 | const mem = @import("mem.zig"); | 3 | const mem = @import("mem.zig"); |
| 4 | const debug = @import("debug.zig"); | 4 | const debug = @import("debug.zig"); |
| 5 | const assert = debug.assert; | 5 | const assert = debug.assert; |
| 6 | const List = @import("list.zig").List; | 6 | const ArrayList = @import("array_list.zig").ArrayList; |
| 7 | const HashMap = @import("hash_map.zig").HashMap; | 7 | const HashMap = @import("hash_map.zig").HashMap; |
| 8 | const Allocator = @import("mem.zig").Allocator; | 8 | const Allocator = @import("mem.zig").Allocator; |
| 9 | const os = @import("os/index.zig"); | 9 | const os = @import("os/index.zig"); |
| ... | @@ -26,22 +26,22 @@ pub const Builder = struct { | ... | @@ -26,22 +26,22 @@ pub const Builder = struct { |
| 26 | have_uninstall_step: bool, | 26 | have_uninstall_step: bool, |
| 27 | have_install_step: bool, | 27 | have_install_step: bool, |
| 28 | allocator: &Allocator, | 28 | allocator: &Allocator, |
| 29 | lib_paths: List([]const u8), | 29 | lib_paths: ArrayList([]const u8), |
| 30 | include_paths: List([]const u8), | 30 | include_paths: ArrayList([]const u8), |
| 31 | rpaths: List([]const u8), | 31 | rpaths: ArrayList([]const u8), |
| 32 | user_input_options: UserInputOptionsMap, | 32 | user_input_options: UserInputOptionsMap, |
| 33 | available_options_map: AvailableOptionsMap, | 33 | available_options_map: AvailableOptionsMap, |
| 34 | available_options_list: List(AvailableOption), | 34 | available_options_list: ArrayList(AvailableOption), |
| 35 | verbose: bool, | 35 | verbose: bool, |
| 36 | invalid_user_input: bool, | 36 | invalid_user_input: bool, |
| 37 | zig_exe: []const u8, | 37 | zig_exe: []const u8, |
| 38 | default_step: &Step, | 38 | default_step: &Step, |
| 39 | env_map: BufMap, | 39 | env_map: BufMap, |
| 40 | top_level_steps: List(&TopLevelStep), | 40 | top_level_steps: ArrayList(&TopLevelStep), |
| 41 | prefix: []const u8, | 41 | prefix: []const u8, |
| 42 | lib_dir: []const u8, | 42 | lib_dir: []const u8, |
| 43 | exe_dir: []const u8, | 43 | exe_dir: []const u8, |
| 44 | installed_files: List([]const u8), | 44 | installed_files: ArrayList([]const u8), |
| 45 | build_root: []const u8, | 45 | build_root: []const u8, |
| 46 | cache_root: []const u8, | 46 | cache_root: []const u8, |
| 47 | 47 | ||
| ... | @@ -63,7 +63,7 @@ pub const Builder = struct { | ... | @@ -63,7 +63,7 @@ pub const Builder = struct { |
| 63 | const UserValue = enum { | 63 | const UserValue = enum { |
| 64 | Flag, | 64 | Flag, |
| 65 | Scalar: []const u8, | 65 | Scalar: []const u8, |
| 66 | List: List([]const u8), | 66 | List: ArrayList([]const u8), |
| 67 | }; | 67 | }; |
| 68 | 68 | ||
| 69 | const TypeId = enum { | 69 | const TypeId = enum { |
| ... | @@ -89,19 +89,19 @@ pub const Builder = struct { | ... | @@ -89,19 +89,19 @@ pub const Builder = struct { |
| 89 | .verbose = false, | 89 | .verbose = false, |
| 90 | .invalid_user_input = false, | 90 | .invalid_user_input = false, |
| 91 | .allocator = allocator, | 91 | .allocator = allocator, |
| 92 | .lib_paths = List([]const u8).init(allocator), | 92 | .lib_paths = ArrayList([]const u8).init(allocator), |
| 93 | .include_paths = List([]const u8).init(allocator), | 93 | .include_paths = ArrayList([]const u8).init(allocator), |
| 94 | .rpaths = List([]const u8).init(allocator), | 94 | .rpaths = ArrayList([]const u8).init(allocator), |
| 95 | .user_input_options = UserInputOptionsMap.init(allocator), | 95 | .user_input_options = UserInputOptionsMap.init(allocator), |
| 96 | .available_options_map = AvailableOptionsMap.init(allocator), | 96 | .available_options_map = AvailableOptionsMap.init(allocator), |
| 97 | .available_options_list = List(AvailableOption).init(allocator), | 97 | .available_options_list = ArrayList(AvailableOption).init(allocator), |
| 98 | .top_level_steps = List(&TopLevelStep).init(allocator), | 98 | .top_level_steps = ArrayList(&TopLevelStep).init(allocator), |
| 99 | .default_step = undefined, | 99 | .default_step = undefined, |
| 100 | .env_map = %%os.getEnvMap(allocator), | 100 | .env_map = %%os.getEnvMap(allocator), |
| 101 | .prefix = undefined, | 101 | .prefix = undefined, |
| 102 | .lib_dir = undefined, | 102 | .lib_dir = undefined, |
| 103 | .exe_dir = undefined, | 103 | .exe_dir = undefined, |
| 104 | .installed_files = List([]const u8).init(allocator), | 104 | .installed_files = ArrayList([]const u8).init(allocator), |
| 105 | .uninstall_tls = TopLevelStep { | 105 | .uninstall_tls = TopLevelStep { |
| 106 | .step = Step.init("uninstall", allocator, makeUninstall), | 106 | .step = Step.init("uninstall", allocator, makeUninstall), |
| 107 | .description = "Remove build artifacts from prefix path", | 107 | .description = "Remove build artifacts from prefix path", |
| ... | @@ -225,7 +225,7 @@ pub const Builder = struct { | ... | @@ -225,7 +225,7 @@ pub const Builder = struct { |
| 225 | } | 225 | } |
| 226 | 226 | ||
| 227 | pub fn make(self: &Builder, step_names: []const []const u8) -> %void { | 227 | pub fn make(self: &Builder, step_names: []const []const u8) -> %void { |
| 228 | var wanted_steps = List(&Step).init(self.allocator); | 228 | var wanted_steps = ArrayList(&Step).init(self.allocator); |
| 229 | defer wanted_steps.deinit(); | 229 | defer wanted_steps.deinit(); |
| 230 | 230 | ||
| 231 | if (step_names.len == 0) { | 231 | if (step_names.len == 0) { |
| ... | @@ -433,7 +433,7 @@ pub const Builder = struct { | ... | @@ -433,7 +433,7 @@ pub const Builder = struct { |
| 433 | switch (prev_value.value) { | 433 | switch (prev_value.value) { |
| 434 | UserValue.Scalar => |s| { | 434 | UserValue.Scalar => |s| { |
| 435 | // turn it into a list | 435 | // turn it into a list |
| 436 | var list = List([]const u8).init(self.allocator); | 436 | var list = ArrayList([]const u8).init(self.allocator); |
| 437 | %%list.append(s); | 437 | %%list.append(s); |
| 438 | %%list.append(value); | 438 | %%list.append(value); |
| 439 | _ = %%self.user_input_options.put(name, UserInputOption { | 439 | _ = %%self.user_input_options.put(name, UserInputOption { |
| ... | @@ -695,9 +695,9 @@ pub const LibExeObjStep = struct { | ... | @@ -695,9 +695,9 @@ pub const LibExeObjStep = struct { |
| 695 | out_filename: []const u8, | 695 | out_filename: []const u8, |
| 696 | major_only_filename: []const u8, | 696 | major_only_filename: []const u8, |
| 697 | name_only_filename: []const u8, | 697 | name_only_filename: []const u8, |
| 698 | object_files: List([]const u8), | 698 | object_files: ArrayList([]const u8), |
| 699 | assembly_files: List([]const u8), | 699 | assembly_files: ArrayList([]const u8), |
| 700 | packages: List(Pkg), | 700 | packages: ArrayList(Pkg), |
| 701 | 701 | ||
| 702 | const Pkg = struct { | 702 | const Pkg = struct { |
| 703 | name: []const u8, | 703 | name: []const u8, |
| ... | @@ -758,9 +758,9 @@ pub const LibExeObjStep = struct { | ... | @@ -758,9 +758,9 @@ pub const LibExeObjStep = struct { |
| 758 | .out_h_filename = builder.fmt("{}.h", name), | 758 | .out_h_filename = builder.fmt("{}.h", name), |
| 759 | .major_only_filename = undefined, | 759 | .major_only_filename = undefined, |
| 760 | .name_only_filename = undefined, | 760 | .name_only_filename = undefined, |
| 761 | .object_files = List([]const u8).init(builder.allocator), | 761 | .object_files = ArrayList([]const u8).init(builder.allocator), |
| 762 | .assembly_files = List([]const u8).init(builder.allocator), | 762 | .assembly_files = ArrayList([]const u8).init(builder.allocator), |
| 763 | .packages = List(Pkg).init(builder.allocator), | 763 | .packages = ArrayList(Pkg).init(builder.allocator), |
| 764 | }; | 764 | }; |
| 765 | self.computeOutFileNames(); | 765 | self.computeOutFileNames(); |
| 766 | return self; | 766 | return self; |
| ... | @@ -875,7 +875,7 @@ pub const LibExeObjStep = struct { | ... | @@ -875,7 +875,7 @@ pub const LibExeObjStep = struct { |
| 875 | return error.NeedAnObject; | 875 | return error.NeedAnObject; |
| 876 | } | 876 | } |
| 877 | 877 | ||
| 878 | var zig_args = List([]const u8).init(builder.allocator); | 878 | var zig_args = ArrayList([]const u8).init(builder.allocator); |
| 879 | defer zig_args.deinit(); | 879 | defer zig_args.deinit(); |
| 880 | 880 | ||
| 881 | const cmd = switch (self.kind) { | 881 | const cmd = switch (self.kind) { |
| ... | @@ -1043,7 +1043,7 @@ pub const TestStep = struct { | ... | @@ -1043,7 +1043,7 @@ pub const TestStep = struct { |
| 1043 | const self = @fieldParentPtr(TestStep, "step", step); | 1043 | const self = @fieldParentPtr(TestStep, "step", step); |
| 1044 | const builder = self.builder; | 1044 | const builder = self.builder; |
| 1045 | 1045 | ||
| 1046 | var zig_args = List([]const u8).init(builder.allocator); | 1046 | var zig_args = ArrayList([]const u8).init(builder.allocator); |
| 1047 | defer zig_args.deinit(); | 1047 | defer zig_args.deinit(); |
| 1048 | 1048 | ||
| 1049 | %%zig_args.append("test"); | 1049 | %%zig_args.append("test"); |
| ... | @@ -1104,14 +1104,14 @@ pub const CLibExeObjStep = struct { | ... | @@ -1104,14 +1104,14 @@ pub const CLibExeObjStep = struct { |
| 1104 | output_path: ?[]const u8, | 1104 | output_path: ?[]const u8, |
| 1105 | static: bool, | 1105 | static: bool, |
| 1106 | version: Version, | 1106 | version: Version, |
| 1107 | cflags: List([]const u8), | 1107 | cflags: ArrayList([]const u8), |
| 1108 | source_files: List([]const u8), | 1108 | source_files: ArrayList([]const u8), |
| 1109 | object_files: List([]const u8), | 1109 | object_files: ArrayList([]const u8), |
| 1110 | link_libs: BufSet, | 1110 | link_libs: BufSet, |
| 1111 | full_path_libs: List([]const u8), | 1111 | full_path_libs: ArrayList([]const u8), |
| 1112 | target: Target, | 1112 | target: Target, |
| 1113 | builder: &Builder, | 1113 | builder: &Builder, |
| 1114 | include_dirs: List([]const u8), | 1114 | include_dirs: ArrayList([]const u8), |
| 1115 | major_only_filename: []const u8, | 1115 | major_only_filename: []const u8, |
| 1116 | name_only_filename: []const u8, | 1116 | name_only_filename: []const u8, |
| 1117 | object_src: []const u8, | 1117 | object_src: []const u8, |
| ... | @@ -1158,13 +1158,13 @@ pub const CLibExeObjStep = struct { | ... | @@ -1158,13 +1158,13 @@ pub const CLibExeObjStep = struct { |
| 1158 | .version = *version, | 1158 | .version = *version, |
| 1159 | .static = static, | 1159 | .static = static, |
| 1160 | .target = Target.Native, | 1160 | .target = Target.Native, |
| 1161 | .cflags = List([]const u8).init(builder.allocator), | 1161 | .cflags = ArrayList([]const u8).init(builder.allocator), |
| 1162 | .source_files = List([]const u8).init(builder.allocator), | 1162 | .source_files = ArrayList([]const u8).init(builder.allocator), |
| 1163 | .object_files = List([]const u8).init(builder.allocator), | 1163 | .object_files = ArrayList([]const u8).init(builder.allocator), |
| 1164 | .step = Step.init(name, builder.allocator, make), | 1164 | .step = Step.init(name, builder.allocator, make), |
| 1165 | .link_libs = BufSet.init(builder.allocator), | 1165 | .link_libs = BufSet.init(builder.allocator), |
| 1166 | .full_path_libs = List([]const u8).init(builder.allocator), | 1166 | .full_path_libs = ArrayList([]const u8).init(builder.allocator), |
| 1167 | .include_dirs = List([]const u8).init(builder.allocator), | 1167 | .include_dirs = ArrayList([]const u8).init(builder.allocator), |
| 1168 | .output_path = null, | 1168 | .output_path = null, |
| 1169 | .out_filename = undefined, | 1169 | .out_filename = undefined, |
| 1170 | .major_only_filename = undefined, | 1170 | .major_only_filename = undefined, |
| ... | @@ -1267,7 +1267,7 @@ pub const CLibExeObjStep = struct { | ... | @@ -1267,7 +1267,7 @@ pub const CLibExeObjStep = struct { |
| 1267 | } | 1267 | } |
| 1268 | } | 1268 | } |
| 1269 | 1269 | ||
| 1270 | fn appendCompileFlags(self: &CLibExeObjStep, args: &List([]const u8)) { | 1270 | fn appendCompileFlags(self: &CLibExeObjStep, args: &ArrayList([]const u8)) { |
| 1271 | if (!self.strip) { | 1271 | if (!self.strip) { |
| 1272 | %%args.append("-g"); | 1272 | %%args.append("-g"); |
| 1273 | } | 1273 | } |
| ... | @@ -1300,7 +1300,7 @@ pub const CLibExeObjStep = struct { | ... | @@ -1300,7 +1300,7 @@ pub const CLibExeObjStep = struct { |
| 1300 | const cc = os.getEnv("CC") ?? "cc"; | 1300 | const cc = os.getEnv("CC") ?? "cc"; |
| 1301 | const builder = self.builder; | 1301 | const builder = self.builder; |
| 1302 | 1302 | ||
| 1303 | var cc_args = List([]const u8).init(builder.allocator); | 1303 | var cc_args = ArrayList([]const u8).init(builder.allocator); |
| 1304 | defer cc_args.deinit(); | 1304 | defer cc_args.deinit(); |
| 1305 | 1305 | ||
| 1306 | switch (self.kind) { | 1306 | switch (self.kind) { |
| ... | @@ -1646,7 +1646,7 @@ pub const RemoveDirStep = struct { | ... | @@ -1646,7 +1646,7 @@ pub const RemoveDirStep = struct { |
| 1646 | pub const Step = struct { | 1646 | pub const Step = struct { |
| 1647 | name: []const u8, | 1647 | name: []const u8, |
| 1648 | makeFn: fn(self: &Step) -> %void, | 1648 | makeFn: fn(self: &Step) -> %void, |
| 1649 | dependencies: List(&Step), | 1649 | dependencies: ArrayList(&Step), |
| 1650 | loop_flag: bool, | 1650 | loop_flag: bool, |
| 1651 | done_flag: bool, | 1651 | done_flag: bool, |
| 1652 | 1652 | ||
| ... | @@ -1654,7 +1654,7 @@ pub const Step = struct { | ... | @@ -1654,7 +1654,7 @@ pub const Step = struct { |
| 1654 | Step { | 1654 | Step { |
| 1655 | .name = name, | 1655 | .name = name, |
| 1656 | .makeFn = makeFn, | 1656 | .makeFn = makeFn, |
| 1657 | .dependencies = List(&Step).init(allocator), | 1657 | .dependencies = ArrayList(&Step).init(allocator), |
| 1658 | .loop_flag = false, | 1658 | .loop_flag = false, |
| 1659 | .done_flag = false, | 1659 | .done_flag = false, |
| 1660 | } | 1660 | } |
std/debug.zig+15-15| ... | @@ -3,7 +3,7 @@ const io = @import("io.zig"); | ... | @@ -3,7 +3,7 @@ const io = @import("io.zig"); |
| 3 | const os = @import("os/index.zig"); | 3 | const os = @import("os/index.zig"); |
| 4 | const elf = @import("elf.zig"); | 4 | const elf = @import("elf.zig"); |
| 5 | const DW = @import("dwarf.zig"); | 5 | const DW = @import("dwarf.zig"); |
| 6 | const List = @import("list.zig").List; | 6 | const ArrayList = @import("array_list.zig").ArrayList; |
| 7 | const builtin = @import("builtin"); | 7 | const builtin = @import("builtin"); |
| 8 | 8 | ||
| 9 | error MissingDebugInfo; | 9 | error MissingDebugInfo; |
| ... | @@ -60,8 +60,8 @@ pub fn writeStackTrace(out_stream: &io.OutStream, allocator: &mem.Allocator, tty | ... | @@ -60,8 +60,8 @@ pub fn writeStackTrace(out_stream: &io.OutStream, allocator: &mem.Allocator, tty |
| 60 | .debug_abbrev = undefined, | 60 | .debug_abbrev = undefined, |
| 61 | .debug_str = undefined, | 61 | .debug_str = undefined, |
| 62 | .debug_line = undefined, | 62 | .debug_line = undefined, |
| 63 | .abbrev_table_list = List(AbbrevTableHeader).init(allocator), | 63 | .abbrev_table_list = ArrayList(AbbrevTableHeader).init(allocator), |
| 64 | .compile_unit_list = List(CompileUnit).init(allocator), | 64 | .compile_unit_list = ArrayList(CompileUnit).init(allocator), |
| 65 | }; | 65 | }; |
| 66 | const st = &stack_trace; | 66 | const st = &stack_trace; |
| 67 | st.self_exe_stream = %return io.openSelfExe(); | 67 | st.self_exe_stream = %return io.openSelfExe(); |
| ... | @@ -179,8 +179,8 @@ const ElfStackTrace = struct { | ... | @@ -179,8 +179,8 @@ const ElfStackTrace = struct { |
| 179 | debug_abbrev: &elf.SectionHeader, | 179 | debug_abbrev: &elf.SectionHeader, |
| 180 | debug_str: &elf.SectionHeader, | 180 | debug_str: &elf.SectionHeader, |
| 181 | debug_line: &elf.SectionHeader, | 181 | debug_line: &elf.SectionHeader, |
| 182 | abbrev_table_list: List(AbbrevTableHeader), | 182 | abbrev_table_list: ArrayList(AbbrevTableHeader), |
| 183 | compile_unit_list: List(CompileUnit), | 183 | compile_unit_list: ArrayList(CompileUnit), |
| 184 | 184 | ||
| 185 | pub fn allocator(self: &const ElfStackTrace) -> &mem.Allocator { | 185 | pub fn allocator(self: &const ElfStackTrace) -> &mem.Allocator { |
| 186 | return self.abbrev_table_list.allocator; | 186 | return self.abbrev_table_list.allocator; |
| ... | @@ -204,7 +204,7 @@ const CompileUnit = struct { | ... | @@ -204,7 +204,7 @@ const CompileUnit = struct { |
| 204 | pc_range: ?PcRange, | 204 | pc_range: ?PcRange, |
| 205 | }; | 205 | }; |
| 206 | 206 | ||
| 207 | const AbbrevTable = List(AbbrevTableEntry); | 207 | const AbbrevTable = ArrayList(AbbrevTableEntry); |
| 208 | 208 | ||
| 209 | const AbbrevTableHeader = struct { | 209 | const AbbrevTableHeader = struct { |
| 210 | // offset from .debug_abbrev | 210 | // offset from .debug_abbrev |
| ... | @@ -216,7 +216,7 @@ const AbbrevTableEntry = struct { | ... | @@ -216,7 +216,7 @@ const AbbrevTableEntry = struct { |
| 216 | has_children: bool, | 216 | has_children: bool, |
| 217 | abbrev_code: u64, | 217 | abbrev_code: u64, |
| 218 | tag_id: u64, | 218 | tag_id: u64, |
| 219 | attrs: List(AbbrevAttr), | 219 | attrs: ArrayList(AbbrevAttr), |
| 220 | }; | 220 | }; |
| 221 | 221 | ||
| 222 | const AbbrevAttr = struct { | 222 | const AbbrevAttr = struct { |
| ... | @@ -254,7 +254,7 @@ const Constant = struct { | ... | @@ -254,7 +254,7 @@ const Constant = struct { |
| 254 | const Die = struct { | 254 | const Die = struct { |
| 255 | tag_id: u64, | 255 | tag_id: u64, |
| 256 | has_children: bool, | 256 | has_children: bool, |
| 257 | attrs: List(Attr), | 257 | attrs: ArrayList(Attr), |
| 258 | 258 | ||
| 259 | const Attr = struct { | 259 | const Attr = struct { |
| 260 | id: u64, | 260 | id: u64, |
| ... | @@ -324,7 +324,7 @@ const LineNumberProgram = struct { | ... | @@ -324,7 +324,7 @@ const LineNumberProgram = struct { |
| 324 | 324 | ||
| 325 | target_address: usize, | 325 | target_address: usize, |
| 326 | include_dirs: []const []const u8, | 326 | include_dirs: []const []const u8, |
| 327 | file_entries: &List(FileEntry), | 327 | file_entries: &ArrayList(FileEntry), |
| 328 | 328 | ||
| 329 | prev_address: usize, | 329 | prev_address: usize, |
| 330 | prev_file: usize, | 330 | prev_file: usize, |
| ... | @@ -335,7 +335,7 @@ const LineNumberProgram = struct { | ... | @@ -335,7 +335,7 @@ const LineNumberProgram = struct { |
| 335 | prev_end_sequence: bool, | 335 | prev_end_sequence: bool, |
| 336 | 336 | ||
| 337 | pub fn init(is_stmt: bool, include_dirs: []const []const u8, | 337 | pub fn init(is_stmt: bool, include_dirs: []const []const u8, |
| 338 | file_entries: &List(FileEntry), target_address: usize) -> LineNumberProgram | 338 | file_entries: &ArrayList(FileEntry), target_address: usize) -> LineNumberProgram |
| 339 | { | 339 | { |
| 340 | LineNumberProgram { | 340 | LineNumberProgram { |
| 341 | .address = 0, | 341 | .address = 0, |
| ... | @@ -394,7 +394,7 @@ const LineNumberProgram = struct { | ... | @@ -394,7 +394,7 @@ const LineNumberProgram = struct { |
| 394 | }; | 394 | }; |
| 395 | 395 | ||
| 396 | fn readStringRaw(allocator: &mem.Allocator, in_stream: &io.InStream) -> %[]u8 { | 396 | fn readStringRaw(allocator: &mem.Allocator, in_stream: &io.InStream) -> %[]u8 { |
| 397 | var buf = List(u8).init(allocator); | 397 | var buf = ArrayList(u8).init(allocator); |
| 398 | while (true) { | 398 | while (true) { |
| 399 | const byte = %return in_stream.readByte(); | 399 | const byte = %return in_stream.readByte(); |
| 400 | if (byte == 0) | 400 | if (byte == 0) |
| ... | @@ -525,7 +525,7 @@ fn parseAbbrevTable(st: &ElfStackTrace) -> %AbbrevTable { | ... | @@ -525,7 +525,7 @@ fn parseAbbrevTable(st: &ElfStackTrace) -> %AbbrevTable { |
| 525 | .abbrev_code = abbrev_code, | 525 | .abbrev_code = abbrev_code, |
| 526 | .tag_id = %return readULeb128(in_stream), | 526 | .tag_id = %return readULeb128(in_stream), |
| 527 | .has_children = (%return in_stream.readByte()) == DW.CHILDREN_yes, | 527 | .has_children = (%return in_stream.readByte()) == DW.CHILDREN_yes, |
| 528 | .attrs = List(AbbrevAttr).init(st.allocator()), | 528 | .attrs = ArrayList(AbbrevAttr).init(st.allocator()), |
| 529 | }); | 529 | }); |
| 530 | const attrs = &result.items[result.len - 1].attrs; | 530 | const attrs = &result.items[result.len - 1].attrs; |
| 531 | 531 | ||
| ... | @@ -574,7 +574,7 @@ fn parseDie(st: &ElfStackTrace, abbrev_table: &const AbbrevTable, is_64: bool) - | ... | @@ -574,7 +574,7 @@ fn parseDie(st: &ElfStackTrace, abbrev_table: &const AbbrevTable, is_64: bool) - |
| 574 | var result = Die { | 574 | var result = Die { |
| 575 | .tag_id = table_entry.tag_id, | 575 | .tag_id = table_entry.tag_id, |
| 576 | .has_children = table_entry.has_children, | 576 | .has_children = table_entry.has_children, |
| 577 | .attrs = List(Die.Attr).init(st.allocator()), | 577 | .attrs = ArrayList(Die.Attr).init(st.allocator()), |
| 578 | }; | 578 | }; |
| 579 | %return result.attrs.resize(table_entry.attrs.len); | 579 | %return result.attrs.resize(table_entry.attrs.len); |
| 580 | for (table_entry.attrs.toSliceConst()) |attr, i| { | 580 | for (table_entry.attrs.toSliceConst()) |attr, i| { |
| ... | @@ -632,7 +632,7 @@ fn getLineNumberInfo(st: &ElfStackTrace, compile_unit: &const CompileUnit, targe | ... | @@ -632,7 +632,7 @@ fn getLineNumberInfo(st: &ElfStackTrace, compile_unit: &const CompileUnit, targe |
| 632 | standard_opcode_lengths[i] = %return in_stream.readByte(); | 632 | standard_opcode_lengths[i] = %return in_stream.readByte(); |
| 633 | }} | 633 | }} |
| 634 | 634 | ||
| 635 | var include_directories = List([]u8).init(st.allocator()); | 635 | var include_directories = ArrayList([]u8).init(st.allocator()); |
| 636 | %return include_directories.append(compile_unit_cwd); | 636 | %return include_directories.append(compile_unit_cwd); |
| 637 | while (true) { | 637 | while (true) { |
| 638 | const dir = %return st.readString(); | 638 | const dir = %return st.readString(); |
| ... | @@ -641,7 +641,7 @@ fn getLineNumberInfo(st: &ElfStackTrace, compile_unit: &const CompileUnit, targe | ... | @@ -641,7 +641,7 @@ fn getLineNumberInfo(st: &ElfStackTrace, compile_unit: &const CompileUnit, targe |
| 641 | %return include_directories.append(dir); | 641 | %return include_directories.append(dir); |
| 642 | } | 642 | } |
| 643 | 643 | ||
| 644 | var file_entries = List(FileEntry).init(st.allocator()); | 644 | var file_entries = ArrayList(FileEntry).init(st.allocator()); |
| 645 | var prog = LineNumberProgram.init(default_is_stmt, include_directories.toSliceConst(), | 645 | var prog = LineNumberProgram.init(default_is_stmt, include_directories.toSliceConst(), |
| 646 | &file_entries, target_address); | 646 | &file_entries, target_address); |
| 647 | 647 |
std/index.zig+21-8| ... | @@ -1,15 +1,21 @@ | ... | @@ -1,15 +1,21 @@ |
| 1 | pub const ArrayList = @import("array_list.zig").ArrayList; | ||
| 2 | pub const BufMap = @import("buf_map.zig").BufMap; | ||
| 3 | pub const BufSet = @import("buf_set.zig").BufSet; | ||
| 4 | pub const Buffer = @import("buffer.zig").Buffer; | ||
| 5 | pub const HashMap = @import("hash_map.zig").HashMap; | ||
| 6 | pub const LinkedList = @import("linked_list.zig").LinkedList; | ||
| 7 | |||
| 1 | pub const base64 = @import("base64.zig"); | 8 | pub const base64 = @import("base64.zig"); |
| 2 | pub const buffer = @import("buffer.zig"); | ||
| 3 | pub const build = @import("build.zig"); | 9 | pub const build = @import("build.zig"); |
| 4 | pub const c = @import("c/index.zig"); | 10 | pub const c = @import("c/index.zig"); |
| 5 | pub const cstr = @import("cstr.zig"); | 11 | pub const cstr = @import("cstr.zig"); |
| 6 | pub const debug = @import("debug.zig"); | 12 | pub const debug = @import("debug.zig"); |
| 13 | pub const dwarf = @import("dwarf.zig"); | ||
| 14 | pub const elf = @import("elf.zig"); | ||
| 7 | pub const empty_import = @import("empty.zig"); | 15 | pub const empty_import = @import("empty.zig"); |
| 16 | pub const endian = @import("endian.zig"); | ||
| 8 | pub const fmt = @import("fmt.zig"); | 17 | pub const fmt = @import("fmt.zig"); |
| 9 | pub const hash_map = @import("hash_map.zig"); | ||
| 10 | pub const io = @import("io.zig"); | 18 | pub const io = @import("io.zig"); |
| 11 | pub const linked_list = @import("linked_list.zig"); | ||
| 12 | pub const list = @import("list.zig"); | ||
| 13 | pub const math = @import("math.zig"); | 19 | pub const math = @import("math.zig"); |
| 14 | pub const mem = @import("mem.zig"); | 20 | pub const mem = @import("mem.zig"); |
| 15 | pub const net = @import("net.zig"); | 21 | pub const net = @import("net.zig"); |
| ... | @@ -20,17 +26,24 @@ pub const target = @import("target.zig"); | ... | @@ -20,17 +26,24 @@ pub const target = @import("target.zig"); |
| 20 | 26 | ||
| 21 | test "std" { | 27 | test "std" { |
| 22 | // run tests from these | 28 | // run tests from these |
| 29 | _ = @import("array_list.zig").ArrayList; | ||
| 30 | _ = @import("buf_map.zig").BufMap; | ||
| 31 | _ = @import("buf_set.zig").BufSet; | ||
| 32 | _ = @import("buffer.zig").Buffer; | ||
| 33 | _ = @import("hash_map.zig").HashMap; | ||
| 34 | _ = @import("linked_list.zig").LinkedList; | ||
| 35 | |||
| 23 | _ = @import("base64.zig"); | 36 | _ = @import("base64.zig"); |
| 24 | _ = @import("buffer.zig"); | ||
| 25 | _ = @import("build.zig"); | 37 | _ = @import("build.zig"); |
| 26 | _ = @import("c/index.zig"); | 38 | _ = @import("c/index.zig"); |
| 27 | _ = @import("cstr.zig"); | 39 | _ = @import("cstr.zig"); |
| 28 | _ = @import("debug.zig"); | 40 | _ = @import("debug.zig"); |
| 41 | _ = @import("dwarf.zig"); | ||
| 42 | _ = @import("elf.zig"); | ||
| 43 | _ = @import("empty.zig"); | ||
| 44 | _ = @import("endian.zig"); | ||
| 29 | _ = @import("fmt.zig"); | 45 | _ = @import("fmt.zig"); |
| 30 | _ = @import("hash_map.zig"); | ||
| 31 | _ = @import("io.zig"); | 46 | _ = @import("io.zig"); |
| 32 | _ = @import("linked_list.zig"); | ||
| 33 | _ = @import("list.zig"); | ||
| 34 | _ = @import("math.zig"); | 47 | _ = @import("math.zig"); |
| 35 | _ = @import("mem.zig"); | 48 | _ = @import("mem.zig"); |
| 36 | _ = @import("net.zig"); | 49 | _ = @import("net.zig"); |
std/linked_list.zig+13-13| ... | @@ -6,7 +6,7 @@ const Allocator = mem.Allocator; | ... | @@ -6,7 +6,7 @@ const Allocator = mem.Allocator; |
| 6 | /// Generic doubly linked list. | 6 | /// Generic doubly linked list. |
| 7 | pub fn LinkedList(comptime T: type) -> type { | 7 | pub fn LinkedList(comptime T: type) -> type { |
| 8 | struct { | 8 | struct { |
| 9 | const List = this; | 9 | const Self = this; |
| 10 | 10 | ||
| 11 | /// Node inside the linked list wrapping the actual data. | 11 | /// Node inside the linked list wrapping the actual data. |
| 12 | pub const Node = struct { | 12 | pub const Node = struct { |
| ... | @@ -27,8 +27,8 @@ pub fn LinkedList(comptime T: type) -> type { | ... | @@ -27,8 +27,8 @@ pub fn LinkedList(comptime T: type) -> type { |
| 27 | /// | 27 | /// |
| 28 | /// Returns: | 28 | /// Returns: |
| 29 | /// An empty linked list. | 29 | /// An empty linked list. |
| 30 | pub fn init(allocator: &Allocator) -> List { | 30 | pub fn init(allocator: &Allocator) -> Self { |
| 31 | List { | 31 | Self { |
| 32 | .first = null, | 32 | .first = null, |
| 33 | .last = null, | 33 | .last = null, |
| 34 | .len = 0, | 34 | .len = 0, |
| ... | @@ -41,7 +41,7 @@ pub fn LinkedList(comptime T: type) -> type { | ... | @@ -41,7 +41,7 @@ pub fn LinkedList(comptime T: type) -> type { |
| 41 | /// Arguments: | 41 | /// Arguments: |
| 42 | /// node: Pointer to a node in the list. | 42 | /// node: Pointer to a node in the list. |
| 43 | /// new_node: Pointer to the new node to insert. | 43 | /// new_node: Pointer to the new node to insert. |
| 44 | pub fn insertAfter(list: &List, node: &Node, new_node: &Node) { | 44 | pub fn insertAfter(list: &Self, node: &Node, new_node: &Node) { |
| 45 | new_node.prev = node; | 45 | new_node.prev = node; |
| 46 | if (node.next) |next_node| { | 46 | if (node.next) |next_node| { |
| 47 | // Intermediate node. | 47 | // Intermediate node. |
| ... | @@ -62,7 +62,7 @@ pub fn LinkedList(comptime T: type) -> type { | ... | @@ -62,7 +62,7 @@ pub fn LinkedList(comptime T: type) -> type { |
| 62 | /// Arguments: | 62 | /// Arguments: |
| 63 | /// node: Pointer to a node in the list. | 63 | /// node: Pointer to a node in the list. |
| 64 | /// new_node: Pointer to the new node to insert. | 64 | /// new_node: Pointer to the new node to insert. |
| 65 | pub fn insertBefore(list: &List, node: &Node, new_node: &Node) { | 65 | pub fn insertBefore(list: &Self, node: &Node, new_node: &Node) { |
| 66 | new_node.next = node; | 66 | new_node.next = node; |
| 67 | if (node.prev) |prev_node| { | 67 | if (node.prev) |prev_node| { |
| 68 | // Intermediate node. | 68 | // Intermediate node. |
| ... | @@ -82,7 +82,7 @@ pub fn LinkedList(comptime T: type) -> type { | ... | @@ -82,7 +82,7 @@ pub fn LinkedList(comptime T: type) -> type { |
| 82 | /// | 82 | /// |
| 83 | /// Arguments: | 83 | /// Arguments: |
| 84 | /// new_node: Pointer to the new node to insert. | 84 | /// new_node: Pointer to the new node to insert. |
| 85 | pub fn append(list: &List, new_node: &Node) { | 85 | pub fn append(list: &Self, new_node: &Node) { |
| 86 | if (list.last) |last| { | 86 | if (list.last) |last| { |
| 87 | // Insert after last. | 87 | // Insert after last. |
| 88 | list.insertAfter(last, new_node); | 88 | list.insertAfter(last, new_node); |
| ... | @@ -96,7 +96,7 @@ pub fn LinkedList(comptime T: type) -> type { | ... | @@ -96,7 +96,7 @@ pub fn LinkedList(comptime T: type) -> type { |
| 96 | /// | 96 | /// |
| 97 | /// Arguments: | 97 | /// Arguments: |
| 98 | /// new_node: Pointer to the new node to insert. | 98 | /// new_node: Pointer to the new node to insert. |
| 99 | pub fn prepend(list: &List, new_node: &Node) { | 99 | pub fn prepend(list: &Self, new_node: &Node) { |
| 100 | if (list.first) |first| { | 100 | if (list.first) |first| { |
| 101 | // Insert before first. | 101 | // Insert before first. |
| 102 | list.insertBefore(first, new_node); | 102 | list.insertBefore(first, new_node); |
| ... | @@ -115,7 +115,7 @@ pub fn LinkedList(comptime T: type) -> type { | ... | @@ -115,7 +115,7 @@ pub fn LinkedList(comptime T: type) -> type { |
| 115 | /// | 115 | /// |
| 116 | /// Arguments: | 116 | /// Arguments: |
| 117 | /// node: Pointer to the node to be removed. | 117 | /// node: Pointer to the node to be removed. |
| 118 | pub fn remove(list: &List, node: &Node) { | 118 | pub fn remove(list: &Self, node: &Node) { |
| 119 | if (node.prev) |prev_node| { | 119 | if (node.prev) |prev_node| { |
| 120 | // Intermediate node. | 120 | // Intermediate node. |
| 121 | prev_node.next = node.next; | 121 | prev_node.next = node.next; |
| ... | @@ -139,7 +139,7 @@ pub fn LinkedList(comptime T: type) -> type { | ... | @@ -139,7 +139,7 @@ pub fn LinkedList(comptime T: type) -> type { |
| 139 | /// | 139 | /// |
| 140 | /// Returns: | 140 | /// Returns: |
| 141 | /// A pointer to the last node in the list. | 141 | /// A pointer to the last node in the list. |
| 142 | pub fn pop(list: &List) -> ?&Node { | 142 | pub fn pop(list: &Self) -> ?&Node { |
| 143 | const last = list.last ?? return null; | 143 | const last = list.last ?? return null; |
| 144 | list.remove(last); | 144 | list.remove(last); |
| 145 | return last; | 145 | return last; |
| ... | @@ -149,7 +149,7 @@ pub fn LinkedList(comptime T: type) -> type { | ... | @@ -149,7 +149,7 @@ pub fn LinkedList(comptime T: type) -> type { |
| 149 | /// | 149 | /// |
| 150 | /// Returns: | 150 | /// Returns: |
| 151 | /// A pointer to the first node in the list. | 151 | /// A pointer to the first node in the list. |
| 152 | pub fn popFirst(list: &List) -> ?&Node { | 152 | pub fn popFirst(list: &Self) -> ?&Node { |
| 153 | const first = list.first ?? return null; | 153 | const first = list.first ?? return null; |
| 154 | list.remove(first); | 154 | list.remove(first); |
| 155 | return first; | 155 | return first; |
| ... | @@ -159,7 +159,7 @@ pub fn LinkedList(comptime T: type) -> type { | ... | @@ -159,7 +159,7 @@ pub fn LinkedList(comptime T: type) -> type { |
| 159 | /// | 159 | /// |
| 160 | /// Returns: | 160 | /// Returns: |
| 161 | /// A pointer to the new node. | 161 | /// A pointer to the new node. |
| 162 | pub fn allocateNode(list: &List) -> %&Node { | 162 | pub fn allocateNode(list: &Self) -> %&Node { |
| 163 | list.allocator.create(Node) | 163 | list.allocator.create(Node) |
| 164 | } | 164 | } |
| 165 | 165 | ||
| ... | @@ -167,7 +167,7 @@ pub fn LinkedList(comptime T: type) -> type { | ... | @@ -167,7 +167,7 @@ pub fn LinkedList(comptime T: type) -> type { |
| 167 | /// | 167 | /// |
| 168 | /// Arguments: | 168 | /// Arguments: |
| 169 | /// node: Pointer to the node to deallocate. | 169 | /// node: Pointer to the node to deallocate. |
| 170 | pub fn destroyNode(list: &List, node: &Node) { | 170 | pub fn destroyNode(list: &Self, node: &Node) { |
| 171 | list.allocator.destroy(node); | 171 | list.allocator.destroy(node); |
| 172 | } | 172 | } |
| 173 | 173 | ||
| ... | @@ -178,7 +178,7 @@ pub fn LinkedList(comptime T: type) -> type { | ... | @@ -178,7 +178,7 @@ pub fn LinkedList(comptime T: type) -> type { |
| 178 | /// | 178 | /// |
| 179 | /// Returns: | 179 | /// Returns: |
| 180 | /// A pointer to the new node. | 180 | /// A pointer to the new node. |
| 181 | pub fn createNode(list: &List, data: &const T) -> %&Node { | 181 | pub fn createNode(list: &Self, data: &const T) -> %&Node { |
| 182 | var node = %return list.allocateNode(); | 182 | var node = %return list.allocateNode(); |
| 183 | *node = Node { | 183 | *node = Node { |
| 184 | .prev = null, | 184 | .prev = null, |
std/list.zig deleted-91| ... | @@ -1,91 +0,0 @@ | ||
| 1 | const debug = @import("debug.zig"); | ||
| 2 | const assert = debug.assert; | ||
| 3 | const mem = @import("mem.zig"); | ||
| 4 | const Allocator = mem.Allocator; | ||
| 5 | |||
| 6 | pub fn List(comptime T: type) -> type{ | ||
| 7 | struct { | ||
| 8 | const Self = this; | ||
| 9 | |||
| 10 | /// Use toSlice instead of slicing this directly, because if you don't | ||
| 11 | /// specify the end position of the slice, this will potentially give | ||
| 12 | /// you uninitialized memory. | ||
| 13 | items: []T, | ||
| 14 | len: usize, | ||
| 15 | allocator: &Allocator, | ||
| 16 | |||
| 17 | pub fn init(allocator: &Allocator) -> Self { | ||
| 18 | Self { | ||
| 19 | .items = []T{}, | ||
| 20 | .len = 0, | ||
| 21 | .allocator = allocator, | ||
| 22 | } | ||
| 23 | } | ||
| 24 | |||
| 25 | pub fn deinit(l: &Self) { | ||
| 26 | l.allocator.free(l.items); | ||
| 27 | } | ||
| 28 | |||
| 29 | pub fn toSlice(l: &Self) -> []T { | ||
| 30 | return l.items[0...l.len]; | ||
| 31 | } | ||
| 32 | |||
| 33 | pub fn toSliceConst(l: &const Self) -> []const T { | ||
| 34 | return l.items[0...l.len]; | ||
| 35 | } | ||
| 36 | |||
| 37 | pub fn append(l: &Self, item: &const T) -> %void { | ||
| 38 | const new_item_ptr = %return l.addOne(); | ||
| 39 | *new_item_ptr = *item; | ||
| 40 | } | ||
| 41 | |||
| 42 | pub fn resize(l: &Self, new_len: usize) -> %void { | ||
| 43 | %return l.ensureCapacity(new_len); | ||
| 44 | l.len = new_len; | ||
| 45 | } | ||
| 46 | |||
| 47 | pub fn resizeDown(l: &Self, new_len: usize) { | ||
| 48 | assert(new_len <= l.len); | ||
| 49 | l.len = new_len; | ||
| 50 | } | ||
| 51 | |||
| 52 | pub fn ensureCapacity(l: &Self, new_capacity: usize) -> %void { | ||
| 53 | var better_capacity = l.items.len; | ||
| 54 | if (better_capacity >= new_capacity) return; | ||
| 55 | while (true) { | ||
| 56 | better_capacity += better_capacity / 2 + 8; | ||
| 57 | if (better_capacity >= new_capacity) break; | ||
| 58 | } | ||
| 59 | l.items = %return l.allocator.realloc(T, l.items, better_capacity); | ||
| 60 | } | ||
| 61 | |||
| 62 | pub fn addOne(l: &Self) -> %&T { | ||
| 63 | const new_length = l.len + 1; | ||
| 64 | %return l.ensureCapacity(new_length); | ||
| 65 | const result = &l.items[l.len]; | ||
| 66 | l.len = new_length; | ||
| 67 | return result; | ||
| 68 | } | ||
| 69 | |||
| 70 | pub fn pop(self: &Self) -> T { | ||
| 71 | self.len -= 1; | ||
| 72 | return self.items[self.len]; | ||
| 73 | } | ||
| 74 | } | ||
| 75 | } | ||
| 76 | |||
| 77 | test "basic list test" { | ||
| 78 | var list = List(i32).init(&debug.global_allocator); | ||
| 79 | defer list.deinit(); | ||
| 80 | |||
| 81 | {var i: usize = 0; while (i < 10) : (i += 1) { | ||
| 82 | %%list.append(i32(i + 1)); | ||
| 83 | }} | ||
| 84 | |||
| 85 | {var i: usize = 0; while (i < 10) : (i += 1) { | ||
| 86 | assert(list.items[i] == i32(i + 1)); | ||
| 87 | }} | ||
| 88 | |||
| 89 | assert(list.pop() == 10); | ||
| 90 | assert(list.len == 9); | ||
| 91 | } | ||
std/os/index.zig+2-2| ... | @@ -36,7 +36,7 @@ const cstr = @import("../cstr.zig"); | ... | @@ -36,7 +36,7 @@ const cstr = @import("../cstr.zig"); |
| 36 | 36 | ||
| 37 | const io = @import("../io.zig"); | 37 | const io = @import("../io.zig"); |
| 38 | const base64 = @import("../base64.zig"); | 38 | const base64 = @import("../base64.zig"); |
| 39 | const List = @import("../list.zig").List; | 39 | const ArrayList = @import("../array_list.zig").ArrayList; |
| 40 | 40 | ||
| 41 | error Unexpected; | 41 | error Unexpected; |
| 42 | error SystemResources; | 42 | error SystemResources; |
| ... | @@ -683,7 +683,7 @@ start_over: | ... | @@ -683,7 +683,7 @@ start_over: |
| 683 | }; | 683 | }; |
| 684 | defer dir.close(); | 684 | defer dir.close(); |
| 685 | 685 | ||
| 686 | var full_entry_buf = List(u8).init(allocator); | 686 | var full_entry_buf = ArrayList(u8).init(allocator); |
| 687 | defer full_entry_buf.deinit(); | 687 | defer full_entry_buf.deinit(); |
| 688 | 688 | ||
| 689 | while (%return dir.next()) |entry| { | 689 | while (%return dir.next()) |entry| { |
std/special/build_runner.zig+2-2| ... | @@ -5,7 +5,7 @@ const fmt = std.fmt; | ... | @@ -5,7 +5,7 @@ const fmt = std.fmt; |
| 5 | const os = std.os; | 5 | const os = std.os; |
| 6 | const Builder = std.build.Builder; | 6 | const Builder = std.build.Builder; |
| 7 | const mem = std.mem; | 7 | const mem = std.mem; |
| 8 | const List = std.list.List; | 8 | const ArrayList = std.ArrayList; |
| 9 | 9 | ||
| 10 | error InvalidArgs; | 10 | error InvalidArgs; |
| 11 | 11 | ||
| ... | @@ -51,7 +51,7 @@ pub fn main() -> %void { | ... | @@ -51,7 +51,7 @@ pub fn main() -> %void { |
| 51 | var builder = Builder.init(allocator, zig_exe, build_root, cache_root); | 51 | var builder = Builder.init(allocator, zig_exe, build_root, cache_root); |
| 52 | defer builder.deinit(); | 52 | defer builder.deinit(); |
| 53 | 53 | ||
| 54 | var targets = List([]const u8).init(allocator); | 54 | var targets = ArrayList([]const u8).init(allocator); |
| 55 | 55 | ||
| 56 | var prefix: ?[]const u8 = null; | 56 | var prefix: ?[]const u8 = null; |
| 57 | 57 |
test/tests.zig+15-15| ... | @@ -4,11 +4,11 @@ const build = std.build; | ... | @@ -4,11 +4,11 @@ const build = std.build; |
| 4 | const os = std.os; | 4 | const os = std.os; |
| 5 | const StdIo = os.ChildProcess.StdIo; | 5 | const StdIo = os.ChildProcess.StdIo; |
| 6 | const Term = os.ChildProcess.Term; | 6 | const Term = os.ChildProcess.Term; |
| 7 | const Buffer = std.buffer.Buffer; | 7 | const Buffer = std.Buffer; |
| 8 | const io = std.io; | 8 | const io = std.io; |
| 9 | const mem = std.mem; | 9 | const mem = std.mem; |
| 10 | const fmt = std.fmt; | 10 | const fmt = std.fmt; |
| 11 | const List = std.list.List; | 11 | const ArrayList = std.ArrayList; |
| 12 | const Mode = @import("builtin").Mode; | 12 | const Mode = @import("builtin").Mode; |
| 13 | 13 | ||
| 14 | const compare_output = @import("compare_output.zig"); | 14 | const compare_output = @import("compare_output.zig"); |
| ... | @@ -138,7 +138,7 @@ pub const CompareOutputContext = struct { | ... | @@ -138,7 +138,7 @@ pub const CompareOutputContext = struct { |
| 138 | 138 | ||
| 139 | const TestCase = struct { | 139 | const TestCase = struct { |
| 140 | name: []const u8, | 140 | name: []const u8, |
| 141 | sources: List(SourceFile), | 141 | sources: ArrayList(SourceFile), |
| 142 | expected_output: []const u8, | 142 | expected_output: []const u8, |
| 143 | link_libc: bool, | 143 | link_libc: bool, |
| 144 | special: Special, | 144 | special: Special, |
| ... | @@ -304,7 +304,7 @@ pub const CompareOutputContext = struct { | ... | @@ -304,7 +304,7 @@ pub const CompareOutputContext = struct { |
| 304 | { | 304 | { |
| 305 | var tc = TestCase { | 305 | var tc = TestCase { |
| 306 | .name = name, | 306 | .name = name, |
| 307 | .sources = List(TestCase.SourceFile).init(self.b.allocator), | 307 | .sources = ArrayList(TestCase.SourceFile).init(self.b.allocator), |
| 308 | .expected_output = expected_output, | 308 | .expected_output = expected_output, |
| 309 | .link_libc = false, | 309 | .link_libc = false, |
| 310 | .special = special, | 310 | .special = special, |
| ... | @@ -432,8 +432,8 @@ pub const CompileErrorContext = struct { | ... | @@ -432,8 +432,8 @@ pub const CompileErrorContext = struct { |
| 432 | 432 | ||
| 433 | const TestCase = struct { | 433 | const TestCase = struct { |
| 434 | name: []const u8, | 434 | name: []const u8, |
| 435 | sources: List(SourceFile), | 435 | sources: ArrayList(SourceFile), |
| 436 | expected_errors: List([]const u8), | 436 | expected_errors: ArrayList([]const u8), |
| 437 | link_libc: bool, | 437 | link_libc: bool, |
| 438 | is_exe: bool, | 438 | is_exe: bool, |
| 439 | 439 | ||
| ... | @@ -486,7 +486,7 @@ pub const CompileErrorContext = struct { | ... | @@ -486,7 +486,7 @@ pub const CompileErrorContext = struct { |
| 486 | const root_src = %%os.path.join(b.allocator, b.cache_root, self.case.sources.items[0].filename); | 486 | const root_src = %%os.path.join(b.allocator, b.cache_root, self.case.sources.items[0].filename); |
| 487 | const obj_path = %%os.path.join(b.allocator, b.cache_root, "test.o"); | 487 | const obj_path = %%os.path.join(b.allocator, b.cache_root, "test.o"); |
| 488 | 488 | ||
| 489 | var zig_args = List([]const u8).init(b.allocator); | 489 | var zig_args = ArrayList([]const u8).init(b.allocator); |
| 490 | %%zig_args.append(if (self.case.is_exe) "build_exe" else "build_obj"); | 490 | %%zig_args.append(if (self.case.is_exe) "build_exe" else "build_obj"); |
| 491 | %%zig_args.append(b.pathFromRoot(root_src)); | 491 | %%zig_args.append(b.pathFromRoot(root_src)); |
| 492 | 492 | ||
| ... | @@ -583,8 +583,8 @@ pub const CompileErrorContext = struct { | ... | @@ -583,8 +583,8 @@ pub const CompileErrorContext = struct { |
| 583 | const tc = %%self.b.allocator.create(TestCase); | 583 | const tc = %%self.b.allocator.create(TestCase); |
| 584 | *tc = TestCase { | 584 | *tc = TestCase { |
| 585 | .name = name, | 585 | .name = name, |
| 586 | .sources = List(TestCase.SourceFile).init(self.b.allocator), | 586 | .sources = ArrayList(TestCase.SourceFile).init(self.b.allocator), |
| 587 | .expected_errors = List([]const u8).init(self.b.allocator), | 587 | .expected_errors = ArrayList([]const u8).init(self.b.allocator), |
| 588 | .link_libc = false, | 588 | .link_libc = false, |
| 589 | .is_exe = false, | 589 | .is_exe = false, |
| 590 | }; | 590 | }; |
| ... | @@ -660,7 +660,7 @@ pub const BuildExamplesContext = struct { | ... | @@ -660,7 +660,7 @@ pub const BuildExamplesContext = struct { |
| 660 | return; | 660 | return; |
| 661 | } | 661 | } |
| 662 | 662 | ||
| 663 | var zig_args = List([]const u8).init(b.allocator); | 663 | var zig_args = ArrayList([]const u8).init(b.allocator); |
| 664 | %%zig_args.append("build"); | 664 | %%zig_args.append("build"); |
| 665 | 665 | ||
| 666 | %%zig_args.append("--build-file"); | 666 | %%zig_args.append("--build-file"); |
| ... | @@ -713,8 +713,8 @@ pub const ParseHContext = struct { | ... | @@ -713,8 +713,8 @@ pub const ParseHContext = struct { |
| 713 | 713 | ||
| 714 | const TestCase = struct { | 714 | const TestCase = struct { |
| 715 | name: []const u8, | 715 | name: []const u8, |
| 716 | sources: List(SourceFile), | 716 | sources: ArrayList(SourceFile), |
| 717 | expected_lines: List([]const u8), | 717 | expected_lines: ArrayList([]const u8), |
| 718 | allow_warnings: bool, | 718 | allow_warnings: bool, |
| 719 | 719 | ||
| 720 | const SourceFile = struct { | 720 | const SourceFile = struct { |
| ... | @@ -761,7 +761,7 @@ pub const ParseHContext = struct { | ... | @@ -761,7 +761,7 @@ pub const ParseHContext = struct { |
| 761 | 761 | ||
| 762 | const root_src = %%os.path.join(b.allocator, b.cache_root, self.case.sources.items[0].filename); | 762 | const root_src = %%os.path.join(b.allocator, b.cache_root, self.case.sources.items[0].filename); |
| 763 | 763 | ||
| 764 | var zig_args = List([]const u8).init(b.allocator); | 764 | var zig_args = ArrayList([]const u8).init(b.allocator); |
| 765 | %%zig_args.append("parseh"); | 765 | %%zig_args.append("parseh"); |
| 766 | %%zig_args.append(b.pathFromRoot(root_src)); | 766 | %%zig_args.append(b.pathFromRoot(root_src)); |
| 767 | 767 | ||
| ... | @@ -847,8 +847,8 @@ pub const ParseHContext = struct { | ... | @@ -847,8 +847,8 @@ pub const ParseHContext = struct { |
| 847 | const tc = %%self.b.allocator.create(TestCase); | 847 | const tc = %%self.b.allocator.create(TestCase); |
| 848 | *tc = TestCase { | 848 | *tc = TestCase { |
| 849 | .name = name, | 849 | .name = name, |
| 850 | .sources = List(TestCase.SourceFile).init(self.b.allocator), | 850 | .sources = ArrayList(TestCase.SourceFile).init(self.b.allocator), |
| 851 | .expected_lines = List([]const u8).init(self.b.allocator), | 851 | .expected_lines = ArrayList([]const u8).init(self.b.allocator), |
| 852 | .allow_warnings = allow_warnings, | 852 | .allow_warnings = allow_warnings, |
| 853 | }; | 853 | }; |
| 854 | tc.addSourceFile("source.h", source); | 854 | tc.addSourceFile("source.h", source); |