Example #1
0
 /**
  * @brief Constructor
  * @param ifd = dictionary to add the function to
  * @param dcr = append a call to CheckRun()
  * @param methInfo = ll...() method to be called
  */
 public TokenDeclInline_BEApi(VarDict ifd, bool dcr, MethodInfo methInfo, FieldInfo acf)
     : base(ifd, dcr, methInfo)
 {
     this.methInfo   = methInfo;
     doCheckRun      = dcr;
     apiContextField = acf;
 }
Example #2
0
        /**
         * @brief Add API functions from the given interface to list of built-in functions.
         *        Only functions beginning with a lower-case letter are entered, all others ignored.
         * @param ifd = internal function dictionary to add them to
         * @param ifaceMethods = list of API functions
         * @param acf = which field in XMRInstanceSuperType holds method's 'this' pointer
         */
        // this one accepts only names beginning with a lower-case letter
        public static void AddInterfaceMethods(VarDict ifd, MethodInfo[] ifaceMethods, FieldInfo acf)
        {
            List <MethodInfo> lcms = new List <MethodInfo> (ifaceMethods.Length);

            foreach (MethodInfo meth in ifaceMethods)
            {
                string name = meth.Name;
                if ((name[0] >= 'a') && (name[0] <= 'z'))
                {
                    lcms.Add(meth);
                }
            }
            AddInterfaceMethods(ifd, lcms.GetEnumerator(), acf);
        }
Example #3
0
        /**
         * @brief Add an inline function definition to the dictionary.
         * @param ifd        = dictionary to add inline definition to
         * @param doCheckRun = true iff the generated code or the function itself can possibly call CheckRun()
         * @param nameArgSig = inline function signature string, in form <name>(<arglsltypes>,...)
         * @param retType    = return type, use TokenTypeVoid if no return value
         */
        protected TokenDeclInline(VarDict ifd,
                                  bool doCheckRun,
                                  string nameArgSig,
                                  TokenType retType)
            : base(null, null, null)
        {
            this.retType    = retType;
            this.triviality = doCheckRun ? Triviality.complex : Triviality.trivial;

            int j = nameArgSig.IndexOf('(');

            this.name = new TokenName(null, nameArgSig.Substring(0, j++));

            this.argDecl = new TokenArgDecl(null);
            if (nameArgSig[j] != ')')
            {
                int       i;
                TokenName name;
                TokenType type;

                for (i = j; nameArgSig[i] != ')'; i++)
                {
                    if (nameArgSig[i] == ',')
                    {
                        type = TokenType.FromLSLType(null, nameArgSig.Substring(j, i - j));
                        name = new TokenName(null, "arg" + this.argDecl.varDict.Count);
                        this.argDecl.AddArg(type, name);
                        j = i + 1;
                    }
                }

                type = TokenType.FromLSLType(null, nameArgSig.Substring(j, i - j));
                name = new TokenName(null, "arg" + this.argDecl.varDict.Count);
                this.argDecl.AddArg(type, name);
            }

            this.location = new CompValuInline(this);
            if (ifd == null)
            {
                ifd = inlineFunctions;
            }
            ifd.AddEntry(this);
        }
Example #4
0
        /**
         * @brief If this is not a local variable frame, just return the frame as is.
         *        If this is a local variable frame, return a version that is frozen,
         *        ie, one that does not contain any future additions.
         */
        public VarDict FreezeLocals()
        {
            /*
             * If not local var frame, return original frame as is.
             * This will allow forward references as the future additions
             * will be seen by lookups done in this dictionary.
             */
            if (!locals)
            {
                return(this);
            }

            /*
             * If local var frame, return a copy frozen at this point.
             * This disallows forward referenes as those future additions
             * will not be seen by lookups done in the frozen dictionary.
             */
            if ((frozenLocals == null) || (frozenLocals.count != this.count))
            {
                /*
                 * Make a copy of the current var dictionary frame.
                 * We copy a reference to the dictionary, and though it may
                 * contain additions made after this point, those additions
                 * will have a count .gt. frozen count and will be ignored.
                 */
                frozenLocals = new VarDict(true);

                frozenLocals.outerVarDict = this.outerVarDict;
                frozenLocals.thisClass    = this.thisClass;
                frozenLocals.master       = this.master;
                frozenLocals.count        = this.count;
                frozenLocals.frozenLocals = frozenLocals;

                /*
                 * Mark it as being frozen.
                 * - assert fail if any attempt is made to add to it
                 * - ignore any additions to the dictionary with greater count
                 */
                frozenLocals.isFrozen = true;
            }
            return(frozenLocals);
        }
Example #5
0
        protected TokenDeclInline(VarDict ifd,
                                  bool doCheckRun,
                                  MethodInfo methInfo)
            : base(null, null, null)
        {
            TokenType retType = TokenType.FromSysType(null, methInfo.ReturnType);

            this.isTaggedCallsCheckRun = IsTaggedCallsCheckRun(methInfo);
            this.name       = new TokenName(null, methInfo.Name);
            this.retType    = GetRetType(methInfo, retType);
            this.argDecl    = GetArgDecl(methInfo.GetParameters());
            this.triviality = (doCheckRun || this.isTaggedCallsCheckRun) ? Triviality.complex : Triviality.trivial;
            this.location   = new CompValuInline(this);

            if (ifd == null)
            {
                ifd = inlineFunctions;
            }
            ifd.AddEntry(this);
        }
Example #6
0
        // this one accepts all methods given to it
        public static void AddInterfaceMethods(VarDict ifd, IEnumerator <MethodInfo> ifaceMethods, FieldInfo acf)
        {
            if (ifd == null)
            {
                ifd = inlineFunctions;
            }

            for (ifaceMethods.Reset(); ifaceMethods.MoveNext();)
            {
                MethodInfo ifaceMethod = ifaceMethods.Current;
                string     key         = ifaceMethod.Name;

                try {
                    /*
                     * See if we will generate a call to CheckRun() right
                     * after we generate a call to the function.
                     * If function begins with xmr, assume we will not call CheckRun()
                     * Otherwise, assume we will call CheckRun()
                     */
                    bool dcr = !key.StartsWith("xmr");
                    foreach (string ncr in noCheckRuns)
                    {
                        if (ncr == key)
                        {
                            dcr = false;
                            break;
                        }
                    }

                    /*
                     * Add function to dictionary.
                     */
                    new TokenDeclInline_BEApi(ifd, dcr, ifaceMethod, acf);
                } catch {
                    ///??? IGNORE ANY THAT FAIL - LIKE UNRECOGNIZED TYPE ???///
                    ///???                          and OVERLOADED NAMES ???///
                }
            }
        }
Example #7
0
 public TokenDeclInline_GetUsedMemory(VarDict ifd)
     : base(ifd, false, "llGetUsedMemory()", new TokenTypeInt(null))
 {
 }
Example #8
0
 public TokenDeclInline_LLRound(VarDict ifd)
     : base(ifd, false, "llRound(float)", new TokenTypeInt(null))
 {
 }
Example #9
0
 public TokenDeclInline_Math(VarDict ifd, string sig, string name, Type[] args)
     : base(ifd, false, sig, new TokenTypeFloat(null))
 {
     methInfo = ScriptCodeGen.GetStaticMethod(typeof(System.Math), name, args);
 }
Example #10
0
        /**
         * @brief Create a dictionary of inline backend API functions.
         */
        private static VarDict CreateDictionary()
        {
            /*
             * For those listed in noCheckRun, we just generate the call (simple computations).
             * For all others, we generate the call then a call to CheckRun().
             */
            noCheckRuns = new string[] {
                "llBase64ToString",
                "llCSV2List",
                "llDeleteSubList",
                "llDeleteSubString",
                "llDumpList2String",
                "llEscapeURL",
                "llEuler2Rot",
                "llGetListEntryType",
                "llGetListLength",
                "llGetSubString",
                "llGetUnixTime",
                "llInsertString",
                "llList2CSV",
                "llList2Float",
                "llList2Integer",
                "llList2Key",
                "llList2List",
                "llList2ListStrided",
                "llList2Rot",
                "llList2String",
                "llList2Vector",
                "llListFindList",
                "llListInsertList",
                "llListRandomize",
                "llListReplaceList",
                "llListSort",
                "llListStatistics",
                "llMD5String",
                "llParseString2List",
                "llParseStringKeepNulls",
                "llRot2Euler",
                "llStringLength",
                "llStringToBase64",
                "llStringTrim",
                "llSubStringIndex",
                "llUnescapeURL"
            };

            /*
             * These functions really return a 'key' even though we see them as
             * returning 'string' because OpenSim has key and string as same type.
             */
            keyReturns = new string[] {
                "llAvatarOnLinkSitTarget",
                "llAvatarOnSitTarget",
                "llDetectedKey",
                "llDetectedOwner",
                "llGenerateKey",
                "llGetCreator",
                "llGetInventoryCreator",
                "llGetInventoryKey",
                "llGetKey",
                "llGetLandOwnerAt",
                "llGetLinkKey",
                "llGetNotecardLine",
                "llGetNumberOfNotecardLines",
                "llGetOwner",
                "llGetOwnerKey",
                "llGetPermissionsKey",
                "llHTTPRequest",
                "llList2Key",
                "llRequestAgentData",
                "llRequestDisplayName",
                "llRequestInventoryData",
                "llRequestSecureURL",
                "llRequestSimulatorData",
                "llRequestURL",
                "llRequestUsername",
                "llSendRemoteData",
                "llTransferLindenDollars"
            };

            VarDict ifd = new VarDict(false);

            Type[] oneDoub  = new Type[] { typeof(double) };
            Type[] twoDoubs = new Type[] { typeof(double), typeof(double) };

            /*
             * Mono generates an FPU instruction for many math calls.
             */
            new TokenDeclInline_LLAbs(ifd);
            new TokenDeclInline_Math(ifd, "llAcos(float)", "Acos", oneDoub);
            new TokenDeclInline_Math(ifd, "llAsin(float)", "Asin", oneDoub);
            new TokenDeclInline_Math(ifd, "llAtan2(float,float)", "Atan2", twoDoubs);
            new TokenDeclInline_Math(ifd, "llCos(float)", "Cos", oneDoub);
            new TokenDeclInline_Math(ifd, "llFabs(float)", "Abs", oneDoub);
            new TokenDeclInline_Math(ifd, "llLog(float)", "Log", oneDoub);
            new TokenDeclInline_Math(ifd, "llLog10(float)", "Log10", oneDoub);
            new TokenDeclInline_Math(ifd, "llPow(float,float)", "Pow", twoDoubs);
            new TokenDeclInline_LLRound(ifd);
            new TokenDeclInline_Math(ifd, "llSin(float)", "Sin", oneDoub);
            new TokenDeclInline_Math(ifd, "llSqrt(float)", "Sqrt", oneDoub);
            new TokenDeclInline_Math(ifd, "llTan(float)", "Tan", oneDoub);

            /*
             * Something weird about the code generation for these calls, so they all have their own handwritten code generators.
             */
            new TokenDeclInline_GetFreeMemory(ifd);
            new TokenDeclInline_GetUsedMemory(ifd);

            /*
             * These are all the xmr...() calls directly in XMRInstAbstract.
             * Includes the calls from ScriptBaseClass that has all the stubs
             * which convert XMRInstAbstract to the various <NAME>_Api contexts.
             */
            MethodInfo[] absmeths = typeof(XMRInstAbstract).GetMethods();
            AddInterfaceMethods(ifd, absmeths, null);

            return(ifd);
        }
Example #11
0
 public TokenDeclInline_LLAbs(VarDict ifd)
     : base(ifd, false, "llAbs(integer)", new TokenTypeInt(null))
 {
 }