more fixes for latest zig
This commit is contained in:
parent
049a388660
commit
74e6beda67
3 changed files with 27 additions and 35 deletions
|
@ -42,7 +42,7 @@ pub const Analyzer = struct {
|
|||
self.err_tok = tok;
|
||||
}
|
||||
|
||||
fn doError(self: *@This(), comptime fmt: []const u8, args: ...) void {
|
||||
fn doError(self: *@This(), comptime fmt: []const u8, args: var) void {
|
||||
self.hadError = true;
|
||||
|
||||
std.debug.warn("analysis error", .{});
|
||||
|
@ -85,11 +85,10 @@ pub const Analyzer = struct {
|
|||
.Enum => SymbolUnderlyingType{ .Enum = val },
|
||||
|
||||
else => blk: {
|
||||
self.doError(
|
||||
"expected struct or enum for '{}', got {}",
|
||||
self.doError("expected struct or enum for '{}', got {}", .{
|
||||
val,
|
||||
@tagName(@as(comp.SymbolType, sym.?.value.*)),
|
||||
);
|
||||
});
|
||||
break :blk null;
|
||||
},
|
||||
};
|
||||
|
@ -136,12 +135,11 @@ pub const Analyzer = struct {
|
|||
expected_ident: []const u8,
|
||||
) !void {
|
||||
if (!std.mem.eql(u8, sym_ident, expected_ident)) {
|
||||
self.doError(
|
||||
"Expected {} {}, got {}",
|
||||
self.doError("Expected {} {}, got {}", .{
|
||||
@tagName(typ_enum),
|
||||
expected_ident,
|
||||
sym_ident,
|
||||
);
|
||||
});
|
||||
|
||||
return CompileError.TypeError;
|
||||
}
|
||||
|
@ -267,12 +265,11 @@ pub const Analyzer = struct {
|
|||
const param_type_val = @as(comp.SymbolUnderlyingTypeEnum, param_type);
|
||||
const arg_type_val = @as(comp.SymbolUnderlyingTypeEnum, arg_type);
|
||||
|
||||
self.doError(
|
||||
"Expected parameter {} to be {}, got {}",
|
||||
self.doError("Expected parameter {} to be {}, got {}", .{
|
||||
idx,
|
||||
@tagName(param_type_val),
|
||||
@tagName(arg_type_val),
|
||||
);
|
||||
});
|
||||
|
||||
return CompileError.TypeError;
|
||||
};
|
||||
|
@ -322,11 +319,10 @@ pub const Analyzer = struct {
|
|||
|
||||
var kv = map.get(name);
|
||||
if (kv == null) {
|
||||
self.doError(
|
||||
"Field {} not found in enum {}",
|
||||
self.doError("Field {} not found in enum {}", .{
|
||||
name,
|
||||
lexeme,
|
||||
);
|
||||
});
|
||||
return CompileError.TypeError;
|
||||
}
|
||||
|
||||
|
@ -334,10 +330,9 @@ pub const Analyzer = struct {
|
|||
},
|
||||
|
||||
else => {
|
||||
self.doError(
|
||||
"Expected Struct/Enum as get target, got {}",
|
||||
self.doError("Expected Struct/Enum as get target, got {}", .{
|
||||
@as(comp.SymbolUnderlyingTypeEnum, global_typ),
|
||||
);
|
||||
});
|
||||
|
||||
return CompileError.TypeError;
|
||||
},
|
||||
|
@ -475,7 +470,10 @@ pub const Analyzer = struct {
|
|||
self.setErrContext("function {}", .{name});
|
||||
var ret_type = self.resolveGlobalType(ctx, decl.return_type.lexeme);
|
||||
|
||||
std.debug.warn("start analysis of fn {}, ret type: {}\n", .{ decl.func_name.lexeme, ret_type });
|
||||
std.debug.warn("start analysis of fn {}, ret type: {}\n", .{
|
||||
decl.func_name.lexeme,
|
||||
ret_type,
|
||||
});
|
||||
|
||||
var parameters = comp.TypeList.init(self.allocator);
|
||||
for (decl.params.toSlice()) |param| {
|
||||
|
|
|
@ -66,11 +66,9 @@ pub fn printNode(node: *const Node, ident: usize) void {
|
|||
print(ident, "(const (\n", .{});
|
||||
|
||||
for (consts.toSlice()) |const_decl| {
|
||||
print(
|
||||
ident + 1,
|
||||
"({} ",
|
||||
print(ident + 1, "({} ", .{
|
||||
const_decl.name.lexeme,
|
||||
);
|
||||
});
|
||||
|
||||
printExpr(const_decl.expr);
|
||||
std.debug.warn(")\n", .{});
|
||||
|
@ -83,11 +81,9 @@ pub fn printNode(node: *const Node, ident: usize) void {
|
|||
print(ident, "(enum {} (\n", .{decl.name.lexeme});
|
||||
|
||||
for (decl.fields.toSlice()) |field| {
|
||||
print(
|
||||
ident + 1,
|
||||
"{}\n",
|
||||
print(ident + 1, "{}\n", .{
|
||||
field.lexeme,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
print(ident, "))\n", .{});
|
||||
|
@ -249,7 +245,7 @@ pub fn printExpr(expr: *const Expr) void {
|
|||
.Get => |get| {
|
||||
warn("(", .{});
|
||||
printExpr(get.target);
|
||||
warn(".{})", get.name.lexeme);
|
||||
warn(".{})", .{get.name.lexeme});
|
||||
},
|
||||
|
||||
.Set => |set| {
|
||||
|
@ -329,7 +325,7 @@ pub fn printStmt(ident: usize, stmt: *const Stmt) void {
|
|||
|
||||
// very bad but be like that
|
||||
fn retWithName(prefix: []const u8, inner: []const u8) []const u8 {
|
||||
var ret_nam_buf = std.heap.direct_allocator.alloc(u8, 256) catch unreachable;
|
||||
var ret_nam_buf = std.heap.page_allocator.alloc(u8, 256) catch unreachable;
|
||||
return std.fmt.bufPrint(ret_nam_buf[0..], "{}({})", .{ prefix, inner }) catch unreachable;
|
||||
}
|
||||
|
||||
|
@ -387,19 +383,17 @@ pub fn printContext(ctx: CompilationContext) void {
|
|||
std.debug.warn("struct '{}'\n", .{kv.key});
|
||||
var map_it = typemap.iterator();
|
||||
while (map_it.next()) |map_kv| {
|
||||
std.debug.warn(
|
||||
"\tfield {} type {}\n",
|
||||
std.debug.warn("\tfield {} type {}\n", .{
|
||||
map_kv.key,
|
||||
prettyType(map_kv.value),
|
||||
);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
.Variable => std.debug.warn(
|
||||
"variable {} type {}\n",
|
||||
.Variable => std.debug.warn("variable {} type {}\n", .{
|
||||
kv.key,
|
||||
kv.value,
|
||||
),
|
||||
}),
|
||||
|
||||
.Enum => |identmap| {
|
||||
std.debug.warn("enum {}:", .{kv.key});
|
||||
|
|
|
@ -230,7 +230,7 @@ pub const Codegen = struct {
|
|||
var buf = try self.allocator.alloc(u8, 512);
|
||||
errdefer self.allocator.free(buf);
|
||||
|
||||
var load_str = try std.fmt.bufPrint(buf, "{}_loaded", vari.lexeme);
|
||||
var load_str = try std.fmt.bufPrint(buf, "{}_loaded", .{vari.lexeme});
|
||||
|
||||
var load_cstr = try std.cstr.addNullByte(self.allocator, load_str);
|
||||
errdefer self.allocator.free(load_cstr);
|
||||
|
@ -435,7 +435,7 @@ pub const Codegen = struct {
|
|||
_ = try self.llvm_table.put(name, func);
|
||||
|
||||
var buf = try self.allocator.alloc(u8, 512);
|
||||
var entry_lbl = try std.fmt.bufPrint(buf, "fn_{}_entry", name);
|
||||
var entry_lbl = try std.fmt.bufPrint(buf, "fn_{}_entry", .{name});
|
||||
var entry_lbl_cstr = try std.cstr.addNullByte(self.allocator, entry_lbl);
|
||||
var entry = llvm.LLVMAppendBasicBlock(func, entry_lbl_cstr.ptr);
|
||||
|
||||
|
|
Loading…
Reference in a new issue