diff --git a/Losetta.Runtime/Alice.Console.cs b/Losetta.Runtime/Alice.Console.cs index a08acab..116e622 100644 --- a/Losetta.Runtime/Alice.Console.cs +++ b/Losetta.Runtime/Alice.Console.cs @@ -1,4 +1,5 @@ using AliceScript.Binding; +using System; using System.Runtime.Versioning; using System.Text; diff --git a/Losetta.Runtime/Alice.Diagnostics.cs b/Losetta.Runtime/Alice.Diagnostics.cs index aeab7a6..11961b8 100644 --- a/Losetta.Runtime/Alice.Diagnostics.cs +++ b/Losetta.Runtime/Alice.Diagnostics.cs @@ -1,4 +1,6 @@ using AliceScript.Binding; +using System; +using System.Collections.Generic; using System.Diagnostics; using System.Text; @@ -239,7 +241,11 @@ public void Kill() public void Kill(bool entireProcessTree) { +#if NETCOREAPP3_0_OR_GREATER Process.Kill(entireProcessTree); +#else + throw new ScriptException("この実装では操作がサポートされていません", Exceptions.NOT_IMPLEMENTED); +#endif } public void Reflesh() diff --git a/Losetta.Runtime/Alice.Environment.cs b/Losetta.Runtime/Alice.Environment.cs index 57bc0a5..234ee18 100644 --- a/Losetta.Runtime/Alice.Environment.cs +++ b/Losetta.Runtime/Alice.Environment.cs @@ -1,5 +1,6 @@ using AliceScript.Binding; using AliceScript.Functions; +using System; namespace AliceScript.NameSpaces { diff --git a/Losetta.Runtime/Alice.IO.cs b/Losetta.Runtime/Alice.IO.cs index 1b4c297..c1e23d3 100644 --- a/Losetta.Runtime/Alice.IO.cs +++ b/Losetta.Runtime/Alice.IO.cs @@ -1,6 +1,9 @@ using AliceScript.Binding; using AliceScript.Extra; using AliceScript.Parsing; +using System; +using System.Collections.Generic; +using System.IO; using System.IO.Compression; using System.Security.Cryptography; using System.Text; @@ -29,7 +32,11 @@ public static void File_Move(string from, string to) } public static void File_Move(string from, string to, bool overwrite) { +#if NETCOREAPP3_0_OR_GREATER File.Move(from, to, overwrite); +#else + throw new ScriptException("この実装では操作がサポートされていません", Exceptions.NOT_IMPLEMENTED); +#endif } public static void File_Copy(string from, string to) { @@ -349,7 +356,11 @@ public static string Directory_Current(string path) } public static void Directory_Create_SymbolicLink(string path, string pathToTarget) { +#if NET6_0 Directory.CreateSymbolicLink(path, pathToTarget); +#else + throw new ScriptException("この実装では操作がサポートされていません", Exceptions.NOT_IMPLEMENTED); +#endif } public static void Directory_Delete(string path) { @@ -461,7 +472,7 @@ public static string Path_ChageExtension(string filename, string extension) } public static bool Path_EndsInDirectorySeparator(string path) { - return Path.EndsInDirectorySeparator(path); + return path.EndsWith(Path.DirectorySeparatorChar) || path.EndsWith(Path.AltDirectorySeparatorChar); } public static string Path_Get_DirectoryName(string path) { @@ -485,7 +496,11 @@ public static string Path_Get_FullPath(string path) } public static string Path_Get_RelativePath(string to, string path) { +#if NETCOREAPP2_0_OR_GREATER return Path.GetRelativePath(to, path); +#else + throw new ScriptException("この実装では操作がサポートされていません", Exceptions.NOT_IMPLEMENTED); +#endif } public static string Path_Get_PathRoot(string path) { @@ -509,7 +524,11 @@ public static bool Path_Has_Extension(string path) } public static bool Path_IsPathFullyQualified(string path) { +#if NETCOREAPP2_1_OR_GREATER return Path.IsPathFullyQualified(path); +#else + throw new ScriptException("この実装では操作がサポートされていません", Exceptions.NOT_IMPLEMENTED); +#endif } public static bool Path_IsPathRooted(string path) { @@ -517,7 +536,11 @@ public static bool Path_IsPathRooted(string path) } public static string Path_TrimEndingDirectorySeparator(string path) { +#if NETCOREAPP3_0_OR_GREATER return Path.TrimEndingDirectorySeparator(path); +#else + throw new ScriptException("この実装では操作がサポートされていません", Exceptions.NOT_IMPLEMENTED); +#endif } public static string Path_Combine(params string[] paths) { @@ -525,7 +548,11 @@ public static string Path_Combine(params string[] paths) } public static string Path_Join(params string[] paths) { +#if NETCOREAPP3_0_OR_GREATER return Path.Join(paths); +#else + throw new ScriptException("この実装では操作がサポートされていません", Exceptions.NOT_IMPLEMENTED); +#endif } #endregion #region ZIPファイル操作 diff --git a/Losetta.Runtime/Alice.Interop.cs b/Losetta.Runtime/Alice.Interop.cs index 3d6e2f7..fef4f69 100644 --- a/Losetta.Runtime/Alice.Interop.cs +++ b/Losetta.Runtime/Alice.Interop.cs @@ -1,6 +1,7 @@ using AliceScript.Binding; using AliceScript.Interop; using AliceScript.Objects; +using System; using System.Reflection; namespace AliceScript.NameSpaces diff --git a/Losetta.Runtime/Alice.Legacy.cs b/Losetta.Runtime/Alice.Legacy.cs index 07c983c..50c6342 100644 --- a/Losetta.Runtime/Alice.Legacy.cs +++ b/Losetta.Runtime/Alice.Legacy.cs @@ -1,4 +1,6 @@ using AliceScript.Functions; +using System; +using System.Collections.Generic; namespace AliceScript.NameSpaces { diff --git a/Losetta.Runtime/Alice.Math.cs b/Losetta.Runtime/Alice.Math.cs index cbea7e3..d04c198 100644 --- a/Losetta.Runtime/Alice.Math.cs +++ b/Losetta.Runtime/Alice.Math.cs @@ -1,4 +1,5 @@ using AliceScript.Binding; +using System; namespace AliceScript.NameSpaces { @@ -62,15 +63,27 @@ public static bool Math_IsNegativeInfinity(double x) } public static bool Math_IsFinite(double x) { +#if NETCOREAPP2_1_OR_GREATER return double.IsFinite(x); +#else + throw new ScriptException("この実装では操作がサポートされていません", Exceptions.NOT_IMPLEMENTED); +#endif } public static bool Math_IsNormal(double x) { +#if NETCOREAPP2_1_OR_GREATER return double.IsNormal(x); +#else + throw new ScriptException("この実装では操作がサポートされていません", Exceptions.NOT_IMPLEMENTED); +#endif } public static bool Math_IsSubnormal(double x) { +#if NETCOREAPP2_1_OR_GREATER return double.IsSubnormal(x); +#else + throw new ScriptException("この実装では操作がサポートされていません", Exceptions.NOT_IMPLEMENTED); +#endif } public static double Math_Pow(double x, double y) { @@ -86,11 +99,18 @@ public static double Math_Ceiling(double x) } public static double Math_Clamp(double x, double min, double max) { - return Math.Clamp(x, min, max); + return double.IsNaN(x) ? double.NaN : x < min ? min : max < x ? max : x; } public static double Math_CopySign(double x, double y) { +#if NETCOREAPP3_0_OR_GREATER return Math.CopySign(x, y); + +#else + int sign = Math.Sign(y); + sign = sign == 0 ? 1 : sign; + return Math.Abs(x) * sign; +#endif } public static double Math_Exp(double x) { @@ -98,7 +118,11 @@ public static double Math_Exp(double x) } public static double Math_FusedMultiplyAdd(double x, double y, double z) { +#if NETCOREAPP3_0_OR_GREATER return Math.FusedMultiplyAdd(x, y, z); +#else + throw new ScriptException("この実装では操作がサポートされていません", Exceptions.NOT_IMPLEMENTED); +#endif } public static double Math_Sqrt(double x) { @@ -106,7 +130,11 @@ public static double Math_Sqrt(double x) } public static double Math_Cbrt(double x) { +#if NETCOREAPP2_1_OR_GREATER return Math.Cbrt(x); +#else + return Math.Pow(x,1/3); +#endif } public static double Math_Max(params double[] nums) { @@ -147,9 +175,9 @@ public static double Math_Factorial(uint n) } #region 数学定数 - public static double Math_Tau => Math.Tau; - public static double Math_PI => Math.PI; - public static double Math_E => Math.E; + public static double Math_Tau => 6.2831853071795862; + public static double Math_PI => 3.1415926535897931; + public static double Math_E => 2.7182818284590451; public static double Math_Infinity => double.PositiveInfinity; public static double Math_NegativeInfinity => double.NegativeInfinity; @@ -164,12 +192,20 @@ public static double Math_Factorial(uint n) #region 端数処理 public static double Math_Round(double x, bool? roudingMode = null) { +#if NETCOREAPP3_0_OR_GREATER MidpointRounding mode = roudingMode.HasValue ? roudingMode.Value ? MidpointRounding.AwayFromZero : MidpointRounding.ToZero : MidpointRounding.ToEven; +#else + MidpointRounding mode = roudingMode.HasValue ? roudingMode.Value ? MidpointRounding.AwayFromZero : throw new ScriptException("この実装では操作がサポートされていません", Exceptions.NOT_IMPLEMENTED) : MidpointRounding.ToEven; +#endif return Math.Round(x, mode); } public static double Math_Round(double x, int digits, bool? roudingMode = null) { +#if NETCOREAPP3_0_OR_GREATER MidpointRounding mode = roudingMode.HasValue ? roudingMode.Value ? MidpointRounding.AwayFromZero : MidpointRounding.ToZero : MidpointRounding.ToEven; +#else + MidpointRounding mode = roudingMode.HasValue ? roudingMode.Value ? MidpointRounding.AwayFromZero : throw new ScriptException("この実装では操作がサポートされていません", Exceptions.NOT_IMPLEMENTED) : MidpointRounding.ToEven; +#endif return Math.Round(x, digits, mode); } public static double Math_Truncate(double x) @@ -185,11 +221,19 @@ public static double Math_Floor(double x) #region ビット加減算 public static double Math_BitIncrement(double x) { +#if NETCOREAPP3_0_OR_GREATER return Math.BitIncrement(x); +#else + throw new ScriptException("この実装では操作がサポートされていません", Exceptions.NOT_IMPLEMENTED); +#endif } public static double Math_BitDecrement(double x) { +#if NETCOREAPP3_0_OR_GREATER return Math.BitDecrement(x); +#else + throw new ScriptException("この実装では操作がサポートされていません", Exceptions.NOT_IMPLEMENTED); +#endif } #endregion #region 三角関数 @@ -245,15 +289,33 @@ public static double Math_Tanh(double x) #region 逆双曲線関数 public static double Math_Asinh(double x) { +#if NETCOREAPP2_1_OR_GREATER return Math.Asinh(x); +#else + return Math.Log(x + Math.Sqrt(x * x + 1)); +#endif } public static double Math_Acosh(double x) { +#if NETCOREAPP2_1_OR_GREATER return Math.Acosh(x); +#else + return x < 1.0 || double.IsNaN(x) + ? double.NaN + : Math.Log(x + Math.Sqrt((x * x) - 1)); +#endif } public static double Math_Atanh(double x) { +#if NETCOREAPP2_1_OR_GREATER return Math.Atanh(x); +#else + if(Math.Abs(x) > 1 || double.IsNaN(x)) + { + return double.NaN; + } + return 0.5 * Math.Log((1 + x) / (1 - x)); +#endif } #endregion #region 対数関数 @@ -271,7 +333,11 @@ public static double Math_Log(double a, double baseNum) public static double Math_ReciprocalEstimate(double a) { +#if NET6_0_OR_GREATER return Math.ReciprocalEstimate(a); +#else + throw new ScriptException("この実装では操作がサポートされていません", Exceptions.NOT_IMPLEMENTED); +#endif } } diff --git a/Losetta.Runtime/Alice.Net.cs b/Losetta.Runtime/Alice.Net.cs index f3f162a..2a8fbcd 100644 --- a/Losetta.Runtime/Alice.Net.cs +++ b/Losetta.Runtime/Alice.Net.cs @@ -1,4 +1,6 @@ using AliceScript.Binding; +using System.Collections.Generic; +using System.Linq; using System.Net; namespace AliceScript.NameSpaces diff --git a/Losetta.Runtime/Alice.Random.cs b/Losetta.Runtime/Alice.Random.cs index eb2ca26..aaee58e 100644 --- a/Losetta.Runtime/Alice.Random.cs +++ b/Losetta.Runtime/Alice.Random.cs @@ -1,4 +1,5 @@ using AliceScript.Binding; +using System; using System.Security.Cryptography; namespace AliceScript.NameSpaces @@ -41,21 +42,33 @@ public static double Rand_Double() #region 暗号学的乱数生成 public static int Random_Int() { +#if NETCOREAPP3_0_OR_GREATER return RandomNumberGenerator.GetInt32(int.MaxValue); +#else + throw new ScriptException("この実装では操作がサポートされていません", Exceptions.NOT_IMPLEMENTED); +#endif } public static int Random_Int(int max) { +#if NETCOREAPP3_0_OR_GREATER return RandomNumberGenerator.GetInt32(max); +#else + throw new ScriptException("この実装では操作がサポートされていません", Exceptions.NOT_IMPLEMENTED); +#endif } public static int Random_Int(int min, int max) { +#if NETCOREAPP3_0_OR_GREATER return RandomNumberGenerator.GetInt32(min, max); +#else + throw new ScriptException("この実装では操作がサポートされていません", Exceptions.NOT_IMPLEMENTED); +#endif } public static byte[] Random_Bytes(int length) { return RandomNumberGenerator.GetBytes(length); } - #endregion +#endregion #region GUID生成 public static string Guid_New_Text() { diff --git a/Losetta.Runtime/Alice.Reflection.cs b/Losetta.Runtime/Alice.Reflection.cs index bd4125c..d115c5b 100644 --- a/Losetta.Runtime/Alice.Reflection.cs +++ b/Losetta.Runtime/Alice.Reflection.cs @@ -1,6 +1,7 @@ using AliceScript.Binding; using AliceScript.Functions; using AliceScript.Parsing; +using System.Collections.Generic; namespace AliceScript.NameSpaces { diff --git a/Losetta.Runtime/Alice.Regex.cs b/Losetta.Runtime/Alice.Regex.cs index 5ab1164..0577313 100644 --- a/Losetta.Runtime/Alice.Regex.cs +++ b/Losetta.Runtime/Alice.Regex.cs @@ -1,4 +1,5 @@ using AliceScript.Binding; +using System.Collections.Generic; using System.Text.RegularExpressions; namespace AliceScript.NameSpaces diff --git a/Losetta.Runtime/Alice.Runtime.cs b/Losetta.Runtime/Alice.Runtime.cs index 4a6aac9..2b68cb6 100644 --- a/Losetta.Runtime/Alice.Runtime.cs +++ b/Losetta.Runtime/Alice.Runtime.cs @@ -1,5 +1,6 @@ using AliceScript.Interop; using AliceScript.NameSpaces; +using System.Collections.Generic; namespace AliceScript { diff --git a/Losetta.Runtime/Alice.Security.cs b/Losetta.Runtime/Alice.Security.cs index f8aa5f2..2e82628 100644 --- a/Losetta.Runtime/Alice.Security.cs +++ b/Losetta.Runtime/Alice.Security.cs @@ -1,4 +1,5 @@ using AliceScript.Binding; +using System.Net.NetworkInformation; using System.Security.Cryptography; namespace AliceScript.NameSpaces @@ -25,25 +26,58 @@ public static byte[] Data_Decrypt(byte[] data, string password, int keySize = 12 #endregion #region ハッシュ関数 +#if !NET5_0_OR_GREATER + // もし必要な場合はハッシュアルゴリズムをキャッシュしておく + private static HashAlgorithm MD5Algorithm { get; set; } + private static HashAlgorithm SHA1Algorithm { get; set; } + private static HashAlgorithm SHA256Algorithm { get; set; } + private static HashAlgorithm SHA384Algorithm { get; set; } + private static HashAlgorithm SHA512Algorithm { get; set; } +#endif public static byte[] MD5_GetHash(byte[] data) { +#if NET5_0_OR_GREATER return MD5.HashData(data); +#else + MD5Algorithm = MD5Algorithm ?? MD5.Create(); + return MD5Algorithm.ComputeHash(data); +#endif } public static byte[] SHA1_GetHash(byte[] data) { +#if NET5_0_OR_GREATER return SHA1.HashData(data); +#else + SHA1Algorithm = SHA1Algorithm ?? SHA1.Create(); + return SHA1Algorithm.ComputeHash(data); +#endif } public static byte[] SHA256_GetHash(byte[] data) { +#if NET5_0_OR_GREATER return SHA256.HashData(data); +#else + SHA256Algorithm = SHA256Algorithm ?? SHA256.Create(); + return SHA256Algorithm.ComputeHash(data); +#endif } public static byte[] SHA384_GetHash(byte[] data) { +#if NET5_0_OR_GREATER return SHA384.HashData(data); +#else + SHA384Algorithm = SHA384Algorithm ?? SHA384.Create(); + return SHA384Algorithm.ComputeHash(data); +#endif } public static byte[] SHA512_GetHash(byte[] data) { +#if NET5_0_OR_GREATER return SHA512.HashData(data); +#else + SHA512Algorithm = SHA512Algorithm ?? SHA512.Create(); + return SHA512Algorithm.ComputeHash(data); +#endif } #endregion @@ -132,11 +166,21 @@ internal static byte[] GetHashData(byte[] password, byte[] salt, int size, int c } return bytesSalt; } +#if !NETCOREAPP2_1_OR_GREATER + private static RandomNumberGenerator RandomNumberGenerator { get; set; } +#endif internal static byte[] GetSalt(int size) { +#if NETCOREAPP2_1_OR_GREATER var bytes = new byte[size]; RandomNumberGenerator.Fill(bytes); return bytes; +#else + RandomNumberGenerator = RandomNumberGenerator ?? RandomNumberGenerator.Create(); + var bytes = new byte[size]; + RandomNumberGenerator.GetBytes(bytes); + return bytes; +#endif } } } \ No newline at end of file diff --git a/Losetta.Runtime/Alice.Threading.cs b/Losetta.Runtime/Alice.Threading.cs index a9e142e..d39358f 100644 --- a/Losetta.Runtime/Alice.Threading.cs +++ b/Losetta.Runtime/Alice.Threading.cs @@ -1,6 +1,10 @@ using AliceScript.Binding; using AliceScript.Objects; using AliceScript.Parsing; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; namespace AliceScript.NameSpaces { diff --git a/Losetta.Runtime/Core/Alice.Core.Flow.cs b/Losetta.Runtime/Core/Alice.Core.Flow.cs index f0b65f7..519c6aa 100644 --- a/Losetta.Runtime/Core/Alice.Core.Flow.cs +++ b/Losetta.Runtime/Core/Alice.Core.Flow.cs @@ -2,7 +2,10 @@ using AliceScript.Functions; using AliceScript.Objects; using AliceScript.Parsing; +using System; using System.Collections; +using System.Collections.Generic; +using System.Linq; using System.Text; namespace AliceScript.NameSpaces.Core diff --git a/Losetta.Runtime/Core/Alice.Core.Utils.cs b/Losetta.Runtime/Core/Alice.Core.Utils.cs index c2131b5..5208509 100644 --- a/Losetta.Runtime/Core/Alice.Core.Utils.cs +++ b/Losetta.Runtime/Core/Alice.Core.Utils.cs @@ -3,6 +3,9 @@ using AliceScript.Objects; using AliceScript.Packaging; using AliceScript.Parsing; +using System; +using System.Collections.Generic; +using System.Threading; namespace AliceScript.NameSpaces.Core { diff --git a/Losetta.Runtime/Core/Extension/Alice.Core.Array.cs b/Losetta.Runtime/Core/Extension/Alice.Core.Array.cs index 7c2292e..cf2e40b 100644 --- a/Losetta.Runtime/Core/Extension/Alice.Core.Array.cs +++ b/Losetta.Runtime/Core/Extension/Alice.Core.Array.cs @@ -2,6 +2,8 @@ using AliceScript.Functions; using AliceScript.Objects; using AliceScript.Parsing; +using System.Collections.Generic; +using System.Linq; namespace AliceScript.NameSpaces.Core { @@ -113,7 +115,26 @@ public static IEnumerable Skip(this VariableCollection ary, int count) } public static IEnumerable SkipLast(this VariableCollection ary, int count) { +#if NETCOREAPP2_1_OR_GREATER return ary.Tuple.SkipLast(count); +#else + // LINQが使えない場合は自分で実装したやつを使う + if(count <= 0) + { + return ary; + } + // 実際に欲しいIEnumratableの先頭からの長さ + int wantCount = ary.Count - count; + + // 何も残らない場合は空のリストを返しておく + if(wantCount <= 0) + { + return new List(); + } + + // 後はTakeするだけ + return ary.Take(wantCount); +#endif } public static IEnumerable SkipWhile(this VariableCollection ary, ParsingScript script, DelegateObject func) { diff --git a/Losetta.Runtime/Core/Extension/Alice.Core.Bytes.cs b/Losetta.Runtime/Core/Extension/Alice.Core.Bytes.cs index 811a365..552aa6a 100644 --- a/Losetta.Runtime/Core/Extension/Alice.Core.Bytes.cs +++ b/Losetta.Runtime/Core/Extension/Alice.Core.Bytes.cs @@ -1,5 +1,6 @@ using AliceScript.Binding; using AliceScript.Functions; +using System; using System.Text; namespace AliceScript.NameSpaces.Core diff --git a/Losetta.Runtime/Core/Extension/Alice.Core.Delegate.cs b/Losetta.Runtime/Core/Extension/Alice.Core.Delegate.cs index 6aa0288..23b5c07 100644 --- a/Losetta.Runtime/Core/Extension/Alice.Core.Delegate.cs +++ b/Losetta.Runtime/Core/Extension/Alice.Core.Delegate.cs @@ -2,6 +2,8 @@ using AliceScript.Functions; using AliceScript.Objects; using AliceScript.Parsing; +using System.Collections.Generic; +using System.Linq; namespace AliceScript.NameSpaces.Core { diff --git a/Losetta.Runtime/Core/Extension/Alice.Core.String.cs b/Losetta.Runtime/Core/Extension/Alice.Core.String.cs index 341ee58..8fb3145 100644 --- a/Losetta.Runtime/Core/Extension/Alice.Core.String.cs +++ b/Losetta.Runtime/Core/Extension/Alice.Core.String.cs @@ -1,5 +1,8 @@ using AliceScript.Binding; using AliceScript.Functions; +using System; +using System.Collections.Generic; +using System.Linq; using System.Text; namespace AliceScript.NameSpaces.Core @@ -108,11 +111,24 @@ public static bool Contains(this string str, string value) } public static bool Contains(this string str, string value, bool ignoreCase) { +#if NETCOREAPP2_1_OR_GREATER return str.Contains(value, ignoreCase ? StringComparison.CurrentCultureIgnoreCase : StringComparison.CurrentCulture); +#else + if (ignoreCase) + { + str = str.ToUpper(); + value = value.ToUpper(); + } + return str.Contains(value); +#endif } public static bool Contains(this string str, string value, bool ignoreCase, bool considerCulture) { +#if NETCOREAPP2_1_OR_GREATER return str.Contains(value, considerCulture ? ignoreCase ? StringComparison.CurrentCultureIgnoreCase : StringComparison.CurrentCulture : ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal); +#else + throw new ScriptException("この実装では操作がサポートされていません", Exceptions.NOT_IMPLEMENTED); +#endif } public static string ToUpper(this string str) { @@ -152,12 +168,21 @@ public static string PadCenter(this string str, int totalWidth, bool padRight = } public static string PadCenter(this string str, int totalWidth, char paddingChar, bool padRight = false, bool truncate = false) { - long length = (totalWidth - str.Length) / 2; - long surplus = totalWidth - str.Length - length; + int length = (totalWidth - str.Length) / 2; + int surplus = totalWidth - str.Length - length; if (padRight) { +#if NET47_OR_GREATER || NETCOREAPP2_0_OR_GREATER // 割り切れないとき右寄せ指定の場合はスワップ (length, surplus) = (surplus, length); +#else + // 割り切れないとき右寄せ指定の場合はスワップ(タプルが使えない時は昔ながらのやり方で) + { + var tmp = length; + length = surplus; + surplus = tmp; + } +#endif } var sb = new StringBuilder(); for (int i = 0; i < length; i++) @@ -167,7 +192,12 @@ public static string PadCenter(this string str, int totalWidth, char paddingChar if (truncate && str.Length > totalWidth) { // 文字列がtotalWidthより長い場合は切り詰め +#if NETCOREAPP2_1_OR_GREATER sb.Append(str.AsSpan().Slice(0, totalWidth)); +#else + // Spanが使えない時は無理しない + sb.Append(str.Substring(0,totalWidth)); +#endif } else { @@ -209,11 +239,19 @@ public static string Replace(this string str, string oldValue, string newValue) } public static string Replace(this string str, string oldvalue, string newValue, bool ignoreCase) { +#if NETCOREAPP2_0_OR_GREATER return str.Replace(oldvalue, newValue, ignoreCase ? StringComparison.CurrentCultureIgnoreCase : StringComparison.CurrentCulture); +#else + throw new ScriptException("この実装では操作がサポートされていません", Exceptions.NOT_IMPLEMENTED); +#endif } public static string Replace(this string str, string oldvalue, string newValue, bool ignoreCase, bool considerCulture) { +#if NETCOREAPP2_0_OR_GREATER return str.Replace(oldvalue, newValue, considerCulture ? ignoreCase ? StringComparison.CurrentCultureIgnoreCase : StringComparison.CurrentCulture : ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal); +#else + throw new ScriptException("この実装では操作がサポートされていません", Exceptions.NOT_IMPLEMENTED); +#endif } public static string ReplaceLineEndings(this string str) { @@ -240,12 +278,12 @@ public static string[] Split(this string str, string separator) } public static string[] SplitLines(this string str) { - Span result = str.Split('\n').AsSpan(); + var result = str.Split('\n'); for (int i = 0; i < result.Length; i++) { result[i] = result[i].Trim('\r'); } - return result.ToArray(); + return result; } public static string Substring(this string str, int startIndex) { diff --git a/Losetta.Runtime/Losetta.Runtime.csproj b/Losetta.Runtime/Losetta.Runtime.csproj index fcac401..3699d00 100644 --- a/Losetta.Runtime/Losetta.Runtime.csproj +++ b/Losetta.Runtime/Losetta.Runtime.csproj @@ -2,10 +2,10 @@ net6.0 - enable + disable disable alice_logo.ico - 0.10.4 + 0.10.5 WSOFT Losetta Alice.Runtime diff --git a/Losetta/Alice.cs b/Losetta/Alice.cs index 7e53ccf..29d4489 100644 --- a/Losetta/Alice.cs +++ b/Losetta/Alice.cs @@ -1,4 +1,6 @@ using AliceScript.Parsing; +using System; +using System.Threading.Tasks; namespace AliceScript { diff --git a/Losetta/Binding/BindAttributes.cs b/Losetta/Binding/BindAttributes.cs index f1f1ef4..0ccd44e 100644 --- a/Losetta/Binding/BindAttributes.cs +++ b/Losetta/Binding/BindAttributes.cs @@ -1,4 +1,5 @@ using AliceScript.Functions; +using System; namespace AliceScript.Binding { diff --git a/Losetta/Binding/BindFunction.cs b/Losetta/Binding/BindFunction.cs index 83c2fb9..6aee16a 100644 --- a/Losetta/Binding/BindFunction.cs +++ b/Losetta/Binding/BindFunction.cs @@ -1,5 +1,8 @@ using AliceScript.Functions; using AliceScript.Objects; +using System; +using System.Collections.Generic; +using System.Linq; using System.Linq.Expressions; using System.Reflection; using System.Runtime.CompilerServices; diff --git a/Losetta/Binding/BindValueFunction.cs b/Losetta/Binding/BindValueFunction.cs index b9fec9b..9810812 100644 --- a/Losetta/Binding/BindValueFunction.cs +++ b/Losetta/Binding/BindValueFunction.cs @@ -1,4 +1,5 @@ using AliceScript.Functions; +using System.Collections.Generic; namespace AliceScript.Binding { diff --git a/Losetta/Binding/BindingOverloadFunction.cs b/Losetta/Binding/BindingOverloadFunction.cs index dba6865..75be3a4 100644 --- a/Losetta/Binding/BindingOverloadFunction.cs +++ b/Losetta/Binding/BindingOverloadFunction.cs @@ -1,7 +1,10 @@ using AliceScript.Functions; using AliceScript.Objects; using AliceScript.Parsing; +using System; using System.Collections; +using System.Collections.Generic; +using System.Linq; using System.Reflection; namespace AliceScript.Binding diff --git a/Losetta/Binding/Utils.Binding.cs b/Losetta/Binding/Utils.Binding.cs index 6a05948..61d5fec 100644 --- a/Losetta/Binding/Utils.Binding.cs +++ b/Losetta/Binding/Utils.Binding.cs @@ -1,5 +1,9 @@ using AliceScript.Binding; using AliceScript.NameSpaces; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; using System.Linq.Expressions; using System.Reflection; using System.Reflection.Emit; diff --git a/Losetta/Constants.cs b/Losetta/Constants.cs index 038d6e7..0cad27b 100644 --- a/Losetta/Constants.cs +++ b/Losetta/Constants.cs @@ -1,4 +1,7 @@ -using System.Text; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Text.RegularExpressions; namespace AliceScript diff --git a/Losetta/Extra/SafeReader.cs b/Losetta/Extra/SafeReader.cs index e8f6d8b..2487e33 100644 --- a/Losetta/Extra/SafeReader.cs +++ b/Losetta/Extra/SafeReader.cs @@ -1,4 +1,6 @@ -using System.Text; +using System; +using System.IO; +using System.Text; namespace AliceScript.Extra { diff --git a/Losetta/Extra/Utils.Extra.cs b/Losetta/Extra/Utils.Extra.cs index 32c397a..590deec 100644 --- a/Losetta/Extra/Utils.Extra.cs +++ b/Losetta/Extra/Utils.Extra.cs @@ -1,4 +1,9 @@ -namespace AliceScript +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace AliceScript { public static partial class Utils { diff --git a/Losetta/Extra/XMLConfig.cs b/Losetta/Extra/XMLConfig.cs index 304af16..3b43d83 100644 --- a/Losetta/Extra/XMLConfig.cs +++ b/Losetta/Extra/XMLConfig.cs @@ -1,4 +1,8 @@ -using System.Security; +using System; +using System.Collections.Generic; +using System.IO; +using System.Security; +using System.Threading.Tasks; using System.Xml; namespace AliceScript.Extra diff --git a/Losetta/Functions/ActionFunctions.cs b/Losetta/Functions/ActionFunctions.cs index c5e24a2..1fcedb2 100644 --- a/Losetta/Functions/ActionFunctions.cs +++ b/Losetta/Functions/ActionFunctions.cs @@ -1,4 +1,6 @@ using AliceScript.Parsing; +using System; +using System.Collections.Generic; namespace AliceScript.Functions { diff --git a/Losetta/Functions/AssignFunction.cs b/Losetta/Functions/AssignFunction.cs index 55dee8f..23bbf7d 100644 --- a/Losetta/Functions/AssignFunction.cs +++ b/Losetta/Functions/AssignFunction.cs @@ -1,4 +1,6 @@ using AliceScript.Parsing; +using System; +using System.Collections.Generic; namespace AliceScript.Functions { diff --git a/Losetta/Functions/CustomFunction.cs b/Losetta/Functions/CustomFunction.cs index 0939435..142e7ce 100644 --- a/Losetta/Functions/CustomFunction.cs +++ b/Losetta/Functions/CustomFunction.cs @@ -1,5 +1,7 @@ using AliceScript.Objects; using AliceScript.Parsing; +using System; +using System.Collections.Generic; namespace AliceScript.Functions { diff --git a/Losetta/Functions/EnumFunction.cs b/Losetta/Functions/EnumFunction.cs index b11ddde..a3d13c9 100644 --- a/Losetta/Functions/EnumFunction.cs +++ b/Losetta/Functions/EnumFunction.cs @@ -1,4 +1,7 @@ -namespace AliceScript.Functions +using System; +using System.Collections.Generic; + +namespace AliceScript.Functions { internal sealed class EnumFunction : FunctionBase { diff --git a/Losetta/Functions/ExternFunctionCreator.cs b/Losetta/Functions/ExternFunctionCreator.cs index eaf975e..ad763be 100644 --- a/Losetta/Functions/ExternFunctionCreator.cs +++ b/Losetta/Functions/ExternFunctionCreator.cs @@ -1,4 +1,5 @@ -using System.Reflection; +using System; +using System.Reflection; namespace AliceScript.Functions { diff --git a/Losetta/Functions/FunctionBase.cs b/Losetta/Functions/FunctionBase.cs index 2ced11e..8e5d604 100644 --- a/Losetta/Functions/FunctionBase.cs +++ b/Losetta/Functions/FunctionBase.cs @@ -1,5 +1,7 @@ using AliceScript.Objects; using AliceScript.Parsing; +using System; +using System.Collections.Generic; namespace AliceScript.Functions { diff --git a/Losetta/Functions/FunctionCreator.cs b/Losetta/Functions/FunctionCreator.cs index 809c5f6..1df2270 100644 --- a/Losetta/Functions/FunctionCreator.cs +++ b/Losetta/Functions/FunctionCreator.cs @@ -1,4 +1,6 @@ using AliceScript.Parsing; +using System; +using System.Collections.Generic; namespace AliceScript.Functions { diff --git a/Losetta/Functions/ParserFunction.cs b/Losetta/Functions/ParserFunction.cs index 12e63d5..5d1d30a 100644 --- a/Losetta/Functions/ParserFunction.cs +++ b/Losetta/Functions/ParserFunction.cs @@ -1,6 +1,9 @@ using AliceScript.NameSpaces; using AliceScript.Objects; using AliceScript.Parsing; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; namespace AliceScript.Functions { @@ -699,9 +702,13 @@ public static void AddGlobalOrLocalVariable(string name, ValueFunction function, newVar.Nullable = true; } newVar.Assign(function.Value); - if (type_inference && type_modifer == Constants.VAR && !newVar.IsNull()) + if (type_inference && type_modifer == Constants.VAR) { - newVar.Nullable = false; + newVar.TypeChecked = true; + if (!newVar.IsNull()) + { + newVar.Nullable = false; + } } newVar.Readonly = isReadOnly; function = value; diff --git a/Losetta/Functions/ValueFunction.cs b/Losetta/Functions/ValueFunction.cs index 9a6b7dd..97b31b2 100644 --- a/Losetta/Functions/ValueFunction.cs +++ b/Losetta/Functions/ValueFunction.cs @@ -1,4 +1,6 @@ using AliceScript.Parsing; +using System; +using System.Collections.Generic; namespace AliceScript.Functions { diff --git a/Losetta/Interop/NetLibraryLoader.cs b/Losetta/Interop/NetLibraryLoader.cs index 665bfe5..d74c333 100644 --- a/Losetta/Interop/NetLibraryLoader.cs +++ b/Losetta/Interop/NetLibraryLoader.cs @@ -1,4 +1,8 @@ -namespace AliceScript.Interop +using System; +using System.Collections.Generic; +using System.IO; + +namespace AliceScript.Interop { public static class NetLibraryLoader { diff --git a/Losetta/Interpreter.cs b/Losetta/Interpreter.cs index f33808d..931a28c 100644 --- a/Losetta/Interpreter.cs +++ b/Losetta/Interpreter.cs @@ -5,9 +5,14 @@ using AliceScript.Packaging; using AliceScript.Parsing; using AliceScript.PreProcessing; +using System; +using System.Collections.Generic; +using System.IO; using System.IO.Compression; +using System.Linq; using System.Reflection; using System.Text; +using System.Threading.Tasks; namespace AliceScript { diff --git a/Losetta/Losetta.csproj b/Losetta/Losetta.csproj index bcd0d91..06d94b8 100644 --- a/Losetta/Losetta.csproj +++ b/Losetta/Losetta.csproj @@ -2,10 +2,10 @@ net6.0 - enable + disable disable alice_logo.ico - 0.10.4 + 0.10.5 WSOFT Losetta Alice.Runtime diff --git a/Losetta/NameSpaces/Alice.Interpreter.cs b/Losetta/NameSpaces/Alice.Interpreter.cs index 4941b4e..7f4f426 100644 --- a/Losetta/NameSpaces/Alice.Interpreter.cs +++ b/Losetta/NameSpaces/Alice.Interpreter.cs @@ -3,6 +3,9 @@ using AliceScript.Objects; using AliceScript.Packaging; using AliceScript.Parsing; +using System; +using System.Collections.Generic; +using System.Linq; namespace AliceScript.NameSpaces { diff --git a/Losetta/NameSpaces/NameSpace.cs b/Losetta/NameSpaces/NameSpace.cs index 6ed28b9..d991ba8 100644 --- a/Losetta/NameSpaces/NameSpace.cs +++ b/Losetta/NameSpaces/NameSpace.cs @@ -1,5 +1,8 @@ using AliceScript.Functions; using AliceScript.Objects; +using System; +using System.Collections.Generic; +using System.Linq; namespace AliceScript.NameSpaces { diff --git a/Losetta/Objects/AliceScriptClass.cs b/Losetta/Objects/AliceScriptClass.cs index eab81ea..3d11e9e 100644 --- a/Losetta/Objects/AliceScriptClass.cs +++ b/Losetta/Objects/AliceScriptClass.cs @@ -2,6 +2,10 @@ using AliceScript.NameSpaces; using AliceScript.Parsing; using AliceScript.PreProcessing; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; namespace AliceScript.Objects { diff --git a/Losetta/Objects/Delegate.cs b/Losetta/Objects/Delegate.cs index 5213806..cea6c89 100644 --- a/Losetta/Objects/Delegate.cs +++ b/Losetta/Objects/Delegate.cs @@ -1,5 +1,7 @@ using AliceScript.Functions; using AliceScript.Parsing; +using System.Collections.Generic; +using System.Threading; namespace AliceScript.Objects { diff --git a/Losetta/Objects/EnumeratorObject.cs b/Losetta/Objects/EnumeratorObject.cs index fda0156..b45961a 100644 --- a/Losetta/Objects/EnumeratorObject.cs +++ b/Losetta/Objects/EnumeratorObject.cs @@ -1,4 +1,5 @@ using AliceScript.Binding; +using System.Collections.Generic; namespace AliceScript.Objects { diff --git a/Losetta/Objects/ObjectBase.cs b/Losetta/Objects/ObjectBase.cs index a9ab2d3..aa4d0fb 100644 --- a/Losetta/Objects/ObjectBase.cs +++ b/Losetta/Objects/ObjectBase.cs @@ -1,5 +1,9 @@ using AliceScript.Functions; using AliceScript.Parsing; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; namespace AliceScript.Objects { diff --git a/Losetta/Objects/TypeObject.cs b/Losetta/Objects/TypeObject.cs index f117de1..340fc6c 100644 --- a/Losetta/Objects/TypeObject.cs +++ b/Losetta/Objects/TypeObject.cs @@ -1,5 +1,7 @@ using AliceScript.Functions; using AliceScript.Parsing; +using System; +using System.Collections.Generic; namespace AliceScript.Objects { diff --git a/Losetta/Objects/VariableCollection.cs b/Losetta/Objects/VariableCollection.cs index d319511..a5bd3ac 100644 --- a/Losetta/Objects/VariableCollection.cs +++ b/Losetta/Objects/VariableCollection.cs @@ -1,4 +1,5 @@ using System.Collections; +using System.Collections.Generic; namespace AliceScript.Objects { diff --git a/Losetta/Packaging/AlicePackage.cs b/Losetta/Packaging/AlicePackage.cs index f99b353..5999d5e 100644 --- a/Losetta/Packaging/AlicePackage.cs +++ b/Losetta/Packaging/AlicePackage.cs @@ -1,6 +1,10 @@ using AliceScript.Extra; using AliceScript.PreProcessing; +using System; +using System.Collections.Generic; +using System.IO; using System.IO.Compression; +using System.Linq; using System.Security.Cryptography; using System.Text; diff --git a/Losetta/Packaging/PackageManifest.cs b/Losetta/Packaging/PackageManifest.cs index 3732998..c91f22b 100644 --- a/Losetta/Packaging/PackageManifest.cs +++ b/Losetta/Packaging/PackageManifest.cs @@ -1,4 +1,6 @@ -namespace AliceScript.Packaging +using System.Collections.Generic; + +namespace AliceScript.Packaging { /// /// AlicePackageの設定 diff --git a/Losetta/Parsing/Parser.cs b/Losetta/Parsing/Parser.cs index c64dc4d..dc04cb3 100644 --- a/Losetta/Parsing/Parser.cs +++ b/Losetta/Parsing/Parser.cs @@ -1,6 +1,10 @@ using AliceScript.Functions; using AliceScript.Objects; +using System; +using System.Collections.Generic; +using System.Linq; using System.Text; +using System.Threading.Tasks; namespace AliceScript.Parsing { @@ -262,12 +266,6 @@ private static bool UpdateResult(ParsingScript script, char[] to, List { switch (preop) { - case PreOperetors.Minus: - { - // -マークがついている場合は数値がマイナス - current.Value = current.Value * -1; - break; - } case PreOperetors.Increment: { current.Value++; @@ -278,6 +276,11 @@ private static bool UpdateResult(ParsingScript script, char[] to, List current.Value--; break; } + case PreOperetors.Minus: + { + current.Value = -current.Value; + break; + } } } @@ -349,6 +352,7 @@ private static PreOperetors CheckConsistencyAndSign(ParsingScript script, List 2 && token.StartsWith(Constants.INCREMENT, StringComparison.Ordinal) && token[2] != Constants.QUOTE) { token = token.Substring(2); @@ -460,7 +464,7 @@ private static bool StillCollecting(string item, char[] to, ParsingScript script return true; } // プラスまたはマイナスはトークン区切りの直後またはプラスマイナスの直後のときのみトークンとしてあつかう - if (item.Length < 2 && (ch == '-' || ch == '+') && (prev == '+' || prev == '-' || Constants.TOKEN_SEPARATION.Contains(prev))) + if (item.Length < 2 && (ch == '-' || ch == '+') && (prev == '+' || prev == '-' || prev == '\0' || Constants.TOKEN_SEPARATION.Contains(prev))) { return true; } diff --git a/Losetta/Parsing/ParsingScript.cs b/Losetta/Parsing/ParsingScript.cs index ef1ba1c..bf3fc09 100644 --- a/Losetta/Parsing/ParsingScript.cs +++ b/Losetta/Parsing/ParsingScript.cs @@ -4,7 +4,12 @@ using AliceScript.Objects; using AliceScript.Packaging; using AliceScript.PreProcessing; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; using System.Text; +using System.Threading.Tasks; namespace AliceScript.Parsing { diff --git a/Losetta/Parsing/Utils.Parsing.cs b/Losetta/Parsing/Utils.Parsing.cs index 6f52575..952ef6c 100644 --- a/Losetta/Parsing/Utils.Parsing.cs +++ b/Losetta/Parsing/Utils.Parsing.cs @@ -1,6 +1,9 @@ using AliceScript.Functions; using AliceScript.Objects; using AliceScript.Parsing; +using System; +using System.Collections.Generic; +using System.Linq; using System.Text; namespace AliceScript diff --git a/Losetta/PreProcessing/PreProcessor.cs b/Losetta/PreProcessing/PreProcessor.cs index 8539eb2..2615d34 100644 --- a/Losetta/PreProcessing/PreProcessor.cs +++ b/Losetta/PreProcessing/PreProcessor.cs @@ -1,5 +1,9 @@ using AliceScript.Extra; using AliceScript.Parsing; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; using System.Text; using System.Text.RegularExpressions; @@ -59,7 +63,6 @@ public static string ConvertToScript(string source, out Dictionary cha bool inComments = false; bool simpleComments = false; char prev = Constants.EMPTY; - char prevprev = Constants.EMPTY; int levelCurly = 0; int levelBrackets = 0; @@ -509,9 +512,9 @@ public static string ConvertToScript(string source, out Dictionary cha pragmaCommand.Clear(); pragmaArgs.Clear(); + i--; } - prevprev = prev; prev = ch; } @@ -541,7 +544,7 @@ public static string ConvertToScript(string source, out Dictionary cha ThrowSyntaxError(curlyErrorMsg, source, Exceptions.UNBALANCED_CURLY_BRACES, levelCurly, lineNumberCurly, lineNumber, filename); } } - return sb.ToString().Trim(); + return sb.ToString(); } private static void ThrowSyntaxError(string msg, string code, Exceptions ecode, int level, int lineStart, int lineEnd, string filename) { @@ -573,7 +576,7 @@ private static void ThrowSyntaxError(string msg, string code, Exceptions ecode, /// Unicode文字を含む文字列 private static string ConvertUnicodeLiteral(string input) { - if (input.Contains('\\', StringComparison.Ordinal) && (input.Contains('u', StringComparison.OrdinalIgnoreCase) || input.Contains('x', StringComparison.Ordinal))) + if (input.Contains("\\u", StringComparison.OrdinalIgnoreCase) || input.Contains("\\x", StringComparison.Ordinal)) { //UTF-16文字コードの置き換え foreach (Match match in Constants.UTF16_LITERAL.Matches(input)) diff --git a/Losetta/ThrowError.cs b/Losetta/ThrowError.cs index b0f87a1..ab795ed 100644 --- a/Losetta/ThrowError.cs +++ b/Losetta/ThrowError.cs @@ -1,4 +1,5 @@ using AliceScript.Parsing; +using System; namespace AliceScript { diff --git a/Losetta/Utils.cs b/Losetta/Utils.cs index 0bfa74c..da5312d 100644 --- a/Losetta/Utils.cs +++ b/Losetta/Utils.cs @@ -2,7 +2,10 @@ using AliceScript.Functions; using AliceScript.Objects; using AliceScript.Parsing; +using System; +using System.Collections.Generic; using System.Globalization; +using System.IO; using System.Runtime.InteropServices; namespace AliceScript diff --git a/Losetta/Variable.cs b/Losetta/Variable.cs index e071138..b40cd5e 100644 --- a/Losetta/Variable.cs +++ b/Losetta/Variable.cs @@ -3,8 +3,12 @@ using AliceScript.Functions; using AliceScript.Objects; using AliceScript.Parsing; +using System; using System.Collections; +using System.Collections.Generic; +using System.Linq; using System.Text; +using System.Threading.Tasks; namespace AliceScript { diff --git a/alice/ArgumentsParser.cs b/alice/ArgumentsParser.cs index 9cc6c24..73a2cbb 100644 --- a/alice/ArgumentsParser.cs +++ b/alice/ArgumentsParser.cs @@ -1,4 +1,6 @@ -using System.Text.RegularExpressions; +using System; +using System.Collections.Generic; +using System.Text.RegularExpressions; namespace AliceScript.CLI { diff --git a/alice/Program.cs b/alice/Program.cs index e5aa2a1..9835e93 100644 --- a/alice/Program.cs +++ b/alice/Program.cs @@ -1,4 +1,7 @@ using AliceScript.Packaging; +using System; +using System.Collections.Generic; +using System.IO; using System.IO.Compression; using System.Text; diff --git a/alice/ShellFunctions.cs b/alice/ShellFunctions.cs index 5fd3154..e23595c 100644 --- a/alice/ShellFunctions.cs +++ b/alice/ShellFunctions.cs @@ -2,6 +2,7 @@ using AliceScript.Functions; using AliceScript.Packaging; using AliceScript.Parsing; +using System.IO; namespace AliceScript.CLI { diff --git a/alice/alice.csproj b/alice/alice.csproj index 55b5ca1..8f0698e 100644 --- a/alice/alice.csproj +++ b/alice/alice.csproj @@ -3,12 +3,12 @@ Exe net6.0 - enable + disable disable true alice_logo.ico - 0.10.4 + 0.10.5 Losetta.CLI WSOFT WSOFT diff --git a/alice/shell.cs b/alice/shell.cs index 8efdef9..ea0bfbe 100644 --- a/alice/shell.cs +++ b/alice/shell.cs @@ -1,5 +1,8 @@ using AliceScript.Functions; using AliceScript.Parsing; +using System; +using System.Collections.Generic; +using System.IO; using System.Text; namespace AliceScript.CLI