Page 2 of 2

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

Posted: Mon Mar 20, 2017 4:05 am
by Josh
nco2k wrote:same reason why ascii was removed. :wink:
Nonsense, Ascii was removed to reduce the administrative overhead for the Pb team.

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

Posted: Tue Mar 21, 2017 7:18 pm
by langinagel
At least nice to see that my point of view is shared.

THX nco2k

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

Posted: Wed Mar 22, 2017 3:38 pm
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.

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

Posted: Wed Mar 22, 2017 5:08 pm
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

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

Posted: Wed Mar 22, 2017 5:16 pm
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

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

Posted: Wed Mar 22, 2017 6:29 pm
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

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

Posted: Wed Mar 22, 2017 7:57 pm
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

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

Posted: Wed Mar 22, 2017 9:02 pm
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 :?

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

Posted: Thu Mar 23, 2017 3:26 am
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 :)