@@ -3396,65 +3396,63 @@ and GenTryCatch cenv cgbuf eenv (e1, vf: Val, ef, vh: Val, eh, m, resty, spTry,
33963396 let startOfFilter = CG.GenerateMark cgbuf " startOfFilter"
33973397 let afterFilter = CG.GenerateDelayMark cgbuf " afterFilter"
33983398 let ( sequelOnBranches , afterJoin , stackAfterJoin , sequelAfterJoin ) = GenJoinPoint cenv cgbuf " filter" eenv g.int_ ty m EndFilter
3399- begin
3400- // We emit the sequence point for the 'with' keyword span on the start of the filter
3401- // block. However the targets of the filter block pattern matching should not get any
3402- // sequence points (they will be 'true'/'false' values indicating if the exception has been
3403- // caught or not).
3404- //
3405- // The targets of the handler block DO get sequence points. Thus the expected behaviour
3406- // for a try/with with a complex pattern is that we hit the "with" before the filter is run
3407- // and then jump to the handler for the successful catch (or continue with exception handling
3408- // if the filter fails)
3409- match spWith with
3410- | SequencePointAtWith m -> CG.EmitSeqPoint cgbuf m
3411- | NoSequencePointAtWith -> ()
3412-
3413-
3414- CG.SetStack cgbuf [ g.ilg.typ_ Object]
3415- let _ , eenvinner = AllocLocalVal cenv cgbuf vf eenvinner None ( startOfFilter, afterFilter)
3416- CG.EmitInstr cgbuf ( pop 1 ) ( Push [ g.iltyp_ Exception]) ( I_ castclass g.iltyp_ Exception)
3417-
3418- GenStoreVal cenv cgbuf eenvinner vf.Range vf
3419-
3420- // Why SPSuppress? Because we do not emit a sequence point at the start of the List.filter - we've already put one on
3421- // the 'with' keyword above
3422- GenExpr cenv cgbuf eenvinner SPSuppress ef sequelOnBranches
3423- CG.SetMarkToHere cgbuf afterJoin
3424- CG.SetStack cgbuf stackAfterJoin
3425- GenSequel cenv eenv.cloc cgbuf sequelAfterJoin
3426- end
3399+ // We emit the sequence point for the 'with' keyword span on the start of the filter
3400+ // block. However the targets of the filter block pattern matching should not get any
3401+ // sequence points (they will be 'true'/'false' values indicating if the exception has been
3402+ // caught or not).
3403+ //
3404+ // The targets of the handler block DO get sequence points. Thus the expected behaviour
3405+ // for a try/with with a complex pattern is that we hit the "with" before the filter is run
3406+ // and then jump to the handler for the successful catch (or continue with exception handling
3407+ // if the filter fails)
3408+ match spWith with
3409+ | SequencePointAtWith m -> CG.EmitSeqPoint cgbuf m
3410+ | NoSequencePointAtWith -> ()
3411+
3412+
3413+ CG.SetStack cgbuf [ g.ilg.typ_ Object]
3414+ let _ , eenvinner = AllocLocalVal cenv cgbuf vf eenvinner None ( startOfFilter, afterFilter)
3415+ CG.EmitInstr cgbuf ( pop 1 ) ( Push [ g.iltyp_ Exception]) ( I_ castclass g.iltyp_ Exception)
3416+
3417+ GenStoreVal cenv cgbuf eenvinner vf.Range vf
3418+
3419+ // Why SPSuppress? Because we do not emit a sequence point at the start of the List.filter - we've already put one on
3420+ // the 'with' keyword above
3421+ GenExpr cenv cgbuf eenvinner SPSuppress ef sequelOnBranches
3422+ CG.SetMarkToHere cgbuf afterJoin
3423+ CG.SetStack cgbuf stackAfterJoin
3424+ GenSequel cenv eenv.cloc cgbuf sequelAfterJoin
34273425 let endOfFilter = CG.GenerateMark cgbuf " endOfFilter"
34283426 let filterMarks = ( startOfFilter.CodeLabel, endOfFilter.CodeLabel)
34293427 CG.SetMarkToHere cgbuf afterFilter
34303428
34313429 let startOfHandler = CG.GenerateMark cgbuf " startOfHandler"
3432- begin
3433- CG.SetStack cgbuf [ g.ilg.typ_ Object]
3434- let _ , eenvinner = AllocLocalVal cenv cgbuf vh eenvinner None ( startOfHandler, afterHandler)
3435- CG.EmitInstr cgbuf ( pop 1 ) ( Push [ g.iltyp_ Exception]) ( I_ castclass g.iltyp_ Exception)
3436- GenStoreVal cenv cgbuf eenvinner vh.Range vh
3437-
3438- GenExpr cenv cgbuf eenvinner SPAlways eh ( LeaveHandler ( false , whereToSave, afterHandler))
3439- end
3430+
3431+ CG.SetStack cgbuf [ g.ilg.typ_ Object]
3432+ let _ , eenvinner = AllocLocalVal cenv cgbuf vh eenvinner None ( startOfHandler, afterHandler)
3433+ CG.EmitInstr cgbuf ( pop 1 ) ( Push [ g.iltyp_ Exception]) ( I_ castclass g.iltyp_ Exception)
3434+ GenStoreVal cenv cgbuf eenvinner vh.Range vh
3435+
3436+ GenExpr cenv cgbuf eenvinner SPAlways eh ( LeaveHandler ( false , whereToSave, afterHandler))
3437+
34403438 let endOfHandler = CG.GenerateMark cgbuf " endOfHandler"
34413439 let handlerMarks = ( startOfHandler.CodeLabel, endOfHandler.CodeLabel)
34423440 ILExceptionClause.FilterCatch( filterMarks, handlerMarks)
34433441 else
34443442 let startOfHandler = CG.GenerateMark cgbuf " startOfHandler"
3445- begin
3446- match spWith with
3447- | SequencePointAtWith m -> CG.EmitSeqPoint cgbuf m
3448- | NoSequencePointAtWith -> ()
3443+
3444+ match spWith with
3445+ | SequencePointAtWith m -> CG.EmitSeqPoint cgbuf m
3446+ | NoSequencePointAtWith -> ()
34493447
3450- CG.SetStack cgbuf [ g.ilg.typ_ Object]
3451- let _ , eenvinner = AllocLocalVal cenv cgbuf vh eenvinner None ( startOfHandler, afterHandler)
3452- CG.EmitInstr cgbuf ( pop 1 ) ( Push [ g.iltyp_ Exception]) ( I_ castclass g.iltyp_ Exception)
3448+ CG.SetStack cgbuf [ g.ilg.typ_ Object]
3449+ let _ , eenvinner = AllocLocalVal cenv cgbuf vh eenvinner None ( startOfHandler, afterHandler)
3450+ CG.EmitInstr cgbuf ( pop 1 ) ( Push [ g.iltyp_ Exception]) ( I_ castclass g.iltyp_ Exception)
34533451
3454- GenStoreVal cenv cgbuf eenvinner m vh
3452+ GenStoreVal cenv cgbuf eenvinner m vh
34553453
3456- GenExpr cenv cgbuf eenvinner SPAlways eh ( LeaveHandler ( false , whereToSave, afterHandler))
3457- end
3454+ GenExpr cenv cgbuf eenvinner SPAlways eh ( LeaveHandler ( false , whereToSave, afterHandler))
3455+
34583456 let endOfHandler = CG.GenerateMark cgbuf " endOfHandler"
34593457 let handlerMarks = ( startOfHandler.CodeLabel, endOfHandler.CodeLabel)
34603458 ILExceptionClause.TypeCatch( g.ilg.typ_ Object, handlerMarks)
@@ -6591,56 +6589,47 @@ and GenTopImpl cenv (mgbuf: AssemblyBuilder) mainInfoOpt eenv (TImplFile (qname,
65916589 else
65926590 [], []
65936591
6594- begin
6595-
6596- match mainInfoOpt with
6597-
6598- // Final file in .EXE
6599- | Some mainInfo ->
6600-
6601- // Generate an explicit main method. If necessary, make a class constructor as
6602- // well for the bindings earlier in the file containing the entry point.
6603- match mgbuf.GetExplicitEntryPointInfo() with
6604-
6605- // Final file, explicit entry point: place the code in a .cctor, and add code to main that forces the .cctor (if topCode has initialization effect).
6606- | Some tref ->
6607- if doesSomething then
6608- lazyInitInfo.Add ( fun fspec feefee seqpt ->
6609- // This adds the explicit init of the .cctor to the explicit entry point main method
6610- mgbuf.AddExplicitInitToSpecificMethodDef(( fun md -> md.IsEntryPoint), tref, fspec, GenPossibleILSourceMarker cenv m, feefee, seqpt))
6611-
6612- let cctorMethDef = mkILClassCtor ( MethodBody.IL topCode)
6613- mgbuf.AddMethodDef( initClassTy.TypeRef, cctorMethDef)
66146592
6615- // Final file, implicit entry point. We generate no .cctor.
6616- // void main@() {
6617- // <topCode>
6618- // }
6619- | None ->
6620-
6621- let ilAttrs = mkILCustomAttrs ( GenAttrs cenv eenv mainInfo)
6622- if not cenv.opts.isInteractive && not doesSomething then
6623- let errorM = m.EndRange
6624- warning ( Error( FSComp.SR.ilMainModuleEmpty(), errorM))
6625-
6626- // generate main@
6627- let ilMainMethodDef =
6628- let mdef = mkILNonGenericStaticMethod( mainMethName, ILMemberAccess.Public, [], mkILReturn ILType.Void, MethodBody.IL topCode)
6629- mdef.With( isEntryPoint= true , customAttrs = ilAttrs)
6630-
6631- mgbuf.AddMethodDef( initClassTy.TypeRef, ilMainMethodDef)
6632-
6633-
6634- // Library file: generate an optional .cctor if topCode has initialization effect
6635- | None ->
6593+ match mainInfoOpt with
6594+ // Final file in .EXE
6595+ | Some mainInfo ->
6596+ // Generate an explicit main method. If necessary, make a class constructor as
6597+ // well for the bindings earlier in the file containing the entry point.
6598+ match mgbuf.GetExplicitEntryPointInfo() with
6599+ // Final file, explicit entry point: place the code in a .cctor, and add code to main that forces the .cctor (if topCode has initialization effect).
6600+ | Some tref ->
66366601 if doesSomething then
6602+ lazyInitInfo.Add ( fun fspec feefee seqpt ->
6603+ // This adds the explicit init of the .cctor to the explicit entry point main method
6604+ mgbuf.AddExplicitInitToSpecificMethodDef(( fun md -> md.IsEntryPoint), tref, fspec, GenPossibleILSourceMarker cenv m, feefee, seqpt))
66376605
6638- // Add the cctor
66396606 let cctorMethDef = mkILClassCtor ( MethodBody.IL topCode)
66406607 mgbuf.AddMethodDef( initClassTy.TypeRef, cctorMethDef)
66416608
6609+ // Final file, implicit entry point. We generate no .cctor.
6610+ // void main@() {
6611+ // <topCode>
6612+ // }
6613+ | None ->
6614+ let ilAttrs = mkILCustomAttrs ( GenAttrs cenv eenv mainInfo)
6615+ if not cenv.opts.isInteractive && not doesSomething then
6616+ let errorM = m.EndRange
6617+ warning ( Error( FSComp.SR.ilMainModuleEmpty(), errorM))
6618+
6619+ // generate main@
6620+ let ilMainMethodDef =
6621+ let mdef = mkILNonGenericStaticMethod( mainMethName, ILMemberAccess.Public, [], mkILReturn ILType.Void, MethodBody.IL topCode)
6622+ mdef.With( isEntryPoint= true , customAttrs = ilAttrs)
66426623
6643- end
6624+ mgbuf.AddMethodDef( initClassTy.TypeRef, ilMainMethodDef)
6625+
6626+
6627+ // Library file: generate an optional .cctor if topCode has initialization effect
6628+ | None ->
6629+ if doesSomething then
6630+ // Add the cctor
6631+ let cctorMethDef = mkILClassCtor ( MethodBody.IL topCode)
6632+ mgbuf.AddMethodDef( initClassTy.TypeRef, cctorMethDef)
66446633
66456634 // Commit the directed initializations
66466635 if doesSomething then
@@ -7511,29 +7500,27 @@ and GenExnDef cenv mgbuf eenv m (exnc: Tycon) =
75117500
75127501let CodegenAssembly cenv eenv mgbuf fileImpls =
75137502 if not ( isNil fileImpls) then
7514- let a , b = List.frontAndBack fileImpls
7515- let eenv = List.fold ( GenTopImpl cenv mgbuf None) eenv a
7516- let eenv = GenTopImpl cenv mgbuf cenv.opts.mainMethodInfo eenv b
7517-
7518- // Some constructs generate residue types and bindings. Generate these now. They don't result in any
7519- // top-level initialization code.
7520- begin
7521- let extraBindings = mgbuf.GrabExtraBindingsToGenerate()
7522- //printfn "#extraBindings = %d" extraBindings.Length
7523- if extraBindings.Length > 0 then
7524- let mexpr = TMDefs [ for b in extraBindings -> TMDefLet( b, range0) ]
7525- let _emptyTopInstrs , _emptyTopCode =
7526- CodeGenMethod cenv mgbuf ([], " unused" , eenv, 0 , ( fun cgbuf eenv ->
7527- let lazyInitInfo = ResizeArray()
7528- let qname = QualifiedNameOfFile( mkSynId range0 " unused" )
7529- LocalScope " module" cgbuf ( fun scopeMarks ->
7530- let eenv = AddBindingsForModuleDef ( fun cloc v -> AllocTopValWithinExpr cenv cgbuf cloc scopeMarks v) eenv.cloc eenv mexpr
7531- GenModuleDef cenv cgbuf qname lazyInitInfo eenv mexpr)), range0)
7532- //printfn "#_emptyTopInstrs = %d" _emptyTopInstrs.Length
7533- ()
7534- end
7535-
7536- mgbuf.AddInitializeScriptsInOrderToEntryPoint()
7503+ let a , b = List.frontAndBack fileImpls
7504+ let eenv = List.fold ( GenTopImpl cenv mgbuf None) eenv a
7505+ let eenv = GenTopImpl cenv mgbuf cenv.opts.mainMethodInfo eenv b
7506+
7507+ // Some constructs generate residue types and bindings. Generate these now. They don't result in any
7508+ // top-level initialization code.
7509+ let extraBindings = mgbuf.GrabExtraBindingsToGenerate()
7510+ //printfn "#extraBindings = %d" extraBindings.Length
7511+ if extraBindings.Length > 0 then
7512+ let mexpr = TMDefs [ for b in extraBindings -> TMDefLet( b, range0) ]
7513+ let _emptyTopInstrs , _emptyTopCode =
7514+ CodeGenMethod cenv mgbuf ([], " unused" , eenv, 0 , ( fun cgbuf eenv ->
7515+ let lazyInitInfo = ResizeArray()
7516+ let qname = QualifiedNameOfFile( mkSynId range0 " unused" )
7517+ LocalScope " module" cgbuf ( fun scopeMarks ->
7518+ let eenv = AddBindingsForModuleDef ( fun cloc v -> AllocTopValWithinExpr cenv cgbuf cloc scopeMarks v) eenv.cloc eenv mexpr
7519+ GenModuleDef cenv cgbuf qname lazyInitInfo eenv mexpr)), range0)
7520+ //printfn "#_emptyTopInstrs = %d" _emptyTopInstrs.Length
7521+ ()
7522+
7523+ mgbuf.AddInitializeScriptsInOrderToEntryPoint()
75377524
75387525//-------------------------------------------------------------------------
75397526// When generating a module we just write into mutable
0 commit comments