From b900c706ef6fdf61a4e10d1a1cf227f09fa83bf4 Mon Sep 17 00:00:00 2001 From: nub31 Date: Fri, 12 Sep 2025 23:29:55 +0200 Subject: [PATCH] better comments in generated code --- .../NubLang/Generation/QBE/QBEGenerator.cs | 11 +++++---- example/src/main.nub | 23 +++++++++++++------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/compiler/NubLang/Generation/QBE/QBEGenerator.cs b/compiler/NubLang/Generation/QBE/QBEGenerator.cs index 9d7ce07..0ea759f 100644 --- a/compiler/NubLang/Generation/QBE/QBEGenerator.cs +++ b/compiler/NubLang/Generation/QBE/QBEGenerator.cs @@ -95,6 +95,7 @@ public class QBEGenerator %size =l loadl %array ret %size } + """); _writer.Comment("========== Referenced structs =========="); @@ -113,7 +114,6 @@ public class QBEGenerator EmitStructDefinition(structDef); } - _writer.NewLine(); _writer.Comment("========== Function definitions =========="); foreach (var funcDef in _definitions.OfType()) @@ -121,7 +121,6 @@ public class QBEGenerator EmitFuncDefinition(funcDef); } - _writer.NewLine(); _writer.Comment("========== cstring literals =========="); foreach (var cStringLiteral in _cStringLiterals) @@ -393,7 +392,7 @@ public class QBEGenerator private void EmitStructDefinition(StructNode structDef) { - _writer.Comment($" ===== {structDef.Module}::{structDef.Name} ====="); + _writer.Comment($"{structDef.Module}::{structDef.Name}"); _writer.WriteLine($"export function {StructCtorName(structDef.Module, structDef.Name)}(l %struct) {{"); _writer.WriteLine("@start"); @@ -410,14 +409,14 @@ public class QBEGenerator _writer.Indented("ret"); _writer.WriteLine("}"); + _writer.NewLine(); foreach (var function in structDef.Functions) { - _writer.Comment($" ===== {structDef.Module}::{structDef.Name}.{function.Name} ====="); + _writer.Comment($"{structDef.Module}::{structDef.Name}.{function.Name}"); _labelIndex = 0; _tmpIndex = 0; - _writer.NewLine(); _writer.Write("export function "); if (function.Signature.ReturnType is not VoidTypeNode) @@ -445,6 +444,7 @@ public class QBEGenerator } _writer.WriteLine("}"); + _writer.NewLine(); } } @@ -482,6 +482,7 @@ public class QBEGenerator } _writer.WriteLine("}"); + _writer.NewLine(); } private void EmitBlock(BlockNode block) diff --git a/example/src/main.nub b/example/src/main.nub index d57a018..32b1724 100644 --- a/example/src/main.nub +++ b/example/src/main.nub @@ -1,18 +1,27 @@ module "main" -export extern "puts" func puts(text: cstring) +extern "puts" func puts(text: cstring) -export struct Human +struct Name { - name: cstring + first: cstring + last: cstring +} + +struct Human +{ + name: Name } extern "main" func main(args: []cstring): i64 { - let x: cstring = "test" + let x: Human = { + name = { + first = "oliver" + last = "stene" + } + } - x = x + "uwu" - - puts(x) + puts(x.name.last) return 0 }