Dummy parse command to fill procedure table?

bbc micro/electron/atom/risc os coding queries and routines
Post Reply
B3_B3_B3
Posts: 404
Joined: Sat Apr 08, 2017 10:42 pm
Contact:

Dummy parse command to fill procedure table?

Post by B3_B3_B3 »

Given that after its first invocation, a beeb's procedure is faster than line number based Gosubs, due to the cached address of the Proc defintion, I wondered if any Bbc basic descendant gained a Dummy parse command to fill the procedure etc address cache table?..

Eg something like a PARSETOCACHE * command called once at start of programme for when a slight initial delay (eg while game instructions are shown) is a good trade off against a faster first call of each routine?


*others can probably think of better names..
User avatar
jgharston
Posts: 5336
Joined: Thu Sep 24, 2009 12:22 pm
Location: Whitby/Sheffield
Contact:

Re: Dummy parse command to fill procedure table?

Post by jgharston »

PROCthing(-1)
....
DEFPROCthing(A%):IF A%<0 THEN ENDPROC
...
do stuff
...
ENDPROC

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.45
(C) Copyright J.G.Harston 1989,2005-2024
>_
B3_B3_B3
Posts: 404
Joined: Sat Apr 08, 2017 10:42 pm
Contact:

Re: Dummy parse command to fill procedure table?

Post by B3_B3_B3 »

jgharston wrote: Tue Apr 30, 2024 2:55 pm PROCthing(-1)
....
DEFPROCthing(A%):IF A%<0 THEN ENDPROC
...
do stuff
...
ENDPROC
But now the 1st line of the procedure is slowing it down every time its called , in addition to the speed cost of an extra parameter/memory cost if made a global flag .... I suppose you could have self modifying code that deleted the 1st line of every procedure and said global after first call of every procedure (from an entire procedure called buildprocedurecache which is then also deleted) ?
julie_m
Posts: 597
Joined: Wed Jul 24, 2019 9:53 pm
Location: Derby, UK
Contact:

Re: Dummy parse command to fill procedure table?

Post by julie_m »

You're over-thinking this!

The slow-down is only ever applicable the first time a PROCedure or FN is called; and it's not that much, in any case. You could speed up the search by putting all your DEFPROCs at the beginning of your program, with a GOTO to jump past them.

But the prevailing attitude at the time was "if you really need as much speed as possible, why are you still using BASIC?"
james
Posts: 347
Joined: Tue Aug 15, 2023 8:41 pm
Location: NE Hampshire
Contact:

Re: Dummy parse command to fill procedure table?

Post by james »

julie_m wrote: Tue Apr 30, 2024 5:46 pm The slow-down is only ever applicable the first time a PROCedure or FN is called;
Apart from the enormous overhead of evaluating "IF A%<0 THEN ENDPROC" every time the FN/PROC is called ...
User avatar
SKS1
Posts: 329
Joined: Sat Sep 19, 2020 12:04 am
Location: Highland Perthshire
Contact:

Re: Dummy parse command to fill procedure table?

Post by SKS1 »

james wrote: Tue Apr 30, 2024 6:24 pm
julie_m wrote: Tue Apr 30, 2024 5:46 pm The slow-down is only ever applicable the first time a PROCedure or FN is called;
Apart from the enormous overhead of evaluating "IF A%<0 THEN ENDPROC" every time the FN/PROC is called ...
Consider PROCinit(-1)
Miserable old curmudgeon who still likes a bit of an ARM wrestle now and then. Pi 4, 3, ARMX6, SA Risc PC, A540, A440
B3_B3_B3
Posts: 404
Joined: Sat Apr 08, 2017 10:42 pm
Contact:

Re: Dummy parse command to fill procedure table?

Post by B3_B3_B3 »

julie_m wrote: Tue Apr 30, 2024 5:46 pm .... You could speed up the search by putting all your DEFPROCs at the beginning of your program, with a GOTO to jump past them...
Routine definitions first would be Pascal like which would seem appropriate for bbcbasic, but a goto would not be... so it would be nice if the goto* could be left out and the parser simply updated its procedure-address table as it read past the definitions, looking for a non definition to parse?.... but multiple endprocs presumably would need a new keyword to mean program code starts , so from Pascal PROGRAMBEGIN / BEGIN...?
EDIT just noticed next post with a neat trick to avoid need for...BEGIN using a PROCmain (C inspired?)...perhaps PROCprogram_begin would be more Pascally...:)

The bbc manual seemed rather offputting about machine code (unlike the atom manual it seems), so I never learnt it univ.
Last edited by B3_B3_B3 on Tue Apr 30, 2024 7:44 pm, edited 2 times in total.
User avatar
sweh
Posts: 3325
Joined: Sat Mar 10, 2012 12:05 pm
Location: 07410 New Jersey
Contact:

Re: Dummy parse command to fill procedure table?

Post by sweh »

Dunno if this would work at speeding up, but it avoids the GOTO.

Code: Select all

10 PROCmain
20 END
100.... all the normal procedures the program needs
20000 DEF PROCmain
....main code goes here
29900 ENDPROC
Rgds
Stephen
B3_B3_B3
Posts: 404
Joined: Sat Apr 08, 2017 10:42 pm
Contact:

Re: Dummy parse command to fill procedure table?

Post by B3_B3_B3 »

sweh wrote: Tue Apr 30, 2024 7:41 pm .....
10 PROCmain
20 END
100.... all the normal procedures the program needs
20000 DEF PROCmain
....main code goes here
29900 ENDPROC
[/code]
I edited my preceding post to respind to this neat idea.
Post Reply

Return to “programming”