From 7d18b88172171d2c8f98d91fef3fc4a0a099f896 Mon Sep 17 00:00:00 2001 From: zengwenjie <1663900244@qq.com> Date: Thu, 16 Oct 2025 12:12:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=B2=E7=BB=8F=E5=AE=8C=E6=88=90=E3=80=8CDo?= =?UTF-8?q?do=E3=80=8D=E8=84=9A=E6=9C=AC=E5=AF=B9=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E6=96=B9=E6=B3=95=E5=8F=82=E6=95=B0=E7=9A=84=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DeedyDesigner/Deedy.Testing/App.xaml.cs | 6 +-- DeedyDesigner/Deedy.Testing/Dodo.cs | 51 ++++++++++++++++--------- 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/DeedyDesigner/Deedy.Testing/App.xaml.cs b/DeedyDesigner/Deedy.Testing/App.xaml.cs index 29ab6e5..f2ccd89 100644 --- a/DeedyDesigner/Deedy.Testing/App.xaml.cs +++ b/DeedyDesigner/Deedy.Testing/App.xaml.cs @@ -16,13 +16,13 @@ namespace Deedy @" VarP var1 111 VarP var2 222 -Func Add var1 var2 +Func Add var1x var2x LetP AddResult -1 - math AddResult var1 var2 + + math AddResult @var1x 777 + @var2 - @var2x - retu AddResult EndF -Call Add var1 var2 +Call Add @var1 99 PopV result "; Todo todo = new Todo(); diff --git a/DeedyDesigner/Deedy.Testing/Dodo.cs b/DeedyDesigner/Deedy.Testing/Dodo.cs index 8a77aa4..e7139c8 100644 --- a/DeedyDesigner/Deedy.Testing/Dodo.cs +++ b/DeedyDesigner/Deedy.Testing/Dodo.cs @@ -374,7 +374,7 @@ namespace Deedy.Testing string cmd = Pre_Hand(this.Script[index]); if (cmd == "whil") { - string cmdArgs = this.Script[index][4..].Trim(); + string cmdArgs = this.Script[index][cmd.Length..].Trim(); if (this.CmdP_Cond(cmdArgs)) this.Control_CurrentLine = index + 1; return; @@ -451,8 +451,8 @@ namespace Deedy.Testing { object paramValue = this.Val_Variant(paramDefine[1]); - if (!Param_Global.TryAdd(paramDefine[0], paramValue)) - this.Param_Global[paramDefine[0]] = paramValue; + if (!Param_Global.TryAdd(paramDefine[0].TrimStart('@'), paramValue)) + this.Param_Global[paramDefine[0].TrimStart('@')] = paramValue; } this.Control_CurrentLine++; } @@ -471,8 +471,8 @@ namespace Deedy.Testing { object paramValue = this.Val_Variant(paramDefine[1]); - if (!funcHandle.LocalParams.TryAdd(paramDefine[0], paramValue)) - funcHandle.LocalParams[paramDefine[0]] = paramValue; + if (!funcHandle.LocalParams.TryAdd(paramDefine[0].TrimStart('@'), paramValue)) + funcHandle.LocalParams[paramDefine[0].TrimStart('@')] = paramValue; } else this.CmdI_VarP(cmdArgs ?? ""); } @@ -556,7 +556,7 @@ namespace Deedy.Testing break; } } - this.FuncDefines.Add(new Def_FuncDefine(funcName, this.Control_CurrentLine + 1)); + this.FuncDefines.Add(new Def_FuncDefine(funcName, this.Control_CurrentLine)); this.Control_CurrentLine = index + 1; return; } @@ -577,13 +577,23 @@ namespace Deedy.Testing return; } string funcName = args[0]; - for (int i = 1; i < args.Length; i++) this.Invoke_ArgsStack.Push(this.ParamGetter(args[i], 0)); + for (int i = 1; i < args.Length; i++) this.Invoke_ArgsStack.Push(this.Val_Variant(args[i])); foreach (var func in this.FuncDefines) { if (func.Name == funcName) { this.Invoke_FuncStack.Push(new Def_FuncInvoke(this.Control_CurrentLine + 1)); - this.Control_CurrentLine = func.Line; + //TODO:根据「Func」指令定义声明局部变量 + string[] funcArgs = this.Script[func.Line].Split(' ', options: StringSplitOptions.RemoveEmptyEntries)[2..]; + Array.Reverse(funcArgs); + for (int i = 0; i < funcArgs.Length; i++) + { + if (this.Invoke_ArgsStack.TryPop(out var arg)) + { + this.CmdI_LetP($"{funcArgs[i]} {arg}"); + } + } + this.Control_CurrentLine = func.Line + 1; break; } } @@ -595,12 +605,12 @@ namespace Deedy.Testing /// 方法名及参数表,参数表可以为空 protected void CmdI_Exec(string cmdArgs) { - string[] argParts = (cmdArgs ?? "").Split(' ', options: StringSplitOptions.RemoveEmptyEntries); - if (argParts.Length > 0) + string[] args = (cmdArgs ?? "").Split(' ', options: StringSplitOptions.RemoveEmptyEntries); + if (args.Length > 0) { - string procName = argParts[0]; - for (int i = 1; i < argParts.Length; i++) - this.Invoke_ArgsStack.Push(this.ParamGetter(argParts[i], 0)); + string procName = args[0]; + for (int i = 1; i < args.Length; i++) + this.Invoke_ArgsStack.Push(this.ParamGetter(args[i], 0)); foreach (var func in this.FuncImports) { if (func.Name == procName) @@ -618,8 +628,12 @@ namespace Deedy.Testing /// 弹出数据的存放位置 protected void CmdS_PopV(string cmdArgs) { - if (this.Invoke_ArgsStack.TryPop(out var param)) - this.ParamSetter(cmdArgs, param); + string[] args = (cmdArgs ?? "").Split(' ', options: StringSplitOptions.RemoveEmptyEntries); + foreach (var arg in args) + { + if (this.Invoke_ArgsStack.TryPop(out var param)) + this.ParamSetter(arg, param); + } this.Control_CurrentLine++; } /// @@ -628,7 +642,8 @@ namespace Deedy.Testing /// 值表达式:支持bool、double、@ParamName|string protected void CmdS_Push(string cmdArgs) { - this.Invoke_ArgsStack.Push(this.Val_Variant(cmdArgs)); + string[] args = (cmdArgs ?? "").Split(' ', options: StringSplitOptions.RemoveEmptyEntries); + foreach (var arg in args) this.Invoke_ArgsStack.Push(this.Val_Variant(arg)); this.Control_CurrentLine++; } /// @@ -665,7 +680,7 @@ namespace Deedy.Testing case ">>": Math_ShR(stack); break; case "<<": Math_ShL(stack); break; default: - stack.Push(this.Val_Double(this.ParamGetter(cmdParts[index], 0))); + stack.Push(this.Val_Double(cmdParts[index])); break; } index++; @@ -1046,6 +1061,7 @@ namespace Deedy.Testing private void ParamSetter(string paramName, object paramValue) { //HACK:暂时不支持代码块级的局部变量 + paramName = paramName.TrimStart('@'); if (this.Invoke_FuncStack.TryPeek(out var funcHandle)) { if (funcHandle.LocalParams.ContainsKey(paramName)) @@ -1080,6 +1096,7 @@ namespace Deedy.Testing private object ParamGetter(string paramName, object @default) { //HACK:暂时不支持代码块级的局部变量 + paramName = paramName.TrimStart('@'); if (this.Invoke_FuncStack.TryPeek(out var funcHandle)) { if (funcHandle.LocalParams.TryGetValue(paramName, out object? localValue))