Author Topic: TYPE problem?  (Read 2441 times)

0 Members and 1 Guest are viewing this topic.

Aurel

  • Guest
TYPE problem?
« on: May 16, 2017, 10:26:50 AM »
Hi Charles
I have this time problem with UDT
do you can test this small program?
this code is part of well known JimKlutho small basic version
written in PowerBasic and i try to translate to Oxygen
but i see that o2 have problem with this UDT.
you may see from screenshot...
if you want i can post whole translation

part of code:

Code: [Select]
test TYPE

TYPE FOR_STACK_TYPE
   vari AS LONG
   Target AS LONG
   Location AS LONG
End TYPE

Dim Ftos AS LONG
Dim Gtos AS LONG

Dim FStack[256] AS FOR_STACK_TYPE


Declare SUB fpush(i as FOR_STACK_TYPE)
Declare SUB fPop(i AS FOR_STACK_TYPE)





SUB fPush(i AS FOR_STACK_TYPE)
   If ftos > 256 THEN
       print "SB_TOO_MNY_FOR"
     Else
        FStack[ftos] = i
        ftos++
   End If
END SUB

SUB fPop(i AS FOR_STACK_TYPE)
   ftos = ftos - 1
   If ftos < 0 THEN
       print "SB_NEXT_WO_FOR"
     Else
       i = FStack[ftos]
   End If
END SUB

.

Charles Pegge

  • Guest
Re: TYPE problem?
« Reply #1 on: May 17, 2017, 03:15:32 AM »

Hi Aurel,

UDT variables can be copied, as a whole: copy @dest, @src, bytes

Code: [Select]
TYPE FOR_STACK_TYPE
   vari AS LONG
   Target AS LONG
   Location AS LONG
End TYPE

Dim Ftos AS LONG
Dim Gtos AS LONG

Dim FStack[256] AS FOR_STACK_TYPE


Declare SUB fpush(i as FOR_STACK_TYPE)
Declare SUB fPop(i AS FOR_STACK_TYPE)





SUB fPush(i AS FOR_STACK_TYPE)
   If ftos > 256 THEN
       print "SB_TOO_MNY_FOR"
     Else
        copy @FStack[ftos], @i, sizeof(FOR_STACK_TYPE)
        ftos++
   End If
END SUB

SUB fPop(i AS FOR_STACK_TYPE)
   ftos = ftos - 1
   If ftos < 0 THEN
       print "SB_NEXT_WO_FOR"
     Else
       copy @i, @FStack[ftos], sizeof(FOR_STACK_TYPE)
   End If
END SUB


Aurel

  • Guest
Re: TYPE problem?
« Reply #2 on: May 17, 2017, 03:49:06 AM »
Hi Charles
and thanks for reply..
so if i understand properly
currently ...i can not use it like in powerBasic?
your presented way is cool and i don't know that ...
it looks that is only when i try to use it with array index,right?

also is there a way to use it with typedef structure ?
thnx!
« Last Edit: May 17, 2017, 11:40:50 AM by Aurel »

Charles Pegge

  • Guest
Re: TYPE problem?
« Reply #3 on: May 17, 2017, 10:53:32 AM »

Copy should work with any variables, indexed or otherwise. It is primitive but very flexible.

But I have now added some code to o2 so it will be possible to assign a UDT variable directly, with the next release.

Yes, you can create typedef struct. It requires a C-style block on the outside:

Code: [Select]

typedef struct _FOR_STACK_TYPE {
   vari AS LONG
   Target AS LONG
   Location AS LONG
} FOR_STACK_TYPE


Aurel

  • Guest
Re: TYPE problem?
« Reply #4 on: May 17, 2017, 11:45:23 AM »
Hi Charles
Personally when i can, i try to avoid UDT or similar stuff but in some
cases are only or one of options.

Quote
But I have now added some code to o2 so it will be possible to assign a UDT variable directly, with the next release.
That would be nice  :)

Yes typedef struct work !
 :D