Page 6 of 25

Re: PureBasic 5.20 beta 4 is ready to test !

Posted: Fri Jun 28, 2013 7:17 pm
by davido
@Fred
Just downloaded it. Looks fine. :D

Thank you for all the hard work.

Re: PureBasic 5.20 beta 4 is ready to test !

Posted: Fri Jun 28, 2013 7:31 pm
by DoubleDutch
Thanks

Re: PureBasic 5.20 beta 4 is ready to test !

Posted: Fri Jun 28, 2013 8:40 pm
by Rescator
Awesome! A large project I'm working on here compiles fine with debugger both on and off with Beta4.
Only had to do two minor edits (two constant name changes).

Go Fred! :)

Re: PureBasic 5.20 beta 4 is ready to test !

Posted: Fri Jun 28, 2013 9:07 pm
by luis
Thanks.

Re: PureBasic 5.20 beta 4 is ready to test !

Posted: Fri Jun 28, 2013 9:45 pm
by Psychophanta
:D

Re: PureBasic 5.20 beta 1 is ready to test !

Posted: Sat Jun 29, 2013 4:56 pm
by charvista
Kwaï chang caïne wrote:

Code: Select all

Added: Gosub are now allowed again inside Procedure
An old request....thanks a lot FRED 8)
KCC saw somewhere that Gosub is now allowed inside Procedure (I don't see it however).
With the beta 3 I still cannot.
I need to know if the Gosub within procedures will come, yes or no.
If Yes, I will wait for the definitive launching of 5.20.
If No, when then, Ever or Never?
This to avoid a mess in my programming, Gosub would be REALLY great.
Thanks for confirming.
Cheers

Re: PureBasic 5.20 beta 4 is ready to test !

Posted: Sat Jun 29, 2013 5:22 pm
by skywalk
Fred wrote:update: beta 2 is available and with the usual bug fixes. As well, zlib have been updated to 1.2.8 and Gosub in procedure have been removed as it can't work for now.
Gosub Bug...

Re: PureBasic 5.20 beta 4 is ready to test !

Posted: Sat Jun 29, 2013 5:40 pm
by charvista
OK, thanks Skywalk. Maybe for v5.30 then :cry:
Danilo wrote last year in april an assembler routine that seemed to work, but I have issues with variables now. Here is Danilo's version again:

Code: Select all

;*====================*===========================================================================================================*
;| Macro .............| mSub
;| Description .......| Gosub in procedures
;| Syntax ............| mSub
;| Parameter(s) ......|
;| Author(s) .........| Danilo
;| Version(s) ........| 2012-04-24
;*--------------------*-----------------------------------------------------------------------------------------------------------*
;| Remarks ...........|
;| Usage example .....|
;*====================*===========================================================================================================*

; The following initializations are required; they are in #Constants.pbi
;******************************************************************************************
; #SUB_STACKSIZE = 100000; number of possible nested subs 
; Global __Sub_ReturnAddress__.s{(#SUB_STACKSIZE+1)*(SizeOf(Integer)/SizeOf(character))}
; Global __Sub_ReturnIndex.i
;******************************************************************************************

;=================================================================================================================================*
Macro mSub(_name_)
    CompilerIf #PB_Compiler_Processor = #PB_Processor_x86 Or #PB_Compiler_Processor = #PB_Processor_x64
        !EndSub_Name equ __EndSub_#_name_
        !  JMP EndSub_Name
        !_sub_#_name_:
    CompilerElse
        CompilerError "Macro Sub(): unsupported processor"
    CompilerEndIf
EndMacro
;=================================================================================================================================*
Macro mExitSub
    CompilerSelect #PB_Compiler_Processor
        CompilerCase #PB_Processor_x86
            !  MOV dword EAX, v___Sub_ReturnAddress__
            !  MOV dword EDX, [v___Sub_ReturnIndex]
            !  JMP dword [EAX+EDX*4]
        CompilerCase #PB_Processor_x64
            !  MOV RAX, v___Sub_ReturnAddress__
            !  MOV R8, [v___Sub_ReturnIndex]
            !  JMP qword [RAX+R8*8]
        CompilerDefault
            CompilerError "Macro ExitSub: unsupported processor"
    CompilerEndSelect
EndMacro
;=================================================================================================================================*
Macro mEndSub
    mExitSub
    !EndSub_Name:
EndMacro

; Macro mEndSub
;     CompilerSelect #PB_Compiler_Processor
;         CompilerCase #PB_Processor_x86
;             !  MOV dword EAX, v___Sub_ReturnAddress__
;             !  MOV dword EDX, [v___Sub_ReturnIndex]
;             !  JMP dword [EAX+EDX*4]
;             !EndSub_Name:
;         CompilerCase #PB_Processor_x64
;             !  MOV RAX, v___Sub_ReturnAddress__
;             !  MOV R8, [v___Sub_ReturnIndex]
;             !  JMP qword [RAX+R8*8]
;             !EndSub_Name:
;         CompilerDefault
;             CompilerError "Macro EndSub: unsupported processor"
;     CompilerEndSelect
; EndMacro
;=================================================================================================================================*
Macro mCall(_name_)
    CompilerSelect #PB_Compiler_Processor
        CompilerCase #PB_Processor_x86
            !  INC dword [v___Sub_ReturnIndex]
            !  MOV dword EAX, v___Sub_ReturnAddress__
            !  MOV dword EDX, [v___Sub_ReturnIndex]
            !  MOV dword [EAX+EDX*4], @f
            !  JMP _sub_#_name_
            !@@:
            !  DEC dword [v___Sub_ReturnIndex]
        CompilerCase #PB_Processor_x64
            !  INC qword [v___Sub_ReturnIndex]
            !  MOV R9, @f
            !  MOV RAX, v___Sub_ReturnAddress__
            !  MOV R8, [v___Sub_ReturnIndex]
            !  MOV qword [RAX+R8*8],R9
            !  JMP _sub_#_name_
            !@@:
            !  DEC qword [v___Sub_ReturnIndex]
        CompilerDefault
            CompilerError "Macro Call(): unsupported processor"
    CompilerEndSelect
EndMacro
;=================================================================================================================================*
And today I am trying using Goto's... (spaghetti-code!) while awaiting for the real Gosub inside procedures...

Code: Select all

; Procedure a()
;     v.i=5
;     Gosub aa
;     Debug v
;     ProcedureReturn
;     
;     aa:
;     v+8
;     Return
;     
; EndProcedure



Procedure b()
    v.i=5
    
    Locate=1 : Goto bb
    bb1:
    Debug v
    ProcedureReturn
    
    bb:
    v+8
    If Locate=1 : Goto bb1 : EndIf
    
EndProcedure



;a()
b()
skywalk wrote:"that Fred has written:

it can't work for now.
So hopefully it will come any day.

Re: PureBasic 5.20 beta 1 is ready to test !

Posted: Sat Jun 29, 2013 5:42 pm
by RichAlgeni
charvista wrote:I need to know if the Gosub within procedures will come, yes or no.
If Yes, I will wait for the definitive launching of 5.20.
If No, when then, Ever or Never?
This to avoid a mess in my programming, Gosub would be REALLY great.
Thanks for confirming.Cheers
You have over 700 posts, so I will not presume that you are a newbie when it comes to coding, but is this something you can do with a procedure? I'd be glad to try and help you, as would many on the forums. I was a big proponent of using Gosubs, but because of the power of procedures, I never use them anymore.

Re: PureBasic 5.20 beta 4 is ready to test !

Posted: Sat Jun 29, 2013 6:27 pm
by charvista
RichAlgeni wrote:is this something you can do with a procedure?
Sure, it can. The only (and big) difference, is that we need to bring all the necessary variables through the argument parameters. Plus, that there is no ByRef possibility (only ByVal), so there is no way to give back the modified variables to the caller -- except with an array, but that is not convenient. And yes, pointers are also possible, and I am using them when absolutely necessary, for integers it is easy, but when you have strings, hello complications... especially when this pointer is calling a second procedure level! If we modify the program later, we need to update the procedure's arguments, plus the Declare as well!
A Gosub is very simple and all variables are available.
Yes, procedures are powerful, but their concept is different.

I just remember that even Goto has problems: it may not be used within a Select block, otherwise variables will lose their values, and the program *can* hang. So probably the same for Gosub, because it is in fact internally nothing more than two Gotos.
RichAlgeni wrote:I'd be glad to try and help you
Thank you RichAlgeni. I am also happy when I can help someone :)

Re: PureBasic 5.20 beta 4 is ready to test !

Posted: Sat Jun 29, 2013 7:33 pm
by RichAlgeni
charvista wrote:And yes, pointers are also possible, and I am using them when absolutely necessary, for integers it is easy, but when you have strings, hello complications...
You are right, pointers are complicated to use, but once you get used to them, pointers can be WONDERFUL! I do use Global strings, but mostly just as parameters. I never pass strings to a procedure, it it doubles the memory use for the string, and like you know, you don't get modifications back.

You do have to account for the string size, but I pass that do when needed. You can pass integers as a pointer, but you are only required to do so when you need to modify the integer.

I try to create small, process independent procedures, that way I can 'include' them into new programs.

Everyone has their own style and way of doing things. No one way is best, but I've found that avoiding Gosub's and especially Goto's are the best way for me to code. I also teach that way, and find that once students get used to no gosub's and goto's, they don't really miss them.

Rich

Re: PureBasic 5.20 beta 4 is ready to test !

Posted: Sat Jun 29, 2013 11:57 pm
by charvista
RichAlgeni wrote: pointers can be WONDERFUL!
I agree!
I am using global variables only as a type of constants that can be changed later. I recognize my constant variables by prefixing an underscore to the variable, ex: _DW.
It looks like you are a school teacher. Are you teaching PureBasic? Interesting.
I have written a little program that helps me how the variables need to be used when they are passed as pointer, because I cannot remember them easily.
First time, you use @var, then use *var\s, but when passing to a second level proc, use *var. That's why I prefer the "basic" var.s !

If pointers are so fast, I wonder why the standard variables are not pointers internally... but I am sure there is a good reason!

I am using Goto often, but rarely. Do you get it? :wink:

Code: Select all

; this is how to use ByRef with string variables

Procedure shower(cont.s) ; here using standard variable, so no change at exit
    cont.s+" Africa." : Debug cont.s
EndProcedure


Procedure addmore(*v.string)
    *v\s+" Asia." : Debug *v\s
EndProcedure


Procedure change(*v.string)
    *v\s+" America." : Debug *v\s
    addmore(*v)      : Debug *v\s
    shower(*v\s)     : Debug *v\s
EndProcedure




;start =================================================================
Define.string tvar, alpha ; or Define tvar.string

tvar\s="Europe." : Debug tvar\s
change(@tvar)    : Debug tvar\s
Debug tvar; this will show the pointer number!




Debug "================================================================"
; and this is how to use ByRef with integer variables (same rule applies to double, long, quad)

Procedure intshow(ival.i)
    ival.i+14 : Debug ival
EndProcedure

Procedure intchangemore(*i.integer)
    *i\i+27 : Debug *i\i
EndProcedure

Procedure intchange(*i.integer)
    *i\i+15           : Debug *i\i
    intchangemore(*i) : Debug *i\i
    intshow(*i\i)     : Debug *i\i
EndProcedure

;start =================================================================
i.i=17        : Debug i.i
intchange(@i) : Debug i.i
Debug i; this, in contrast to strings, it shows the real value! (only for integers)
Please let me know if this is the good way. And of course, you can use it as a reference for your students.
Cheers

Re: PureBasic 5.20 beta 4 is ready to test !

Posted: Sun Jun 30, 2013 1:21 pm
by Fred
Please use a different thread for such questions, it's annoying, thanks.

Re: PureBasic 5.20 beta 5 is ready to test !

Posted: Sun Jun 30, 2013 6:57 pm
by RichAlgeni
Fred is exactly right, my fault!

@Charvista, create a post in coding questions, that way more will feel free to contribute.

Re: PureBasic 5.20 beta 5 is ready to test !

Posted: Sun Jun 30, 2013 7:21 pm
by c4s
I like how fast you guys are. Thanks for releasing another beta! :o