test: 增加 Demo32
This commit is contained in:
parent
981a1eacdb
commit
783be100e7
56
playground/Demo/Demo32/Main.snow
Normal file
56
playground/Demo/Demo32/Main.snow
Normal file
@ -0,0 +1,56 @@
|
||||
module: main
|
||||
struct: Student extends Person
|
||||
fields:
|
||||
declare studentId: int
|
||||
init:
|
||||
params:
|
||||
name: int
|
||||
studentId: int
|
||||
body:
|
||||
super(name)
|
||||
this.studentId = studentId
|
||||
end body
|
||||
end init
|
||||
|
||||
// 新增:无参数构造
|
||||
init:
|
||||
params:
|
||||
body:
|
||||
super(0)
|
||||
this.studentId = 0
|
||||
end body
|
||||
end init
|
||||
|
||||
// 新增:只带 name
|
||||
init:
|
||||
params:
|
||||
name: int
|
||||
body:
|
||||
super(name)
|
||||
this.studentId = -1
|
||||
end body
|
||||
end init
|
||||
|
||||
function: getStudentId
|
||||
returns: int
|
||||
body:
|
||||
return this.studentId
|
||||
end body
|
||||
end function
|
||||
end struct
|
||||
|
||||
function: main
|
||||
returns: void
|
||||
body:
|
||||
declare a: Student = new Student(123, 1001)
|
||||
declare b: Student = new Student()
|
||||
declare c: Student = new Student(88)
|
||||
os.println(a.getName()) // 123
|
||||
os.println(a.getStudentId()) // 1001
|
||||
os.println(b.getName()) // 0
|
||||
os.println(b.getStudentId()) // 0
|
||||
os.println(c.getName()) // 88
|
||||
os.println(c.getStudentId()) // -1
|
||||
end body
|
||||
end function
|
||||
end module
|
||||
18
playground/Demo/Demo32/OS.snow
Normal file
18
playground/Demo/Demo32/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