@@ -28,7 +28,7 @@ open System.Collections.Generic
2828let codeLabelOrder = ComparisonIdentity.Structural< ILCodeLabel>
2929
3030// Convert the output of convCustomAttr
31- #if SILVERLIGHT
31+ #if FX _ REFLECTION _ EMITS _ CUSTOM _ ATTRIBUTES _ USING _ BUILDER
3232let wrapCustomAttr setCustomAttr ( cinfo , cinfoBuilder ) =
3333 setCustomAttr( cinfoBuilder cinfo)
3434#else
@@ -46,12 +46,7 @@ let logRefEmitCalls = false
4646
4747type System.AppDomain with
4848 member x.DefineDynamicAssemblyAndLog ( asmName , flags , asmDir : string ) =
49- #if SILVERLIGHT
50- ignore asmDir
51- let asmB = x.DefineDynamicAssembly( asmName, flags)
52- #else
5349 let asmB = x.DefineDynamicAssembly( asmName, flags, asmDir)
54- #endif
5550 if logRefEmitCalls then
5651 printfn " open System"
5752 printfn " open System.Reflection"
@@ -62,20 +57,15 @@ type System.AppDomain with
6257
6358type System.Reflection.Emit.AssemblyBuilder with
6459 member asmB.DefineDynamicModuleAndLog ( a , b , c ) =
65- #if SILVERLIGHT
66- ignore c
67- let modB = asmB.DefineDynamicModule( a, b)
68- #else
6960 let modB = asmB.DefineDynamicModule( a, b, c)
70- #endif
7161 if logRefEmitCalls then printfn " let moduleBuilder%d = assemblyBuilder%d .DefineDynamicModule(%A ,%A ,%A )" ( abs <| hash modB) ( abs <| hash asmB) a b c
7262 modB
7363
7464 member asmB.SetCustomAttributeAndLog ( cinfo , bytes ) =
7565 if logRefEmitCalls then printfn " assemblyBuilder%d .SetCustomAttribute(%A , %A )" ( abs <| hash asmB) cinfo bytes
7666 wrapCustomAttr asmB.SetCustomAttribute ( cinfo, bytes)
7767
78- #if SILVERLIGHT
68+ #if FX _ NO _ REFLECTION _ EMIT _ RESOURCE _ FILE
7969#else
8070 member asmB.AddResourceFileAndLog ( nm1 , nm2 , attrs ) =
8171 if logRefEmitCalls then printfn " assemblyBuilder%d .AddResourceFile(%A , %A , enum %d )" ( abs <| hash asmB) nm1 nm2 ( LanguagePrimitives.EnumToValue attrs)
@@ -108,11 +98,7 @@ type System.Reflection.Emit.ModuleBuilder with
10898
10999 member modB.DefineManifestResourceAndLog ( name , stream , attrs ) =
110100 if logRefEmitCalls then printfn " moduleBuilder%d .DefineManifestResource(%A ,%A ,enum %d )" ( abs <| hash modB) name stream ( LanguagePrimitives.EnumToValue attrs)
111- #if SILVERLIGHT
112- // Annoyingly, DefineManifestResource is security critical on Silverlight
113- #else
114101 modB.DefineManifestResource( name, stream, attrs)
115- #endif
116102
117103 member modB.SetCustomAttributeAndLog ( cinfo , bytes ) =
118104 if logRefEmitCalls then printfn " moduleBuilder%d .SetCustomAttribute(%A , %A )" ( abs <| hash modB) cinfo bytes
@@ -210,13 +196,12 @@ type System.Reflection.Emit.TypeBuilder with
210196 if logRefEmitCalls then printfn " typeBuilder%d .AddInterfaceImplementation(%A )" ( abs <| hash typB) ty
211197 typB.AddInterfaceImplementation( ty)
212198
199+ #if FX_ NO_ INVOKE_ MEMBER
200+ #else
213201 member typB.InvokeMemberAndLog ( nm , flags , args ) =
214202 if logRefEmitCalls then printfn " typeBuilder%d .InvokeMember(\" %s \" ,enum %d ,null,null,%A ,Globalization.CultureInfo.InvariantCulture)" ( abs <| hash typB) nm ( LanguagePrimitives.EnumToValue flags) args
215- #if SILVERLIGHT
216- typB.InvokeMember( nm, flags, null , null , args)
217- #else
218203 typB.InvokeMember( nm, flags, null , null , args, Globalization.CultureInfo.InvariantCulture)
219- #endif
204+ #endif
220205
221206 member typB.SetCustomAttributeAndLog ( cinfo , bytes ) =
222207 if logRefEmitCalls then printfn " typeBuilder%d .SetCustomAttribute(%A , %A )" ( abs <| hash typB) cinfo bytes
@@ -355,11 +340,8 @@ let convTypeRefAux (cenv:cenv) (tref:ILTypeRef) =
355340 | ILScopeRef.Assembly asmref ->
356341 let assembly =
357342 match cenv.resolvePath asmref with
358- #if SILVERLIGHT
359- #else
360343 | Some ( Choice1Of2 path) ->
361344 FileSystem.AssemblyLoadFrom( path)
362- #endif
363345 | Some ( Choice2Of2 assembly) ->
364346 assembly
365347 | None ->
@@ -418,8 +400,6 @@ let envUpdateCreatedTypeRef emEnv (tref:ILTypeRef) =
418400 let typT , typB , typeDef , _createdTypOpt = Zmap.force tref emEnv.emTypMap " envGetTypeDef: failed"
419401 if typB.IsCreated() then
420402 let typ = typB.CreateTypeAndLog()
421- #if SILVERLIGHT
422- #else
423403 // Bug DevDev2 40395: Mono 2.6 and 2.8 has a bug where executing code that includes an array type
424404 // match "match x with :? C[] -> ..." before the full loading of an object of type
425405 // causes a failure when C is later loaded. One workaround for this is to attempt to do a fake allocation
@@ -430,7 +410,6 @@ let envUpdateCreatedTypeRef emEnv (tref:ILTypeRef) =
430410 try
431411 System.Runtime.Serialization.FormatterServices.GetUninitializedObject( typ) |> ignore
432412 with e -> ()
433- #endif
434413
435414 { emEnv with emTypMap = Zmap.add tref ( typT, typB, typeDef, Some typ) emEnv.emTypMap}
436415 else
@@ -616,7 +595,7 @@ let convFieldInit x =
616595 | ILFieldInit.Double ieee64 -> box ieee64
617596 | ILFieldInit.Null -> ( null :> Object)
618597
619- #if SILVERLIGHT
598+ #if FX _ REFLECTION _ EMITS _ CUSTOM _ ATTRIBUTES _ USING _ BUILDER
620599//----------------------------------------------------------------------------
621600// convAttribElem
622601//----------------------------------------------------------------------------
@@ -891,7 +870,7 @@ let emitInstrNewobj cenv emEnv (ilG:ILGenerator) mspec varargs =
891870 | Some _ vartyps -> failwith " emit: pending new varargs" // XXX - gap
892871
893872let emitSilverlightCheck ( ilG : ILGenerator ) =
894- #if SILVERLIGHT
873+ #if DYNAMIC _ CODE _ EMITS _ INTERRUPT _ CHECKS
895874 if Microsoft.FSharp.Silverlight.EmitInterruptChecks then
896875 let methWL = typeof< Microsoft.FSharp.Silverlight>. GetMethod( " CheckInterrupt" , BindingFlags.Static ||| BindingFlags.Public ||| BindingFlags.NonPublic, null , [||], null )
897876 ilG.EmitCall( OpCodes.Call, methWL, [||])
@@ -909,7 +888,7 @@ let emitInstrCall cenv emEnv (ilG:ILGenerator) opCall tail (mspec:ILMethodSpec)
909888 | Some _ vartyps -> failwith " emitInstrCall: .ctor and varargs"
910889 else
911890 let minfo = convMethodSpec cenv emEnv mspec
912- #if SILVERLIGHT
891+ #if DYNAMIC _ CODE _ REWRITES _ CONSOLE _ WRITE
913892 // When generating code for silverlight, we intercept direct
914893 // calls to System.Console.WriteLine.
915894 let fullName = minfo.DeclaringType.FullName + " ." + minfo.Name
@@ -1090,7 +1069,7 @@ let rec emitInstr cenv (modB : ModuleBuilder) emEnv (ilG:ILGenerator) instr =
10901069 emitInstrCall cenv emEnv ilG OpCodes.Callvirt tail mspec varargs
10911070 | I_ callconstraint ( tail, typ, mspec, varargs) -> ilG.Emit( OpCodes.Constrained, convType cenv emEnv typ);
10921071 emitInstrCall cenv emEnv ilG OpCodes.Callvirt tail mspec varargs
1093- #if SILVERLIGHT
1072+ #if FX _ NO _ REFLECTION _ EMIT _ CALLI
10941073 | I_ calli ( tail,_ callsig, None) -> emitInstrTail ilG tail ( fun () -> ())
10951074 | I_ calli ( tail,_ callsig, Some _ vartyps) -> emitInstrTail ilG tail ( fun () -> ())
10961075#else
@@ -1356,7 +1335,7 @@ let convCustomAttr cenv emEnv cattr =
13561335 | res -> res
13571336// In Silverlight, we cannot use the byte[] data to generate attributes (security restriction).
13581337// Instead, we return a function which creates a CustomAttributeBuilder to be used for SetCustomAttributes.
1359- #if SILVERLIGHT
1338+ #if FX _ REFLECTION _ EMITS _ CUSTOM _ ATTRIBUTES _ USING _ BUILDER
13601339 let ty : System.Type = convType cenv emEnv cattr.Method.EnclosingType
13611340 let convAttrArray arr = [| for i in arr -> convAttribElem cenv emEnv i|]
13621341
@@ -1531,7 +1510,7 @@ let rec buildMethodPass2 cenv tref (typB:TypeBuilder) emEnv (mdef : ILMethodDef)
15311510(* p.CharBestFit *)
15321511(* p.NoMangle *)
15331512
1534- #if SILVERLIGHT
1513+ #if FX _ NO _ REFLECTION _ EMIT _ PINVOKE
15351514 failwith " PInvoke methods may not be defined when targeting Silverlight via System.Reflection.Emit"
15361515#else
15371516 let methB = typB.DefinePInvokeMethod( mdef.Name,
@@ -1641,7 +1620,7 @@ let buildFieldPass2 cenv tref (typB:TypeBuilder) emEnv (fdef : ILFieldDef) =
16411620 let attrs = attrsAccess ||| attrsOther
16421621 let fieldT = convType cenv emEnv fdef.Type
16431622 let fieldB =
1644- #if SILVERLIGHT
1623+ #if FX _ NO _ REFLECTION _ EMIT _ STATIC _ DATA
16451624#else
16461625 match fdef.Data with
16471626 | Some d -> typB.DefineInitializedData( fdef.Name, d, attrs)
@@ -1667,7 +1646,7 @@ let buildFieldPass2 cenv tref (typB:TypeBuilder) emEnv (fdef : ILFieldDef) =
16671646 // => here we cannot detect if underlying type is already set so as a conservative solution we delay initialization of fields
16681647 // to the end of pass2 (types and members are already created but method bodies are yet not emitted)
16691648 { emEnv with delayedFieldInits = ( fun () -> fieldB.SetConstant( convFieldInit initial)):: emEnv.delayedFieldInits }
1670- #if SILVERLIGHT
1649+ #if FX _ NO _ REFLECTION _ EMIT _ STATIC _ DATA
16711650#else
16721651 fdef.Offset |> Option.iter ( fun offset -> fieldB.SetOffset( offset));
16731652#endif
@@ -1976,7 +1955,7 @@ let createTypeRef (visited : Dictionary<_,_>, created : Dictionary<_,_>) emEnv t
19761955 visited.[ tref] <- priority;
19771956 let tdef = envGetTypeDef emEnv tref
19781957 if verbose2 then dprintf " - traversing type %s \n " typB.FullName;
1979- #if SILVERLIGHT
1958+ #if FX _ NO _ TYPE _ RESOLVE _ EVENT
19801959 traverseTypeDef priority tref tdef;
19811960#else
19821961 let typeCreationHandler =
@@ -2055,7 +2034,7 @@ let buildModuleFragment cenv emEnv (asmB : AssemblyBuilder) (modB : ModuleBuilde
20552034 | ILResourceLocation.Local bf ->
20562035 modB.DefineManifestResourceAndLog( r.Name, new System.IO.MemoryStream( bf()), attribs)
20572036 | ILResourceLocation.File ( mr,_ n) ->
2058- #if SILVERLIGHT
2037+ #if FX _ NO _ REFLECTION _ EMIT _ RESOURCE _ FILE
20592038 ()
20602039#else
20612040 asmB.AddResourceFileAndLog( r.Name, mr.Name, attribs)
@@ -2071,16 +2050,14 @@ let buildModuleFragment cenv emEnv (asmB : AssemblyBuilder) (modB : ModuleBuilde
20712050let mkDynamicAssemblyAndModule ( assemblyName , optimize , debugInfo , collectible ) =
20722051 let filename = assemblyName ^ " .dll"
20732052 let currentDom = System.AppDomain.CurrentDomain
2074- #if SILVERLIGHT
2075- ignore optimize
20762053 let asmName = new AssemblyName()
2077- asmName.Name <- assemblyName;
2054+ asmName.Name <- assemblyName
2055+ #if FX_ NO_ REFLECTION_ EMIT_ SAVE_ ASSEMBLY
2056+ ignore optimize
20782057 let asmB = currentDom.DefineDynamicAssembly( asmName, AssemblyBuilderAccess.Run)
20792058 let modB = asmB.DefineDynamicModule( filename, debugInfo)
20802059#else
20812060 let asmDir = " ."
2082- let asmName = new AssemblyName()
2083- asmName.Name <- assemblyName;
20842061 let asmAccess = if collectible then AssemblyBuilderAccess.RunAndCollect else AssemblyBuilderAccess.RunAndSave
20852062 let asmB = currentDom.DefineDynamicAssemblyAndLog( asmName, asmAccess, asmDir)
20862063 if not optimize then
@@ -2093,7 +2070,7 @@ let mkDynamicAssemblyAndModule (assemblyName, optimize, debugInfo, collectible)
20932070#endif
20942071 asmB, modB
20952072
2096- #if SILVERLIGHT
2073+ #if FX _ NO _ INVOKE _ MEMBER
20972074type EntryDelegate = delegate of unit -> unit
20982075#endif
20992076
@@ -2109,7 +2086,7 @@ let emitModuleFragment (ilg, emEnv, asmB : AssemblyBuilder, modB : ModuleBuilder
21092086 // invoke entry point methods
21102087 let execEntryPtFun (( typB : TypeBuilder ), methodName ) () =
21112088 try
2112- #if SILVERLIGHT
2089+ #if FX _ NO _ INVOKE _ MEMBER
21132090 let mi = typB.GetMethod( methodName, BindingFlags.InvokeMethod ||| BindingFlags.Public ||| BindingFlags.Static)
21142091 System.Diagnostics.Debug.WriteLine( " mi: {0}" , string( mi.ToString()))
21152092 let dm = DynamicMethod(( methodName+ " dm" ), null , null )
0 commit comments