private GraceObject mAlloc(GraceObject arg) { var num = arg.FindNativeParent <GraceNumber>(); var i = (int)num.Double; return(new FixedSizeArray(i)); }
private GraceObject mYieldFor(EvaluationContext ctx, GraceObject arg) { var n = arg.FindNativeParent <GraceNumber>(); if (n == null) { return(GraceObject.Done); } var sw = System.Diagnostics.Stopwatch.StartNew(); GraceObject block; object[] args; var ms = (int)(n.Double); while (sw.ElapsedMilliseconds < ms) { var delay = (int)(ms - sw.ElapsedMilliseconds); if (delay < 0) { delay = 0; } if (sink.AwaitRemoteCallback(delay, out block, out args)) { processCallback(ctx, block, args); } } return(GraceObject.Done); }
private GraceObject mParse(GraceObject code) { GraceString gs = code.FindNativeParent <GraceString>(); string s = gs.Value; var p = new Parser(s); return(new GraceObjectProxy(p.Parse())); }
private GraceObject mSleep(GraceObject arg) { var n = arg.FindNativeParent <GraceNumber>(); if (n == null) { return(GraceObject.Done); } Thread.Sleep((int)(n.Double)); return(GraceObject.Done); }
private GraceObject mParseFile(GraceObject code) { GraceString gs = code.FindNativeParent <GraceString>(); string path = gs.Value; using (StreamReader reader = File.OpenText(path)) { var p = new Parser(reader.ReadToEnd()); return(new GraceObjectProxy(p.Parse())); } }
private GraceObject mTranslateFile(GraceObject code) { GraceString gs = code.FindNativeParent <GraceString>(); string path = gs.Value; using (StreamReader reader = File.OpenText(path)) { var p = new Parser(reader.ReadToEnd()); var module = p.Parse(); ExecutionTreeTranslator ett = new ExecutionTreeTranslator(); Node eModule = ett.Translate(module as ObjectParseNode); return(eModule); } }
private GraceObject mAt(EvaluationContext ctx, GraceObject index) { var num = index.FindNativeParent <GraceNumber>(); var i = (int)num.Double; checkIndex(ctx, i, data); var ret = data[i]; if (ret == null) { ErrorReporting.RaiseError(ctx, "R2008", new Dictionary <string, string> { { "name", "index " + i }, { "receiver", ToString() } }, "UninitialisedReadError: Cannot read from index " + i ); } return(ret); }