IonicWind Software

Aurora Compiler => Update Announcements => Topic started by: Ionic Wind Support Team on November 06, 2005, 02:52:14 PM

Title: Alpha update
Post by: Ionic Wind Support Team on November 06, 2005, 02:52:14 PM
I've just updated the alpha.  Hope the three of you that have purchased saved the download link ;)

Changes/Additions:
-break; command added for FOR and WHILE loops
-#define now works for constants and conditional compiling.  Helps when converting C header files.

#define WM_USER 0x400

-Better error checking.
-Removed some syntax conficts dealing with the '*'
-Very simple OOP.

You can now define a class, it's member funcitons (methods) , and class variables. It's not fully complete yet as the code for calling constructors/destructors isn't in there yet.  I'll post an example shortly.

Paul.
Title: Re: Alpha update
Post by: Ionic Wind Support Team on November 06, 2005, 05:21:20 PM
The promised OOP example.  An integer array that manages its own memory and can grow as needed in size.  Probably not completely bug free but it works.

The class functions could be compiled in a separate source file and the class definition placed in an include file.



[edit] Code modified see further down
Title: Re: Alpha update
Post by: Steven Picard on November 06, 2005, 05:35:36 PM
I compiled this example and it completely crashed on me as soon as it launched.  I'm using Windows XP SP2.  Just let me know if you need more info about my computer setup.
Title: Re: Alpha update
Post by: Ionic Wind Support Team on November 06, 2005, 05:38:13 PM
Compile a debug mode and go.  See where it stops.

I may have munged up a library when building the installation.   Anyone else care to test?
Title: Re: Alpha update
Post by: Doc on November 06, 2005, 05:39:48 PM
Works just fine here on my PC. (XP Home w/SP2)

-Doc-
Title: Re: Alpha update
Post by: mrainey on November 06, 2005, 05:50:01 PM
Crashes for me  XP SP2

Will try to get an error report.


Title: Re: Alpha update
Post by: Steven Picard on November 06, 2005, 05:51:22 PM
Here's were it crashed:
GlobalFree(m_mem);
The thread 'Win32 Thread' (0xcc8) has exited with code 0 (0x0).
Unhandled exception at 0x004053d3 in class example.exe: 0xC0000005: Access violation reading location 0x00000018.


If I run it using the debug icon on the toolbar it doesn't crash.
Title: Re: Alpha update
Post by: mrainey on November 06, 2005, 05:57:38 PM
Same here.  Runs okay when I click on Debug.
Title: Re: Alpha update
Post by: Doc on November 06, 2005, 06:01:29 PM
I just re-compiled after checking to make sure debug mode was off (it was) and got the same results as the first time...
...no problems on this end.

Maybe a reboot is in order? (stranger things happen ya know)

-Doc-
Title: Re: Alpha update
Post by: Ionic Wind Support Team on November 06, 2005, 06:10:53 PM
Which GlobalFree statement?

Title: Re: Alpha update
Post by: Steven Picard on November 06, 2005, 06:23:15 PM
Quote from: Ionic Wizard on November 06, 2005, 06:10:53 PM
Which GlobalFree statement?



Whoops! That wasn't too helpful of me.  Line 86.
Title: Re: Alpha update
Post by: Ionic Wind Support Team on November 06, 2005, 06:27:52 PM
Error in my logic somewhere and you have fragmented memory ;)

Give me a sec...
Title: Re: Alpha update
Post by: Steven Picard on November 06, 2005, 06:36:48 PM
Quote from: Ionic Wizard on November 06, 2005, 06:27:52 PM
...and you have fragmented memory ;)

Sorry, what were we talking about again?  ??? ;D

BTW, do you know of a good free app for defraging memory??
Title: Re: Alpha update
Post by: Ionic Wind Support Team on November 06, 2005, 06:37:21 PM
Try this:


//simple example of using objects in Aurora
declare import,GlobalAlloc(flags as unsigned int,size as int),unsigned int;
declare import,GlobalReAlloc(handle as unsigned int,size as int,flags as unsigned int),unsigned int;
declare import,GlobalFree(handle as unsigned int),int;
declare import,RtlMoveMemory(dest as int,source as int,size as int);

class IntArray {
//the class constructor
declare IntArray();
//the class destructor
declare _IntArray();
//member functions
declare GetAt(int pos),int;
declare SetAt(int pos,int value);
declare SetAtGrow(int pos,int value);
declare SetSize(int size);
declare GetCount(),int;
declare RemoveAll();
//member variables
int m_mem;
int m_GrowBy;
int m_numItems;
int m_allocated;
}

IntArray :: IntArray()
{
m_GrowBy = 10;
m_mem = GlobalAlloc(0x40,m_GrowBy * 4);
m_numItems = 0;
m_allocated = 10;
return;
}

IntArray :: _IntArray()
{
//clean up our object
if(m_mem)
{
GlobalFree(m_mem);
m_mem = NULL;
}
m_numItems = 0;
m_allocated = 0;
return;
}

IntArray :: GetAt(int pos),int
{
if pos < m_numItems
{
return *(int)(m_mem + (pos * 4));
}
return 0;
}

IntArray :: SetAt(int pos,int value)
{
if(pos < m_allocated)
{
*(int)(m_mem + (pos * 4)) = value;
if((pos+1) > m_numItems)
{
m_numItems = pos+1;
}
}
return;
}

IntArray :: SetAtGrow(int pos,int value)
{
unsigned int temp;
int total;
if( (pos + 1) > m_allocated)
{
//calculate how many blocks to allocate
total = (pos+1) - m_allocated;
total = (total & m_GrowBy) + 1;
total *= m_GrowBy;
//Grow the array
temp = GlobalRealloc(m_mem,(m_allocated + total) * 4,0x40);
if(temp)
{
m_mem = temp;
}
else
{
//could not reallocate so copy
temp = GlobalAlloc(0x40,(m_allocated + total) * 4);
RtlMoveMemory(temp,m_mem,m_allocated * 4);
GlobalFree(m_mem);
m_mem = temp;
}
m_allocated += m_GrowBy;

}
*(IntArray)this.SetAt(pos,value);
return;
}

IntArray :: SetSize(int size)
{
unsigned int temp;
if(size > m_allocated)
{
temp = GlobalRealloc(m_mem,(size - m_allocated) * 4,0x40);
if(temp)
{
m_mem = temp;
}
else
{
temp = GlobalAlloc(0x40,(size - m_allocated) * 4);
RtlMoveMemory(temp,m_mem,m_allocated * 4);
GlobalFree(m_mem);
m_mem = temp;

}
m_allocated = size;
}
return;
}

IntArray :: GetCount(),int
{
return m_numItems;
}

IntArray :: RemoveAll()
{
if(m_allocated)
{
GlobalFree(m_mem);
m_allocated = 10;
m_numItems = 0;
m_mem = GlobalAlloc(0x40,m_GrowBy * 4);
}
return;
}


//test program for Intarray class

global sub main(),int
{
IntArray ia;
//temporary until constructors work
ia.IntArray();
for x=0;x < 100;x++
{
ia.SetAtGrow(x,RAND(100));
}
writeln("array has :" + str$(ia.GetCount(),0) + " items\n");
writeln("Press any key to show array contents\n");
while GetKey() = "";
//now lets show what we did.
for x=0;x < ia.GetCount();x++
{
writeln(str$(ia.GetAt(x),0));
}
writeln("\n\n");
ia.RemoveAll();
writeln("array now has :" + str$(ia.GetCount(),0) + " items\n");
writeln("Press any key close\n");
while GetKey() = "";

//temporary until destructors work
ia._IntArray();

return 0;

}


RtlMoveMemory was declared wrong, and my logic for growing was a bit off.

Title: Re: Alpha update
Post by: Ionic Wind Support Team on November 06, 2005, 06:40:11 PM
Quote from: stevenp on November 06, 2005, 06:36:48 PM
Quote from: Ionic Wizard on November 06, 2005, 06:27:52 PM
...and you have fragmented memory ;)

Sorry, what were we talking about again?  ??? ;D

BTW, do you know of a good free app for defraging memory??

Nope.  Use the Ctrl-Alt-Delete method myself ;)
Title: Re: Alpha update
Post by: Steven Picard on November 06, 2005, 06:44:57 PM
Excellent! Worked great.  But was it supposed to format my hard drive? J/K
Title: Re: Alpha update
Post by: mrainey on November 06, 2005, 06:45:34 PM
Works now.
Title: Re: Alpha update
Post by: Doc on November 06, 2005, 06:51:02 PM
I don't get it...
How could two out of three of us have had problems with the exact same code, especially when both samples work on my end?  :-\

I know I'm more than a little bit "different", but geesh..

-Doc-
Title: Re: Alpha update
Post by: Doc on November 06, 2005, 06:54:10 PM
QuoteNope.  Use the Ctrl-Alt-Delete method myself ;)

All hail to the old three finger salute!  ;D

-Doc-
Title: Re: Alpha update
Post by: Brian on November 07, 2005, 02:25:04 AM
Hi,

Just tried this example, due to the time difference. Works OK for me, XP Pro, SP2

Brian
Title: Re: Alpha update
Post by: Ionic Wind Support Team on November 07, 2005, 02:39:35 AM
Quote from: docmann on November 06, 2005, 06:51:02 PM
I don't get it...
How could two out of three of us have had problems with the exact same code, especially when both samples work on my end?  :-\

I know I'm more than a little bit "different", but geesh..

-Doc-

GlobalRealloc will fail if memory is overly fragmented.  Which then drops into the other part of the code to allocate a new block of memory and copy the contents of the array.  Your system and mine worked because GlobalRealloc succeeded.

Title: Window exaple
Post by: Brian on November 07, 2005, 06:57:04 AM
Paul,

Any chance of an example with a window, with maybe a menu and button, etc?

Brian
Title: Re: Window exaple
Post by: Steven Picard on November 07, 2005, 08:32:25 AM
Quote from: Brian Pugh on November 07, 2005, 06:57:04 AM
Paul,

Any chance of an example with a window, with maybe a menu and button, etc?

Brian

Brian, I don't think the GUI is supposed to be completed until Beta 1:
http://www.ionicwind.com/forums/index.php?topic=18.0
Title: Re: Alpha update
Post by: Brian on November 07, 2005, 08:37:30 AM
Whoops! Should have RTFM'd!
Title: Re: Alpha update
Post by: Ionic Wind Support Team on November 07, 2005, 11:48:18 AM
Still designing the GUI commands.  The alphas are to shake down the syntax, check for glaring bugs, etc.

You can use the API directly if you really need to see a window pop up ;)   Alpha 2 will have the start of the GUI commands.

I have been toying with the idea of an oop hybrid for the GUI libray.   Something along the lines of:

window win;
win.CreateWindow(0,0,100,300,style,exstyle,title);
win.DrawRect(10,10,50,50,fg,bg);
...

Then you could have two choices of how to handle messages.

#1 Inherit from the window class.  Those of you that don't know oop will need a little help.

class mainwindow : window
{
    declare virtual OnMouseMove(int x, int y, int flags);
    declare virtual OnLbuttonDown(int x, int y, int flags);
...
}

mainwindow :: OnMouseMove(int x, int y, int flags)
{
     //handle mouse move messages for our mainwindow.
}

mainwindow.CreateWindow(0,0,100,300,style,exstyle,title);



For those of you that have only used procedural languages OOP allows inheriting all of the functions and capabilities of the base class. In the case above we created a new class called 'mainwindow' whose base class was 'window'.  We only need to override the functions in the base class we want to use.  In the base 'window' class there would be virtual functions of the same name that do nothing.

#2.  A hybrid merging of worlds.  Using just the window class I could have a function like:

win.SetExternalHandler(&myhandler);

sub myhandler(msg as uint, ...)
{
}

In anyevent I am just thinking out loud.

Title: Re: Alpha update
Post by: Steven Picard on November 07, 2005, 11:49:59 AM
Either would be excellent although I prefer the first one.   8)
Title: Re: Alpha update
Post by: GWS on November 07, 2005, 02:08:02 PM
Paul, your grasp of these things is awesome ..ÂÃ,  :)

Pick whichever you think is most elegant.

best wishes, :)

Graham
Title: Re: Alpha update
Post by: Doc on November 07, 2005, 04:46:26 PM
I don't know that I would have a preference either way.

QuoteThose of you that don't know oop will need a little help

Being a cross-platform language with a distinctive "C-like" syntax, Aurora I believe, will eventually be (for me at least)  that "serious" new language tool that will be well worth the learning curve... whatever that may be.

-Doc-
Title: Re: Alpha update
Post by: Steven Picard on November 07, 2005, 07:46:52 PM
I would prefer the first method since it is more what I am use to and is probably more standard.
Title: Re: Alpha update
Post by: Steven Picard on November 07, 2005, 07:47:41 PM
Quote from: docmann on November 07, 2005, 04:46:26 PM
....Aurora I believe, will eventually be (for me at least)  that "serious" new language tool that will be well worth the learning curve... whatever that may be.

I am with you on that.