Author Topic: do we can this to?  (Read 3120 times)

0 Members and 2 Guests are viewing this topic.

Aurel

  • Guest
do we can this to?
« on: April 23, 2015, 09:14:13 PM »
from bp.org ..by Ed Davis:
Quote
Interestingly, FreeBasic can use computed gotos for select case statements:

From the FreeBasic documentation:

Select Case As Const integer_expression
[ Case constant | enumeration ]
[ statements ]
[ Case Else ]
[ statements ]
End Select

If As Const is used, only integer constants (all numeric constants excluding the two floating-point constants: single and double) can be evaluated and the expression list supports simple constants and enumerations only. "To" ranges are supported, but "Is" relational operators are not.

With As Const, a jump table is created to contain the full range of integer Cases handled. This allows Select Case As Const to be faster than Select Case. However, the size of the range of values is limited, and the largest value in the range may be no higher than the smallest value + 4096.

Kind of neat I think!

Charles Pegge

  • Guest
Re: do we can this to?
« Reply #1 on: April 23, 2015, 10:45:53 PM »
Hi Aurel,

Not in a case block but computed gotos / Jump Tables are easy to set up.

Code: OxygenBasic
  1. 'SETUP
  2. ======
  3. indexbase 1
  4. sys t={@AA,@BB,@CC} 'map label addreses into table
  5.  
  6. 'TEST
  7. =====
  8.  
  9. token=2
  10. goto t[token]
  11.  
  12. AA:
  13. print "AA"
  14. jmp fwd done
  15.  
  16. BB:
  17. print "BB"
  18. jmp fwd done
  19.  
  20. CC:
  21. print "CC"
  22. jmp fwd done
  23.  
  24.  
  25.  
  26. done:
  27.  

Aurel

  • Guest
Re: do we can this to?
« Reply #2 on: April 24, 2015, 02:32:47 AM »
ok Charles i will try  ;)

Charles Pegge

  • Guest
Re: do we can this to?
« Reply #3 on: April 24, 2015, 03:34:55 AM »
You can also build the table this way, of course:

Assigning with a specific index will make the code clearer when there are many jump targets.

Code: OxygenBasic
  1. sys t[100]
  2. indexbase 1
  3. t[1]=@AA
  4. t[2]=@BB
  5. t[3]=@CC
  6. ...
  7.