test: 更新以测试新功能

This commit is contained in:
Luke 2025-08-30 17:04:00 +08:00
parent 4b90f15371
commit f00d99d748

View File

@ -1,15 +1,13 @@
module: Main module: Main
import: os
// 一个很简单的结构体,只有内建类型字段
struct: Address struct: Address
fields: fields:
declare country: string declare country: int
declare city: string declare city: int
// 构造函数(可要可不要,不影响触发点)
init: init:
params: params:
country: string country: int
city: string city: int
body: body:
this.country = country this.country = country
this.city = city this.city = city
@ -17,28 +15,35 @@ module: Main
end init end init
end struct end struct
// 在这里做“嵌套字段”Person.addr 的类型是 Address
struct: Person struct: Person
fields: fields:
declare name: string declare name: int
declare addr: Address // ← 触发点:自定义类型出现在字段类型位置 declare addr: Address
// 可选构造(同样不影响触发点)
init: init:
params: params:
name: string name: int
addr: Address addr: Address
body: body:
this.name = name this.name = name
this.addr = addr this.addr = addr
end body end body
end init end init
function: getName
returns: int
body:
return this.name
end body
end function
end struct end struct
// 主函数可以是空体,避免其它解析干扰
function: main function: main
returns: void returns: void
body: body:
// 什么都不做;关键在于上面的“嵌套字段”声明 // 初始化 Person 和 Address 的实例
declare p: Person = new Person(123, new Address(1, 2))
os.print(p.getName) // 打印 name
end body end body
end function end function