News for hackers. Stuff that matters.
Re:Google joins .NET Foundation as Samsung brings .NET suppo... by KMag on Wednesday November 16, 2016 @12:40PM (#12969336)
But that C/C++ code you're calling still needs to be compiled to native code. The GP was referring to .NET CIL (bytecode) supporting (by design) a large subset of C/C++ semantics.

The GP wants to avoid shipping N different binaries for N platforms in cases where the C/C++ code being called isn't already on the platforms.

I haven't used Managed C++ and I'm fuzzy on the details, but my understanding is that a fairly large subset of C/C++ can be efficiently compiled to .NET CIL. (Of course, the class loader for untrusted security contexts will refuse to load classes that use the type-unsafe/memory-unsafe portions of .NET CIL, just like the Java classloader for untrusted applets won't load classes making arbitrary JNI calls.)

Re:Google joins .NET Foundation as Samsung brings .NET suppo... by int_19h on Wednesday November 16, 2016 @08:16PM (#12973315)
Based on what I know about CIL and C++, the entirety of C and C++ can be compiled to [unverifiable] CIL. The sole exception is setjmp/longjmp - this might be doable on top of CLI exceptions, but I'm not sure.

And, indeed, VC++ lets you do just that. There are some bits of the standard library, mostly new stuff like threads and atomic, that had some issues, as I recall. But it's more about the amount of effort that's needed to target what's essentially a completely different platform.

The thing to know about CIL is that it has:

- structs;

- unions;

- raw data pointers, with pointer arithmetic;

- raw function pointers;

- dynamic stack allocation (like alloca in C);

- tail calls;

- exceptions with exception filters (arbitrary expression evaluation when deciding whether to transfer to a given catch-block or not) and finally blocks.

I'm actually curious if there's any language that cannot be compiled down to this efficiently.

Re:Google joins .NET Foundation as Samsung brings .NET suppo... by pjmlp on Friday November 18, 2016 @12:38PM (#12988456)
Dynamic languages cannot be easily mapped to CIL, which is why IronPython was the genesis of DLR extensions, later added as standard part of .NET.
Re:Google joins .NET Foundation as Samsung brings .NET suppo... by int_19h on Friday November 18, 2016 @09:04PM (#12991594)
Dynamic languages typically aren't compiled, though. So either a language would have some kind of VM of its own (which is typically implemented in C, and hence can be implemented in CIL), or else they have some form of JIT compilation, which can use CIL as a target.
Re:Google joins .NET Foundation as Samsung brings .NET suppo... by pjmlp on Saturday November 19, 2016 @09:34AM (#12993635)
Those are scripting languages.

If you bothered to read why DLR was created, you will see why CIL wasn't enough.

Or why Java following the same linr of thought had to follow DLR changes to the CLR and introduce invokedynamic byte code and its related infrastructure.

Re:Google joins .NET Foundation as Samsung brings .NET suppo... by int_19h on Saturday November 19, 2016 @05:27PM (#12996062)
I know why DLR was created. I work on a team that has one of the guys who was working on it, and specifically on IronPython.

My point is that they are two different layers in the stack. CIL and JVM are lower level. DLR is a higher level layer. Said higher level can be implemented on any kind of lower level that's powerful enough - for example, you could have a kind of DLR directly on top of native code. All that matters for the lower level is that it's flexible enough to permit something like DLR to be implemented on top of it. CIL is undeniably flexible enough for that.

Re:Google joins .NET Foundation as Samsung brings .NET suppo... by pjmlp on Sunday November 20, 2016 @04:03PM (#13001210)
I remember reading some articles that justified DLR as CIL not having enough semantics that allowed to properly implement optimization algorithms commonly used in dynamic languages, like method lookup and call site caches.

Then again, maybe I understood it wrongly back then and I surely don't have the knowledge of your team.

Re:Google joins .NET Foundation as Samsung brings .NET suppo... by int_19h on Tuesday November 22, 2016 @09:01PM (#13019354)
Yes, that's right. But it's kinda what I meant. CIL is really roughly the level of C, plus some strongly typed object oriented stuff on top. It doesn't really offer anything useful for a dynamic language directly. But you can use it to implement a dynamic language VM with all those optimizations - just like C was used to write Parrot VM. DLR is to CLR as Parrot is to native code.