Recent

Author Topic: Go-flavored Pascal: now with Raylib bindings  (Read 7628 times)

vtereshkov

  • New member
  • *
  • Posts: 8
Go-flavored Pascal: now with Raylib bindings
« on: March 27, 2020, 11:18:05 pm »
By replacing the heavyweight Delphi-style OOP with a much simpler method/interface model inspired by Go, I have written an extremely compact (~10000 lines) Pascal compiler for Windows. Initially built with Free Pascal, it is now self-hosting. It can be viewed as an implementation of Russ Cox's thought:

"If I could export one feature of Go into other languages, it would be interfaces."

The compiler directly emits native x86 code and doesn't require any external assembler or linker. It can be easily embedded into larger software systems and used for educational purposes, e.g., as a playground for language design amateurs.

Integration with the Raylib 2D/3D game development library has become the first sign of maturity for my compiler.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11351
  • FPC developer.
Re: Go-flavored Pascal: now with Raylib bindings
« Reply #1 on: March 27, 2020, 11:32:28 pm »
"If I could export one feature of Go into other languages, it would be interfaces."

https://wiki.freepascal.org/How_To_Use_Interfaces

vtereshkov

  • New member
  • *
  • Posts: 8
Re: Go-flavored Pascal: now with Raylib bindings
« Reply #2 on: March 27, 2020, 11:44:55 pm »
In Delphi and Free Pascal (which both use the C++-style OOP model), an interface is a secondary notion that depends on the fundamental notion of a class.

Go does not have classes, objects, or inheritance. All these concepts are replaced by an interface. This is much simpler but provides the same polymorphic behavior as C++-style classes.

That's how it is done in Go and in my compiler.

 

440bx

  • Hero Member
  • *****
  • Posts: 3921
Re: Go-flavored Pascal: now with Raylib bindings
« Reply #3 on: March 28, 2020, 12:06:34 am »
I have written an extremely compact (~10000 lines) Pascal compiler for Windows. Initially built with Free Pascal, it is now self-hosting.
I've looked at your compiler in the past.  I see you've been busy :)

Nicely done.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

440bx

  • Hero Member
  • *****
  • Posts: 3921
Re: Go-flavored Pascal: now with Raylib bindings
« Reply #4 on: March 28, 2020, 02:38:45 am »
Just in case you'd like to know.  When compiling this program:
Code: Pascal  [Select][+][-]
  1.   program Test;
  2.  
  3.   const
  4.     ACONSTANT = not true;
  5.  
  6.   begin
  7.   end.
  8.  
I get a stack overflow
Quote
XD Pascal for Windows 0.12
Copyright (c) 2009-2010, 2019-2020, Vasiliy Tereshkov
Compiling system.pas
Compiling BooleanConstantExpression.lpr
An unhandled exception occurred at $00416D6A:
EStackOverflow: Stack overflow
  $00416D6A
  $00416FA7
  $00416FA7
  $00416FA7
  $00416FA7
  $00416FA7
  $00416FA7
  $00416FA7
  $00416FA7
  $00416FA7
  $00416FA7
  $00416FA7
  $00416FA7
  $00416FA7
  $00416FA7
  $00416FA7
  $00416FA7
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

vtereshkov

  • New member
  • *
  • Posts: 8
Re: Go-flavored Pascal: now with Raylib bindings
« Reply #5 on: March 28, 2020, 10:41:51 am »
Thank you. I've fixed it :)

circular

  • Hero Member
  • *****
  • Posts: 4181
    • Personal webpage
Re: Go-flavored Pascal: now with Raylib bindings
« Reply #6 on: March 28, 2020, 11:20:55 am »
Interesting.

By the way, while you're at it, why not remove the ";" ?
Conscience is the debugger of the mind

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11351
  • FPC developer.
Re: Go-flavored Pascal: now with Raylib bindings
« Reply #7 on: March 28, 2020, 11:21:48 am »
Well, the license is a main pro of course, because that makes it embeddable, and I'll certainly have a look. That appeals more to me than the GO stuff.

You could try to develop that idea further with a compile to memory option or so and a good demonstration (integrate in old dev pascal ide or so?).

If you are going for embeddability it might be good to rename some of the compiler units as their names are (literally) awfully COMMON :)

For bits and pieces like the bug that 440bx found you could try to harvest the FPC testsuite (and maybe pas2js has tests somewhere too for the fcl-passrc parser)

vtereshkov

  • New member
  • *
  • Posts: 8
Re: Go-flavored Pascal: now with Raylib bindings
« Reply #8 on: March 28, 2020, 11:45:17 am »
By the way, while you're at it, why not remove the ";" ?
Is the semicolon so annoying for you? Even more than begin...end instead of (now common) {...} ? :)
I'll think of it, but the semicolon cannot be completely removed - it can be made optional. The compiler source will have them anyway, since I need to keep it compatible with Delphi/FPC.

vtereshkov

  • New member
  • *
  • Posts: 8
Re: Go-flavored Pascal: now with Raylib bindings
« Reply #9 on: March 28, 2020, 12:05:55 pm »
You could try to develop that idea further with a compile to memory option or so and a good demonstration (integrate in old dev pascal ide or so?).
I'll definitely do it if I see any signs of practical interest from the community. Now many people like my project as a curious museum piece, but not as a tool for their daily tasks.
Quote
For bits and pieces like the bug that 440bx found you could try to harvest the FPC testsuite (and maybe pas2js has tests somewhere too for the fcl-passrc parser)
The only test suite I regularly run is the ISO Pascal Acceptance Test by S. A. Moore (with some Borland-specific changes). Once I tried to run a huge GNU Pascal test suite, but it mostly contains tests for some rare features (like "modules" from ISO Extended Pascal). So my compiler has successfully compiled just about 600 tests of 5000 (Delphi compiled about 900). I have to look at the FPC test suite.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11351
  • FPC developer.
Re: Go-flavored Pascal: now with Raylib bindings
« Reply #10 on: March 28, 2020, 12:26:16 pm »
By the way, while you're at it, why not remove the ";" ?
Is the semicolon so annoying for you? Even more than begin...end instead of (now common) {...} ? :)
I'll think of it, but the semicolon cannot be completely removed - it can be made optional. The compiler source will have them anyway, since I need to keep it compatible with Delphi/FPC.

If not for compatibility, you'd be better off implementing a Modula2 than a Pascal anyway. Even if you stick with Wirthian. So keeping compatibility is paramount IMHO

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11351
  • FPC developer.
Re: Go-flavored Pascal: now with Raylib bindings
« Reply #11 on: March 28, 2020, 12:37:09 pm »
You could try to develop that idea further with a compile to memory option or so and a good demonstration (integrate in old dev pascal ide or so?).
I'll definitely do it if I see any signs of practical interest from the community. Now many people like my project as a curious museum piece, but not as a tool for their daily tasks.

I understand.  I also mostly envision usage for an old project (that might become live again if a customer comes back again). Mostly to replace a kind of  expression evaluator with generated code, that is then compiled + reloaded/unloaded.

So I'm also not immediately starting unfortunately and only storing the link for future reference.

As for the testsuite, it might get you more borland oriented source pieces. But probably it is a mish mash of the various dialects support for FPC (turbo/delphi/iso/objective pascal). so might require some sorting out. It certainly won't be ready to run.

vtereshkov

  • New member
  • *
  • Posts: 8
Re: Go-flavored Pascal: now with Raylib bindings
« Reply #12 on: March 28, 2020, 12:38:56 pm »
If not for compatibility, you'd be better off implementing a Modula2 than a Pascal anyway. Even if you stick with Wirthian. So keeping compatibility is paramount IMHO
If I dare abandon compatibility, I'll probably make a completely different language. Modula-2 and Oberon still require that declarations be separated from statements, so that I cannot declare a variable where I really need it. They still don't have type inference, returning multiple values from a function, the "+=" operator, the generalized for statement, etc.
« Last Edit: March 28, 2020, 12:40:30 pm by vtereshkov »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11351
  • FPC developer.
Re: Go-flavored Pascal: now with Raylib bindings
« Reply #13 on: March 28, 2020, 01:00:43 pm »

If I dare abandon compatibility, I'll probably make a completely different language. Modula-2 and Oberon still require that declarations be separated from statements, so that I cannot declare a variable where I really need it. They still don't have type inference, returning multiple values from a function, the "+=" operator, the generalized for statement, etc.

If you care about those. 

Except maybe generalized for, but that depends on what you mean with it. I kind of like the situation in Object Pascal, where the normal FOR is a true for (as in that the number of iterations is known up front), but for..in allows escape from that using duck-typing iterators.

Horrible as language design from a purist view, but it simply works nice in practice. But too many skip out the true for in favour of only the generalized for, and that is IMHO a shame.


vtereshkov

  • New member
  • *
  • Posts: 8
Re: Go-flavored Pascal: now with Raylib bindings
« Reply #14 on: March 28, 2020, 10:40:09 pm »
As for the testsuite, it might get you more borland oriented source pieces. But probably it is a mish mash of the various dialects support for FPC (turbo/delphi/iso/objective pascal). so might require some sorting out. It certainly won't be ready to run.
Thank you. It is not well-suited to my compiler, but anyway it has already helped me find and fix one more bug :)

 

TinyPortal © 2005-2018