Re: [fpc-pascal] Case statement for class introspection

2022-01-14 Thread Ryan Joseph via fpc-pascal


> On Jan 15, 2022, at 8:30 AM, Michael Van Canneyt via fpc-pascal 
>  wrote:
> 
>> I saw a new syntax in Swift which I thought was clever and fits a pattern
>> I've seen before.  Basically it's a case statement for class types which
>> lets you branch depending on which class type the class instance is at run
>> time.
> 
> I think Scala did it before Swift.

What did it look like? Seems like an obvious feature any OOP language should 
have.

Swift has a compound switch statement which does lots of things. It's a little 
messy but it accomplishes this well. For example here they have a "case is" and 
"case let _ as" which tests for class type or casts to a local variable using 
"as".

   switch object {
case is Message:
   break
case let content as MessageContent:
   break
case let attachment as Attachment:
   break
default: break
  }

Problem for Pascal is how to handle the casting mess. C languages (and Delphi 
now I guess) can do inline variable declarations to avoid the casting. 

Come to think of it this a similar problem with for-loops where you want to 
loop over a collection of only certain types. For example:

for monster in monsters do
if monster is TZenChan then
  TZenChan(monster).Dothis;

Swift does something similar as the switch which would look kind of like this:

for case monster as TZenChan in monsters do
  TZenChan(monster).Dothis;


That syntax is not so nice but I like they're trying to help us manage class 
introspection using existing language constructs.

Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Case statement for class introspection

2022-01-14 Thread Michael Van Canneyt via fpc-pascal



On Sat, 15 Jan 2022, Ryan Joseph via fpc-pascal wrote:


I saw a new syntax in Swift which I thought was clever and fits a pattern
I've seen before.  Basically it's a case statement for class types which
lets you branch depending on which class type the class instance is at run
time.


I think Scala did it before Swift.



I wonder if this could be implemented in FPC? The syntax would be kind of 
clumsy though since you can't declare  scoped variables in Pascal so you would 
need to do lots of casts but it's still cleaner than the equivalent code as if 
statements.


This idea has been proposed before by Izak Maciej. 
I'm all for it.


Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Case statement for class introspection

2022-01-14 Thread Ryan Joseph via fpc-pascal
I saw a new syntax in Swift which I thought was clever and fits a pattern I've 
seen before. Basically it's a case statement for class types which lets you 
branch depending on which class type the class instance is at run time.

I wonder if this could be implemented in FPC? The syntax would be kind of 
clumsy though since you can't declare  scoped variables in Pascal so you would 
need to do lots of casts but it's still cleaner than the equivalent code as if 
statements.

=

  case monster of
TZenChan:
  TZenChan(monster).DoThis;
TPulPul:
  TPulPul(monster).DoThat;
otherwise
  monster.DoSomething;
  end;

Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] StrToInt is using ShortString buffer?

2022-01-14 Thread Alexey Tor. via fpc-pascal

That is another reason for PChar based inner func. :)


the input might be


Re: [fpc-pascal] StrToInt is using ShortString buffer?

2022-01-14 Thread Benito van der Zander via fpc-pascal

Hi,


I don’t see what the problem with a shortstring buffer is.. strtoint 
could not make use of an input string longer than 256 characters 
anyway, because the output integer could not have more than 19 digits 
anyway.. so an input string longer than this would be useless… just 
convert to a shortstring and to strtoint.




the input might be


Re: [fpc-pascal] Crash on Windows for Aarch64 target

2022-01-14 Thread Marc Weustink via fpc-pascal



On 12-1-2022 14:37, Volo Zyko via fpc-pascal wrote:

Hello,

Some time ago it was announced an experimental support for Windows on Aarch64 
(namely in this post 
https://lists.freepascal.org/pipermail/fpc-pascal/2020-April/057762.html). I 
tried to build a dll with a proprietary code for that target. Building 
succeeded but it crashes on loading. At the moment I don't understand how to 
investigate the issue to provide more information about it.


I've been experimenting with this too. It looked cool to me to see if I 
can show our flagship product running on a rpi4.


The major pain is to debug windbg what is going wrong on asm level.
One of the issues I ran into was something weird when a case jumptable 
was used. It jumped to invalid code. I never was able to reproduce this 
in a smaller example and in the full code it was one of the issues it 
could run into.
Now that VisualStudio starts to supports more and more dwarf debug info, 
I hope one day to use it as debugger.


Marc

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal