BASIC code to test compilers

The place for codemasters or beginners to talk about programming any language for the Spectrum.
User avatar
1024MAK
Bugaboo
Posts: 3123
Joined: Wed Nov 15, 2017 2:52 pm
Location: Sunny Somerset in the U.K. in Europe

Re: BASIC code to test compilers

Post by 1024MAK »

I think this topic shows why BASIC compilers were not as popular as some may have expected, far too many limitations.

I know it’s an unfair comparison, but using OPL on a Psion in comparison is like being in a different universe.

For comparison purposes, the PCW benchmark programs (Rugg/Feldman benchmarks) are normally used, as mostly they do allow comparisons across various platforms and BASIC versions.

Mark
:!: Standby alert :!:
“There are four lights!”
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :dance
Looking forward to summer later in the year.
User avatar
1024MAK
Bugaboo
Posts: 3123
Joined: Wed Nov 15, 2017 2:52 pm
Location: Sunny Somerset in the U.K. in Europe

Re: BASIC code to test compilers

Post by 1024MAK »

Turtle_Quality wrote: Mon Aug 14, 2023 5:41 pm The only drawback with using Frames as a timer is that you're assuming the interrupts are always enabled. The ROMs BEEP will disable interrupts temporarily, we can't be sure what compilers might do with interrupts, especially compilers with different trace levels like MCoder. Quite likely nothing, I'm probably just displaying nerdy levels of caution
This however is not too difficult to test, run a FOR NEXT routine for long enough (say a minute or two), timing also with a stopwatch, then compare to the Frames counter result.

Mark
:!: Standby alert :!:
“There are four lights!”
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :dance
Looking forward to summer later in the year.
User avatar
PeterJ
Site Admin
Posts: 6879
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: BASIC code to test compilers

Post by PeterJ »

1024MAK wrote: Mon Aug 14, 2023 7:10 pm For comparison purposes, the PCW benchmark programs (Rugg/Feldman benchmarks) are normally used, as mostly they do allow comparisons across various platforms and BASIC versions.
Thanks. think these are the ones I posted to earlier Mark

viewtopic.php?p=123029#p123029

PS. I think summer has come and gone now...
User avatar
1024MAK
Bugaboo
Posts: 3123
Joined: Wed Nov 15, 2017 2:52 pm
Location: Sunny Somerset in the U.K. in Europe

Re: BASIC code to test compilers

Post by 1024MAK »

Currently sunny weather in sunny Somerset, current outside air temperature of 18°C :D

Yes, the link was earlier in the topic.

Mark
:!: Standby alert :!:
“There are four lights!”
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :dance
Looking forward to summer later in the year.
User avatar
Pegaz
Dynamite Dan
Posts: 1210
Joined: Mon Nov 13, 2017 1:44 pm

Re: BASIC code to test compilers

Post by Pegaz »

What is the fastest compiler that supports decimal numbers ?
Mcoder II gives Nonsense in basic message.
User avatar
PeterJ
Site Admin
Posts: 6879
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: BASIC code to test compilers

Post by PeterJ »

Probably Mcoder 3 @Pegaz,

https://spectrumcomputing.co.uk/entry/8421

Ones that support floating point are slower. Crash issues 19 and 20 have some good articles.

Image
User avatar
Pegaz
Dynamite Dan
Posts: 1210
Joined: Mon Nov 13, 2017 1:44 pm

Re: BASIC code to test compilers

Post by Pegaz »

Did I make a mistake somewhere, its almost 5x slower in the bubble sort example, than Mcoder II?
260ms vs 1180ms
User avatar
PeterJ
Site Admin
Posts: 6879
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: BASIC code to test compilers

Post by PeterJ »

Pegaz wrote: Mon Aug 14, 2023 9:49 pm Did I make a mistake somewhere, its almost 5x slower in the buuble sort example, than Mcoder II?
260ms vs 1180ms
I'm still learning @Pegaz, but FP compilers are much slower than integer compilers.
User avatar
Pegaz
Dynamite Dan
Posts: 1210
Joined: Mon Nov 13, 2017 1:44 pm

Re: BASIC code to test compilers

Post by Pegaz »

PeterJ wrote: Mon Aug 14, 2023 9:50 pm I'm still learning @Pegaz, but FP compilers are much slower than integer compilers.
I'm not an expert either, I just have a some experience with Boriel Basic compiler, but as @1024MAK already said, there are a lot of limitations with all of them and it takes a effort and knowledge to adapt the BASIC program to compile successfully, which is quite frustrating.
btw, Is there a some user manual for ZIP compiler?
Its very fast, but it seems also supports integer numbers only...
User avatar
PeterJ
Site Admin
Posts: 6879
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: BASIC code to test compilers

Post by PeterJ »

Pegaz wrote: Mon Aug 14, 2023 10:03 pm btw, Is there a some user manual for ZIP compiler?
Its very fast, but it seems also supports integer numbers only...
I have a user manual for ZIP, but I can't distribute it as the author is still selling it. It was originally a listing in Your Sinclair, so you should find some detail there. MCODER 3 should compile the majority of BASIC without alteration.

https://spectrumcomputing.co.uk/page.ph ... 21&page=68

Efit... Sorry, should have read Your Spectrum!
User avatar
Pegaz
Dynamite Dan
Posts: 1210
Joined: Mon Nov 13, 2017 1:44 pm

Re: BASIC code to test compilers

Post by Pegaz »

PeterJ wrote: Mon Aug 14, 2023 10:14 pm I have a user manual for ZIP, but I can't distribute it as the author is still selling it. It was originally a listing in Your Sinclair, so you should find some detail there. MCODER 3 should compile the majority of BASIC without alteration.

https://spectrumcomputing.co.uk/page.ph ... 21&page=68
Sorry, I thought it was available as a type in.
Actually, Mcoder II/III are perfectly fine and easy to use.
marenja
Microbot
Posts: 108
Joined: Sun Dec 26, 2021 4:15 pm

Re: BASIC code to test compilers

Post by marenja »

I tried all 3 available download files of MCoder 2 with permanent Nonsense in BASIC for

Code: Select all

10 DIM p$(1000)
Pobulous wrote: Mon Aug 14, 2023 3:47 pm MCoder II was what I used, too.
Whilst it says it supports AND and OR in IF statements, the version I had was definitely bugged when using them leading to much hair pulling debugging code which then worked if replaced with IF ... THEN IF .... THEN IF .... for AND
OR would be IF NOT .... THEN IF NOT ... THEN IF NOT .... THEN GOTO nomatch.
@Pobulous
Can you be so kind to explain your success with NOT operation?
Was it file from download pages or you have other file?

I have not only trouble with DIM but no success with simple OR instructions - i get the same Nonsense in BASIC.

Code: Select all

IF (1<2) OR (2<3) THEN 
IF ((1<2) OR (2<3)) THEN 
Moreover NOT instruction has the same result

Code: Select all

IF NOT (1<2) THEN
IF (NOT 1<2) THEN
IF (NOT (1<2)) THEN
But using AND operation compiles OK.

Code: Select all

IF (1<2) AND (2<3) THEN 
It is possible to use AND + NOT to change program logic and get rid of OR operations but i have errors with NOT as you see above.
User avatar
PeterJ
Site Admin
Posts: 6879
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: BASIC code to test compilers

Post by PeterJ »

marenja wrote: Tue Aug 15, 2023 1:14 pm I tried all 3 available download files of MCoder 2 with permanent Nonsense in BASIC for

Code: Select all

10 DIM p$(1000)
String arrays are not supported.
User avatar
Pobulous
Dynamite Dan
Posts: 1366
Joined: Wed Nov 15, 2017 12:51 pm

Re: BASIC code to test compilers

Post by Pobulous »

marenja wrote: Tue Aug 15, 2023 1:14 pm @Pobulous
Can you be so kind to explain your success with NOT operation?
Was it file from download pages or you have other file?

.....

It is possible to use AND + NOT to change program logic and get rid of OR operations but i have errors with NOT as you see above.
It's possible I misremembered using NOT. You could however invert your logic manually.

So

100 IF a>b OR d=e THEN goto 1000
110 REM do stuff when IF fails

becomes:

100 IF a<=b THEN IF d<>e THEN goto 110
105 GOTO 1000
110 REM do stuff when IF fails

I remember that AND was accepted in IF statements but didn't actually work properly in MCoder II - would be worth running some tests on that.
catmeows
Manic Miner
Posts: 718
Joined: Tue May 28, 2019 12:02 pm
Location: Prague

Re: BASIC code to test compilers

Post by catmeows »

TomD wrote: Mon Aug 14, 2023 12:31 pm Interestingly MCODER II is no faster than basic at plotting CIRCLES, both taking around 12seconds to plot 20.
Most of compilers would delegate task of drawing circle to ROM routine. Same for PLOT or DRAW commands.
Proud owner of Didaktik M
C.Born
Manic Miner
Posts: 229
Joined: Sat Dec 09, 2017 4:09 pm

Re: BASIC code to test compilers

Post by C.Born »

PeterJ wrote: Mon Aug 14, 2023 9:35 pm Probably Mcoder 3 @Pegaz,

https://spectrumcomputing.co.uk/entry/8421

Ones that support floating point are slower. Crash issues 19 and 20 have some good articles.

Image
i used it for my ultra slow 4connect ;)
User avatar
dust hill resident
Dizzy
Posts: 52
Joined: Sat Sep 23, 2023 6:05 pm
Location: London
Contact:

Re: BASIC code to test compilers

Post by dust hill resident »

equinox wrote: Sun Aug 13, 2023 10:32 pm Thanks. I actually thought "ok I'll write quicksort, how hard can it be?" and then after writing DIM a(500) and remembering that we don't have either local scope, or bounds checks*, I cried and gave up. (Recursion is enough fun when you have scope.) Haha! The problem of implementing textbook stuff in Spectrum BASIC is absolutely not a problem of memory or CPU, it's just how am I going to use this awful BASIC to code it. We've been spoiled with data structures and templates. [Well, I guess half the people reading this can write assembler, but do you know what you've got, that BASIC hasn't got? PUSH and POP†]
Your post got me intrigued and I thought it'd be a fun challenge so I had a go at it tonight, here is quicksort in Sinclair BASIC:
http://dusthillresident.ddns.net/quicksort.tzx

Sorry for the weird URL, I would have posted it as an attachment on the board, but I couldn't see an option for it.

Here's a youtube video of it in action:


- dhr
User avatar
dust hill resident
Dizzy
Posts: 52
Joined: Sat Sep 23, 2023 6:05 pm
Location: London
Contact:

Re: BASIC code to test compilers

Post by dust hill resident »

Perhaps this program would also be useful for testing basic compilers? It calculates an approximation of the sine function.
https://dusthillresident.ddns.net/sinapprox.tzx

- dhr
Wall_Axe
Manic Miner
Posts: 500
Joined: Mon Nov 13, 2017 11:13 pm

Re: BASIC code to test compilers

Post by Wall_Axe »

Is it sad that I watched the whole quicksort video
User avatar
ParadigmShifter
Manic Miner
Posts: 670
Joined: Sat Sep 09, 2023 4:55 am

Re: BASIC code to test compilers

Post by ParadigmShifter »

I watched it too. Wonder how "quick" it would be in the pathological worst case (an already sorted array, which is O(n^2) for quicksort - so same sort of performance as a bubble sort (probably worse than that though if it is recursive))? The expected ("amortised") time is O(n log n) though. If you suspect the array may be sorted better to reverse it first ;)
equinox
Dynamite Dan
Posts: 1052
Joined: Mon Oct 08, 2018 1:57 am
Location: SE England

Re: BASIC code to test compilers

Post by equinox »

Wall_Axe wrote: Tue Nov 14, 2023 10:29 pm Is it sad that I watched the whole quicksort video
You think it's going to surprise you, but no, it just prepares the ground for Super Skiing Simulator.
Post Reply