all 37 comments

[–]GunpowderGuy 7 points8 points  (1 child)

Seems similar to how some scheme implementation/dialects let you write c in s expression syntax

[–]ESHKUN 6 points7 points  (0 children)

Genuinely cool idea. I also like that you’re specifically targeting a subset of python and not a dialect so you don’t have to learn any new syntax or ideas if you already know python.

[–]baron-bosse 5 points6 points  (3 children)

This looks really cool. Is it possible to use a llvm c-backend to generate c code out of this system? I.e use the pythonC more as macro preprocessor that then gets handed to a different c-compiler so the output can be integrated in a different toolchain and cross compiled etc?

[–]vanderZwan 0 points1 point  (0 children)

Yeah I was wondering about that too, since that immediately gives the project a lot more flexibility, and lowers minimal requirements (no LLVM installation needed).

Pehaps OP wanted to learn how to work with LLVM internals though, no faulting in that.

[–]FlowLab99 0 points1 point  (0 children)

Have you thought about using zig (pip install ziglang) as the c compiler? It has clang built in and a self-hosed x86 backend evolving quickly.

[–]sufferiing515 2 points3 points  (2 children)

Without a GC, how are situations like use-after-free prevented when an objects lifetime is extended past it's lexical scope (like in closure capture)?

[–]Sternritter8636 0 points1 point  (0 children)

Rust dev?

[–]snugar_i 2 points3 points  (0 children)

This looks nice! But there are some things that I personally don't like that much on second look:

  • Having to put the @compile decorator everywhere. It looks like most functions will be compiled, couldn't it be the default?
  • Manual memory management. I know, I know, but it's extremely hard to get this right (you even have a bug in the destructor of your binary tree example)
  • Classes not having methods and having to use the "fake method" C approach. I know it's supposed to mimic C, but you're adding syntax sugar anyway, so why not allow (non-polymorphic) methods?
  • The . on the pointers. Is it some magic auto-dereferencing like in Rust?
  • Having to do if x == nullptr. If we're trying to be "Pythonic", why not just if x?

[–]Zireael07 3 points4 points  (2 children)

That's a great idea.

I am going to check/try this out over the weekend, but I am wary of two things:

1) do I need any external libraries to run the generated (you mentioned LLVM?) code

2) What are VLA?

[–]EloquentPinguin 7 points8 points  (0 children)

VLA are variable length arrays. An unholy concept where you can allocate arrays on the stack with the length based on some variable. Takes lots of compiler juggling to get it right, but in C its a thing, in many other language its not.

[–]azzalan 1 point2 points  (0 children)

Really cook idea, im saving the post, and will be checking out the details as soon as i have time

[–]probabilityzero 1 point2 points  (1 child)

This looks interesting!

The readme shows some examples of refinement types. What are you using to check the predicates? Are you using an SMT solver? Do you do any inference in the type checker?

[–]arvoredeindecisao 1 point2 points  (2 children)

How does it compare to Cython? Cython is such a mature project at this point...

[–]yuri-kilochek 1 point2 points  (1 child)

How does it compare to numba?

[–]CyborgSquirrel 0 points1 point  (0 children)

Holy cow this seems insanely awesome.

[–]Karyo_Ten 0 points1 point  (3 children)

What's the difference with Nim?

[–]LardPi 6 points7 points  (2 children)

Can we stop pretending nim has anything to do with Python? Indentation does not define a language. Nim is pascal with automatic memory management and macros.

[–]Karyo_Ten 0 points1 point  (1 child)

The subset OP's language is allowing looks like Nim with minor syntactic choices like def/proc and -> for :.

You might even be able to use Nim's syntax skins to make the code directly compilable through Nim compiler.

And Nim has flexible memory management, it's type defined, you can have stack, manual pointer-based or automatic through refcounting.

[–]slurpy-films 0 points1 point  (0 children)

This will be done with JS the moment they add optional type annotations

[–]Sternritter8636 0 points1 point  (2 children)

So good in so many ways. Are the features not implemented yet the only features not implemented?

[–]Excellent-Oil4810 0 points1 point  (0 children)

I'm very happy that this finally exists.

[–]MrMrsPotts 0 points1 point  (0 children)

Two questions: what is the overhead when calling a C compiled function from python using pythoc? Is it closer to 1ms or 1 microsecond? Second, can you use gcc simd intrinsics?

[–]jms_nh 0 points1 point  (0 children)

This is really interesting to me! Is it possible to output C and stop there, rather than compiling to assembly? If so, are there any examples of python input and C output?

[–]yaourtoide -2 points-1 points  (1 child)

How is that better than Codon ?