Skip to content

Commit 128eaa9

Browse files
committed
Stop expanding unknown aliases to 0
Also stop expanding non-number aliases to 1. These are extremely bad decisions made by C's preprocessor, I have no idea why I replicated them in the first place.
1 parent d524a3a commit 128eaa9

2 files changed

Lines changed: 11 additions & 10 deletions

File tree

examples/a728d28/adder.asm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
_Model "A728D28[0A]" ; * Specify target model.
22

3+
%include "common"
4+
35
start:
46
ldb ; * Get a number and
57
st r0 | ldb ; store it in r0, then get another and

src/evaluate.lua

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,14 @@ return function(tokens, cursor, last, aliases)
6868
operands[ix] = operands[ix].value
6969
elseif operands[ix].type == "alias" then
7070
local alias = operands[ix].value
71-
if alias then
72-
local ok, number
73-
if #alias == 1 then
74-
ok, number = alias[1]:parse_number()
75-
end
76-
operands[ix] = ok and number or 1
77-
else
78-
operands[ix] = 0
71+
local ok, number
72+
if #alias == 1 then
73+
ok, number = alias[1]:parse_number()
7974
end
75+
if not ok then
76+
return false, operands[ix].position, ("operand %i does not expand to a number"):format(ix)
77+
end
78+
operands[ix] = number
8079
else
8180
return false, operands[ix].position, ("operand %i is %s, should be number"):format(ix, operands[ix].type)
8281
end
@@ -144,10 +143,10 @@ return function(tokens, cursor, last, aliases)
144143
return false, pos, err
145144
end
146145

147-
elseif tokens[cursor]:identifier() then
146+
elseif tokens[cursor]:identifier() and aliases[tokens[cursor].value] then
148147
table.insert(stack, {
149148
type = "alias",
150-
value = aliases[tokens[cursor].value] or false,
149+
value = aliases[tokens[cursor].value],
151150
position = cursor,
152151
depth = 1
153152
})

0 commit comments

Comments
 (0)