コード例 #1
0
ファイル: dna.cs プロジェクト: bmjoy/dnaunity
        /// <summary>
        /// Resets entire DNA environment to it's initial state, clearing all DnaObject references to null.
        /// </summary>
        public static void Reset()
        {
            Type.Clear();
            CLIFile.Clear();
            InternalCall.Clear();
            Finalizer.Clear();
            Heap.Clear();
            Generics.Clear();
            MonoType.Clear();
            MetaData.Clear();
            DnaObject.Clear();
            JIT_Execute.Clear();
            JIT.Clear();
            Sys.Clear();
            H.Clear();
            Mem.Clear();

            _isInitialized = false;
        }
コード例 #2
0
        /// <summary>
        /// Initializes the DNA script engine.
        /// </summary>
        /// <param name="memsize">The heap memory size to use (note: can not be expanded)</param>
        /// <param name="assemblySearchPaths">Array of assembly search paths to use when loading assemblies</param>
        public static void Init(int memsize = DEFAULT_MEM_SIZE, string[] assemblySearchPaths = null)
        {
            if (_isInitialized)
            {
                throw new System.InvalidOperationException("Dna has already been initialized.  Use Dna.Reset() to reset the interpreter");
            }

            if (assemblySearchPaths == null)
            {
                assemblySearchPaths = defaultAssemblySearchPaths;
            }
            #if UNITY_EDITOR
            string[] finalAssemblySearchPaths = new string[assemblySearchPaths.Length];
            string   unityDir   = UnityEditor.EditorApplication.applicationContentsPath;
            string   projectDir = System.IO.Path.GetDirectoryName(UnityEngine.Application.dataPath);
            for (int i = 0; i < assemblySearchPaths.Length; i++)
            {
                finalAssemblySearchPaths[i] = assemblySearchPaths[i]
                                              .Replace("${UNITY_DIR}", unityDir)
                                              .Replace("${PROJECT_DIR}", projectDir);
            }
            #else
            string[] finalAssemblySearchPaths = assemblySearchPaths;
            #endif

            Mem.Init(memsize);
            H.Init();
            Sys.Init();
            JIT.Init();
            JIT_Execute.Init();
            DnaObject.Init();
            MetaData.Init();
            MonoType.Init();
            Generics.Init();
            Serialization.Init();
            Heap.Init();
            Finalizer.Init();
            InternalCall.Init();
            CLIFile.Init(finalAssemblySearchPaths);
            Type.Init();

            _isInitialized = true;
        }
コード例 #3
0
ファイル: MetaData_Search.cs プロジェクト: bmjoy/dnaunity
        public static tMD_MethodDef *GetMethodDefFromDefRefOrSpec(tMetaData *pMetaData, /*IDX_TABLE*/ uint token,
                                                                  tMD_TypeDef **ppClassTypeArgs, tMD_TypeDef **ppMethodTypeArgs)
        {
            void *pTableEntry;

            pTableEntry = MetaData.GetTableRow(pMetaData, token);
            if (((tMDC_ToMethodDef *)pTableEntry)->pMethodDef != null)
            {
                return(((tMDC_ToMethodDef *)pTableEntry)->pMethodDef);
            }

            switch (MetaData.TABLE_ID(token))
            {
            case MetaDataTable.MD_TABLE_METHODDEF:
                ((tMDC_ToMethodDef *)pTableEntry)->pMethodDef = (tMD_MethodDef *)pTableEntry;
                return((tMD_MethodDef *)pTableEntry);

            case MetaDataTable.MD_TABLE_MEMBERREF:
            {
                tMD_MemberRef *pMemberRef;

                pMemberRef = (tMD_MemberRef *)pTableEntry;
                switch (MetaData.TABLE_ID(pMemberRef->class_))
                {
                case MetaDataTable.MD_TABLE_TYPEREF:
                case MetaDataTable.MD_TABLE_TYPESPEC:
                {
                    tMD_TypeDef *  pTypeDef;
                    tMD_MethodDef *pMethodDef;

                    pTypeDef = MetaData.GetTypeDefFromDefRefOrSpec(pMetaData, pMemberRef->class_, ppClassTypeArgs, ppMethodTypeArgs);
                    MetaData.Fill_TypeDef(pTypeDef, null, null);
                    pMethodDef = FindMethodInType(pTypeDef, pMemberRef->name, pMetaData, pMemberRef->signature, pTypeDef->ppClassTypeArgs, ppMethodTypeArgs);
                    //pMethodDef->pMethodDef = pMethodDef;
                    return(pMethodDef);
                }

                default:
                    Sys.Crash("MetaData.GetMethodDefFromMethodDefOrRef(): Cannot handle pMemberRef->class_=0x%08x", pMemberRef->class_);
                    return(null);
                }
            }

            case MetaDataTable.MD_TABLE_METHODSPEC:
            {
                tMD_MethodSpec *pMethodSpec;
                tMD_MethodDef * pMethodDef;

                pMethodSpec = (tMD_MethodSpec *)pTableEntry;
                pMethodDef  = Generics.GetMethodDefFromSpec(pMethodSpec, ppClassTypeArgs, ppMethodTypeArgs);

                // Note: Cannot cache the MethodDef from the MethodSpec, as class generic arguments
                // may be different.

                return(pMethodDef);
            }
            }

            Sys.Crash("MetaData.GetMethodDefFromMethodDefOrRef(): Cannot handle token: 0x%08x", token);
            return(null);
        }