Re: [fpc-pascal] Procedural generics question

2020-09-04 Thread Michael Van Canneyt via fpc-pascal
On Thu, 3 Sep 2020, Lars via fpc-pascal wrote: On 2020-08-26 05:44, Nico Neumann via fpc-pascal wrote: The TypeInfo function checks the code during run-time thus the generated code is 'bloated'. Better use the compiler intrinsic GetTypeKind. {$mode objfpc} uses typinfo; generic procedur

Re: [fpc-pascal] Procedural generics question

2020-09-03 Thread Lars via fpc-pascal
On 2020-08-26 05:44, Nico Neumann via fpc-pascal wrote: The TypeInfo function checks the code during run-time thus the generated code is 'bloated'. Better use the compiler intrinsic GetTypeKind. {$mode objfpc} uses typinfo; generic procedure Add; begin if GetTypeKind(T) = tkInteger then

Re: [fpc-pascal] Procedural generics question

2020-08-26 Thread Ryan Joseph via fpc-pascal
> On Aug 27, 2020, at 3:49 AM, Sven Barth wrote: > >> if T is integer then >> ; >> >> and get something which is well optimized. > Because there was simply no need for this. Since the introduction of generics this would be a nice extension to add for the is operator. Regards, Ryan

Re: [fpc-pascal] Procedural generics question

2020-08-26 Thread Sven Barth via fpc-pascal
Am 25.08.2020 um 23:47 schrieb Benito van der Zander via fpc-pascal: Hi, that is generating rather odd code (r40721) project1.lpr:9    begin 00401090 55   push   %rbp 00401091 4889e5   mov    %rsp,%rbp 00401094

Re: [fpc-pascal] Procedural generics question

2020-08-26 Thread Sven Barth via fpc-pascal
Am 26.08.2020 um 14:59 schrieb Ryan Joseph via fpc-pascal: On Aug 26, 2020, at 5:44 PM, Nico Neumann via fpc-pascal wrote: generic procedure Add; begin if GetTypeKind(T) = tkInteger then WriteLn('an integer'); if GetTypeKind(T) = tkString then WriteLn('a string'); end; Question fo

Re: [fpc-pascal] Procedural generics question

2020-08-26 Thread Ryan Joseph via fpc-pascal
> On Aug 26, 2020, at 5:44 PM, Nico Neumann via fpc-pascal > wrote: > > generic procedure Add; > begin > if GetTypeKind(T) = tkInteger then WriteLn('an integer'); > if GetTypeKind(T) = tkString then WriteLn('a string'); > end; Question for the compiler team why doesn't the "is" operat

Re: [fpc-pascal] Procedural generics question

2020-08-26 Thread Nico Neumann via fpc-pascal
The TypeInfo function checks the code during run-time thus the generated code is 'bloated'. Better use the compiler intrinsic GetTypeKind. {$mode objfpc} uses typinfo; generic procedure Add; begin if GetTypeKind(T) = tkInteger then WriteLn('an integer'); if GetTypeKind(T) = tkString t

Re: [fpc-pascal] Procedural generics question

2020-08-25 Thread Benito van der Zander via fpc-pascal
Hi, that is generating rather odd code (r40721) project1.lpr:9    begin 00401090 55   push   %rbp 00401091 4889e5   mov    %rsp,%rbp 00401094 488d6424f0   lea -0x10(%rsp),%rsp 00401099 48895df

Re: [fpc-pascal] Procedural generics question

2020-08-24 Thread leledumbo via fpc-pascal
> I remember something like this in RTTI though but can't find it in your docs yet for generics. {$mode objfpc} uses typinfo; generic procedure Add; begin if TypeInfo(T) = TypeInfo(Integer) then WriteLn('an integer'); if TypeInfo(T) = TypeInfo(String) then WriteLn('a string'); end; begi

[fpc-pascal] Procedural generics question

2020-08-24 Thread Lars via fpc-pascal
Inside a generic procedure (no objects used just a procedure) is there a way to check which type the code is being used for such as: generic procedure Add(); begin if type = integer then... if type = string then... begin // specialized code for that type only end end; I remember so