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

Zap/Preserve now ignores variables/identifiers that are unrelated #19

Merged
merged 2 commits into from
Nov 20, 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
13 changes: 10 additions & 3 deletions lua/wire/client/hlzasm/hc_syntax.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ for i=0,15 do VectorSyntax.MATRIX[i+1] = {tostring(i)} end

--------------------------------------------------------------------------------
-- Compile an opcode (called after if self:MatchToken(TOKEN.OPCODE))
function HCOMP:Opcode() local TOKEN = self.TOKEN
function HCOMP:Opcode() local TOKEN,TOKENSET = self.TOKEN,self.TOKENSET
local opcodeName = self.TokenData
local opcodeNo = self.OpcodeNumber[self.TokenData]
local operandCount = self.OperandCount[opcodeNo]
Expand Down Expand Up @@ -456,7 +456,7 @@ end

--------------------------------------------------------------------------------
-- Compile a variable/function. Returns corresponding labels
function HCOMP:DefineVariable(isFunctionParam,isForwardDecl,isRegisterDecl,isStructMember) local TOKEN = self.TOKEN
function HCOMP:DefineVariable(isFunctionParam,isForwardDecl,isRegisterDecl,isStructMember) local TOKEN,TOKENSET = self.TOKEN,self.TOKENSET
local varType,varSize,isStruct
if self:MatchToken(TOKEN.IDENT) then -- Define structure
varType = self.TokenData
Expand Down Expand Up @@ -742,7 +742,7 @@ end

--------------------------------------------------------------------------------
-- Compile a single statement
function HCOMP:Statement() local TOKEN = self.TOKEN
function HCOMP:Statement() local TOKEN,TOKENSET = self.TOKEN,self.TOKENSET
-- Parse code for absolute labels and define (LABEL:)
if self.CurrentToken == 1 then
while not(self:MatchToken(TOKEN.EOF)) do
Expand Down Expand Up @@ -826,6 +826,13 @@ function HCOMP:Statement() local TOKEN = self.TOKEN
local tokenType = self.TokenType
if self.BlockDepth > 0 then
while self:MatchToken(TOKEN.REGISTER) or self:MatchToken(TOKEN.IDENT) do
-- Don't error on catching a variable being used near a zap/preserve
if self:MatchToken(TOKENSET.OPERATORS) then
-- move back 2 tokens and then re-parse this
self:PreviousToken()
self:PreviousToken()
return self:Statement()
end
if self.TokenType == TOKEN.IDENT then
if self.RegisterIdentities[self.TokenData] then
if tokenType == TOKEN.PRESERVE then
Expand Down
52 changes: 52 additions & 0 deletions lua/wire/client/hlzasm/hc_tokenizer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@
HCOMP.TOKEN_TEXT["EOF"] = {{"ZASM","HLZASM"},{}} -- end of file

-- Add ZCPU ports
for port=0,1023 do

Check warning on line 102 in lua/wire/client/hlzasm/hc_tokenizer.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator
HCOMP.TOKEN_TEXT["REGISTER"][2][1024+port] = "PORT"..port

Check warning on line 103 in lua/wire/client/hlzasm/hc_tokenizer.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator

Check warning on line 103 in lua/wire/client/hlzasm/hc_tokenizer.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator
end

-- Add extended registers
for reg=0,31 do

Check warning on line 107 in lua/wire/client/hlzasm/hc_tokenizer.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator
HCOMP.TOKEN_TEXT["REGISTER"][2][96+reg] = "R"..reg

Check warning on line 108 in lua/wire/client/hlzasm/hc_tokenizer.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator

Check warning on line 108 in lua/wire/client/hlzasm/hc_tokenizer.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator
end


Expand All @@ -114,6 +114,7 @@
--------------------------------------------------------------------------------
-- Generate table of all possible tokens
HCOMP.TOKEN = {}
HCOMP.TOKENSET = {} -- Manuallly defined sets of tokens
HCOMP.TOKEN_NAME = {}
HCOMP.TOKEN_NAME2 = {}
local IDX = 1
Expand All @@ -128,6 +129,49 @@
IDX = IDX + 1
end

HCOMP.TOKENSET.OPERATORS = {
HCOMP.TOKEN.LPAREN,
HCOMP.TOKEN.RPAREN,
HCOMP.TOKEN.LSUBSCR,
HCOMP.TOKEN.RSUBSCR,
HCOMP.TOKEN.TIMES,
HCOMP.TOKEN.SLASH,
HCOMP.TOKEN.MODULUS,
HCOMP.TOKEN.PLUS,
HCOMP.TOKEN.MINUS,
HCOMP.TOKEN.AND,
HCOMP.TOKEN.OR,
HCOMP.TOKEN.XOR,
HCOMP.TOKEN.POWER,
HCOMP.TOKEN.INC,
HCOMP.TOKEN.DEC,
HCOMP.TOKEN.SHL,
HCOMP.TOKEN.SHR,
HCOMP.TOKEN.EQL,
HCOMP.TOKEN.NEQ,
HCOMP.TOKEN.LEQ,
HCOMP.TOKEN.LSS,
HCOMP.TOKEN.GEQ,
HCOMP.TOKEN.GTR,
HCOMP.TOKEN.NOT,
HCOMP.TOKEN.EQUAL,
HCOMP.TOKEN.LAND,
HCOMP.TOKEN.LOR,
HCOMP.TOKEN.EQLADD,
HCOMP.TOKEN.EQLSUB,
HCOMP.TOKEN.EQLMUL,
HCOMP.TOKEN.EQLDIV,
HCOMP.TOKEN.DOT
}

HCOMP.TOKENSET.ASSIGNMENT = {
HCOMP.TOKEN.EQUAL,
HCOMP.TOKEN.EQLADD,
HCOMP.TOKEN.EQLSUB,
HCOMP.TOKEN.EQLMUL,
HCOMP.TOKEN.EQLDIV
}

-- Create lookup tables for faster parsing
HCOMP.PARSER_LOOKUP = {}
for symID,symList in pairs(HCOMP.TOKEN_TEXT) do
Expand Down Expand Up @@ -161,9 +205,9 @@
end
if #symText == 1 then
for _,lang in pairs(languages) do
HCOMP.PARSER_SYMBOLS[lang] = HCOMP.PARSER_SYMBOLS[lang] or {}

Check warning on line 208 in lua/wire/client/hlzasm/hc_tokenizer.lua

View workflow job for this annotation

GitHub Actions / lint

"Syntax inconsistency"

Inconsistent use of tabs and spaces for indentation
HCOMP.PARSER_SYMBOLS[lang][symText] = true
end

Check warning on line 210 in lua/wire/client/hlzasm/hc_tokenizer.lua

View workflow job for this annotation

GitHub Actions / lint

"Syntax inconsistency"

Inconsistent use of tabs and spaces for indentation
end
end

Expand Down Expand Up @@ -226,7 +270,7 @@
while (self:getChar() == " ") or
(self:getChar() == "\t") or
(self:getChar() == "\n") or
(self:getChar() == "\r") do self:nextChar() end

Check warning on line 273 in lua/wire/client/hlzasm/hc_tokenizer.lua

View workflow job for this annotation

GitHub Actions / lint

"Syntax inconsistency"

Inconsistent use of tabs and spaces for indentation

-- Read token position
local tokenPosition = { Line = self.Code[1].Line,
Expand Down Expand Up @@ -323,7 +367,7 @@
end

-- Check if token was redefined
if (token ~= "") and (self.Defines[token]) then

Check warning on line 370 in lua/wire/client/hlzasm/hc_tokenizer.lua

View workflow job for this annotation

GitHub Actions / lint

"Unnecessary parentheses"

Unnecessary parentheses
if token == "__FILE__" then
table.insert(self.Tokens,{
Type = TOKEN.STRING,
Expand Down Expand Up @@ -495,6 +539,14 @@

-- Returns true and skips a token if it matches this one
function HCOMP:MatchToken(tok)
if istable(tok) then -- Match against a table of tokens
for _,token in pairs(tok) do
if self:MatchToken(token) then
return true
end
end
return false
end
if not self.Tokens[self.CurrentToken] then
return tok == self.TOKEN.EOF
end
Expand Down
Loading