static JS() { const string csJScriptSource = @"package _{ class _{ static function __(e) : Object { return eval(e); }}}"; var loParameters = new CompilerParameters() { GenerateInMemory = true }; var loMethod = (new JScriptCodeProvider()).CompileAssemblyFromSource(loParameters, csJScriptSource).CompiledAssembly.GetType("_._").GetMethod("__"); moEvalDelegate = (EvalDelegate)Delegate.CreateDelegate(typeof(EvalDelegate), loMethod); }
public void Generate() { foreach (var channel in channels) { GenerateFor(channel); } ilGenerator.Emit(OpCodes.Ret); this.evalDelegate = (EvalDelegate)dynamicMethod.CreateDelegate(typeof(EvalDelegate)); }
internal NestedWrapper(_Codeblock[] nested_cbs, EvalDelegate eval_func) { nested_cbs_ = nested_cbs; eval_func_ = eval_func; }
public RxInterpreterFactory(byte[] program, EvalDelegate eval_del) { this.program = program; this.eval_del = eval_del; }
public RxInterpreterFactory (byte[] program, EvalDelegate eval_del) { this.program = program; this.eval_del = eval_del; }
protected void UpdateBitmap() { if (m_Bitmap == null) { return; } using (Graphics G = Graphics.FromImage(m_Bitmap)) { G.FillRectangle(Brushes.White, 0, 0, Width, Height); if (m_Phase == null) { return; } switch (m_Type) { case DISPLAY_TYPE.LOG: { G.DrawLine(Pens.Black, 10, 0, 10, Height); G.DrawLine(Pens.Black, 0, Height - 10, Width, Height - 10); double LogPhaseMin = Math.Floor(Math.Log10(m_PhaseMin)); double LogPhaseMax = Math.Ceiling(Math.Log10(m_PhaseMax)); EvalDelegate Eval = ( float _x ) => { int AngleIndex = (int)((m_Phase.Length - 1) * _x); double Num = Math.Log10(m_Phase[AngleIndex]) - LogPhaseMin; double Den = LogPhaseMax - LogPhaseMin; double P = Num / Den; return((float)P); }; float px = 0.0f; float py = Eval(0.0f); for (int X = 10; X <= Width; X++) { float x = (float)(X - 10.0f) / (Width - 10); float y = Eval(x); DrawLine(G, px, py, x, y, Pens.Black); px = x; py = y; } } break; case DISPLAY_TYPE.POLAR: { G.DrawLine(Pens.Black, 0, Height / 2, Width, Height / 2); G.DrawLine(Pens.Black, Width / 2, 0, Width / 2, Height); double LogPhaseMin = Math.Floor(Math.Log10(m_PhaseMin)); double LogPhaseMax = Math.Ceiling(Math.Log10(m_PhaseMax)); EvalDelegate Eval = ( float _x ) => { int AngleIndex = (int)((m_Phase.Length - 1) * _x / Math.PI); double Num = Math.Log10(m_Phase[AngleIndex]) - LogPhaseMin; double Den = LogPhaseMax - LogPhaseMin; double P = Num / Den; return((float)P); }; for (int i = 0; i < 1800; i++) { float Angle0 = (float)(Math.PI * i / 1800.0f); float Angle1 = (float)(Math.PI * (i + 1) / 1800.0f); float P0 = 0.5f * Width * Eval(Angle0); float P1 = 0.5f * Width * Eval(Angle1); float C0 = (float)Math.Cos(Angle0); float C1 = (float)Math.Cos(Angle1); float S0 = (float)Math.Sin(Angle0); float S1 = (float)Math.Sin(Angle1); G.DrawLine(Pens.Black, 0.5f * Width + P0 * C0, 0.5f * Height + P0 * S0, 0.5f * Width + P1 * C1, 0.5f * Height + P1 * S1); G.DrawLine(Pens.Black, 0.5f * Width + P0 * C0, 0.5f * Height - P0 * S0, 0.5f * Width + P1 * C1, 0.5f * Height - P1 * S1); } } break; case DISPLAY_TYPE.QUANTILES_PEAK: case DISPLAY_TYPE.QUANTILES_OFF_PEAK: { G.DrawLine(Pens.Black, 10, 0, 10, Height); G.DrawLine(Pens.Black, 0, Height - 10, Width, Height - 10); QuantileInfos Infos; EvalDelegate Eval = null; if (m_Type == DISPLAY_TYPE.QUANTILES_PEAK) { Eval = ( float _x ) => { int QuantileIndex = (int)((m_PhaseQuantilesPeak.Length - 1) * _x); float R = m_PhaseQuantilesPeak[QuantileIndex] / (m_PhaseInfosPeak.m_AngleEnd * (float)Math.PI / 180.0f); return(R); }; Infos = m_PhaseInfosPeak; } else { Eval = ( float _x ) => { int QuantileIndex = (int)((m_PhaseQuantilesOffPeak.Length - 1) * _x); float R = m_PhaseQuantilesOffPeak[QuantileIndex] / (float)Math.PI; return(R); }; Infos = m_PhaseInfosOffPeak; } float px = 0.0f; float py = Eval(0.0f); for (int X = 10; X <= Width; X++) { float x = (float)(X - 10.0f) / (Width - 10); float y = Eval(x); DrawLine(G, px, py, x, y, Pens.Black); px = x; py = y; } // Draw some info G.DrawString("Angle Start = " + Infos.m_AngleStart + "°", Font, Brushes.Black, 20, 20 * 1); G.DrawString("Angle End = " + Infos.m_AngleEnd + "°", Font, Brushes.Black, 20, 20 * 2); G.DrawString("Total Phase = " + Infos.m_SumPhaseTotal, Font, Brushes.Black, 20, 20 * 3); G.DrawString("Sum Phase = " + Infos.m_SumPhase + " (" + (100.0 * Infos.m_SumPhase / Infos.m_SumPhaseTotal).ToString("G6") + "%)", Font, Brushes.Black, 20, 20 * 4); } break; case DISPLAY_TYPE.SCATTERING_SIMULATION: { G.DrawLine(Pens.Black, 0, Height / 2, Width, Height / 2); G.DrawLine(Pens.Black, Width / 2, 0, Width / 2, Height); // Shoot random numbers and stack them according to phase tables int[] Accum = new int[1080]; Random RNG = new Random(); float PeakLimit = m_PhaseInfosPeak.m_SumPhase / m_PhaseInfosPeak.m_SumPhaseTotal; float NormPeak = 1.0f / PeakLimit; float NormOffPeak = 1.0f / (1.0f - PeakLimit); int PeakArraySize = m_PhaseQuantilesPeak.Length; int OffPeakArraySize = m_PhaseQuantilesOffPeak.Length; int MinAccum = 100000000; int MaxAccum = 0; for (int i = 0; i < 10000000; i++) { float R = (float)RNG.NextDouble(); float Angle; if (R < PeakLimit) { // Peak draw int QuantileIndex = (int)Math.Floor(R * NormPeak * PeakArraySize); Angle = m_PhaseQuantilesPeak[Math.Min(PeakArraySize - 1, QuantileIndex)]; } else { // Off-peak draw int QuantileIndex = (int)Math.Floor((R - PeakLimit) * NormOffPeak * OffPeakArraySize); Angle = m_PhaseQuantilesOffPeak[Math.Min(OffPeakArraySize - 1, QuantileIndex)]; } int nAngle = (int)Math.Floor((Angle * 1080) / Math.PI); Accum[nAngle]++; MinAccum = Math.Min(MinAccum, Accum[nAngle]); MaxAccum = Math.Max(MaxAccum, Accum[nAngle]); } float Normalizer = 1.0f / MaxAccum; double LogPhaseMin = Math.Floor(Math.Log10(Math.Max(1, MinAccum))); double LogPhaseMax = Math.Ceiling(Math.Log10(MaxAccum)); EvalDelegate Eval = ( float _x ) => { int AngleIndex = (int)Math.Min(1079, 1080 * _x / Math.PI); // float P = Accum[AngleIndex] * Normalizer; // float P = (float) (Math.Log10( Math.Max( 1, Accum[AngleIndex] ) ) / Math.Log10( MaxAccum )); // return P; double Num = Math.Log10(Math.Max(1, Accum[AngleIndex])) - LogPhaseMin; double Den = LogPhaseMax - LogPhaseMin; double P = Num / Den; return((float)P); }; for (int i = 0; i < 1800; i++) { float Angle0 = (float)(Math.PI * i / 1800.0f); float Angle1 = (float)(Math.PI * (i + 1) / 1800.0f); float P0 = 0.5f * Width * Eval(Angle0); float P1 = 0.5f * Width * Eval(Angle1); float C0 = (float)Math.Cos(Angle0); float C1 = (float)Math.Cos(Angle1); float S0 = (float)Math.Sin(Angle0); float S1 = (float)Math.Sin(Angle1); G.DrawLine(Pens.Black, 0.5f * Width + P0 * C0, 0.5f * Height + P0 * S0, 0.5f * Width + P1 * C1, 0.5f * Height + P1 * S1); G.DrawLine(Pens.Black, 0.5f * Width + P0 * C0, 0.5f * Height - P0 * S0, 0.5f * Width + P1 * C1, 0.5f * Height - P1 * S1); } } break; } } Invalidate(); }