I’m fairly new to C#, and have recently learned that it’s possible to emit IL to implement a simple evaluation stack:
stack [ B C * A + ] ==> push B, push C, DO MULT, push A, DO ADD, POP return value
this example arises from the string "A + ( B * C )"
Can someone provide some advice and/or a sample IL snippet of the basic operation – i.e. push 1,2 or 3 doubles and invoke an unary, binary or ternary function or arithmetic operator on them.
Your advice may include whether or not emitting IL is a good idea. The expressions are assumptions fed to a monte-carlo simulation – so there is a good reason to think about speeding them up, but I don’t want to do this if it’s regarded as doable but unsafe.
See http://msdn.microsoft.com/en-us/library/exczf7b9.aspx for an excellent description of how to do this. Extremely well commented & well written.