示例#1
0
 public void regNativeFunction(NativeFunctionBase nativefunction)
 {
     regNativeFunction(nativefunction, false);
 }
示例#2
0
        public byte[] Serialize(CSWC swc)
        {
            serizlizedObjects.Clear(); stringpool.Clear(); dictSerizlized.Clear();

            //swc._dictlinkcreatorfunctionname.Clear();
            foreach (var item in swc.class_Creator)
            {
                NativeFunctionBase nativeFunctionBase = (NativeFunctionBase)item.Value;

                if (!swc._dictlinkcreatorfunctionname.ContainsKey(nativeFunctionBase.name))
                {
                    swc._dictlinkcreatorfunctionname.Add(nativeFunctionBase.name, item.Key);
                }
                else
                {
                    if (
                        swc._dictlinkcreatorfunctionname[nativeFunctionBase.name] != item.Key)
                    {
                        throw new InvalidOperationException("确认ClassCreator失败:" + nativeFunctionBase.name + "多次对应不同Class");
                    }
                }
            }


            using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
            {
                using (System.IO.BinaryWriter bw = new System.IO.BinaryWriter(ms, System.Text.Encoding.UTF8))
                {
                    bw.Write(swc.classes.Count);
                    for (int i = 0; i < swc.classes.Count; i++)
                    {
                        SerializeObject <rtti.Class>(bw, swc.classes[i]);
                    }

                    bw.Write(swc.functions.Count);
                    for (int i = 0; i < swc.functions.Count; i++)
                    {
                        SerializeObject <rtti.FunctionDefine>(bw, swc.functions[i]);
                    }

                    bw.Write(swc.blocks.Count);
                    for (int i = 0; i < swc.blocks.Count; i++)
                    {
                        SerializeObject <CodeBlock>(bw, swc.blocks[i]);
                    }

                    bw.Write(swc.primitive_to_class_table.Count);
                    for (int i = 0; i < swc.primitive_to_class_table.Count; i++)
                    {
                        SerializeObject <rtti.Class>(bw, swc.primitive_to_class_table[i]);
                    }

                    bw.Write(swc.dict_Vector_type.Count);
                    foreach (var item in swc.dict_Vector_type)
                    {
                        SerializeObject <rtti.Class>(bw, item.Key);
                        bw.Write(item.Value);
                    }

                    bw.Write(swc._dictlinkcreatorfunctionname.Count);
                    foreach (var item in swc._dictlinkcreatorfunctionname)
                    {
                        bw.Write(item.Key);
                        SerializeObject <rtti.Class>(bw, item.Value);
                    }

                    SerializeObject <OperatorFunctions>(bw, swc.operatorOverrides);


                    ///// <summary>
                    ///// 链接到系统Object的类型
                    ///// </summary>
                    //public Class LinkObjectClass;
                    SerializeObject <rtti.Class>(bw, swc.LinkObjectClass);

                    ///// <summary>
                    ///// Class类型
                    ///// </summary>
                    //public Class TypeClass;
                    SerializeObject <rtti.Class>(bw, swc.TypeClass);
                    ///// <summary>
                    ///// Object类
                    ///// </summary>
                    //public Class ObjectClass;
                    SerializeObject <rtti.Class>(bw, swc.ObjectClass);
                    ///// <summary>
                    ///// IEnumerator接口
                    ///// </summary>
                    //public Class IEnumeratorInterface;
                    SerializeObject <rtti.Class>(bw, swc.IEnumeratorInterface);
                    ///// <summary>
                    ///// IEnumerable接口
                    ///// </summary>
                    //public Class IEnumerableInterface;
                    SerializeObject <rtti.Class>(bw, swc.IEnumerableInterface);
                    ///// <summary>
                    ///// yielditerator类
                    ///// </summary>
                    //public Class YieldIteratorClass;
                    SerializeObject <rtti.Class>(bw, swc.YieldIteratorClass);
                    ///// <summary>
                    ///// Function类
                    ///// </summary>
                    //public Class FunctionClass;
                    SerializeObject <rtti.Class>(bw, swc.FunctionClass);
                    ///// <summary>
                    ///// 异常类
                    ///// </summary>
                    //public Class ErrorClass;
                    SerializeObject <rtti.Class>(bw, swc.ErrorClass);
                    ///// <summary>
                    ///// 字典特殊类
                    ///// </summary>
                    //public Class DictionaryClass;
                    SerializeObject <rtti.Class>(bw, swc.DictionaryClass);
                    ///// <summary>
                    ///// 正则类
                    ///// </summary>
                    //public Class RegExpClass;
                    SerializeObject <rtti.Class>(bw, swc.RegExpClass);


                    bw.Write(swc.MaxMemNumberCount);
                    bw.Write(swc.MaxMemIntCount);
                    bw.Write(swc.MaxMemUIntCount);
                    bw.Write(swc.MaxMemBooleanCount);
                    //bw.Write(swc.MaxMemObjectCount);
                }



                serizlizedObjects.Clear(); stringpool.Clear(); dictSerizlized.Clear();
                return(ms.ToArray());
            }
        }