I'm writing a very basic compiler for the .NET platform and would like to know something for my implementation of constants.
In my compiler, the use of constants will hopefully replace the ldloc operation.
If the constants theAge(18) and theName(Barry) were actually variables, the IL might be something like:
ldstr "Your name is "
ldloc theName
concat //Example operation for concatenating
ldstr " and you are "
concat
ldloc theAge
tostring //Example operation for changing the variable to a string
concat
But if I implemented constants:
ldstr "Your name is "
ldstr "Barry"
concat
ldstr " and you are "
concat
ldc.i4 18
tostring
concat
Which is faster: ldc.i4/ldstr or ldloc? Or is it better to store the constants as variables?