From fdcef37be3fcf76009fac3a6e0e2edcd55b7d0f6 Mon Sep 17 00:00:00 2001
From: zengwenjie <1663900244@qq.com>
Date: Thu, 16 Oct 2025 10:47:09 +0800
Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E3=80=8CDodo=E3=80=8D?=
=?UTF-8?q?=E8=84=9A=E6=9C=AC=E7=9A=84=E5=AE=9A=E4=B9=89=E4=B8=8E=E6=9C=8D?=
=?UTF-8?q?=E5=8A=A1=E5=85=B3=E9=94=AE=E9=80=BB=E8=BE=91=E7=9A=84=E6=B5=8B?=
=?UTF-8?q?=E8=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
DeedyDesigner/Deedy.Testing/App.xaml.cs | 20 +
DeedyDesigner/Deedy.Testing/Dodo.cs | 1102 +++++++++++++++++++++++
2 files changed, 1122 insertions(+)
create mode 100644 DeedyDesigner/Deedy.Testing/Dodo.cs
diff --git a/DeedyDesigner/Deedy.Testing/App.xaml.cs b/DeedyDesigner/Deedy.Testing/App.xaml.cs
index cc36506..29ab6e5 100644
--- a/DeedyDesigner/Deedy.Testing/App.xaml.cs
+++ b/DeedyDesigner/Deedy.Testing/App.xaml.cs
@@ -1,6 +1,7 @@
using System.Configuration;
using System.Data;
using System.Windows;
+using Deedy.Testing;
namespace Deedy
{
@@ -9,6 +10,25 @@ namespace Deedy
///
public partial class App : Application
{
+ public App()
+ {
+ string script =
+@"
+VarP var1 111
+VarP var2 222
+Func Add var1 var2
+ LetP AddResult -1
+ math AddResult var1 var2 +
+ retu AddResult
+EndF
+
+Call Add var1 var2
+PopV result
+";
+ Todo todo = new Todo();
+ todo.Init(script);
+ todo.Redo();
+ }
}
}
diff --git a/DeedyDesigner/Deedy.Testing/Dodo.cs b/DeedyDesigner/Deedy.Testing/Dodo.cs
new file mode 100644
index 0000000..8a77aa4
--- /dev/null
+++ b/DeedyDesigner/Deedy.Testing/Dodo.cs
@@ -0,0 +1,1102 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Deedy.Testing
+{
+ ///
+ /// 解释执行「DodoScript」脚本的引擎
+ /// 仿照「C」语言执行逻辑实现
+ ///
+ public class Todo
+ {
+ ///
+ /// 运行模式
+ ///
+ public enum Mode
+ {
+ ///
+ /// 暂停运行状态
+ ///
+ Waiting,
+ ///
+ /// 正常运行状态
+ ///
+ Running,
+ ///
+ /// 当「Continue」或「Reentry」操作执行后的状态
+ ///
+ Reentry,
+ ///
+ /// 当「Break」或「Return」操作执行后的状态
+ ///
+ JumpOut,
+ }
+ ///
+ /// 脚本内部的方法定义
+ ///
+ public struct Def_FuncDefine(string name, int line)
+ {
+ public string Name = name;
+ public int Line = line;
+ }
+ ///
+ /// 外部方法的引用记录
+ ///
+ public struct Def_FuncImport(string name, Action> action)
+ {
+ public string Name = name;
+ public Action> Action = action;
+ }
+ ///
+ /// 脚本内方法调用记录
+ ///
+ public struct Def_FuncInvoke(int returnLine)
+ {
+ public int ReturnLine = returnLine;
+ public Dictionary LocalParams = [];
+ }
+ ///
+ /// 外部参数的引用记录
+ ///
+ public struct Def_ParamRefer(string name, object param)
+ {
+ public string Name = name;
+ public object Param = param;
+ }
+ ///
+ /// 当前要执行的脚本行号
+ ///
+ private int Control_CurrentLine = 0;
+ ///
+ /// 脚本调度周期,等待指令每次的等待时间
+ ///
+ private int Control_WakeupCycle = 10;
+ ///
+ /// 每条指令在开始执行时的时间,由脚本主解释逻辑负责记录
+ ///
+ private DateTime Control_CurrentTime = DateTime.Now;
+ ///
+ /// 脚本运行模式,用于外部控制正在执行的脚本的行为
+ ///
+ public Mode RunningMode { get; set; } = Mode.Waiting;
+ ///
+ /// 脚本内容
+ ///
+ private readonly List Script = [];
+
+ ///
+ /// 脚本内部的自定义方法映射表
+ ///
+ private List FuncDefines = [];
+ ///
+ /// 外部引用的可执行方法映射表
+ ///
+ private readonly List FuncImports = [];
+
+ ///
+ /// 脚本内方法调用栈
+ ///
+ private Stack Invoke_FuncStack = [];
+ ///
+ /// 调用外部方法时使用的参数栈
+ ///
+ private Stack