public string GetCustomClassFunctionCode(string typeName, string functionName, CodeMode codeMode) { if (codeMode == CodeMode.Decode) { string decodeMethod = string.Empty; if (CodeGenConstants.exportMode == ExportMode.HelperClass) { decodeMethod = "value = " + CodeGenConstants.SerializeHelperClass + typeName + "Decode(bb);"; } else if (CodeGenConstants.exportMode == ExportMode.SelfClass) { decodeMethod = "value.Decode(bb);"; } return(string.Format(GetProtocolVoStatementFormat, functionName, typeName, decodeMethod)); } else if (codeMode == CodeMode.Encode) { string encodeMethod = string.Empty; if (CodeGenConstants.exportMode == ExportMode.HelperClass) { encodeMethod = CodeGenConstants.SerializeHelperClass + typeName + "Encode(bb,value);"; } else if (CodeGenConstants.exportMode == ExportMode.SelfClass) { encodeMethod = "value.Encode(bb);"; } return(string.Format(PutProtocolVoStatementFormat, functionName, typeName, encodeMethod)); } return(string.Empty); }
private void Awake() { #if ENABLE_IL2CPP this.CodeMode = CodeMode.ILRuntime; #endif System.AppDomain.CurrentDomain.UnhandledException += (sender, e) => { Log.Error(e.ExceptionObject.ToString()); }; SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance); DontDestroyOnLoad(gameObject); LitJson.UnityTypeBindings.Register(); ETTask.ExceptionHandler += Log.Error; Log.ILog = new UnityLogger(); Options.Instance = new Options(); CodeLoader.Instance.CodeMode = this.CodeMode; }
//驻留在内存中,直到RemoveModule private VAL Execute(string src, CodeType ty, CodeMode overwritten) { Module module = Library.CompileModule(ref moduleName, moduleSize, scope, src, ty, overwritten); if (module != null) { return(Computer.Run(module, context)); } return(VAL.VOID); }
public string GetCodeModeName(CodeMode codeMode) { if (codeMode == CodeMode.Decode) { return("Get"); } else if (codeMode == CodeMode.Encode) { return("Put"); } return(string.Empty); }
public string GetListFunctionCode(string typeName, string functionName, CodeMode codeMode, string nestFunctionName) { if (codeMode == CodeMode.Decode) { return(string.Format(GetListFunctionFormat, functionName, typeName, nestFunctionName)); } else if (codeMode == CodeMode.Encode) { return(string.Format(PutListFunctionFormat, functionName, typeName, nestFunctionName)); } return(string.Empty); }
public string GetCustomClassFunctionCode(string typeName, string functionName, CodeMode codeMode) { if (codeMode == CodeMode.Decode) { return(string.Format(GetProtocolVoStatementFormat, functionName, typeName)); } else if (codeMode == CodeMode.Encode) { return(string.Format(PutProtocolVoStatementFormat, functionName, typeName)); } return(string.Empty); }
public string GetDictionaryFunctionCode(string typeName, string functionName, CodeMode codeMode, string nestFunctionName1, string nestFunctionName2) { if (codeMode == CodeMode.Decode) { return(string.Format(GetDictionaryFunctionFormat, functionName, typeName, nestFunctionName1, nestFunctionName2)); } else if (codeMode == CodeMode.Encode) { int index = typeName.IndexOf(CodeGenConstants.ComplexType[2]); string keyValuePairType = typeName.Remove(index, CodeGenConstants.ComplexType[2].Length).Insert(index, "KeyValuePair"); return(string.Format(PutDictionaryFunctionFormat, functionName, typeName, keyValuePairType, nestFunctionName1, nestFunctionName2)); } return(string.Empty); }
public string GetArrayFunctionCode(string typeName, string functionName, CodeMode codeMode, string nestFunctionName) { if (codeMode == CodeMode.Decode) { int firstLeftBracketIndex = typeName.IndexOf("["); string newArrayType = typeName.Insert(firstLeftBracketIndex + 1, "length"); return(string.Format(GetArrayFunctionFormat, functionName, typeName, newArrayType, nestFunctionName)); } else if (codeMode == CodeMode.Encode) { return(string.Format(PutArrayFunctionFormat, functionName, typeName, nestFunctionName)); } return(string.Empty); }
//函数调用语句 public static string GetFunctionStatement(Language language, CodeMode codeMode, string type, string fieldName, bool isStatement = false) { List <object> nestArray = TypeName2NestArray(type); string code = string.Empty; object element = nestArray[0]; string functionName = NestArray2FunctionName(language, nestArray, codeMode); if (element is string) { string prefixType = element as string; string typeForGetArrayDemision = type; int array = GetArraySuffix(ref prefixType); if (array == 0) { array = GetArraySuffix(ref typeForGetArrayDemision); } if (Array.IndexOf(CodeGenConstants.BaseType, prefixType) != -1 && array == 0) { if (CodeMode.Encode == codeMode) { code = "bb." + functionName + "(" + fieldName + ")"; } else if (CodeMode.Decode == codeMode) { code = "bb." + functionName + "()"; } } else { if (CodeMode.Encode == codeMode) { code = CodeGenConstants.SerializeHelperClass + functionName + "(bb," + fieldName + ")"; } else if (CodeMode.Decode == codeMode) { code = CodeGenConstants.SerializeHelperClass + functionName + "(bb)"; } } } if (isStatement) { if (CodeMode.Decode == codeMode) { code = fieldName + " = " + code; } code += ";"; } return(code); }
//复杂类型函数导出 public static string GenerateFunctionCode(Language language, string type, CodeMode codeMode) { List <object> nestArray = TypeName2NestArray(type); string code = string.Empty; object element = nestArray[0]; string functionName = NestArray2FunctionName(language, nestArray, codeMode); if (element is string) { string prefixType = element as string; string typeForGetArrayDemision = type; int array = GetArraySuffix(ref prefixType); if (array == 0) { array = GetArraySuffix(ref typeForGetArrayDemision); } if (array > 0) //Array { string nestStatement = GetFunctionStatement(language, codeMode, GetArrayElementTypeName(type), "value[i]"); return(BufferCodeExporter.GetArrayFunctionCode(language, type, functionName, codeMode, nestStatement)); } else if (prefixType == CodeGenConstants.ComplexType[1])//List { string nestStatement = GetFunctionStatement(language, codeMode, GetListGenericTypeName(type), "value[i]"); return(BufferCodeExporter.GetListFunctionCode(language, type, functionName, codeMode, nestStatement)); } else if (prefixType == CodeGenConstants.ComplexType[2])//Dictionary { string[] genericTypes = GetDictionaryGenericTypeName(type); string nestStatement1 = GetFunctionStatement(language, codeMode, genericTypes[0], "kv.Key"); string nestStatement2 = GetFunctionStatement(language, codeMode, genericTypes[1], "kv.Value"); return(BufferCodeExporter.GetDictionaryFunctionCode(language, type, functionName, codeMode, nestStatement1, nestStatement2)); } else if (Array.IndexOf(CodeGenConstants.BaseType, prefixType) == -1) //custom class { return(BufferCodeExporter.GetCustomClassFunctionCode(language, type, functionName, codeMode)); } } return(code); }
public bool CompileCodeBlock(string scope, string codePiece, CodeType ty, CodeMode codeMode) { //SourceCode line# may be messy if !overwritten, becuase codePiece merged, this.pos = new Position(moduleName, codePiece); this.error = new Error(pos); if (blocks.Count == 0) { codeMode = CodeMode.Overwritten; } if (codeMode == CodeMode.Append) { if (blocks.Count + 1 > Constant.MAX_CODEBLOCK_NUM) { throw new CompilingException("CodeBlock number reaches maximum limitation.", Position.UNKNOWN); } IP1 = IP2; } this.pos.block = (byte)blocks.Count; blocks.Add(new CodeBlock(IP1, codePiece)); JParser parser = new JParser(scope, codePiece, CodeSource.STRING, this); if (!parser.IsBlank) { IP2 = parser.Compile(ty) + 1; } pos.ModuleName = moduleName; return(!parser.IsBlank); }
public static string GetDictionaryFunctionCode(Language language, string typeName, string functionName, CodeMode codeMode, string nestFunctionName1, string nestFunctionName2) { return(GetCodeExporter(language).GetDictionaryFunctionCode(typeName, functionName, codeMode, nestFunctionName1, nestFunctionName2)); }
public string GetByteBufferCode(string typeName, CodeMode codeMode) { return(typeName.UppercaseFirst()); }
public static string GetCodeModeName(Language language, CodeMode codeMode) { return(GetCodeExporter(language).GetCodeModeName(codeMode)); }
/// <summary> /// Encode the specified string . /// </summary> /// <param name="valueStr"> content string.</param> public int Encode(string valueStr, CodeMode eCodeFormat) { // var writer = new QRCodeWriter(); var writer = new MultiFormatWriter(); Dictionary <EncodeHintType, object> hints = new Dictionary <EncodeHintType, object>(); //set the code type hints.Add(EncodeHintType.CHARACTER_SET, "UTF-8"); hints.Add(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); switch (eCodeFormat) { case CodeMode.QR_CODE: byteMatrix = writer.encode(valueStr, BarcodeFormat.QR_CODE, e_QRCodeWidth, e_QRCodeHeight, hints); break; case CodeMode.EAN_13: if ((valueStr.Length == 12 || valueStr.Length == 13) && bAllDigit(valueStr)) { if (valueStr.Length == 13) { valueStr = valueStr.Substring(0, 12); } byteMatrix = writer.encode(valueStr, BarcodeFormat.EAN_13, e_QRCodeWidth, e_QRCodeWidth / 2, hints); } else { return(-13); } break; case CodeMode.EAN_8: if ((valueStr.Length == 7 || valueStr.Length == 8) && bAllDigit(valueStr)) { if (valueStr.Length == 8) { valueStr = valueStr.Substring(0, 7); } byteMatrix = writer.encode(valueStr, BarcodeFormat.EAN_8, e_QRCodeWidth, e_QRCodeWidth / 2, hints); } else { return(-8); } break; case CodeMode.CODE_128: if (valueStr.Length <= 80) { byteMatrix = writer.encode(valueStr, BarcodeFormat.CODE_128, e_QRCodeWidth, e_QRCodeWidth / 2, hints); } else { return(-128); } break; /* * case CodeMode.DATA_MATRIX: * byteMatrix = writer.encode( valueStr, BarcodeFormat.DATA_MATRIX, e_QRCodeWidth, e_QRCodeHeight,hints); * break; */ case CodeMode.NONE: return(-1); break; } if (m_EncodedTex != null) { Destroy(m_EncodedTex); m_EncodedTex = null; } m_EncodedTex = new Texture2D(byteMatrix.Width, byteMatrix.Height); for (int i = 0; i != m_EncodedTex.width; i++) { for (int j = 0; j != m_EncodedTex.height; j++) { if (byteMatrix[i, j]) { m_EncodedTex.SetPixel(i, j, Color.black); } else { m_EncodedTex.SetPixel(i, j, Color.white); } } } ///rotation the image Color32[] pixels = m_EncodedTex.GetPixels32(); //pixels = RotateMatrixByClockwise(pixels, m_EncodedTex.width); m_EncodedTex.SetPixels32(pixels); m_EncodedTex.Apply(); onQREncodeFinished(m_EncodedTex); return(0); }
/// <summary> /// Compile module /// </summary> /// <param name="moduleName"></param> /// <param name="moduleSize"></param> /// <param name="scope"></param> /// <param name="codePiece"></param> /// <param name="codeType"></param> /// <param name="overwritten"></param> /// <returns></returns> public static Module CompileModule(ref string moduleName, int moduleSize, string scope, string codePiece, CodeType codeType, CodeMode overwritten) { Module module = Library.GetModule(moduleName); if (module != null) { if (module.CompileCodeBlock(scope, codePiece, codeType, overwritten)) { moduleName = module.moduleName; return(module); } else { return(null); } } module = new Module(moduleName, moduleSize); if (module.CompileCodeBlock(scope, codePiece, codeType, overwritten)) { Library.AddModule(module); moduleName = module.moduleName; return(module); } return(null); }
public string GetDictionaryFunctionCode(string typeName, string functionName, CodeMode codeMode, string nestFunctionName1, string nestFunctionName2) { return(string.Empty); }
public string GetListFunctionCode(string typeName, string functionName, CodeMode codeMode, string nestFunctionName) { return(string.Empty); }
public string GetCustomClassFunctionCode(string typeName, string functionName, CodeMode codeMode) { return(string.Empty); }
public string GetByteBufferCode(string typeName, CodeMode codeMode) { return(string.Empty); }
public string GetCodeModeName(CodeMode codeMode) { return(string.Empty); }
public static string GetByteBufferCode(Language language, string typeName, CodeMode codeMode) { return(GetCodeExporter(language).GetByteBufferCode(typeName, codeMode)); }
public static string GetCustomClassFunctionCode(Language language, string typeName, string functionName, CodeMode codeMode) { return(GetCodeExporter(language).GetCustomClassFunctionCode(typeName, functionName, codeMode)); }
private void Awake() { #if !UNITY_EDITOR && !FORCE_UPDATE //编辑器模式下跳过更新 Define.Networked = Application.internetReachability != NetworkReachability.NotReachable; #endif System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); //初始化App版本,解决覆盖安装问题 sw.Start(); InitAppVersion(); sw.Stop(); Debug.Log(string.Format("InitAppVersion use {0}ms", sw.ElapsedMilliseconds)); //先初始化AssetBundleMgr, 必须在Addressable系统初始化之前 sw.Start(); AssetBundleMgr.GetInstance().InitBuildInAssetBundleHashInfo(); sw.Stop(); Debug.Log(string.Format("InitBuildInAssetBundleHashInfo use {0}ms", sw.ElapsedMilliseconds)); sw.Reset(); sw.Start(); AssetBundleConfig.Instance.SyncLoadGlobalAssetBundle(); sw.Stop(); Debug.Log(string.Format("SyncLoadGlobalAssetBundle use {0}ms", sw.ElapsedMilliseconds)); sw.Reset(); //先设置remote_cdn_url sw.Start(); AssetBundleMgr.GetInstance().SetAddressableRemoteResCdnUrl(AssetBundleConfig.Instance.remote_cdn_url); sw.Stop(); Debug.Log(string.Format("SetAddressableRemoteResCdnUrl use {0}ms", sw.ElapsedMilliseconds)); sw.Reset(); //开始热修复 sw.Start(); AddressablesManager.Instance.StartInjectFix(); sw.Stop(); Debug.Log(string.Format("StartInjectFix use {0}ms", sw.ElapsedMilliseconds)); sw.Reset(); InitUnitySetting(); #if ENABLE_IL2CPP this.CodeMode = CodeMode.ILRuntime; //#elif UNITY_EDITOR // this.CodeMode = CodeMode.Reload; #endif System.AppDomain.CurrentDomain.UnhandledException += (sender, e) => { Log.Error(e.ExceptionObject.ToString()); }; SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance); DontDestroyOnLoad(gameObject); LitJson.UnityTypeBindings.Register(); ETTask.ExceptionHandler += Log.Error; Log.ILog = new UnityLogger(); Options.Instance = new Options(); CodeLoader.Instance.CodeMode = this.CodeMode; Options.Instance.Develop = 1; Options.Instance.LogLevel = 0; }
public static string NestArray2FunctionName(Language language, List <object> nestArray, CodeMode codeMode = CodeMode.None) { string code = string.Empty; code += BufferCodeExporter.GetCodeModeName(language, codeMode); object element; for (int i = 0; i < nestArray.Count; i++) { element = nestArray[i]; if (element is string) { string prefixType = element as string; int array = GetArraySuffix(ref prefixType); string typeConvention = BufferCodeExporter.GetByteBufferCode(language, prefixType, codeMode); //UppercaseWords(); code += typeConvention; if (i + 1 < nestArray.Count && nestArray[i + 1] is List <object> ) { List <object> generics = nestArray[i + 1] as List <object>; code += NestArray2FunctionName(language, generics, CodeMode.None); i++; } if (nestArray.Count > 1 || array > 0) { code += array; } } } return(code); }