Oxygen Basic
Information => Development => Topic started 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. :)
-
Hi Brian,
Global labels were implemented in 0.2.0 (07/06/2019)
'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?
-
Do you mean jumping to an earlier line? If so... yes. I will make some tests tonight. :)
Thanks!
-
The linker will require some extra house-keeping to maintain previous labels.
-
Okay. Should i hold my tests then?
-
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!
-
That is what i do. Sometimes a GOTO saves me from adding extra code. Reuse existing one. :)
Thanks!
-
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.
-
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.
-
If that is a problem, then dont worry. I will handle it here. Something like a prefix will do.
-
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!
-
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):
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:
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:
manual: 0
done.
But i was expecting this:
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.
-
...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)
-
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:
for i=1 to 100 step 10
...
next
translates to:
i=1
do
if i>100 then exit do
...
i+=10
loop
-
My test cases for restricted (global) labels:
'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"
-
Nice! I await with expectation. :)
Thanks.
-
Bad news... i managed to get oxygen to complain about perfectly valid code regarding goto/gosub... :(
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.