Skip to content
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
10 changes: 10 additions & 0 deletions lua/wire/client/hlzasm/hc_compiler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,16 @@ function HCOMP:StartCompile(sourceCode,fileName,writeByteCallback,writeByteCalle
self.WriteByteCallback = writeByteCallback
self.WriteByteCaller = writeByteCaller

-- Refresh the keywords table.
local keywordsTable = WireTextEditor.Modes.ZCPU.keywordsTable
local keywordsTableOriginal = WireTextEditor.Modes.ZCPU.keywordsTableOriginal

for k,v in pairs(keywordsTable) do
if keywordsTableOriginal[k] == nil then
keywordsTable[k] = nil
end
end

-- Set the working directory
self.FileName = string.sub(fileName,string.find(fileName,"\\$") or 1)
if string.GetPathFromFilename then
Expand Down
1 change: 1 addition & 0 deletions lua/wire/client/hlzasm/hc_syntax.lua
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ function HCOMP:DefineVariable(isFunctionParam,isForwardDecl,isRegisterDecl,isStr
varType = self.TokenData
varSize = 0 -- Depends on pointer level
isStruct = true
WireTextEditor.Modes.ZCPU.keywordsTable[string.upper(varType)] = true -- Add the new struct to the keywords table.
else -- Define variable
self:ExpectToken(TOKEN.TYPE)
varType = self.TokenData
Expand Down
14 changes: 12 additions & 2 deletions lua/wire/client/text_editor/modes/zcpu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,16 @@ local keywordsList = {
"INT","FLOAT","CHAR","VOID","PRESERVE","ZAP","STRUCT","VECTOR"
}

local keywordsTable = {}
EDITOR.keywordsTable = {}
local keywordsTable = EDITOR.keywordsTable

for k,v in pairs(keywordsList) do
keywordsTable[v] = true
end

-- For checking the keywords to remove structs in the editor.
EDITOR.keywordsTableOriginal = table.Copy(keywordsTable)

-- Build lookup table for registers
local registersTable = {
EAX = true,EBX = true,ECX = true,EDX = true,ESI = true,EDI = true,
Expand Down Expand Up @@ -202,6 +207,9 @@ function EDITOR:SyntaxColorLine(row)

local isGpu = self:GetParent().EditorType == "GPU"

-- Remember the last token to prevent structs from being highlighted.
local previousToken = ""

while self.character do
local tokenname = ""
self.tokendata = ""
Expand All @@ -217,13 +225,15 @@ function EDITOR:SyntaxColorLine(row)
tokenname = "opcode"
elseif registersTable[sstr] then
tokenname = "register"
elseif keywordsTable[sstr] then
elseif keywordsTable[sstr] and (previousToken ~= "STRUCT") then -- Default to number/normal if it's declaring a struct.
tokenname = "keyword"
elseif tonumber(self.tokendata) then
tokenname = "number"
else
tokenname = "normal"
end

previousToken = sstr
elseif (self.character == "'") or (self.character == "\"") then
tokenname = "string"
local delimiter = self.character
Expand Down
Loading