From 9a16f240a74e6e49a32b3cc281d1c4142a63c03f Mon Sep 17 00:00:00 2001 From: DerelictDrone <57756830+DerelictDrone@users.noreply.github.com> Date: Wed, 15 Nov 2023 14:31:52 -0600 Subject: [PATCH] ZCPU Warnings now display in the editor too (#16) --- lua/wire/client/hlzasm/hc_compiler.lua | 23 +++++++++++++++++++++-- lua/wire/client/hlzasm/hc_preprocess.lua | 10 ++++++++-- lua/wire/client/hlzasm/hc_tokenizer.lua | 7 ++++--- lua/wire/cpulib.lua | 10 +++++++--- 4 files changed, 40 insertions(+), 10 deletions(-) diff --git a/lua/wire/client/hlzasm/hc_compiler.lua b/lua/wire/client/hlzasm/hc_compiler.lua index 47ead1e..664de4c 100644 --- a/lua/wire/client/hlzasm/hc_compiler.lua +++ b/lua/wire/client/hlzasm/hc_compiler.lua @@ -93,7 +93,23 @@ end -- -- Same rules for calling as for Error() function HCOMP:Warning(msg,param1,param2,param3) - print(self:formatPrefix(param1,param2,param3)..": Warning: "..msg) + local prefixstr,file,line,col = self:formatPrefix(param1,param2,param3) + local parent = self:CurrentSourcePosition().ParentFile + print(prefixstr..": Warning: "..msg) -- This is the original console print, we should only mute the editor warnings + if self.SilencedFiles[file] then + if self.SilencedFiles[file].Silenced or self.SilencedParents[parent] then + return + end + elseif self.SilencedParents[parent] then + return + end + local warning = {} + warning.trace = {start_line = line, start_col = col} + warning.message = msg + if file ~= self.FileName then -- self.FileName is the file that's open in the editor at the start of compile + warning.message = "(in file: '"..file.."') " .. warning.message + end + self.Warnings[#self.Warnings+1] = warning end @@ -237,7 +253,9 @@ function HCOMP:StartCompile(sourceCode,fileName,writeByteCallback,writeByteCalle self.DebugInfo.Labels = {} self.DebugInfo.PositionByPointer = {} self.DebugInfo.PointersByLine = {} - + self.Warnings = {} -- Warnings to pass to the editor + self.SilencedFiles = {} -- Will not push warnings from silenced files + self.SilencedParents = {} -- Includes from these files will get silenced -- Exported function list (library generation) self.ExportedSymbols = {} self.LabelLookup = {} @@ -256,6 +274,7 @@ function HCOMP:StartCompile(sourceCode,fileName,writeByteCallback,writeByteCalle -- Output text self.OutputText = {} + return self.Warnings end diff --git a/lua/wire/client/hlzasm/hc_preprocess.lua b/lua/wire/client/hlzasm/hc_preprocess.lua index 131e1f9..78edbfd 100644 --- a/lua/wire/client/hlzasm/hc_preprocess.lua +++ b/lua/wire/client/hlzasm/hc_preprocess.lua @@ -98,7 +98,7 @@ function HCOMP:ParsePreprocessMacro(lineText,macroPosition) local crtFilename = "lib\\"..string.lower(pragmaCommand).."\\init.txt" local fileText = self:LoadFile(crtFilename) if fileText then - table.insert(self.Code, 1, { Text = fileText, Line = 1, Col = 1, File = crtFilename, NextCharPos = 1 }) + table.insert(self.Code, 1, { Text = fileText, Line = 1, Col = 1, File = crtFilename, ParentFile = macroPosition.File, NextCharPos = 1 }) else self:Error("Unable to include CRT library "..pragmaCommand, macroPosition.Line,macroPosition.Col,macroPosition.File) @@ -110,6 +110,12 @@ function HCOMP:ParsePreprocessMacro(lineText,macroPosition) CPULib.CPUName = pragmaCommand elseif pragmaName == "searchpath" then table.insert(self.SearchPaths,pragmaCommand) + elseif pragmaName == "silence" or pragmaName == "mute" then + if pragmaCommand == "self" then + self.SilencedFiles[macroPosition.File] = { Silenced = true, FromParent = false } + elseif pragmaCommand == "includes" or pragmaCommand == "other" then + self.SilencedParents[macroPosition.File] = true + end elseif pragmaName == "allow" or pragmaName == "zap" then if not self.Settings.AutoBusyRegisters then self.Settings.AutoBusyRegisters = true @@ -250,7 +256,7 @@ function HCOMP:ParsePreprocessMacro(lineText,macroPosition) -- Push this file on top of the stack if fileText then - table.insert(self.Code, 1, { Text = fileText, Line = 1, Col = 1, File = fileName, NextCharPos = 1 }) + table.insert(self.Code, 1, { Text = fileText, Line = 1, Col = 1, File = fileName, ParentFile = macroPosition.File, NextCharPos = 1 }) else self:Error("Cannot open file: "..fileName, macroPosition.Line,macroPosition.Col,macroPosition.File) diff --git a/lua/wire/client/hlzasm/hc_tokenizer.lua b/lua/wire/client/hlzasm/hc_tokenizer.lua index 8103fcc..8c984b8 100644 --- a/lua/wire/client/hlzasm/hc_tokenizer.lua +++ b/lua/wire/client/hlzasm/hc_tokenizer.lua @@ -231,7 +231,8 @@ function HCOMP:Tokenize() local TOKEN = self.TOKEN -- Read token position local tokenPosition = { Line = self.Code[1].Line, Col = self.Code[1].Col, - File = self.Code[1].File } + File = self.Code[1].File, + ParentFile = self.Code[1].ParentFile } -- Check for end of file if self:getChar() == "" then @@ -582,7 +583,7 @@ function HCOMP:CurrentSourcePosition() return self.Tokens[self.CurrentToken-1].Position end elseif self.FileName then - return { Line = 1, Col = 1, File = self.FileName} + return { Line = 1, Col = 1, File = self.FileName, ParentFile = 'HL-ZASM'} end - return { Line = 1, Col = 1, File = "HL-ZASM"} + return { Line = 1, Col = 1, File = "HL-ZASM", ParentFile = "HL-ZASM"} end diff --git a/lua/wire/cpulib.lua b/lua/wire/cpulib.lua index 2e8690d..8879e10 100644 --- a/lua/wire/cpulib.lua +++ b/lua/wire/cpulib.lua @@ -65,9 +65,9 @@ if CLIENT then CPULib.Debugger.PositionByPointer = {} CPULib.Debugger.PointersByLine = {} CPULib.CPUName = nil + CPULib.Warnings = HCOMP:StartCompile(source,fileName or "source",CPULib.OnWriteByte,nil) -- Start compiling the sourcecode - HCOMP:StartCompile(source,fileName or "source",CPULib.OnWriteByte,nil) HCOMP.Settings.CurrentPlatform = targetPlatform or "CPU" print("=== HL-ZASM High Level Assembly Compiler Output ==") @@ -112,8 +112,12 @@ if CLIENT then -- Request validating the code function CPULib.Validate(editor,source,fileName) CPULib.Compile(source,fileName, - function() + function(warnings) + if #warnings > 0 then + editor.C.Val:Update(nil,warnings," "..#warnings.." Warnings, with "..(HCOMP.WritePointer or "?").." bytes compiled.", Color(163, 130, 64, 255)) + else editor.C.Val:Update(nil, nil, " Success, "..(HCOMP.WritePointer or "?").." bytes compiled.", Color(50, 128, 20)) + end end, function(error,errorPos) local issue = (error or "unknown error") @@ -163,7 +167,7 @@ if CLIENT then CPULib.Debugger.PositionByPointer = HCOMP.DebugInfo.PositionByPointer CPULib.Debugger.PointersByLine = HCOMP.DebugInfo.PointersByLine - CPULib.SuccessCallback() + CPULib.SuccessCallback(CPULib.Warnings) end timer.Remove("cpulib_compile") CPULib.Compiling = false