Welcome, Guest |
You have to register before you can post on our site.
|
Online Users |
There are currently 157 online users. » 0 Member(s) | 155 Guest(s) Bing, Google
|
Latest Threads |
Strange Happenings
Forum: Bug Reports
Last Post: zedex82
05-07-2025, 09:05 AM
» Replies: 0
» Views: 30
|
.tap file code not execut...
Forum: Help & Support
Last Post: Zoran
04-28-2025, 10:59 AM
» Replies: 4
» Views: 411
|
Exit from more than one l...
Forum: Wishlist
Last Post: Duefectu
04-23-2025, 10:06 PM
» Replies: 3
» Views: 325
|
put small ASM programs li...
Forum: How-To & Tutorials
Last Post: Zoran
04-18-2025, 02:02 PM
» Replies: 6
» Views: 1,652
|
Creating +3 Menus - Loadi...
Forum: Help & Support
Last Post: merlinkv
04-16-2025, 02:08 PM
» Replies: 6
» Views: 599
|
Randomize not very random...
Forum: Help & Support
Last Post: Zoran
04-08-2025, 10:40 AM
» Replies: 4
» Views: 928
|
Scope rules
Forum: Bug Reports
Last Post: Zoran
04-04-2025, 09:46 AM
» Replies: 2
» Views: 369
|
Using constants not allow...
Forum: Bug Reports
Last Post: baltasarq
03-19-2025, 10:00 PM
» Replies: 8
» Views: 1,127
|
404 page not found
Forum: Documentation
Last Post: boriel
03-08-2025, 07:16 PM
» Replies: 5
» Views: 2,917
|
Spectrum keywords codes
Forum: Bug Reports
Last Post: boriel
03-08-2025, 11:00 AM
» Replies: 1
» Views: 437
|
|
|
Optimizer bug (*solved*) |
Posted by: einar - 10-17-2014, 07:50 PM - Forum: Bug Reports
- Replies (2)
|
 |
I found an error in ZX BASIC optimizer. Take a look at this test program:
Code: GO TO 10
sub FASTCALL test(flag AS UBYTE)
asm
cp 1
jp m,45000
jp 50000
end asm
end sub
10 POKE 50000,201: POKE 45000,201
test(1)
This program produces the expected result if you compile it as follows:
Code: zxb.exe -t -O2 prog.bas
However it will refuse to compile if you use this instead:
Code: zxb.exe -t -O3 prog.bas
In this latter case it will produce this error message:
Code: C:>zxb.exe -t -O3 prog.bas
Traceback (most recent call last):
File "zxb.py", line 348, in <module>
File "zxb.py", line 301, in main
File "optimizer.pyc", line 2287, in optimize
File "optimizer.pyc", line 1493, in update_goes_and_comes
KeyError: '45000'
EDIT: Tested using latest ZX BASIC version 1.4.0s1898.
|
|
|
Serious bug indexing arrays (*solved*) |
Posted by: einar - 09-29-2014, 03:48 AM - Forum: Bug Reports
- Replies (4)
|
 |
Try running this program:
Code: DIM score(1 TO 2) AS UBYTE
DIM player AS UBYTE
LET score(1)=0
LET score(2)=0
LET player = 1
LET score(player)=score(player)+1
PRINT "SCORE ";score(1);"x";score(2)
The result will be "SCORE 0x1". This code was supposed to increment the score for player 1, but it will increment it for player 2 instead!
Now try changing this program as follows:
Code: DIM score(1 TO 2) AS UBYTE
DIM player AS UBYTE
LET score(1)=0
LET score(2)=0
LET player = 1
LET score(1)=score(1)+1
PRINT "SCORE ";score(1);"x";score(2)
Now it will give the correct result "SCORE 1x0".
Tested using latest ZX BASIC release 1.4.0s1893.
|
|
|
Conditional operator? |
Posted by: einar - 09-16-2014, 08:57 PM - Forum: Wishlist
- Replies (8)
|
 |
Whenever I'm programming anything in ZX BASIC that involves non-trivial calculations, I really miss the conditional operator from C. So much that I finally decided to post a request here...
Since ZX BASIC already incorporates many useful operators from C like << (binary shift) and & (binary and), could you please consider incorporating C conditional operator also? What I mean is allowing code like this:
Code: IF (a < 30) THEN
LET a = a + 2
ELSE
LET a = a + 1
END IF
To be written like this:
Code: LET a = a + (a < 30 ? 2 : 1)
Those unfamiliar with C programming may not recognize it at first, but after you get used to it, the latter version is a lot easier to read. It's also easier for a compiler to optimize a single expression using conditional operators, instead of multiple IFs. Also this kind of feature would not introduce any problems or ambiguity in the parser.
For more complex expressions it makes a huge difference. Here's another example:
Code: IF (row > 0) THEN
LET pos = pos | (move & UP)
ELSE
LET pos = pos | TOP
END IF
IF (row < 21) THEN
LET pos = pos | (move & DOWN)
ELSE
LET pos = pos | BOTTOM
END IF
IF (col > 0) THEN
LET pos = pos | (move & LEFT)
ELSE
LET pos = pos | LEFTMOST
END IF
IF (col < 31) THEN
LET pos = pos | (move & RIGHT)
ELSE
LET pos = pos | RIGHTMOST
END IF
Using conditional operators, all this code above would be simplified to this:
Code: LET pos = pos | (row > 0 ? move & UP : TOP) |
(row < 21 ? move & DOWN : BOTTOM) |
(col > 0 ? move & LEFT : LEFTMOST) |
(col < 31 ? move & RIGHT : RIGHTMOST)
Makes sense?
|
|
|
|