apple2js/test
Ian Flanigan d67f3d8086
Applesoft compiler fixes (#98)
* Add tests for Applesoft compiler in preparation for refactoring

While refactoring the compiler, I found several small bugs:

*   Lower-case letters in strings and REM statements were converted
    to upper-case.
*   Lines are stored in the order received, not sorted by line number.
*   Does not prefer `ATN` to `AT`.
*   Does not prefer `TO` to `AT`.
*   `DATA` statements don't preserve spaces.
*   `DATA` statements don't preserve lowercase.

These will be fixed in the upcoming refactoring.

* Refactor the Applesoft Compiler

Before, the compiler had a few bugs that were not trivial to solve
because the implementation was in one heavily-nested function.

In this refactoring of the compiler, things like tokenization have
been split into separate methods which makes them a bit easier to
understand.

This refactoring also passes all of the tests.

* Set `PRGEND` when compiling to memory

Before, `PRGEND` was not adjusted which made round-tripping from
the Applesoft compiler to the decompiler not work.  This change
now updates `PRGEND` with the end-of-program + 2 bytes which seems
to be the most frequent value that I have observed.

* Fix two compiler bugs

In debugging the decompiler, I noticed two bugs in the compiler:
*   The first character after a line number was skipped.
*   `?` was not accepted as a shortcut for `PRINT`.

This change fixes these two problems and adds tests.

* Ignore spaces more aggressively

It turns out that Applesoft happily accepts 'T H E N' for `THEN`
but the parser did not. This change fixes that and adds tests for
some odd cases.

Interestingly, this means that there are some valid statements
that Applesoft can never parse correctly because it is greedy
and ignores (most) spaces. For example, `NOT RACE` will always
parse as `NOTRACE` even though `NOT RACE` is a valid expression.

* Move tokens into a separate file

Because the token lists are just maps in opposite directions, put
them in the same file. In the future, maybe we can build one
automatically.

* Fix `apple2.ts`

I had neglected to actually update `apple2.ts` to use the new
compiler and decompiler. They now do.

Also, the decompiler can be created from `Memory`. It assumes,
though, that the zero page pointers to the start and end of the
program are correct.

* Address comments

*   No more `as const` for tokens.
*   Extracted zero page constants to their own file.

Co-authored-by: Will Scullin <scullin@scullin.com>
2022-06-23 20:41:45 -07:00
..
components Add drag and drop for disks (#130) 2022-06-12 09:42:01 -07:00
env Create a FileChooser component using showOpenFilePicker (#116) 2022-05-28 10:52:48 -07:00
js Applesoft compiler fixes (#98) 2022-06-23 20:41:45 -07:00
roms Update eslint, fix issues 2021-11-28 16:20:25 -08:00
util Add the recommended eslint plugins for TypeScript (#121) 2022-05-31 08:38:40 -07:00
cpu6502.spec.ts No Opcode left behind (#92) 2021-12-22 10:37:05 -08:00
cpu-tom-harte.spec.ts Apply semi rule to interfaces (#109) 2022-05-10 08:04:20 -07:00
cpu.spec.ts Enforce strict equality (#115) 2022-05-18 08:19:45 -07:00
jest-setup.ts Preact error dialog (#120) 2022-05-31 17:41:24 -07:00