News:

Let's find out together what makes a PIC Tick!

Main Menu

Compile-time variable type information

Started by LeonJ, Jul 27, 2026, 04:53 PM

Previous topic - Next topic

LeonJ

Question regarding compile-time variable type information

Hi Les / everyone,

While developing a command-driven object interface for Trastikata's TFT graphics library, I have been looking at ways to make the Object Interface (OI) wrappers (which call the library procedures) more generic.

Positron obviously knows a variable's type during compilation, since it can handle things like:

MyVar = MyDword.Float

and:

SizeOf(MyVar)

My requirement is not runtime type discovery (I understand that the PIC does not store type information with variables once the code is compiled).

What I would like to know is whether Positron exposes any compile-time intrinsic that can return a variable's declared type, something along the lines of:

If VarType(MyVar) = _Word Then
    ...
ElseIf VarType(MyVar) = _Float Then
    ...
EndIf

or perhaps:

Select VarType(MyVar)

Case _Byte
Case _Word
Case _DWord
Case _Float

EndSelect

The purpose would be to allow generic procedures/macros to generate the correct code depending on the destination variable type for a procedure call.

For example, my OI layer currently has to manually know that:

ArcRL: (draw an Arc)

    parameter 6  = Bit
    parameter 8  = SWord
    parameter 9  = SWord
    parameter 10 = Float

and then load temporary variables of the correct type before calling the library procedure.

A compile-time VarType() (if possible) would allow this type mapping to become much more automatic.

Does Positron have such a feature already, or is there another recommended method for obtaining a variable's declared type during compilation?

Thanks.

RGV250

Hi,
It looks like you want structures which Positron does not support.

Regards,
Bob

LeonJ

In the manual under "Protected Compiler Words" there are terms like:

Prm_Count, Prm_1 ... Prm_15

Return_Type, Return_Var

Float_Dword, Dword_Float, Word_Float, Float_Word

Bit_Bit, Byte_Bit, Wreg_Word, Wreg_Float, etc.

Num_Word, Num_Dword, Num_Float

VarPtr, AddressOf, SizeOf

Some of these are documented and usable, while others appear to be compiler internal.

Out of curiosity, are any of the undocumented ones intended for user use, or are they strictly internal?

In particular, I'm wondering whether any of them provide compile-time information about a procedure or its parameters (such as parameter count, parameter types, return type, etc.).

I'm not looking for runtime reflection, only whether the compiler exposes any compile-time information that could be used when writing generic procedures or macros.

top204

Some of the, undocumented, protected commands are for the macro mechanism that is in the compilers, and that were used extensibly before I added procedures to the Positron8 compiler.


Such as: Return_Type, Return_Var, Float_Dword, Dword_Float, Word_Float, Float_Word, Bit_Bit, Byte_Bit, Wreg_Word, Wreg_Float, Num_Word, Num_Dword, Num_Float, etc...

Others are for compiler internals, or assembler commands or directives etc...

Regards
Les

LeonJ

Thanks, Les.

That clarifies things. I had wondered whether they were remnants of earlier language features or simply internal compiler support.

Are any of these commands intended to be used directly from user code, or are they strictly for compiler/macros and internal use?

If there are any that are supported for user programs, could you perhaps give a brief example of how they are intended to be used?

Regards,

Leon