Пример #1
0
 private static void DefineMethods(TypeBuilder proxyTB, ISeq methods)
 {
     for (ISeq s = methods == null ? null : methods.seq(); s != null; s = s.next())
     {
         DefineMethod(proxyTB, (IPersistentVector)s.first());
     }
 }
Пример #2
0
        public static Type GenerateInterface(string iName, ISeq extends, ISeq methods)
        {
            GenContext context = new GenContext(iName, CompilerMode.File);

            //            GenContext context = (GenContext)Compiler.COMPILER_CONTEXT.deref();
            //            if (context == null)
            //            {
            //#if DEBUG
            //                context = new GenContext(iName, CompilerMode.File);
            //#else
            //                throw new InvalidOperationException("No compiler context on the stack.");
            //#endif
            //            }

            Type[] interfaceTypes = GenClass.CreateTypeArray(extends == null ? null : extends.seq());

            TypeBuilder proxyTB = context.ModuleBldr.DefineType(
                iName,
                TypeAttributes.Interface | TypeAttributes.Public | TypeAttributes.Abstract,
                null,
                interfaceTypes);

            DefineMethods(proxyTB, methods);

            Type t = proxyTB.CreateType();
            context.AssyBldr.Save(iName  + ".dll");
            return t;
        }
Пример #3
0
        internal static Type[] CreateTypeArray(ISeq seq)
        {
            List <Type> types = new List <Type>();

            for (ISeq s = seq?.seq(); s != null; s = s.next())
            {
                Object o       = s.first();
                Type   oAsType = o as Type;
                if (oAsType != null)
                {
                    types.Add(oAsType);
                }
                else if (o is ISeq)
                {
                    object first         = RT.first(o);
                    Symbol firstAsSymbol = first as Symbol;
                    if (firstAsSymbol == null || !firstAsSymbol.Equals(HostExpr.ByRefSym))
                    {
                        throw new ArgumentException("First element of parameter definition is not by-ref");
                    }

                    Type secondAsType = RT.second(o) as Type;

                    if (secondAsType == null)
                    {
                        throw new ArgumentException("by-ref must be paired with a type");
                    }

                    types.Add(secondAsType.MakeByRefType());
                }
                else
                {
                    throw new ArgumentException("Bad parameter definition");
                }
            }

            if (types.Count == 0)
            {
                return(Type.EmptyTypes);
            }

            return(types.ToArray <Type>());
        }
Пример #4
0
        public static Type GenerateInterface(string iName, IPersistentMap attributes, ISeq extends, ISeq methods)
        {
            iName = iName.Replace('-', '_');

            GenContext context;

            if (Compiler.IsCompiling)
            {
                //string path = (string)Compiler.COMPILE_PATH.deref();
                //if (path == null)
                //    throw new Exception("*compile-path* not set");
                //context = new GenContext(iName, ".dll", path, CompilerMode.File);
                context = (GenContext)Compiler.COMPILER_CONTEXT.deref();
            }
            else
                // TODO: In CLR4, should create a collectible type?
                context = GenContext.CreateWithExternalAssembly(iName, ".dll", false);

            Type[] interfaceTypes = GenClass.CreateTypeArray(extends == null ? null : extends.seq());

            TypeBuilder proxyTB = context.ModuleBuilder.DefineType(
                iName,
                TypeAttributes.Interface | TypeAttributes.Public | TypeAttributes.Abstract,
                null,
                interfaceTypes);

            SetCustomAttributes(proxyTB, attributes);

            DefineMethods(proxyTB, methods);

            Type t = proxyTB.CreateType();

            //if ( Compiler.IsCompiling )
            //    context.SaveAssembly();

            Compiler.RegisterDuplicateType(t);

            return t;
        }
Пример #5
0
 private static void DefineMethods(TypeBuilder proxyTB, ISeq methods)
 {
     for (ISeq s = methods == null ? null : methods.seq(); s != null; s = s.next())
         DefineMethod(proxyTB, (IPersistentVector)s.first());
 }
Пример #6
0
        internal static Type[] CreateTypeArray(ISeq seq)
        {
            List<Type> types = new List<Type>();

            for (ISeq s = seq == null ? null : seq.seq(); s != null; s = s.next())
            {
                Object o = s.first();
                Type oAsType = o as Type;
                if (oAsType != null )
                    types.Add(oAsType);
                else if (o is ISeq)
                {
                    object first = RT.first(o);
                   Symbol firstAsSymbol = first as Symbol;
                    if (firstAsSymbol == null || !firstAsSymbol.Equals(HostExpr.ByRefSym))
                        throw new ArgumentException("First element of parameter definition is not by-ref");

                    Type secondAsType = RT.second(o) as Type;

                    if (secondAsType == null)
                        throw new ArgumentException("by-ref must be paired with a type");

                    types.Add(secondAsType.MakeByRefType());
                }
                else
                    throw new ArgumentException("Bad parameter definition");
            }

            if ( types.Count ==  0 )
                return Type.EmptyTypes;

            return types.ToArray<Type>();
        }
Пример #7
0
        internal static Type[] CreateTypeArray(ISeq seq)
        {
            List<Type> types = new List<Type>();

            for (ISeq s = seq == null ? null : seq.seq(); s != null; s = s.next())
            {
                Object o = s.first();
                if (o is Type)
                    types.Add((Type)o);
                else if (o is ISeq)
                {
                    object first = RT.first(o);
                    object second = RT.second(o);
                    if (!(first is Symbol) || !((Symbol)first).Equals(HostExpr.BY_REF))
                        throw new ArgumentException("First element of parameter definition is not by-ref");
                    if (!(second is Type))
                        throw new ArgumentException("by-ref must be paired with a type");
                    Type t = (Type)second;
                    types.Add(t.MakeByRefType());
                }
                else
                    throw new ArgumentException("Bad parameter definition");
            }

            if ( types.Count ==  0 )
                return Type.EmptyTypes;

            return types.ToArray<Type>();
        }
Пример #8
0
        internal static Type[] CreateTypeArray(ISeq seq)
        {
            List<Type> types = new List<Type>();

            for (ISeq s = seq == null ? null :seq.seq(); s != null; s = s.next())
                types.Add((Type)s.first());

            if ( types.Count ==  0 )
                return Type.EmptyTypes;

            return types.ToArray<Type>();
        }