Enhanced Restore/Goto/Gosub commands

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Enhanced Restore/Goto/Gosub commands

Post by DoubleDutch »

Having the restore/goto/gosub commands enhanced to support expressions would be good.

I know it would break compatibility, as existing code would have to be changed from something like:

Code: Select all

Restore Mydata
to:

Code: Select all

Restore ?MyData
But changing the commands would be *very* useful and make it overall a lot more consistant.

You could possibly add different commands to keep existing code working, the new commands could be:

Code: Select all

Restore(expression)
Goto(expression)
Gosub(expression)
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

I have been searching through the forum a request i made for that in the past, but i don't find it :roll: It was only for Restore.
So i second that.
Restore <Expression>
Goto <Expression>
Gosub <Expression>

In fact i would request for defined labels to be treated as common long typed variables. So the feature requested in this thread would automatically done. :)
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

Another good feature would be to be able to discover the current pointer memory position. So you could save it for later restoration. Having multiple 'Read' parameters would also be good.

eg:

Code: Select all

Position=Data()
.
.
Read this, that, blah$
.
.
Restore Position
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

DoubleDutch wrote:Having multiple 'Read' parameters would also be good.

eg:

Code: Select all

Position=Data()
.
.
Read this, that, blah$
.
.
Restore Position
Definately a good idea, old basics used to allow this.
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

It would also be good if PureBasic "knew" that data type from the actual data, rather from the Data command itself.

eg:

Code: Select all

Data "string", 90, 4.b, "string again"
Would have a string, a long, a byte and then another string.

If all these enhancements were made then a nice side effect would be that you could load a binary file into memory then:

Code: Select all

Restore memoryaddr
Read String$, check, flag.b
Instead of having to peek through memory and keep updating pointers like:

Code: Select all

position=memoryaddr
String$=PeekS(position)
position+len(String$)+1
check=PeekL(position)
position+4
flag=PeekB(position)&$ff
position+1
The enhanced solution looks nicer and is easier to follow.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

DoubleDutch wrote:Another good feature would be to be able to discover the current pointer memory position. So you could save it for later restoration. Having multiple 'Read' parameters would also be good.

eg:

Code: Select all

Position=Data()
.
.
Read this, that, blah$
.
.
Restore Position
Oops! I believed the multiple 'Read' parameters feature was already implemented :o
What about this syntax for the 'Read' word?
Read [From <position>,] <variable1> [,variable2, variable3...]

BTW: there is a bug in the PB manual (dunno if already reported). It wrote:
Syntax
Read
and it is wrong because the syntax requires a variable as parameter, i.e. The word 'Read' alone is a syntax error :!: .
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

Oops! I believed the multiple 'Read' parameters feature was already implemented
Really, thats good. :)

All I see in the help on Read syntax is:
Syntax
Read

Description

Read the next available data. The next available data can be changed by using the Restore command. By default, the next available data is the first data declared.
Which is of course (as you mentioned) incorrect.

I did a quick look for other infor on read but all the examples (with restore/data) imply that its single parameters.

Edit:
I just did a quick test and:

Code: Select all

Read	id,flags,x.w,y.w,w.w,h.w,text$
results in a garbage at end of line error.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

This code will allow you to read the current data pointer easily...

Code: Select all

Procedure RestorePointer()
	!MOV eax,dword [PB_DataPointer]
	ProcedureReturn
EndProcedure

Debug("Uninitialised restore pointer: "+Hex(RestorePointer()))

Restore MyData

Debug("MyData address: "+Hex(?MyData))
Debug("Current restore pointer: "+Hex(RestorePointer()))

Read var
Debug("Restore pointer after read: "+Hex(RestorePointer()))

DataSection
MyData:
	Data.l	123
EndDataSection
I tried to extend this with:

Code: Select all

Procedure RestorePointer(position=0)
	!MOV eax,dword [PB_DataPointer]
	!MOV edx,dword [p.v_position]
	!CMP edx,0
	!JE	@f
	!MOV dword [PB_DataPointer],edx
!@@
	ProcedureReturn
EndProcedure

Debug("Uninitialised restore pointer: "+Hex(RestorePointer()))

Restore MyData

Debug("MyData address: "+Hex(?MyData))
Debug("Current restore pointer: "+Hex(RestorePointer()))

Read var
Debug("Restore pointer after read: "+Hex(RestorePointer(?MyData)))
Debug("Restore pointer after optional setting: "+Hex(RestorePointer()))

DataSection
MyData:
	Data.l	123
EndDataSection
But I get an error on compilation with the !@@ line, purebasic insists that it is an illegal instruction, but it's actually a way of doing anonymous labels in fasm.
Fasm documentation wrote:The @@ name means anonymous label, you can have defined many of them in the source. Symbol @b (or equivalent @r) references the nearest preceding anonymous label, symbol @f references the nearest following anonymous label. These special symbol are case-insensitive.
Is this a bug in the PureBasic compiler? I thought that ! would pass anything following (on the same line) direct to fasm without checks or interference.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

When you define a label you need to put a : after it.
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

Oops! It was staring me in the face!

I've added this to tricks n tips:
http://www.purebasic.fr/english/viewtop ... 372#229372

Here is a post with info on how to goto/gosub a variable and a psuedo on goto/gosub:

http://www.purebasic.fr/english/viewtop ... 381#229381
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
Post Reply