Commit Graph

859 Commits

Author SHA1 Message Date
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
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
ISSOtm
2e6f5ac679 Fix unary NOT being broken
nVal wasn't being set, this made the operator a no-op on constant expressions
2019-09-08 21:42:17 +02:00
ISSOtm
7a45fc68d9 Fix incorrect evaluation of && and ||
f29d768 forgot to switch these two `expr->nVal` to `src1->nVal`
This won't break anything, since this wasn't published yet.
I checked, and didn't see any other missed changes.

Reported by pret, I confirmed that `1 && 1` evaluated to 0.
2019-09-08 21:12:31 +02:00
ISSOtm
9faa5c7a9e Update docs on char escapes in macro args
Fixes #415
2019-09-05 15:40:54 +02:00
ISSOtm
6fbb25c0da Clean up lexer.c
Remove some hardcoded character values
Allow tabs to be used for line continuations
2019-09-05 15:22:24 +02:00
ISSOtm
65fc42cce5 Remove -Wchkp from develop target
This option has been removed in GCC 9, and according to GCC 8.2's man page,
only has an implementation on Intel MRX anyways.
2019-09-05 05:56:11 +02:00
Eldred Habert
736b7727b6 Merge pull request #400 from NieDzejkob/out.pipe-substitute
test/asm: Generate .out.pipe files on the fly
2019-09-04 18:43:00 +02: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
Eldred Habert
f6b7e39ce7 Merge pull request #405 from ISSOtm/output_errors
Make RGBDS behave identically whether writing a .o
2019-09-03 10:05:19 +02:00
clach04
1363dd8f34 Add url link to releases page to readme (#413) 2019-09-03 01:51:38 +02:00
Eldred Habert
8214f0c09d Merge pull request #412 from clach04/patch-1
Clarify install instructions on Windows
2019-09-03 00:50:43 +02:00
clach04
ff7c46f5a6 Readme windows install instructions, alternative install location 2019-09-02 10:19:22 -07:00
ISSOtm
b44f5825a5 Make RGBDS behave identically whether writing a .o
Some errors are only tripped in `out_WriteObject`, which was
basically a stub when `-o` wasn't specified. Now, instead,
errors are checked in a separate function before out_WriteFile
2019-09-02 15:04:46 +02:00
Eldred Habert
631910bd67 Merge pull request #395 from ISSOtm/better_error_stack
Improve error stack
2019-09-02 14:33:06 +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
476ccc9f6b Fix undefined behavior in yyunputstr
Refer to comment at lexer.c:100 for more info
2019-09-02 02:09:59 +02:00
Eldred Habert
89dc14fcaf Merge pull request #408 from ISSOtm/plumbing
Fix memory leaks with macro args
2019-09-01 22:16:27 +02:00
clach04
1ca2f12d24 Update README.rst
Add Windows path note, in preference from adding exes to system locations
2019-09-01 09:51:47 -07: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
3cc67c48cf Add recursion limit info to man and help 2019-08-31 17:34:54 +02:00
ISSOtm
f9a04696f2 Add recursion overflow tests 2019-08-31 17:22:43 +02:00
ISSOtm
e0e8170fe6 Add recursion limit for string expansions
Unlike macros, REPTs and INCLUDEs, this recursion depth is independent.
This is intentional, because string expansions work very differently.

While it's easy to know when a string expansion begins, checking where it
ends is much more complicated, since the expansion's contents are simply
injected back into the lex buffer. Therefore, the depth has to be checked
after lexing took place.
Because of this, the placement of the expansion end check is somewhat
haphazard, but I think it's good. While I have no certainty, all tests
ended with all expansions properly ended, and I couldn't find any pitfalls.

Finally, `pCurrentStringExpansion` has been made global so error printing
can use it to tell the user if an error occurred inside of an expansion.
2019-08-31 15:50:08 +02:00
Eldred Habert
9b40663d54 Merge pull request #409 from rednex/dd-head
Use POSIX-compatible dd(1) instead of head -c.
2019-08-31 12:59:18 +02:00
Anthony J. Bentley
a517f900e4 Use POSIX-compatible dd(1) instead of head -c. 2019-08-30 23:11:28 -06:00
Eldred Habert
350f40300c Merge pull request #403 from dbrotz/multiple-charmaps
Add support for multiple charmaps
2019-08-31 04:44:58 +02:00
dbrotz
d3db5f0d76 Add pushc and popc directives 2019-08-30 19:36:23 -07:00
ISSOtm
7e3af4b3cd Make testing external projects use local RGBDS
Currently, the installed version is used instead, which isn't
consistent with the tests, which use the local version.
2019-08-31 04:17:16 +02:00
ISSOtm
dfb3072381 Fix memory leaks with macro args
REPT blocks nested in macros (and possibly other cases) leaked
memory on every call. Unlike most other memory leaks, which would
be freed at the end of program execution if they were done properly,
those piled up the more compilation went on.
I believe memory usage could have started being fairly high on
large projects following the "one master file INCLUDEs all the rest"
so this may have actually been worth it.
2019-08-31 03:52:42 +02:00
ISSOtm
02191135a0 Fix possible unterminated string
sym_SetMacroArgID used a `sprintf` that could write no \0.
In practice this was benign because %u cannot print 256 chars,
but better future-proof this.
2019-08-31 03:00:26 +02:00
ISSOtm
dc2c97fe0c Comment and improve ParseSymbol and AppendMacroArg 2019-08-31 02:31:46 +02:00
ISSOtm
6068b565f5 Add recursion limit for INCLUDE and macros
(And REPT.)
Not exactly a *recursion* limit, more like a *stack depth* limit,
but calling it "recursion" conveys its purpose better.
The default of 64 is super overkill: even in a a project with
what I believe to be above-average levels of nesting, the
level only peaked at 6.
Keeping in mind the purpose of this is to catch infinite
recursion, which is still caught quickly (in usual cases, anyways),
this default seems sensible.
And it passes tests. What more do you need?
2019-08-31 02:31:42 +02:00
ISSOtm
a21cef7190 Say which macro argument caused an error when one does 2019-08-30 20:57:11 +02:00
dbrotz
461ef6cea5 Don't complain about initializing statics
This error is specific to the way the Linux kernel handles statics.
It does not apply to userspace programs.
2019-08-29 22:48:16 -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
05becf3f4b Merge pull request #381 from NieDzejkob/rgbgfx-curve
rgbgfx: Add an option to take the CGB's color profile into account
2019-08-29 22:19:36 +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
Eldred Habert
e27f381842 Merge pull request #361 from ISSOtm/better_section_overflow
Improve section overflow error message
2019-08-29 20:04:48 +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