internal unsafe static T RunParserOnString<T,TParser,TUserState>( string str, int index, int length, Microsoft.FSharp.Core.FSharpFunc<TParser,Microsoft.FSharp.Core.FSharpFunc<State<TUserState>,T>> applyParser, TParser parser, TUserState userState, string streamName) { CharStream.Anchor anchor; fixed (char* pStr = str) { var stream = new CharStream(str, pStr, pStr + index, length, 0, &anchor); try { var data = new State<TUserState>.Data{Line = 1, LineBegin = 0, UserState = userState, StreamName = streamName}; var state = new State<TUserState>{data = data}; // state0.Iter = stream.Begin state.Iter.Anchor = &anchor; state.Iter.Ptr = anchor.BufferBegin; // will be null if length is 0 state.Iter.Block = length == 0 ? -1 : 0; var applyParserOpt = applyParser as Microsoft.FSharp.Core.OptimizedClosures.FSharpFunc<TParser, State<TUserState>, T>; if (applyParserOpt != null) return applyParserOpt.Invoke(parser, state); else return applyParser.Invoke(parser).Invoke(state); } finally { // manually dispose stream if (stream.anchor != null) { stream.anchor = null; anchor.StreamHandle.Free(); } } } }
internal static T RunParserOnSubstream<T,TUserState,TSubStreamUserState>( Microsoft.FSharp.Core.FSharpFunc<State<TSubStreamUserState>,T> parser, TSubStreamUserState userState, State<TUserState> stateBeforeSubStream, State<TUserState> stateAfterSubStream) { CharStream stream = stateBeforeSubStream.Iter.Stream; if (stream != stateAfterSubStream.Iter.Stream) throw new ArgumentException("The states are associated with different CharStreams."); int idx0 = stateBeforeSubStream.Iter.Idx; int idx1 = stateAfterSubStream.Iter.Idx; if (idx0 < 0) idx0 = stream.IndexEnd; if (idx1 < 0) idx1 = stream.IndexEnd; if (idx0 > idx1) throw new ArgumentException("The position of the second state lies before the position of the first state."); var subStream = new CharStream(stream.String, idx0, idx1 - idx0, (uint)idx0 + stream.StringToStreamIndexOffset); var data0 = stateBeforeSubStream.data; var data = new State<TSubStreamUserState>.Data{Line = data0.Line, LineBegin = data0.LineBegin, UserState = userState, StreamName = data0.StreamName}; var state = new State<TSubStreamUserState>{data = data}; // state.Iter = subStream.Begin state.Iter.Stream = subStream; state.Iter.Idx = idx0 == idx1 ? Int32.MinValue : idx0; return parser.Invoke(state); }
public static double InvokeFunction(Microsoft.FSharp.Core.FSharpFunc <FSharpList <FScheme.Value>, FScheme.Value> f, double x) { return(((FScheme.Value.Number)f.Invoke(DoubleToFSharpList(x))).Item); }
private void button1_Click(object sender, EventArgs e) { //while (true) { } //MessageBox.Show("hello"); //var eeeoue = Application.InputBox("testoeu", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, 8); try { //var eoue = Application.InputBox("test", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, 8); //throw (new System.Exception("gao")); if (keepOnSimulating) { // stop simulating keepOnSimulating = false; } else { if (stillSimulating) { // finishing last simulation SetText("completing simulation, please wait", StatusLabel); } else { // start simulating iterations = (int)iterationsNumericUpDown.Value; Excel.Range input = Application.ActiveCell; if (input == null) { var inputBox = Application.InputBox("seleziona casella input", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, 8); if (!(inputBox is Excel.Range)) return; input = (Excel.Range)inputBox; } Excel.Range output = null; if (output == null) { var inputBox = Application.InputBox("seleziona range output (almeno 2 colonne)", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, 8); if (!( inputBox is Excel.Range && ((inputBox as Excel.Range).Columns.Count > 1) )) return; output = (Excel.Range)inputBox; } double min = double.NaN; var minstr = minTextBox.Text; //Application.InputBox("Minimum value"); if ("".Equals(minstr.ToString()) || !double.TryParse(minstr.ToString(), out min)) min = double.NaN; double max = double.NaN; var maxstr = maxTextBox.Text; //Application.InputBox("Maxumum value"); if ("".Equals(maxstr.ToString()) || !double.TryParse(maxstr.ToString(), out max)) max = double.NaN; //int iterazioni = 1000000;// Application.InputBox("Numero di iterazioni", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, 8); try { load = Globals.api.SimulateThreaded(input, output, iterations, min, max); System.Threading.Thread t = new System.Threading.Thread(RunSimulation); t.Start(); } catch (Exception ee) { var d = new ErrorDialog(); d.textBox1.Text = ee.Message; d.ShowDialog(); } } } } catch (System.Exception exce) { MessageBox.Show(exce.ToString()); } }
internal unsafe static T RunParserOnSubstream<T,TUserState,TSubStreamUserState>( Microsoft.FSharp.Core.FSharpFunc<State<TSubStreamUserState>,T> parser, TSubStreamUserState userState, State<TUserState> stateBeforeSubStream, State<TUserState> stateAfterSubStream) { CharStream.Anchor subStreamAnchor; var s0 = stateBeforeSubStream; var data0 = s0.data; var data = new State<TSubStreamUserState>.Data{Line = data0.Line, LineBegin = data0.LineBegin, UserState = userState, StreamName = data0.StreamName}; var state = new State<TSubStreamUserState>{data = data}; // the Iter member is assigned below CharStream.Anchor* anchor = s0.Iter.Anchor; var s1 = stateAfterSubStream; if (anchor != s1.Iter.Anchor) throw new ArgumentException("The states are associated with different CharStreams."); if (anchor->LastBlock == 0) { // the CharStream has only one block, so its safe to // construct a new CharStream from a pointer into the original buffer char* ptr = s0.Iter.Ptr; if (ptr == null) ptr = anchor->BufferEnd; char* end = s1.Iter.Ptr; if (end == null) end = anchor->BufferEnd; if (end < ptr) throw new ArgumentException("The position of the second state lies before the position of the first state."); int length = CharStream.PositiveDistance(ptr, end); CharStream stream = (CharStream)anchor->StreamHandle.Target; using (var subStream = new CharStream(stream.BufferString, stream.BufferStringPointer, ptr, length, s0.Index, &subStreamAnchor)) { // state.Iter = subStream.Begin state.Iter.Anchor = &subStreamAnchor; state.Iter.Ptr = subStreamAnchor.BufferBegin; // will be null if length is 0 state.Iter.Block = length == 0 ? -1 : 0; return parser.Invoke(state); } } else if (s0.Iter.Block == s1.Iter.Block && anchor->Block == s1.Iter.Block) { char* ptr = s0.Iter.Ptr; char* end = s1.Iter.Ptr; if (end < ptr) throw new ArgumentException("The position of the second state lies before the position of the first state."); int length = CharStream.PositiveDistance(ptr, end); string subString = new String(ptr, 0, length); fixed (char* pSubString = subString) using (var subStream = new CharStream(subString, pSubString, pSubString, length, s0.Index, &subStreamAnchor)) { // state.Iter = subStream.Begin state.Iter.Anchor = &subStreamAnchor; state.Iter.Ptr = subStreamAnchor.BufferBegin; // will be null if length is 0 state.Iter.Block = length == 0 ? -1 : 0; return parser.Invoke(state); } } else { ulong index1 = (ulong)s0.Iter.Index; ulong index2 = (ulong)s1.Iter.Index; if (index2 < index1) throw new ArgumentException("The position of the second state lies before the position of the first state."); ulong length_ = index2 - index1; // length >= Int32.MaxValue will trigger an exception anyway (because the string is too large) int length = length_ > (uint)System.Int32.MaxValue ? System.Int32.MaxValue : (int)length_; string subString = new String('\u0000', length); fixed (char* pSubString = subString) { s0.Iter.Read(pSubString, length); using (var subStream = new CharStream(subString, pSubString, pSubString, length, s0.Index, &subStreamAnchor)) { // state.Iter = subStream.Begin state.Iter.Anchor = &subStreamAnchor; state.Iter.Ptr = subStreamAnchor.BufferBegin; // will be null if length is 0 state.Iter.Block = length == 0 ? -1 : 0; return parser.Invoke(state); } } } }
/// <summary> /// Helper method for running an Oryx handler in the client context with authentication handling. /// </summary> /// <param name="handler">The handler to run.</param> /// <param name="token">The cancellation token to use.</param> /// <typeparam name="T">The type of the response.</typeparam> /// <returns>Result.</returns> protected async Task <T> RunAsync <T>(Microsoft.FSharp.Core.FSharpFunc <Microsoft.FSharp.Core.FSharpFunc <Oryx.Context <T>, Task <Microsoft.FSharp.Core.FSharpResult <Oryx.Context <T>, Oryx.HandlerError <ResponseException> > > >, Microsoft.FSharp.Core.FSharpFunc <HttpContext, Task <Microsoft.FSharp.Core.FSharpResult <Oryx.Context <T>, Oryx.HandlerError <ResponseException> > > > > handler, CancellationToken token) { var req = _authHandler is null ? handler : withTokenRenewer(_authHandler, handler); return(await runUnsafeAsync(_ctx, token, req).ConfigureAwait(false)); }