From f0e3bfe05ce3d9368a85bbfa2dc5b781b8667956 Mon Sep 17 00:00:00 2001 From: Luke Date: Sun, 31 Aug 2025 17:38:23 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E6=B7=BB=E5=8A=A0=20Demo30?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- playground/Demo/Demo30/Main.snow | 66 ++++++++++++++++++++++++++++++++ playground/Demo/Demo30/OS.snow | 18 +++++++++ 2 files changed, 84 insertions(+) create mode 100644 playground/Demo/Demo30/Main.snow create mode 100644 playground/Demo/Demo30/OS.snow diff --git a/playground/Demo/Demo30/Main.snow b/playground/Demo/Demo30/Main.snow new file mode 100644 index 0000000..fda54c3 --- /dev/null +++ b/playground/Demo/Demo30/Main.snow @@ -0,0 +1,66 @@ +module: Main + import: os + struct: Address + fields: + declare country: int + declare city: int + init: + params: + country: int + city: int + body: + this.country = country + this.city = city + end body + end init + + function: getCity + returns: int + body: + return this.city + end body + end function + end struct + + struct: Person + fields: + declare name: int + declare addr: Address + init: + params: + name: int + addr: Address + body: + this.name = name + this.addr = addr + end body + end init + + function: getName + returns: int + body: + return this.name + end body + end function + + function: getAddr + returns: Address + body: + return this.addr + end body + end function + end struct + + function: main + returns: void + body: + // 初始化 Person 和 Address 的实例 + declare p: Person = new Person(123, new Address(1, 2)) + declare a: Person = p + os.println(a.getName()) // -> 123 + os.println(a.getAddr().getCity()) // -> 2 + + end body + end function + +end module diff --git a/playground/Demo/Demo30/OS.snow b/playground/Demo/Demo30/OS.snow new file mode 100644 index 0000000..7c6de6f --- /dev/null +++ b/playground/Demo/Demo30/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