Skip to content

Commit

Permalink
Merge pull request #119 from WSOFT-Project/develop
Browse files Browse the repository at this point in the history
Losetta v0.10.3
  • Loading branch information
taiseiue authored Dec 24, 2023
2 parents 3e46ca2 + 1255b91 commit af40e33
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 28 deletions.
34 changes: 32 additions & 2 deletions Losetta.Runtime/Core/Alice.Core.Flow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public static Variable Switch(ParsingScript script, Variable item)
//スタート地点に帰ってブロックを終わらせる
script.Pointer = startPointer;
script.SkipBlock();
if (needBreak && result.Type != Variable.VarType.BREAK && !result.IsReturn)
if (needBreak && result.Type != Variable.VarType.BREAK && !result.IsReturn && result.Type != Variable.VarType.CONTINUE)
{
throw new ScriptException("defaultブロックはbreakまたはreturnで抜ける必要があります", Exceptions.CASE_BLOCK_MISSING_BREAK);
}
Expand All @@ -235,12 +235,18 @@ public static Variable Switch(ParsingScript script, Variable item)
nextTrue = false;
caseDone = true;
result = script.ProcessBlock();
if (result.Type == Variable.VarType.BREAK || result.IsReturn || result.Type == Variable.VarType.CONTINUE)
{
script.SkipBlock();
script.Forward();
break;
}
if (!fallThrough)
{
//スタート地点に帰ってブロックを終わらせる
script.Pointer = startPointer;
script.SkipBlock();
if (needBreak && result.Type != Variable.VarType.BREAK && !result.IsReturn)
if (needBreak && result.Type != Variable.VarType.BREAK && !result.IsReturn && result.Type != Variable.VarType.CONTINUE)
{
throw new ScriptException("caseブロックはbreakまたはreturnで抜ける必要があります", Exceptions.CASE_BLOCK_MISSING_BREAK);
}
Expand Down Expand Up @@ -280,6 +286,10 @@ public static Variable While(ParsingScript script)
{
return result;
}
if (result.Type == Variable.VarType.CONTINUE)
{
continue;
}
}

return result;
Expand All @@ -301,6 +311,10 @@ public static Variable Do(ParsingScript script)
script.Pointer = startDoCondition;
break;
}
if (result.Type == Variable.VarType.CONTINUE)
{
continue;
}
script.Forward(Constants.WHILE.Length + 1);
Variable condResult = script.Execute(Constants.END_ARG_ARRAY);
stillValid = condResult.AsBool();
Expand Down Expand Up @@ -357,6 +371,10 @@ public static Variable For(ParsingScript script)
{
return result;
}
if (result.Type == Variable.VarType.CONTINUE)
{
continue;
}
loopScript.Execute(null, 0);
}

Expand Down Expand Up @@ -417,6 +435,10 @@ Variable ProcessEach(Variable current)
{
return result;
}
if (result.Type == Variable.VarType.CONTINUE)
{
continue;
}
}
break;
}
Expand All @@ -429,6 +451,10 @@ Variable ProcessEach(Variable current)
{
return result;
}
if (result.Type == Variable.VarType.CONTINUE)
{
continue;
}
}
break;
}
Expand All @@ -448,6 +474,10 @@ Variable ProcessEach(Variable current)
disposable?.Dispose();
return result;
}
if (result.Type == Variable.VarType.CONTINUE)
{
continue;
}
}
disposable?.Dispose();
break;
Expand Down
4 changes: 2 additions & 2 deletions Losetta.Runtime/Core/Alice.Core.Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static void Throw(ParsingScript script, string message)
public static void Throw(ParsingScript script, ExceptionObject exception)
{
var s = exception.MainScript ?? script;
throw new ScriptException(exception.Message, exception.ErrorCode, s);
throw new ScriptException(exception.Message, exception.Error, s);
}
[AliceFunction(Attribute = FunctionAttribute.FUNCT_WITH_SPACE)]
public static void Throw(ParsingScript script, string message, int errorCode)
Expand Down Expand Up @@ -175,7 +175,7 @@ public static Variable Return(ParsingScript script, Variable result = null)
script.SetDone();
if (result is null)
{
result = Variable.EmptyInstance;
result = new Variable(Variable.VarType.VOID);
}
result.IsReturn = true;

Expand Down
2 changes: 1 addition & 1 deletion Losetta.Runtime/Losetta.Runtime.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
<ApplicationIcon>alice_logo.ico</ApplicationIcon>
<Version>0.10.2</Version>
<Version>0.10.3</Version>
<Company>WSOFT</Company>
<Product>Losetta</Product>
<Title>Alice.Runtime</Title>
Expand Down
11 changes: 10 additions & 1 deletion Losetta/Binding/BindFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ namespace AliceScript.Binding
/// </summary>
public class BindFunction : FunctionBase
{
/// <summary>
/// BindFunctionを初期化します
/// </summary>
public BindFunction()
{
Run += BindFunction_Run;
Expand Down Expand Up @@ -55,7 +58,7 @@ private void BindFunction_Run(object sender, FunctionBaseEventArgs e)
}

/// <summary>
/// メソッドからBindFunctionを生成
/// メソッドからBindFunctionを生成します
/// </summary>
/// <param name="methodInfos">同じメソッド名のオーバーロード</param>
/// <param name="needBind">このメソッドをバインドするには属性が必要</param>
Expand Down Expand Up @@ -157,6 +160,12 @@ internal static BindFunction CreateBindFunction(HashSet<MethodInfo> methodInfos,

return func.Overloads.Count > 0 ? func : null;
}
/// <summary>
/// コンストラクタからBindFunctionを生成します
/// </summary>
/// <param name="constructors">同じクラスのコンストラクタ</param>
/// <param name="needBind">このメソッドをバインドするには属性が必要</param>
/// <returns>生成されたFunctionBase</returns>
internal static BindFunction CreateBindConstructor(ConstructorInfo[] constructors, bool needBind)
{
var func = new BindFunction();
Expand Down
4 changes: 3 additions & 1 deletion Losetta/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ public static string TypeToString(Variable.VarType type)
case Variable.VarType.BOOLEAN: return "BOOLEAN";
case Variable.VarType.BYTES: return "BYTES";
case Variable.VarType.UNDEFINED: return "UNDEFINED";
case Variable.VarType.VOID: return "VOID";
default: return "NONE";
}
}
Expand Down Expand Up @@ -438,7 +439,8 @@ public static bool TryParseType(string text, out Variable.VarType type)
case "CONTINUE": type = Variable.VarType.CONTINUE; break;
case "DELEGATE": type = Variable.VarType.DELEGATE; break;
case "VARIABLE": type = Variable.VarType.VARIABLE; break;
default: type = Variable.VarType.NONE; return false;
case "VOID": type = Variable.VarType.VOID; break;
default: type = Variable.VarType.VARIABLE; return false;
}
return true;
}
Expand Down
16 changes: 10 additions & 6 deletions Losetta/Functions/CustomFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public CustomFunction(string funcName,
m_returnType = returnType;
Run += CustomFunction_Run;

if (m_returnType == Variable.VarType.NONE)
if (m_returnType == Variable.VarType.VOID)
{
m_nullable = true;
}
Expand Down Expand Up @@ -185,14 +185,18 @@ private void CustomFunction_Run(object sender, FunctionBaseEventArgs e)
throw new ScriptException($"関数`{m_args.Length}`は引数`{m_args.Length}`を受取ることが出来ません。", Exceptions.TOO_MANY_ARGUREMENTS, e.Script);
}
Variable result = ARun(e.Args, e.Script, e.ClassInstance, e.CurentVariable);
if (m_nullable && m_returnType != Variable.VarType.VOID && result.IsNull())
{
// nullをとる場合は妥当なnull許容型に置き換える
result.Type = m_returnType;
}
if (m_nullable)
{
result.Nullable = true;
}
if (!(result.Type == Variable.VarType.VARIABLE && result.IsNull()) && (m_nullable || (!m_nullable && result.Nullable)) && !result.Type.HasFlag(m_returnType))
// if ((!m_nullable && result.Nullable) && !result.Type.HasFlag(m_returnType))
if ((m_returnType != Variable.VarType.VARIABLE && (!result.Type.HasFlag(m_returnType) || (!m_nullable && result.Nullable))) || (m_returnType == Variable.VarType.VOID && result.Type != Variable.VarType.VOID))
{
throw new ScriptException($"関数は宣言とは異なり{result.Type}{(m_nullable ? "?" : "")}型を返しました", Exceptions.TYPE_MISMATCH, m_parentScript);
throw new ScriptException($"関数は宣言とは異なり{result.Type}{(result.Nullable ? "?" : "")}型を返しました", Exceptions.TYPE_MISMATCH, m_parentScript);
}
e.Return = result;
}
Expand Down Expand Up @@ -259,7 +263,7 @@ private void RegisterArguments(List<Variable> args,
{
for (int i = 0; i < args.Count; i++)
{
if (args[i].Type == Variable.VarType.NONE ||
if (args[i].Type == Variable.VarType.VOID ||
(!string.IsNullOrWhiteSpace(args[i].CurrentAssign) &&
args[i].CurrentAssign != m_args[i]))
{
Expand Down Expand Up @@ -390,7 +394,7 @@ public Variable ARun(List<Variable> args = null, ParsingScript script = null,

if (result is null || (!result.IsReturn && !m_forceReturn))
{
result = Variable.EmptyInstance;
result = new Variable(Variable.VarType.VOID);
}

result.IsReturn = false;
Expand Down
25 changes: 21 additions & 4 deletions Losetta/Functions/FunctionBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

namespace AliceScript.Functions
{
/// <summary>
/// AliceScriptで使用できる関数を表します
/// </summary>
public class FunctionBase : ParserFunction
{

Expand Down Expand Up @@ -61,7 +64,7 @@ public Variable Evaluate(List<Variable> args, ParsingScript script, AliceScriptC
{
ex.OriginalScript = script.OriginalScript;
}
ex.Return = Variable.EmptyInstance;
ex.Return = new Variable(Variable.VarType.VOID);
ex.Script = script;
ex.Keywords = Keywords;
ex.ClassInstance = instance;
Expand Down Expand Up @@ -340,7 +343,15 @@ public static void Remove(FunctionBase func, string name = "", ParsingScript scr
/// </summary>
public static List<string> Functions => new List<string>(ParserFunction.s_functions.Keys);
}
/// <summary>
/// FunctionBaseがイベントを伝えるためのハンドラ
/// </summary>
/// <param name="sender">送り主のオブジェクト</param>
/// <param name="e">イベントの情報</param>
public delegate void FunctionBaseEventHandler(object sender, FunctionBaseEventArgs e);
/// <summary>
/// 関数の呼び出し時の情報を提供します
/// </summary>
public class FunctionBaseEventArgs : EventArgs
{
/// <summary>
Expand All @@ -359,13 +370,17 @@ public class FunctionBaseEventArgs : EventArgs
public List<Variable> Args { get; set; }

/// <summary>
/// [使用されていません]
/// ObjectResultを使用する場合はTrue、それ以外の場合はfalse
/// 今後は、ObjectResulではなく関数バインドを使用してください
/// </summary>
[Obsolete("関数バインドを使用してください")]
public bool UseObjectResult { get; set; }

/// <summary>
/// [使用されていません]
/// オブジェクトをそのまま戻り値として返す場合に使用するプロパティ
/// 今後は、ObjectResulではなく関数バインドを使用してください
/// </summary>
[Obsolete("関数バインドを使用してください")]
public object ObjectResult { get; set; }

/// <summary>
Expand All @@ -382,7 +397,9 @@ public class FunctionBaseEventArgs : EventArgs
/// この関数の呼び出し時に同時に指定されたキーワードを表します
/// </summary>
public HashSet<string> Keywords { get; set; }

/// <summary>
/// 呼び出し元が所属するクラスのインスタンス
/// </summary>
public AliceScriptClass.ClassInstance ClassInstance { get; set; }
}

Expand Down
2 changes: 1 addition & 1 deletion Losetta/Losetta.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
<ApplicationIcon>alice_logo.ico</ApplicationIcon>
<Version>0.10.2</Version>
<Version>0.10.3</Version>
<Company>WSOFT</Company>
<Product>Losetta</Product>
<Title>Alice.Runtime</Title>
Expand Down
11 changes: 8 additions & 3 deletions Losetta/Objects/ExceptionObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,25 @@ public class ExceptionObject
public string Message { get; set; }
public string HelpLink { get; set; }
public string Source { get; set; }
public Exceptions ErrorCode { get; set; }
public Exceptions Error { get; set; }
public int ErrorCode
{
get => (int)Error;
set => Error = (Exceptions)value;
}
public ParsingScript MainScript { get; set; }
public ExceptionObject(string message, Exceptions errorcode, ParsingScript mainScript, string source = null, string helplink = null)
{
Message = message;
ErrorCode = errorcode;
Error = errorcode;
MainScript = mainScript;
Source = source;
HelpLink = helplink;
}
public ExceptionObject() { }
public override string ToString()
{
return ErrorCode.ToString() + "(0x" + ((int)ErrorCode).ToString("x3") + ")" + (string.IsNullOrWhiteSpace(Message) ? string.Empty : ": " + Message);
return ErrorCode.ToString() + "(0x" + Error.ToString("x3") + ")" + (string.IsNullOrWhiteSpace(Message) ? string.Empty : ": " + Message);
}
}
}
2 changes: 1 addition & 1 deletion Losetta/Objects/VariableCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public List<Variable> Tuple
/// <returns>追加できればTrue、それ以外の場合はFalse。</returns>
private bool CanAdd(Variable item)
{
if (Type is not null && Type.Type == Variable.VarType.NONE && item is not null)
if (Type is not null && Type.Type == Variable.VarType.VOID && item is not null)
{
if (Type.Type != item.Type)
{
Expand Down
2 changes: 1 addition & 1 deletion Losetta/Parsing/Utils.Parsing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public static Variable GetProperties(ParsingScript script)
break;
}
}
if (result.Type == Variable.VarType.NONE)
if (result.Type == Variable.VarType.VOID)
{
result.Type = Variable.VarType.CUSTOM;
}
Expand Down
12 changes: 8 additions & 4 deletions Losetta/Variable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class Variable : ScriptObject, IComparable<Variable>
public enum VarType
{
VARIABLE = 0,
NONE = 1,
VOID = 1,
UNDEFINED = 2,
NUMBER = 4,
CHAR = 8,
Expand Down Expand Up @@ -394,7 +394,7 @@ public bool IsNull()
switch (Type)
{
case VarType.VARIABLE:
case VarType.NONE: return true;
case VarType.VOID: return true;
default: return false;
case VarType.ARRAY:
return Tuple is null;
Expand Down Expand Up @@ -816,7 +816,7 @@ public override bool Equals(object obj)
}
if (obj is Variable item)
{
if (item.Type == VarType.NONE)
if (item.Type == VarType.VOID)
{
return IsNull();
}
Expand Down Expand Up @@ -1197,6 +1197,10 @@ public virtual string AsString(bool isList = true,
bool sameLine = true,
int maxCount = -1)
{
if (IsNull())
{
return string.Empty;
}
switch (Type)
{
case VarType.BOOLEAN:
Expand Down Expand Up @@ -1330,7 +1334,7 @@ public void SetAsArray()
}

public int Count => Type == VarType.ARRAY ? m_tuple.Count :
Type == VarType.NONE ? 0 : 1;
Type == VarType.VOID ? 0 : 1;


public Variable SetProperty(string propName, Variable value, ParsingScript script, string baseName = "")
Expand Down
2 changes: 1 addition & 1 deletion alice/alice.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<ApplicationIcon>alice_logo.ico</ApplicationIcon>
<Version>0.10.2</Version>
<Version>0.10.3</Version>
<Title>Losetta.CLI</Title>
<Authors>WSOFT</Authors>
<Company>WSOFT</Company>
Expand Down

0 comments on commit af40e33

Please sign in to comment.