Commit Graph

578 Commits

Author SHA1 Message Date
ISSOtm
cdd8200936 Add test for nested brackets 2019-10-10 15:00:59 +02:00
ISSOtm
d76f994318 Run tests under a specific locale
Fixes #427
2019-10-10 13:23:36 +02:00
Eldred Habert
e93d65d736 Merge pull request #425 from ISSOtm/eexpansion_error
Add info about string expansions in error reports
2019-10-03 10:20:49 +02:00
ISSOtm
dab5f59ed9 Fix location of all relevant SECTIONs in tests
If section placement is changed such that those are no longer guaranteed to be
placed at zero, tests would break when they shouldn't.
2019-09-23 01:28:48 +02:00
Eldred Habert
22a6a82642 Merge pull request #419 from dbrotz/fix-blackslash-tab-at-eof
Handle tabs after backslash at end of file
2019-09-23 00:05:21 +02:00
ISSOtm
55fbecee49 Add info about string expansions in error reports
This is especially useful when an EQUS expands to another one, to help
track them.
This is done separately from the file stack as the EQUS stack is separate
(which is itself because EQUS are managed *way* differently).
2019-09-12 10:02:24 +02:00
dbrotz
f36a3d5b2a Fix macro and rept buffer overflows
Macro and rept buffers were not always being terminated with newlines
and/or were vulnerable to the final newline being escaped, allowing
buffer overflows to occur. Now, they are terminated with newlines using
the same mechanism as the file buffer.
2019-09-10 03:03:04 -07:00
dbrotz
c5e8e4ff83 Reject input that contains null characters
Null characters in the middle of strings interact badly with the RGBDS
codebase, which assumes null-terminated strings. There is no reason to
support null characters in input source code, so the simplest way to deal
with null characters is to reject them early.
2019-09-09 17:27:56 -07:00
dbrotz
89eda89838 Handle tabs after backslash at end of file
Commit 6fbb25c added support for tabs between a \ and the newline it escapes,
but yy_create_buffer() was not updated to handle tabs.
2019-09-09 12:25:26 -07:00
dbrotz
889dd83798 Print useful error message when '\0' is used in a symbol name
AppendMacroArg() was passing 0 to sym_FindMacroArg(), which caused an assertion
failure. Now, AppendMacroArg() prints an error message instead.
2019-09-09 09:46:18 -07:00
Jakub Kądziołka
fa920f8449 Remove the no-longer-needed .out.pipe files 2019-09-03 23:25:27 +02:00
Jakub Kądziołka
01aa56606f test/asm: special-case include-recursion 2019-09-03 23:25:15 +02:00
Jakub Kądziołka
bddd5bc678 test/asm: Generate .out.pipe files on the fly 2019-09-03 22:46:05 +02:00
ISSOtm
37089ef940 Improve error stack
The old error stack was fairly obtuse and hard to use for debugging.
This improves it notably by ensuring all line numbers are relative
to the file, and not, say, the macro definition.
This is a breaking change if you were parsing the old stack, but
the change should be painless, and the new stack only brings more info.
The syntax is unchanged for files, macros see their name prefixed
with the file they're defined in and a pair of colors, REPT blocks
simply append a '::REPT~n' to the context they're in, where 'n' is
the number of iterations the REPT has done.
This is especially helpful in macro-heavy code such as rgbds-structs.
2019-09-02 14:18:29 +02:00
Eldred Habert
4ef27a0d23 Merge pull request #411 from ISSOtm/recursion_limit
Add a recursion limit
2019-09-02 02:21:16 +02:00
ISSOtm
20b2f5ee2f Fix incorrect line numbers with some IF blocks
If a line ended with a string's closing quote, or a newline escape, then
skipping over that line via IF/ELIF/ELSE would fail to count that line,
offsetting the rest of the file.
I have no idea why but for some reason 9829be1 changed *specifically*
`if_skip_to_else` to have incorrect behavior on string endings. The incorrect
behavior on newline escapes seems to have been here since the beginning.
Also added a test to check for both of those behaviors in both functions.

Honestly, it baffles me that nobody ever noticed. I didn't until I started
working on #395.
2019-09-01 03:59:29 +02:00
ISSOtm
f9a04696f2 Add recursion overflow tests 2019-08-31 17:22:43 +02:00
Anthony J. Bentley
a517f900e4 Use POSIX-compatible dd(1) instead of head -c. 2019-08-30 23:11:28 -06:00
dbrotz
d3db5f0d76 Add pushc and popc directives 2019-08-30 19:36:23 -07:00
dbrotz
e05199ca1e Add support for multiple charmaps
This adds two new directives: newcharmap and setcharmap.
newcharmap creates a new charmap and switches to it.
setcharmap switches to an existing charmap.
2019-08-29 21:54:06 -07:00
Eldred Habert
12d82eb768 Remove extra entry in error stack on macro not defined (#394)
While working on #392, I noticed that the macro-@ test (as well
as the line-continuation test, but for that one see #393)
printed an additional '@(-1)' entry which doesn't make sense.
2019-08-30 02:14:21 +02:00
Eldred Habert
3cc7981c82 Merge pull request #402 from dbrotz/fix-386
Fix nested if statements that don't have following whitespace
2019-08-29 22:06:10 +02:00
dbrotz
8f287eeef9 Fix nested if statements that don't have following whitespace
When trying to skip over nested if statements, if there was no whitespace
after an "if", then that "if" would not be recognized. That's a problem since
"if(" and "if{" are also valid ways to start an if statement. This change
will make it so that they are recognized correctly.
2019-08-29 12:37:59 -07:00
Eldred Habert
ce05cb5683 Merge pull request #401 from dbrotz/line-cont-test
Get rid of error in line continuation test
2019-08-29 21:23:00 +02:00
dbrotz
17945a7377 Get rid of error in line continuation test
The purpose of the test is to ensure that rgbasm doesn't segfault in this case.
The "Macro '@' not defined" error is unnecessary.
2019-08-29 11:49:17 -07:00
Eldred Habert
3a1b47129e Merge pull request #397 from NieDzejkob/test-local-without-parent
Add a test for a defining local label without a parent
2019-08-29 20:24:36 +02:00
Eldred Habert
6ffa751090 Merge pull request #390 from ISSOtm/print_types
Add "print types" to bracketed symbols
2019-08-29 20:12:32 +02:00
Eldred Habert
c3641321d7 Merge pull request #399 from ISSOtm/allow_dots
Allow periods to continue macro args
2019-08-29 20:09:32 +02:00
Eldred Habert
446173f0cb Merge pull request #387 from ISSOtm/set_doesnt_override_equ
Prevent `SET` from overriding constant symbols
2019-08-29 20:08:08 +02:00
ISSOtm
a3ee76dddd Allow periods to continue macro args
c75a953 broke my (previously-working) project that defined, via
macros, 'sizeof_.player'.
A test was added to confirm that those are indeed accepted
outside of macros.
2019-08-29 19:51:47 +02:00
ISSOtm
995265c549 Improve testing bracketed symbols
Also test EQU and _RS constants, as well as that EQUS errors out,
and that labels don't work.
2019-08-29 19:16:28 +02:00
Jakub Kądziołka
03629b74d9 Add a test for a defining local label without a parent 2019-08-29 19:14:02 +02:00
Eldred Habert
b069278e98 Merge pull request #384 from dbrotz/fix-local-label-segfault
Check if parent exists for local label reference
2019-08-29 19:05:27 +02:00
ISSOtm
a21ea30be0 Add tests for bracketed symbols 2019-08-29 17:08:54 +02:00
ISSOtm
e3e18063c6 Prevent SET from overriding constant symbols
Fixes #341
2019-08-27 21:23:36 +02:00
dbrotz
a6bf77718c Check if parent exists for local label reference
If an attempt is made to reference a local label before any non-local label
is defined, raise an error instead of segfaulting.
2019-08-20 09:57:53 -07:00
dbrotz
c2787a9ea9 Change the precedence of == to match the documentation
The documentation states that == has the same precedence as the other
comparison operators.
2019-08-20 08:50:18 -07:00
Antonio Niño Díaz
b8d5dd1824 Merge pull request #366 from dbrotz/fix-313
Fix signed integer overflow issues
2019-08-17 16:09:09 +01:00
Antonio Niño Díaz
88b66f2941 Merge pull request #364 from dbrotz/fix-362
Don't append invalid characters to symbol name
2019-08-17 16:08:27 +01:00
Ben Hetherington
16111f46ef Allow PUSHS to be used before a section
Previously, a PUSHS before a SECTION directive would cause rgbasm to crash when encountering a subsequent POPS.

This is because the subsequently-called out_setCurrentSection() expected the new section to be non-null, which wasn’t the case in this situation. This has been addressed by allowing the ‘null’ section to be set in this function, and only dereferencing it (to set nPC) if a non-null section is to be set.

In practice, this means that PUSHS/POPS can now be used to push/restore a context without a section.
2019-08-16 13:22:19 +01:00
Antonio Niño Díaz
b019b03946 Merge pull request #358 from dbrotz/fix-357
Fix buffer overflow when creating patches with long RPN expressions
2019-07-12 00:49:08 +01:00
dbrotz
484d15dbb2 Handle unprintable characters more gracefully
* Skip UTF-8 byte order mark at beginning of file
* Error on other unexpected unprintable characters
2019-07-04 17:14:55 -07:00
dbrotz
1decf5d0d4 Fix out of bounds array access in lexer
If the type char is signed, then in the function
yylex_GetFloatMaskAndFloatLen(), *s can have a negative value and be converted
to a negative int32_t which is then used as an array index. It should be
converted to uint8_t instead to ensure that the value is in the bounds of the
tFloatingFirstChar, tFloatingSecondChar, and tFloatingChars arrays.
2019-07-04 17:01:29 -07:00
dbrotz
015d2b0830 Fix buffer overflow when creating patches with long RPN expressions
The createpatch() function was using a fixed-size buffer. I've changed it
to be dynamically allocated. I saw that the RPN format used in patches is
slightly different from the one used internally in the assembler, so I
added a new member to the Expression struct to track the patch size.

I've also limited the RPN expression length to 1MB. I realized that the
patch RPN expression could potentially be longer than the internal RPN
expression, so the internal expression would need a limit smaller than
UINT32_MAX. I thought 1MB would be a reasonable limit.
2019-07-04 16:49:09 -07:00
dbrotz
c75a9539ba Don't append invalid characters to symbol name
When a macro arg appears in a symbol name, the contents are appended.
However, the contents of the macro arg were not being validated.
Any character, regardless of whether it was allowed in a symbol name,
would be appended. With this change, the contents of the macro arg
are now validated character by character. The symbol name is considered
to end at the last valid character. The remainder of the macro arg is
treated as though it followed the symbol name in the asm source code.
2019-07-04 16:34:47 -07:00
dbrotz
ca6149abcf Fix signed integer overflow issues
It seemed that the consensus in our discussions of signed integer
overflow, which invokes undefined behavior in C, was that integer
arithmetic should be two's complement and there should be no warning for
overflows. I have implemented that by converting values to unsigned types
when appropriate. These changes will mostly preserve existing behavior,
except for a few cases that were being handled incorrectly before.

The case of dividing INT_MIN by -1 previously resulted in a CPU
exception and program termination. Now, that case is detected and results
in a warning and a value of INT_MIN.

Similarly, INT_MIN % -1 would have resulted in a CPU exception. Since this
is a mathematically valid operation with a result of 0, it now simply
gives that result without a warning.

I noticed that in rpn.c, there were attempts in certain operation handlers
to validate the nVal members of the source expressions even when the
expressions may have been relocatable expressions with meaningless numbers
for the nVal member. This could have caused spurious errors/warnings, so I
made those handlers confirm that isReloc is false before validating nVal.

Also, integer constants that are too large now result in a warning. The
post-conversion values have not been changed, in order to preserve
backward compatibility.
2019-07-04 16:27:31 -07:00
Jakub Kądziołka
df15c97b6e Handle zero-byte files gracefully 2019-07-03 16:38:35 +02:00
Jakub Kądziołka
f7bc61e874 Automatic tests for input from stdin 2019-07-03 16:05:54 +02:00
Antonio Niño Díaz
3cd1d46a1b Merge pull request #356 from NieDzejkob/add-narg-test
Add a test for the behavior of NARG after SHIFT
2019-06-16 22:35:37 +01:00
Jakub Kądziołka
88eceec257 Add a test for the behavior of NARG after SHIFT 2019-06-09 12:58:32 +02:00