[Mono-list] Doubt in Reflection.Emit
Ben Maurer
05mauben@hawken.edu
Tue, 09 Mar 2004 10:03:05 -0500
ldarg.0 is the implict `this' pointer for any instance method. Take a
look at the code mcs generates for something like
class T {
void Foo () { Bar (); }
void Bar () {}
static void Main () { new T ().Foo (); }
}
>>> mono devel <nvineeth_mono@yahoo.com> 03/09/04 09:40 AM >>>
hello,
I have doubt in Reflection.Emit.Opcodes.
I have noticed that before setting a variable , or
calling a function
Opcodes.ldarg_0 is always emitted.
I want to know if ldarg_0 contains a reference to
current object(something like "this" pointer) ::
The example i came accross is as follows ( i have
marked the lines which do this )::
FieldBuilder xField =
pointTypeBld.DefineField("x", typeof(int),
FieldAttributes.Public);
FieldBuilder yField =
pointTypeBld.DefineField("y", typeof(int),
FieldAttributes.Public);
Type objType = Type.GetType("System.Object");
ConstructorInfo objCtor =
objType.GetConstructor(new Type[0]);
ConstructorBuilder pointCtor =
pointTypeBld.DefineConstructor(
MethodAttributes.Public,
CallingConventions.Standard,
ctorParams);
ILGenerator ctorIL =
pointCtor.GetILGenerator();
// First, you build the constructor.
ctorIL.Emit(OpCodes.Ldarg_0);//<--Here####
ctorIL.Emit(OpCodes.Call, objCtor);//objCtor is
the constructor of System.Object;
ctorIL.Emit(OpCodes.Ldarg_0);//<--Here#######
ctorIL.Emit(OpCodes.Ldarg_1);
ctorIL.Emit(OpCodes.Stfld, xField);
ctorIL.Emit(OpCodes.Ldarg_0);//<--Here#####
ctorIL.Emit(OpCodes.Ldarg_2);
ctorIL.Emit(OpCodes.Stfld, yField);
ctorIL.Emit(OpCodes.Ret);
//--------------------------------
can someone please rectify this doubt.
thanks,
vineeth
=====
vineeth N
__________________________________
Do you Yahoo!?
Yahoo! Search - Find what you're looking for faster
http://search.yahoo.com
_______________________________________________
Mono-list maillist - Mono-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list