test: 添加 Demo30
This commit is contained in:
parent
c99614869f
commit
f0e3bfe05c
66
playground/Demo/Demo30/Main.snow
Normal file
66
playground/Demo/Demo30/Main.snow
Normal file
@ -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
|
||||
18
playground/Demo/Demo30/OS.snow
Normal file
18
playground/Demo/Demo30/OS.snow
Normal file
@ -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
|
||||
Loading…
x
Reference in New Issue
Block a user