コード例 #1
0
        private void RunForEach(ForEachStatementSyntax node)
        {
            var list = RunExpression(node.Expression);
            var e    = list.GetEnumerator();

            Vars = new VarFrame(Vars);
            while (true)
            {
                if (e.MoveNext() == false)
                {
                    break;
                }

                Vars.SetValue($"{node.Identifier}", e.Current.Wrap());

                Run(node.Statement);

                if (Halt == HaltType.Continue ||
                    Halt == HaltType.YieldReturn)
                {
                    Halt = HaltType.None;
                }
                if (Halt != HaltType.None)
                {
                    break;
                }
            }
            Vars = Vars.Parent;

            if (Halt == HaltType.Break)
            {
                Halt = HaltType.None;
            }
        }
コード例 #2
0
ファイル: Runner.Lambda.cs プロジェクト: ru-ace/SlowSharp
        private void ActionBody(SeparatedSyntaxList <ParameterSyntax> ps, BlockSyntax body, params object[] args)
        {
            var vf = new VarFrame(Vars);

            for (int i = 0; i < ps.Count; i++)
            {
                vf.SetValue($"{ps[i].Identifier}", HybInstance.Object(args[i]));
            }
            RunBlock(body as BlockSyntax, vf);
            if (Halt == HaltType.Return)
            {
                Halt = HaltType.None;
            }
        }
コード例 #3
0
ファイル: CatchFrame.cs プロジェクト: ru-ace/SlowSharp
        public bool RunCatch(Exception e)
        {
            foreach (var c in TryNode.Catches)
            {
                var type = $"{c.Declaration.Type}";
                var rt   = Runner.Resolver.GetType(type);

                if (rt == null)
                {
                    continue;
                }
                if (e.GetType().IsSubclassOf(rt))
                {
                    var vf = new VarFrame(Runner.Vars);
                    vf.SetValue($"{c.Declaration.Identifier}", HybInstance.Object(e));
                    Runner.RunBlock(c.Block, vf);
                    return(true);
                }
            }

            return(false);
        }
コード例 #4
0
ファイル: Runner.cs プロジェクト: forestrf/SlowSharp
        internal HybInstance RunMethod(SSInterpretMethodInfo method, HybInstance[] args)
        {
            Ret = null;
            Ctx.PushMethod(method);

            var node  = ((SSInterpretMethodInfo)method).Declaration;
            var vf    = new VarFrame(null);
            var count = 0;

            foreach (var p in method.Parameters)
            {
                if (p.DefaultValue == null)
                {
                    continue;
                }
                vf.SetValue(p.Id, p.DefaultValue);
            }
            foreach (var arg in args)
            {
                var p = method.Parameters[count++];
                if (p.IsParams)
                {
                    break;
                }

                vf.SetValue(p.Id, arg);
            }

            if (method.IsVaArg)
            {
                var paramId = node.ParameterList.Parameters.Last()
                              .Identifier.Text;

                var vaArgs = args.Skip(count - 1).ToArray();
                vf.SetValue(paramId, HybInstance.ObjectArray(vaArgs));
            }

            Frames.Push(Vars);
            Vars = null;

            if (node.Body != null)
            {
                if (method.ReturnType != null && // ctor doesn't have return type
                    method.ReturnType.IsCompiledType &&
                    method.ReturnType.CompiledType == typeof(IEnumerator))
                {
                    var enumerator = new SSEnumerator(this, node.Body, vf);
                    Ret = HybInstance.Object(enumerator);
                }
                else
                {
                    RunBlock(node.Body, vf);
                }
            }
            else
            {
                Ret = RunArrowExpressionClause(node.ExpressionBody, vf);
            }

            Vars = Frames.Pop();

            if (Halt == HaltType.Return)
            {
                Halt = HaltType.None;
            }

            Ctx.PopMethod();

            return(Ret);
        }