allow GOTO to also jmp to integer variables (dynamic)

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: allow GOTO to also jmp to integer variables (dynamic)

Post by Josh »

nco2k wrote:same reason why ascii was removed. :wink:
Nonsense, Ascii was removed to reduce the administrative overhead for the Pb team.
sorry for my bad english
User avatar
langinagel
Enthusiast
Enthusiast
Posts: 131
Joined: Fri Jan 28, 2005 11:53 pm
Location: Germany
Contact:

Re: allow GOTO to also jmp to integer variables (dynamic)

Post by langinagel »

At least nice to see that my point of view is shared.

THX nco2k
https://www.doerpsoft.org

Boost. Work. Efficiency.
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Re: allow GOTO to also jmp to integer variables (dynamic)

Post by GPI »

for GOSUB - it think it should be really removed, because procedures can do everything, that gosub can do, but i a better, easier way.

But Goto - goto is like an ejection seat. Don't use it every time, only on emergencys :)

There a reason, why, for example, a goto to a diffrent procedure is imposible. An Goto to a pointer can easlier cause very hard to detect errors. Also a jump outside a structure can theoretically cause really bad things.

Can you post a example-Code, where you need "Goto" on pointers? Maybe there is a simpler better Method to solve your problem.
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: allow GOTO to also jmp to integer variables (dynamic)

Post by Keya »

GPI wrote:Can you post a example-Code, where you need "Goto" on pointers? Maybe there is a simpler better Method to solve your problem.
well the particular one that made me post the request was because i had to use inline assembly for a jmp into my jump table, a Goto would've been ideal and then i wouldn't need two CompilerIf/ElseIfs to handle jmp dword/qword for x86/64 http://purebasic.fr/english/viewtopic.php?f=12&t=67044
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: allow GOTO to also jmp to integer variables (dynamic)

Post by Josh »

GPI wrote:Can you post a example-Code, where you need "Goto" on pointers? Maybe there is a simpler better Method to solve your problem.
Or Here
sorry for my bad english
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Re: allow GOTO to also jmp to integer variables (dynamic)

Post by GPI »

ok, thats a very spezific problem :)

on C64-Basic there was a "on xx goto label1,label2,label3,label4..." - maybe this would be nice in PB.

But in your case maybe a Macro should be a good solution:

Code: Select all

Macro GotoVariable(Variable)
;   CompilerIf #PB_Compiler_Procedure=""
    CompilerIf #PB_Processor_x64
      ! jmp qword [v_#variable]
    CompilerElse
      ! jmp dword [v_#variable]
    CompilerEndIf
   CompilerElse
     ;Sorry don't know how to access a protected Variable in Asm here....
   CompilerEndIf
  
EndMacro

Procedure test2()
  Protected a
  a=?label
  
  GotoVariable(a)
  
  Debug "Never2"
  label:
  Debug "ok2"
EndProcedure


a=?label
GotoVariable(a)
Debug "never"


label:
Debug "OK"
test2()

Macro is incomplete, because i don't know the command to access the protected variable
User avatar
langinagel
Enthusiast
Enthusiast
Posts: 131
Joined: Fri Jan 28, 2005 11:53 pm
Location: Germany
Contact:

Re: allow GOTO to also jmp to integer variables (dynamic)

Post by langinagel »

I remember the On x GOTO 100,200,300 command.
But in Purebasic we have Procedures.
Why not a SELECT instead?

Code: Select all

SELECT a
 case 0
 Procedure_1()
 case 1
 Procedure_2()
 case 3
 Procedure_3()
 default
 Procedure_1()
 Endselect 
Should be easier to maintain.

Greetings
LN
https://www.doerpsoft.org

Boost. Work. Efficiency.
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: allow GOTO to also jmp to integer variables (dynamic)

Post by Josh »

langinagel wrote:But in Purebasic we have Procedures.
But I'm not willing to to create some hundred procedures
langinagel wrote:Why not a SELECT instead?

Code: Select all

SELECT a
 case 0
 Procedure_1()
 case 1
 Procedure_2()
 case 3
 Procedure_3()
 default
 Procedure_1()
 Endselect 
Should be easier to maintain.
Always smoking a cigarette while the processor is calculating, wouldn't good for my health :?
sorry for my bad english
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: allow GOTO to also jmp to integer variables (dynamic)

Post by Keya »

Keya wrote:
GPI wrote:Can you post a example-Code, where you need "Goto" on pointers? Maybe there is a simpler better Method to solve your problem.
well the particular one that made me post the request was because i had to use inline assembly for a jmp into my jump table, a Goto would've been ideal and then i wouldn't need two CompilerIf/ElseIfs to handle jmp dword/qword for x86/64 http://purebasic.fr/english/viewtopic.php?f=12&t=67044
GPI wrote:But in your case maybe a Macro should be a good solution:

Code: Select all

Macro GotoVariable(Variable)
;   CompilerIf #PB_Compiler_Procedure=""
    CompilerIf #PB_Processor_x64
      ! jmp qword [v_#variable]
    CompilerElse
      ! jmp dword [v_#variable]
    CompilerEndIf
   CompilerElse
     ;Sorry don't know how to access a protected Variable in Asm here....
   CompilerEndIf
EndMacro
But that's just a wrapper for the jmp instruction i'm already having to use, using the two CompilerIf/Else directives i mentioned it'd be good not to have to type :) ... another good example of why Goto <Address> would be better :)
Post Reply