added %option splitarrays (block level)

This commit is contained in:
Irmen de Jong 2023-05-31 18:49:21 +02:00
parent bb9d29b061
commit 8f864417c4
6 changed files with 48 additions and 12 deletions

View File

@ -800,7 +800,7 @@ internal class AstChecker(private val program: Program,
err("this directive may only occur in a block or at module level")
if(directive.args.isEmpty())
err("missing option directive argument(s)")
else if(directive.args.map{it.name in arrayOf("enable_floats", "force_output", "no_sysinit", "align_word", "align_page", "merge")}.any { !it })
else if(directive.args.map{it.name in arrayOf("enable_floats", "force_output", "no_sysinit", "align_word", "align_page", "merge", "splitarrays")}.any { !it })
err("invalid option directive argument(s)")
}
else -> throw SyntaxError("invalid directive ${directive.directive}", directive.position)

View File

@ -164,20 +164,25 @@ class AstPreprocessor(val program: Program,
}
if(options.splitWordArrays && (decl.datatype==DataType.ARRAY_W || decl.datatype==DataType.ARRAY_UW)) {
// make all word arrays automatically be tagged as split arrays
if(!decl.definingBlock.isInLibrary) {
val splitDt = ArrayToElementTypes.getValue(decl.datatype)
val newDecl = VarDecl(
decl.type, decl.origin, splitDt, decl.zeropage, decl.arraysize, decl.name,
decl.value, true, decl.sharedWithAsm, true, decl.position
)
return listOf(IAstModification.ReplaceNode(decl, newDecl, parent))
}
if(!decl.definingBlock.isInLibrary)
return makeSplitArray(decl)
}
if("splitarrays" in decl.definingBlock.options() && (decl.datatype==DataType.ARRAY_W || decl.datatype==DataType.ARRAY_UW))
return makeSplitArray(decl)
return noModifications
}
private fun makeSplitArray(decl: VarDecl): Iterable<IAstModification> {
val splitDt = ArrayToElementTypes.getValue(decl.datatype)
val newDecl = VarDecl(
decl.type, decl.origin, splitDt, decl.zeropage, decl.arraysize, decl.name,
decl.value, true, decl.sharedWithAsm, true, decl.position
)
return listOf(IAstModification.ReplaceNode(decl, newDecl, decl.parent))
}
override fun after(subroutine: Subroutine, parent: Node): Iterable<IAstModification> {
// For non-kernal subroutines and non-asm parameters:
// inject subroutine params as local variables (if they're not there yet).

View File

@ -168,7 +168,7 @@ class IntermediateAstMaker(private val program: Program, private val options: Co
"align_word" -> alignment = PtBlock.BlockAlignment.WORD
"align_page" -> alignment = PtBlock.BlockAlignment.PAGE
"force_output" -> forceOutput=true
"merge" -> { /* ignore this one */ }
"merge", "splitarrays" -> { /* ignore this one */ }
else -> throw FatalAstException("weird directive option: ${arg.name}")
}
}

View File

@ -86,7 +86,7 @@ The compiler will link everything together into one output program at the end.
If you start the compiler without arguments, it will print a short usage text.
For normal use the compiler can be invoked with the command:
``$ java -jar prog8compiler-7.3-all.jar sourcefile.p8``
``$ java -jar prog8compiler-8.14-all.jar sourcefile.p8``
(Use the appropriate name and version of the jar file downloaded from one of the Git releases.
Other ways to invoke the compiler are also available: see the introduction page about how
@ -252,12 +252,37 @@ that support these symbol and breakpoint lists.
Troubleshooting
---------------
Compiler doesn't run, complains about "UnsupportedClassVersionError"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
You need to install and use JDK version 11 or newer to run the prog8 compiler. Check this with "java -version".
The computer resets unexpectedly (at the end of the program)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
If you are using the default 'zeropage' compiler option, and your program exits, it is not possible
to return back to the BASIC prompt. The only reliable course of action is to reboot the system.
(this is due to the fact that in the default mode, prog8 can overwrite important BASIC and Kernal
variables in memory).
To avoid a sudden system reset, use an empty ``repeat`` loop at the end of your program to keep it from exiting.
Alternatively, if you want your program to exit cleanly back to the BASIC prompt,
you have to use ``%zeropage basicsafe``, see :ref:`directives`.
Odd text and screen colors at start
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Prog8 will reset the screen mode and colors to a uniform well-known state. If you don't like the
default text and screen colors, you can simply change them to whatever you want using the
appropriate routines in the ``textio`` module.
Alternatively you can choose to disable this re-initialization altogether
using ``%option no_sysinit``, see :ref:`directives`.
Floats error
^^^^^^^^^^^^
Getting an assembler error about undefined symbols such as ``not defined 'floats'``?
This happens when your program uses floating point values, and you forgot to import ``floats`` library.
If you use floating points, the compiler needs routines from that library.
Fix it by adding an ``%import floats``.
Examples
--------

View File

@ -129,6 +129,7 @@ Directives
- ``align_word`` (in a block) will make the assembler align the start address of this block on a word boundary in memory (so, an even memory address).
- ``align_page`` (in a block) will make the assembler align the start address of this block on a page boundary in memory (so, the LSB of the address is 0).
- ``merge`` (in a block) will merge this block's contents into an already existing block with the same name. Useful in library scenarios.
- ``splitarrays`` (in a block) makes all word-arrays in this block lsb/msb split arrays (as if they all have the @split tag). See Arrays.
.. data:: %asmbinary "<filename>" [, <offset>[, <length>]]

View File

@ -1,6 +1,10 @@
TODO
====
- instead of resetting the computer at program exit, reinit screen and print message >PROGRAM EXIT CODE 123;RESET COMPUTER.< + sei + endless loop.
change troubleshooting and other references in the docs.
For 9.0 major changes
^^^^^^^^^^^^^^^^^^^^^
- DONE: added 'cbm' block in the syslib module that now contains all CBM compatible kernal routines and variables
@ -17,6 +21,7 @@ For 9.0 major changes
- DONE: added sys.irqsafe_xxx irqd routines
- DONE: added gfx2.fill() flood fill routine
- DONE: added @split storage class for (u)word arrays to store them as split lsb/msb arrays which is more efficient (but doesn't yet support all array operations)
- DONE: added -splitarrays command line option to treat all word arrays as tagged with @split
- [much work:] more support for (64tass) SEGMENTS ?
- (What, how, isn't current BSS support enough?)