Recent

Author Topic: Possible future competition for Delphi and FPC?  (Read 3400 times)

SlightlyOutOfPhase

  • New Member
  • *
  • Posts: 33
Possible future competition for Delphi and FPC?
« on: December 14, 2018, 04:27:10 am »
Found this project earlier today, called NextPascal. https://github.com/SkliarOleksandr/NextPascal

The compiler implementation seems extremely complete and very professionally written, and it looks to even have language features that don't exist in Delphi or FPC. Anyone familiar with it/know anything about it?
« Last Edit: December 14, 2018, 04:28:49 am by SlightlyOutOfPhase »

CCRDude

  • Hero Member
  • *****
  • Posts: 502
Re: Possible future competition for Delphi and FPC?
« Reply #1 on: December 14, 2018, 09:48:43 am »
From something called "professionally written", I would expect file headers. Would make it much easier for the reader to understand the basic structure of the repo.
I would also expect some kind of documentation, "docs/" is just external information used, and "features.txt" is in cyrillic letters, and Google Translate only reveals attributes as something worth noting. I see in your post history that you're unhappy about FPC not supporting attributes, but I mostly see many features that are not listed in the translation.
I see references to JS, LLVM and execution VMs, but all this seems to be external.
And I see that it seems to use CodeTyphon for testing, instead of pure Lazarus. Since CT is based on Lazarus, it would make much more sense to test it with Lazarus first.

Finally, keep in mind that any advanced IT student can write a simple compiler, but Delphi and FPC are much more than that (take a look at their rich RTLs).

I could try to see it from a different perspective, but if you raise the bar that high, disappointment is a logical first reaction ;)

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7858
Re: Possible future competition for Delphi and FPC?
« Reply #2 on: December 14, 2018, 10:23:13 am »
Instead of posting here some empty message, why don't you post your testing results with e.g. Delphi or FPC sources?

From what I can see it is a parser more than a compiler with an incomplete virtual machine.
« Last Edit: December 14, 2018, 10:25:41 am by marcov »

Thaddy

  • Hero Member
  • *****
  • Posts: 9436
Re: Possible future competition for Delphi and FPC?
« Reply #3 on: December 14, 2018, 11:24:30 am »
Rather nice, but not very good code:
Code: Pascal  [Select]
  1. function Sign(I: Integer): Integer; inline; // faster then Math.Sign.
  2. begin
  3.   if I < 0 then
  4.     Sign := -1
  5.   else if I > 0 then
  6.     Sign := +1
  7.   else
  8.     Sign := 0;
  9. end;

That does not look too good when a proper student would probably write something like this:
Code: Pascal  [Select]
  1. function sign(const i:integer):integer;
  2. begin
  3.  Result := integer(i > 0) - integer(i < 0); // casts are cheap..
  4. end;
Which is branchless....

There are more first look issues...
also related to equus asinus.

wp

  • Hero Member
  • *****
  • Posts: 6654
Re: Possible future competition for Delphi and FPC?
« Reply #4 on: December 14, 2018, 11:42:55 am »
Code: Pascal  [Select]
  1. function Sign(I: Integer): Integer; inline; // faster then Math.Sign.
  2. begin
  3.   if I < 0 then
  4.     Sign := -1
  5.   else if I > 0 then
  6.     Sign := +1
  7.   else
  8.     Sign := 0;
  9. end;
A question regarding the comment "faster than Math.Sign": Why is this code supposed to be faster than the one which I just copied out of Math.pas?
Code: Pascal  [Select]
  1. Type
  2.   TValueSign = -1..1;
  3.  
  4. const
  5.   NegativeValue = Low(TValueSign);
  6.   ZeroValue = 0;
  7.   PositiveValue = High(TValueSign);
  8.  
  9. function Sign(const AValue: Integer): TValueSign;inline;
  10. begin
  11.   If Avalue<0 then
  12.     Result:=NegativeValue
  13.   else If Avalue>0 then
  14.     Result:=PositiveValue
  15.   else
  16.     Result:=ZeroValue;
  17. end;  
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

440bx

  • Hero Member
  • *****
  • Posts: 1359
Re: Possible future competition for Delphi and FPC?
« Reply #5 on: December 14, 2018, 04:11:23 pm »
Rather nice, but not very good code:
<snip>
That does not look too good when a proper student would probably write something like this:
Code: Pascal  [Select]
  1. function sign(const i:integer):integer;
  2. begin
  3.  Result := integer(i > 0) - integer(i < 0); // casts are cheap..
  4. end;
Which is branchless....
Yes, it is branchless but...  as written above the function's result is undefined when the parameter passed to it is zero.

Should that be documented as a "limitation" ?  I guess a "proper student" would properly initialize the return value upon function entry.  In programming, propriety is even better than property.


using FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

SlightlyOutOfPhase

  • New Member
  • *
  • Posts: 33
Re: Possible future competition for Delphi and FPC?
« Reply #6 on: December 14, 2018, 04:28:32 pm »
A question regarding the comment "faster than Math.Sign": Why is this code supposed to be faster than the one which I just copied out of Math.pas?

Yours is from the FPC version I think? It seems likely they're referring to Delphi. I can't remember what that implementation looks like.

Either way I think the Sign thing is a pretty irrelevant nitpick. When I said "professional" I was referring to the stuff in this folder: https://github.com/SkliarOleksandr/NextPascal/blob/master/Compiler

Take a look at this file, for example: https://github.com/SkliarOleksandr/NextPascal/blob/master/Compiler/NPCompiler.pas

From what I can see it is a parser more than a compiler with an incomplete virtual machine.

I'm not so sure about that. It seems to implement the full infrastructure of a compiler, e.g. type-checker/e.t.c and even a package system.

It also has a variety of in-progress codegen backends, not just a VM implementation:

https://github.com/SkliarOleksandr/NextPascal/tree/master/ILTranslators
« Last Edit: December 14, 2018, 04:30:15 pm by SlightlyOutOfPhase »

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 693
    • Lebeau Software
Re: Possible future competition for Delphi and FPC?
« Reply #7 on: December 15, 2018, 01:26:21 am »
Yes, it is branchless but...  as written above the function's result is undefined when the parameter passed to it is zero.

How do you figure that?  I see it as being defined as 0:

integer(i > 0) = integer(0 > 0) = integer(false) = 0

integer(i < 0) = integer(0 < 0) = integer(false) = 0

So:

Result = integer(i > 0) - integer(i < 0) = 0 - 0 = 0

Yours is from the FPC version I think? It seems likely they're referring to Delphi. I can't remember what that implementation looks like.

Like this:

Code: [Select]
type
  TValueSign = -1..1;

const
  NegativeValue = Low(TValueSign);
  ZeroValue = 0;
  PositiveValue = High(TValueSign);

function Sign(const AValue: Integer): TValueSign;
begin
  Result := ZeroValue;
  if AValue < 0 then
    Result := NegativeValue
  else if AValue > 0 then
    Result := PositiveValue;
end;

function Sign(const AValue: Int64): TValueSign;
begin
  Result := ZeroValue;
  if AValue < 0 then
    Result := NegativeValue
  else if AValue > 0 then
    Result := PositiveValue;
end;

function Sign(const AValue: Single): TValueSign;
begin
  if (PInteger(@AValue)^ and $7FFFFFFF) = $00000000 then
    Result := ZeroValue
  else
    if (PInteger(@AValue)^ and $80000000) = $80000000 then
      Result := NegativeValue
    else
      Result := PositiveValue;
end;

function Sign(const AValue: Double): TValueSign;
begin
  if ((PInt64(@AValue)^ and $7FFFFFFFFFFFFFFF) = $0000000000000000) then
    Result := ZeroValue
  else if ((PInt64(@AValue)^ and $8000000000000000) = $8000000000000000) then
    Result := NegativeValue
  else
    Result := PositiveValue;
end;

function Sign(const AValue: Extended): TValueSign;
begin
{$IFDEF CPUX64}
  if ((PInt64(@AValue)^ and $7FFFFFFFFFFFFFFF) = $0000000000000000) then
    Result := ZeroValue
  else if ((PInt64(@AValue)^ and $8000000000000000) = $8000000000000000) then
    Result := NegativeValue
  else
    Result := PositiveValue;
{$ELSE !CPUX64}
  if (PExtendedRec(@AValue)^.Frac and $FFFFFFFFFFFFFFFF) = $0000000000000000 then
    Result := ZeroValue
  else
    if PExtendedRec(@AValue)^.sign then
      Result := NegativeValue
    else
      Result := PositiveValue;
{$ENDIF}
end;
« Last Edit: December 15, 2018, 01:30:29 am by Remy Lebeau »
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

VTwin

  • Hero Member
  • *****
  • Posts: 841
  • Former Turbo Pascal 3 user
Re: Possible future competition for Delphi and FPC?
« Reply #8 on: December 15, 2018, 01:44:59 am »
I'd encourage assisting with FPC rather than competing. Hard to see how they could jump ahead. That's a huge bar. What is the goal?
« Last Edit: December 15, 2018, 01:58:09 am by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

macOS 10.13.6: Lazarus 2.0.7 fixes svn r62562 (64 bit Cocoa)
Ubuntu 18.04.3: Lazarus 2.0.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.6 (64 bit on VBox)
fpc 3.0.4

440bx

  • Hero Member
  • *****
  • Posts: 1359
Re: Possible future competition for Delphi and FPC?
« Reply #9 on: December 15, 2018, 02:04:52 am »
Yes, it is branchless but...  as written above the function's result is undefined when the parameter passed to it is zero.

How do you figure that?  I see it as being defined as 0:
Remy, you are absolutely correct. It gets assigned false - false which is false. 

I owe Taddy an apology.

Thank you for pointing out that mistake.
using FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7858
Re: Possible future competition for Delphi and FPC?
« Reply #10 on: December 15, 2018, 01:30:32 pm »
From what I can see it is a parser more than a compiler with an incomplete virtual machine.

I'm not so sure about that. It seems to implement the full infrastructure of a compiler, e.g. type-checker/e.t.c and even a package system.

It also has a variety of in-progress codegen backends, not just a VM implementation:

Well, we see. The point remains, what does it do?  Can it compile code? Can it produce working exes for major OSes ? How do they perform, what dialect does it support? Does it require modification of existing delphi sourcode, and if it does, how much? (always a problem with compilers with IL backends) Does it have a massive own libraries (fileformats, networking, even simple date calculations), or can it compile borrow them from some major compiler?

I think the whole competition angle is dragged in by the hairs. All I see is one of the many pascal->IL attempts(*), nothing close to a production product like Delphi or FPC. That Il2LLVM generator has barely 100 uncommented lines.

Worse, I don't see any evidence of what works, just the codedump. Talk of competition is very, very, very premature. >:D

Initial compilers can be made by a focussed person or a team (e.g. as part of a student project) in a few months, specially if you borrow code and avoid the hard parts like own codegenerators.

But then every step you take widens the project, and it slows down, usually beyond the abilities of a single person who can only afford fulltime work on it for so long.

Making them production ready, dialect, codegeneration quality and libraries beyond the bare minimum and supporting them for a period of time, that is where the work goes.  Initial means nothing there are so many small compilers

(*) the last similar message is not even that long ago: http://forum.lazarus-ide.org/index.php/topic,43007.0.html
« Last Edit: December 15, 2018, 01:50:19 pm by marcov »

SlightlyOutOfPhase

  • New Member
  • *
  • Posts: 33
Re: Possible future competition for Delphi and FPC?
« Reply #11 on: December 15, 2018, 07:08:11 pm »
Worse, I don't see any evidence of what works, just the codedump. Talk of competition is very, very, very premature. >:D

Overall I didn't mean "competition" in any kind of negative sense. I just thought it looked like an interesting project. IMO it's good to have more stuff like this than less to keep the Pascal ecosystem healthy.

Laksen

  • Hero Member
  • *****
  • Posts: 637
    • J-Software
Re: Possible future competition for Delphi and FPC?
« Reply #12 on: December 15, 2018, 09:48:40 pm »
Diversity in a software ecosystem is great. Good luck to those people :)