removed restriction on array indexer expression again from docs and code... :)

This commit is contained in:
Irmen de Jong 2020-10-18 14:05:26 +02:00
parent b9706a180b
commit 74b5124a42
4 changed files with 7 additions and 15 deletions

View File

@ -254,14 +254,6 @@ 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, and simple expressions such as
"i+1" or "i*2". If you need more complex indexing expressions, the compiler refuses the statement and
will suggest to use a temporary indexer variable instead.
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.)

View File

@ -166,8 +166,7 @@ main {
else else
c64.SPRPTR[i] = $2000/64 ; small ball c64.SPRPTR[i] = $2000/64 ; small ball
ubyte scolor = (zc>>13) as ubyte + 4 c64.SPCOL[i] = spritecolors[(zc>>13) as ubyte + 4] ; further away=darker color
c64.SPCOL[i] = spritecolors[scolor] ; further away=darker color
} }
} }
} }

View File

@ -43,8 +43,7 @@ main {
while multiple < len(sieve) { while multiple < len(sieve) {
ubyte number = lsb(multiple) sieve[lsb(multiple)] = true
sieve[number] = true
multiple += candidate_prime multiple += candidate_prime
} }
return candidate_prime return candidate_prime

View File

@ -314,7 +314,6 @@ market {
ubyte[17] units = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 0] ubyte[17] units = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 0]
str[17] names = ["Food", "Textiles", "Radioactives", "Slaves", "Liquor/Wines", "Luxuries", "Narcotics", "Computers", str[17] names = ["Food", "Textiles", "Radioactives", "Slaves", "Liquor/Wines", "Luxuries", "Narcotics", "Computers",
"Machinery", "Alloys", "Firearms", "Furs", "Minerals", "Gold", "Platinum", "Gem-Stones", "Alien Items"] "Machinery", "Alloys", "Firearms", "Furs", "Minerals", "Gold", "Platinum", "Gem-Stones", "Alien Items"]
str[3] unitnames = ["t", "kg", "g"]
ubyte[17] current_quantity = 0 ubyte[17] current_quantity = 0
uword[17] current_price = 0 uword[17] current_price = 0
@ -360,8 +359,11 @@ market {
util.print_10s(current_price[ci]) util.print_10s(current_price[ci])
txt.print(" ") txt.print(" ")
txt.print_ub(current_quantity[ci]) txt.print_ub(current_quantity[ci])
ubyte unit = units[ci] when units[ci] {
txt.print(unitnames[unit]) 0 -> txt.chrout('t')
1 -> txt.print("kg")
2 -> txt.chrout('g')
}
txt.print(" ") txt.print(" ")
txt.print_ub(ship.cargohold[ci]) txt.print_ub(ship.cargohold[ci])
txt.chrout('\n') txt.chrout('\n')