Пример #1
0
        private void DefineConstructor(Method constructor)
        {
            Type[] parameters = new Type[1 + constructor.Parameters.Count];

            parameters[0] = typeof(RuntimeState);

            for (int n = 1; n < parameters.Length; n++)
            {
                parameters[n] = typeof(object);
            }

            ConstructorBuilder builder = typeBuilder.DefineConstructor(
                MethodAttributes.Public,
                CallingConventions.Standard,
                parameters);

            Block generator = new Block();

            SetMethodsToInitialValues(generator);

            if (!constructor.IsInstance)
            {
                throw new Exception();
            }

            MethodInfo callMethod = typeof(Method).GetMethod("Call", new Type[] { typeof(RuntimeState), typeof(object), typeof(object[]) });

            if (callMethod == null)
            {
                throw new Exception();
            }

            generator.Load(constructor);
            generator.LoadArg(1);
            generator.LoadArg(0);

            generator.Load(constructor.Parameters.Count);
            generator.NewArray(typeof(object));

            for (int n = 0; n < constructor.Parameters.Count; n++)
            {
                generator.Dup();
                generator.Load(n);
                generator.LoadArg(n + 1);
                generator.StoreElementRef();
            }

            generator.Call(callMethod);
            generator.Pop();

            generator.Return();

            generator.Build(new ConstructorBuilderProxy(builder));
        }
Пример #2
0
 private void SetMethodsToInitialValues(Block generator)
 {
     foreach (Method method in methods)
     {
         generator.LoadArg(0);
         generator.Load(method);
         generator.StoreField(typeBuilder.GetField(method.Name));
     }
 }
Пример #3
0
 private void DefineConstructor(Method constructor)
 {
     Type[] parameters = new Type[1 + constructor.Parameters.Count];
     
     parameters[0] = typeof(RuntimeState);
     
     for (int n = 1; n < parameters.Length; n++)
         parameters[n] = typeof(object);
     
     ConstructorBuilder builder = typeBuilder.DefineConstructor(
         MethodAttributes.Public,
         CallingConventions.Standard,
         parameters);
     
     Block generator = new Block();
     
     SetMethodsToInitialValues(generator);
     
     if (!constructor.IsInstance)
         throw new Exception();
     
     MethodInfo callMethod = typeof(Method).GetMethod("Call", new Type[]{typeof(RuntimeState), typeof(object), typeof(object[])});
     
     if (callMethod == null)
         throw new Exception();
     
     generator.Load(constructor);
     generator.LoadArg(1);
     generator.LoadArg(0);
     
     generator.Load(constructor.Parameters.Count);
     generator.NewArray(typeof(object));
     
     for (int n = 0; n < constructor.Parameters.Count; n++)
     {
         generator.Dup();
         generator.Load(n);
         generator.LoadArg(n + 1);
         generator.StoreElementRef();
     }
     
     generator.Call(callMethod);
     generator.Pop();
     
     generator.Return();
     
     generator.Build(new ConstructorBuilderProxy(builder));
 }
Пример #4
0
 private void SetMethodsToInitialValues(Block generator)
 {
     foreach (Method method in methods)
     {
         generator.LoadArg(0);
         generator.Load(method);
         generator.StoreField(typeBuilder.GetField(method.Name));
     }
 }
Пример #5
0
 public override void EmitGet(Block generator)
 {
     generator.Load(o);
 }