Mailing List Archive

Any ideas for a new language inspired to Python?
Let me first say that I don't know if my post is on topic with the
mailing list. If so, please inform me.

My idea seems to be very simple (so probably it's not simple at all):
a language similar to Python, but statically compiled.

(Yes, I know Cython, RPython, Julia, Rust...)

Since I've not great skill in low-level programming, I'm trying first
to define what I really want.

My core ideas are:

1. Statically compiled (of course...). So if you write:

var a = 1

the variable `a` is an integer and it's value can't be changed to
anything that is not an integer

2. Use of smart pointers. Instead of having a refcount in every
object, the language implementation will use a smart pointer as a sort
of "proxy" to the "real" pointer. This could allow the language
implementation to delete the object only when really necessary (lack
of memory) and/or do JIT optimizations (move the object to a slower or
a faster memory; compute and cache some object attributes, as hash;
remove object duplicates...)

3. functional programming under-the-hood. Users can write also in
imperative style, but in the language implementation only the
functional style is really used. This way *maybe* it's more simple to
write concurrent programs without a GIL.

But I have a lot of doubts. The one that bothers me most is: compile
to binary or to C?

My idea at the beginning was to compile to C code without creating an
AST. Virtually any system has its own C compiler. Maybe it *seems*
more simple, but it's quite more difficult?
--
https://mail.python.org/mailman/listinfo/python-list
Re: Any ideas for a new language inspired to Python? [ In reply to ]
>> On 7 Aug 2020, at 23:28, Marco Sulla <Marco.Sulla.Python@gmail.com> wrote:
> ?Let me first say that I don't know if my post is on topic with the
> mailing list. If so, please inform me.
>
> My idea seems to be very simple (so probably it's not simple at all):
> a language similar to Python, but statically compiled.
>
> (Yes, I know Cython, RPython, Julia, Rust...)

Have a look at Apple’s Swift. It reminds me of python as I read it.
I have not done more the read the language reference docs.

Sadly it seems that it has not been ported to none Apple platforms.

Barry

>
> Since I've not great skill in low-level programming, I'm trying first
> to define what I really want.
>
> My core ideas are:
>
> 1. Statically compiled (of course...). So if you write:
>
> var a = 1
>
> the variable `a` is an integer and it's value can't be changed to
> anything that is not an integer
>
> 2. Use of smart pointers. Instead of having a refcount in every
> object, the language implementation will use a smart pointer as a sort
> of "proxy" to the "real" pointer. This could allow the language
> implementation to delete the object only when really necessary (lack
> of memory) and/or do JIT optimizations (move the object to a slower or
> a faster memory; compute and cache some object attributes, as hash;
> remove object duplicates...)
>
> 3. functional programming under-the-hood. Users can write also in
> imperative style, but in the language implementation only the
> functional style is really used. This way *maybe* it's more simple to
> write concurrent programs without a GIL.
>
> But I have a lot of doubts. The one that bothers me most is: compile
> to binary or to C?
>
> My idea at the beginning was to compile to C code without creating an
> AST. Virtually any system has its own C compiler. Maybe it *seems*
> more simple, but it's quite more difficult?
> --
> https://mail.python.org/mailman/listinfo/python-list

--
https://mail.python.org/mailman/listinfo/python-list
Re: Any ideas for a new language inspired to Python? [ In reply to ]
On Sat, 8 Aug 2020 at 14:10, Barry <barry@barrys-emacs.org> wrote:
> >> On 7 Aug 2020, at 23:28, Marco Sulla <Marco.Sulla.Python@gmail.com> wrote:
> > My idea seems to be very simple (so probably it's not simple at all):
> > a language similar to Python, but statically compiled.
>
> Have a look at Apple’s Swift. It reminds me of python as I read it.

Thank you, some features are interesting, even if I prefer the Python syntax.

What about the compiler? Is it better to "compile" to C or to
bytecode? How can I generate a bytecode that can be compiled by gcc?
Can I skip the AST generation for now, or it will be a great problem
later?
--
https://mail.python.org/mailman/listinfo/python-list
Re: Any ideas for a new language inspired to Python? [ In reply to ]
On 2020-08-07, Marco Sulla <Marco.Sulla.Python@gmail.com> wrote:

> My core ideas are:
>
> 1. Statically compiled (of course...). So if you write:
>
> var a = 1
>
> the variable `a` is an integer and it's value can't be changed to
> anything that is not an integer

That's "statically typed". It has nothing to do with whether it's
statically compiled or not.

--
Grant

--
https://mail.python.org/mailman/listinfo/python-list
Re: Any ideas for a new language inspired to Python? [ In reply to ]
> On 8 Aug 2020, at 18:18, Marco Sulla <Marco.Sulla.Python@gmail.com> wrote:
>
> On Sat, 8 Aug 2020 at 14:10, Barry <barry@barrys-emacs.org> wrote:
>>>> On 7 Aug 2020, at 23:28, Marco Sulla <Marco.Sulla.Python@gmail.com> wrote:
>>> My idea seems to be very simple (so probably it's not simple at all):
>>> a language similar to Python, but statically compiled.
>>
>> Have a look at Apple’s Swift. It reminds me of python as I read it.
>
> Thank you, some features are interesting, even if I prefer the Python syntax.
>
> What about the compiler? Is it better to "compile" to C or to
> bytecode?

By going to C you are really saying you want to use the native instructions of your CPU.
Contrast that with bytecode that needs an interpreter.

> How can I generate a bytecode that can be compileed by gcc?

Have a look at http://www.nuitka.net/ <http://www.nuitka.net/> that compiles python into C.
One part of its speed up is that the bytecode evel code is not needed.
It can also spot optimisations that help, for example noticing that
code is doing int math and write that as C avoiding the python objects.

> Can I skip the AST generation for now, or it will be a great problem
> later?

You need a compiler person to explain better than I can.
But the steps that you need are:
1. Parse the source into an intermediate form (AST for example)
2. Check that the code is valid
3. Compile into runnable code

Barry
--
https://mail.python.org/mailman/listinfo/python-list
Re: Any ideas for a new language inspired to Python? [ In reply to ]
On Sun, 9 Aug 2020 at 10:31, Barry Scott <barry@barrys-emacs.org> wrote:
> By going to C you are really saying you want to use the native instructions of your CPU.
> Contrast that with bytecode that needs an interpreter.

This is also an answer for Grant Edwards: the idea was to generate
bytecode and compile it to machine code. See gcj, for example, that
translates the Java bytecode into machine code.
Even if it's not needed by the "mainstream" implementation, it could
be good if someone wants to implement its own interpreter.

Currently I don't care if this will slow down the compilation: things
can be accelerated or removed. My doubt is if the initial work is too
much and if I can, eventually, add this extra step later without many
troubles.

On Sun, 9 Aug 2020 at 10:31, Barry Scott <barry@barrys-emacs.org> wrote:
> Have a look at http://www.nuitka.net/ that compiles python into C.
> It can also spot optimisations that help, for example noticing that
> code is doing int math and write that as C avoiding the python objects.

This is another big problem: everything is an object?
It seems that in practice, using integers and floats as objects leads
to great slowdowns. And personally I never saw people that created
superclasses of int or float. Anyway, if they feel the urgence, they
can use `numbers` ABCs. It seems to me that the Java separation
between primitive types vs objects is quite practical.

On Sun, 9 Aug 2020 at 10:31, Barry Scott <barry@barrys-emacs.org> wrote:
> You need a compiler person to explain better than I can.
> But the steps that you need are:
> 1. Parse the source into an intermediate form (AST for example)
> 2. Check that the code is valid
> 3. Compile into runnable code

I know this is not trivial... I read also about lexers and parsers.
For example, it seems that Guido now uses a new parser, a PEG parser.
Don't know if it uses a lexer or not and why. And it seems they exist
generators of lexers and parsers. The more simple to use seems to be
ANTLR: https://github.com/antlr/antlr4 but it does not generate a PEG
parser.

Do you think py devs will be greatly bored if I link this discussion
in the python-dev mailing list?
--
https://mail.python.org/mailman/listinfo/python-list
Re: Any ideas for a new language inspired to Python? [ In reply to ]
On 8/9/2020 12:44 PM, Marco Sulla wrote:

> Do you think py devs will be greatly bored if I link this discussion
> in the python-dev mailing list?

Don't. This is neither about language development (and proposals
initially go to python-ideas) nor about immediate cpython development


--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list
Re: Any ideas for a new language inspired to Python? [ In reply to ]
On 2020-08-09, Marco Sulla <Marco.Sulla.Python@gmail.com> wrote:
> On Sun, 9 Aug 2020 at 10:31, Barry Scott <barry@barrys-emacs.org> wrote:

>> By going to C you are really saying you want to use the native
>> instructions of your CPU. Contrast that with bytecode that needs
>> an interpreter.
>
> This is also an answer for Grant Edwards: the idea was to generate
> bytecode and compile it to machine code.

Right. I was just pointing out that you said you wanted to do "static
compilation", and then provided an small example that demonstrated
something unrelated[1] (static typing). If you want to design a
language that has static typing, that's fine. If you want to
implement that language using static compilation, that's fine. You
can have both if you want. But, they are two independent concepts,
and you're going to confuse people if you use them interchangeably.

[1] Though in theory they are orthogonal, in practice certain
combinations of static compilation vs. bytecode+VM and static
vs. dynamic typing are harder to implement than others.

--
Grant

--
https://mail.python.org/mailman/listinfo/python-list
Re: Any ideas for a new language inspired to Python? [ In reply to ]
On 2020-08-09 at 13:07:03 -0400,
Dennis Lee Bieber <wlfraed@ix.netcom.com> wrote:

> On Sun, 9 Aug 2020 09:31:04 +0100, Barry Scott <barry@barrys-emacs.org>
> declaimed the following:
>
> >
> >By going to C you are really saying you want to use the native instructions of your CPU.
> >Contrast that with bytecode that needs an interpreter.
> >
>
> Unless one has located a C-compiler that generates byte-code for some
> virtual machine.

gcc compiles source code into different levels of virtual machines, and
then those virtual machines into actual object code. Start at
https://gcc.gnu.org/onlinedocs/gccint/index.html, and drill down into
section 6.3.8 (Anatomy of a Language Front End) and chapter 9 (Passes
and Files of the Compiler). Nothing stops you from translating your
source code directly into, say, RTL.

The Wikipedia page for LLVM tells me it's designed for this sort of
thing.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Any ideas for a new language inspired to Python? [ In reply to ]
On Mon, Aug 10, 2020 at 2:46 AM Marco Sulla
<Marco.Sulla.Python@gmail.com> wrote:
> This is another big problem: everything is an object?
> It seems that in practice, using integers and floats as objects leads
> to great slowdowns. And personally I never saw people that created
> superclasses of int or float. Anyway, if they feel the urgence, they
> can use `numbers` ABCs. It seems to me that the Java separation
> between primitive types vs objects is quite practical.

That isn't a problem. It is, in fact, extremely practical. EVERY
Python object has a repr, EVERY Python object has a type, etc, etc,
etc. You can ask questions like "is this object an instance of
(float,int)" and get back a useful answer.

If you *really* want to get away from ints-as-objects, what I would
recommend is emulating it. Some languages pretend that everything's an
object, but for small integers (say, those less than 2**60), it
doesn't store the object itself, it just stores the integer (with the
low bit set, for example). It requires special-casing integers
*everywhere* in the language executor (interpreter/compiler), and in
return, you get to save about 20 bytes per integer compared to the way
CPython does it. Is that worth it?

ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
Re: Any ideas for a new language inspired to Python? [ In reply to ]
On 2020-08-10 at 09:02:57 +1000,
Chris Angelico <rosuav@gmail.com> wrote:

> If you *really* want to get away from ints-as-objects, what I would
> recommend is emulating it. Some languages pretend that everything's an
> object, but for small integers (say, those less than 2**60), it
> doesn't store the object itself, it just stores the integer (with the
> low bit set, for example). It requires special-casing integers
> *everywhere* in the language executor (interpreter/compiler), and in
> return, you get to save about 20 bytes per integer compared to the way
> CPython does it. Is that worth it?

As always, it depends.

The special casing to which Chris referred is no worse than the special
casing that has to happen for every arithmetic operation anyway. How
does Python calculate a * b? Well, it depends on the type of a and the
type of b, and then dispatching to a special case multiplication
routine. All that boxing and unboxing (pulling the actual values out of
the objects, creating new objects, memory management, etc.) can add up,
too.

If my application deals with arithmetic on millions or billions? of
small integers (say, those less than 2**60), then it can make a big
difference. ;-)

? whether a billion is 1e9 or 1e12
--
https://mail.python.org/mailman/listinfo/python-list
Re: Any ideas for a new language inspired to Python? [ In reply to ]
On 08/08/2020 18:18, Marco Sulla wrote:

....

> Thank you, some features are interesting, even if I prefer the Python syntax.
>
> What about the compiler? Is it better to "compile" to C or to
> bytecode? How can I generate a bytecode that can be compiled by gcc?
> Can I skip the AST generation for now, or it will be a great problem
> later?

Most modern compilers use an AST - it is simply an internal
representation of the syntax, and for most compilers it it is an
intermediate step before code generation.

I think you mean skipping the bytecode generation and generating
straight to C/machine code.

--

Tony Flury

--
https://mail.python.org/mailman/listinfo/python-list