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
Rangi
28abf03c0a
Output USED space, not FREE space, in the .map file
...
Fixes #808
2021-03-28 15:49:44 -04:00
Rangi
7e7f92f18c
Assign section locations to all UNIONs/FRAGMENTs
...
Fixes the test case from #800
The `out.gb` output was corrected, since the two "test"
fragments have a different order in ROM than in SRAM.
It is effectively:
; ROM0[$0000], fragments ordered by size
jr Label
dw Label
db 0
; SRAM[$a000], fragments ordered by .o order
ds 1 ; db 0
ds 2 ; jr Label
Label: ; $a003
ds 2 ; dw Label
2021-03-28 15:21:17 -04:00
Rangi
17752d7094
Backslash in normal lexer mode must be a line continuation
...
Macro args were already handled by `peek`, and character escapes
do not exist outside of string literals.
This only affects the error message printed when a non-whitespace
character comes after the backslash. Instead of "Illegal character
escape '%s'", it will print "Begun line continuation, but
encountered character '%s'".
2021-03-26 13:23:05 -04:00
Rangi
aa99ed056c
Do not evaluate an untaken ELIF's condition
...
Fixes #764
2021-03-23 16:20:24 +01:00
Rangi
093631ca0b
Revise rgbasm(5) string symbol documentation
...
Clarify the differences between EQUS expansion and {interpolation}
2021-03-19 01:48:36 +01:00
Rangi
7e127a4e52
Don't expand string symbols in MACRO and FOR symbol names
...
Explicit {interpolation} can still achieve this, but
to match DEF, REDEF, and PURGE, these new directives that
define symbols do not expand string EQUS.
2021-03-19 01:48:36 +01:00
Rangi
b8093847dc
New definition syntax with leading DEF keyword
...
This will enable fixing #457 later once the old
definition syntax is removed.
2021-03-19 01:48:36 +01:00
Rangi
8d1b56bcf5
rgblink identifies patches' PC sections after reading all sections
...
Fixes #794
2021-03-18 23:53:54 +01:00
Rangi
ee900ae7a3
Add a missing newline to a verbosePrint
2021-03-17 20:53:25 -04:00
Rangi
88646093ca
Swap the Name and Type columns in Predeclared Symbols
2021-03-05 17:00:06 -05:00
Rangi
88048cdcd7
Clarify the character encoding example in rgbasm.5
2021-03-05 10:08:43 -05:00
Rangi
8a75cc5051
Test an indented anonymous label
2021-03-03 12:26:35 -05:00
Rangi
b674c5fcaa
Comment refers to "built-in" symbols
2021-03-03 10:35:47 -05:00
Rangi
365484ef18
Factor out handleCRLF()
...
This logic repeats ten times
2021-03-03 10:03:52 +01:00
Rangi
5e2bd35239
Factor out a 'plain_directive' parser rule similar to the reverted 'last_line'
...
Also expand on the comment explaining how the EOF-newline hack affects the parser
2021-03-02 20:46:17 -05:00
Rangi
6655e04ef0
Restore the "EOF-newline" lexer hack
...
This was removed in b3c0db218d
(along with two unrelated changes).
Removing this hack introduced issue #742 , whereby INCLUDing
a file without a trailing newline can cause a syntax error.
A more proper fix would involve Bison's tracking locations,
but for now the EOF-newline hack fixes the issue while only
affecting some reported errors (expecting "newline"
instead of "end of file").
Fixes #742
2021-03-02 16:53:56 -08:00
Rangi
56071599e7
Allow trailing commas in bare lists
...
This applies to macro arguments, DB, DW, DL, DS,
PRINT, PRINTLN, EXPORT, PURGE, and OPT.
It also removes support for empty entries in DB/DW/DL.
(Deprecating it would require keeping parser support,
which is ambiguous with trailing commas.)
Fixes #753
2021-03-02 11:48:20 +01:00
Rangi
c637447d5d
Make the "db/dw/dl directive without data in ROM" warning more specific
...
Also use uppercase for DB/DW/DL to be consistent
2021-03-02 11:48:20 +01:00
Rangi
ac2cefdd87
Refactor some math functions into a shared file for rgbasm and rgblink
...
Fixes #769
Fixes #770
2021-03-02 11:40:03 +01:00
Rangi
0774f5eb9d
Rename math.c/mymath.h to fixpoint.c/.h
...
This also changes the functions' prefix
from "math_" to "fix_".
2021-03-02 11:40:03 +01:00
Rangi
76d8862900
Refactor part of getSection into createSection
...
getSection validates its parameters and calls
either mergeSections or createSection.
2021-02-28 16:12:03 -05:00
Rangi
1dafc1c762
Allow empty macro arguments, with a warning
...
Fixes #739
2021-02-28 10:38:49 -08:00
Rangi
63d15ac8c9
append_yylval_tzString should always evaluate its argument
...
Fixes #762
2021-02-28 10:38:49 -08:00
Rangi
1f579deaff
Trim right whitespace from macro args before warning about length
2021-02-28 10:38:49 -08:00
Rangi
fad48326f8
Support /* block comments */ in macro arguments
...
Fixes #746
2021-02-28 10:38:49 -08:00
Rangi
953f79c0d9
Support 'MACRO mac' as well as 'mac: MACRO' for defining macros
...
The new syntax is used in documentation, but
the old syntax is not yet deprecated.
2021-02-25 04:42:35 +01:00
Rangi
3c5e1caa7c
Disallow "." as a local label
...
Fixes #760
2021-02-25 04:40:42 +01:00
Rangi
d4028fff10
Prevent ELIF or ELSE after an ELSE
...
Fixes #749
2021-02-25 04:39:49 +01:00
Rangi
dd892d61d8
Correct rgbasm(5) about whitespace before labels
...
Also rephrase some more label-related documentation
2021-02-23 15:31:29 -05:00
Rangi
a09f2d4115
Test an indented macro label
2021-02-23 14:48:27 -05:00
Rangi
037bc7abb3
Add an rgblink test case for an $8000-byte ROM0 section with -t
2021-02-21 16:30:02 -05:00
Rangi
39c179aa32
Fix missing newline in a dbgPrint
2021-02-17 13:14:02 -05:00
Rangi
5c1ae4ce22
Shorter quine test cases
2021-02-17 11:51:21 -05:00
Rangi
efbfeca292
Avoid two peek(1) calls when lexing """multi-line strings"""
2021-02-17 10:36:36 -05:00
Rangi
7dd34f1572
Format INT32_MIN as '-2147483648', not '--2147483648'
2021-02-17 09:48:40 -05:00