test: 重构 Student 类并简化 Main 函数

This commit is contained in:
Luke 2025-09-01 15:33:33 +08:00
parent fefb44cda7
commit 5c48f4038b

View File

@ -1,56 +1,55 @@
module: main module: main
struct: Student extends Person import: os
fields:
declare studentId: int
init:
params:
name: int
studentId: int
body:
super(name)
this.studentId = studentId
end body
end init
// 新增:无参数构造 struct: Student
init: fields:
params: declare name: int
body: declare studentId: int
super(0)
this.studentId = 0
end body
end init
// 新增:只带 name init:
init: params:
params: name: int
name: int studentId: int
body: body:
super(name) this.name = name
this.studentId = -1 this.studentId = studentId
end body end body
end init end init
function: getStudentId init:
returns: int params:
body: body:
return this.studentId this.name = 0
end body this.studentId = 0
end function end body
end struct end init
function: main init:
returns: void params:
body: name: int
declare a: Student = new Student(123, 1001) body:
declare b: Student = new Student() this.name = name
declare c: Student = new Student(88) this.studentId = -1
os.println(a.getName()) // 123 end body
os.println(a.getStudentId()) // 1001 end init
os.println(b.getName()) // 0
os.println(b.getStudentId()) // 0 function: getStudentId
os.println(c.getName()) // 88 returns: int
os.println(c.getStudentId()) // -1 body:
end body return this.studentId
end function end body
end module 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)
println(a.getStudentId())
println(b.getStudentId())
println(b.getStudentId())
end body
end function
end module