diff --git a/src/asm/output.cpp b/src/asm/output.cpp index b67bda0c..e217c41b 100644 --- a/src/asm/output.cpp +++ b/src/asm/output.cpp @@ -130,9 +130,8 @@ void out_RegisterNode(struct FileStackNode *node) } } -void out_ReplaceNode(struct FileStackNode *node) +void out_ReplaceNode(struct FileStackNode * /* node */) { - (void)node; #if 0 This is code intended to replace a node, which is pretty useless until ref counting is added... @@ -469,10 +468,8 @@ static void writeFileStackNode(struct FileStackNode const *node, FILE *f) } } -static void registerUnregisteredSymbol(struct Symbol *symbol, void *arg) +static void registerUnregisteredSymbol(struct Symbol *symbol, void *) { - (void)arg; // sym_ForEach requires a void* parameter, but we are not using it. - // Check for symbol->src, to skip any built-in symbol from rgbasm if (symbol->src && symbol->ID == (uint32_t)-1) { registerSymbol(symbol); diff --git a/src/asm/parser.y b/src/asm/parser.y index 4bcc7798..a28bfb44 100644 --- a/src/asm/parser.y +++ b/src/asm/parser.y @@ -1021,6 +1021,7 @@ align : T_OP_ALIGN align_spec { sect_AlignPC($2.alignment, $2.alignOfs); } align_spec : uconst { if ($1 > 16) { error("Alignment must be between 0 and 16, not %u\n", $1); + $$.alignment = $$.alignOfs = 0; } else { $$.alignment = $1; $$.alignOfs = 0; @@ -1029,10 +1030,12 @@ align_spec : uconst { | uconst T_COMMA const { if ($1 > 16) { error("Alignment must be between 0 and 16, not %u\n", $1); + $$.alignment = $$.alignOfs = 0; } else if ($3 <= -(1 << $1) || $3 >= 1 << $1) { error("The absolute alignment offset (%" PRIu32 ") must be less than alignment size (%d)\n", (uint32_t)($3 < 0 ? -$3 : $3), 1 << $1); + $$.alignment = $$.alignOfs = 0; } else { $$.alignment = $1; $$.alignOfs = $3 < 0 ? (1 << $1) + $3 : $3; diff --git a/src/asm/rpn.cpp b/src/asm/rpn.cpp index ea2faf3d..f07f4dba 100644 --- a/src/asm/rpn.cpp +++ b/src/asm/rpn.cpp @@ -512,10 +512,7 @@ void rpn_BinaryOp(enum RPNCommand op, struct Expression *expr, if (src2->val < 0) fatalerror("Exponentiation by negative power\n"); - if (src1->val == INT32_MIN && src2->val == -1) - expr->val = 0; - else - expr->val = op_exponent(src1->val, src2->val); + expr->val = op_exponent(src1->val, src2->val); break; case RPN_NEG: diff --git a/src/asm/section.cpp b/src/asm/section.cpp index 88624b66..aaa3e848 100644 --- a/src/asm/section.cpp +++ b/src/asm/section.cpp @@ -167,10 +167,9 @@ static unsigned int mergeSectUnion(struct Section *sect, enum SectionType type, return nbSectErrors; } -static unsigned int mergeFragments(struct Section *sect, enum SectionType type, uint32_t org, - uint8_t alignment, uint16_t alignOffset) +static unsigned int mergeFragments(struct Section *sect, uint32_t org, uint8_t alignment, + uint16_t alignOffset) { - (void)type; assert(alignment < 16); // Should be ensured by the caller unsigned int nbSectErrors = 0; @@ -183,8 +182,7 @@ static unsigned int mergeFragments(struct Section *sect, enum SectionType type, // If both are fixed, they must be the same if (sect->org != (uint32_t)-1 && sect->org != curOrg) fail("Section already declared as fixed at incompatible address $%04" - PRIx32 " (cur addr = %04" PRIx32 ")\n", - sect->org, sect->org + sect->size); + PRIx32 "\n", sect->org); else if (sect->align != 0 && (mask(sect->align) & (curOrg - sect->alignOfs))) fail("Section already declared as aligned to %u bytes (offset %" PRIu16 ")\n", 1U << sect->align, sect->alignOfs); @@ -232,8 +230,9 @@ static void mergeSections(struct Section *sect, enum SectionType type, uint32_t switch (mod) { case SECTION_UNION: case SECTION_FRAGMENT: - nbSectErrors += (mod == SECTION_UNION ? mergeSectUnion : mergeFragments) - (sect, type, org, alignment, alignOffset); + nbSectErrors += mod == SECTION_UNION ? + mergeSectUnion(sect, type, org, alignment, alignOffset) : + mergeFragments(sect, org, alignment, alignOffset); // Common checks @@ -499,7 +498,7 @@ void sect_AlignPC(uint8_t alignment, uint16_t offset) return; struct Section *sect = sect_GetSymbolSection(); - uint16_t alignSize = 1 << alignment; // Size of an aligned "block" + uint32_t alignSize = 1 << alignment; // Size of an aligned "block" if (sect->org != (uint32_t)-1) { if ((sect->org + curOffset - offset) % alignSize) diff --git a/src/link/assign.cpp b/src/link/assign.cpp index 621d2e06..d9657c6f 100644 --- a/src/link/assign.cpp +++ b/src/link/assign.cpp @@ -328,9 +328,8 @@ static struct UnassignedSection *sections; * @param section The section to categorize * @param arg Callback arg, unused */ -static void categorizeSection(struct Section *section, void *arg) +static void categorizeSection(struct Section *section, void *) { - (void)arg; uint8_t constraints = 0; if (section->isBankFixed) diff --git a/src/link/main.cpp b/src/link/main.cpp index 2a0abb90..6b5753e2 100644 --- a/src/link/main.cpp +++ b/src/link/main.cpp @@ -406,7 +406,6 @@ int main(int argc, char *argv[]) break; case 's': // TODO: implement "smart linking" with `-s` - (void)musl_optarg; warning(NULL, 0, "Nobody has any idea what `-s` does"); break; case 't': diff --git a/src/link/object.cpp b/src/link/object.cpp index 2c801de8..d94c377e 100644 --- a/src/link/object.cpp +++ b/src/link/object.cpp @@ -669,10 +669,8 @@ static void freeNode(struct FileStackNode *node) free(node->name); } -static void freeSection(struct Section *section, void *arg) +static void freeSection(struct Section *section, void *) { - (void)arg; - do { struct Section *next = section->nextu; diff --git a/src/link/patch.cpp b/src/link/patch.cpp index 7627210f..d028acda 100644 --- a/src/link/patch.cpp +++ b/src/link/patch.cpp @@ -502,8 +502,8 @@ void patch_CheckAssertions(struct Assertion *assert) /* * Applies all of a section's patches - * @param section The section to patch - * @param arg Ignored callback arg + * @param section The section component to patch + * @param dataSection The section to patch */ static void applyFilePatches(struct Section *section, struct Section *dataSection) { @@ -554,23 +554,17 @@ static void applyFilePatches(struct Section *section, struct Section *dataSectio } /* - * Applies all of a section's patches, iterating over "components" of - * unionized sections + * Applies all of a section's patches, iterating over "components" of unionized sections * @param section The section to patch * @param arg Ignored callback arg */ -static void applyPatches(struct Section *section, void *arg) +static void applyPatches(struct Section *section, void *) { if (!sect_HasData(section->type)) return; - (void)arg; - struct Section *dataSection = section; - - do { - applyFilePatches(section, dataSection); - section = section->nextu; - } while (section); + for (struct Section *component = section; component; component = component->nextu) + applyFilePatches(component, section); } void patch_ApplyPatches(void) diff --git a/src/link/section.cpp b/src/link/section.cpp index 12a85401..3308f9b0 100644 --- a/src/link/section.cpp +++ b/src/link/section.cpp @@ -219,10 +219,8 @@ void sect_CleanupSections(void) hash_EmptyMap(sections); } -static void doSanityChecks(struct Section *section, void *ptr) +static void doSanityChecks(struct Section *section, void *) { - (void)ptr; - // Sanity check the section's type if (section->type < 0 || section->type >= SECTTYPE_INVALID) { diff --git a/test/asm/anon-label-bad.asm b/test/asm/anon-label-bad.asm index 4e37519c..d76aeeb4 100644 --- a/test/asm/anon-label-bad.asm +++ b/test/asm/anon-label-bad.asm @@ -5,6 +5,10 @@ SECTION "Anonymous label errors test", ROM0 db :-- ; Reference goes too far back + : ; Can't EXPORT or PURGE anonymous labels + EXPORT :- + PURGE :- + ; Uncomment this if you're a badass with a *lot* of RAM ; REPT 2147483647 ; : diff --git a/test/asm/anon-label-bad.err b/test/asm/anon-label-bad.err index 9c85f37c..bd16a1d5 100644 --- a/test/asm/anon-label-bad.err +++ b/test/asm/anon-label-bad.err @@ -2,6 +2,10 @@ error: anon-label-bad.asm(2): Label "!0" created outside of a SECTION error: anon-label-bad.asm(6): Reference to anonymous label 2 before, when only 1 has been created so far -error: anon-label-bad.asm(18): +error: anon-label-bad.asm(9): + syntax error, unexpected anonymous label, expecting label or identifier or local identifier +error: anon-label-bad.asm(10): + syntax error, unexpected anonymous label, expecting label or identifier or local identifier +error: anon-label-bad.asm(22): syntax error, unexpected :: -error: Assembly aborted (3 errors)! +error: Assembly aborted (5 errors)! diff --git a/test/asm/anon-label-bad.simple.err b/test/asm/anon-label-bad.simple.err index 6cdd160c..87274794 100644 --- a/test/asm/anon-label-bad.simple.err +++ b/test/asm/anon-label-bad.simple.err @@ -2,6 +2,10 @@ error: anon-label-bad.asm(2): Label "!0" created outside of a SECTION error: anon-label-bad.asm(6): Reference to anonymous label 2 before, when only 1 has been created so far -error: anon-label-bad.asm(18): +error: anon-label-bad.asm(9): syntax error -error: Assembly aborted (3 errors)! +error: anon-label-bad.asm(10): + syntax error +error: anon-label-bad.asm(22): + syntax error +error: Assembly aborted (5 errors)! diff --git a/test/asm/bank.asm b/test/asm/bank.asm index 7b859ae6..8a170ac2 100644 --- a/test/asm/bank.asm +++ b/test/asm/bank.asm @@ -4,12 +4,14 @@ macro def_sect ELSE SECTION "\1", \2, BANK[\3] ENDC - - PRINTLN BANK("\1") + Label\@:: + PRINTLN "\1 (\2): ", BANK("\1"), " == ", BANK(Label\@) endm - def_sect ROM0_ok, ROM0 - def_sect ROMX_ok, ROMX, 42 + def_sect ROM0_ok1, ROM0 + def_sect ROM0_ok2, ROM0[$2000] + def_sect ROMX_ok1, ROMX[$4567] + def_sect ROMX_ok2, ROMX, 42 def_sect ROMX_bad, ROMX def_sect VRAM_ok, VRAM, 1 def_sect VRAM_bad, VRAM @@ -20,3 +22,5 @@ endm def_sect WRAMX_bad,WRAMX def_sect OAM_ok, OAM def_sect HRAM_ok, HRAM + + PRINTLN "def_sect: ", BANK(def_sect) ; not a label diff --git a/test/asm/bank.err b/test/asm/bank.err index 9eadde82..ef111113 100644 --- a/test/asm/bank.err +++ b/test/asm/bank.err @@ -1,9 +1,23 @@ error: bank.asm(13) -> bank.asm::def_sect(8): + Expected constant expression: Section "ROMX_ok1"'s bank is not known +error: bank.asm(13) -> bank.asm::def_sect(8): + Expected constant expression: "Label_u3"'s bank is not known +error: bank.asm(15) -> bank.asm::def_sect(8): Expected constant expression: Section "ROMX_bad"'s bank is not known error: bank.asm(15) -> bank.asm::def_sect(8): + Expected constant expression: "Label_u5"'s bank is not known +error: bank.asm(17) -> bank.asm::def_sect(8): Expected constant expression: Section "VRAM_bad"'s bank is not known error: bank.asm(17) -> bank.asm::def_sect(8): + Expected constant expression: "Label_u7"'s bank is not known +error: bank.asm(19) -> bank.asm::def_sect(8): Expected constant expression: Section "SRAM_bad"'s bank is not known -error: bank.asm(20) -> bank.asm::def_sect(8): +error: bank.asm(19) -> bank.asm::def_sect(8): + Expected constant expression: "Label_u9"'s bank is not known +error: bank.asm(22) -> bank.asm::def_sect(8): Expected constant expression: Section "WRAMX_bad"'s bank is not known -error: Assembly aborted (4 errors)! +error: bank.asm(22) -> bank.asm::def_sect(8): + Expected constant expression: "Label_u12"'s bank is not known +error: bank.asm(26): + BANK argument must be a label +error: Assembly aborted (11 errors)! diff --git a/test/asm/bank.out b/test/asm/bank.out index affd9464..c1a51888 100644 --- a/test/asm/bank.out +++ b/test/asm/bank.out @@ -1,12 +1,15 @@ -$0 -$2A -$0 -$1 -$0 -$4 -$0 -$0 -$7 -$0 -$0 -$0 +ROM0_ok1 (ROM0): $0 == $0 +ROM0_ok2 (ROM0[$2000]): $0 == $0 +ROMX_ok1 (ROMX[$4567]): $0 == $0 +ROMX_ok2 (ROMX): $2A == $2A +ROMX_bad (ROMX): $0 == $0 +VRAM_ok (VRAM): $1 == $1 +VRAM_bad (VRAM): $0 == $0 +SRAM_ok (SRAM): $4 == $4 +SRAM_bad (SRAM): $0 == $0 +WRAM0_ok (WRAM0): $0 == $0 +WRAMX_ok (WRAMX): $7 == $7 +WRAMX_bad (WRAMX): $0 == $0 +OAM_ok (OAM): $0 == $0 +HRAM_ok (HRAM): $0 == $0 +def_sect: $4B4E4142 diff --git a/test/asm/bracketed-macro-args.asm b/test/asm/bracketed-macro-args.asm index bbbd9d7e..95ccc6dc 100644 --- a/test/asm/bracketed-macro-args.asm +++ b/test/asm/bracketed-macro-args.asm @@ -17,3 +17,23 @@ MACRO mac ENDM mac 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 1 + + def nonnumeric equs "1" + def zero equ 0 + def two equ 2 + +MACRO bad + println "nonnumeric", \ + println "zero", \ + println "undefined", \ + println "two", \ + println "2", \<2> +ENDM + + bad 42 + +MACRO toolong + println \ +ENDM + + toolong 42 diff --git a/test/asm/bracketed-macro-args.err b/test/asm/bracketed-macro-args.err new file mode 100644 index 00000000..a7dd5f2c --- /dev/null +++ b/test/asm/bracketed-macro-args.err @@ -0,0 +1,15 @@ +error: bracketed-macro-args.asm(33) -> bracketed-macro-args.asm::bad(26): + Bracketed symbol "nonnumeric" is not numeric +error: bracketed-macro-args.asm(33) -> bracketed-macro-args.asm::bad(27): + Invalid bracketed macro argument '\<0>' +error: bracketed-macro-args.asm(33) -> bracketed-macro-args.asm::bad(28): + Bracketed symbol "undefined" does not exist +error: bracketed-macro-args.asm(33) -> bracketed-macro-args.asm::bad(29): + Macro argument '\<2>' not defined +error: bracketed-macro-args.asm(33) -> bracketed-macro-args.asm::bad(30): + Macro argument '\<2>' not defined +warning: bracketed-macro-args.asm(39) -> bracketed-macro-args.asm::toolong(36): [-Wlong-string] + Bracketed symbol name too long +error: bracketed-macro-args.asm(39) -> bracketed-macro-args.asm::toolong(36): + Bracketed symbol "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstu" does not exist +error: Assembly aborted (6 errors)! diff --git a/test/asm/bracketed-macro-args.out b/test/asm/bracketed-macro-args.out index 0d4ff09c..8d800ac4 100644 --- a/test/asm/bracketed-macro-args.out +++ b/test/asm/bracketed-macro-args.out @@ -5,3 +5,9 @@ last = D $F0 $F0 $F0 +nonnumeric +zero +undefined +two +2 + diff --git a/test/asm/break.asm b/test/asm/break.asm index 47f5ee07..d93b422a 100644 --- a/test/asm/break.asm +++ b/test/asm/break.asm @@ -15,6 +15,7 @@ macro elif invalid endr warn "OK" +break ; not in a rept/for rept 1 if 1 break diff --git a/test/asm/break.err b/test/asm/break.err index 2cbec5d6..e9a961a8 100644 --- a/test/asm/break.err +++ b/test/asm/break.err @@ -2,5 +2,7 @@ warning: break.asm(9): [-Wuser] done 5 warning: break.asm(17): [-Wuser] OK -FATAL: break.asm(18) -> break.asm::REPT~1(22): +error: break.asm(18): + BREAK can only be used inside a REPT/FOR block +FATAL: break.asm(19) -> break.asm::REPT~1(23): Ended block with 1 unterminated IF construct diff --git a/test/asm/character-escapes.asm b/test/asm/character-escapes.asm new file mode 100644 index 00000000..e5e7b098 --- /dev/null +++ b/test/asm/character-escapes.asm @@ -0,0 +1,10 @@ +MACRO m + DEF S EQUS \1 + println "{S}" + println \1 + println "illegal character \ +escape \z?" + println "invalid character \<\n>?" + println """invalid character \< >?""" +ENDM + m "(\n \r \t)" diff --git a/test/asm/character-escapes.err b/test/asm/character-escapes.err new file mode 100644 index 00000000..536b1af3 --- /dev/null +++ b/test/asm/character-escapes.err @@ -0,0 +1,7 @@ +error: character-escapes.asm(10) -> character-escapes.asm::m(6): + Illegal character escape 'z' +error: character-escapes.asm(10) -> character-escapes.asm::m(7): + Invalid character in bracketed macro argument '\' +error: character-escapes.asm(10) -> character-escapes.asm::m(8): + Invalid character in bracketed macro argument '\t' +error: Assembly aborted (3 errors)! diff --git a/test/asm/character-escapes.out b/test/asm/character-escapes.out new file mode 100644 index 00000000..a8d6e32a --- /dev/null +++ b/test/asm/character-escapes.out @@ -0,0 +1,7 @@ +( + ) +( + ) +illegal character escape z? +invalid character n>? +invalid character >? diff --git a/test/asm/crlf.asm b/test/asm/crlf.asm index 29d41be0..ea07f197 100644 --- a/test/asm/crlf.asm +++ b/test/asm/crlf.asm @@ -4,6 +4,10 @@ DEF s EQUS "Hello, \ world!" assert !strcmp("{s}", "Hello, world!") +/* + * block comment + */ + DEF t EQUS """Hello, world!""" assert !strcmp("{t}", "Hello,\nworld!") diff --git a/test/asm/data-in-ram.asm b/test/asm/data-in-ram.asm new file mode 100644 index 00000000..2873a967 --- /dev/null +++ b/test/asm/data-in-ram.asm @@ -0,0 +1,4 @@ +SECTION "code", WRAM0 + xor a +SECTION "data", WRAMX + db 42 diff --git a/test/asm/data-in-ram.err b/test/asm/data-in-ram.err new file mode 100644 index 00000000..b3bb9d81 --- /dev/null +++ b/test/asm/data-in-ram.err @@ -0,0 +1,5 @@ +error: data-in-ram.asm(2): + Section 'code' cannot contain code or data (not ROM0 or ROMX) +error: data-in-ram.asm(4): + Section 'data' cannot contain code or data (not ROM0 or ROMX) +error: Assembly aborted (2 errors)! diff --git a/test/asm/ds-byte.asm b/test/asm/ds-byte.asm index d612ab60..46284947 100644 --- a/test/asm/ds-byte.asm +++ b/test/asm/ds-byte.asm @@ -7,3 +7,4 @@ Label: ds 60, .last - Label ; ...even if not constant .last ds 11, $67, $89 + ds 2, !Label, ~Label diff --git a/test/asm/ds-byte.out.bin b/test/asm/ds-byte.out.bin index 94880523..1572cfd0 100644 --- a/test/asm/ds-byte.out.bin +++ b/test/asm/ds-byte.out.bin @@ -1 +1 @@ -****˙˙˙˙˙EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEg‰g‰g‰g‰g‰g \ No newline at end of file +****˙˙˙˙˙EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEg‰g‰g‰g‰g‰g˙ \ No newline at end of file diff --git a/test/asm/endc-outside-if.asm b/test/asm/endc-outside-if.asm new file mode 100644 index 00000000..55fa4b3a --- /dev/null +++ b/test/asm/endc-outside-if.asm @@ -0,0 +1 @@ +ENDC diff --git a/test/asm/endc-outside-if.err b/test/asm/endc-outside-if.err new file mode 100644 index 00000000..274d8d6e --- /dev/null +++ b/test/asm/endc-outside-if.err @@ -0,0 +1,2 @@ +FATAL: endc-outside-if.asm(1): + Found ENDC outside an IF construct diff --git a/test/asm/endsection-in-load.asm b/test/asm/endsection-in-load.asm new file mode 100644 index 00000000..06eb1edc --- /dev/null +++ b/test/asm/endsection-in-load.asm @@ -0,0 +1,4 @@ +SECTION "test", ROM0 +LOAD "ram", WRAM0 +ENDSECTION +ENDL diff --git a/test/asm/endsection-in-load.err b/test/asm/endsection-in-load.err new file mode 100644 index 00000000..696beea1 --- /dev/null +++ b/test/asm/endsection-in-load.err @@ -0,0 +1,2 @@ +FATAL: endsection-in-load.asm(3): + Cannot end the section within a `LOAD` block diff --git a/test/asm/endsection-in-union.asm b/test/asm/endsection-in-union.asm new file mode 100644 index 00000000..05db665e --- /dev/null +++ b/test/asm/endsection-in-union.asm @@ -0,0 +1,4 @@ +SECTION "test", WRAM0 +UNION +ENDSECTION +ENDU diff --git a/test/asm/endsection-in-union.err b/test/asm/endsection-in-union.err new file mode 100644 index 00000000..4bda1f17 --- /dev/null +++ b/test/asm/endsection-in-union.err @@ -0,0 +1,2 @@ +FATAL: endsection-in-union.asm(3): + Cannot end the section within a UNION diff --git a/test/asm/endsection-outside-section.asm b/test/asm/endsection-outside-section.asm new file mode 100644 index 00000000..3deb4253 --- /dev/null +++ b/test/asm/endsection-outside-section.asm @@ -0,0 +1 @@ +ENDSECTION diff --git a/test/asm/endsection-outside-section.err b/test/asm/endsection-outside-section.err new file mode 100644 index 00000000..92d74226 --- /dev/null +++ b/test/asm/endsection-outside-section.err @@ -0,0 +1,2 @@ +FATAL: endsection-outside-section.asm(1): + Cannot end the section outside of a SECTION diff --git a/test/asm/fragment-mismatch.asm b/test/asm/fragment-mismatch.asm new file mode 100644 index 00000000..1ba82689 --- /dev/null +++ b/test/asm/fragment-mismatch.asm @@ -0,0 +1,2 @@ +SECTION FRAGMENT "test", ROM0[0] +SECTION FRAGMENT "test", ROM0[1] diff --git a/test/asm/fragment-mismatch.err b/test/asm/fragment-mismatch.err new file mode 100644 index 00000000..a7b9e36a --- /dev/null +++ b/test/asm/fragment-mismatch.err @@ -0,0 +1,4 @@ +error: fragment-mismatch.asm(2): + Section already declared as fixed at incompatible address $0000 +FATAL: fragment-mismatch.asm(2): + Cannot create section "test" (1 error) diff --git a/test/asm/impossible-bank.asm b/test/asm/impossible-bank.asm new file mode 100644 index 00000000..0ceeedc3 --- /dev/null +++ b/test/asm/impossible-bank.asm @@ -0,0 +1 @@ +SECTION "hram", HRAM, BANK[0] diff --git a/test/asm/impossible-bank.err b/test/asm/impossible-bank.err new file mode 100644 index 00000000..60e156f5 --- /dev/null +++ b/test/asm/impossible-bank.err @@ -0,0 +1,3 @@ +error: impossible-bank.asm(1): + BANK only allowed for ROMX, WRAMX, SRAM, or VRAM sections +error: Assembly aborted (1 error)! diff --git a/test/asm/interpolation.asm b/test/asm/interpolation.asm index 028ee656..7dc9a321 100644 --- a/test/asm/interpolation.asm +++ b/test/asm/interpolation.asm @@ -13,3 +13,8 @@ PRINTLN STRCAT("{NAME}_{d:INDEX}", " is ", {NAME}_{d:INDEX}) ; Purges ITEM_100 PURGE {NAME}_{d:INDEX} ASSERT !DEF({NAME}_{d:INDEX}) + +; not string or number +MACRO foo +ENDM +PRINTLN "foo {foo}" diff --git a/test/asm/interpolation.err b/test/asm/interpolation.err new file mode 100644 index 00000000..03a5a4ee --- /dev/null +++ b/test/asm/interpolation.err @@ -0,0 +1,3 @@ +error: interpolation.asm(20): + Only numerical and string symbols can be interpolated +error: Assembly aborted (1 error)! diff --git a/test/asm/interpolation.out b/test/asm/interpolation.out index ab1deb34..a764c4f2 100644 --- a/test/asm/interpolation.out +++ b/test/asm/interpolation.out @@ -1 +1,2 @@ ITEM_100 is hundredth +foo diff --git a/test/asm/invalid-alignment.asm b/test/asm/invalid-alignment.asm new file mode 100644 index 00000000..17be76a6 --- /dev/null +++ b/test/asm/invalid-alignment.asm @@ -0,0 +1,23 @@ +; valid + +SECTION "valid", ROM0 +align 16 ; this is achievable at $0000 + +; invalid + +SECTION "invalid", ROMX[$4000] +align 16 + +SECTION "a", ROMX[$4000], ALIGN[20] + +SECTION FRAGMENT "b", ROM0[$0000], ALIGN[20] + +SECTION UNION "c", WRAM0[$c000], ALIGN[20] + +; unattainable + +SECTION "d", HRAM[$ff80], ALIGN[10] + +SECTION FRAGMENT "e", ROMX[$4000], ALIGN[15] + +SECTION UNION "f", WRAM0[$c000], ALIGN[15] diff --git a/test/asm/invalid-alignment.err b/test/asm/invalid-alignment.err new file mode 100644 index 00000000..17a8ff20 --- /dev/null +++ b/test/asm/invalid-alignment.err @@ -0,0 +1,15 @@ +error: invalid-alignment.asm(9): + Section's fixed address fails required alignment (PC = $4000) +error: invalid-alignment.asm(11): + Alignment must be between 0 and 16, not 20 +error: invalid-alignment.asm(13): + Alignment must be between 0 and 16, not 20 +error: invalid-alignment.asm(15): + Alignment must be between 0 and 16, not 20 +error: invalid-alignment.asm(19): + Section "d"'s fixed address doesn't match its alignment +error: invalid-alignment.asm(21): + Section "e"'s fixed address doesn't match its alignment +error: invalid-alignment.asm(23): + Section "f"'s fixed address doesn't match its alignment +error: Assembly aborted (7 errors)! diff --git a/test/asm/invalid-bank.asm b/test/asm/invalid-bank.asm new file mode 100644 index 00000000..7aa7610a --- /dev/null +++ b/test/asm/invalid-bank.asm @@ -0,0 +1 @@ +SECTION "vram", VRAM, BANK[2] diff --git a/test/asm/invalid-bank.err b/test/asm/invalid-bank.err new file mode 100644 index 00000000..784aee3a --- /dev/null +++ b/test/asm/invalid-bank.err @@ -0,0 +1,3 @@ +error: invalid-bank.asm(1): + VRAM bank value $0002 out of range ($0000 to $0001) +error: Assembly aborted (1 error)! diff --git a/test/asm/invalid-charsub.asm b/test/asm/invalid-charsub.asm new file mode 100644 index 00000000..52b452f3 --- /dev/null +++ b/test/asm/invalid-charsub.asm @@ -0,0 +1 @@ +DEF S EQUS CHARSUB("ABC", 4) diff --git a/test/asm/invalid-charsub.err b/test/asm/invalid-charsub.err new file mode 100644 index 00000000..ea6cb973 --- /dev/null +++ b/test/asm/invalid-charsub.err @@ -0,0 +1,2 @@ +warning: invalid-charsub.asm(1): [-Wbuiltin-args] + CHARSUB: Position 4 is past the end of the string diff --git a/test/asm/invalid-format.asm b/test/asm/invalid-format.asm new file mode 100644 index 00000000..6c5e2b5e --- /dev/null +++ b/test/asm/invalid-format.asm @@ -0,0 +1,16 @@ +println STRFMT("%+d %++d", 42, 42) +println STRFMT("%#x %##x", 42, 42) +println STRFMT("%-4d %--4d", 42, 42) +println STRFMT("%.f %..f", 42.0, 42.0) + +DEF N = 42 +println "{5d:N} {5d5:N}" +println "{x:N} {xx:N}" + +println STRFMT("%+s", "hello") +println STRFMT("%#s", "hello") +println STRFMT("%0s", "hello") +println STRFMT("%.5s", "hello") + +println STRFMT("%#d", 42) +println STRFMT("%.5d", 42) diff --git a/test/asm/invalid-format.err b/test/asm/invalid-format.err new file mode 100644 index 00000000..4433ca8d --- /dev/null +++ b/test/asm/invalid-format.err @@ -0,0 +1,25 @@ +error: invalid-format.asm(1): + STRFMT: Invalid format spec for argument 2 +error: invalid-format.asm(2): + STRFMT: Invalid format spec for argument 2 +error: invalid-format.asm(3): + STRFMT: Invalid format spec for argument 2 +error: invalid-format.asm(4): + STRFMT: Invalid format spec for argument 2 +error: invalid-format.asm(7): + Invalid format spec '5d5' +error: invalid-format.asm(8): + Invalid format spec 'xx' +error: invalid-format.asm(10): + Formatting string with sign flag '+' +error: invalid-format.asm(11): + Formatting string with prefix flag '#' +error: invalid-format.asm(12): + Formatting string with padding flag '0' +error: invalid-format.asm(13): + Formatting string with fractional width +error: invalid-format.asm(15): + Formatting type 'd' with prefix flag '#' +error: invalid-format.asm(16): + Formatting type 'd' with fractional width +error: Assembly aborted (12 errors)! diff --git a/test/asm/invalid-format.out b/test/asm/invalid-format.out new file mode 100644 index 00000000..129cbbbb --- /dev/null +++ b/test/asm/invalid-format.out @@ -0,0 +1,12 @@ ++42 %d +$2a %x +42 %4d +42 %f + 42 42 +2a 2a +hello +hello +hello +hello +42 +42 diff --git a/test/asm/invalid-jr.asm b/test/asm/invalid-jr.asm new file mode 100644 index 00000000..c57c888e --- /dev/null +++ b/test/asm/invalid-jr.asm @@ -0,0 +1,3 @@ +SECTION "test", ROM0 +Label: ds 256 +jr Label diff --git a/test/asm/invalid-jr.err b/test/asm/invalid-jr.err new file mode 100644 index 00000000..86bb8af0 --- /dev/null +++ b/test/asm/invalid-jr.err @@ -0,0 +1,3 @@ +error: invalid-jr.asm(3): + jr target out of reach (expected -129 < -258 < 128) +error: Assembly aborted (1 error)! diff --git a/test/asm/invalid-opt.asm b/test/asm/invalid-opt.asm new file mode 100644 index 00000000..f57272dc --- /dev/null +++ b/test/asm/invalid-opt.asm @@ -0,0 +1,6 @@ +opt b123 +opt g12345 +opt p1234 +opt Q1234 +opt Q32 +opt W diff --git a/test/asm/invalid-opt.err b/test/asm/invalid-opt.err new file mode 100644 index 00000000..6263a3db --- /dev/null +++ b/test/asm/invalid-opt.err @@ -0,0 +1,13 @@ +error: invalid-opt.asm(1): + Must specify exactly 2 characters for option 'b' +error: invalid-opt.asm(2): + Must specify exactly 4 characters for option 'g' +error: invalid-opt.asm(3): + Invalid argument for option 'p' +error: invalid-opt.asm(4): + Invalid argument for option 'Q' +error: invalid-opt.asm(5): + Argument for option 'Q' must be between 1 and 31 +error: invalid-opt.asm(6): + Must specify an argument for option 'W' +error: Assembly aborted (6 errors)! diff --git a/test/asm/invalid-union.asm b/test/asm/invalid-union.asm new file mode 100644 index 00000000..4a8b9379 --- /dev/null +++ b/test/asm/invalid-union.asm @@ -0,0 +1,6 @@ +ENDU ; outside UNION +NEXTU ; outside UNION +UNION ; outside SECTION + +SECTION "test", WRAM0 +UNION ; no ENDU diff --git a/test/asm/invalid-union.err b/test/asm/invalid-union.err new file mode 100644 index 00000000..afd00a5c --- /dev/null +++ b/test/asm/invalid-union.err @@ -0,0 +1,9 @@ +error: invalid-union.asm(1): + Found ENDU outside of a UNION construct +error: invalid-union.asm(2): + Found NEXTU outside of a UNION construct +error: invalid-union.asm(3): + UNIONs must be inside a SECTION +error: invalid-union.asm(7): + Unterminated UNION construct +error: Assembly aborted (4 errors)! diff --git a/test/asm/line-continuation.asm b/test/asm/line-continuation.asm index 4fccf54f..d851dbae 100644 --- a/test/asm/line-continuation.asm +++ b/test/asm/line-continuation.asm @@ -1,3 +1,10 @@ +; Test text after \ line continuation + +MACRO \ spam + WARN "spam" +ENDM + spam ; The macro was defined despite the error + ; Test that \ after a macro invocation at the end of the file doesn't ; cause a segfault. diff --git a/test/asm/line-continuation.err b/test/asm/line-continuation.err index d16ad5d2..416709c6 100644 --- a/test/asm/line-continuation.err +++ b/test/asm/line-continuation.err @@ -1,3 +1,7 @@ -error: line-continuation.asm(7): +error: line-continuation.asm(3): + Begun line continuation, but encountered character 's' +warning: line-continuation.asm(6) -> line-continuation.asm::spam(4): [-Wuser] + spam +error: line-continuation.asm(14): Label "foo" created outside of a SECTION -error: Assembly aborted (1 error)! +error: Assembly aborted (2 errors)! diff --git a/test/asm/load-in-load.asm b/test/asm/load-in-load.asm new file mode 100644 index 00000000..28115a63 --- /dev/null +++ b/test/asm/load-in-load.asm @@ -0,0 +1,5 @@ +SECTION "outer", ROM0 +LOAD "inner", WRAM0 +LOAD "matryoshka", HRAM +ENDL +ENDL diff --git a/test/asm/load-in-load.err b/test/asm/load-in-load.err new file mode 100644 index 00000000..7e68df17 --- /dev/null +++ b/test/asm/load-in-load.err @@ -0,0 +1,5 @@ +error: load-in-load.asm(3): + `LOAD` blocks cannot be nested +error: load-in-load.asm(5): + Found `ENDL` outside of a `LOAD` block +error: Assembly aborted (2 errors)! diff --git a/test/asm/negative-ds.asm b/test/asm/negative-ds.asm new file mode 100644 index 00000000..814ed366 --- /dev/null +++ b/test/asm/negative-ds.asm @@ -0,0 +1,6 @@ +SECTION "manual union", WRAM0 +Foo:: dw +ds @ - Foo +Bar:: db +ds -1 +Baz:: dl diff --git a/test/asm/negative-ds.err b/test/asm/negative-ds.err new file mode 100644 index 00000000..391cc4f8 --- /dev/null +++ b/test/asm/negative-ds.err @@ -0,0 +1,2 @@ +FATAL: negative-ds.asm(5): + Constant must not be negative: -1 diff --git a/test/asm/purge.asm b/test/asm/purge.asm index 1552cea0..b18f3099 100644 --- a/test/asm/purge.asm +++ b/test/asm/purge.asm @@ -11,3 +11,5 @@ Label: Exported:: PURGE Exported Exported:: + + PURGE Undefined diff --git a/test/asm/purge.err b/test/asm/purge.err index 3228a909..c6fb6599 100644 --- a/test/asm/purge.err +++ b/test/asm/purge.err @@ -1,3 +1,5 @@ error: purge.asm(9): Symbol "Referenced" is referenced and thus cannot be purged -error: Assembly aborted (1 error)! +error: purge.asm(15): + 'Undefined' not defined +error: Assembly aborted (2 errors)! diff --git a/test/asm/rept-line-no.asm b/test/asm/rept-line-no.asm index b752d57e..de47afeb 100644 --- a/test/asm/rept-line-no.asm +++ b/test/asm/rept-line-no.asm @@ -6,3 +6,9 @@ REPT 3 ENDR WARN "Line 8" + +REPT 2 + REPT 2 + WARN "Line 12" + ENDR +ENDR diff --git a/test/asm/rept-line-no.err b/test/asm/rept-line-no.err index 8c259aef..9bde4c3d 100644 --- a/test/asm/rept-line-no.err +++ b/test/asm/rept-line-no.err @@ -8,3 +8,11 @@ warning: rept-line-no.asm(3) -> rept-line-no.asm::REPT~3(5): [-Wuser] Line 5 warning: rept-line-no.asm(8): [-Wuser] Line 8 +warning: rept-line-no.asm(10) -> rept-line-no.asm::REPT~1(11) -> rept-line-no.asm::REPT~1::REPT~1(12): [-Wuser] + Line 12 +warning: rept-line-no.asm(10) -> rept-line-no.asm::REPT~1(11) -> rept-line-no.asm::REPT~1::REPT~2(12): [-Wuser] + Line 12 +warning: rept-line-no.asm(10) -> rept-line-no.asm::REPT~2(11) -> rept-line-no.asm::REPT~2::REPT~1(12): [-Wuser] + Line 12 +warning: rept-line-no.asm(10) -> rept-line-no.asm::REPT~2(11) -> rept-line-no.asm::REPT~2::REPT~2(12): [-Wuser] + Line 12 diff --git a/test/asm/section-in-load.asm b/test/asm/section-in-load.asm new file mode 100644 index 00000000..a32213e7 --- /dev/null +++ b/test/asm/section-in-load.asm @@ -0,0 +1,4 @@ +SECTION "outer", ROM0 +LOAD "ram", WRAM0 +SECTION "inner", ROM0 +ENDL diff --git a/test/asm/section-in-load.err b/test/asm/section-in-load.err new file mode 100644 index 00000000..69fd68dd --- /dev/null +++ b/test/asm/section-in-load.err @@ -0,0 +1,2 @@ +FATAL: section-in-load.asm(3): + Cannot change the section within a `LOAD` block diff --git a/test/asm/section-in-union.asm b/test/asm/section-in-union.asm new file mode 100644 index 00000000..584be0aa --- /dev/null +++ b/test/asm/section-in-union.asm @@ -0,0 +1,5 @@ +SECTION "outer", WRAM0 +UNION +SECTION "inner", WRAM0 +NEXTU +ENDU diff --git a/test/asm/section-in-union.err b/test/asm/section-in-union.err new file mode 100644 index 00000000..a8e1ab2d --- /dev/null +++ b/test/asm/section-in-union.err @@ -0,0 +1,2 @@ +FATAL: section-in-union.asm(3): + Cannot change the section within a UNION diff --git a/test/asm/section-name-undefined.asm b/test/asm/section-name-undefined.asm new file mode 100644 index 00000000..ae22a62f --- /dev/null +++ b/test/asm/section-name-undefined.asm @@ -0,0 +1 @@ +assert SECTION(Undefined) diff --git a/test/asm/section-name-undefined.err b/test/asm/section-name-undefined.err new file mode 100644 index 00000000..237ef974 --- /dev/null +++ b/test/asm/section-name-undefined.err @@ -0,0 +1,2 @@ +FATAL: section-name-undefined.asm(1): + Unknown symbol "Undefined" diff --git a/test/asm/section-union-mismatch.asm b/test/asm/section-union-mismatch.asm new file mode 100644 index 00000000..d7b2b0e5 --- /dev/null +++ b/test/asm/section-union-mismatch.asm @@ -0,0 +1,2 @@ +SECTION UNION "test", WRAM0[$c000] +SECTION UNION "test", WRAM0[$c001] diff --git a/test/asm/section-union-mismatch.err b/test/asm/section-union-mismatch.err new file mode 100644 index 00000000..625b2762 --- /dev/null +++ b/test/asm/section-union-mismatch.err @@ -0,0 +1,4 @@ +error: section-union-mismatch.asm(2): + Section already declared as fixed at different address $c000 +FATAL: section-union-mismatch.asm(2): + Cannot create section "test" (1 error) diff --git a/test/asm/undefined-opt.asm b/test/asm/undefined-opt.asm new file mode 100644 index 00000000..4ee2033d --- /dev/null +++ b/test/asm/undefined-opt.asm @@ -0,0 +1 @@ +opt x ; there is no opt x diff --git a/test/asm/undefined-opt.err b/test/asm/undefined-opt.err new file mode 100644 index 00000000..3c205072 --- /dev/null +++ b/test/asm/undefined-opt.err @@ -0,0 +1,3 @@ +error: undefined-opt.asm(1): + Unknown option 'x' +error: Assembly aborted (1 error)! diff --git a/test/asm/union-in-rom.asm b/test/asm/union-in-rom.asm new file mode 100644 index 00000000..1b41b68b --- /dev/null +++ b/test/asm/union-in-rom.asm @@ -0,0 +1,3 @@ +SECTION "test", ROM0 +UNION +ENDU diff --git a/test/asm/union-in-rom.err b/test/asm/union-in-rom.err new file mode 100644 index 00000000..0bd95f04 --- /dev/null +++ b/test/asm/union-in-rom.err @@ -0,0 +1,5 @@ +error: union-in-rom.asm(2): + Cannot use UNION inside of ROM0 or ROMX sections +error: union-in-rom.asm(3): + Found ENDU outside of a UNION construct +error: Assembly aborted (2 errors)! diff --git a/test/asm/union-in-union.asm b/test/asm/union-in-union.asm new file mode 100644 index 00000000..c97fc4e0 --- /dev/null +++ b/test/asm/union-in-union.asm @@ -0,0 +1,11 @@ +SECTION "test", WRAM0 +UNION + UNION + db + NEXTU + dw + ENDU +NEXTU + dl +ENDU +assert sizeof("test") == 4 diff --git a/test/asm/unique-id-values.asm b/test/asm/unique-id-values.asm index 12a30c32..8f01bdee 100644 --- a/test/asm/unique-id-values.asm +++ b/test/asm/unique-id-values.asm @@ -20,3 +20,14 @@ for p, 10 println "p = {d:p}" endc endr + +rept 3 + if def(m) + purge m + endc + MACRO m + println "go \1 \@" + ENDM + m \@ +endr + m outside diff --git a/test/asm/unique-id-values.out b/test/asm/unique-id-values.out index 29d3e768..3f4913ef 100644 --- a/test/asm/unique-id-values.out +++ b/test/asm/unique-id-values.out @@ -52,3 +52,7 @@ p = 9: _u19 q = 5 (m: still _u23) (p: still _u19) +go _u25 _u26 +go _u27 _u28 +go _u29 _u30 +go outside _u31 diff --git a/test/asm/unterminated-rept.asm b/test/asm/unterminated-rept.asm new file mode 100644 index 00000000..8b196e0e --- /dev/null +++ b/test/asm/unterminated-rept.asm @@ -0,0 +1 @@ +REPT 3 diff --git a/test/asm/unterminated-rept.err b/test/asm/unterminated-rept.err new file mode 100644 index 00000000..1ab94d1a --- /dev/null +++ b/test/asm/unterminated-rept.err @@ -0,0 +1,3 @@ +error: unterminated-rept.asm(2): + Unterminated REPT/FOR block +error: Assembly aborted (1 error)!