doc about array index restriction

This commit is contained in:
Irmen de Jong 2020-10-17 20:35:36 +02:00
parent f37564c49c
commit 353d6cfc55
4 changed files with 13 additions and 12 deletions

View File

@ -41,7 +41,7 @@ of that build task, you can start the compiler with:
(You should probably make an alias...) (You should probably make an alias...)
.. note:: .. hint::
Development and testing is done on Linux, but the compiler should run on most Development and testing is done on Linux, but the compiler should run on most
operating systems. If you do have trouble building or running operating systems. If you do have trouble building or running
the compiler on another operating system, please let me know! the compiler on another operating system, please let me know!

View File

@ -16,7 +16,7 @@ with Prog8 are written like this.
You can ``%import`` and use these modules explicitly, but the compiler may also import one or more You can ``%import`` and use these modules explicitly, but the compiler may also import one or more
of these library modules automatically as required. of these library modules automatically as required.
.. note:: .. caution::
The resulting compiled binary program *only works on the target machine it was compiled for*. The resulting compiled binary program *only works on the target machine it was compiled for*.
You must recompile the program for every target you want to run it on. You must recompile the program for every target you want to run it on.

View File

@ -254,12 +254,19 @@ Array types are also supported. They can be made of bytes, words or floats, stri
This means byte arrays should be <= 256 elements, word arrays <= 128 elements, and float This means byte arrays should be <= 256 elements, word arrays <= 128 elements, and float
arrays <= 51 elements. arrays <= 51 elements.
.. note::
To avoid slow and complex assembly code generation, Prog8 currently enforces some limits on
what you can index the array with. *It is not possible to use an arbitrary expression/calculation as an index value*.
You can use a numerical constant value or a single variable as an index value.
You can split an array initializer list over several lines if you want. You can split an array initializer list over several lines if you want.
Note that the various keywords for the data type and variable type (``byte``, ``word``, ``const``, etc.) Note that the various keywords for the data type and variable type (``byte``, ``word``, ``const``, etc.)
can't be used as *identifiers* elsewhere. You can't make a variable, block or subroutine with the name ``byte`` can't be used as *identifiers* elsewhere. You can't make a variable, block or subroutine with the name ``byte``
for instance. for instance.
It's possible to assign a new array to another array, this will overwrite all elements in the original It's possible to assign a new array to another array, this will overwrite all elements in the original
array with those in the value array. The number and types of elements have to match. array with those in the value array. The number and types of elements have to match.
For large arrays this is a slow operation because every element is copied over. It should probably be avoided. For large arrays this is a slow operation because every element is copied over. It should probably be avoided.
@ -307,7 +314,7 @@ as newlines, quote characters themselves, and so on. The ones used most often ar
read the syntax reference on strings. read the syntax reference on strings.
.. note:: .. hint::
Strings and uwords (=memory address) can often be interchanged. Strings and uwords (=memory address) can often be interchanged.
An array of strings is actually an array of uwords where every element is the memory An array of strings is actually an array of uwords where every element is the memory
address of the string. You can pass a memory address to assembly functions address of the string. You can pass a memory address to assembly functions
@ -372,13 +379,6 @@ address you specified, and setting the varible will directly modify that memory
&word SCREENCOLORS = $d020 ; a 16-bit word at the addres $d020-$d021 &word SCREENCOLORS = $d020 ; a 16-bit word at the addres $d020-$d021
.. note::
Directly accessing random memory locations is not yet supported without the
intermediate step of declaring a memory-mapped variable for the memory location.
The advantages of this however, is that it's clearer what the memory location
stands for, and the compiler also knows the data type.
Converting types into other types Converting types into other types
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -16,8 +16,9 @@ Currently there are two machines that are supported as compiler target (selectab
This chapter explains the relevant system details of these machines. This chapter explains the relevant system details of these machines.
.. note:: .. hint::
If you only use standard kernel and prog8 library routines, it is possible to compile the *exact same program* for both machines (just change the compiler target flag)! If you only use standard kernel and prog8 library routines,
it is possible to compile the *exact same program* for both machines (just change the compiler target flag)!
Memory Model Memory Model