What if I need to use a complex type in HLA-CTL, when defining a macro for example?
Is there something as a CTL-STDLIB?
How can I declare a compile-time variable as array or other complex type?
Am I limited to primtive types when creating compile-time variables???
Thanks :U
Julio
You're limited only by imagination :)
The Hla "type" section is compile-time, so you can use it to make complex types for both run time and compile time variables. The only difference is that the compile time works a little different, more 'high level'
Here's an example:
program ctlvar;
type
valRecord :record
val1 :dword;
val2 :dword;
endrecord;
endtype;
val
zeroOnes :valRecord[10] := 10 dup [valRecord:[0,1]];
endval;
begin ctlvar;
#for ( cnt := 0 to 9)
#print ( zeroOnes[cnt].val1, ", ", zeroOnes[cnt].val2);
#endfor
end ctlvar;
Can I use type section to make a class for compile-time?
Something as:
type
valRecord :class
var
val1 :dword;
val2 :dword;
endclass;
endtype;
What I really want to know is the real power of HLA macros...
If I am able to use dynamic memory allocation and explore the features of OOP in HLA-CTL, for example, I can write very complex and useful macros...
I've never tried to use classes in CTL so I don't know. My first impression is no, since class VMTs are statically allocated. You would need a compile time virtual macro table which the engine just doesn't allow as far as I know.
However, you can have inheritance in records, which can serve as imitation classes.
The macro I intend to write does several calculations and has to store partial results for later processing... I don't know how much memory is necessary since it depends on the value of an argument passed to the macro and on the results of those calculations...
Of course I could create a very large array so I would get all memory I need but I'm wondring if there isn't any ellegant way of doing that...
I'd like to use something similar to a stack so I could push data into it as long as I need doing that. But there's no such thing in CTL so I have to create one.
I started with a Linked List but CTL doesn't allow writing something like this:
Node :record
value :int32;
next :Node;
endrecord;
Although a record member is allowed to be another record, it can't be of the same type of the record being defined (since the type is not defined yet).
Oh, I am very disappointed. Every idea I have can't be implemented..... :toothy
Quote from: juliomacedo on January 18, 2006, 02:02:33 AM
Can I use type section to make a class for compile-time?
Something as:
type
valRecord :class
var
val1 :dword;
val2 :dword;
endclass;
endtype;
Classes cannot be initialized at compile time, hence they aren't really CTL objects. Certainly you can declare them and manipulate them at compile-time, but you can't initialize them nor reference fields at compile time. However, as records provide most of the facilities of classes (when dealing with data), so this shouldn't be too much of a problem.
Cheers,
Randy Hyde
How can I simulate a stack class for compile-time using records? I can't, can I?
Quote from: Randall Hyde on January 19, 2006, 12:27:48 AM
Quote from: juliomacedo on January 18, 2006, 02:02:33 AM
Can I use type section to make a class for compile-time?
Something as:
type
valRecord :class
var
val1 :dword;
val2 :dword;
endclass;
endtype;
Classes cannot be initialized at compile time, hence they aren't really CTL objects. Certainly you can declare them and manipulate them at compile-time, but you can't initialize them nor reference fields at compile time. However, as records provide most of the facilities of classes (when dealing with data), so this shouldn't be too much of a problem.
Cheers,
Randy Hyde
Hi Randall,
There is a crash bug in HLA here. You can't declare a single instence of a record as a ctl variable, doing so causes a crash.
program ctlvar;
type
valRecord :record
val1 :dword;
val2 :dword;
endrecord;
endtype;
// ?zeroOnes :valRecord; // HLA goes bonkers
?zeroOnes :valRecord[1]; // this is okay
begin ctlvar;
end ctlvar;
1. Yeeees, it's terrible... HLA does not complain about an error, it simply causes a windows message to be shown :'(
2. I still want a compile-time stack... No ideas? :U