Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1008549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:47:18+00:00 2026-05-16T08:47:18+00:00

I am using Reflection.Emit to build a mathematical expression parser (e.g. 2+2 ). A

  • 0

I am using Reflection.Emit to build a mathematical expression parser (e.g. 2+2). A class takes in an infix expression (e.g. 2+2), turns it into a postfix expression (e.g. 2 2 +), and then another class compiles that postfix expression into IL and creates a DynamicMethod. From there, the expression can be evaluated as if it had been created at compile time, with similar speed.

This compiler also supports implicit multiplication, so something like x(2 + 2) evaluates as x * (2 + 2)

Right now, I am attempting to implement user-defined functions (e.g. f(x)). A problem arises when I try to differentiate between implicit multiplication, as shown above, and user defined functions. An example of this is if a user inputs x(5), how do I know whether they want to multiply x by 5, or invoke the x function with an argument of 5?

To solve this, in the previous case, the compiler inserts an if statement into the IL stream. It calls a function to determine if the function is defined with the identifier of x. If there is, then it inserts a MethodInfo instance onto the stack through an out variable and a local.

My actual question is, is it possible to execute a method using the MethodInfo instance on the stack that is equivalent in speed to calling IlGenerator.Emit(OpCodes.Call, MethodInfo) during compilation?

Thanks.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T08:47:18+00:00Added an answer on May 16, 2026 at 8:47 am

    The only way I am aware of that allows you to invoke a MethodInfo instance on the stack is by invoking the Invoke method on it. I’m sure you are already aware of this possibility, but you fear that it may be too slow. I recommend that you try it and time the performance under stress. You might find that it is fast enough for your purposes.

    If it isn’t, then you will have to think about how to restructure your design so that you don’t pass around MethodInfo instances. You could, for example, pass managed function pointers instead. Those are the things that the ldftn and ldvirtftn instructions return. You can then use the calli instruction to invoke one of those. You will need to construct the “call-site description”, which calli expects as an operand, using the SignatureHelper class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my 'myClass' class, I am using Reflection.Emit to dynamically write an event handler
How can I generate types like these using the System.Reflection.Emit libraries: public class Test<T>
Can I build a class as shown below dynamically using reflection? There are no
I need to define something like this using reflection Emit: public class Foo {
I am generating an Assembly on the fly using Reflection.Emit and then saving it.
When using Reflection.Emit to build an assembly at runtime, I'd like to verify the
I'm generating a dynamic assembly using Reflection.Emit which includes a single class. I have
I've built an assembly using Reflection.Emit. Running PEVerify returns 214 warnings of the same
What are some pros/cons for using the Reflection.Emit library versus CodeDOM for dynamically generating
I'm using reflection to see if the Equalizer class is available for Android OS

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.