Skip to content

Commit

Permalink
Update zig build system to support user defined options
Browse files Browse the repository at this point in the history
 * 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
  • Loading branch information
andrewrk committed Apr 6, 2017
1 parent d15bcdc commit 6fbe163
Show file tree
Hide file tree
Showing 10 changed files with 442 additions and 69 deletions.
14 changes: 13 additions & 1 deletion src/ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ static TypeTableEntry *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *ins
static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, TypeTableEntry *expected_type);

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

if (target_value_ptr->value.type->id == TypeTableEntryIdMetaType) {
assert(instr_is_comptime(target_value_ptr));
TypeTableEntry *ptr_type = target_value_ptr->value.data.x_type;
assert(ptr_type->id == TypeTableEntryIdPointer);
ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base);
out_val->type = ira->codegen->builtin_types.entry_type;
out_val->data.x_type = ptr_type->data.pointer.child_type;
return out_val->type;
}

assert(target_value_ptr->value.type->id == TypeTableEntryIdPointer);

TypeTableEntry *target_type = target_value_ptr->value.type->data.pointer.child_type;
ConstExprValue *pointee_val = nullptr;
if (target_value_ptr->value.special != ConstValSpecialRuntime) {
if (instr_is_comptime(target_value_ptr)) {
pointee_val = const_ptr_pointee(&target_value_ptr->value);
if (pointee_val->special == ConstValSpecialRuntime)
pointee_val = nullptr;
Expand Down
3 changes: 1 addition & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,8 @@ int main(int argc, char **argv) {
ZigList<const char *> args = {0};
args.append(zig_exe_path);
for (int i = 2; i < argc; i += 1) {
if (strcmp(argv[i], "--verbose") == 0) {
if (strcmp(argv[i], "--debug-build-verbose") == 0) {
verbose = true;
args.append(argv[i]);
} else {
args.append(argv[i]);
}
Expand Down
7 changes: 3 additions & 4 deletions std/buf_map.zig
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ pub const BufMap = struct {

pub fn init(allocator: &Allocator) -> BufMap {
var self = BufMap {
.hash_map = undefined,
.hash_map = BufMapHashMap.init(allocator),
};
self.hash_map.init(allocator);
return self;
}

pub fn deinit(self: &BufMap) {
var it = self.hash_map.entryIterator();
var it = self.hash_map.iterator();
while (true) {
const entry = it.next() ?? break;
self.free(entry.key);
Expand Down Expand Up @@ -54,7 +53,7 @@ pub const BufMap = struct {
}

pub fn iterator(self: &const BufMap) -> BufMapHashMap.Iterator {
return self.hash_map.entryIterator();
return self.hash_map.iterator();
}

fn free(self: &BufMap, value: []const u8) {
Expand Down
7 changes: 3 additions & 4 deletions std/buf_set.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ pub const BufSet = struct {

pub fn init(allocator: &Allocator) -> BufSet {
var self = BufSet {
.hash_map = undefined,
.hash_map = BufSetHashMap.init(allocator),
};
self.hash_map.init(allocator);
return self;
}

pub fn deinit(self: &BufSet) {
var it = self.hash_map.entryIterator();
var it = self.hash_map.iterator();
while (true) {
const entry = it.next() ?? break;
self.free(entry.key);
Expand All @@ -43,7 +42,7 @@ pub const BufSet = struct {
}

pub fn iterator(self: &const BufSet) -> BufSetHashMap.Iterator {
return self.hash_map.entryIterator();
return self.hash_map.iterator();
}

fn free(self: &BufSet, value: []const u8) {
Expand Down
Loading

0 comments on commit 6fbe163

Please sign in to comment.