From 46ed385c78ededa03b1144d765788d303dfeb318 Mon Sep 17 00:00:00 2001 From: chai2010 Date: Sat, 25 Oct 2025 20:23:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20wz=20=E7=94=9F=E5=91=BD?= =?UTF-8?q?=E6=B8=B8=E6=88=8F=E4=BB=A3=E7=A0=81=E7=9A=84=E4=B8=AD=E6=96=87?= =?UTF-8?q?=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/images/logo/logo1010.txt | 7 ++++ internal/app/applogo/print_logo.go | 22 +++++++++- internal/types/resolver.go | 2 +- waroot/examples/life-game-wz/src/生命游戏.wz | 42 ++++++++++---------- waroot/examples/wz/hello/hello3.wz | 9 +++++ waroot/src/apple/add.wa | 4 ++ waroot/src/image/image_impl.wa | 4 ++ waroot/src/js/canvas/canvas.wa | 4 ++ waroot/src/src.go | 3 +- waroot/src/假死门/画布/画布.wz | 6 ++- waroot/src/图像/图像.wz | 15 +++++++ waroot/src/图像/颜色/颜色.wz | 6 ++- waroot/src/菠萝/readme.md | 3 ++ waroot/src/菠萝/菠萝.wz | 10 +++++ 14 files changed, 110 insertions(+), 27 deletions(-) create mode 100644 docs/images/logo/logo1010.txt create mode 100644 waroot/examples/wz/hello/hello3.wz create mode 100644 waroot/src/图像/图像.wz create mode 100644 waroot/src/菠萝/readme.md create mode 100644 waroot/src/菠萝/菠萝.wz diff --git a/docs/images/logo/logo1010.txt b/docs/images/logo/logo1010.txt new file mode 100644 index 00000000..e9249227 --- /dev/null +++ b/docs/images/logo/logo1010.txt @@ -0,0 +1,7 @@ ++---+ +---+ +| o | | o | +| +----+ | +| | +| 1010 | +| | ++------------+ diff --git a/internal/app/applogo/print_logo.go b/internal/app/applogo/print_logo.go index ba3906b0..039d6962 100644 --- a/internal/app/applogo/print_logo.go +++ b/internal/app/applogo/print_logo.go @@ -13,9 +13,12 @@ func PrintLogoSvg() { } func PrintLogo(more bool) { - if is1024Day() { + switch { + case is1010Day(): + fmt.Print(logo1010) + case is1024Day(): fmt.Print(logo1024) - } else { + default: fmt.Print(logo) } @@ -25,6 +28,11 @@ func PrintLogo(more bool) { fmt.Println() } +func is1010Day() bool { + _, month, day := time.Now().Date() + return month == 10 && day == 10 +} + func is1024Day() bool { _, month, day := time.Now().Date() return month == 10 && day == 24 @@ -40,6 +48,16 @@ const logo = ` +------------+ ` +const logo1010 = ` ++---+ +---+ +| o | | o | +| +----+ | +| | +| 1010 | +| | ++------------+ +` + const logo1024 = ` +---+ +---+ | o | | o | diff --git a/internal/types/resolver.go b/internal/types/resolver.go index 3f43d074..566d017b 100644 --- a/internal/types/resolver.go +++ b/internal/types/resolver.go @@ -440,7 +440,7 @@ func (check *Checker) collectObjects() { case *ast.TypeSpec: obj := NewTypeName(s.Name.Pos(), pkg, s.Name.Name, nil) obj.setNode(s) - check.declarePkgObj(s.Name, obj, &declInfo{file: fileScope, typ: s.Type, alias: false}) + check.declarePkgObj(s.Name, obj, &declInfo{file: fileScope, typ: s.Type, alias: s.Assign.IsValid()}) if s.Doc == nil { if d.Lparen == token.NoPos && d.Doc != nil { diff --git a/waroot/examples/life-game-wz/src/生命游戏.wz b/waroot/examples/life-game-wz/src/生命游戏.wz index d0a862ee..4d93b627 100644 --- a/waroot/examples/life-game-wz/src/生命游戏.wz +++ b/waroot/examples/life-game-wz/src/生命游戏.wz @@ -1,10 +1,10 @@ 注: 版权 @2025 life 作者。保留所有权利。 -引入 "image" -引入 "image/color" -引入 "js/canvas" -引入 "数学/随机数" 引入 "洪荒" +引入 "图像" +引入 "图像/颜色" +引入 "假死门/画布" +引入 "数学/随机数" 全局: 宽度 :整型 = 0 @@ -12,27 +12,27 @@ 暂停中 :布尔 = 假 - 细胞状态甲 :*image·Gray = 空 - 细胞状态乙 :*image·Gray = 空 - 细胞状态快照 :*image·RGBA = 空 + 细胞状态甲 :*图像·灰色图像 = 空 + 细胞状态乙 :*图像·灰色图像 = 空 + 细胞状态快照 :*图像·彩色图像 = 空 - 画布上下文 :canvas·Context2D + 画布上下文 :画布·平面上下文 完毕 函数·初始化(宽, 高, 随机火种: 整型): 宽度 = 宽 高度 = 高 - 细胞状态甲 = image·NewGray(宽, 高) - 细胞状态乙 = image·NewGray(宽, 高) - 细胞状态快照 = image·NewRGBA(宽, 高) + 细胞状态甲 = 图像·新建灰色图像(宽, 高) + 细胞状态乙 = 图像·新建灰色图像(宽, 高) + 细胞状态快照 = 图像·新建彩色图像(宽, 高) 随机数·点火(长整型(随机火种)) - 循环 i := 0; i < 宽度*高度; i++: + 循环 位 := 0; 位 < 宽度*高度; 位++: 如果 (随机数·整数() % 2) != 0: - 细胞状态甲·Pix[i] = color·Gray(1) + 细胞状态甲·Pix[位] = 颜色·灰色(1) 否则: - 细胞状态甲·Pix[i] = color·Gray(0) + 细胞状态甲·Pix[位] = 颜色·灰色(0) 完毕 完毕 完毕 @@ -61,16 +61,16 @@ 如果 细胞状态甲·Pix[竖*宽度+横] != 0: 找辙 邻居数量: 有辙 2, 3: - 细胞状态乙·Pix[竖*宽度+横] = color·Gray(1) + 细胞状态乙·Pix[竖*宽度+横] = 颜色·灰色(1) 没辙: - 细胞状态乙·Pix[竖*宽度+横] = color·Gray(0) + 细胞状态乙·Pix[竖*宽度+横] = 颜色·灰色(0) 完毕 否则: 找辙 邻居数量: 有辙 3: - 细胞状态乙·Pix[竖*宽度+横] = color·Gray(1) + 细胞状态乙·Pix[竖*宽度+横] = 颜色·灰色(1) 没辙: - 细胞状态乙·Pix[竖*宽度+横] = color·Gray(0) + 细胞状态乙·Pix[竖*宽度+横] = 颜色·灰色(0) 完毕 完毕 完毕 @@ -92,15 +92,15 @@ 循环 横 := 0; 横 < 宽度; 横++: 循环 竖 := 0; 竖 < 高度; 竖++: 如果 细胞状态甲·Pix[竖*宽度+横] != 0: - 细胞状态快照·SetRGBA(横, 竖, 0xFF0000FF) + 细胞状态快照·设置彩色(横, 竖, 0xFF0000FF) 否则: - 细胞状态快照·SetRGBA(横, 竖, 0xFFFFFFFF) + 细胞状态快照·设置彩色(横, 竖, 0xFFFFFFFF) 完毕 完毕 完毕 注: 绘制到 Canvas - 画布上下文·PutImageData( + 画布上下文·装填图像数据( 洪荒·原生(细胞状态快照·Pix), 0, 0, 0, 0, 单精(宽度), 单精(高度), ) diff --git a/waroot/examples/wz/hello/hello3.wz b/waroot/examples/wz/hello/hello3.wz new file mode 100644 index 00000000..faf07cf5 --- /dev/null +++ b/waroot/examples/wz/hello/hello3.wz @@ -0,0 +1,9 @@ +注: 这是注释 + +引入 "菠萝" + +函数·主控: + 甲 := 菠萝·创建我的整型(100) + 乙 := 菠萝·创建我的整型(42) + 输出(甲 + 乙) +完毕 diff --git a/waroot/src/apple/add.wa b/waroot/src/apple/add.wa index 7c7c46aa..64e1bb3d 100644 --- a/waroot/src/apple/add.wa +++ b/waroot/src/apple/add.wa @@ -15,6 +15,10 @@ type MyInt :struct { V: int } +func NewMyInt(x: int) => MyInt { + return MyInt{V: x} +} + #wa:generic AddF64 func MyInt.Add(a: int) { this.V += a diff --git a/waroot/src/image/image_impl.wa b/waroot/src/image/image_impl.wa index 161ecc9d..fbcef2a3 100644 --- a/waroot/src/image/image_impl.wa +++ b/waroot/src/image/image_impl.wa @@ -34,3 +34,7 @@ func RGBA.RGBAAt(x, y: int) => color.RGBA { func RGBA.SetRGBA(x, y: int, c: color.RGBA) { this.Pix[y*this.Width+x] = c } + +func RGBA.设置彩色(x, y: int, c: color.RGBA) { + this.Pix[y*this.Width+x] = c +} diff --git a/waroot/src/js/canvas/canvas.wa b/waroot/src/js/canvas/canvas.wa index 29848cfe..8a38046b 100644 --- a/waroot/src/js/canvas/canvas.wa +++ b/waroot/src/js/canvas/canvas.wa @@ -611,6 +611,10 @@ func Context2D.PutImageData(imagedata: []u8, dx, dy: f32, dirtyX, dirtyY, dirtyW jsPutImageData(this.GetHandle(), imagedata, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight) } +func Context2D.装填图像数据(imagedata: []u8, dx, dy: f32, dirtyX, dirtyY, dirtyWidth, dirtyHeight: f32) { + jsPutImageData(this.GetHandle(), imagedata, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight) +} + /***************************************** * * * Synthesis * diff --git a/waroot/src/src.go b/waroot/src/src.go index b28bcfbf..ed77617c 100644 --- a/waroot/src/src.go +++ b/waroot/src/src.go @@ -190,7 +190,8 @@ var stdPkgs = []string{ } var wzStdPkgs = []string{ - "书", + "菠萝", // apple + "书", // fmt "图像", // image "图像/颜色", // image/color "数学/随机数", // math/rand diff --git a/waroot/src/假死门/画布/画布.wz b/waroot/src/假死门/画布/画布.wz index 3d4e3830..ff06fb1d 100644 --- a/waroot/src/假死门/画布/画布.wz +++ b/waroot/src/假死门/画布/画布.wz @@ -3,6 +3,10 @@ 引入 "js/canvas" -函数·查询画布(代号: 字串) => (canvas·Canvas, 布尔): +类型·画布 = canvas·Canvas + +类型·平面上下文 = canvas·Context2D + +函数·查询画布(代号: 字串) => (画布, 布尔): 返回 canvas·QueryCanvas(代号) 完毕 diff --git a/waroot/src/图像/图像.wz b/waroot/src/图像/图像.wz new file mode 100644 index 00000000..3aab0b97 --- /dev/null +++ b/waroot/src/图像/图像.wz @@ -0,0 +1,15 @@ +注: Copyright (C) 2025 武汉凹语言科技有限公司 +注: SPDX-License-Identifier: MIT + +引入 "image" + +类型·灰色图像 = image·Gray +类型·彩色图像 = image·RGBA + +函数·新建灰色图像(宽, 高: 整型) => *灰色图像: + 返回 image·NewGray(宽, 高) +完毕 + +函数·新建彩色图像(宽, 高: 整型) => *彩色图像: + 返回 image·NewRGBA(宽, 高) +完毕 diff --git a/waroot/src/图像/颜色/颜色.wz b/waroot/src/图像/颜色/颜色.wz index d4d00801..3d164ebc 100644 --- a/waroot/src/图像/颜色/颜色.wz +++ b/waroot/src/图像/颜色/颜色.wz @@ -1,2 +1,6 @@ -注: Copyright (C) 2024 武汉凹语言科技有限公司 +注: Copyright (C) 2025 武汉凹语言科技有限公司 注: SPDX-License-Identifier: MIT + +引入 "image/color" + +类型·灰色 = color.Gray diff --git a/waroot/src/菠萝/readme.md b/waroot/src/菠萝/readme.md new file mode 100644 index 00000000..f3870725 --- /dev/null +++ b/waroot/src/菠萝/readme.md @@ -0,0 +1,3 @@ +# 菠萝包 + +这是 apple 包的中文版本。 diff --git a/waroot/src/菠萝/菠萝.wz b/waroot/src/菠萝/菠萝.wz new file mode 100644 index 00000000..d2ffae96 --- /dev/null +++ b/waroot/src/菠萝/菠萝.wz @@ -0,0 +1,10 @@ +注: Copyright (C) 2025 武汉凹语言科技有限公司 +注: SPDX-License-Identifier: MIT + +引入 "apple" + +类型·我的整型 = apple·MyInt + +函数·创建我的整型(某: 整型) => 我的整型: + 返回 apple·NewMyInt(某) +完毕