Skip to content

Commit 6fbe163

Browse files
committed
Update zig build system to support user defined options
* Fix assertion failure when switching on type. Closes #310 * Update zig build system to support user defined options. See #204 * fmt.format supports {sNNN} to set padding for a buffer arg. * add std.fmt.bufPrint and std.fmt.allocPrint * std.hash_map.HashMap.put returns the previous value * add std.mem.startsWith
1 parent d15bcdc commit 6fbe163

File tree

10 files changed

+442
-69
lines changed

10 files changed

+442
-69
lines changed

src/ir.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ static TypeTableEntry *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *ins
5757
static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, TypeTableEntry *expected_type);
5858

5959
ConstExprValue *const_ptr_pointee(ConstExprValue *const_val) {
60+
assert(const_val->type->id == TypeTableEntryIdPointer);
6061
assert(const_val->special == ConstValSpecialStatic);
6162
switch (const_val->data.x_ptr.special) {
6263
case ConstPtrSpecialInvalid:
@@ -10350,10 +10351,21 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
1035010351
if (type_is_invalid(target_value_ptr->value.type))
1035110352
return ira->codegen->builtin_types.entry_invalid;
1035210353

10354+
if (target_value_ptr->value.type->id == TypeTableEntryIdMetaType) {
10355+
assert(instr_is_comptime(target_value_ptr));
10356+
TypeTableEntry *ptr_type = target_value_ptr->value.data.x_type;
10357+
assert(ptr_type->id == TypeTableEntryIdPointer);
10358+
ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base);
10359+
out_val->type = ira->codegen->builtin_types.entry_type;
10360+
out_val->data.x_type = ptr_type->data.pointer.child_type;
10361+
return out_val->type;
10362+
}
10363+
1035310364
assert(target_value_ptr->value.type->id == TypeTableEntryIdPointer);
10365+
1035410366
TypeTableEntry *target_type = target_value_ptr->value.type->data.pointer.child_type;
1035510367
ConstExprValue *pointee_val = nullptr;
10356-
if (target_value_ptr->value.special != ConstValSpecialRuntime) {
10368+
if (instr_is_comptime(target_value_ptr)) {
1035710369
pointee_val = const_ptr_pointee(&target_value_ptr->value);
1035810370
if (pointee_val->special == ConstValSpecialRuntime)
1035910371
pointee_val = nullptr;

src/main.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,8 @@ int main(int argc, char **argv) {
167167
ZigList<const char *> args = {0};
168168
args.append(zig_exe_path);
169169
for (int i = 2; i < argc; i += 1) {
170-
if (strcmp(argv[i], "--verbose") == 0) {
170+
if (strcmp(argv[i], "--debug-build-verbose") == 0) {
171171
verbose = true;
172-
args.append(argv[i]);
173172
} else {
174173
args.append(argv[i]);
175174
}

std/buf_map.zig

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@ pub const BufMap = struct {
1111

1212
pub fn init(allocator: &Allocator) -> BufMap {
1313
var self = BufMap {
14-
.hash_map = undefined,
14+
.hash_map = BufMapHashMap.init(allocator),
1515
};
16-
self.hash_map.init(allocator);
1716
return self;
1817
}
1918

2019
pub fn deinit(self: &BufMap) {
21-
var it = self.hash_map.entryIterator();
20+
var it = self.hash_map.iterator();
2221
while (true) {
2322
const entry = it.next() ?? break;
2423
self.free(entry.key);
@@ -54,7 +53,7 @@ pub const BufMap = struct {
5453
}
5554

5655
pub fn iterator(self: &const BufMap) -> BufMapHashMap.Iterator {
57-
return self.hash_map.entryIterator();
56+
return self.hash_map.iterator();
5857
}
5958

6059
fn free(self: &BufMap, value: []const u8) {

std/buf_set.zig

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@ pub const BufSet = struct {
99

1010
pub fn init(allocator: &Allocator) -> BufSet {
1111
var self = BufSet {
12-
.hash_map = undefined,
12+
.hash_map = BufSetHashMap.init(allocator),
1313
};
14-
self.hash_map.init(allocator);
1514
return self;
1615
}
1716

1817
pub fn deinit(self: &BufSet) {
19-
var it = self.hash_map.entryIterator();
18+
var it = self.hash_map.iterator();
2019
while (true) {
2120
const entry = it.next() ?? break;
2221
self.free(entry.key);
@@ -43,7 +42,7 @@ pub const BufSet = struct {
4342
}
4443

4544
pub fn iterator(self: &const BufSet) -> BufSetHashMap.Iterator {
46-
return self.hash_map.entryIterator();
45+
return self.hash_map.iterator();
4746
}
4847

4948
fn free(self: &BufSet, value: []const u8) {

0 commit comments

Comments
 (0)