Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZCPU Compile-time warnings can now be displayed in the editor + pragma for muting them #16

Merged
merged 3 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 All @@ -76,7 +76,7 @@
CPULib.ErrorCallback = errorCallback

-- Run the timer
timer.Create("cpulib_compile",1/60,0,CPULib.OnCompileTimer)

Check warning on line 79 in lua/wire/cpulib.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator
CPULib.Compiling = true
end

Expand All @@ -85,14 +85,14 @@
function CPULib.SelectTab(editor,fileName)
if not editor then return end
local editorType = string.lower(editor.EditorType)
local fullFileName = editorType.."chip\\"..fileName

Check warning on line 88 in lua/wire/cpulib.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator

Check warning on line 88 in lua/wire/cpulib.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator

if string.sub(fileName,1,7) == editorType.."chip" then

Check warning on line 90 in lua/wire/cpulib.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator
fullFileName = fileName
end

local sourceTab
for tab=1,editor:GetNumTabs() do

Check warning on line 95 in lua/wire/cpulib.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator
if editor:GetEditor(tab).chosenfile == fullFileName then
sourceTab = tab
end
Expand All @@ -112,8 +112,12 @@
-- 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))

Check warning on line 117 in lua/wire/cpulib.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator

Check warning on line 117 in lua/wire/cpulib.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator

Check warning on line 117 in lua/wire/cpulib.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator

Check warning on line 117 in lua/wire/cpulib.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace after ')'
else
editor.C.Val:Update(nil, nil, " Success, "..(HCOMP.WritePointer or "?").." bytes compiled.", Color(50, 128, 20))

Check warning on line 119 in lua/wire/cpulib.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator
end
end,
function(error,errorPos)
local issue = (error or "unknown error")
Expand Down Expand Up @@ -163,7 +167,7 @@
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
Loading