Select ...Case...

BlitzMax Forums/BlitzMax Beginners Area/Select ...Case...

_33(Posted 2007) [#1]
I wish to know, in BlitzMax, if a Select Case using a Byte would compile using a jump table?

Thanks.


H&K(Posted 2007) [#2]
no
http://www.blitzmax.com/Community/posts.php?topic=71252#796832


_33(Posted 2007) [#3]
Yikes!!! OMG, how adventurous should we be with BMAX??? Any substitutes anyone came up with? I'm thinking about a pointer list or something in the likes. Say a 256 INT table containing function pointers, or goto pointers or labels, and that we could just use that as our jump table.

Toughts?


Dreamora(Posted 2007) [#4]
goto: Not existant in strict. BM code without strict is inacceptable

You don't need to be adventurous. If you need insane speed, don't use GC managed language.
BM is by far fast enough, you don't need to worry for such stuff. If you do, you better write it in ASM and import the assembler file :)


GfK(Posted 2007) [#5]
BM code without strict is inacceptable
No it isn't. Its a preference.


H&K(Posted 2007) [#6]
Yikes!!! OMG, how adventurous should we be with BMAX??? Any substitutes anyone came up with? I'm thinking about a pointer list or something in the likes. Say a 256 INT table containing function pointers, or goto pointers or labels, and that we could just use that as our jump table
I see you didnt read the thread I posted, which was only 2 days old.


Dreamora(Posted 2007) [#7]
Gfk: No its inacceptable as the compiler and some inner workings are different if no Strict / SuperStrict is applied. (variable scope as the single problem you will realize first)

The only real reason for goto is to leave loops and for that reason BM has loop lables to jump out of any number of nested loops or continue them.

Above that, you can not do variable gotos anyway, so it won't help in this situation.


_33(Posted 2007) [#8]
I've read what you linked me to H&K.

Dreamora
You don't need to be adventurous. If you need insane speed, don't use GC managed language.
BM is by far fast enough, you don't need to worry for such stuff. If you do, you better write it in ASM and import the assembler file :)


Do you think it's acceptable to have, say 200 jumps to the next condition in hope of finding what corresponds (Select...Case) in your compiled BMX when you could actually have a single jump referenced by a jump table? I'll have to see if I can find something in BlitzMax that could do this. Just a shame that the language has the Byte type, but no jump table to use it, in this case.

And no, I can't use assembler to do what I wish to do as it's an ANSI code interpreter.


Dreamora(Posted 2007) [#9]
and why can't you? whats actually holding you back doing it?
as everything you write in something else will end earlier or later as an ASM its clearly doable in ASM :-)


But you could use something like this as well if you are able to put the "case" parts into functions:

   
Strict

Graphics 800,600

Global funcTable()[256]


For Local i:Int = 0 To 255
	funcTable[i] = printAscii
Next

Global char:Int
While Not KeyHit(key_escape)
	Cls
	
	char = GetChar()
	funcTable[char]()
	
	DrawText "char: " + char, 0, 0
	Flip
Wend
char = 1
printAscii()

WaitKey()


Function printAscii()
	Print "Ascii: " + char
End Function


this is just a simple example to show you what I mean


_33(Posted 2007) [#10]
Oh, well :)

Ah! So you can do this funcTable[char]() in BlitzMax?

Interesting. This would definately solve the problem if it does work. I'll try it out right now.

Yep this does work. Seems you found what most everyone's after with the jump table.

Thanks! And this is another plus for BlitzMax that makes it a desirable language for me. Good.

Oh, and I'm not saying I won't write small assembler code in BlitzMax to perform stuff like filling up a table, or creating textures, with MMX or SSE. It's all possible in BlitzMax from what I heard, but definately not in Blitz3D.


Dreamora(Posted 2007) [#11]
Yes, you can do function pointer (and arrays of them) in BM, something badly missing in Blitz3D, right ...

Although I normally use it for callbacks :-)


H&K(Posted 2007) [#12]
@_33 It just shocked me that two of your proposed solutions where ones that thread had said you couldnt have, and that it said what the solutuon was, but you still waited till dream said it as well.
But hah, who cares, we all have solutions now


_33(Posted 2007) [#13]
Sorry I was distracted.


MGE(Posted 2007) [#14]
Dreamora, how come I can't do this? And do you have a solution then? Thanks!
Global FuncPointer()
'
SetFunctionPointer(Test)
FuncPointer()
'
Function SetFunctionPointer(Func)
 FuncPointer = Func
End Function
'
Function Test()
 Print "It worked!"
End Function



ImaginaryHuman(Posted 2007) [#15]
Looks like it should work.


TomToad(Posted 2007) [#16]
MGE Developer:
Global FuncPointer()
'
SetFunctionPointer(Test)
FuncPointer()
'
Function SetFunctionPointer(Func())
 FuncPointer = Func
End Function
'
Function Test()
 Print "It worked!"
End Function



_33(Posted 2007) [#17]
haaa... Of course! I feel good being a rookie in BlitzMax. Lots of nice little surprises.


MGE(Posted 2007) [#18]
hey.. I've only had BMax for 2 weeks so far, lots of little things to learn!!! TomToad - uh...holy !@#$% you just solved a problem I've had for days!!! So this thread won't be too much off topic, I'm going to start another. Thanks!!!


Dreamora(Posted 2007) [#19]
Only to clarify that.

BM is a typesafe language.
So the input and output of a function must remain the same!

You can not assign func:int(int) to func(float) or anything the like. It is only compatible to a function with the same header, much like delegates.