@@ -28,7 +28,7 @@ open System.Collections.Generic
28
28
let codeLabelOrder = ComparisonIdentity.Structural< ILCodeLabel>
29
29
30
30
// Convert the output of convCustomAttr
31
- #if SILVERLIGHT
31
+ #if FX _ REFLECTION _ EMITS _ CUSTOM _ ATTRIBUTES _ USING _ BUILDER
32
32
let wrapCustomAttr setCustomAttr ( cinfo , cinfoBuilder ) =
33
33
setCustomAttr( cinfoBuilder cinfo)
34
34
#else
@@ -46,12 +46,7 @@ let logRefEmitCalls = false
46
46
47
47
type System.AppDomain with
48
48
member x.DefineDynamicAssemblyAndLog ( asmName , flags , asmDir : string ) =
49
- #if SILVERLIGHT
50
- ignore asmDir
51
- let asmB = x.DefineDynamicAssembly( asmName, flags)
52
- #else
53
49
let asmB = x.DefineDynamicAssembly( asmName, flags, asmDir)
54
- #endif
55
50
if logRefEmitCalls then
56
51
printfn " open System"
57
52
printfn " open System.Reflection"
@@ -62,20 +57,15 @@ type System.AppDomain with
62
57
63
58
type System.Reflection.Emit.AssemblyBuilder with
64
59
member asmB.DefineDynamicModuleAndLog ( a , b , c ) =
65
- #if SILVERLIGHT
66
- ignore c
67
- let modB = asmB.DefineDynamicModule( a, b)
68
- #else
69
60
let modB = asmB.DefineDynamicModule( a, b, c)
70
- #endif
71
61
if logRefEmitCalls then printfn " let moduleBuilder%d = assemblyBuilder%d .DefineDynamicModule(%A ,%A ,%A )" ( abs <| hash modB) ( abs <| hash asmB) a b c
72
62
modB
73
63
74
64
member asmB.SetCustomAttributeAndLog ( cinfo , bytes ) =
75
65
if logRefEmitCalls then printfn " assemblyBuilder%d .SetCustomAttribute(%A , %A )" ( abs <| hash asmB) cinfo bytes
76
66
wrapCustomAttr asmB.SetCustomAttribute ( cinfo, bytes)
77
67
78
- #if SILVERLIGHT
68
+ #if FX _ NO _ REFLECTION _ EMIT _ RESOURCE _ FILE
79
69
#else
80
70
member asmB.AddResourceFileAndLog ( nm1 , nm2 , attrs ) =
81
71
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
108
98
109
99
member modB.DefineManifestResourceAndLog ( name , stream , attrs ) =
110
100
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
114
101
modB.DefineManifestResource( name, stream, attrs)
115
- #endif
116
102
117
103
member modB.SetCustomAttributeAndLog ( cinfo , bytes ) =
118
104
if logRefEmitCalls then printfn " moduleBuilder%d .SetCustomAttribute(%A , %A )" ( abs <| hash modB) cinfo bytes
@@ -210,13 +196,12 @@ type System.Reflection.Emit.TypeBuilder with
210
196
if logRefEmitCalls then printfn " typeBuilder%d .AddInterfaceImplementation(%A )" ( abs <| hash typB) ty
211
197
typB.AddInterfaceImplementation( ty)
212
198
199
+ #if FX_ NO_ INVOKE_ MEMBER
200
+ #else
213
201
member typB.InvokeMemberAndLog ( nm , flags , args ) =
214
202
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
218
203
typB.InvokeMember( nm, flags, null , null , args, Globalization.CultureInfo.InvariantCulture)
219
- #endif
204
+ #endif
220
205
221
206
member typB.SetCustomAttributeAndLog ( cinfo , bytes ) =
222
207
if logRefEmitCalls then printfn " typeBuilder%d .SetCustomAttribute(%A , %A )" ( abs <| hash typB) cinfo bytes
@@ -355,11 +340,8 @@ let convTypeRefAux (cenv:cenv) (tref:ILTypeRef) =
355
340
| ILScopeRef.Assembly asmref ->
356
341
let assembly =
357
342
match cenv.resolvePath asmref with
358
- #if SILVERLIGHT
359
- #else
360
343
| Some ( Choice1Of2 path) ->
361
344
FileSystem.AssemblyLoadFrom( path)
362
- #endif
363
345
| Some ( Choice2Of2 assembly) ->
364
346
assembly
365
347
| None ->
@@ -418,8 +400,6 @@ let envUpdateCreatedTypeRef emEnv (tref:ILTypeRef) =
418
400
let typT , typB , typeDef , _createdTypOpt = Zmap.force tref emEnv.emTypMap " envGetTypeDef: failed"
419
401
if typB.IsCreated() then
420
402
let typ = typB.CreateTypeAndLog()
421
- #if SILVERLIGHT
422
- #else
423
403
// Bug DevDev2 40395: Mono 2.6 and 2.8 has a bug where executing code that includes an array type
424
404
// match "match x with :? C[] -> ..." before the full loading of an object of type
425
405
// 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) =
430
410
try
431
411
System.Runtime.Serialization.FormatterServices.GetUninitializedObject( typ) |> ignore
432
412
with e -> ()
433
- #endif
434
413
435
414
{ emEnv with emTypMap = Zmap.add tref ( typT, typB, typeDef, Some typ) emEnv.emTypMap}
436
415
else
@@ -616,7 +595,7 @@ let convFieldInit x =
616
595
| ILFieldInit.Double ieee64 -> box ieee64
617
596
| ILFieldInit.Null -> ( null :> Object)
618
597
619
- #if SILVERLIGHT
598
+ #if FX _ REFLECTION _ EMITS _ CUSTOM _ ATTRIBUTES _ USING _ BUILDER
620
599
//----------------------------------------------------------------------------
621
600
// convAttribElem
622
601
//----------------------------------------------------------------------------
@@ -891,7 +870,7 @@ let emitInstrNewobj cenv emEnv (ilG:ILGenerator) mspec varargs =
891
870
| Some _ vartyps -> failwith " emit: pending new varargs" // XXX - gap
892
871
893
872
let emitSilverlightCheck ( ilG : ILGenerator ) =
894
- #if SILVERLIGHT
873
+ #if DYNAMIC _ CODE _ EMITS _ INTERRUPT _ CHECKS
895
874
if Microsoft.FSharp.Silverlight.EmitInterruptChecks then
896
875
let methWL = typeof< Microsoft.FSharp.Silverlight>. GetMethod( " CheckInterrupt" , BindingFlags.Static ||| BindingFlags.Public ||| BindingFlags.NonPublic, null , [||], null )
897
876
ilG.EmitCall( OpCodes.Call, methWL, [||])
@@ -909,7 +888,7 @@ let emitInstrCall cenv emEnv (ilG:ILGenerator) opCall tail (mspec:ILMethodSpec)
909
888
| Some _ vartyps -> failwith " emitInstrCall: .ctor and varargs"
910
889
else
911
890
let minfo = convMethodSpec cenv emEnv mspec
912
- #if SILVERLIGHT
891
+ #if DYNAMIC _ CODE _ REWRITES _ CONSOLE _ WRITE
913
892
// When generating code for silverlight, we intercept direct
914
893
// calls to System.Console.WriteLine.
915
894
let fullName = minfo.DeclaringType.FullName + " ." + minfo.Name
@@ -1090,7 +1069,7 @@ let rec emitInstr cenv (modB : ModuleBuilder) emEnv (ilG:ILGenerator) instr =
1090
1069
emitInstrCall cenv emEnv ilG OpCodes.Callvirt tail mspec varargs
1091
1070
| I_ callconstraint ( tail, typ, mspec, varargs) -> ilG.Emit( OpCodes.Constrained, convType cenv emEnv typ);
1092
1071
emitInstrCall cenv emEnv ilG OpCodes.Callvirt tail mspec varargs
1093
- #if SILVERLIGHT
1072
+ #if FX _ NO _ REFLECTION _ EMIT _ CALLI
1094
1073
| I_ calli ( tail,_ callsig, None) -> emitInstrTail ilG tail ( fun () -> ())
1095
1074
| I_ calli ( tail,_ callsig, Some _ vartyps) -> emitInstrTail ilG tail ( fun () -> ())
1096
1075
#else
@@ -1356,7 +1335,7 @@ let convCustomAttr cenv emEnv cattr =
1356
1335
| res -> res
1357
1336
// In Silverlight, we cannot use the byte[] data to generate attributes (security restriction).
1358
1337
// 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
1360
1339
let ty : System.Type = convType cenv emEnv cattr.Method.EnclosingType
1361
1340
let convAttrArray arr = [| for i in arr -> convAttribElem cenv emEnv i|]
1362
1341
@@ -1531,7 +1510,7 @@ let rec buildMethodPass2 cenv tref (typB:TypeBuilder) emEnv (mdef : ILMethodDef)
1531
1510
(* p.CharBestFit *)
1532
1511
(* p.NoMangle *)
1533
1512
1534
- #if SILVERLIGHT
1513
+ #if FX _ NO _ REFLECTION _ EMIT _ PINVOKE
1535
1514
failwith " PInvoke methods may not be defined when targeting Silverlight via System.Reflection.Emit"
1536
1515
#else
1537
1516
let methB = typB.DefinePInvokeMethod( mdef.Name,
@@ -1641,7 +1620,7 @@ let buildFieldPass2 cenv tref (typB:TypeBuilder) emEnv (fdef : ILFieldDef) =
1641
1620
let attrs = attrsAccess ||| attrsOther
1642
1621
let fieldT = convType cenv emEnv fdef.Type
1643
1622
let fieldB =
1644
- #if SILVERLIGHT
1623
+ #if FX _ NO _ REFLECTION _ EMIT _ STATIC _ DATA
1645
1624
#else
1646
1625
match fdef.Data with
1647
1626
| Some d -> typB.DefineInitializedData( fdef.Name, d, attrs)
@@ -1667,7 +1646,7 @@ let buildFieldPass2 cenv tref (typB:TypeBuilder) emEnv (fdef : ILFieldDef) =
1667
1646
// => here we cannot detect if underlying type is already set so as a conservative solution we delay initialization of fields
1668
1647
// to the end of pass2 (types and members are already created but method bodies are yet not emitted)
1669
1648
{ emEnv with delayedFieldInits = ( fun () -> fieldB.SetConstant( convFieldInit initial)):: emEnv.delayedFieldInits }
1670
- #if SILVERLIGHT
1649
+ #if FX _ NO _ REFLECTION _ EMIT _ STATIC _ DATA
1671
1650
#else
1672
1651
fdef.Offset |> Option.iter ( fun offset -> fieldB.SetOffset( offset));
1673
1652
#endif
@@ -1976,7 +1955,7 @@ let createTypeRef (visited : Dictionary<_,_>, created : Dictionary<_,_>) emEnv t
1976
1955
visited.[ tref] <- priority;
1977
1956
let tdef = envGetTypeDef emEnv tref
1978
1957
if verbose2 then dprintf " - traversing type %s \n " typB.FullName;
1979
- #if SILVERLIGHT
1958
+ #if FX _ NO _ TYPE _ RESOLVE _ EVENT
1980
1959
traverseTypeDef priority tref tdef;
1981
1960
#else
1982
1961
let typeCreationHandler =
@@ -2055,7 +2034,7 @@ let buildModuleFragment cenv emEnv (asmB : AssemblyBuilder) (modB : ModuleBuilde
2055
2034
| ILResourceLocation.Local bf ->
2056
2035
modB.DefineManifestResourceAndLog( r.Name, new System.IO.MemoryStream( bf()), attribs)
2057
2036
| ILResourceLocation.File ( mr,_ n) ->
2058
- #if SILVERLIGHT
2037
+ #if FX _ NO _ REFLECTION _ EMIT _ RESOURCE _ FILE
2059
2038
()
2060
2039
#else
2061
2040
asmB.AddResourceFileAndLog( r.Name, mr.Name, attribs)
@@ -2071,16 +2050,14 @@ let buildModuleFragment cenv emEnv (asmB : AssemblyBuilder) (modB : ModuleBuilde
2071
2050
let mkDynamicAssemblyAndModule ( assemblyName , optimize , debugInfo , collectible ) =
2072
2051
let filename = assemblyName ^ " .dll"
2073
2052
let currentDom = System.AppDomain.CurrentDomain
2074
- #if SILVERLIGHT
2075
- ignore optimize
2076
2053
let asmName = new AssemblyName()
2077
- asmName.Name <- assemblyName;
2054
+ asmName.Name <- assemblyName
2055
+ #if FX_ NO_ REFLECTION_ EMIT_ SAVE_ ASSEMBLY
2056
+ ignore optimize
2078
2057
let asmB = currentDom.DefineDynamicAssembly( asmName, AssemblyBuilderAccess.Run)
2079
2058
let modB = asmB.DefineDynamicModule( filename, debugInfo)
2080
2059
#else
2081
2060
let asmDir = " ."
2082
- let asmName = new AssemblyName()
2083
- asmName.Name <- assemblyName;
2084
2061
let asmAccess = if collectible then AssemblyBuilderAccess.RunAndCollect else AssemblyBuilderAccess.RunAndSave
2085
2062
let asmB = currentDom.DefineDynamicAssemblyAndLog( asmName, asmAccess, asmDir)
2086
2063
if not optimize then
@@ -2093,7 +2070,7 @@ let mkDynamicAssemblyAndModule (assemblyName, optimize, debugInfo, collectible)
2093
2070
#endif
2094
2071
asmB, modB
2095
2072
2096
- #if SILVERLIGHT
2073
+ #if FX _ NO _ INVOKE _ MEMBER
2097
2074
type EntryDelegate = delegate of unit -> unit
2098
2075
#endif
2099
2076
@@ -2109,7 +2086,7 @@ let emitModuleFragment (ilg, emEnv, asmB : AssemblyBuilder, modB : ModuleBuilder
2109
2086
// invoke entry point methods
2110
2087
let execEntryPtFun (( typB : TypeBuilder ), methodName ) () =
2111
2088
try
2112
- #if SILVERLIGHT
2089
+ #if FX _ NO _ INVOKE _ MEMBER
2113
2090
let mi = typB.GetMethod( methodName, BindingFlags.InvokeMethod ||| BindingFlags.Public ||| BindingFlags.Static)
2114
2091
System.Diagnostics.Debug.WriteLine( " mi: {0}" , string( mi.ToString()))
2115
2092
let dm = DynamicMethod(( methodName+ " dm" ), null , null )
0 commit comments