test: 添加自定义类型字段嵌套示例

- 新增 Main.snow 文件,定义了 Address 和 Person 两个结构体- 在 Person 结构体中使用 Address 类型的字段,实现类型嵌套
- 添加 OS.snow 文件,提供基本的打印功能- 此示例展示了如何在 SNOBOL 中使用自定义类型进行字段嵌套
This commit is contained in:
Luke 2025-08-30 14:25:11 +08:00
parent cbd8b24c4c
commit 4b90f15371
2 changed files with 63 additions and 0 deletions

View File

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

View 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