Skip to content

Commit

Permalink
refactor: Update lvalue and multiret node type checks to use lookup t…
Browse files Browse the repository at this point in the history
…ables
  • Loading branch information
bytexenon committed Aug 16, 2024
1 parent 92dbc3d commit c940ddc
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions the-tiny-lua-compiler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,8 @@ end
--]]

local PARSER_UNARY_OPERATOR_PRECEDENCE = 8
local PARSER_MULTIRET_NODE_TYPES = createLookupTable({ "FunctionCall", "MethodCall", "VarArg" })
local PARSER_LVALUE_NODE_TYPES = createLookupTable({ "Variable", "TableIndex" })
local PARSER_STOP_KEYWORDS = createLookupTable({ "end", "else", "elseif", "until" })
local PARSER_OPERATOR_PRECEDENCE = { ["+"] = {6, 6}, ["-"] = {6, 6},
["*"] = {7, 7}, ["/"] = {7, 7}, ["%"] = {7, 7},
Expand Down Expand Up @@ -653,12 +655,10 @@ function Parser.parse(tokens)

--// NODE CHECKERS //--
local function isValidAssignmentLvalue(node)
local nodeType = node.TYPE
return nodeType == "Variable" or nodeType == "TableIndex"
return PARSER_LVALUE_NODE_TYPES[node.TYPE]
end
local function isMultiretNode(node)
local nodeType = node.TYPE
return nodeType == "FunctionCall" or nodeType == "MethodCall" or nodeType == "VarArg"
return PARSER_MULTIRET_NODE_TYPES[node.TYPE]
end

--// EXPECTORS //--
Expand Down Expand Up @@ -1381,8 +1381,7 @@ function InstructionGenerator.generate(ast)
--// UTILITY FUNCTIONS //--
local function isMultiretNode(node)
if not node then return false end
local nodeType = node.TYPE
return nodeType == "FunctionCall" or nodeType == "MethodCall" or nodeType == "VarArg"
return PARSER_MULTIRET_NODE_TYPES[node.TYPE]
end
local function updateJumpInstruction(instructionIndex)
local currentInstructionIndex = #code
Expand Down

0 comments on commit c940ddc

Please sign in to comment.