示例#1
0
        private GraceObject mAlloc(GraceObject arg)
        {
            var num = arg.FindNativeParent <GraceNumber>();
            var i   = (int)num.Double;

            return(new FixedSizeArray(i));
        }
示例#2
0
        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);
        }
示例#3
0
        private GraceObject mParse(GraceObject code)
        {
            GraceString gs = code.FindNativeParent <GraceString>();
            string      s  = gs.Value;
            var         p  = new Parser(s);

            return(new GraceObjectProxy(p.Parse()));
        }
示例#4
0
        private GraceObject mSleep(GraceObject arg)
        {
            var n = arg.FindNativeParent <GraceNumber>();

            if (n == null)
            {
                return(GraceObject.Done);
            }
            Thread.Sleep((int)(n.Double));
            return(GraceObject.Done);
        }
示例#5
0
        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()));
            }
        }
示例#6
0
        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);
            }
        }
示例#7
0
        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);
        }