Exemplo n.º 1
0
        private P5Exception FixupException(P5Exception e)
        {
            // TODO required until Language::P::Exception can be derived
            //      from P5Exception
            if (e.Reference != null)
            {
                var stash = e.Reference.BlessedReferenceStash(parser_runtime);
                var l_p_e = parser_runtime.SymbolTable.GetPackage(parser_runtime, "Language::P::Exception", false);

                if (stash.IsDerivedFrom(parser_runtime, l_p_e))
                {
                    P5Array arglist_format_message =
                        new P5Array(parser_runtime,
                                    e.Reference);
                    var msg = arglist_format_message.CallMethod(parser_runtime, Opcode.ContextValues.SCALAR, "format_message");

                    return new P5Exception(parser_runtime, msg.AsString(parser_runtime));
                }
            }

            return e;
        }
Exemplo n.º 2
0
        public virtual P5Code FindMethod(Runtime runtime, string method,
                                         out P5Exception error)
        {
            var refbody = body as P5Reference;
            int colon = method.LastIndexOf("::");
            bool is_super = false;
            P5SymbolTable stash;
            string stash_name;

            error = null;

            if (colon != -1)
            {
                is_super = method.StartsWith("SUPER::");

                if (is_super)
                {
                    stash_name = runtime.Package;
                    stash = runtime.SymbolTable.GetPackage(runtime, runtime.Package);
                }
                else
                {
                    stash_name = method;
                    stash = runtime.SymbolTable.GetPackage(runtime, method, true, false);
                }

                method = method.Substring(colon + 2);
            }
            else if (refbody != null)
            {
                stash = refbody.Referred.Blessed(runtime);
                if (stash == null)
                {
                    error = new P5Exception(runtime, string.Format("Can't call method \"{0:S}\" on unblessed reference", method));

                    return null;
                }
                stash_name = stash.GetName(runtime);
            }
            else
            {
                stash_name = AsString(runtime);
                stash = runtime.SymbolTable.GetPackage(runtime, stash_name, false);
            }

            P5Code res = null;
            if (stash != null)
                res = stash.FindMethod(runtime, method, is_super);

            if (res == null && stash != null)
                error = new P5Exception(runtime, string.Format("Can't locate object method \"{0:S}\" via package \"{1:S}\"", method, stash_name));
            else if (res == null && stash == null)
                error = new P5Exception(runtime, string.Format("Can't locate object method \"{0:S}\" via package \"{1:S}\" (perhaps you forgot to load \"{1:S}\"?)", method, stash_name));

            return res;
        }
Exemplo n.º 3
0
        public void SetException(P5Exception e)
        {
            P5Scalar s = e.Reference;

            if (s == null)
                s = new P5Scalar(this, e.Message);

            SymbolTable.GetStashScalar(this, "@", true).Assign(this, s);
        }