Oxygen Basic

Information => Development => Topic started by: Brian Alvarez on June 29, 2019, 11:36:49 AM

Title: Global labels
Post by: Brian Alvarez 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. :)
Title: Re: Global labels
Post by: Charles Pegge 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?
Title: Re: Global labels
Post by: Brian Alvarez 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!
Title: Re: Global labels
Post by: Charles Pegge on June 29, 2019, 05:42:13 PM
The linker will require some extra house-keeping to maintain previous labels.
Title: Re: Global labels
Post by: Brian Alvarez on June 29, 2019, 09:06:16 PM
Okay. Should i hold my tests then?
Title: Re: Global labels
Post by: Charles Pegge 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!
Title: Re: Global labels
Post by: Brian Alvarez 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!
Title: Re: Global labels
Post by: Brian Alvarez on July 01, 2019, 11:07:44 AM
A couple questions though...
I will make tests tonight.
Title: Re: Global labels
Post by: Charles Pegge 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.
Title: Re: Global labels
Post by: Brian Alvarez 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.
Title: Re: Global labels
Post by: Brian Alvarez 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!
Title: Re: Global labels
Post by: Brian Alvarez 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.
Title: Re: Global labels
Post by: Brian Alvarez 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)

Title: Re: Global labels
Post by: Charles Pegge 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
Title: Re: Global labels
Post by: Charles Pegge 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"
Title: Re: Global labels
Post by: Brian Alvarez on July 15, 2019, 09:46:41 AM
Nice! I await with expectation. :)

 Thanks.
Title: Re: Global labels
Post by: Brian Alvarez on July 15, 2019, 10:00:39 PM
Bad news... i managed to get oxygen to complain about perfectly valid code regarding goto/gosub... :(

Code: [Select]
   int ite0007
   gosub .FNini0007
   goto .FNind0007
    ..FNini0007
       int iti0007 = 1
       RET
    ..FNind0007
   for ite0007 = 0 TO 2 step 1
   ..FNst0007

   ..BBCmiddles
      print "Hello world"
           
      if iti0007 = 0 then
         gosub .FNini0007
      end if
      goto .FNst0007
   NEXT

Note: The code is useless, it only serves the purpose of showing a compilation time error with valid code.