Cc i am holding off abit on the compiler side of thing because posting code it emits is asking for all the guys here to jump onto it like a pack of starving dogs.
In regards i actualy coverted the above scripts to see the performance gain or decrease in the compiler. From my observation Grendel's code actualy ran faster in the compiler than my original version that i did about a week ago. So congrats to grendel for his help there. I have mainly underlined the bottleneck with the system, its in regards how the compiler treats variables. I will do some higher language examples here and some code that is emited from the compiler that you can see how things are done.
Remember its an OOC it not a precedual language. I have thought about it long and hard, and any such tasks that i find that require a large amout of proccessing i can actualy convert into libaray files eg.. the compiler enables you to also write in higher language to built your function files, such i have tended to mostly keep the whole compiler in the script language department to test performance hit it would cause.
I am finding out con-currently the performance hit i am getting using the techniquie i do in the compiler is "lets just say, a hit in the nutts when doing jobs that require down to the micro second to execute".
Anyway onto some examples.
<!-- Last chance to turn back -->
/**
* Author Chad Lion
* Version: 1.00
* Date: Thursday, June 02, 2005
*
* This document is for demonstration purposes.
* Its to reflect a ongoing development of two current projects
* One the object orientated compiler and the next is the
* A.I. Heuristic
*/
/**
* Okay lets start with the basics and move up from there
* this is a class type, a class is a blue print to building
* an object. What is an object, well an object is a instance
* of a class. With a copy of all its variables and methods
* such try not to confuse a ofp game object with higher
* language object.
*/
public class Example{
/**
* This is the location that ofp will jump to when the file
* is executed. But for this demostration its to show how
* methods and variables are handeled within the compiler
*/
public static void main(){
/**
* We want to declare some variables for some calculations
* you have the following types
* boolean <- Boolean
* int <- Number
* string <- String
* unitside <- side
* mygroup <- group
* object <- game object
* The above are all your primitive data types.
*
* Higher language data types
* Class <- Blue print for a object
* array <- Can be any of the primitive data types and also class data type
*/
int a1 = 2;
int a2 = 3;
int a3 = 4;
int a4 = 5;
a1 = (a1 * a2)/2*a4-a3;
print( a1 );
}
}
This is the emited code
MA=0
heapsearch = preprocessFile "heapsearch.sqf"
_heap=[]
_stack=[]
_reg2=0
_stack = _stack + [0]
_stack = _stack + [0]
goto "5"
#5
_stack set [ (count _stack), _reg2]
_reg2 = (count _stack)
_stack set [ (count _stack), [0,0,0,0]] [b]REFERNCE ONE[/b]
_reg1 = (_stack select _reg2)
_reg4=2.0
_reg1 set [0,_reg4] [b]REFERNCE TWO[/b]
_reg4=3.0
_reg1 set [1,_reg4] [b]REFERNCE THREE[/b]
_reg4=4.0
_reg1 set [2,_reg4] [b]REFERNCE FOUR[/b]
_reg4=5.0
_reg1 set [3,_reg4] [b]REFERNCE FIVE[/b]
_reg4= (_reg1 select 0)
_reg5= (_reg1 select 1)
_reg4=_reg4*_reg5
_reg5=2.0
_reg6=_reg4/_reg5
_reg4= (_reg1 select 3)
_reg6=_reg6*_reg4
_reg4= (_reg1 select 2)
_reg5=_reg6-_reg4
_reg1 set [0,_reg5]
_reg4= (_reg1 select 0)
hint format[ "%1",_reg4]
exit
Okay lets start from the top down what the compiler does. Because ofp has no actualy memory address range that you will have within a normal machine language for example x86. This has to be emulated some how, this emulation is done via an array, using it as a stack to allocate and de-allocate memory on the fly via the programs execution.
In reference 1 you will see that the compiler via its second pass will count all the variables within the higher language. Then will create a make frame ( Make Frame being memory space for the method to store its local variables ). This is the memory space that the variables are stored in, so each time you assign a = b. b is retreaved from the stack yes, each time. And then assigned to the array at position a.
Though this is mostly the bottleneck within the system. That because of variables not actualy being stored in an memory address range, they have to be stored within an array that holds those locations.
You will see the same keep occuring in reference to 2,3,4 in the emited code from the compiler.
But!
Not all is lost, because of the nature and how i have designed the system. It emits assembly instructions out into an interface that converts those assembly instructions into ofp game script language code. Such the result is what you see above.
Objects and other things are handeled ore or less in regards the same way, but with key differences that i wont go into in this dicussion. But, what i am thinking lately is actualy creating a faster emited code by simply declaring the whole stack within functions that would greatly speed up the proccessing time of the script lagnuage completly abstracted from the higher language.
So, even though at this point in time. I have found issues arrising within the system. Its not the end of the world. I can simply re-modifiy the emited game script language to take into account doing things differently.
But right now i have to head off to sleep, its getting late and i need the rest for a full days work tommoro.