r/Compilers • • 24d ago

MPC - Probably the worlds first polyglot optimizing compiler handling 10 languages on several platforms.

/r/delphi/comments/1xq3qsb/mpc_probably_the_worlds_first_polyglot_optimizing/
0 Upvotes

19 comments sorted by

3

u/FloweyTheFlower420 24d ago

How do you handle object representation and the safe/unsafe boundary between C and the other languages?

-7

u/kimmadsen 23d ago

The general problem is that C has raw pointers and no memory safety, while the other languages have managed objects and guarantees. Joining them usually means C can corrupt those objects or hold them past their lifetime.

Our approach, briefly:

  • C never touches managed internals. It gets either a copy with a real C layout (scalars, text, plain structs, value objects) or an opaque handle (MIMERCode values). Anything with no safe C shape is refused at compile time.
  • Ownership is decided per crossing, not left to the programmer. Arguments are borrowed for the call, results are copied into the caller's scope, and handles are released explicitly. The compiler generates every binding.
  • One allocator for everything, so lifetime is known across all languages.
  • C can opt into checks with [[mimer::safe]]: bounds checks, use-after-free detection, and no pointer↔integer round trips.
  • Failures don't cross as exceptions. Native code reports a status to C and raises the language's own exception elsewhere, so no unwinding passes through C frames.

The remaining gap is code you mark unsafe, plus pointers into another language's arrays that are kept across a resize. Those are the programmer's responsibility, as in any FFI.

5

u/stlynnxx 23d ago • Heartwarming

Its fine to use AI in development if you know what you're doing. But since you can't even reply to a comment about your program without AI, it's safe to assume you don't know what you're doing and should especially stay out of systems level programming.

4

u/IlluminatiNotRealOr 23d ago

It is funny just 3-4 years ago if I had seen someone write so much in such detail I would think they are a genius altruist willing to share their knowledge with commoners.

Now I know to reject it as slop by default. Sad what the LLMs have done.

-1

u/kimmadsen 23d ago

Right... why accept true detailed answers. Better deny reality.

-2

u/kimmadsen 23d ago

Perhaps dont talk about things you dont know about.

3

u/stlynnxx 23d ago

Take your own advice, OP.

-1

u/kimmadsen 23d ago

You obviously have no clue what you are talking about and what my experience is, and my motivation is. So no, you are absolutely clueless, and instead of crapping on something made for free for those that see something useful, then stfu and spend your time with something that is of interest to you instead.

2

u/stlynnxx 23d ago

Why're you defensive to the point of anger? Why did you turn to insults instead of an actual argument? Did I hit an insecurity you can't structure a defense against?

-1

u/kimmadsen 23d ago

Because you chose to dismiss the project and ridicule my person, instead of either keeping quite and thinking your own, or engaging with interest.
The only input you provided was negativity from start having no clue to who you are talking with, the experience I may or may not have, the motivation I may or may not have.
So why did you spend your and my time on this type of engagement and NOT expect me to either completely ignore you, or tell you off?

4

u/stlynnxx 23d ago

Every angry response only further proves my point. If you're passionate and informed about the project then prove it, don't tell me to "stfu". This is public discourse; you're defending the validity of your project in the public eye and this is how you do it? It's not even about proving me wrong, it's about showing the world what your project means to you and that your work can stand up to scrutiny. You proved the opposite. You at first responded with AI, and then responded with insults and anger. You showed all of us the way you face scrutiny to your work; you tell the person to "stfu".

That is not the mark of a mature engineer who has poured themselves into a project.

If you want your project to become anything you will face scrutiny at every turn, especially with AI being involved. If you think I'm the last or only person you are very mistaken. Your choice is to learn how to actually respond to it, it be defeated by it.

You certainly didn't nail it on this round.

-1

u/kimmadsen 23d ago

I cant make everyone happy can I? And I really do not care! If people are interested they are interested. If they are not they are welcome to ignore the post, and that certainly includes you.
I do not have to convince you about anything. You could have chosen a different way to engage. You did not.

2

u/[deleted] 23d ago

MPC has frontends for MimerCode, Object Pascal, C, Python, ...

The compilation paths converge on a shared, structured Pascal representation, which MPC compiles to native machine code.

So MPC can compile Python to native code via intermediate Pascal.

How does that work? Is Python code still slow? How much of Python can it translate?

0

u/kimmadsen 23d ago

Tuning wise the first beta release has primarily focused on performance in the Pascal compiler (which generates faster code than whats out there today) and the optional GPU accelleration ([gpu] attribute), automated optional memory safety ([safe] attribute) and the automated optional secure compile features preventing eavesdropping from other VMs on a running routine ([secure] attribute), and the parallelism of for loops (parallel for statement), in addition to the generators for x64 (Windows and Linux), ARM64, Xtensa 32 and RISC-V compilation output that already is in mpc.

The alternative front end languages have seen a good amount of optimization, but there is still plenty of room in the next betas to improve for for example Python.

Currently the biggest selling points are the highly optimized channels that all languages can take advantage of, that is bundled with the mpc installation, that makes Python gain access to high performance, high quality and top level functionality in 3D visualization (in the top tier level now), GIS (in the top tier level now), CAD (in the top 30% level now), communications etc including industrial protocols, AND the ability to directly use code written in other languages compiled in in one go using mpc.

Regarding whats supported of Python, then currently the following is not supported:

Statements: async, match, except*, the type statement.
Types and values: 1j, memoryview, ... (Ellipsis).
Classes: metaclass=.
Dynamic and console: eval, input.
Imports: import os, import re, import collections.
Expressions: yield in a lambda, starred subscript (x[*a]).

But as its a first beta with a huge number of languages included, Python is probably one of them that have been getting the least of love until now. That will change during the beta releases.

/Kim

0

u/kimmadsen 23d ago

Actually this forum is horrible. It seems its not interested in technical stuff. Now I engaged with detailed reply and was voted down again LOL
There really are some sad people here!

2

u/ChaunceyWallopsEsq 23d ago

People are such haters on here! I think they believe that your answer didn’t actually respond to the very straightforward question that was asked and instead was a dump of vaguely related and clearly ai generated text. People can be really negative online! Trust me, I know from having to deal with my nephew and his friends on my Facebook page. My advice? Just stick to chatting with Claude, he will totally get where you’re coming from. Its been working great for me

1

u/kimmadsen 23d ago

As said... just keep on ignoring a technically correct response.

9

u/ChaunceyWallopsEsq 23d ago

Awesome! I like talking to Claude too. He is so smart! And never gives me any sort of attitude unlike my nephews. Have a good one