Author Topic: Global labels  (Read 3328 times)

0 Members and 3 Guests are viewing this topic.

Brian Alvarez

  • Guest
Global labels
« on: June 29, 2019, 11:36:49 AM »
  Hello Charles, i havent tested the global labels. What is the status of them?

I am at the point that PluriBASIC can compile itself... if it just had a free jumping goto. :)

Charles Pegge

  • Guest
Re: Global labels
« Reply #1 on: June 29, 2019, 01:12:14 PM »
Hi Brian,

Global labels were implemented in 0.2.0 (07/06/2019)

Code: [Select]
'22:02 29/06/2019
'global labels
int a=0
goto .inside
if a
  if a
    ..inside
    print "here inside"
  endif
endif

Will you need backward goto for global labels?
« Last Edit: June 29, 2019, 02:13:21 PM by Charles Pegge »

Brian Alvarez

  • Guest
Re: Global labels
« Reply #2 on: June 29, 2019, 03:45:35 PM »
 Do you mean jumping to an earlier line? If so... yes. I will make some tests tonight. :)

 Thanks!

Charles Pegge

  • Guest
Re: Global labels
« Reply #3 on: June 29, 2019, 05:42:13 PM »
The linker will require some extra house-keeping to maintain previous labels.

Brian Alvarez

  • Guest
Re: Global labels
« Reply #4 on: June 29, 2019, 09:06:16 PM »
Okay. Should i hold my tests then?

Charles Pegge

  • Guest
Re: Global labels
« Reply #5 on: July 01, 2019, 07:04:08 AM »
I've just released version 0.2.2 supporting global goto in both directions.

All I can say is avoid spaghetti code and a maintenance nightmare, choose instead tortilla code which has well defined interiors and exteriors!

Brian Alvarez

  • Guest
Re: Global labels
« Reply #6 on: July 01, 2019, 11:05:10 AM »
That is what i do. Sometimes a GOTO saves me from adding extra code. Reuse existing one. :)

 Thanks!

Brian Alvarez

  • Guest
Re: Global labels
« Reply #7 on: July 01, 2019, 11:07:44 AM »
A couple questions though...
  • By Global goto you mean global like in... across functions? That does sound dangerous. I hope its not that.
  • Is it a global GOTO or also a GOSUB?
I will make tests tonight.

Charles Pegge

  • Guest
Re: Global labels
« Reply #8 on: July 02, 2019, 05:14:48 AM »
Global labels have no restrictions, and work with goto gosub jmp call and @ & addressing.

The default linkage is to first search backwards for a label, before referencing forwards. But backwards searching can be inhibited with expressions like:

goto next xyz
jmp fwd xyx


I'll look into the best method of confining gotos etc within procedures, but it may require major work on the linker.

Brian Alvarez

  • Guest
Re: Global labels
« Reply #9 on: July 02, 2019, 12:03:45 PM »

If that is a problem, then dont worry. I will handle it here. Something like a prefix will do.

Brian Alvarez

  • Guest
Re: Global labels
« Reply #10 on: July 03, 2019, 09:26:42 PM »
Hello Charles. I Just finished making the changes to my engine so that it generates label names according to yor newest example for goto/gosub.

 However when i try to compile my code, it complains about ZSTRING2 not defined, do, i cannot make any tests. I'm sorry maybe you announced it somewhere else but i dont find any news about it being removed... was it removed? renamed? is this a missbehavior?

 Thanks!

Brian Alvarez

  • Guest
Re: Global labels
« Reply #11 on: July 03, 2019, 09:52:34 PM »
 I went back a few weeks and the dll worked. I am doint tests for the new goto gosub! :D It seems to work!

 I can now jump inside blocks... but i found an issue. Well... not an issue, just maybe something that is not
entirely compatible with it.

 I have this code (pluribasic, untranslated, but you get the idea):

Code: [Select]
        int i = 0 ' initialize the variable manually

        'goto manual ' manually initialized! jump in!

        for (i = 0; i < 10; i++) {           
               
                stdout "normal: " + str$(i)
               
                manual:
               
                stdout "manual: " + str$(i)       
            }
           
        stdout "done."

This code (correctly) outputs this:

Code: [Select]
normal:  0
manual:  0
normal:  1
manual:  1
normal:  2
manual:  2
normal:  3
manual:  3
normal:  4
manual:  4
normal:  5
manual:  5
normal:  6
manual:  6
normal:  7
manual:  7
normal:  8
manual:  8
normal:  9
manual:  9
done.

If i un-remark the GOTO assuming the i variable has been correctly initialized, and jump in the loop, it outputs this:

Code: [Select]
manual:  0
done.

 But i was expecting this:

Code: [Select]
manual:  0
normal:  1
manual:  1
normal:  2
manual:  2
normal:  3
manual:  3
normal:  4
manual:  4
normal:  5
manual:  5
normal:  6
manual:  6
normal:  7
manual:  7
normal:  8
manual:  8
normal:  9
manual:  9
done.

How does for/next blocks work? Is the condition checked at th beggining or at the end of the for/next block? or both?

P.S. I understand that i am doing the equivalent of a 360 Inward Heelflip, but please bear with me.

Brian Alvarez

  • Guest
Re: Global labels
« Reply #12 on: July 14, 2019, 01:40:09 AM »
...when i try to compile my code, it complains about ZSTRING2 not defined, do, i cannot make any tests. I'm sorry maybe you announced it somewhere else but i dont find any news about it being removed... was it removed? renamed? is this a missbehavior?

Hello Charles, any news on this? I would like to test te newest goto/gosub functionality...

(looking for goto to an earlier label)


Charles Pegge

  • Guest
Re: Global labels
« Reply #13 on: July 15, 2019, 12:46:48 AM »
Hi Brian,

Sorry I missed your earlier posts.

0.2.3 is nearly ready, and includes the restricted global labels which confine goto and gosub within the body of a procedure.

Some changes to wide string type names for consistency:

wstring
wbstring
wzstring
wchar



For loops have initialisation and test at the top, and step at the bottom:

Code: [Select]
for i=1 to 100 step 10
  ...
next

translates to:
Code: [Select]
i=1
do
   if i>100 then exit do
  ...
  i+=10
loop

Charles Pegge

  • Guest
Re: Global labels
« Reply #14 on: July 15, 2019, 01:36:40 AM »
My test cases for restricted (global) labels:

Code: [Select]
'09:55 15/07/2019
'
'restricted proc labels
'
'goto .inside1 'error

function f1()
  'goto .inside1 'ok
  if 0
    ..inside1
    print "inside1"
    exit function
  endif
  'goto .inside1 'ok
  'goto .inside2 'error
end function

function f2()
  'goto .inside2 'ok
  if 0
    ..inside2
    print "inside2"
    exit function
  endif
  'goto .inside2 'ok
  'goto .inside1 'error
end function

'goto .inside1 'error
'goto .inside2 'error

f1
f2
'print "ok"