Oxygen Basic

Information => Open Forum => Topic started by: kryton9 on June 09, 2012, 11:11:06 PM

Title: Classes, Unions and Arrays Help Please
Post by: kryton9 on June 09, 2012, 11:11:06 PM
I am trying to figure out what I can and can't do with my classes. I can't get this to compile, tried different things. Is it possible?
Code: OxygenBasic
  1. class cVec2
  2.     public
  3.         'public member vars
  4.        union
  5.         {
  6.             {
  7.                 double x
  8.                 double y
  9.             }
  10.             {
  11.                 double v[2]
  12.             }
  13.         }
  14.     public
  15.         'public methods
  16.        method constructor()
  17.             x = 0
  18.             y = 0
  19.         end method
  20.        
  21.         method constructor(double aX = 0, double aY = 0)
  22.             x = aX
  23.             y = aY
  24.         end method
  25.        
  26.         method constructor(double aV[2] = {0,0})
  27.             v = aV
  28.         end method
  29.        
  30.         method add(double aX = 0, double aY = 0) as cVec2
  31.             cVec2 temp
  32.             temp.x = x + aX
  33.             temp.y = y + aY
  34.             return temp
  35.         end method
  36.        
  37.         'method add(double aV[2] => (0,0)) as cVec2
  38.        method add(double aV[2] = {0,0}) as cVec2
  39.             cVec2 temp
  40.             temp.v[1] = v[1] + aV[1]
  41.             temp.v[2] = v[2] + aV[2]
  42.             return temp
  43.         end method
  44. end class
  45.  
  46. new cVec2 v1
  47. new cVec2 v2 5,10
  48. new cVec2 v3 => (12,24)
  49.  
  50.     print "v1 should be   0,0 :" v1.x ", " v1.y
  51.     print "v2 should be  5,10 :" v2.x ", " v2.y
  52.     print "v3 should be as x,y 12,24 :" v3.x ", " v3.y
  53.     print "v3 should be        12,24 :" v3.v[1] ", " v3.v[2]
  54.  
  55. del v1
  56. del v2
  57. del v3
Title: Re: Classes, Unions and Arrays Help Please
Post by: kryton9 on June 09, 2012, 11:38:50 PM
Heading off to sleep. Will be dreaming about what we can do in oxygen!!!
Title: Re: Classes, Unions and Arrays Help Please
Post by: Charles Pegge on June 10, 2012, 12:41:08 AM
For overloading, something like this: (unions=confusions :))

Code: OxygenBasic
  1.  
  2. class cVec2  
  3.     public  
  4.         'public member vars  
  5.        double x,y  
  6.    public  
  7.         'public methods  
  8.          
  9.         method destructor()  
  10.         end method  
  11.          
  12.         method constructor()  
  13.         end method  
  14.          
  15.         method constructor(double*ax,*ay)  
  16.             x=ax  
  17.             y=ay
  18.         end method  
  19.  
  20.         method constructor(cVec2*v)  
  21.             x=v.x  
  22.             y=v.y
  23.         end method        
  24.          
  25.         method load(double*u,*v)  
  26.             x=u
  27.             y=v
  28.         end method  
  29.          
  30.         method load(cVec2*v)  
  31.             x=v.x
  32.             y=v.y
  33.         end method  
  34.          
  35.         method add(double*u,*v)  
  36.             x+=u
  37.             y+=v
  38.         end method  
  39.          
  40.         method add(cVec2*v)  
  41.             x+=v.x
  42.             y+=v.y
  43.         end method  
  44.          
  45. end class  
  46.  
  47. test:
  48. '====
  49.  
  50. new cVec2 v1  
  51. new cVec2 v2(5,6)
  52. new cVec2 v3(10,20)
  53. new cVec2 v4(v3)
  54.  
  55. print v4.x "," v4.y
  56. v4.add v2
  57. print v4.x "," v4.y
  58.  
  59. del v1  
  60. del v2  
  61. del v3
  62. del v4  
  63.  

Charles
Title: Re: Classes, Unions and Arrays Help Please
Post by: Charles Pegge on June 10, 2012, 12:32:17 PM
Handling dynamic vector arrays. This is somewhat excessive for such a simple data structure but it can be used as a model for more complex things like particles.

All members are contained with a single object. Using one buffer, it is a bit like 'TextArray' (many lines, one text)

Code: OxygenBasic
  1.  
  2. type tVec2
  3.     double x,y
  4. end type
  5.  
  6. class cVecArray2  
  7.     private
  8.         string buf
  9.         sys    pb,mx  
  10.    public  
  11.         'public methods  
  12.          
  13.         method destructor()
  14.         buf=""
  15.         pb=0
  16.         end method              
  17.          
  18.         method constructor(sys n)
  19.           this.dim n
  20.         end method  
  21.                
  22.          
  23.         method redim(sys n)
  24.             sys le=len buf
  25.             n*=sizeof tVec2
  26.             if n<le
  27.               buf=left buf,n
  28.             elseif n>le
  29.               buf+=nuls n-le
  30.             end if
  31.             pb=strptr buf
  32.             mx=n
  33.         end method
  34.  
  35.  
  36.         method dim(sys n)
  37.             buf=""
  38.             redim n
  39.         end method
  40.  
  41.  
  42.         method lboud() as sys
  43.           return 0
  44.         end method
  45.  
  46.      
  47.         method ubound() as sys
  48.           return mx-1
  49.         end method
  50.                
  51.          
  52.         method load(sys n,= double x, y)
  53.             sys pn=pb+n*sizeof tVec2
  54.             tVec2 v at pn
  55.             v.x=x
  56.             v.y=y
  57.         end method  
  58.          
  59.         method load(sys m,n)
  60.             sys pm,pn
  61.             pm=pb+m*sizeof tVec2  
  62.             pn=pb+n*sizeof tVec2
  63.             tVec2 vm at pm,vn at pn  
  64.             vm.x=vn.x
  65.             vm.y=vn.y
  66.         end method  
  67.          
  68.         method add(sys n,= double x, y)  
  69.             sys pn=pb+n*sizeof tVec2
  70.             tVec2 v at pn
  71.             v.x+=x
  72.             v.y+=y
  73.         end method  
  74.          
  75.         method add(sys m,n)  
  76.             sys pm,pn
  77.             pm=pb+m*sizeof tVec2  
  78.             pn=pb+n*sizeof tVec2
  79.             tVec2 vm at pm,vn at pn  
  80.             vm.x+=vn.x
  81.             vm.y+=vn.y
  82.         end method
  83.  
  84.         method info(sys n) as string
  85.             sys pn=pb+n*sizeof tVec2
  86.             tVec2 v at pn
  87.             return " " v.x "," v.y
  88.         end method
  89.        
  90.          
  91.         method vectors(sys n) as tVec2 ptr
  92.           return pb+n*sizeof tVec2
  93.         end method
  94.        
  95.          
  96. end class
  97.  
  98. #recordof cVecArray2  
  99.  
  100.  
  101. 'INDEX IS BASE ZERO
  102. '==================
  103.  
  104. new cVecArray2 vv(10) 'PSEUDO-ARRAY
  105.  
  106. 'LOAD DOUBLES
  107. '
  108. vv.load(1)=5.0,6.0
  109. vv.load(2)=10.0,20.0
  110.  
  111. 'TEST REDIM
  112. '
  113. vv.redim(20)
  114.  
  115. 'ADD DOUBLES
  116. '
  117. vv.add(2)=1.0,2.0
  118. print vv.info(2)
  119.  
  120. 'ADD FROM ANOTHER VECTOR MEMBER
  121. '
  122. vv.add(2,1)
  123. print vv.info(2)
  124.  
  125.  
  126. 'ADD SERIES OF DATA
  127. '
  128. let v=vv.vectors(4)        'create vector v pointing to member 4
  129. v<=11,22,33,44,55,66,77,88 'v was automatically created as a tVec2 pointer
  130. print vv.info 5
  131.  
  132. del vv
  133.  
Title: Re: Classes, Unions and Arrays Help Please
Post by: kryton9 on June 10, 2012, 12:52:27 PM
Thanks Charles for both samples. Will study them as I plan out my project in more detail.
Title: Re: Classes, Unions and Arrays Help Please
Post by: Charles Pegge on June 10, 2012, 02:11:23 PM
I will file these pieces in the examples\OOP folder. There are a few more tweaks to Oxygen going in, so these examples will have one or two additional features.

Charles
Title: Don't know why this isn't working
Post by: kryton9 on June 10, 2012, 09:42:52 PM
Here is my stumper for tonight. I can't see why it is not working. The listing is showing the code in line 19 wrong so I attached the script.
Code: OxygenBasic
  1. 'test cArray.o2bas
  2. 'by Kent Sarikaya 2012
  3.  
  4. ' $ filename "./../_bin/test cArray.exe"
  5. ' #include "../../../inc/RTL32.inc"
  6.  
  7. ' includepath + "./../_inc/"
  8. ' include once "cConsole.inc"
  9.  
  10. ' % cr c.print crlf
  11.  
  12. class cArray
  13.     private
  14.         string array mA[10]
  15.         sys mLength = 10
  16.     public
  17.         method Constructor()
  18.             for i = 1 to mLength
  19.                 mA[i] = ""
  20.             next
  21.         end method
  22.        
  23.         method Destructor()
  24.             freememory mA
  25.         end method
  26.        
  27.         method GetLength() as sys
  28.             return mLength
  29.         end method
  30.        
  31.         method Set(sys aIndex, sys aValue)
  32.             mA[aIndex] = str aValue
  33.         end method
  34.        
  35.         method Set(sys aIndex, string aString)
  36.             mA[aIndex] = aString
  37.         end method
  38.        
  39.         method Get(sys aIndex) as string
  40.             return mA[aIndex]
  41.         end method
  42.     protected
  43.     private
  44. end class
  45.  
  46. 'new cConsole c "test cArray.o2bas"
  47.    new cArray a
  48.    
  49.         string s = "I see aliens."
  50.         a.Set 3, s
  51.         'c.Print a.Get 3
  52.        Print a.Get 3
  53.         'cr
  54.        
  55.         a.Set 4, "I see ufos."
  56.         'c.Print a.Get 4
  57.        Print a.Get 4
  58.         'cr
  59.        a.Set 5, 42
  60.         'c.Print a.Get 5
  61.        Print a.Get 5
  62.         'cr
  63.        'c.WaitKey
  64.    del a
  65. 'del c
Title: Re: Classes, Unions and Arrays Help Please
Post by: Charles Pegge on June 11, 2012, 12:50:58 AM
Almost there!

line 14:

string ma[10] ' delete 'array'

line 24:

freememory ma
delete this line. strings and wstrings are memory-managed automatically

You can inspect the record of a class at compile-time, to see if your source code has been understood:

#recordof cArray

Charles
Title: Re: Classes, Unions and Arrays Help Please
Post by: kryton9 on June 11, 2012, 10:51:05 AM
Thanks Charles!

Quote
freememory ma
delete this line. strings and wstrings are memory-managed automatically
But I should use it for any other type of arrays in a class?

Title: Operator Overloading Test
Post by: kryton9 on June 11, 2012, 11:42:27 AM
I was testing operator overloading Charles. Can't get it to work. I see that you have it in some of your samples.

Code: OxygenBasic
  1. string crlf = chr( 13 ) + chr( 10 )
  2.  
  3. class tiny
  4.     'member variables
  5.    private
  6.         string mPhrase
  7.     'methods
  8.    public
  9.         method Set( string aString )
  10.             mPhrase = aString
  11.         end method
  12.        
  13.         method Prnt()
  14.             print mPhrase
  15.         end method
  16.        
  17.         method "?"( string aString)
  18.             print aString
  19.         end method
  20.        
  21.         method "??"()
  22.             print "to " crlf "believe."
  23.         end method
  24. end class
  25.  
  26. tiny t
  27. t.Set "The X Files"
  28. t.Prnt
  29. t.? "I want "
  30. t.??
Title: Re: Classes, Unions and Arrays Help Please
Post by: Charles Pegge on June 11, 2012, 02:20:16 PM
Hi Kent,

For operator overloading you need to implement "load" "push" "pop" and "=" as the minimum operator set. The class. A static accumulator stack is also required'

The easiest way to get an operator-supporting class going is to base it on the vector example. You can also create custom operators by defining them before the class that uses them like this:

operator "aga" 9, "ogo" 8 ,...
where the number indicates the precedence level (ascending priority)
a aga b ogo (c+d)

Code: OxygenBasic
  1.  
  2. '===========================
  3. 'VECTOR ARITHMETIC OPERATORS
  4. '===========================
  5.  
  6.  
  7. type vector3d
  8.  double x,y,z
  9. end type
  10.  
  11.  
  12. class VectorOp3d
  13. '===============
  14.  
  15. has vector3d
  16.  
  17. static sys i,pp
  18. static vector3d accum[32]
  19.  
  20. macro GetOperand()
  21.   vector3d*a,*b
  22.   @a=@accum+i          'establish current stack position
  23.  if pp then
  24.     @b=@a+sizeof accum 'operand is on the stack (next position up)
  25.    pp=0
  26.   else
  27.     @b=@this           'operand is this object (not on the stack)
  28.  end if
  29. end macro
  30.  
  31. method "load"()
  32.   GetOperand
  33.   a.x=b.x
  34.   a.y=b.y
  35.   a.z=b.z
  36. end method
  37.  
  38. method "push"()
  39.   i+=sizeof accum
  40. end method
  41.  
  42. method "pop"()
  43.   pp=1 'take operand from the stack (next operation)
  44.  i-=sizeof accum
  45. end method
  46.  
  47. method "="()
  48.   GetOperand
  49.   b.x=a.x
  50.   b.y=a.y
  51.   b.z=a.z
  52. end method
  53.  
  54. method "+"()
  55.   GetOperand
  56.   a.x+=b.x
  57.   a.y+=b.y
  58.   a.z+=b.z
  59. end method
  60.  
  61. method "-"()
  62.   GetOperand
  63.   a.x-=b.x
  64.   a.y-=b.y
  65.   a.z-=b.z
  66. end method
  67.  
  68. method "*"()
  69.   GetOperand
  70.   a.x*=b.x
  71.   a.y*=b.y
  72.   a.z*=b.z
  73. end method
  74.  
  75. method "/"()
  76.   GetOperand
  77.   a.x/=b.x
  78.   a.y/=b.y
  79.   a.z/=b.z
  80. end method
  81.  
  82. end class
  83.  
  84. '#recordof vectorop3d
  85.  
  86.  
  87.  
  88. vectorop3d va[9],vb[9],vc[9]
  89.  
  90. 'assign xyz values
  91.  
  92. va<=1.0,2.0,3.0
  93. vb<=0.1, 0.2, 0.3, 0.01, 0.02, 0.03
  94.  
  95. 'test expression
  96.  
  97. 'vc=vb[1]+va*va+vb[2]
  98. vc=(vb[1])+va*va+vb[2]
  99.  
  100. print str(vc.y,4)
  101.  
  102.  
  103.  
  104.  

Charles
Title: Re: Classes, Unions and Arrays Help Please
Post by: Charles Pegge on June 11, 2012, 02:47:54 PM
Bstrings need explicit memory management

bstring b= nuls 100
...
frees b 'when b is no longer needed

Also low level memory allocation

sys a=getmemory 100
char z at a 'creating a char buffer in the memorry block
...
freememory a

Charles

Title: Re: Classes, Unions and Arrays Help Please
Post by: kryton9 on June 11, 2012, 03:15:15 PM
Thanks. I will need to study this as it is not sinking in. Only experimenting will help. But your tips give me a focusing point. Thanks again.
Title: Re: Classes, Unions and Arrays Help Please
Post by: Charles Pegge on June 11, 2012, 04:02:34 PM
I'll cook up a sensible example with custom operators, Kent.

I've updated the listing above. I hope its meaning is a bit clearer.

The multiassign went pear-shaped on my last update (about 6 hours ago)
Sorry about that. It affects the example above.

Corrected Oxygen zip attached

New zip attached further on
Title: Re: Classes, Unions and Arrays Help Please
Post by: kryton9 on June 11, 2012, 04:43:11 PM
Thanks Charles, I am having fun analyzing and seeing what I can and can't do. The new commented example helps.
Title: Re: Classes, Unions and Arrays Help Please
Post by: kryton9 on June 11, 2012, 04:53:39 PM
Quote
You can also create custom operators by defining them before the class that uses them like this:

operator "aga" 9, "ogo" 8 ,...
where the number indicates the precedence level (ascending priority)
a aga b ogo (c+d)
  I thought this would eliminate the required methods for load, push.. etc.
But couldn't get it to work.

Code: OxygenBasic
  1. string crlf = chr( 13 ) + chr( 10 )
  2.  
  3. operator "?" 1, "??" 2
  4.  
  5. class tiny
  6.     'member variables
  7.    private
  8.         string mPhrase
  9.     'methods
  10.    public
  11.         method Set( string aString )
  12.             mPhrase = aString
  13.         end method
  14.        
  15.         method Prn()
  16.             print mPhrase
  17.         end method
  18.        
  19.         method "?"( string aString)
  20.             print aString
  21.         end method
  22.        
  23.         method "??"()
  24.             print "to " crlf "believe."
  25.         end method
  26.        
  27.         ' method ?( string aString)
  28.            ' print aString
  29.        ' end method
  30.        
  31.         ' method ??()
  32.            ' print "to " crlf "believe."
  33.        ' end method
  34. end class
  35.  
  36. tiny t
  37. t.Set "The X Files"
  38. t.Prn
  39. t.? "I want "
  40. t.??
  41. ' t."?" "I want "
  42. ' t."??"
  43. ' t ? "I want "
  44. ' t ??
Title: Re: Classes, Unions and Arrays Help Please
Post by: kryton9 on June 11, 2012, 05:06:47 PM
I tried this too and no luck.
Code: OxygenBasic
  1. string crlf = chr( 13 ) + chr( 10 )
  2.  
  3. 'operator "?" 1, "??" 2
  4.  
  5. class tiny
  6.     'member variables
  7.    private
  8.         string mPhrase
  9.        
  10.     'Code for Operator Overloading
  11.    static sys i,pp  
  12.     static string accum[32]  
  13.      
  14.     macro GetOperand()  
  15.       string *a,*b  
  16.       @a=@accum+i          'establish current stack position  
  17.      if pp then  
  18.         @b=@a+sizeof accum 'operand is on the stack (next position up)  
  19.        pp=0  
  20.       else  
  21.         @b=@this           'operand is this object (not on the stack)  
  22.      end if  
  23.     end macro
  24.    
  25.     method "load"()  
  26.         GetOperand    
  27.     end method  
  28.      
  29.     method "push"()  
  30.         i+=sizeof accum  
  31.     end method  
  32.      
  33.     method "pop"()  
  34.         pp=1 'take operand from the stack (next operation)  
  35.        i-=sizeof accum  
  36.     end method
  37.  
  38.     'methods
  39.    public
  40.         method Set( string aString )
  41.             mPhrase = aString
  42.         end method
  43.        
  44.         method Prn()
  45.             print mPhrase
  46.         end method
  47.        
  48.         method "?"( string aString)
  49.             GetOperand
  50.             print aString
  51.         end method
  52.        
  53.         method "??"()
  54.             GetOperand
  55.             print "to " crlf "believe."
  56.         end method
  57. end class
  58.  
  59. tiny t
  60. t.Set "The X Files"
  61. t.Prn
  62. ' t.? "I want "
  63. ' t.??
  64. ' t."?" "I want "
  65. ' t."??"
  66. t ? "I want "
  67. t ??
Title: Re: Classes, Unions and Arrays Help Please
Post by: Charles Pegge on June 11, 2012, 05:14:36 PM
Operator names are restricted. "?" is already in use and "??" will not parse as one symbol.

Objects belonging to an operator class do not use dot syntax when behaving as operands in an expression. Thus vectors v1=v2+v3*v4 is legit.

But accessing other (non-operator) methods and members is done in the usual way
v1.x=2 : v1.y=2.5 ..

I think an AI Logic class would be a useful way to illustrate the use of custom operators "common" "merge" etc

I will dream about it. 2.00 AM: Siesta time here :)

Charles

ps

operator tadd 5
...
method "tadd"()
  GetOperand
  a.x+=b.x
  a.y+=b.y
  a.z+=b.z
end method

...

vc=vb[1] tadd va[1]
print str(vc.x,3) "," str(vc.y,3) "," str(vc.z,3)

Title: Re: Classes, Unions and Arrays Help Please
Post by: kryton9 on June 11, 2012, 07:48:58 PM
Sleep well. I just got up from a nap to give you more nightmares.  Check this one out and think about >=, <=, != 
I will think about this when I sleep for good tonight too.
Title: Re: Classes, Unions and Arrays Help Please
Post by: Charles Pegge on June 12, 2012, 03:07:47 AM
Good Morning Kent!

I'm upgrading operators to include comparators. It will take a few more hours to debug and test.

Charles
Title: Re: Classes, Unions and Arrays Help Please
Post by: Charles Pegge on June 12, 2012, 06:05:31 AM

Here it is. New Oxygen with your test and a sample Vectors class.

Code: OxygenBasic
  1. method "boolean"() as bool
  2.   GetOperand
  3.   if a.x + a.y + a.z<>0 then return -1
  4. end method
  5.  
  6. method "=="() as bool
  7.   GetOperand
  8.   if a.x=b.x and a.y=b.y and a.z=b.z then return -1
  9. end method
  10.  
  11. method "<>"() as bool
  12.   GetOperand
  13.   if not a.x=b.x and a.y=b.y and a.z=b.z then return -1
  14. end method
  15.  
  16. macro hyp(a)
  17.     sqrt(a.x*a.x+a.y*a.y+a.z*a.z)
  18. end macro
  19.  
  20. method "<"() as bool
  21.   GetOperand
  22.   if hyp(a) < hyp(b) then return -1
  23. end method
  24.  
  25. method ">"() as bool
  26.   GetOperand
  27.   if hyp(a) > hyp(b) then return -1
  28. end method
  29.  
  30. method "<="() as bool
  31.   GetOperand
  32.   if hyp(a) <= hyp(b) then return -1
  33. end method
  34.  
  35. method ">="() as bool
  36.   GetOperand
  37.   if hyp(a) >= hyp(b) then return -1
  38. end method
  39.  
  40.  

Charles

[attachment deleted by admin]
Title: Re: Classes, Unions and Arrays Help Please
Post by: kryton9 on June 12, 2012, 09:23:16 AM
Thanks Charles, I hope it wasn't too much of a headache!  I will test it in coming days. Thanks, this is super!
Title: Re: Classes, Unions and Arrays Help Please
Post by: Charles Pegge on June 12, 2012, 10:40:14 AM
No headaches, Kent. It's good to have a full set of operators available, even though some of them are rarely used for higher types.

One limitation of this design: due to the use of a static accumulator, it is not safe to share the class between multiple threads. They will all fight over the accumulator and scramble it! So each thread must have its own independent class. This could be done with a macro for easy deployment.

Charles
Title: Re: Classes, Unions and Arrays Help Please
Post by: kryton9 on June 12, 2012, 04:21:23 PM
I had to sit hear and read and reread your post and think about each idea out to understand it. But I get it, finally. I do have a question though, why is the accumulator sized to 32? I don't understand that.
Title: Re: Classes, Unions and Arrays Help Please
Post by: Charles Pegge on June 12, 2012, 05:50:31 PM
Hi Kent

Nesting an expression to 31 levels (very generous :))

This expression would require an accumulator stack with three levels (2 nested levels ):

a=((b+c)*(d+e) and 127)+4

The compiler's precedence evaluator automatically inserts brackets, so nestings are not always explicit.

Charles

Title: Re: Classes, Unions and Arrays Help Please
Post by: kryton9 on June 12, 2012, 07:19:44 PM
I misunderstood it to be 32 items in an expression and not nesting levels :)
Title: Re: Classes, Unions and Arrays Help Please
Post by: Aurel on June 12, 2012, 09:08:56 PM
People..
Discussion is interesting ,but where is practical advantage of all this operators...etc.
And for what is all this stuff good.?
Title: A thank you to Charles
Post by: kryton9 on June 12, 2012, 09:36:00 PM
The only way I can thank you for putting up with my questions the last few days is a new class and demo. This is a result of learning this stuff. We now have a new class for booleans.
All that is necessary is included. The exe has the runtime so no need for the oxygen.dll.

Hope this answers your questions too Aurel. Pretty neat what we can do with Oxygen. Java doesn't have operator overloading, but pretty much all the other popular languages do.

Just extract to your projects folder.
Title: Thought of this while sleeping and couldn't get it to work
Post by: kryton9 on June 13, 2012, 07:53:07 AM
I thought about the cBool and thought of this addition today and can't resolve it.
Looking at the code you will see the areas I have commented out. These were my attempts at figuring it out.

The problem, how to have it equal to a non class type, that is something that is not cBool as in the working demo before.
What about a sys value of true or false.

It should be clearer to see when looking at the code.
Title: Re: Classes, Unions and Arrays Help Please
Post by: Charles Pegge on June 13, 2012, 11:08:24 AM

Hi Kent,
Thanks for the cBool class.

I suggest making the mbool member public. Then you can load it like this

bVal <= true

Code: OxygenBasic
  1. 'test cBool 2.o2bas
  2. 'by Kent Sarikaya June 2012
  3.  
  4. ' $ filename "./../_bin/test cBool 2.exe"
  5. ' #include "../../../inc/RTL32.inc"
  6.  
  7. ' includepath + "./../_inc/"
  8. include once "cConsole.inc"
  9. include once "cBool.inc"
  10.  
  11. new cConsole c "test cBool.o2bas 2"
  12. new cBool bVal
  13. bVal <= true '<<<<<<<<
  14. c.Print "bVal is " bVal.Get + crlf
  15. bval <= false
  16. c.Print "bVal is " bVal.Get + crlf
  17. c.WaitKey  
  18. del bVal
  19. del c
  20.  

The technique is also good for filling complex numbers and vectors:

vector v
v<=x,y,z


Charles
Title: Re: Classes, Unions and Arrays Help Please
Post by: kryton9 on June 13, 2012, 04:56:41 PM
I was thinking about doing that, but then wanted to know if could do it with private. Probably the easiest solution. Will think about it some more.
Title: Re: Classes, Unions and Arrays Help Please
Post by: Charles Pegge on June 13, 2012, 09:13:07 PM
Hi Kent,

Private members are quite well guarded.

When dealing with compound math types that use operators, such as vectors, quaternions and matrices, you need efficient access to the individual members, at least for input and output of scalar values.

Oxygen performs automatic conversion between integers, floats and strings, which in many cases, eliminates the need for accessor methods.

Code: OxygenBasic
  1. class vec
  2.   double x,y,z
  3. end class
  4.  
  5. vec v
  6. v<="1.1","2.2","3.3" 'these are converted to doubles automatically
  7.  
  8. print str(v.x+v.y+v.z,4) 'answer 6.6 (integrity check)
  9.  

Charles
Title: Re: Classes, Unions and Arrays Help Please
Post by: kryton9 on June 13, 2012, 10:37:06 PM
I forget that Oxygen is no ordinary language and compiler, it is Smart++. That will be super then, a lot easier than having to write all the methods to get and set!!
Title: This could lead to some neat things.
Post by: kryton9 on June 14, 2012, 10:49:13 PM
I need your help oh master of oxygen.

Unzip the attachment to the projects folder. There is a readme.txt file to read and the comments in the code.

Getting this to work could lead to some powerful stuff, at least that is my hope!!
Title: Re: Classes, Unions and Arrays Help Please
Post by: Charles Pegge on June 15, 2012, 12:56:19 AM

I made a few minor changes, Kent, but the one to scrutinize is how to hook dynamic objects (of csqlite)into a new class. The new object has to be instantiated inside a method, in this case your constructor.

I've include to techniques for doing it. Solution d is the simplest


new cSqlite lDB ()
@mDB=@lDB 'link to this member

Solution d
Code: OxygenBasic
  1.  
  2. class cArray
  3.     'member variables
  4.    private
  5.  
  6.         string  mName
  7.         cSqlite *mdb
  8.  
  9.     public
  10.  
  11.         method Constructor( string aName = "AutoTableName" )
  12.             new cSqlite lDB ()
  13.             @mDB=@lDB 'link to this member
  14.            mname=aname
  15.             mDB.Exec "create table "mName" ( t text );"
  16.         end method
  17.        
  18.         method Destructor()
  19.             del mDB
  20.         end method
  21.        
  22. ....
  23.  
Title: Re: Classes, Unions and Arrays Help Please
Post by: kryton9 on June 15, 2012, 01:03:19 AM
Thanks Charles, it was driving me crazy. I couldn't sleep thinking about it. It is 5 a.m. already. So thanks now I can have some peace and sleep!

One question in solution D, which I agree, I like the best.  What about lDB?  shouldn't that be deleted also in the destructor along with mDB?
Title: Re: Classes, Unions and Arrays Help Please
Post by: Charles Pegge on June 15, 2012, 01:47:09 AM

No. In reality, lDB is just a pointer. Once its value is transferred to the mDB pointer, it is redundant.

then mDB takes on the role of the new object.
Title: Re: Classes, Unions and Arrays Help Please
Post by: kryton9 on June 15, 2012, 10:57:10 AM
Thanks for the explanation. That is a very elegant solution.
Title: Dynamic Array Start
Post by: kryton9 on June 15, 2012, 06:58:32 PM
Here is the start of a pretty slick dynamic array using sqlite3 as the backend. Right now it is only in the beginning stages. I am not flushing out any of the classes till I know that the whole idea I have in my mind can be done.

For now it is a single dimensional dynamic array that can hold numbers and strings. You can sort easily in either direction and go through the array with minimal code.

Unzip the attachment into your projects directory.
Title: The snag for tonight. Step 2
Post by: kryton9 on June 15, 2012, 11:11:41 PM
Charles, just download, unzip into the projects folder and please read the "Read Me.txt".
Another one I am at a loss.
Title: Re: Classes, Unions and Arrays Help Please
Post by: Charles Pegge on June 16, 2012, 02:14:03 AM

Hi Kent, I see a problem with self-referencing. That is: when a member of the class is the class.

If this was a direct member, you would get a recursive explosion, but it should be possible to have a pointered member, as you have in cVec3

class cVec3 
    public 'member vars
        has tVec3
       
    private 'member vars
        cVec3 *mTemp
       


Anyway this will keep me busy for a while.

Charles
Title: Re: I see a problem with self-referencing
Post by: kryton9 on June 16, 2012, 01:55:34 PM
I knew that was going to be tough one. I hate to hit you with it, good luck!
Title: Re: Classes, Unions and Arrays Help Please
Post by: Charles Pegge on June 17, 2012, 03:05:08 AM
Hi Kent,

It's been an interesting journey through the hall of mirrors :)

I've marked up 2 infinite recursions!

Below your program files, a new Oxygen, and an example tree class, which I trust is reasonably proof against unintended recursion.

new tree trunk
let branchA = trunk.CreateBranch 1
let twigA1 = branchA.CreateBranch 1
...
del trunk

Charles

[attachment deleted by admin]
Title: RE: New oxygen class update
Post by: kryton9 on June 17, 2012, 12:00:39 PM
Charles, I love it. Since we are not using New, then no Del, we are using getmemory and then freememory, so that eliminates confusion on when to use which.

I don't understand this:
Code: OxygenBasic
  1.   method ShowAll() as string
  2.   tree*tr
  3.   sys i
  4.   method+=s  ": Coords "  x ", " y ", " z chr(13) chr(10)
  5.   for i=1 to branches
  6.     if t[i] then
  7.       @tr=t[i]
  8.       method+=tr.ShowAll() 'RECURSE
  9.    end if
  10.   next
  11.   end method

method+=s  ": Coords "  x ", " y ", " z chr(13) chr(10)
method+=tr.ShowAll() 'RECURSE

I thought method used like that was like return. How can you have +=?  Also on the recurse, won't it exit when it sees the first method? I don't see a conditional to prevent it.

Anyways, I know this must have been a nightmare to solve. But it is making for a tighter better oxygen.

The last 2 days I have been working on 1 million cVec3's, creating, inserting, resorting and getting back the data. Here is the moral of the story:
With a small test, as we have in the cArray that you were using, it was just a few records hand entered. It was no problem. Once I got a good RandDouble function to generate random cVec3's, I started bumping it up. One thousand, no problem. Ten Thousand, no problem. 100 Thousand, about 5 seconds total time, not bad at all. 1 Million about a minute, too slow and that was after optimizing. The original took about 4 minutes at 1 Million. In reading Sqlite3 documentation, they say I should be able to do about 50,000 inserts per second on an average computer. So I am working to get it down to around 20 seconds, with 1 million inserts. With your improvements to the classes, it will help get data in and out faster now.

Thanks again!


Title: Re: Classes, Unions and Arrays Help Please
Post by: Charles Pegge on June 17, 2012, 12:26:41 PM
Hi Kent,

it works like function= in PowerBasic. Method is the variable that will be returned at the end of the procedure. In this case it behaves like any other string variable.

No problem with recursion, the string just accumulates the recursed output of levels below. Though it is not the most efficient way of doing it, and a large tree would be better served by using a buffering techniques rather than simple concatenation.

I wouldn't worry too much about speed. Once you have a working system, the bottlenecks will become obvious, and if necessary, we unleash the assembler! But once optimisations are in place, it becomes more difficult to change your program design, so they are best done later in the project.

Charles
Title: Re: Classes, Unions and Arrays Help Please
Post by: kryton9 on June 17, 2012, 04:35:57 PM
I never knew that there was a difference between return and method or function as in PowerBasic. That is very useful to know for sure.

About speed, I got good news. As I wrote before, I do my main programming on my netbook. Long battery life, built in accelerated graphics, but not powerful. Definitely not a gaming computer. So I thought, well the sqlite3 optimization's I put in did work but not fast enough on the netbook, let me try it on my gaming notebook. I am happy to report it did it all in under 11 seconds. For loading a game level of decent quality, that is very acceptable speeds.  That is around 330,000 polygons. In many of my higher end games I wait from 30 to 45 seconds for a level to load, but those are made by a team of 30 to 50 people. Even making game level over 300,000 polys is a lot of work for a single developer. So this is all very promising performance results!!!!

Let me update the code to the latest class version that you came up with so that we work with current code to see what we can break next :)
Title: Re: Classes, Unions and Arrays Help Please
Post by: kryton9 on June 17, 2012, 06:59:05 PM
I came up with this new proposal to take oxygen to the next level. No rush, but it would be nice. The attached file is not to run, just to look at in SciTe.
Title: Re: Classes, Unions and Arrays Help Please
Post by: Charles Pegge on June 17, 2012, 09:38:23 PM

Hi Kent,

We can create a range of generic classes using macros, and substantially improve the presentation of the code.

Still need GetOperand though.

Code: OxygenBasic
  1.  
  2.  
  3. '==============================
  4. macro OperatorClass(name,tbody)
  5. '==============================
  6.  
  7.   type type##name tbody
  8.  
  9.   class name
  10.  
  11.   static type##name accum[32]
  12.   static type##name *a, *b
  13.  
  14.   static sys accumIndex, accumPopped
  15.  
  16.   has type##name
  17.  
  18.   macro GetOperand  
  19.     if accumPopped then  
  20.       @b = @a + sizeof accum
  21.       accumPopped = 0  
  22.     else  
  23.       @b = @this
  24.     end if  
  25.   end macro  
  26.  
  27.   method "load"()
  28.     @a = @accum + accumIndex
  29.     GetOperand  
  30.     copy @a,@b,sizeof accum
  31.   end method  
  32.  
  33.   method "="()
  34.     GetOperand
  35.     copy @b,@a,sizeof accum
  36.   end method  
  37.  
  38.   method "push"()  
  39.     accumIndex += sizeof accum  
  40.   end method  
  41.  
  42.   method "pop"()  
  43.     accumPopped = 1
  44.     accumIndex -= sizeof accum  
  45.     @a = @accum + accumIndex
  46.   end method
  47.  
  48. end macro
  49.  
  50.  
  51.  
  52. OperatorClass (Vector,{double x,y,z})
  53. '====================================
  54.  
  55.  
  56.   method constructor(double ax=0,ay=0,az=0)
  57.     this<=ax,ay,az
  58.   end method
  59.  
  60.   method destructor()
  61.   end method
  62.  
  63.  
  64.   method "+"()
  65.     getoperand  
  66.     a.x += b.x  
  67.     a.y += b.y  
  68.     a.z += b.z  
  69.   end method  
  70.  
  71.   method "-"()
  72.     getoperand  
  73.     a.x -= b.x  
  74.     a.y -= b.y  
  75.     a.z -= b.z  
  76.   end method  
  77.  
  78.   method "*"()
  79.     getoperand  
  80.     a.x *= b.x  
  81.     a.y *= b.y  
  82.     a.z *= b.z  
  83.   end method  
  84.  
  85.   method "/"()
  86.     getoperand  
  87.     a.x /= b.x  
  88.     a.y /= b.y  
  89.     a.z /= b.z  
  90.   end method  
  91.  
  92. '...
  93.  
  94. end class
  95.  
  96. '#recordof Vector
  97.  
  98. new vector v1 (1,2,3)
  99. new vector v2 (10,20,30)
  100. new vector v3
  101. v3=v1+v2*v2
  102.  
  103. print v3.x "," v3.y "," v3.z 'result 101,402,903
  104.  

Charles
Title: Re: Classes, Unions and Arrays Help Please
Post by: kryton9 on June 17, 2012, 10:23:56 PM
That is neat Charles. I can live happily with that syntax! Very clever as always!!!

The code does not run. I think when pasted in, it put nasties in. I noticed it did that with mine the other day. Can you attach the code, thanks.

Now one thing however. In games we need to use threads. I am not up to speed on using threads other than the little tests. I remember you said we couldn't thread something we were doing, so an area that would need work is making us be able to use our classes in threads. No hurry, but something that eventually needs to be addressed.

Here is a bottleneck my speed tests from the last few days lead too. I optimized Sqlite3, so it is running very fast, even on my netbook. It is when doing string += 's.
I then went to a string array and that is very fast, but then putting that array into 1 string bottlenecks again. When you do an insert of many records, being in one string file makes it dramatically faster.
Anyways, this is older, but very experimental files so keep them separate as I do in its own folder.

So either we need a new faster string += or be able to pass a string array. I couldn't figure it out and took out all my attempt code to make it easier to see what is going on.

Here is my latest speedtest from my weak netbook.
Title: Re: Classes, Unions and Arrays Help Please
Post by: Charles Pegge on June 17, 2012, 10:48:56 PM

Thanks Kent,

Here is the program. Do you have the new dll? (above). it has to go in the Oxygen base directory.
Title: Re: Classes, Unions and Arrays Help Please
Post by: kryton9 on June 17, 2012, 11:01:35 PM
Thanks, that worked fine. Will look at in detail now.
Title: Re: Classes, Unions and Arrays Help Please
Post by: kryton9 on June 17, 2012, 11:09:27 PM
How come you are not deleting the new vectors that were created Charles?
Title: Problem with Macro Way
Post by: kryton9 on June 17, 2012, 11:22:55 PM
Charles, I found some problems with the macro way.

Mainly, lost private, protected and public for vars and methods.
Here is my code to test. It won't compile because of the public.
Title: speed faster, but can be with one more tweak
Post by: kryton9 on June 17, 2012, 11:56:46 PM
This is a continuation of my speed tests from this post: http://www.oxygenbasic.org/forum/index.php?topic=461.msg3632#msg3632

Both of these have optimized sqlite3 setups. The post above generates 1 million vec3's. But since it is slow only puts into the sqlite3 database 20,000.
It took around 89 seconds on my netbook as the screenshot shows.

Now here is a version where I bypass the choke with strings and put one at a time into sqlite3 a million. That is it generates and puts 1 million into the database in about
47 seconds.

Once we get a single string sent with all inserts in one string, it should be as fast as it can be, even on my netbook!
Title: Re: Classes, Unions and Arrays Help Please
Post by: Charles Pegge on June 18, 2012, 01:30:26 AM
The thread problem:

Any class or procedure that relies on static variables is likely to run into state conflicts when more than one thread tries to use them.

The solution is really quite simple: Parcel all the classes and procedures concerned, into a macro, then invoke the macro a the start of each thread. Then there will be no possibility of conflict.


macro OperatorClassCluster

OperatorClass Vector2f, {single x,y}
...
end class

OperatorClass Vector3d, {double x,y,z}
...
end class

...

end macro



This generates extra code but the alternatives are too awful to contemplate  ;)
Title: Re: Classes, Unions and Arrays Help Please
Post by: Charles Pegge on June 18, 2012, 01:44:23 AM
Using OperatorClass

You can put restrictors inside the macro

macro OperatorClass(name,tbody)

  type type##name tbody

  class name

  protected

  static type##name accum[32]
  static type##name *a, *b

  static sys accumIndex, accumPopped

  has type##name

  macro GetOperand  
    if accumPopped then  
      @b = @a + sizeof accum
      accumPopped = 0  
    else  
      @b = @this
    end if  
  end macro  


  public


Title: Re: Classes, Unions and Arrays Help Please
Post by: Charles Pegge on June 18, 2012, 02:48:54 AM
Kent,

My speed test results:

Overall: 16.6 seconds

This breaks down approximately as follows

Randomiser calls: 0.15

Conversion of doubles to strings: 2.38

Concatenation of strings: 2.15


which leaves about 12 seconds for sqlite processing

my test rig:

                    tSub.Start
                        a.Begin
string s
string d1="123456789",d2="123456789",d3="123456789"
'double d1,d2,d3
                            for x = 1 to 1000000
'd1=RandD(rx,ry,rz)
'd2=RandD(rx,ry,rz)
'd3=RandD(rx,ry,rz)
                                s= "insert into Enterprise values ( "RandD( rx, ry, rz )","RandD( rx, ry, rz )","RandD( rx, ry, rz )" );" crlf
                                'a.put( "insert into Enterprise values ( "RandD( rx, ry, rz )","RandD( rx, ry, rz )","RandD( rx, ry, rz )" );" crlf )
                                'a.put( "insert into Enterprise values ( "d1","d2","d3" );" crlf )
                            next
                        a.End
                    tSub.Stop
Title: Re: Classes, Unions and Arrays Help Please
Post by: kryton9 on June 18, 2012, 11:41:43 AM
I guess the speed is fine if you are on a computer that can play high quality games.

But, if I could put the string array into a string with some pointer magic and pass that one string, even on a weak system we would get great speed, I am sure. So if you know any tricks let me know!

I will test your macro updated code later tonight when I have time. Thanks.
Title: Running single string into sqlite, saved 10 seconds
Post by: kryton9 on June 18, 2012, 06:58:42 PM
I dumped the data from the sqlite database of 1 million random double Vec3's into a text file.
I was then able to test what a difference it would make. It was 25% faster on my slow netbook.
Before single inserts, around 47 seconds.
Now around 36 to 37 seconds.

With the sqlite optimizations writing to hard disk or doing in memory are almost the same amount of time.
Which is impressive.
Title: Re: Classes, Unions and Arrays Help Please
Post by: Charles Pegge on June 18, 2012, 07:44:06 PM
Hi Kent,

The benchmarks I ran suggest the 25% time reduction is due to eliminating millions of float-to-string conversions and  string concatenations.
Title: Re: Classes, Unions and Arrays Help Please
Post by: kryton9 on June 18, 2012, 08:04:52 PM
This is a new one Charles. Actually in older speed tests I tested those and they were not that much of a hit. The += of a string is the real slow down and it seems to get longer as the amount additions take place.

Can you show how a dynamic string array can be passed to a method in another class? Or how a dynamic string array that is filled with date can be dumped to a string quickly with += ?
Title: Re: Classes, Unions and Arrays Help Please
Post by: Charles Pegge on June 18, 2012, 08:58:46 PM
Hi Kent,

Using a string buffer avoids the problem of accumulative concatentation. This demo generates a string of 100 million bytes, built from 10 million strings.

On my PC, it takes less than a second.

Code: OxygenBasic
  1.  
  2. Class StringBuffer
  3.  
  4. string Buf
  5. sys    i,le
  6.  
  7. method constructor(sys lb=1000)
  8.   buf=nuls lb
  9.   le=lb
  10.   i=0
  11. end method
  12.  
  13. method destructor()
  14.   buf=""
  15.   i=0
  16.   le=0
  17. end method
  18.  
  19. method add(string s)
  20.   sys ls=len s
  21.   if i+ls>le then
  22.     buf+=nuls le+ls 'extend buffer
  23.    le+=le+ls
  24.   end if
  25.   mid buf,i+1,s
  26.   i+=ls
  27. end method
  28.  
  29. method get() as string
  30.   return left(buf,i)
  31. end method
  32.  
  33. end class
  34.  
  35. 'TEST
  36. '====
  37.  
  38. new StringBuffer b(1e8)
  39.  
  40. for i=1 to 1e7
  41.   b.add "0123456789"
  42. next
  43.  
  44. print mid(b.buf,i-9,10) " : length of string: " b.i
  45.  
  46. del b
  47.  
  48.  

Charles
Title: Re: Classes, Unions and Arrays Help Please
Post by: Charles Pegge on June 18, 2012, 09:11:38 PM
Easy way to pass a string array:

Code: OxygenBasic
  1.  
  2. 'Passing string array
  3.  
  4. function f(sys p,n)
  5. string s at p
  6. string pr
  7. sys i
  8. for i=1 to n
  9.   pr+=s[  i  ]
  10. next
  11. print pr
  12. end function
  13.  
  14.  
  15. string s[10]
  16.  
  17. for i=1 to 10
  18.   s[ i ]=chr(i+64)
  19. next
  20.  
  21. f(@s,10)
  22.  

Charles
Title: Re: Classes, Unions and Arrays Help Please
Post by: kryton9 on June 24, 2013, 10:47:01 PM
Hi Kent,

Using a string buffer avoids the problem of accumulative concatentation. This demo generates a string of 100 million bytes, built from 10 million strings.

On my PC, it takes less than a second.

Code: OxygenBasic
  1.  
  2. Class StringBuffer
  3.  
  4. string Buf
  5. sys    i,le
  6.  
  7. method constructor(sys lb=1000)
  8.   buf=nuls lb
  9.   le=lb
  10.   i=0
  11. end method
  12.  
  13. method destructor()
  14.   buf=""
  15.   i=0
  16.   le=0
  17. end method
  18.  
  19. method add(string s)
  20.   sys ls=len s
  21.   if i+ls>le then
  22.     buf+=nuls le+ls 'extend buffer
  23.    le+=le+ls
  24.   end if
  25.   mid buf,i+1,s
  26.   i+=ls
  27. end method
  28.  
  29. method get() as string
  30.   return left(buf,i)
  31. end method
  32.  
  33. end class
  34.  
  35. 'TEST
  36. '====
  37.  
  38. new StringBuffer b(1e8)
  39.  
  40. for i=1 to 1e7
  41.   b.add "0123456789"
  42. next
  43.  
  44. print mid(b.buf,i-9,10) " : length of string: " b.i
  45.  
  46. del b
  47.  
  48.  

Charles

This is giving an error now Charles, as of June 2013.
Title: Re: Classes, Unions and Arrays Help Please
Post by: kryton9 on June 24, 2013, 10:49:55 PM
This is also giving an error now.

Easy way to pass a string array:

Code: OxygenBasic
  1.  
  2. 'Passing string array
  3.  
  4. function f(sys p,n)
  5. string s at p
  6. string pr
  7. sys i
  8. for i=1 to n
  9.   pr+=s[  i  ]
  10. next
  11. print pr
  12. end function
  13.  
  14.  
  15. string s[10]
  16.  
  17. for i=1 to 10
  18.   s[ i ]=chr(i+64)
  19. next
  20.  
  21. f(@s,10)
  22.  

Charles

Title: Re: Classes, Unions and Arrays Help Please
Post by: Charles Pegge on June 25, 2013, 12:27:01 AM
Hi Kent,

Both of these work on my PC. Is your system launching the right Oxygen?
Title: Re: Classes, Unions and Arrays Help Please
Post by: Peter on June 25, 2013, 01:37:09 AM
Quote
Class StringBuffer
 

Runs!
It needed 10 seconds here!
Title: Re: Classes, Unions and Arrays Help Please
Post by: kryton9 on June 25, 2013, 10:48:21 AM
Hi Kent,

Both of these work on my PC. Is your system launching the right Oxygen?

I downloaded and am running from the in progress zip here:
http://www.oxygenbasic.org/o2zips/OxygenBasic.zip

Will redownload and try again just to make sure all is OK.

Update: Redownloaded and still get errors. Will look for the oxygen.dll update on the forums next.
update2:downloaded from here and still get errors. http://www.oxygenbasic.org/forum/index.php?topic=749.0
update3:Deleted everything. Went in regedit and deleted all oxygen and scite entries. Reinstalled in progress OxygenBasic.
Still getting this error running the shorter code example for string array passing:
>"C:\Dev\OxygenBasic\gxo2" " -c StringArrayAsParameter.o2bas"

     pr + = [edi]!!  Unidentified instruction:   pr
 ; AFTER:     ._c
 ; LINE:       9



>Exit code: 0
Title: Re: Classes, Unions and Arrays Help Please
Post by: Charles Pegge on June 25, 2013, 12:17:31 PM
What happens if you execute:

print 0x80000000<<<2
Title: Re: Classes, Unions and Arrays Help Please
Post by: Aurel on June 25, 2013, 12:21:52 PM
Kent
where is this example...?
Title: Re: Classes, Unions and Arrays Help Please
Post by: Peter on June 25, 2013, 12:42:30 PM
Quote
pr + = [edi]!!  Unidentified instruction:   pr

Runs!
Code: [Select]
indexbase 0

sys rolled, pr=100
'print 32<<<2

'mov  eax,32
'rol  eax,2
'mov  rolled,eax
'print rolled

mem= getmemory 100
 
mov  al,255
mov  edi,mem
mov  [edi],al

pr += [edi]
print pr     ' pr=355
Title: Re: Classes, Unions and Arrays Help Please
Post by: JRS on June 25, 2013, 01:33:39 PM
I'm sure you have already done this but is there a chance an older version of Oxygen.dll is defined earlier in your search path? (syswow64 ???)
Title: Re: Classes, Unions and Arrays Help Please
Post by: kryton9 on June 25, 2013, 01:46:02 PM
What happens if you execute:

print 0x80000000<<<2


Avast popped up, I gave it permission and it ran and printed -1.
Title: Re: Classes, Unions and Arrays Help Please
Post by: kryton9 on June 25, 2013, 01:46:46 PM
Kent
where is this example...?

Copied from this example post Aurel:
http://www.oxygenbasic.org/forum/index.php?topic=461.msg3658#msg3658
Title: Re: Classes, Unions and Arrays Help Please
Post by: kryton9 on June 25, 2013, 01:54:17 PM
I'm sure you have already done this but is there a chance an older version of Oxygen.dll is defined earlier in your search path? (syswow64 ???)

I checked my environment path variables, cleaned up the registry of any scite or oxygen entries. That is why I am stumped.

Title: Re: Classes, Unions and Arrays Help Please
Post by: Aurel on June 25, 2013, 01:56:46 PM
Aha i see.
Hmmm it looks that work ok on my computer

X
Title: Re: Classes, Unions and Arrays Help Please
Post by: Charles Pegge on June 25, 2013, 02:09:38 PM
Hi kent,

the answer you should get is 2
(Oxygen-in-progress posted 14 hours ago)

Whet happens with

print version





PS: also posted lastest oxygen.dll here:

http://www.oxygenbasic.org/forum/index.php?topic=749
Title: Re: Classes, Unions and Arrays Help Please
Post by: kryton9 on June 25, 2013, 03:56:33 PM
Ok, downloaded both the latest in progress and also the oxygen.dll.

I do get an answer of 2 now for print 0x80000000<<<2  :)

Version is: A40 17:42 21/06/2013

I am thinking perhaps the code I copy from the forum is not working, perhaps it added a strange character. I will check into that next.
update: It has to be the copy and paste from the forums. I turned on view white spaces and end of line and compiled and got a different error this time.

X
Title: the solution
Post by: kryton9 on June 25, 2013, 04:12:26 PM
This did the trick:



X
Title: Re: Classes, Unions and Arrays Help Please
Post by: kryton9 on June 28, 2013, 12:49:29 AM
Charles, you mentioned that operator overloading was out, but is it still valid using it this way (OperatorClass.o2bas)?
http://www.oxygenbasic.org/forum/index.php?topic=461.msg3633#msg3633
Title: Re: Classes, Unions and Arrays Help Please
Post by: Charles Pegge on June 28, 2013, 01:38:09 AM
Hi Kent,

I dropped the whole operator overloading system, including operator classes, because it was conceptually unsound, and seldom used. So its back to straight functions, methods and macros. It sounds drastic, but in practice, I think it will have minimal impact and avoid much confusion.

To take vectors as an example, it is rare to do vector-vector arithmetic, but there are many useful vector functions, for which operator notation would be inappropriate such as producing dot products, normals, and polar conversions.
Title: Re: Classes, Unions and Arrays Help Please
Post by: kryton9 on June 28, 2013, 11:49:35 AM
I understand, I just wanted to nail it down so I can move forward then without it.