public void MacroCompilerIsTakenFromTheEnvironment() { var compiler = new Mock <MacroCompiler>(MockBehavior.Strict); ActiveEnvironment.With(CompilerContextEnvironmentWith(compiler), () => { var module = CreateModule(); var macroApplication = new MacroStatement(new LexicalInfo("file.boo", 1, 1), "foo"); module.Globals.Add(macroApplication); var macroDefinition = CreateClassOn(module, "FooMacro"); compiler.Setup(o => o.AlreadyCompiled(macroDefinition)).Returns(false); compiler.Setup(o => o.Compile(macroDefinition)).Returns((Type)null); var expander = My <MacroExpander> .Instance; Assert.IsFalse(expander.ExpandAll()); var errors = CompilerErrors(); Assert.AreEqual(1, errors.Count); Assert.AreEqual(CompilerErrorFactory.AstMacroMustBeExternal(macroApplication, (IType)macroDefinition.Entity).ToString(), errors[0].ToString()); }); compiler.VerifyAll(); }
public void CompileUnitIsProvidedToTheEnvironment() { var compileUnit = new CompileUnit(); ActiveEnvironment.With( new CompilerContext(compileUnit).Environment, () => Assert.AreSame(compileUnit, My <CompileUnit> .Instance)); }
public void ExactTypeRequestIsFullfilled() { var environment = new DeferredEnvironment { { typeof(Foo), () => new Foo() } }; ActiveEnvironment.With(environment, () => Assert.IsNotNull(My <Foo> .Instance)); }
public void CompatibleTypeRequestIsFullfilled() { var environment = new DeferredEnvironment { { typeof(ImprovedFoo), () => new ImprovedFoo() } }; ActiveEnvironment.With(environment, () => Assert.IsNotNull(My <Foo> .Instance)); }
protected T InvokeInCompilerContextEnvironment <T>(System.Func <T> function) { List <T> container = new List <T>(); ActiveEnvironment.With(Environment, () => { container.Add(function()); }); return(container[0]); }
protected INamespace ThreadSafeGetNamespace(string qname) { INamespace result = null; var env = ActiveEnvironment.Instance; Application.Current.Dispatcher.Invoke( () => ActiveEnvironment.With(env, () => result = SafeGetNamespace(qname))); return(result); }
public void SelectRunsInsideOriginalEnvironment() { var environment = new ClosedEnvironment("42"); var v = default(EnvironmentBoundValue <string>); ActiveEnvironment.With(environment, () => v = EnvironmentBoundValue.Capture <string>()); var valueEnvironmentPair = v.Select(value => new object[] { value, ActiveEnvironment.Instance }).Value; Assert.AreEqual("42", valueEnvironmentPair[0]); Assert.AreSame(environment, valueEnvironmentPair[1]); }
protected static void AssertDisplayNameGoesThroughEntityFormatter(IType entity) { var mock = new Mock <EntityFormatter>(); ActiveEnvironment.With(new ClosedEnvironment(mock.Object), () => { mock.Setup(formatter => formatter.FormatType(entity)) .Returns("") .AtMostOnce(); entity.DisplayName(); mock.VerifyAll(); }); }
public void CustomTypeInferenceRuleAttribute() { var customAttributeName = typeof(CustomAttribute).FullName.Replace('+', '.'); var parameters = new CompilerParameters(); parameters.References.Add(typeof(CustomAttribute).Assembly); CommandLineParser.ParseInto(parameters, "-x-type-inference-rule-attribute:" + customAttributeName); ActiveEnvironment.With(new CompilerContext(parameters).Environment, () => { var m = Methods.Of <object>(MethodWithCustomTypeInferenceRule); Assert.AreEqual("custom", My <TypeInferenceRuleProvider> .Instance.TypeInferenceRuleFor(m)); }); }
virtual public void Run(CompilerContext context) { ActiveEnvironment.With(context.Environment, () => { OnBefore(context); try { Prepare(context); RunSteps(context); } finally { try { DisposeSteps(); } finally { OnAfter(context); } } }); }
public void ProvisioningHappensOnDemandAndOnlyOnce() { var mock = new Mock <IEnvironment>(); mock.Setup(e => e.Provide <Foo>()).Returns(new Foo()).AtMostOnce(); var foo = new EnvironmentProvision <Foo>(); ActiveEnvironment.With(mock.Object, () => { var first = foo.Instance; var second = foo.Instance; Assert.IsNotNull(first); Assert.AreSame(first, second); }); mock.VerifyAll(); }
public void CompatibleInstancesAreReturned() { const string instance = "42"; var mock = new Mock <IEnvironment>(); mock.Setup(e => e.Provide <string>()).Returns(instance).AtMostOnce(); var subject = new CachingEnvironment(mock.Object); ActiveEnvironment.With(subject, () => { Assert.AreSame(instance, My <string> .Instance); Assert.AreSame(instance, My <object> .Instance); }); mock.VerifyAll(); }
public void IncompatibleTypeRequestIsNotFullfilled() { var environment = new DeferredEnvironment { { typeof(Foo), () => new Foo() } }; ActiveEnvironment.With(environment, () => { try { My <Bar> .Instance.ToString(); } catch (InvalidOperationException) { return; } Assert.Fail("InvalidOperationException expected"); }); }
public void DefaultGeneratorTypeRepresentationComesFromLanguageAmbience() { var languageAmbianceMock = new Mock <LanguageAmbiance>(); var formatterMock = new Mock <EntityFormatter>(); ActiveEnvironment.With(new ClosedEnvironment(languageAmbianceMock.Object, formatterMock.Object), () => { var type = new Mock <IType>(MockBehavior.Strict).Object; formatterMock.Setup(f => f.FormatType(type)) .Returns("string"); languageAmbianceMock.Setup(ambience => ambience.DefaultGeneratorTypeFor("string")) .Returns("string*") .AtMostOnce(); CompilerErrorFactory.InvalidGeneratorReturnType(new SimpleTypeReference(), type); languageAmbianceMock.VerifyAll(); }); }
private CodeCompileUnit DoParse(params ICompilerInput[] inputs) { DoParseLocals53 DoParseLocals = new DoParseLocals53(); BooCompiler booCompiler = new BooCompiler(); booCompiler.Parameters.Pipeline = new ResolveExpressions(); CompilerPipeline pipeline = booCompiler.Parameters.Pipeline; pipeline.BreakOnErrors = false; // TODO //pipeline.AfterStep += $adaptor$__BooCodeParser$callable2$27_25__$CompilerStepEventHandler$0.Adapt(this.$DoParse$closure$5); pipeline.Replace(typeof(ProcessMethodBodiesWithDuckTyping), new FakeProcessMethodBodies()); booCompiler.Parameters.Input.AddRange(inputs); AppDomain.CurrentDomain.GetAssemblies(); HashSet <string> hashSet = new HashSet <string>(this._references); hashSet.Add("System.Windows.Forms"); hashSet.Add("System.Drawing"); Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); int i = 0; Assembly[] array = assemblies; for (int length = array.Length; i < length; i = checked (i + 1)) { if (RuntimeServices.op_Member(array[i].GetName().Name, hashSet)) { hashSet.Remove(array[i].GetName().Name); booCompiler.Parameters.References.Add(array[i]); } } DoParseLocals.context = booCompiler.Run(); if (DoParseLocals.context.Errors.Count > 0) { throw ((Boo.Lang.List <Boo.Lang.Compiler.CompilerError>)DoParseLocals.context.Errors)[0]; } DoParseLocals.converter = new BooCodeDomConverter(); ActiveEnvironment.With(new InstantiatingEnvironment(), new DoParseClosure6(DoParseLocals).Invoke); return(DoParseLocals.converter.CodeDomUnit); }
internal static bool Prefix(ActiveEnvironment __instance, WeatherStateConfig wsA, WeatherStateConfig wsB, float weatherBlendFrac, TODBlendState todBlendState, float todBlendFrac, float todBlendBiased, bool isIndoors) { // if ((Time.frameCount % 50) == 0) { ColorGradingSettings settings1A = null; ColorGradingSettings settings1B = null; ColorGradingSettings settings2A = null; ColorGradingSettings settings2B = null; Traverse traverseA = Traverse.Create(__instance).Field("m_WorkA"); TODStateConfig m_WorkA = traverseA.GetValue <TODStateConfig>(); Traverse traverseB = Traverse.Create(__instance).Field("m_WorkB"); TODStateConfig m_WorkB = traverseB.GetValue <TODStateConfig>(); TODStateConfig[] wsA_TodStates = { wsA.m_NightColors, wsA.m_DawnColors, wsA.m_MorningColors, wsA.m_MiddayColors, wsA.m_AfternoonColors, wsA.m_DuskColors, wsA.m_NightColors, wsA.m_NightColors }; TODStateConfig[] wsB_TodStates = { wsB.m_NightColors, wsB.m_DawnColors, wsB.m_MorningColors, wsB.m_MiddayColors, wsB.m_AfternoonColors, wsB.m_DuskColors, wsB.m_NightColors, wsA.m_NightColors }; bool flagtoAdd = false; int[] nightstates = { 1, 0, 0, 0, 0, 2, 3 }; float[] keyangles = { Solstice_RV.dawndusk_angle, Solstice_RV.riseset_angle, Solstice_RV.mornaft_angle, Solstice_RV.getSunAngleAtUnitime(Mathf.Floor(Solstice_RV.unitime()) + 0.5f), Solstice_RV.mornaft_angle, Solstice_RV.riseset_angle, Solstice_RV.dawndusk_angle, Solstice_RV.getSunAngleAtUnitime(Mathf.Floor(Solstice_RV.unitime())) }; if (GameManager.GetUniStorm().m_NormalizedTime > 1f) { GameManager.GetUniStorm().SetNormalizedTime(GameManager.GetUniStorm().m_NormalizedTime - 1f); flagtoAdd = true; } todBlendState = GameManager.GetUniStorm().GetTODBlendState(); // Debug.Log(todBlendState); int itod = (int)todBlendState; string debugtext; float zenith = Solstice_RV.getSunAngleAtUnitime(Mathf.Floor(Solstice_RV.unitime()) + 0.5f); float nadir = Solstice_RV.getSunAngleAtUnitime(Mathf.Floor(Solstice_RV.unitime()) + 0.0f); float throughpcntzen; float throughpcntnad; TODStateConfig wsAStartblend; TODStateConfig wsAEndblend; TODStateConfig wsBStartblend; TODStateConfig wsBEndblend; TODStateConfig wsAZenblend; TODStateConfig wsANadblend; TODStateConfig wsBZenblend; TODStateConfig wsBNadblend; wsAStartblend = wsA_TodStates[itod]; wsAEndblend = wsA_TodStates[itod + 1]; wsBStartblend = wsB_TodStates[itod]; wsBEndblend = wsB_TodStates[itod + 1]; String namestartblend = Enum.GetNames(typeof(TODBlendState))[(int)todBlendState]; String nameendblend = Enum.GetNames(typeof(TODBlendState))[((int)todBlendState + 1) % 6]; float st_ang = keyangles[itod]; float en_ang = keyangles[itod + 1]; throughpcntzen = (zenith - st_ang) / (en_ang - st_ang); debugtext = Solstice_RV.gggtime(Solstice_RV.unitime()) + " " + Enum.GetNames(typeof(TODBlendState))[(int)todBlendState]; // do we need a new zen state if (throughpcntzen >= 0 && throughpcntzen <= 1) { if (itod == (int)TODBlendState.MorningToMidday)// need to correct against game zenith of 45 { throughpcntzen = Mathf.Clamp((zenith - st_ang) / (45f - st_ang), 0, 1); } if (itod == (int)TODBlendState.MiddayToAfternoon)// need to correct against game zenith of 45 { throughpcntzen = Mathf.Clamp((zenith - 45f) / (en_ang - 45f), 0, 1); } //debugtext += " mc:" + throughpcntzen; wsAZenblend = Solstice_RV.createNewMidPoint(wsA_TodStates[itod], wsA_TodStates[itod + 1], wsA_TodStates[6 - itod], wsA_TodStates[((5 - itod) % 8 + 8) % 8], throughpcntzen); wsBZenblend = Solstice_RV.createNewMidPoint(wsB_TodStates[itod], wsB_TodStates[itod + 1], wsB_TodStates[6 - itod], wsB_TodStates[((5 - itod) % 8 + 8) % 8], throughpcntzen); if (itod < 3) { en_ang = zenith; nameendblend = "Zen"; wsAEndblend = wsAZenblend; wsBEndblend = wsBZenblend; } else { st_ang = zenith; namestartblend = "Zen"; wsAStartblend = wsAZenblend; wsBStartblend = wsBZenblend; } } throughpcntnad = (nadir - st_ang) / (en_ang - st_ang); if (throughpcntnad >= 0 && throughpcntnad <= 1) { debugtext += " mc:" + throughpcntnad + "[" + itod + "][" + (itod + 1) + "][" + (6 - itod) + "][" + ((5 - itod) % 8 + 8) % 8 + "]"; wsANadblend = Solstice_RV.createNewMidPoint(wsA_TodStates[itod], wsA_TodStates[itod + 1], wsA_TodStates[6 - itod], wsA_TodStates[((5 - itod) % 8 + 8) % 8], throughpcntnad); wsBNadblend = Solstice_RV.createNewMidPoint(wsB_TodStates[itod], wsB_TodStates[itod + 1], wsB_TodStates[6 - itod], wsB_TodStates[((5 - itod) % 8 + 8) % 8], throughpcntnad); if (itod > 3) { en_ang = nadir; nameendblend = "Nad"; wsAEndblend = wsANadblend; wsBEndblend = wsBNadblend; } else { st_ang = nadir; namestartblend = "Nad"; wsAStartblend = wsANadblend; wsBStartblend = wsBNadblend; } } float newtodBlendFrac = (Solstice_RV.getSunAngleAtUnitime(Solstice_RV.unitime()) - st_ang) / (en_ang - st_ang); debugtext += "(" + namestartblend + ":" + nameendblend + ")"; debugtext += " s:" + st_ang + " e:" + en_ang + " c:" + string.Format("{0:0.00}", Solstice_RV.getSunAngleAtUnitime(Solstice_RV.unitime())) + " =:" + string.Format("{0:0.00}", newtodBlendFrac); m_WorkA.SetBlended(wsAStartblend, wsAEndblend, newtodBlendFrac, newtodBlendFrac, nightstates[itod]); m_WorkB.SetBlended(wsBStartblend, wsBEndblend, newtodBlendFrac, newtodBlendFrac, nightstates[itod]); settings1A = wsA_TodStates[(int)todBlendState].m_ColorGradingSettings; settings1B = wsA_TodStates[((int)todBlendState + 1) % 7].m_ColorGradingSettings; settings2A = wsB_TodStates[(int)todBlendState].m_ColorGradingSettings; settings2B = wsB_TodStates[((int)todBlendState + 1) % 7].m_ColorGradingSettings; __instance.m_TodState.SetBlended(m_WorkA, m_WorkB, weatherBlendFrac, weatherBlendFrac, 0); //if ((Time.frameCount % 1600) == 0) Debug.Log(debugtext); if (isIndoors) { __instance.m_TodState.SetIndoors(); } else { UnityEngine.Rendering.PostProcessing.ColorGrading colorGrading = GameManager.GetCameraEffects().ColorGrading(); if (colorGrading != null) { //if ((Time.frameCount % 50) == 0) Debug.Log("[A"+ (int)todBlendState + "][A"+ ((int)todBlendState + 1) % 7 + "[B" + (int)todBlendState + "][B" + ((int)todBlendState + 1) % 7 + "],"+ newtodBlendFrac + ","+ weatherBlendFrac); colorGrading.UpdateLutForTimeOfDay(settings1A, settings1B, settings2A, settings2B, newtodBlendFrac, newtodBlendFrac, weatherBlendFrac); //colorGrading.UpdateLutForTimeOfDay(wsA.m_DawnColors.m_ColorGradingSettings, wsA.m_MorningColors.m_ColorGradingSettings, wsB.m_DawnColors.m_ColorGradingSettings, wsB.m_MorningColors.m_ColorGradingSettings, 0.5f,0.5f, 0.5f); } } __instance.m_GrassTintScalar = Mathf.Lerp(wsA.m_GrassTintScalar, wsB.m_GrassTintScalar, weatherBlendFrac); if (flagtoAdd) { GameManager.GetUniStorm().SetNormalizedTime(GameManager.GetUniStorm().m_NormalizedTime + 1f); } return(false); } }
private void RunInCompilerContextEnvironment(Action action) { ActiveEnvironment.With(new CompilerContext().Environment, () => { action(); }); }
protected void RunInCompilerContextEnvironment(System.Action action) { ActiveEnvironment.With(Environment, () => { action(); }); }