mirror of
https://github.com/notwa/lips
synced 2024-06-16 04:33:06 -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:
parent
7af890c3b5
commit
7ccc2b180f
|
@ -350,11 +350,11 @@ function Lexer:lex(_yield)
|
||||||
self:nextc()
|
self:nextc()
|
||||||
local buff = self:read_chars('[%w_]')
|
local buff = self:read_chars('[%w_]')
|
||||||
if self.chr ~= ']' then
|
if self.chr ~= ']' then
|
||||||
self:error('invalid define name')
|
self:error('invalid variable name')
|
||||||
end
|
end
|
||||||
self:nextc()
|
self:nextc()
|
||||||
if self.chr ~= ':' then
|
if self.chr ~= ':' then
|
||||||
self:error('define requires a colon')
|
self:error('expected a colon after closing bracket')
|
||||||
end
|
end
|
||||||
self:nextc()
|
self:nextc()
|
||||||
yield('DEF', buff)
|
yield('DEF', buff)
|
||||||
|
|
|
@ -35,11 +35,11 @@ end
|
||||||
function Preproc:process(tokens)
|
function Preproc:process(tokens)
|
||||||
self.tokens = tokens
|
self.tokens = tokens
|
||||||
|
|
||||||
local defines = {}
|
local variables = {}
|
||||||
local plus_labels = {} -- constructed forwards
|
local plus_labels = {} -- constructed forwards
|
||||||
local minus_labels = {} -- constructed backwards
|
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 = {}
|
local new_tokens = {}
|
||||||
self.i = 0
|
self.i = 0
|
||||||
while self.i < #self.tokens do
|
while self.i < #self.tokens do
|
||||||
|
@ -64,14 +64,14 @@ function Preproc:process(tokens)
|
||||||
elseif t.tt == 'DEF' then
|
elseif t.tt == 'DEF' then
|
||||||
local t2 = self:advance()
|
local t2 = self:advance()
|
||||||
if t2.tt ~= 'NUM' then
|
if t2.tt ~= 'NUM' then
|
||||||
self:error('expected number for define')
|
self:error('expected number for variable')
|
||||||
end
|
end
|
||||||
defines[t.tok] = t2.tok
|
variables[t.tok] = t2.tok
|
||||||
elseif t.tt == 'DEFSYM' then
|
elseif t.tt == 'DEFSYM' then
|
||||||
local tt = 'NUM'
|
local tt = 'NUM'
|
||||||
local tok = defines[t.tok]
|
local tok = variables[t.tok]
|
||||||
if tok == nil then
|
if tok == nil then
|
||||||
self:error('undefined define') -- uhhh nice wording
|
self:error('undefined variable')
|
||||||
end
|
end
|
||||||
insert(new_tokens, self:token(tt, tok * sign))
|
insert(new_tokens, self:token(tt, tok * sign))
|
||||||
elseif t.tt == 'RELLABEL' then
|
elseif t.tt == 'RELLABEL' then
|
||||||
|
|
Loading…
Reference in New Issue
Block a user