Oxygen Basic

Programming => Problems & Solutions => Topic started by: Frankolinox on August 17, 2012, 12:40:03 AM

Title: "structureof" command?
Post by: Frankolinox on August 17, 2012, 12:40:03 AM
hello charles, do you know where I can find the command "structureof" in source code folder? I noticed that in a "udt type" example (type2) in "basics" folder. best regards, frank
Title: Re: "structureof" command?
Post by: Peter on August 17, 2012, 01:14:58 AM
Hi,

Quote
where I can find the command "structureof"

Return data structure of compund (UDT) or variabe
 
USE: obtain data for diagnostics or reflective programming
 
EXAMPLE: type vt long v,double d
dim as vt v :  r=recordof v


 
RESULT: r="
v 0 4 1 A0 , long
d 4 4 1 A0 , double
"
Title: Re: "structureof" command?
Post by: Charles Pegge on August 17, 2012, 01:44:29 AM
Hi Frank, you will find it in o2pars.bas and o2keyw.bas . Just search for 'structureof.
Title: Re: "structureof" command?
Post by: Peter on August 17, 2012, 03:34:28 AM
Hi,

Alien description:

Code: [Select]
type ABC
  sys    p1
  single s1
  byte   b1
  string v1
end type

ABC pa
pa = {256,0.125,255,"HELLO"}

print structureof(pa)

'long name p1: ? 019A: type = sys 
'long name s1: ? 419A: type = single
'long name b1: ? 819A: type = byte 
'long name v1: ? 129A: type = string   

print pa.v1 + " Number  " + pa.b1
Title: Re: "structureof" command?
Post by: Peter on August 17, 2012, 04:06:05 AM
Hi,

We need a tutorial about OxygenBasic for easy understanding about this stuff, what
Charles under pressure and drugs has developed.

I think Aurel is the right man for this matter.
He has always time, is in thousand foren and has AurelBasic developed.

First, I thought JRS could it do,but I have my doubts, he knows only ScriptBasic and handies and his holy Linux.

About me, I am sorry, my English too bad for this job. people would laugh about me.
 
What do you think?
 :D  :D  :D
Title: Re: "structureof" command?
Post by: Aurel on August 17, 2012, 08:42:08 AM
Like David Lynch say:
 “Through the darkness of future past, the magician longs to see, one chance out between two worlds, fire walk with me!”

Hi Peter ...you always cheer me up... ;)

Yes you right, Oxygen really need some sort of tutorial or user guide or help
to to present the language in the easiest way.
I think that Kent do something about that but where he stops,i don't know.
My english is not good,bucause i am to lazy to learn gramatic rules. >:(
I don't know many things about oxygen to... ::)

And there is no better person here than Charles...

-------------------------
About content:
General about... syntax rules ...etc
Variable ...types...how to use ...pointers...etc
structure or types or UDT....type/end ...uninon/end....etc
macros...

OOP way...etc...


Title: Re: "structureof" command?
Post by: efgee on August 17, 2012, 08:44:04 AM
... I am sorry, my English too bad for this job. people would laugh about me.
  
What do you think?
 :D  :D  :D

Close your eyes and imagine:

Millions of people (programmers and non programmers alike) read the O2-Tutorials...
...not because O2 is such a great language...
...but because they all want to read the hilarious funny tutorials...
...written by you!

Tempting?

 ;D
Title: Re: "structureof" command?
Post by: Charles Pegge on August 17, 2012, 10:40:24 AM

Oxygen is not quite complete yet and takes a wider range of syntax than other Basics. But I hope we will eventually be able to distil some useful documentation from the substantial collection of examples that we have so far.

Charles
Title: Re: "structureof" command?
Post by: Frankolinox on August 18, 2012, 12:48:12 AM
thank you charles, peter, aurel and efgee for your feedback. my search engine on my notebook strikes sometimes, it's bad I am thinking. I've searched for "structureof" with "no match found" :)
the more I see the genius structure of oxygenbasic the more I am astonished what's possible with very few code lines. I like oxygen very mucho although there's a lot of things I must go to another planet (for example: jupiter) to understand their language and behaviour (like "avatar" movie) :-) thanks charles! best regards, frank
Title: Re: "structureof" command?
Post by: Charles Pegge on August 18, 2012, 01:23:55 AM
Hi Frank,

Here is the Attributes function in o2pars.bas (handling structureof)

Code: [Select]

'---------------------------------------------------------
function attributes(s as string, byref i as sys) as string
'=========================================================
  '
  dim as sys kn,a,c,k,m,wa,ty
  dim as string wr,w1
  '
  kn=maco(mp,5)
  '
  if ascn=lbr then c=1 : i+=1 'SKIP LEFT BRACKET
  '
  nmac=1
  w1=pword(s,i) 'resolve
  nmac=0
  ty=typ
'if ascn=91 then fixsqbr(s,i)
'if ascn=lbr then wpfx+=arrayres(s,i,ty,w1)
  typ=ty
  '
  if c then
    if ascn=rbr then
      i+=1 : skiplspace(s,i) 'BLANK RIGHT BRACKET
    end if
  end if
  '
  '
  '
  wr="0" : k=mp : m=k
  '
  'VARIABLE OR STRUCTURE ?
  '
  if mc>=0 then
    m=mc
  end if
  '
  '
  '
  select case kn                  'SIZEOF
  case 1
    if mc=0 then
      if isq(ascw) then
        wa=cpuw
        goto attrin
      end if
    end if
    if mc>=0 then
      wa=lent
    elseif instrword(" string wstring bstring bstring2 ",w1) then
      wa=cpuw
    elseif instrword(" char zstring asciiz ",w1) then
      wa=1
    elseif instrword(" wchar zstring2 ",w1) then
      wa=2
    elseif mc<0 then
      a=identype(w1) : if a then wa=lent
    end if
    goto attrin
  case 2
    if mc>=0 then
      wa=maco(mp,2)+woff
    end if
    goto attrin                     'OFFSETOF
  case 3
    if mc>=0 then
      wa=wval(macso(mp,2))          'SPANOF: NUMBER OF ELEMENTS OF MAIN ARRAY
      if wa=0 then wa=1
    end if
    goto attrin
  case 4                            'TYPEOF:
    if mc>=0 then
      if len(sog) then
        wr=sog
      else
        wr=identypes(typ)
      end if
    elseif mc<0 then
      wr="metatype "+str(mc)+" "+_
     dicsn(metatypes,mc)            'TYPEOF TYPE
    end if
  case 5
    wr=macso(m,1)                   'STRUCTUREOF ENCODINGOF
  case 6
    wr=macso(k,3)                   'PROTOTYPEOF
  case 7
    wa=typ
    goto attrin                     'TYPECODEOF
  case 8
    wr=writestates(k,k)             'RECORDOF
  case 9
    if isstr(typ)=0 then
      ert=109 : ers="Not a string"
    else
      makestrptr(w1)
      function=w1                   'STRPTR
    end if
    exit function
  end select
  '
  '
  '-----
  attris:
  '-----
  '
  if nl then
    typ=0 'raw code
  else
    wr=iq+wr+iq 'quoted string literal
    typ=&hc1
  end if
  '
  goto attrix
  '
  '-----
  attrin:
  '-----
  '
  wr=str(wa) : typ=cpuw
  '
  '-----
  attrix:
  '-----
  '
  mc=0 : mp=0 : varf=0
  function=wr
  '
end function


Charles
Title: Re: "structureof" command?
Post by: Aurel on August 18, 2012, 02:01:08 AM
Charles ...
There is problem in this line with pword()
-unknown function
I have latest oxygen from forum...
what might be that?
Title: Re: "structureof" command?
Post by: Charles Pegge on August 18, 2012, 03:58:53 AM
What is pword?
Title: Re: "structureof" command?
Post by: Peter on August 18, 2012, 05:50:03 AM
Aurel meant this here:

Code: [Select]
w1=pword(s,i) 'resolve
Title: Re: "structureof" command?
Post by: Aurel on August 18, 2012, 07:13:25 AM
Yes i mean that.
Title: Re: "structureof" command?
Post by: Charles Pegge on August 18, 2012, 01:04:04 PM
It can't find your pword definition. Is it out of scope?
Title: Re: "structureof" command?
Post by: Aurel on August 18, 2012, 01:07:04 PM
As i say i recive error about unknown function - pword
and before that with maco function...
what are those functions ???
here:
Code: [Select]
function attributes(s as string, byref i as sys) as string
'=========================================================
  '
  dim as sys kn,a,c,k,m,wa,ty
  dim as string wr,w1
  '
  kn=maco(mp,5)  ' <---- error
  '
  if ascn=lbr then c=1 : i+=1 'SKIP LEFT BRACKET
  '
  nmac=1
  w1=pword(s,i) 'resolve   ' <----error




X
Title: Re: "structureof" command?
Post by: Charles Pegge on August 18, 2012, 01:36:09 PM
Oh I see! you are referring to the source code. You have to compile the whole thing.

fbc -dll Oxygen.bas

I'm using FB version 0.21

pword is part of the parsing suite - it resolves macros, pointers and a few other items.

You will find it further down in o2pars.bas. These functions are often used recursively.

Charles
Title: Re: "structureof" command?
Post by: Aurel on August 18, 2012, 02:04:45 PM
Uops ...i don't know that this is conected with FB source of oxygen.
Charles ...belive me i have never tried to compile oxygen with FB.
I have version v0.20b.
By the way i study examples by Dean Hodgson about how he create multiple windows.
You probably see this example on FB forum.
Title: Re: "structureof" command?
Post by: Frankolinox on August 19, 2012, 10:42:00 AM
thanks you all :) my example with udt types "structure of" are working well!
 nice week-end, here in my home town there's a big celebretion day for summer days and farmers :-) today at sunday there were 38 celsius degree!!!
best regards, frank (and I can repeat it every day thanks for your great oxygen basic works) !