Skip to content

Commit

Permalink
ZCPU Warnings now display in the editor too (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
DerelictDrone authored Nov 15, 2023
1 parent 0a29c04 commit 9a16f24
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
23 changes: 21 additions & 2 deletions lua/wire/client/hlzasm/hc_compiler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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 = {}
Expand All @@ -256,6 +274,7 @@ function HCOMP:StartCompile(sourceCode,fileName,writeByteCallback,writeByteCalle

-- Output text
self.OutputText = {}
return self.Warnings
end


Expand Down
10 changes: 8 additions & 2 deletions lua/wire/client/hlzasm/hc_preprocess.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions lua/wire/client/hlzasm/hc_tokenizer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
10 changes: 7 additions & 3 deletions lua/wire/cpulib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 ==")

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9a16f24

Please sign in to comment.