Ejemplo n.º 1
0
 public Invokable(SSInterpretMethodInfo methodInfo, Runner runner, BaseMethodDeclarationSyntax declaration)
 {
     this.Type            = InvokeType.Interpret;
     this.MethodInfo      = methodInfo;
     this.Runner          = runner;
     this.InterpretMethod = declaration;
 }
Ejemplo n.º 2
0
 public void PushMethod(SSInterpretMethodInfo methodInfo)
 {
     Callstack.Push(new CallFrame()
     {
         _this  = _this,
         Method = Method
     });
     Method = methodInfo;
 }
Ejemplo n.º 3
0
        internal void RunStaticInitializerForClass(Class klass)
        {
            if (initializedTypes.Add(klass) == false)
            {
                return;
            }

            SSInterpretMethodInfo methodInfo = null;

            if (staticInitializers.TryGetValue(klass, out methodInfo))
            {
                RunMethod(methodInfo, new HybInstance[] { });
            }
        }
Ejemplo n.º 4
0
        public SSInterpretMethodInfo AddMethod(string id, BaseMethodDeclarationSyntax method, JumpDestination[] jumps)
        {
            EnsureMethodKey(id);

            var signature = MemberSignature.GetSignature(
                Runner.Resolver, id, method);

            var methodInfo = new SSInterpretMethodInfo(Runner, id, Type, method)
            {
                Id             = id,
                IsStatic       = method.Modifiers.IsStatic(),
                DeclaringClass = this,
                Declaration    = method,
                Jumps          = jumps,

                AccessModifier = AccessModifierParser.Parse(method.Modifiers)
            };

            Methods[id].RemoveAll(x => x.Signature == signature);
            Methods[id].Add(methodInfo);

            return(methodInfo);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Runs method with `_this`.
 /// </summary>
 internal HybInstance RunMethod(HybInstance _this, SSInterpretMethodInfo method, HybInstance[] args)
 {
     BindThis(_this);
     return(RunMethod(method, args));
 }
Ejemplo n.º 6
0
        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);
        }