Amiga BlitzBasic2 do it, and it is useful.
Please think that a function is a program; or said almost samething in other way, a program is a function.
Moreover, it should be another big and greeeat difference and advantage over C/C++

Code: Select all
Procedure Sub(nu)
!label1:
!CALL .str
!jmp @f
!.str:
!mov eax,dword[esp+4]
!inc eax
!ret
!@@:
ProcedureReturn
EndProcedure
Debug Sub(74)
Code: Select all
Procedure Sub(nu)
!label1:
!mov eax,dword[esp]
!times 400 CALL near .str0
ProcedureReturn
!.str0:times 300 call .str
!ret
!.str:
!times 4 call out1.out1
!inc eax
!ret
EndProcedure
Debug Sub(0)
end
!out1:
!.out1:inc eax
!ret
No, that's not more difficult, this is what Fred means:Psychophanta wrote:Yeah...
Still more difficult:This works, and that means Gosub should work tooCode: Select all
Procedure Sub(nu) !label1: !mov eax,dword[esp] !times 400 CALL near .str0 ProcedureReturn !.str0:times 300 call .str !ret !.str: !times 4 call out1.out1 !inc eax !ret EndProcedure Debug Sub(0) end !out1: !.out1:inc eax !ret
Code: Select all
Procedure.l go_sub(a, b, c)
If a = 1
!call lbl_a1
EndIf
Debug "a="+Str(a)+", b="+Str(b)+", c="+Str(c)
ProcedureReturn
!lbl_a1:
a = b+c
!ret
EndProcedure
go_sub(1, 1, 1)
Well I'm used to different variants of Subroutines:Psychophanta wrote:I think it should be easy to implement to PB the ability to call a routine ( basic command Gosub) from inside a function to inside that function.
Amiga BlitzBasic2 do it, and it is useful.
Please think that a function is a program; or said almost samething in other way, a program is a function.
Moreover, it should be another big and great difference and advantage over C/C++
Code: Select all
Procedure.l go_sub(d,f,g)
Shared a,b,c
If a = 1
!call lbl_a1
EndIf
Debug "a="+Str(a)+", b="+Str(b)+", c="+Str(c)
ProcedureReturn
!lbl_a1:
a = b+c
!ret
EndProcedure
a=1:b=1:c=1
go_sub(1,1,1)
Adaptation by me:fsw wrote:
Just popped in my mind:
if it's to critical to jump to a label outside a procedure, maybe it's possible to allow GoSub inside procedures like in XBasic/XBlite.
Code: Select all
Procedure.l go_sub(d,f,g)
Shared a,b,c
If a = 1
GoSub lbl_a1
EndIf
Debug "a="+Str(a)+", b="+Str(b)+", c="+Str(c)
ProcedureReturn
lbl_a1:
a = b+c
Return
EndProcedure
a=1:b=1:c=1
go_sub(1,1,1)
I see - this does not work out:Fred wrote:Yes, the problem is when you deal with local variables. Global variables are not affected by this limitation.
Code: Select all
Procedure.l go_sub2(d,f,g)
a=d:b=f:c=g
If a = 1
!call go_sub1_lbl_a1
EndIf
Debug "a="+Str(a)+", b="+Str(b)+", c="+Str(c)
ProcedureReturn
!go_sub2_lbl_a1:
a = b+c
!ret
EndProcedure
go_sub2(1,1,1)
Code: Select all
Procedure.l go_sub(a, b, c)
If a = 1
!jmp near lbl_a1;<-a Gosub here write next address (rett) into at compilation time and then just jumps.
!rett:; |
EndIf; |
; /
Debug "a="+Str(a)+", b="+Str(b)+", c="+Str(c) ; |
ProcedureReturn ; /
; /
!lbl_a1:; /
; /
a = b+c; /
!jmp near rett;<-------------------------------------------/
EndProcedure
go_sub(1, 1, 1)