1
0
Fork 0
mirror of https://github.com/notwa/lips synced 2024-05-03 18:13:23 -07:00

rename "defines" to "variables"

this follows bass' terminology:
constants don't care where they're defined, but can never be changed.
variables must be defined before use, but can be redefined.
defines aren't necessarily numbers.

bass: https://github.com/ARM9/bass
This commit is contained in:
Connor Olding 2016-04-20 01:41:44 -07:00
parent 7af890c3b5
commit 7ccc2b180f
2 changed files with 8 additions and 8 deletions

View File

@ -350,11 +350,11 @@ function Lexer:lex(_yield)
self:nextc()
local buff = self:read_chars('[%w_]')
if self.chr ~= ']' then
self:error('invalid define name')
self:error('invalid variable name')
end
self:nextc()
if self.chr ~= ':' then
self:error('define requires a colon')
self:error('expected a colon after closing bracket')
end
self:nextc()
yield('DEF', buff)

View File

@ -35,11 +35,11 @@ end
function Preproc:process(tokens)
self.tokens = tokens
local defines = {}
local variables = {}
local plus_labels = {} -- constructed forwards
local minus_labels = {} -- constructed backwards
-- first pass: resolve unary ops, defines, and collect relative labels
-- first pass: resolve unary ops, variables, and collect relative labels
local new_tokens = {}
self.i = 0
while self.i < #self.tokens do
@ -64,14 +64,14 @@ function Preproc:process(tokens)
elseif t.tt == 'DEF' then
local t2 = self:advance()
if t2.tt ~= 'NUM' then
self:error('expected number for define')
self:error('expected number for variable')
end
defines[t.tok] = t2.tok
variables[t.tok] = t2.tok
elseif t.tt == 'DEFSYM' then
local tt = 'NUM'
local tok = defines[t.tok]
local tok = variables[t.tok]
if tok == nil then
self:error('undefined define') -- uhhh nice wording
self:error('undefined variable')
end
insert(new_tokens, self:token(tt, tok * sign))
elseif t.tt == 'RELLABEL' then