cil

Can/does the (forward) pipe operator prevent tail call optimization?

99封情书 提交于 2019-11-29 09:13:10
For a parameter optimization problem at work I wrote a genetic algorithm to find some good settings because a brute-force solution is unfeasible. Unfortunately, when I return in the morning, most of the time I'm presented with a StackOverflowException . I've been using F# for quite some time now so I'm aware of TCO and the need for functions with accumulator arguments and generally use that form. After a lot of searching I think I was able to nail to the code that triggered the exception: breedPopulation alive |> simulate (generation + 1) lastTime ewma breedPopulation generates a new

Does PowerShell compile scripts?

那年仲夏 提交于 2019-11-29 08:19:26
问题 Suppose I have a simple PowerShell script: 1..3 | Write-Host How does PowerShell process it? Does it build in-memory assembly or some temporary .dll file? Can I examine this assembly and MSIL using some tools (e.g. ILSpy, VS, WinDbg)? Does PowerShell treat processing of file scripts and REPL command line input the same way (i.e. both compiled / interpreted)? Can I use this compiled assembly together with C# and other .Net languages? Can the PS script be compiled to a native binary code? 回答1:

CIL, CLS, and CTS in .NET

纵饮孤独 提交于 2019-11-29 07:05:58
What is the CIL , CTS , and CLS in .NET and what is the difference between them? CIL (Common Intermediate Language) is the byte code to which your C# or Visual Basic code is compiled. It's the "machine code" of the .NET execution engine. The CTS (Common Type System) is the representation of types (classes and structures) at the compiled level. Basically, it's saying that all .NET languages will use a common way of representing types (classes and structures). The CLS (Common Language Specification) is a set of constraints on APIs and a complementary set of requirements on languages. If a

Is there an API for verifying the MSIL of a dynamic assembly at runtime?

你。 提交于 2019-11-29 05:47:28
When using Reflection.Emit to build an assembly at runtime, I'd like to verify the assembly MSIL before saving to disc. Like PEVerify but at runtime. Is there such an API? It seems that peverify.exe is a front-end to c:\Windows\Microsoft.NET\Framework\v4.0.30319\peverify.dll (or c:\Windows\Microsoft.NET\Framework\v2.0.50727\peverify.dll for CLR 2.0), which is a native DLL (actually, peverify.exe is also native) I don't see this documented anywhere so it's probably not a public API. You may be able to figure out the exported functions from that DLL using something like Dependency Walker , but I

What is the (# … #) syntax seen in F# standard library implementation?

谁都会走 提交于 2019-11-29 05:30:04
Reading sources of Array2D module, I've stumbled upon this interesting construct in implementation of many core functions, for example: [<CompiledName("Get")>] let get (array: 'T[,]) (n:int) (m:int) = (# "ldelem.multi 2 !0" type ('T) array n m : 'T #) I can only assume that this is the syntax to inline CIL and is used here obviously to gain performance benefits. However, when I've tried to use this syntax in my program, I get an error: warning FS0042: This construct is deprecated: it is only for use in the F# library What exactly is this? Is there any detailed documentation? I think that this

C# Intercept/change/redirect a method

巧了我就是萌 提交于 2019-11-29 05:08:29
Let's say I have a private, "instance," non-static, bool method in a third-party dll. All this method does is return a value. Nothing else. How would I go about intercepting calls to this method, changing it's IL OpCodes/method body, or redirecting it to an extra, overridden or derived method. I do not want to decompile the third-party dll, manually change the source, and recompile it. I also would rather not to save the assembly to disk as this would also involve using a "recompiled" assembly instead of the original. I basically want to be able to use the original dll - no replacements or

What is the (fnptr)* type and how to create it?

帅比萌擦擦* 提交于 2019-11-29 02:50:06
问题 The following IL code creates a Type instance named (fnptr)* (token 0x2000000 - invalid, module mscorlib.dll). ldtoken method void* ()* call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle) What's the purpose of this type? Is it possible to create this type instance in C# without writing any IL code, maybe with reflection? Module.ResolveType on the token throws ArgumentOutOfRangeException . Edit: It's clear the (fnptr) type is

Is there a simple way to obtain all the local variables in the current stack frame in C# (or CIL)

断了今生、忘了曾经 提交于 2019-11-29 02:09:36
Following my previous question, in which I wanted to dump all the variables in the stack (from the current and all the previous frame) that can be seen here: Is there a way to examine the stack variables at runtime in C#? I was suggested to intercept the calls manually or use AOP framework like PostSharp to simplify such a task. I looked at PostSharp and the interception arguments don't include the variables in the current stack frame. I wonder if there is a simple way to automatically get all the local variables in the current stack frame. I suppose I can perform code analysis and generate

Compiler generated incorrect code for anonymous methods [MS BUG FIXED]

微笑、不失礼 提交于 2019-11-29 01:42:12
问题 See the following code: public abstract class Base { public virtual void Foo<T>() where T : class { Console.WriteLine("base"); } } public class Derived : Base { public override void Foo<T>() { Console.WriteLine("derived"); } public void Bang() { Action bang = new Action(delegate { base.Foo<string>(); }); bang(); //VerificationException is thrown } } new Derived().Bang(); throws an exception. Inside the generated CIL of the method Bang I got: call instance void ConsoleApp.Derived::'<>n_

How to translate “default(SomeType)” from C# to CIL?

可紊 提交于 2019-11-28 21:32:42
I'm currently working on a problem that involves System.Reflection.Emit code generation. I'm trying to figure out what CIL to emit in places where I would use default(SomeType) in C#. I've run a few basic experiments from Visual Studio 11 Beta. JustDecompile shows me the following CIL output for default(bool) , default(string) , and default(int? : .locals init ( [0] bool V_0, [1] string V_1, [2] valuetype [mscorlib]System.Nullable`1<int32> V_2 ) // bool b = default(bool); ldc.i4.0 stloc.0 // string s = default(string); ldnull stloc.1 // int? ni = default(int?); ldloca.s V_2 initobj valuetype