From 9f7628aded7662337e9e31d09c3d63c637aa8ba5 Mon Sep 17 00:00:00 2001 From: Luke Date: Sun, 31 Aug 2025 17:55:49 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E6=B7=BB=E5=8A=A0=E7=B1=BB=E7=BB=A7?= =?UTF-8?q?=E6=89=BF=E6=BC=94=E7=A4=BA=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- playground/Demo/Demo31/Main.snow | 56 ++++++++++++++++++++++++++++++++ playground/Demo/Demo31/OS.snow | 18 ++++++++++ 2 files changed, 74 insertions(+) create mode 100644 playground/Demo/Demo31/Main.snow create mode 100644 playground/Demo/Demo31/OS.snow diff --git a/playground/Demo/Demo31/Main.snow b/playground/Demo/Demo31/Main.snow new file mode 100644 index 0000000..0d31c7f --- /dev/null +++ b/playground/Demo/Demo31/Main.snow @@ -0,0 +1,56 @@ +module: Main + import: os + + // 父类 Person + struct: Person + fields: + declare name: int + init: + params: + name: int + body: + this.name = name + end body + end init + + function: getName + returns: int + body: + return this.name + end body + end function + end struct + + // 子类 Student 继承 Person + struct: Student extends Person + fields: + declare studentId: int + init: + params: + name: int + studentId: int + body: + super(name) // 调用父类构造函数 + this.studentId = studentId + end body + end init + + function: getStudentId + returns: int + body: + return this.studentId + end body + end function + end struct + + function: main + returns: void + body: + declare s: Student = new Student(123, 1001) + + // Student 拥有父类方法 + os.println(s.getName()) // 来自 Person → 123 + os.println(s.getStudentId()) // 来自 Student → 1001 + end body + end function +end module diff --git a/playground/Demo/Demo31/OS.snow b/playground/Demo/Demo31/OS.snow new file mode 100644 index 0000000..7c6de6f --- /dev/null +++ b/playground/Demo/Demo31/OS.snow @@ -0,0 +1,18 @@ +module: os + function: print + params: + declare i1: int + returns: void + body: + syscall("PRINT", i1) + end body + end function + function: println + params: + declare i1: int + returns: void + body: + syscall("PRINTLN", i1) + end body + end function +end module