From 7976b64cf624f37417b592c5c09a7656142002b4 Mon Sep 17 00:00:00 2001 From: Luna Date: Wed, 1 Apr 2020 16:09:39 -0300 Subject: [PATCH] tuple-inator pass --- src/analysis.zig | 20 ++++++++-------- src/codegen/llvm.zig | 54 ++++++++++++++++++++++---------------------- src/comp_ctx.zig | 14 ++++++------ src/errors.zig | 10 ++++---- src/main.zig | 8 +++---- src/parsers.zig | 12 +++++----- 6 files changed, 59 insertions(+), 59 deletions(-) diff --git a/src/analysis.zig b/src/analysis.zig index c3363a5..4f92c4a 100644 --- a/src/analysis.zig +++ b/src/analysis.zig @@ -45,18 +45,18 @@ pub const Analyzer = struct { fn doError(self: *@This(), comptime fmt: []const u8, args: ...) void { self.hadError = true; - std.debug.warn("analysis error"); + std.debug.warn("analysis error" , .{ }); if (self.err_tok) |tok| { - std.debug.warn(" at line {}", tok.line); + std.debug.warn(" at line {}" , .{ tok.line }); } if (self.err_ctx) |ctx| { - std.debug.warn(" on {}", ctx); + std.debug.warn(" on {}" , .{ ctx }); } - std.debug.warn("\n\t"); + std.debug.warn("\n\t" , .{ }); std.debug.warn(fmt, args); - std.debug.warn("\n"); + std.debug.warn("\n" , .{ }); } /// Resolve a type in global scope @@ -108,7 +108,7 @@ pub const Analyzer = struct { ) !void { var actual_enum = @as(comp.SymbolUnderlyingTypeEnum, symbol_type); if (actual_enum != wanted_type_enum) { - std.debug.warn("Expected {}, got {}\n", wanted_type_enum, actual_enum); + std.debug.warn("Expected {}, got {}\n" , .{ wanted_type_enum, actual_enum }); return CompileError.TypeError; } } @@ -122,7 +122,7 @@ pub const Analyzer = struct { .Integer32, .Integer64, .Double => {}, else => { var actual_enum = @as(comp.SymbolUnderlyingTypeEnum, symbol_type); - std.debug.warn("Expected numeric, got {}\n", actual_enum); + std.debug.warn("Expected numeric, got {}\n" , .{ actual_enum }); return CompileError.TypeError; }, } @@ -158,7 +158,7 @@ pub const Analyzer = struct { const expected_enum = @as(comp.SymbolUnderlyingTypeEnum, expected_type); if (symbol_enum != expected_enum) { - std.debug.warn("Expected {}, got {}\n", expected_enum, symbol_enum); + std.debug.warn("Expected {}, got {}\n" , .{ expected_enum, symbol_enum }); return CompileError.TypeError; } @@ -292,7 +292,7 @@ pub const Analyzer = struct { var target = get.target.*; const target_type = @as(ast.ExprType, target); if (target_type != .Variable) { - std.debug.warn("Expected Variable as get target, got {}\n", target_type); + std.debug.warn("Expected Variable as get target, got {}\n" , .{ target_type }); return CompileError.TypeError; } @@ -475,7 +475,7 @@ 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| { diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 6071da0..010dc1c 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -41,7 +41,7 @@ pub const Codegen = struct { .Bool => llvm.LLVMInt1Type(), .OpaqueType => |val| { - std.debug.warn("Invalid return type: {}\n", val); + std.debug.warn("Invalid return type: {}\n", .{val}); return CompileError.TypeError; }, @@ -51,14 +51,14 @@ pub const Codegen = struct { .Struct => unreachable, .Enum => llvm.LLVMInt32Type(), else => { - std.debug.warn("Function {} is not a type\n", lex); + std.debug.warn("Function {} is not a type\n", .{lex}); return CompileError.TypeError; }, }; }, else => { - std.debug.warn("TODO handle {}\n", typ); + std.debug.warn("TODO handle {}\n", .{typ}); return CompileError.TypeError; }, }; @@ -82,7 +82,7 @@ pub const Codegen = struct { .Struct => @panic("TODO handle struct"), else => { - std.debug.warn("Invalid get target: {}\n", @as(comp.SymbolType, sym.*)); + std.debug.warn("Invalid get target: {}\n", .{@as(comp.SymbolType, sym.*)}); return CompileError.EmitError; }, } @@ -144,7 +144,7 @@ pub const Codegen = struct { .Or => llvm.LLVMBuildOr(builder, left, right, "ortmp"), else => { - std.debug.warn("Unexpected binary operator: '{}'\n", binary.op); + std.debug.warn("Unexpected binary operator: '{}'\n", .{binary.op}); return CompileError.EmitError; }, }; @@ -168,7 +168,7 @@ pub const Codegen = struct { }, else => { - std.debug.warn("Invalid get target: {}\n", @as(ast.ExprType, target)); + std.debug.warn("Invalid get target: {}\n", .{@as(ast.ExprType, target)}); return CompileError.EmitError; }, } @@ -179,7 +179,7 @@ pub const Codegen = struct { var llvm_func = self.llvm_table.get(name); if (llvm_func == null) { - std.debug.warn("Function '{}' not found\n", name); + std.debug.warn("Function '{}' not found\n", .{name}); return CompileError.EmitError; } @@ -218,7 +218,7 @@ pub const Codegen = struct { var kv_opt = self.ctx.current_scope.?.meta_map.get(vari.lexeme); if (kv_opt == null) { - std.debug.warn("variable {} not fully analyzed\n", vari.lexeme); + std.debug.warn("variable {} not fully analyzed\n", .{vari.lexeme}); return CompileError.EmitError; } @@ -226,7 +226,7 @@ pub const Codegen = struct { // is coming from the scope or from the function var metadata = kv_opt.?.value; - std.debug.warn("!! LOAD FROM VAR META {}\n", @ptrToInt(metadata)); + std.debug.warn("!! LOAD FROM VAR META {}\n", .{@ptrToInt(metadata)}); var buf = try self.allocator.alloc(u8, 512); errdefer self.allocator.free(buf); @@ -255,14 +255,14 @@ pub const Codegen = struct { }, else => { - std.debug.warn("Got unexpected expr {}\n", @as(ast.ExprType, expr.*)); + std.debug.warn("Got unexpected expr {}\n", .{@as(ast.ExprType, expr.*)}); return CompileError.EmitError; }, }; } fn emitStmt(self: *Codegen, builder: var, stmt: *ast.Stmt) anyerror!void { - std.debug.warn("cgen: emitting stmt {}\n", @as(ast.StmtType, stmt.*)); + std.debug.warn("cgen: emitting stmt {}\n", .{@as(ast.StmtType, stmt.*)}); switch (stmt.*) { .Expr => |expr| _ = try self.emitExpr(builder, expr), @@ -379,14 +379,14 @@ pub const Codegen = struct { var_metadata.*.llvm_alloca = variable; - std.debug.warn("!! DECL VAR {} => {}\n", @ptrToInt(var_metadata), variable); + std.debug.warn("!! DECL VAR {} => {}\n", .{ @ptrToInt(var_metadata), variable }); var llvm_expr = try self.emitExpr(builder, vardecl.value); _ = llvm.LLVMBuildStore(builder, llvm_expr, variable); }, else => { - std.debug.warn("Got unexpected stmt {}\n", stmt.*); + std.debug.warn("Got unexpected stmt {}\n", .{stmt.*}); return CompileError.EmitError; }, } @@ -409,7 +409,7 @@ pub const Codegen = struct { .FnDecl => |decl| { const name = decl.func_name.lexeme; self.current_function_name = name; - std.debug.warn("cgen: genning function '{}'\n", name); + std.debug.warn("cgen: genning function '{}'\n", .{name}); var fn_sym = self.getFnSymbol(name); @@ -454,7 +454,7 @@ pub const Codegen = struct { var alloca = llvm.LLVMBuildAlloca(builder, try self.typeToLLVM(param.typ), param_name_cstr.ptr); - std.debug.warn("SET PARAM LLVM ALLOCA {} to {}\n", param_node.name.lexeme, alloca); + std.debug.warn("SET PARAM LLVM ALLOCA {} to {}\n", .{ param_node.name.lexeme, alloca }); param.llvm_alloca = alloca; _ = llvm.LLVMBuildStore( @@ -474,7 +474,7 @@ pub const Codegen = struct { } self.ctx.dumpScope(); - std.debug.warn("cgen: generated function '{}'\n", name); + std.debug.warn("cgen: generated function '{}'\n", .{name}); }, // NOTE: enums don't have specific llvm ir code generated for them @@ -503,14 +503,14 @@ pub const Codegen = struct { }, else => { - std.debug.warn("TODO handle node type {}\n", @tagName(node.*)); + std.debug.warn("TODO handle node type {}\n", .{@tagName(node.*)}); return; }, } } pub fn gen(self: *Codegen, root: *ast.Node) !void { - std.debug.warn("cgen: start gen\n"); + std.debug.warn("cgen: start gen\n", .{}); _ = llvm.LLVMInitializeNativeTarget(); var mod = llvm.LLVMModuleCreateWithName("awoo").?; @@ -525,16 +525,16 @@ pub const Codegen = struct { defer llvm.LLVMDisposeMessage(err); if (llvm.LLVMPrintModuleToFile(mod, "output.ll", &err) != 0) { - std.debug.warn("error printing module to file: {}\n", sliceify(err)); + std.debug.warn("error printing module to file: {}\n", .{sliceify(err)}); return CompileError.BackendError; } //if (llvm.LLVMWriteBitcodeToFile(mod, "awoo.bc") != 0) { - // std.debug.warn("error writing bitcode to file: {}\n", sliceify(err)); + // std.debug.warn("error writing bitcode to file: {}\n" , .{ sliceify(err) }); // return CompileError.BackendError; //} - std.debug.warn("cgen: verify llvm module\n"); + std.debug.warn("cgen: verify llvm module\n", .{}); _ = llvm.LLVMVerifyModule( mod, llvm.LLVMVerifierFailureAction.LLVMAbortProcessAction, @@ -549,7 +549,7 @@ pub const Codegen = struct { var engine: llvm.LLVMExecutionEngineRef = undefined; if (llvm.LLVMCreateExecutionEngineForModule(&engine, mod, &err) != 0) { - std.debug.warn("failed to create execution engine: {}\n", sliceify(err)); + std.debug.warn("failed to create execution engine: {}\n", .{sliceify(err)}); return CompileError.BackendError; } @@ -569,9 +569,9 @@ pub const Codegen = struct { var features = llvm.LLVMGetTargetMachineFeatureString(machine); var triple = llvm.LLVMGetTargetMachineTriple(machine); - std.debug.warn("target: {}\n", sliceify(desc)); - std.debug.warn("triple: {}\n", sliceify(triple)); - std.debug.warn("features: {}\n", sliceify(features)); + std.debug.warn("target: {}\n", .{sliceify(desc)}); + std.debug.warn("triple: {}\n", .{sliceify(triple)}); + std.debug.warn("features: {}\n", .{sliceify(features)}); //if (llvm.LLVMTargetMachineEmitToFile( // machine, @@ -580,7 +580,7 @@ pub const Codegen = struct { // llvm.LLVMCodeGenFileType.LLVMAssemblyFile, // &err, //) != 0) { - // std.debug.warn("failed to emit to assembly file: {}\n", sliceify(err)); + // std.debug.warn("failed to emit to assembly file: {}\n" , .{ sliceify(err) }); // return CompileError.BackendError; //} @@ -591,7 +591,7 @@ pub const Codegen = struct { llvm.LLVMCodeGenFileType.LLVMObjectFile, &err, ) != 0) { - std.debug.warn("failed to emit to file: {}\n", sliceify(err)); + std.debug.warn("failed to emit to file: {}\n", .{sliceify(err)}); return CompileError.BackendError; } } diff --git a/src/comp_ctx.zig b/src/comp_ctx.zig index fdbcaeb..751ef6c 100644 --- a/src/comp_ctx.zig +++ b/src/comp_ctx.zig @@ -158,7 +158,7 @@ pub const VariableMetadata = struct { typ: SymbolUnderlyingType, ) !*VariableMetadata { var meta = try allocator.create(VariableMetadata); - std.debug.warn("VARMETA create from scope={}, meta={}\n", @ptrToInt(scope), @ptrToInt(meta)); + std.debug.warn("VARMETA create from scope={}, meta={}\n" , .{ @ptrToInt(scope), @ptrToInt(meta) }); meta.* = VariableMetadata{ .typ = typ, .from_scope = scope, .using = .Scope }; return meta; } @@ -169,7 +169,7 @@ pub const VariableMetadata = struct { typ: SymbolUnderlyingType, ) !*VariableMetadata { var meta = try allocator.create(VariableMetadata); - std.debug.warn("VARMETA create from fndecl={}, meta={}\n", @ptrToInt(func), @ptrToInt(meta)); + std.debug.warn("VARMETA create from fndecl={}, meta={}\n" , .{ @ptrToInt(func), @ptrToInt(meta) }); meta.* = VariableMetadata{ .typ = typ, .from_function = func, .using = .Function }; return meta; } @@ -204,7 +204,7 @@ pub const CompilationContext = struct { @panic("can't bump scope from null"); } - std.debug.warn("==scope bump== '{}'\n", scope_id); + std.debug.warn("==scope bump== '{}'\n" , .{ scope_id }); var child = try self.current_scope.?.createChild(scope_id); self.current_scope = child; @@ -212,7 +212,7 @@ pub const CompilationContext = struct { /// Set a given scope as the current scope. pub fn setScope(self: *@This(), scope: *Scope) void { - std.debug.warn("==set== set scope to {}\n", scope.id); + std.debug.warn("==set== set scope to {}\n" , .{ scope.id }); self.current_scope = scope; } @@ -349,7 +349,7 @@ pub const CompilationContext = struct { ) !*SymbolData { var sym_kv = self.symbol_table.get(identifier); if (sym_kv == null) { - std.debug.warn("Unknown {} '{}'\n", typ, identifier); + std.debug.warn("Unknown {} '{}'\n" , .{ typ, identifier }); return CompilationError.TypeError; } @@ -357,7 +357,7 @@ pub const CompilationContext = struct { var sym_typ = @as(SymbolType, value.*); if (sym_typ != typ) { - std.debug.warn("Expected {}, got {}\n", sym_typ, typ); + std.debug.warn("Expected {}, got {}\n" , .{ sym_typ, typ }); return CompilationError.TypeError; } @@ -417,7 +417,7 @@ pub const CompilationContext = struct { } } - std.debug.warn("Unknown name {}\n", name); + std.debug.warn("Unknown name {}\n" , .{ name }); return CompilationError.UnknownName; } diff --git a/src/errors.zig b/src/errors.zig index 9043f2e..39528b6 100644 --- a/src/errors.zig +++ b/src/errors.zig @@ -2,9 +2,9 @@ const std = @import("std"); pub fn report(line: usize, where: []const u8, ctx_opt: ?[]const u8, message: []const u8) void { if (ctx_opt) |ctx| { - std.debug.warn("[line {}] Error{} on {}: {}", line, where, ctx, message); + std.debug.warn("[line {}] Error{} on {}: {}" , .{ line, where, ctx, message }); } else { - std.debug.warn("[line {}] Error{}: {}", line, where, message); + std.debug.warn("[line {}] Error{}: {}" , .{ line, where, message }); } } @@ -14,11 +14,11 @@ pub fn reportN(line: usize, message: []const u8) void { pub fn reportFmt(line: usize, ctx_opt: ?[]const u8, comptime fmt: []const u8, args: ...) void { if (ctx_opt) |ctx| { - std.debug.warn("[line {}] Error on {}", line, ctx); + std.debug.warn("[line {}] Error on {}" , .{ line, ctx }); } else { - std.debug.warn("[line {}] Error", line); + std.debug.warn("[line {}] Error" , .{ line }); } std.debug.warn(fmt, args); - std.debug.warn("\n"); + std.debug.warn("\n" , .{ }); } diff --git a/src/main.zig b/src/main.zig index 5e91ab8..3c99ce7 100644 --- a/src/main.zig +++ b/src/main.zig @@ -32,7 +32,7 @@ pub fn run(allocator: *std.mem.Allocator, slice: []const u8) !Result { if (tok.typ == .EOF) break; // TODO remove - std.debug.warn("{x}\n", tok); + std.debug.warn("{x}\n" , .{ tok }); } } @@ -47,13 +47,13 @@ pub fn run(allocator: *std.mem.Allocator, slice: []const u8) !Result { var root = root_opt.?; - std.debug.warn("parse tree\n"); + std.debug.warn("parse tree\n" , .{ }); printer.printNode(root, 0); var solver = try analysis.Analyzer.init(allocator); var ctx = try solver.pass(root); - std.debug.warn("symbol table\n"); + std.debug.warn("symbol table\n" , .{ }); printer.printContext(ctx); var cgen = codegen.llvm.Codegen.init(allocator, &ctx); @@ -94,7 +94,7 @@ pub fn main() anyerror!void { .ParseError, .CompileError, => { - std.debug.warn("error: {}\n", result); + std.debug.warn("error: {}\n" , .{ result }); std.os.exit(1); }, } diff --git a/src/parsers.zig b/src/parsers.zig index dbf3722..68cf653 100644 --- a/src/parsers.zig +++ b/src/parsers.zig @@ -107,15 +107,15 @@ pub const Parser = struct { fn doError(self: *Parser, comptime fmt: []const u8, args: ...) ParseError { self.hadError = true; - std.debug.warn("parser error at line {}", self.scanner.line); + std.debug.warn("parser error at line {}" , .{ self.scanner.line }); if (self.err_ctx) |ctx| { - std.debug.warn(" on {}", ctx); + std.debug.warn(" on {}" , .{ ctx }); } - std.debug.warn("\n\t"); + std.debug.warn("\n\t" , .{ }); std.debug.warn(fmt, args); - std.debug.warn("\n"); + std.debug.warn("\n" , .{ }); return ParseError.CompileError; } @@ -146,7 +146,7 @@ pub const Parser = struct { } fn tokenError(self: *Parser, token: Token, msg: []const u8) ParseError { - std.debug.warn("ctx: '{}'\n", self.err_ctx); + std.debug.warn("ctx: '{}'\n" , .{ self.err_ctx }); if (token.typ == .EOF) { ereport.report(token.line, " at end", self.err_ctx, msg); } else { @@ -177,7 +177,7 @@ pub const Parser = struct { } try self.tokens.append(token); - std.debug.warn("skip to {}\n", token); + std.debug.warn("skip to {}\n" , .{ token }); return token; }