Rangi
4a73eb56ea
Make peek() tail recursive instead of using goto
...
Compilation is identical with `gcc` or `clang`, -O3` or `-O2`
2021-08-18 01:30:47 +02:00
Rangi
b51e1c7c2c
Compare FOR ranges to Python's range
2021-08-01 10:45:44 +02:00
Rangi
26ddf1ff4d
Prevent defining invalid local labels
...
Fixes #913
2021-07-30 15:21:47 +02:00
Rangi
03bb510588
endCapture shouldn't handle lexerState->atLineStart
...
`startCapture` did not initialize `lexerState->atLineStart`;
its final value is a consequence of the separate but similar
behaviors within `lexer_CaptureRept` and `lexer_CaptureMacroBody`.
2021-07-04 18:31:46 -04:00
Rangi
695dfe9dbd
Add missing file line-continuation-string.asm
...
Also make some minor formatting corrections
2021-07-04 16:12:34 -04:00
Rangi
1b5648bb06
Line continuations *do* work inside strings
...
The rgbasm.5(5) documentation was outdated here
2021-07-01 17:56:49 -04:00
Rangi
a67f5d6e01
SIZEOF("Section") and STARTOF("Section") can be known
...
Fixes #890
2021-06-27 21:03:06 +02:00
Rangi
06b57aa1ce
Avoid unnecessary "overwriting a non-zero byte" warnings
...
- Don't warn if the non-zero byte being written is the same as the original byte
- Add a `-O` / `--overwrite` flag to silence all such warnings
Fixes #897
2021-06-27 19:16:11 +02:00
Rangi
80a376f045
Syntax errors resets the lexer right away
...
`DEF`, `REDEF`, etc disable EQUS expansion, and reading
macro or OPT arguments sets the lexer to raw mode.
Syntax errors resume normal parsing at the line's end,
but should resume normal tokenization even before that.
2021-05-22 16:08:55 -04:00
Rangi
0068c1375c
Syntax error message hints to indent macro invocations
...
This message is only printed for identifiers parsed as
`T_LABEL` (since they're at the start of a line) but
already defined as macros. Otherwise it may not be
relevant, e.g. for `MyLabel;:` or `My Label::`.
2021-05-22 14:58:26 +02:00
Rangi
23721694ea
Comment that anonymous labels internally start with '!'
...
`startsIdentifier` should not accept this character so
anonymous labels won't conflict with nonymous ones.
2021-05-15 12:57:22 -04:00
Rangi
6a5e2f439e
Fix the STRFMT documentation in rgbasm(5)
...
Fixes #886
2021-05-09 17:23:57 -04:00
Rangi
fba77c4dce
Specify to update the release branch in RELEASE.rst
...
This is done manually after publishing a release.
2021-05-08 23:44:53 -04:00
Rangi
830df360ae
Specify that all .sh files need Unix line endings
...
The `git config --global --unset core.autocrlf` command
was failing in the "Create release artifacts" workflow,
so this is an alternate method of fixing issue #841 .
2021-05-08 23:22:31 -04:00
Rangi
c75551b1b3
Release 0.5.1
2021-05-08 22:38:20 -04:00
Rangi
5a38f6e148
rgbasm supports "Q16.16" fixed-point literals
...
"Qm.n" signifies an m-bit two's complement integer
with n fractional bits.
<https://en.wikipedia.org/wiki/Q_(number_format) >
2021-05-06 23:17:08 -04:00
Rangi
869021f47d
Fix -Wformat build warnings on macOS
...
C arithmetic promotes certain expressions to `int`,
so formatting has to use "%d" or "%x", not inttypes.h.
Fixes #883
2021-05-04 21:28:57 -04:00
Rangi
8397b3d8ec
.sym file sorts symbols from zero-length sections first
...
This will, for instance, ensure that a zero-length
`SECTION "NULL", ROM0[0] / NULL::` comes first.
2021-05-02 17:57:20 -04:00
Rangi
296e5489c9
rgblink adjusts patches' PC offsets when merging FRAGMENTs
...
Fixes #869
2021-05-02 23:54:42 +02:00
Rangi
9ab9d0f39c
Output all SECTION UNION/FRAGMENT symbols in .sym files
...
Fixes #809
2021-05-02 23:51:17 +02:00
Rangi
e9bfe849ad
Allow OPT to toggle -h
2021-05-02 11:06:53 +02:00
Rangi
665eb916a2
OPT L acts like -L and *dis*ables optimizing LD to LDH
...
Fixes #867
2021-05-02 11:06:53 +02:00
Rangi
04788e15af
Fix a potential out-of-bounds array access in RGBGFX
...
This was caught by ASAN for pokered's gfx/battle/minimize.png.
2021-05-01 22:33:54 -04:00
Rangi
ca36422ac9
Parse 'ld hl, sp - <e8>' correctly
...
Fixes #864
2021-05-01 11:08:01 +02:00
Rangi
8e4ba8d2e4
Allow REDEF for EQU constants
...
Fixes #853
2021-04-29 12:24:07 +02:00
Rangi
ee67f1039c
Fix REDEF EQUS behavior
...
Redefining an EQUS constant will now update its filename,
like redefining a SET/= constant.
Attempting to redefine as EQUS a non-EQUS constant will
print an appropriate error message.
This also standardizes on `sym` versus `symbol` as a
variable name (which pairs with `symName`).
2021-04-28 12:11:26 -04:00
Rangi
d37aa93a7d
Port some cleanup from the WIP 'strings' branch
...
This is mostly variable renaming
2021-04-28 11:58:56 -04:00
Rangi
bba532193b
Port some cleanup from PR #847
...
- Update some whitespace formatting
- Factor out some functions
- Free data after outputting to an object file
2021-04-28 11:58:56 -04:00
Rangi
4ee2eb845b
Clone test repositories with earlier --shallow-since dates
...
The previous dates were not reliably downloading the
necessary commit IDs for checkout to work.
2021-04-27 17:27:23 -04:00
Rangi
3fdf01c0f5
Resolve some TODO comments
...
- `out_PushSection` should not set `currentSection` to NULL because
PUSHS, PUSHC, and PUSHO consistently keep the current section,
charmap, and options, even though the stack has been pushed.
- `Callback__FILE__` does not need to assert that `fileName` is not
empty because `__FILE__`'s value is quoted, and can safely be empty.
- `YY_FATAL_ERROR` and `YYLMAX` are not needed since the lexer is
not generated with flex.
2021-04-26 15:52:30 -04:00
Rangi
1949a61c6f
Tested the ctz and clz shim functions
...
Their values match the GCC builtins for all
4,294,967,295 nonzero inputs.
2021-04-26 12:17:34 -04:00
Rangi
43cf20b155
Support Mac OS classic CR line endings in linkerscripts
...
This also refactors `readChar(file)` to `nextChar()` to be
more like the rgbasm lexer.
2021-04-26 12:05:36 -04:00
Rangi
e27a6d53a0
Support character escapes in linkerscript strings
...
This allows linkerscripts to refer to section names even if
they contain special characters: '\r' '\n' '\t' '"' '\\'.
2021-04-26 12:05:36 -04:00
Rangi
e050803ed1
Use size_t for measuring nested depths
...
Multiple functions involve tracking the current depth
of a nested structure (symbol expansions, interpolations,
REPT/FOR blocks, parentheses).
2021-04-23 14:28:10 +02:00
Rangi
27f38770d4
Parentheses in macro args prevent commas from starting new arguments
...
This is similar to C's behavior, and convenient for passing
function calls as single values, like `MUL(3.0, 4.0)` or
`STRSUB("str", 2, 1)`.
Fixes #704
2021-04-23 14:28:10 +02:00
Rangi
4d21588eb2
Make invalid UTF-8 characters in strings non-fatal
...
STRLEN and STRSUB report the erroneous bytes
Fixes #848
2021-04-22 09:59:02 +02:00
Rangi
e596dbfc80
Make failed macro arg expansions non-fatal
...
Expanding empty strings is valid but pointless;
macro args already skipped doing so, now other
`beginExpansion` calls do too.
This also fixes failed interpolations (which were
already non-fatal) to continue reading characters,
not evaluate to their initial '{' character.
2021-04-22 09:59:02 +02:00
Rangi
1aeaca2af6
Add test case sort-algorithms.asm
...
This combines 0.5.0 and post-0.5.0 features:
print and println, strfmt, for loops,
def assignments, redef equs, {interpolation},
new macro syntax, and \<bracketed macro args>
2021-04-20 22:36:56 -04:00
Rangi
267e4bc25c
rgbds.7(7) shows an example of piping rgbasm to rgblink to rgbfix
...
This uses one line instead of three
2021-04-20 22:06:02 -04:00
Rangi
c3e27217dd
More specific "Symbol name too long" error messages
...
Identifiers, {interpolations} and \<macroArgs> are distinct
2021-04-20 17:14:21 +02:00
Rangi
fe3521c7a4
Switch from parentheses to angle brackets
...
`\(` is more likely to be a valid escape sequence in the
future (as is `\[`) and `\{` is already taken.
2021-04-20 17:14:21 +02:00
Rangi
b0f8d75d1d
Shorten quine.asm with \(parenthesized) macro args
2021-04-20 17:14:21 +02:00
Rangi
7a314e7aff
Support numeric symbol names in \(parentheses)
...
For example, \(_NARG) will get the last argument
2021-04-20 17:14:21 +02:00
Rangi
637bbbdf43
Support multi-digit macro arguments in parentheses
...
This allows access to arguments past \9 without using 'shift'
2021-04-20 17:14:21 +02:00
Rangi
8230e8165c
Eliminate isAtEOF by changing yylex control flow
...
`yylex` calls `yywrap` at the beginning of the next call, after it
has set `lexerState->lastToken` to `T_EOB`.
2021-04-20 17:10:08 +02:00
Rangi
a727a0f81f
Capture termination status is equivalent to not having reached EOF
...
This avoids the need for a separate `terminated` flag
2021-04-20 17:10:08 +02:00
Rangi
7a587eb7d6
Use midrule action values for captures' terminated status
...
Bison 3.1 introduces "typed midrule values", which would write
`<captureTerminated>{ ... }` and `$$` instead of `{ ... }` and
`$<captureTerminated>[1-9]`, but rgbds supports 3.0 or even lower.
2021-04-20 17:10:08 +02:00
Rangi
7ac8bd6e24
Return a marker token at the end of any buffer
...
Removes the lexer hack mentioned in #778
2021-04-20 17:10:08 +02:00
Rangi
be2572edca
Track nested interpolation depth even outside string literals
...
Fixes #837
2021-04-20 09:37:29 -04:00
Rangi
cf2bbe6435
Position -1 is the last character of a string
...
Position 0 is invalid, which matches with STRIN/STRRIN
returning 0 on failure.
2021-04-20 14:27:59 +02:00
Rangi
dc5b7802c8
Make the len parameter optional in STRSUB(str, pos, len)
...
An unspecified length will continue to the end of the string.
2021-04-20 14:27:59 +02:00
Rangi
b1e6c73197
STRSUB and CHARSUB allow zero or negative positions
...
These are offsets from the end of the string, as if the
STRLEN or CHARLEN respectively were added to the position.
Fixes #812
2021-04-20 14:27:59 +02:00
Rangi
459773b3f0
Update some whitespace after Hungarian prefixes were removed
...
Keep the parameter alignment and 100-char line limit
2021-04-19 16:47:39 -04:00
Rangi
3bea7930a9
Only update documentation for gbdev/rgbds
...
Prevent the relevant GitHub Actions from running on forks
2021-04-18 16:16:17 -04:00
Rangi
5108c5643c
Let charmap_ConvertNext advance its output pointer
2021-04-17 18:18:34 -04:00
Rangi
2005ed1df9
Implement CHARLEN and CHARSUB
...
Fixes #786
2021-04-17 18:18:34 -04:00
Rangi
d43408f4f3
Allow OPT to modify -W
...
Warning flags are processed individually;
PUSHO and POPO (re)store all the warning states.
2021-04-18 00:11:18 +02:00
Rangi
2c30ab8731
Allow OPT to modify -L
...
-L is a Boolean flag option, so you specify 'OPT L' or 'OPT !L'.
2021-04-18 00:11:18 +02:00
Rangi
750e93be3d
Further simplify formatting code
...
- Remove redundant length checks before `memcpy`
- Coerce `sign` and `prefix` to boolean for `numLen`
2021-04-17 01:11:11 -04:00
Rangi
503c3b5364
Revert "Fix interpolation/STRFMT overflow issues"
...
This reverts commit 992be3fd9b .
2021-04-16 22:19:37 -04:00
Rangi
992be3fd9b
Fix interpolation/STRFMT overflow issues
...
Widths and fractional widths greater than 255 would overflow a
uint8_t and wrap around to smaller values.
Total formatted lengths greater than the avilable buffer size
would overflow it and potentially corrupt memory.
Fixes #830
Closes #831
2021-04-16 22:00:17 -04:00
Rangi
c755fa3469
readIdentifier does not process characters that get truncated
...
Previously a '.' could be past the truncation limit but still
cause the identifier to be marked as local, violating an
assertion in `sym_AddLocalLabel`.
Fixes #832
2021-04-16 21:15:01 -04:00
Rangi
e78a1d5bfd
readInterpolation is limited by nMaxRecursionDepth
...
Fixes #837
2021-04-16 16:10:46 -04:00
Rangi
d2f6def2eb
Remove unused function hash_ReplaceElement
2021-04-16 12:36:45 -04:00
Rangi
6be3584467
LexerState's 'size' and 'offset' for mmapped files are unsigned
...
These were using signed 'off_t' because that is the type of
'st_size' from 'stat()', but neither one can be negative.
2021-04-16 10:23:37 +02:00
Rangi
8c90d9d2d7
Get rid of skip in struct Expansion
...
This was only used to skip the two macro arg characters,
but shiftChar() can skip them before the expansion.
2021-04-16 10:23:37 +02:00
Rangi
f69e666b00
expansionOfs cannot be negative
...
lexerState->expansionOfs is always either set to 0, or updated by
adding a positive quantity:
if (distance > lexerState->expansions->distance) {
lexerState->expansionOfs += distance - lexerState->expansions->distance;
...
}
so it will always be positive or zero.
2021-04-16 10:23:37 +02:00
Rangi
eba06404f0
peek(0) => peek()
...
This does not completely refactor `peek` as #708 suggested,
to make it shift and cache a character itself. However it
does simplify the lexer code.
2021-04-16 10:23:37 +02:00
Rangi
9558ccea1b
shiftChars(1) => shiftChar()
...
Only two sites were for distances greater than 1:
a `shiftChars(2)`, trivial to just do two `shiftChar()`s;
and `shiftChars(size)` in `reportGarbageChar`, which
can be a `for` loop, and should be fixed anyway to
"avoid having to peek further than 0".
2021-04-16 10:23:37 +02:00
Rangi
260d372acd
Lex $ff00+c without needing large peek lookahead
...
This also allows arbitrary amounts of whitespace in `$ff00 + c`,
instead of needing to fit in the 42-byte LEXER_BUF_SIZE
2021-04-16 10:23:37 +02:00
Rangi
4e1b0ce793
Rephrase CONTRIBUTING.rst
...
Fix #729
2021-04-14 21:19:54 -04:00
Rangi
363ee9578c
Document the release process in RELEASE.rst
...
Fix #718
2021-04-14 21:13:37 -04:00
Rangi
8fa5a4255e
Mention alternative mnemonics in gbz80(7)
...
Fixes #819
2021-04-14 16:59:31 -04:00
Rangi
b3312886fb
Use a lookupExpansion, but not as an X macro
...
Instead of defining `LOOKUP_PRE_NEST` and `LOOKUP_POST_NEST`,
pass a variable name and a block to `lookupExpansion`; it
will assign successive looked-up expansions to the variable
and use them in the block.
The technique of using `__VA_ARGS__` to allow commas within a
block passed to a macro is not original, and should be stable.
2021-04-13 17:58:46 +02:00
Rangi
7fc8a65d0a
Refactor the lexer to not use the lookupExpansion X macro
...
This macro was only used twice, in `beginExpansion` and
`lexer_DumpStringExpansions`, with `getExpansionAtDistance`
already containing an inlined and slightly modified version
of `lookupExpansion` (retaining the `LOOKUP_PRE_NEST` and
`LOOKUP_POST_NEST` macros, but with both of them doing nothing).
Not using an X macro here makes the actual control flow in both
places more obvious, and I think the repeated code is acceptable
for the same reasons as the similar-but-distinct implementations
of `readString`, `appendStringLiteral`, `yylex_NORMAL`, and
`yylex_RAW`.
2021-04-13 17:58:46 +02:00
Rangi
c278a361da
Remove the unused calchash djb2 hash function
...
Note that hashmap.c uses its own FNV-1a hash function
2021-04-13 17:41:12 +02:00
Rangi
a2f52867ad
Rename print to printChar
...
This clarifies its usage, for printing a single character
in error messages.
2021-04-13 17:41:12 +02:00
Rangi
ab79e6bede
Change how print(c) formats reported characters
...
Printable ASCII becomes single-quoted, using backslash
escapes if necessary. Unprintable characters use 0xNN
formatting, without quotes.
2021-04-13 17:41:12 +02:00
Rangi
850c78aaf4
Report garbage chars as their bytes; don't try decoding them as UTF-8
...
This decoding required high lookahead, and was not even
consistently useful (the `garbage_char` test case was not
valid UTF-8 and so did not benefit from `reportGarbageChar`).
This limits UTF-8 handling to the `STRLEN` and `STRSUB`
built-in functions, and to charmap conversion.
2021-04-13 17:41:12 +02:00
Rangi
c08cf783c8
Remove 'inline' from functions not in headers
2021-04-13 10:27:08 -04:00
Rangi
25a8518fbf
Remove unused function removeLeadingZeros
2021-04-13 10:12:40 -04:00
Rangi
49174f4486
Define the UTC time components as EQU, not EQUS
...
Fixes #827
2021-04-13 10:11:21 -04:00
Rangi
81327b0d99
Merge branch 'master' of https://github.com/gbdev/rgbds
2021-04-13 09:31:35 -04:00
Rangi
c0859e64f7
fstk_FindFile checks for sprintf failure
2021-04-13 09:31:05 -04:00
Rangi
3e0b7d428f
Fix an unclosed file and unfreed memory in out_BinaryFileSlice
...
Use 'goto cleanup' in both out_BinaryFileSlice and out_BinaryFile
2021-04-13 09:19:59 -04:00
Rangi
bcb78f5d18
Define __RGBDS_VERSION__ as the output of rgbasm --version (sans "rgbasm")
...
Fixes #824
2021-04-09 19:42:48 +02:00
Rangi
310d34c655
Comment on REG_SP and REG_AF both being 3
...
No instruction needs to distinguish them both
2021-03-31 18:41:42 -04:00
Rangi
39c38f9838
Add a test case for unattainable SECTION UNION alignment
...
This test cases used to fail an assertion in `make develop`
2021-03-31 16:09:52 -04:00
Rangi
576b063519
Fix unattainable alignments to address 0
...
Fixes #818
2021-03-31 16:06:15 -04:00
Rangi
596e17ee61
Factor out a common strlen into beginExpansion
...
This avoids the possibility of `size` not matching `str`
2021-03-31 14:41:38 -04:00
Rangi
363b3d0134
Flush stdout after PRINTLN
...
This allows debug PRINTLN statements to run even if
subsequent rgbasm directives cause a crash.
2021-03-31 11:22:41 -04:00
Rangi
c7ed9a275e
Do not expand empty strings
...
Fixes #813
2021-03-31 10:21:04 -04:00
Rangi
49aac2961d
Warn about backwards FOR loops with -Wbackwards-for (-Wall)
...
Fixes #816
2021-03-31 10:00:21 -04:00
Rangi
3741bd4617
Speed up the div-mod test case
...
Test various explicit cases, not nested `for` loops
over thousands of cases
2021-03-31 09:37:23 -04:00
Rangi
61a9bfd33c
Some tests use the new macro <name> syntax
...
This happens to make quine.asm shorter
2021-03-31 00:00:18 -04:00
Rangi
aaa92659ea
Require a plus sign in ld hl, sp + <e8>
...
Fixes #810
2021-03-30 13:05:21 -04:00
Rangi
be877134e5
Remove support for ld bc/de/hl/sp for ld hl, bc/de/hl/sp
...
Fixes #811
2021-03-30 13:01:49 -04:00
Rangi
d05703c692
Release 0.5.0-rc2
2021-03-28 17:15:44 -04:00
Rangi
5dbfafcc55
Update man page copyrights to 2021
2021-03-28 16:37:15 -04:00
Rangi
a265b85d9d
Report "1 error", not "1 errors", when assembly is aborted
...
This matches other such pluralized error messages
2021-03-28 15:55:32 -04:00