Lazarus

Free Pascal => General => Topic started by: inky on October 16, 2020, 11:13:37 am

Title: defining a subset of pascal
Post by: inky on October 16, 2020, 11:13:37 am
i am disturbed by the amount of features pascal accumulated over years.
today was searching on the net and found my old reddit post: https://www.reddit.com/r/ada/comments/5bvyey/language_complexity/

i do like pascal, and especially i like freepascal compiler implementation. i like, for example, that it is not part of gcc, but independently developed, has own, very good memory manager, and by default generates kernel calls avoiding libc usage.

on the other hand i mostly program in oberon. because of its, i would say, modernistic and minimalistic design and concentration on safety. i know it has a small and divided community, almost no libraries, in other words small number of speakers. but i tell it to make clear why am i writing this.

i think freepascal devs or community have to try to define a new, completely new language subset, which compiler would check with some switch.
i know we have iso pascal, but that's not enough.
for example, i would suggest that this new subset, which should, i believe concentrate on safety, would not allow more than one exit from a function procedure.

here cbfsoftware describes how oberon enforces many of misra rules: https://web.archive.org/web/20130703231115/http://www.ocp.inf.ethz.ch/forum/index.php/topic,609.0.html

so what do you think?
i understand that we have a lot of legacy code (python decided to not support legacy code but create a better 3.x branch) and need to have some kind of delphi compatibility.
also, LCL is, as far as i know, written without any restrictions on features used.
but i think that fpc community and/or devs are the people who can agree on some minimalistic and safe features for clean design of new pascal language subset.

even ada did similar thing by introducing spark though it is a bit different story.

the good thing it won't require much changes, or introduction of new features. it would only require a limitation of feature usage by a commandline switch.
Title: Re: defining a subset of pascal
Post by: Thaddy on October 16, 2020, 11:44:54 am
We already have the two ISO modes (7185 and 10206), which are quite restrictive and concise. Why add another one?
Anyway, some of the forum members already have written things like TinyPascal and family.
7185 is from 1983 and revised in 1990. Seems limiting enough... :P

So defining a subset of modern  pascal can be done: use the ISO 7185 as a template and start from there. It does not support objects nor classes...
Title: Re: defining a subset of pascal
Post by: MarkMLl on October 16, 2020, 11:59:47 am
I think that (i) Liam Proven joined a couple of days ago and you should be talking to each other due to your Oberon interest and (ii) that what you might be looking for is "Spayed Pascal" i.e. with the "dangerous" bits chopped out.

Frankly I am an admirer of the Modula-3 way of doing things, i.e. with specific modules annotated as containing unsafe code which should be maintained only by an experienced programmer.

Tangentially, and with apologies for departing from OP's topic as raised, I also feel that the ongoing Oracle vs Google case (heard by the US Supreme Court a few days ago) should be taken as a wakeup call: it's far easier to separate a descriptive interface (not eligible for copyright protection) and an implementation (eligible for copyright and possibly patent protection) if they're in separate files, and the Modula-3 approach demonstrates that that can also have project management advantages.

MarkMLl
Title: Re: defining a subset of pascal
Post by: lproven on October 16, 2020, 01:27:33 pm
I think that (i) Liam Proven joined a couple of days ago and you should be talking to each other due to your Oberon interest

Oh, er, hello. That'll be me, then.

Yes, I am interested in Oberon, although I have not learned it as of yet. The reason I joined the fora here is that I am trying to resurrect my extremely rusty Pascal skills from the 1980s.

@inky -- Oberon is alive and relatively well. The "ETH Oberon and related systems" mailing list <oberon@lists.inf.ethz.ch> is relatively active. I am also in a Telegram chat channel on Oberon and A2 and it's busy, but it's all in Russian. That seems to be where the language and OS are most appreciated these days.

I am interested to see if I can learn enough to attempt a port to the Raspberry Pi -- I think it could be an ideal hobbyist/teaching environment, especially on the low-price single-core RasPis (the Zero, Zero W etc.) where Linux does not work well.
Title: Re: defining a subset of pascal
Post by: MarkMLl on October 16, 2020, 01:56:34 pm
I am interested to see if I can learn enough to attempt a port to the Raspberry Pi -- I think it could be an ideal hobbyist/teaching environment, especially on the low-price single-core RasPis (the Zero, Zero W etc.) where Linux does not work well.

Hold on, I think you've dropped a sentence. Port what in this context?

MarkMLl
Title: Re: defining a subset of pascal
Post by: inky on October 16, 2020, 10:12:54 pm
I think that (i) Liam Proven joined a couple of days ago and you should be talking to each other due to your Oberon interest

Oh, er, hello. That'll be me, then.

Yes, I am interested in Oberon, although I have not learned it as of yet. The reason I joined the fora here is that I am trying to resurrect my extremely rusty Pascal skills from the 1980s.

@inky -- Oberon is alive and relatively well. The "ETH Oberon and related systems" mailing list <oberon@lists.inf.ethz.ch> is relatively active. I am also in a Telegram chat channel on Oberon and A2 and it's busy, but it's all in Russian. That seems to be where the language and OS are most appreciated these days.

I am interested to see if I can learn enough to attempt a port to the Raspberry Pi -- I think it could be an ideal hobbyist/teaching environment, especially on the low-price single-core RasPis (the Zero, Zero W etc.) where Linux does not work well.

hello!
i am founder of vishap oberon compiler and i hang out in #oberon room on irc.freenode.net.
right now not, though because my country is in war and i have no mood.
the room is not busy anyway, but there you can find my bot - vocbot - which is written in oberon from scratch - first i implemented unix sockets wrapper, then python like easy to use internet library, then irc module, and then the bot logic. https://github.com/norayr/irc_bot. it uses packages as git submodules - Internet, irc, lists and time packages from my
other repositories.

i don't use telegram.
glad to know there is active russian community though.

for raspberry pi, if you're interested in just commandline compiler, i would of course suggest to use ours - vishap oberon compiler. https://github.com/vishaps/voc

if you'd like to use oberon as an operating system/editor/environment - you have two options:

0. josef temple's ofront. it is an amazing tool and became more amazing recently, in 2016 he added dynamic module loading. so it works like a real oberon system though when you compile your module, it actually gets translated to c, then linked as shared object, and loaded, when needed.
but you need 32bit linux for this.

1. oberon linux revival by peter mathias. amazing project, actually even two projects. he has oberon s3 for arm, and he has latest po13 oberon with oberon-07 compiler for arm.
i would suggest running more classical version, it has more software and is more fun. though it is also only 32bit, you can use it on pure 64bit linux system.
because it uses x protocol to draw (no linkind to xlib necessary) and it uses kernel calls (like fpc) directly without glibc linking. so it only requires kernel and x (or framebuffer) to run.
Title: Re: defining a subset of pascal
Post by: marcov on October 17, 2020, 12:34:34 am
(added later as clarifier: I'm refering to Misra rules below)
How would this work in FPC's case? I think those rules goes for the entire system, so a limited subset calling into a RTL in a not limited  context would violate them?

Anyway, I played with the idea of starting a M2 platform at some time in the past and asked some questions, the stages of the current compiler's scanner-parser are somewhat interwoven and optimized for speed.  This makes alternate, pluggable frontends a bit hard, as few parts of the compiler are modularly isolated because of practical (speed) reasons.

Another possible problem would be having to surpress Pascal's type promotion type systems.
Title: Re: defining a subset of pascal
Post by: inky on October 17, 2020, 12:56:00 am
I think that (i) Liam Proven joined a couple of days ago and you should be talking to each other due to your Oberon interest and (ii) that what you might be looking for is "Spayed Pascal" i.e. with the "dangerous" bits chopped out.

thank you. but i did not find "spayed pascal" on the net.
also i would like to have a fpc based solution because i like the compiler.
Title: Re: defining a subset of pascal
Post by: inky on October 17, 2020, 12:59:51 am
We already have the two ISO modes (7185 and 10206), which are quite restrictive and concise. Why add another one?
Anyway, some of the forum members already have written things like TinyPascal and family.
7185 is from 1983 and revised in 1990. Seems limiting enough... :P

So defining a subset of modern  pascal can be done: use the ISO 7185 as a template and start from there. It does not support objects nor classes...

thank you very much, i looked at both standards, and extended pascal seems attractive.
it's a pity it has no oop. also some things are not intuitive, like usage of Succ and Pred instead of Inc and Dec.

i think may be ideally it should be modern pascal like dialect, but with minimal features, i. e. only one type of string, etc.

but yes, for non-oop work i think i can consider extended pascal.
Title: Re: defining a subset of pascal
Post by: 440bx on October 17, 2020, 05:56:57 am
it's a pity it has no oop. also some things are not intuitive, like usage of Succ and Pred instead of Inc and Dec.

i think may be ideally it should be modern pascal like dialect, but with minimal features, i. e. only one type of string, etc.

but yes, for non-oop work i think i can consider extended pascal.
Just in case you might be interested, there is Per Brinch Hansen's SuperPascal which is both a subset and a superset of Pascal.  It eliminates unsafe features and adds coroutines.  One of its interesting features is that the compiler can determine at compile time potential synchronization problems among coroutines.

If interested you can find a good description in Wikipedia at the link https://en.wikipedia.org/wiki/SuperPascal (https://en.wikipedia.org/wiki/SuperPascal)

The bottom of the page has links to the original version which was for a Sun Sparc and an FPC (mode iso) port.  Per Brinch Hansen placed the source code in the public domain but retains copyrights on the compiler manuals which are in Tex (or one of its variants).  It's a very interesting compiler and, it is very well written (recursive descent, hand written by PBH) and easy to understand, the documentation is easy to read and also easy to understand.  (Note: it's not a "real" compiler, it produces bytecode which is interpreted. Also while the manuals are good, they are not a tutorial on how to write a compiler.)

HTH.
Title: Re: defining a subset of pascal
Post by: dbannon on October 17, 2020, 07:19:42 am
Maybe all you need is to define a particular style guide ?  A set of rules, we don't exit a method early, we don't use classes, we use only short strings and so on ?

The trouble with asking for a minimal Pascal is just about every one who agrees a minimal pascal is a good idea will require a slightly different subset. So, its very unlikely you could get your subset enforced by the compiler.

But defining your own style guide is entirely within your reach. And up to you to apply to your programming.

Where you would run into trouble is if you want to use something like LCL. Internally it uses the things you may not approve of and quite often those internals are exposed and you are expected to use them. But, honestly, you cannot reasonably expect something like LCL to be rewritten to suite either a new compile language OR style. It just won't happen.

So, you need to provide all your own libraries. Hmm....

Davo
Title: Re: defining a subset of pascal
Post by: MarkMLl on October 17, 2020, 09:18:47 am
I think that (i) Liam Proven joined a couple of days ago and you should be talking to each other due to your Oberon interest and (ii) that what you might be looking for is "Spayed Pascal" i.e. with the "dangerous" bits chopped out.

thank you. but i did not find "spayed pascal" on the net.
also i would like to have a fpc based solution because i like the compiler.

Looks like it needs to be mis-spelled as "spade pascal" to get any useful hits.

MarkMLl
Title: Re: defining a subset of pascal
Post by: inky on October 17, 2020, 10:56:41 am
it's a pity it has no oop. also some things are not intuitive, like usage of Succ and Pred instead of Inc and Dec.

i think may be ideally it should be modern pascal like dialect, but with minimal features, i. e. only one type of string, etc.

but yes, for non-oop work i think i can consider extended pascal.
Just in case you might be interested, there is Per Brinch Hansen's SuperPascal which is both a subset and a superset of Pascal.  It eliminates unsafe features and adds coroutines.  One of its interesting features is that the compiler can determine at compile time potential synchronization problems among coroutines.


indeed, i did not consider it, because i was thinking of limiting a subset from the fpc supported features.

but he did an amazing work and i have his book. it is one of the most interesting works on compiler construction.
it is interesting that my copy, which is used, has notes made in pencil, someone tried to translate the code to modula-2.
it's a pity it won't be possible to use his code for the frontend and add a custom backend and release it under a free license.
but thanks for reminding me!
Title: Re: defining a subset of pascal
Post by: inky on October 17, 2020, 10:59:13 am
Maybe all you need is to define a particular style guide ?  A set of rules, we don't exit a method early, we don't use classes, we use only short strings and so on ?

The trouble with asking for a minimal Pascal is just about every one who agrees a minimal pascal is a good idea will require a slightly different subset. So, its very unlikely you could get your subset enforced by the compiler.

But defining your own style guide is entirely within your reach. And up to you to apply to your programming.

Where you would run into trouble is if you want to use something like LCL. Internally it uses the things you may not approve of and quite often those internals are exposed and you are expected to use them. But, honestly, you cannot reasonably expect something like LCL to be rewritten to suite either a new compile language OR style. It just won't happen.

So, you need to provide all your own libraries. Hmm....

Davo

yes, style guide and the checker would be something like SPARK i mentioned.
they did not write a separate ADA compiler but decided to use a separate tool that limits the feature usage, if i can simplify like that.

yes, i don't expect LCL or any other existing fpc code to be rewritten.
i even can link to existing libraries, i anyway do now link to C code when writing in Oberon. at least i can know i like that my own code uses that limited minimalistic subset.
Title: Re: defining a subset of pascal
Post by: inky on October 17, 2020, 11:02:58 am
I am interested to see if I can learn enough to attempt a port to the Raspberry Pi -- I think it could be an ideal hobbyist/teaching environment, especially on the low-price single-core RasPis (the Zero, Zero W etc.) where Linux does not work well.

Hold on, I think you've dropped a sentence. Port what in this context?

MarkMLl

may be i misunderstood him.
i thought he needs an oberon compiler or environment for raspberry pi/linux, but i see now he may be thinks of booting a version natively.

that would be much harder, at least would require writing driver and replacing many low level modules that do linux system calls.
Title: Re: defining a subset of pascal
Post by: 440bx on October 17, 2020, 12:06:07 pm
but he did an amazing work and i have his book.
Is the book you are referring to "Per Brinch Hansen on Pascal Compilers" ? (Pascal-) if it is, you can use the same architecture he used for Pascal- to implement a variant of SuperPascal.  Since SuperPascal is public domain, just borrowing Pascal-'s architecture (not the code) should be ok. 

it is one of the most interesting works on compiler construction.
I agree.  IMO, his implementations are by far the cleanest.

it is interesting that my copy, which is used, has notes made in pencil, someone tried to translate the code to modula-2.
I translated/ported Pascal- to Turbo Pascal and then Delphi 2 long ago.

it's a pity it won't be possible to use his code for the frontend and add a custom backend and release it under a free license.
I believe it is possible if you use the SuperPascal code which is public domain and only use the architecture of Pascal-.  IMO, that's the ideal implementation of a back end to produce highly optimized code.

but thanks for reminding me!
My pleasure.
Title: Re: defining a subset of pascal
Post by: PascalDragon on October 17, 2020, 12:17:00 pm
i think freepascal devs or community have to try to define a new, completely new language subset, which compiler would check with some switch.

No. Neither we devs nor the community has to try anything here. We're already hard at work catching up with Delphi's features which is a very much community driven demand plus the support of the two Pascal standards for the sake of completeness and bragging points. Adding an additional, new, more restricted language dialect would result in unnecessary work and complication and the target audience would probably be even smaller than those that currently use mode ISO and look forward to a fully supported mode ExtPas.

but i think that fpc community and/or devs are the people who can agree on some minimalistic and safe features for clean design of new pascal language subset.

No. We don't agree on that. Even among us devs there is the division between those that defend the ObjFPC dialect (which is at least a bit more strict than mode Delphi) and those that would like to see it gone (though that will never happen due to our stance on backwards compatibility).

the good thing it won't require much changes, or introduction of new features. it would only require a limitation of feature usage by a commandline switch.

It would nevertheless complicate the parser even more, because each added modeswitch requires checking after all.
Title: Re: defining a subset of pascal
Post by: BeniBela on October 17, 2020, 01:24:08 pm
Less features do not make it safer

We need more features to make it safer. Smart pointers or a borrow checker or a garbage collector to get memory safety. Better checking for uninitialized variables, so uninitialized variables become a compile time error. Inline for variable declarations, so the loop variable is not uninitialized after the for loop. A contract verifier like SPARK or like Wuffs that proves there are  no range check errors or integer overflows when the code compiles.   Perhaps one could change Wuffs to have a Pascal syntax and generate Pascal code.
Title: Re: defining a subset of pascal
Post by: lproven on October 18, 2020, 01:09:01 pm
Hmm. Apparently the Preview button does not work? This kind of thing is why I loathe web fora. :-(
 
@inky:

Quote
i am founder of vishap oberon compiler and i hang out in #oberon room on irc.freenode.net.


I don't normally do IRC except for work, but I will have a look.

Quote

right now not, though because my country is in war and i have no mood.

Um. Which country is that? I cannot view your profile -- it says I do not have permission.

Quote
for raspberry pi, if you're interested in just commandline compiler, i would of course suggest to use ours - vishap oberon compiler. https://github.com/vishaps/voc

I think that compiles to C, right?

Quote
if you'd like to use oberon as an operating system/editor/environment

I am interested in a **native** port of Oberon to the Pi, and I hope later to other ARM SBCs. I am not really interested in anything running on top of Linux, because part of my objective is to demonstrate that something far smaller and simpler than Linux is viable.
Title: Re: defining a subset of pascal
Post by: lproven on October 18, 2020, 01:13:40 pm

@inky
Quote
i thought he needs an oberon compiler or environment for raspberry pi/linux

No. I have seen several.

Quote
but i see now he may be thinks of booting a version natively.

Yes. The single remaining lecturer at ETH has said that they do have an experimental version booting internally to the university, built from the work of many students, but that he is too busy to share it externally. :-(

Quote
that would be much harder, at least would require writing driver and replacing many low level modules that do linux system calls.

I realise that.

But for me the interest and significance of Oberon is as a minimal OS environment. Running it on top of a bloated C-based OS fails to communicate this.

It is not that I dislike Linux -- I work in the Linux industry for a Linux vendor -- but I am interested in exploring alternatives to C-based OSes and the entire C-based ecosystem. That is (part of) my interest in Pascal. 
Title: Re: defining a subset of pascal
Post by: PascalDragon on October 18, 2020, 01:18:34 pm
Hmm. Apparently the Preview button does not work? This kind of thing is why I loathe web fora. :-(

It does. It's just that if you scrolled down the preview will be inserted above and the browser won't scroll up, but you can see at the scrollbar on the right that something happend. If you now scroll up then you'll see the preview (I've just tested this to confirm).
Title: Re: defining a subset of pascal
Post by: MarkMLl on October 18, 2020, 01:27:49 pm
Less features do not make it safer

We need more features to make it safer.

That sort of thing only works if the older feature can be completely replaced by the newer one, and in a way that users don't notice (i.e. the old syntax remains available as a shim over the new implementation, and there is no performance change).

For example, why does a modern Pascal have to have both strings and objects, when in principle strings could be reimplemented as objects?

MarkMLl
Title: Re: defining a subset of pascal
Post by: MarkMLl on October 18, 2020, 01:35:21 pm
Quote
if you'd like to use oberon as an operating system/editor/environment

I am interested in a **native** port of Oberon to the Pi, and I hope later to other ARM SBCs. I am not really interested in anything running on top of Linux, because part of my objective is to demonstrate that something far smaller and simpler than Linux is viable.

OK, so let's get something straight here although I must say that you're not expressing it very well (I have the advantage here of our copious "private correspondence" as they say in academia).

What you're trying to do I think- and please correct me if I'm putting words in your mouth- is port the Oberon operating system to an ARM target such as the RPi. That's not "native" so much as bare metal... and I'd suggest that it would still be fair to have what used to be called a virtual machine but today would probably have to be called an interpreter executing bytecodes at the lowest level (prior art: Burroughs MCP, UCSD Pascal).

MarkMLl
Title: Re: defining a subset of pascal
Post by: MarkMLl on October 18, 2020, 01:48:06 pm
But for me the interest and significance of Oberon is as a minimal OS environment. Running it on top of a bloated C-based OS fails to communicate this.

As you know I can sympathise with that, but the difficult thing is looking at the entire set of OSes (i.e. every OS that has ever been written, extant or otherwise) and working out what features are absolutely essential.

A good place to start would be looking at what absolutely had to go into microkernel based OSes: MINIX, L4, Redox or for that matter https://ultibo.org/ My own conviction is that the OS itself at the very lowest level needs memory management, context switching and a locking mechanism for interprocess communications and not much else: things like process scheduling algorithms can be external.

It's also necessary at this stage to look at some of the "howlers" that have gone into modern OSes. However I won't continue since I'm not sure that we should be hijacking this thread for extended discussion.
Title: Re: defining a subset of pascal
Post by: marcov on October 18, 2020, 03:06:59 pm
For example, why does a modern Pascal have to have both strings and objects, when in principle strings could be reimplemented as objects?

Can they? Since then strings would be a purely library concept, the lifetime would be very generalized and optimal.  How would you implement copy on write?

Afaik even java and C# have special internal handling in the GC for strings to avoid their immutability not leading to a memory bloat.
 
Title: Re: defining a subset of pascal
Post by: MarkMLl on October 18, 2020, 04:00:06 pm
Can they? Since then strings would be a purely library concept, the lifetime would be very generalized and optimal.  How would you implement copy on write?

If you can identify shortcomings in the object model then perhaps they should be fixed in the object model.

Quote
Afaik even java and C# have special internal handling in the GC for strings to avoid their immutability not leading to a memory bloat.

Which TBH is something that bothers me enormously: if a "fundamental" high-level-language facility can't be implemented without lots of low-level tricks then perhaps it should be reconsidered.

MarkMLl
Title: Re: defining a subset of pascal
Post by: marcov on October 18, 2020, 04:58:39 pm
Can they? Since then strings would be a purely library concept, the lifetime would be very generalized and optimal.  How would you implement copy on write?

If you can identify shortcomings in the object model then perhaps they should be fixed in the object model.

You an also reverse that. We were talking about strings, not objects. If they are really the same, it should reveal no new shortcomings in the object model. If new shortcomings exist, maybe the assumption simply doesn't hold true.

Quote
Quote
Afaik even java and C# have special internal handling in the GC for strings to avoid their immutability not leading to a memory bloat.

Which TBH is something that bothers me enormously: if a "fundamental" high-level-language facility can't be implemented without lots of low-level tricks then perhaps it should be reconsidered.

I don't understand what your conclusion with this paragraph is. Not to have strings? Not to map them to objects?
Title: Re: defining a subset of pascal
Post by: ASBzone on October 19, 2020, 10:49:00 pm
Maybe all you need is to define a particular style guide ?  A set of rules, we don't exit a method early, we don't use classes, we use only short strings and so on ?

The trouble with asking for a minimal Pascal is just about every one who agrees a minimal pascal is a good idea will require a slightly different subset. So, its very unlikely you could get your subset enforced by the compiler.
So true!  :)
Title: Re: defining a subset of pascal
Post by: dtoffe on October 21, 2020, 03:16:09 am
    The fpc team has a clearly stated commitment to support standards and backwards compatibility, and supporting six dialects seems complex enough already for a compiler.
    Perhaps you can start a project based on other available projects, for example this "fairly complete" compiler has been discussed some time ago in this forum:

https://github.com/75557032/llvmpas

https://forum.lazarus.freepascal.org/index.php/topic,43007.0.html

    And there is also this one which lacks code generation:

https://github.com/wanderlan/llvm-pascal

    There are also other fairly complete Modula 2/3 and Oberon compilers written in languages other than Object Pascal, it depends on how much adventurous you feel about taming a dragon...

Daniel
TinyPortal © 2005-2018