Compare commits

...

163 Commits
v0.5.0 ... main

Author SHA1 Message Date
5b3d807bbc
!67 release: 合并 v0.8.0 版本至 main 分支
Merge pull request !67 from Luke/release/v0.8.0
2025-08-27 07:44:23 +00:00
44b2ebb64a chore: 优化多平台打包 2025-08-27 15:24:58 +08:00
eb7e2e7e93 chore: 更新项目版本至 0.8.0
- 修改 .env 文件中的 SNOW_VERSION 从 0.7.0 到 0.8.0
- 更新 Gitee 问题模板中的软件版本选项
- 修改 pom.xml 中的项目版本号
- 更新 README.md 中的项目版本徽章链接
2025-08-27 14:52:30 +08:00
77eddb83f4
!65 enhancement: 支持字符串转义与 Unicode
Merge pull request !65 from Luke/feature/add-escape-characters
2025-08-27 03:17:00 +00:00
4181ff8ae2 refactor: 移除 StringEscape 类中未使用的 escape 方法
- 删除了 StringEscape 类中的 escape 方法,该方法用于将普通字符串编码为可安全存储的转义字符串
- 保留了unescape方法,并简化了其文档注释
2025-08-27 10:44:44 +08:00
49b5e61e8e feat: 增加字符串字面量的转义符和 Unicode 转义解析
- 引入 StringEscape 工具类用于字符串转义
- 在解析字符串字面量时,去除首尾引号
- 对字符串内部内容进行转义符和 Unicode 转义解析
2025-08-27 10:43:34 +08:00
e75a60026d test: 新增 Demo26 演示程序 2025-08-27 10:42:11 +08:00
83eb29fa3c chore: 更新测试配置文件
- 在测试配置文件中添加了 Demo21、Demo22、Demo23、Demo24 和 Demo25 应用
2025-08-27 10:41:34 +08:00
bc512fd02d feat: 添加字符串转义/反转义工具类
- 新增 StringEscape 类,提供编译期和运行期的字符串转义/反转义功能
- 支持常见控制字符、特殊字符和 Unicode 字符的转义/反转义
- 适用于 .water指令文件的保存和虚拟机执行时的字符串还原
2025-08-27 10:41:19 +08:00
0bbd82e9ce chore: 删除 Run 配置文件 2025-08-27 10:39:28 +08:00
2fc2a93414 feat: 增强引用推送指令功能
- 支持字符串字面量和数组字面量的解析
- 添加对不同数据类型(如浮点数、长整型等)的解析支持
- 优化了代码结构,提高了可读性和可维护性
- 增加了对 Unicode 逃逸序列的支持
- 添加了详细的类和方法注释,提高了文档质量
2025-08-27 10:39:21 +08:00
9bdc6245bf fix: 修复字符串常量在 VM 代码中的表示问题
- 在 LoadConstGenerator 中添加字符串转义功能,确保字符串常量在 VM 代码中正确表示
- 优化 formatConst 方法,对字符串常量进行转义处理
- 新增 escape 方法,用于字符串转义,包括控制字符和非 ASCII 字符的处理
2025-08-27 10:35:23 +08:00
16ba11c391
!64 feature: 实现私有函数(下划线开头仅限本模块访问)语义检查
Merge pull request !64 from Luke/feature/add-function-access-control
2025-08-26 10:12:30 +00:00
19e473e93c chore: 添加 Demo25运行配置 2025-08-26 18:09:15 +08:00
5537a448e8 test: 添加 Demo25 示例项目 2025-08-26 18:09:01 +08:00
caa62b0bfb feat: 增加模块私有函数访问控制
- 新增规则:以"_"开头的函数名只允许在本模块访问,禁止跨模块访问
- 在 CallExpressionAnalyzer 中实现该规则的检查逻辑
2025-08-26 18:08:46 +08:00
3595631e2c
!63 feat: 增强语义分析与全局常量处理
Merge pull request !63 from Luke/feature/add-constant
2025-08-26 09:31:01 +00:00
b033d53d28 test: Demo24 增加更多测试用例 2025-08-26 17:30:15 +08:00
8eda4fcbce chore: 修改 Demo24 配置文件 2025-08-26 17:29:51 +08:00
b02af0728a test: 修改 Demo24 2025-08-26 16:59:25 +08:00
b058ee4526 refactor: 优化全局变量处理和常量折叠逻辑
- 过滤与函数参数重名的全局声明,避免命名冲突
- 优化常量折叠逻辑,支持跨模块常量优化- 修复字符串字面量和布尔字面量的处理
- 优化代码结构,提高可读性和可维护性
2025-08-26 16:29:29 +08:00
71cbb3a737 test: 增加 Demo 24 2025-08-26 16:22:53 +08:00
ac0d3b9785 chore: 添加 Demo23 和 Demo24 的运行配置文件 2025-08-26 16:22:28 +08:00
f69dd85365 test: 增加 Demo23 2025-08-26 14:40:45 +08:00
c412d1194b feat: 增加全局符号表支持
- 在 ModuleInfo 类中添加 SymbolTable 类型的 globals 字段
- 实现 getGlobals 和 setGlobals 方法,用于获取和设置全局符号表
2025-08-26 14:33:45 +08:00
f39aece9cf feat: 支持模块成员访问的语义分析
- 实现了跨模块常量和全局变量访问的语义分析- 能根据目标模块的全局符号表返回准确的类型信息- 完全支持跨模块类型推断
- 对非模块成员访问的情况增加了错误处理
2025-08-26 14:32:58 +08:00
439304c86a feat: 增强全局常量处理与字面量解析
- 支持整数、浮点数、字符串和布尔字面量的解析
- 添加类型后缀支持(b/s/l/f/d),并进行相应的类型转换
- 优化数字字面量的解析逻辑,支持科学计数法和下划线分隔符
- 改进字面量提取工具的文档注释,明确支持的类型和转换规则
2025-08-26 14:32:13 +08:00
6e31185519 feat: 重构 FunctionChecker 采用两遍扫描策略
- 设计核心:采用“两遍扫描”方案,彻底解决跨模块全局变量/常量类型推断和引用依赖问题
  - 第一遍:为所有模块预先构建并注册全局符号表(globals)
  - 第二遍:在全局符号表全部就绪后,依次分析所有模块的函数体
-功能职责:
  - 遍历所有模块,先建立 globals,再遍历并检查所有函数体语句
  - 为每个函数体构建完整符号表,并注册参数变量
  - 分发每条语句到对应 StatementAnalyzer进行类型检查和错误校验
  - 自动检查非 void 函数 return 完备性
  - 记录所有语义错误,便于前端高亮和诊断
2025-08-26 14:29:37 +08:00
1c86c1dce7 feat: 改进 IR 指令生成逻辑并支持浮点数
- 新增对 long、float 和 double 类型常量加载的支持
- 优化二元运算指令生成,支持不同类型的操作数
- 实现基于变量类型的 move 指令,提高类型兼容性
- 简化控制流指令的生成逻辑
- 优化代码结构,提高可读性和可维护性
2025-08-26 14:01:19 +08:00
1f8176d15e test: 修改 Demo22 2025-08-26 11:55:25 +08:00
f8a331809f chore: 移除 Demo22.run.xml 中的调试参数 2025-08-26 11:55:10 +08:00
0d6c6cef5a feat: 添加成员表达式语义分析器
- 实现了 MemberExpressionAnalyzer 类,用于分析成员访问表达式
- 目前仅支持 ModuleName.constOrVar 形式的跨模块常量/全局变量访问
- 不支持对象成员访问,如 a.b.c- 类型降级为 int,后续由 IR 阶段进行常量折叠
2025-08-26 11:52:47 +08:00
06bb647c83 feat: 实现全局常量预加载及跨模块常量折叠
- 新增 preloadGlobals 方法,扫描所有模块节点,将常量注册到全局常量表- 支持整数、浮点数、字符串和布尔字面量的直接评估
- 优化了 IRProgram 的构建过程,增加了对全局常量的处理
2025-08-26 11:44:04 +08:00
cc66eee75f feat: 支持跨模块全局常量查找
- 新增 externalConsts 字典用于存放跨模块导入的全局常量
- 修改 getConstValue 方法以支持查找外部常量
- 添加 importExternalConst 方法用于导入外部常量
2025-08-26 11:37:05 +08:00
1e2b0e4e0d feat: 新增全局常量表支持跨模块常量管理
- 添加 GlobalConstTable 类,用于编译期间跨模块常量查询和折叠
- 提供注册常量、查询常量和获取所有常量的功能
- 保证线程安全,支持并发操作- 常量的 key采用“模块名.常量名”的格式,确保唯一性
2025-08-26 11:35:08 +08:00
1a0c3a38cb feat: 更新 FunctionBuilder构建流程与文档
- 在全局函数表中注册函数名与返回类型
- 初始化 IRFunction 实例与 IRContext 上下文对象
- 自动导入全局常量(包括跨模块 const 变量)到当前作用域
- 根据函数返回类型设置表达式推断的默认字面量类型后缀
- 遍历声明形参,每个参数分配虚拟寄存器,并注册到作用域
- 依次转换函数体中的每条语句为 IR指令
- 函数体转换完成后,清理默认类型后缀
2025-08-26 11:32:48 +08:00
fcdc3a49f8 feat: 支持成员访问表达式
- 添加对成员访问表达式(如 ModuleA.a)的支持
- 实现 buildMember 方法来处理成员表达式节点
- 增加对全局常量和作用域内常量的处理逻辑
2025-08-26 11:30:20 +08:00
139c42a90e feat: 实现成员访问表达式分析器
- 替换 UnsupportedExpressionAnalyzer 为 MemberExpressionAnalyzer
2025-08-26 11:29:03 +08:00
2dfcc4c95e chore: 更新项目构建配置 2025-08-26 09:52:14 +08:00
91aef32a42 feat: 添加常量符号类型并完善文档注释
- 在 SymbolKind 枚举中添加 CONSTANT 类型,用于表示只读、不可变的公开常量- 完善了各符号类型的文档注释,明确其用途和特点
- 优化了代码格式和段落结构,提高了代码可读性
2025-08-26 01:45:00 +08:00
18c9cbad7b feat: 增加常量声明支持并优化变量声明节点
- 在 DeclarationNode 类中添加 isConst 字段,用于表示是否为常量声明
-增加 isConst() 方法以判断声明是否为常量
- 优化类注释,明确变量和方法的作用
- 更新构造函数以支持常量声明
2025-08-26 01:44:16 +08:00
310e909359 test: 重构 Demo22 模块导入和文件布局
- 修改 Main.snow,移除未使用的 ModuleA 导入
- 将 ModuleA.snow 文件内容合并到 Main.snow 中
2025-08-26 01:43:27 +08:00
d10b7336c1 test: 重构示例代码 Demo22 2025-08-26 01:19:05 +08:00
3b39e9059b feat: 添加 const 关键字支持
- 在 TokenFactory 类中的 KEYWORDS 集合中添加了 "const" 关键字
- 此修改为编译器增加了对常量声明的支持,扩展了语言的功能
2025-08-26 01:18:24 +08:00
c44f8a4630 refactor: 优化 declare 语句的标识符处理逻辑
- 允许 declare 后跟随 const 关键字
-调整错误提示信息,使其更加清晰
- 优化代码结构,提高可读性
2025-08-26 01:18:07 +08:00
c4e9e541fb refactor: 优化全局变量声明的错误信息
-根据变量是否为常量,动态设置符号种类
-针对常量和变量分别定制重复声明的错误信息
2025-08-26 01:17:47 +08:00
da7d7bbcaa feat: 增加常量声明支持并优化声明语句解析
- 增加对常量声明的支持,通过匹配 "const" 关键字
-优化代码结构,使用 var tokens变量引用词法 token 流
- 简化代码逻辑,提高可读性和可维护性
2025-08-26 01:17:13 +08:00
d0c34ce1c2 feat: 优化声明语句语义分析
- 重构代码,优化分析流程,增加对常量声明的处理
-改进错误处理和日志输出,提高可读性和调试友好性
- 修复了一些潜在的语义分析问题,如常量未初始化的检查
2025-08-26 01:16:40 +08:00
1872221666 refactor: 优化赋值语句语义分析逻辑 2025-08-26 01:16:26 +08:00
0a35289ad0 chore: 添加 Demo22运行配置 2025-08-25 18:01:02 +08:00
5f42beaf2a test: 添加 Demo22 演示项目 2025-08-25 18:00:54 +08:00
b454d65962 chore: 新增 Demo14 的运行配置 2025-08-25 18:00:40 +08:00
d536bd17ce
!62 feat: 构建与发布脚本优化
Merge pull request !62 from Luke/feature/add-build-docker
2025-08-25 07:33:23 +00:00
3b3478ee30 style: 删除无用注释 2025-08-25 15:21:18 +08:00
926e87888c build: 优化打包脚本并移除并行构建总结 2025-08-25 15:20:36 +08:00
f7db4fcce8 chore: 添加 build-release-all.ps1 运行配置 2025-08-25 13:47:20 +08:00
9afc1caac7 build: 移除构建失败时的冗余错误提示 2025-08-25 13:47:08 +08:00
2a9d2b7f5f chore: 修改脚本名词 2025-08-25 13:43:38 +08:00
f11303f0e8 build: 添加 Linux 和 Windows 平台的发布脚本配置 2025-08-25 13:41:40 +08:00
7dd273759a build: 实现 Windows 和 Linux并行构建脚本
- 新增 build-parallel.ps1脚本,用于同时执行 Windows 和 Linux 构建任务
- 实现了日志实时输出和错误处理功能
- 添加了构建结果摘要和错误代码处理
2025-08-25 13:41:26 +08:00
e626553a9c build: 降级 SNOW_VERSION 至 0.7.0 2025-08-25 13:18:01 +08:00
b2c0b986c4 build: 更新版本号并重构发布脚本
-重构 release-linux.ps1 脚本,添加版本号读取和输出路径定义
- 新增 release-windows.ps1 脚本,实现 Windows 版本的构建和打包
- 添加 dotenv.ps1工具脚本,用于统一解析 .env 文件
2025-08-25 13:17:51 +08:00
a16f0ac059 chore: 添加 Linux 版本导出脚本和相关配置
- 新增 .env 文件和生成脚本
- 更新 docker-compose.yml 和 Dockerfile 以支持 Linux 版本导出
- 添加 PowerShell 脚本生成 .env 文件
- 实现 Linux 版本导出的完整流程
2025-08-25 12:32:10 +08:00
d3646c86ec chore: 增加docker自动构建 2025-08-24 22:02:54 +08:00
39dff9efc5
!61 release: 合并 v0.7.0 版本至 main 分支
Merge pull request !61 from Luke/release/v0.7.0
2025-08-24 04:15:25 +00:00
80efd7c357 feat: 添加 os.snow系统库模块 2025-08-24 12:13:23 +08:00
99345ddd19 chore: 更新项目版本至0.7.0 2025-08-24 12:05:30 +08:00
df07531edc chore: 更新 bug issue 模板中的软件版本选项
将 v0.6.0 版本替换为 v0.7.0版本,以反映软件的最新版本。
2025-08-24 12:05:15 +08:00
5511978ed8
!60 refactor: 移除词法分析器中的调试代码
Merge pull request !60 from Luke/feature/del-tokens
2025-08-22 09:37:19 +00:00
3406e1a2dd refactor: 移除词法分析器中的调试代码 2025-08-22 17:34:53 +08:00
00f73ecb47
!56 refactor: 重构关键字
Merge pull request !56 from zhangxun/feature/refactor-keyword
2025-08-04 09:23:38 +00:00
e51ba01962
!58 fix: 省略模块函数调用前缀,语义分析依然判定函数存在
Merge pull request !58 from zhangxun/bugfix/module-function-call-prefix
2025-08-04 09:00:21 +00:00
zhangxun
a9b4a6682a fix: 省略模块函数调用前缀,语义分析依然判定函数存在 2025-08-04 16:37:04 +08:00
zhangxun
6c5bafb3e9
!57 docs: 移除废弃的字面量后缀 i、d
Merge pull request !57 from zhangxun/bugfix/abandoned-numerical-suffixes
2025-08-04 07:56:50 +00:00
zhangxun
8d04397f32 docs: 移除废弃的字面量后缀 i、d 2025-08-04 15:26:00 +08:00
zhangxun
7898505717 docs: update README.md 2025-08-04 15:20:30 +08:00
5fdb86cd1b
!55 feature: 增强错误定位
Merge pull request !55 from zhangxun/feature/enhancement-error-location
2025-08-04 07:15:07 +00:00
zhangxun
60adecf808 Merge remote-tracking branch 'origin/feature/refactor-keyword' into feature/refactor-keyword 2025-08-04 15:08:50 +08:00
zhangxun
4ae77434dc docs: 更新文档 2025-08-04 15:08:29 +08:00
zhangxun
582ba2ce27 test: 重构 Demo 2025-08-04 15:08:29 +08:00
zhangxun
359c65228d test: 重构 BugFarm 2025-08-04 15:08:28 +08:00
zhangxun
3e7e5f2dad feat: 支持标准 URL 格式 2025-08-04 15:01:11 +08:00
zhangxun
9a61798d81 docs: 更新文档 2025-08-04 14:52:24 +08:00
zhangxun
9f3b3ad860 refactor: 重构 Demo 2025-08-04 14:52:13 +08:00
zhangxun
62f58cd83a refactor: 重构 BugFarm 2025-08-04 14:52:02 +08:00
zhangxun
a8cf93671e refactor: 重构标准库 2025-08-04 14:51:24 +08:00
zhangxun
d11822f4ba refactor: 重构模板代码 2025-08-04 14:50:10 +08:00
zhangxun
87560db20d refactor: 重构关键字 2025-08-04 14:49:39 +08:00
zhangxun
3a2a1363e6 feat: 增强错误定位 2025-08-04 13:45:23 +08:00
d54a2c59b6
!54 feat: 禁止全局变量重复声明
Merge pull request !54 from Luke/bugfix/fix-global-redeclare-error
2025-08-03 15:25:48 +00:00
4eb1aff553 Merge branch 'dev' into bugfix/fix-global-redeclare-error 2025-08-03 00:49:18 +08:00
80ee450b41
!53 feat: 支持一维及多维数组类型和字面量,重构调用指令生成逻辑
Merge pull request !53 from Luke/feature/add-support-for-array-syntax
2025-08-02 16:48:02 +00:00
f876f66414 chore: 添加 Bug6 运行配置文件 2025-08-03 00:39:18 +08:00
2188171b63 test: 添加 Bug6 2025-08-03 00:39:12 +08:00
7fab3cc662 feat: 检查全局变量重复声明
- 在 FunctionChecker 类中增加了对全局变量重复声明的检查
- 如果全局变量已经存在,则添加语义错误信息
2025-08-03 00:36:34 +08:00
62f2baab03 chore: 添加 Demo21运行配置 2025-08-03 00:16:35 +08:00
60388f6846 test: 添加 Demo21 项目 2025-08-03 00:16:17 +08:00
7c242d998f test: 更新 Demo20 2025-08-03 00:08:56 +08:00
d3a85a24bf feat: 支持数组元素赋值操作
- 新增 __setindex_x 系列内置函数,用于数组元素赋值
- 实现了对 byte、short、int、long、float、double、boolean 和引用类型数组的支持
- 修改了 ExpressionBuilder 和 StatementBuilder以支持数组赋值语法
- 更新了 VirtualMachineEngine 和 SyscallCommand 以支持新的 ARR_SET系统调用
2025-08-03 00:08:28 +08:00
477591303a chore: 添加 Demo20运行配置文件 2025-08-02 19:53:55 +08:00
f4a269540a chore: 更新测试配置文件 2025-08-02 12:33:27 +08:00
cedc77cbc6 test: 修改 Demo20 2025-08-02 12:33:14 +08:00
f61cfa5638 fix: 修复常量类型在 VM 中的表示问题
- 为浮点数添加 f 后缀,避免在 VM 中被错误解释为双精度浮点数
- 为长整数添加 L 后缀,保留类型信息
- 双精度浮点数和整数使用默认格式输出
- 支持数组常量的递归序列化,保留类型信息
- 优化了常量生成逻辑,提高了代码可读性和维护性
2025-08-02 12:32:28 +08:00
f6c877a7a1 refactor: 调整代码格式和注释 2025-08-02 10:51:14 +08:00
6083c0b024 test: 将 print 函数替换为 os.print 2025-08-02 10:50:22 +08:00
b093f8db72 feat: 支持数组下标访问类型分派
- 扩展 __index_i 函数支持 byte、short、int、long、float、double、boolean等类型
- 新增 __index_b、__index_s、__index_l、__index_f、__index_d、__index_r 函数- 优化数组元素访问的 IR 生成逻辑,根据类型选择合适的函数
- 更新 VM 层的 ARR_GET 子命令处理逻辑,支持多种数据类型
2025-08-02 10:49:54 +08:00
4a84f37b20 test: 更新 Demo19 示例 2025-08-01 23:34:57 +08:00
2a6fa8034c chore: Demo19 添加调试参数 2025-08-01 23:34:40 +08:00
102e84bc01 feat: 重构并扩展调用指令生成逻辑
- 优化了 syscall、数组下标访问和普通函数调用的处理逻辑
- 新增对多维数组下标访问的支持
- 改进了字符串常量和寄存器的绑定机制
- 统一了参数加载和错误处理的代码
2025-08-01 23:33:31 +08:00
e5f23b77bd chore: 添加 Demo19运行配置文件 2025-08-01 18:36:15 +08:00
028561fc4f test: 添加 Demo19 项目 2025-08-01 18:36:06 +08:00
82f4ba1a6e feat: 支持数组类型及数组字面量
- 新增 ArrayLiteralNode 表示数组字面量表达式节点
- 实现 ArrayLiteralAnalyzer 进行数组字面量的语义分析
- 添加 ArrayType 表示数组类型,并支持多维数组
- 修改 Context 类,增加对数组类型的支持
- 更新 DeclarationStatementParser,支持多维数组类型的声明
- 在 CallGenerator 中添加对特殊函数 __index_i 的处理,用于数组索引操作
2025-08-01 18:34:03 +08:00
f1069d6e5d
!52 release: 合并 v0.6.0 版本至 main 分支
Merge pull request !52 from Luke/release/v0.6.0
2025-07-31 09:53:38 +00:00
ad11efe974 chore: 更新项目版本至 v0.6.0 2025-07-31 17:29:11 +08:00
736e088a91
!51 feat: 支持模块内函数调用自动补全为当前模块前缀
Merge pull request !51 from Luke/bugfix/fix-function-call
2025-07-31 06:35:25 +00:00
d77368bb13 chore: 添加 Bug5 运行配置文件 2025-07-31 14:17:46 +08:00
e1a7f3310c test: 添加 Bug5 模块进行操作系统交互测试 2025-07-31 14:17:28 +08:00
b7e9c8121e refactor: 重构 RetCommand 并添加日志记录
- 更新导入语句,明确导入模块
- 使用 LoggingUtils 替代 System.out.println 输出日志
- 添加换行符改善日志可读性
2025-07-31 14:11:09 +08:00
466b6ca2be refactor: 移除 VMCodeGenerator 中的冗余字段
- 删除了 VMCodeGenerator 类中不再使用的 currentFn 字段- 将 currentFn 作为局部变量在 generate 方法中使用
- 这个改动简化了类的结构,减少了冗余代码
2025-07-31 12:48:10 +08:00
1cb5951e68 chore: 添加 Bug4 运行配置 2025-07-31 12:45:49 +08:00
1d73fc298e test: 添加 Bug4 测试用例 2025-07-31 12:44:33 +08:00
156f2b76c4 test: 修改 Demo14 中的打印函数 2025-07-31 12:44:05 +08:00
8e26b57cde test: 修改 Demo15 中的打印函数 2025-07-31 12:44:01 +08:00
be8e57ef60 test: 修改 Demo16 中的打印函数 2025-07-31 12:43:55 +08:00
2c3c4089f8 test: 修改 Demo17 中的打印函数 2025-07-31 12:43:48 +08:00
cadace165a feat: 改进函数调用和模块处理机制
- 补充模块名以生成全限定函数名,增强模块间调用的准确性
- 重构 IRProgramBuilder 以更清晰地处理模块和函数
- 优化 VMCodeGenerator 和 VMProgramBuilder 以支持新的全限定名机制
2025-07-31 12:43:17 +08:00
15cd43a7d5
!49 enhancement: 优化数字字面量溢出的错误检测与提示
Merge pull request !49 from Luke/bugfix/int-literal-range-diagnostic
2025-07-30 16:29:58 +00:00
f3409f32ce chore: 添加 Bug3 运行配置 2025-07-31 00:26:56 +08:00
1293ac1f83 refactor: 优化数字字面量的语义分析与错误提示
- 重构了类型推断逻辑,支持更精确的类型判断
- 实现了智能的错误提示策略,根据不同情况给出具体建议
- 优化了范围校验逻辑,提高了代码的健壮性
- 改进了代码结构和注释,提高了可读性和可维护性
2025-07-31 00:26:44 +08:00
9a2b5d5e4e test: 移除 Bug3测试中的溢出声明 2025-07-30 12:03:57 +08:00
fdeaa36366 feat: 增强数字字面量的语义分析和错误提示
- 添加类型推断和范围校验逻辑,支持 byte、short、int、long、float 和 double 类型
- 实现溢出和格式错误的统一处理,提供详细的错误提示
- 优化代码结构,增加私有方法以提高可读性和可维护性
2025-07-30 12:03:41 +08:00
3dfc8b63c8 test: 添加整数溢出测试用例 2025-07-30 11:54:34 +08:00
30fa84604b test: 重构 Bug2 示例程序 2025-07-30 11:50:58 +08:00
025ea75f08
!48 fix: 变量声明初始化寄存器别名导致内外层循环相互影响
Merge pull request !48 from Luke/bugfix/declare-init-aliasing-
2025-07-30 00:40:06 +00:00
c49b9f3df9
!47 feat: 引入了对 continue 语句的支持
Merge pull request !47 from Luke/feature/add-continue-operator
2025-07-30 00:39:58 +00:00
d932ba10f0 chore: 添加 Bug2 运行配置文件 2025-07-29 11:50:54 +08:00
f1699bfbbe test: 添加嵌套循环变量作用域测试代码 2025-07-29 11:50:32 +08:00
63835a1cce refactor: 优化变量声明语句的处理逻辑
- 澄清变量声明语句的处理流程,特别是带有初始值的情况
- 引入新分配的虚拟寄存器,确保变量和初始值表达式中的变量物理上独立
- 优化类型设置和作用域声明的顺序,提高代码的可读性和维护性
2025-07-29 11:50:06 +08:00
7c0a5e2524 docs: 优化 BreakStatementParser 类的文档注释 2025-07-29 11:23:01 +08:00
1eaaacdf8c chore: 添加 Demo18运行配置 2025-07-29 11:22:04 +08:00
2f16dd2749 test: 添加 Demo18 项目 2025-07-29 11:21:09 +08:00
7395256b5a feat: 添加 continue 语句支持
- 新增 ContinueNode、ContinueAnalyzer 和 ContinueStatementParser 类
- 在 AnalyzerRegistrar 中注册 continue 语句分析器
- 在 StatementBuilder 中添加 continue 语句的处理逻辑
- 更新 StatementParserFactory 和 TokenFactory 以支持 continue 关键字
2025-07-29 11:20:46 +08:00
187ec7e0e9 Merge branch 'main' into dev
# Conflicts:
#	.run/Demo1.run.xml
#	.run/Demo10.run.xml
#	.run/Demo11.run.xml
#	.run/Demo12.run.xml
#	.run/Demo13.run.xml
#	.run/Demo14.run.xml
#	.run/Demo2.run.xml
#	.run/Demo3.run.xml
#	.run/Demo4.run.xml
#	.run/Demo5.run.xml
#	.run/Demo6.run.xml
#	.run/Demo7.run.xml
#	.run/Demo8.run.xml
#	.run/Demo9.run.xml
#	src/main/java/org/jcnc/snow/pkg/tasks/CompileTask.java
2025-07-29 09:21:03 +08:00
c334dd3e28
!46 feat: loop 循环实现了 break 关键字的支持
Merge pull request !46 from Luke/feature/add-break-operator
2025-07-29 01:17:42 +00:00
5b15b2d170
!45 feat: 编译器补齐对 取模运算符 % 的完整支持
Merge pull request !45 from Luke/feature/add-mod-operator
2025-07-29 01:17:32 +00:00
21e4668b16 chore: 更新测试配置文件 2025-07-28 18:02:36 +08:00
5b8d7b98f3 chore: 更新 Demo16 和 Demo17 的运行配置 2025-07-28 18:01:41 +08:00
63e8b0163a test: 添加 Demo17 2025-07-28 18:01:06 +08:00
856d113b53 feat: 添加 break 语句支持
- 新增 BreakNode、BreakAnalyzer 和 BreakStatementParser 类
- 在 AnalyzerRegistrar 中注册 break 语句分析器
- 在 ASTPrinter 中添加 break 语句的打印处理
- 在 StatementBuilder 中实现 break 语句的 IR 构建逻辑
- 更新 StatementParserFactory 和 TokenFactory,支持 break 关键字
2025-07-28 18:00:41 +08:00
0cb2132e80 chore: 添加 Demo16运行配置 2025-07-28 17:35:49 +08:00
83b2122bd7 test: 添加 Demo16 2025-07-28 17:35:38 +08:00
9132c79c54 feat: 添加整数和浮点数的取余运算指令
- 在 IROpCode枚举中添加了 MOD_B8、MOD_S16、MOD_I32、MOD_L64、MOD_F32 和 MOD_D64 指令
- 更新了 IROpCodeMapper 映射,增加了取余运算的后端指令
- 修改了 IROpCodeMappings 类,添加了取余运算符与 IR 操作码的映射
2025-07-28 17:11:25 +08:00
12fc14e6e7
!44 feat: 实现 globals 关键字
Merge pull request !44 from Luke/feature/add-globals-keyword
2025-07-28 07:26:34 +00:00
52d811b6aa test: 更新 Demo15 文件 2025-07-28 15:25:09 +08:00
e0ad945202 test: 更新 Demo15 文件 2025-07-28 13:43:27 +08:00
2e4b76dfe2 chore: 更新测试配置文件
- 在测试配置文件中添加了 Demo14 和 Demo15 两个新的测试用例
2025-07-28 13:42:22 +08:00
9fb2dfae51 chore: 在 Demo 运行配置中添加 --debug 参数
- 在所有 Demo 示例的 run.xml 文件中添加 --debug 参数
- 此修改有助于在调试时提供更多详细信息
2025-07-28 13:39:55 +08:00
21ca6e6cab feat: 支持模块全局变量声明
- 在 ModuleNode 中添加 globals 字段,用于存储全局变量声明
- 实现 globals 区块的解析逻辑,支持全局变量的声明
- 更新 ASTJsonSerializer 以支持全局变量的序列化
- 修改 FunctionChecker 和 IRProgramBuilder 以支持全局变量
2025-07-28 13:39:33 +08:00
421eb0a0d9 chore: 修正 Debug 参数格式 2025-07-28 10:26:18 +08:00
f5a6443c8a refactor: 将调试标志从 -debug 改为 --debug 2025-07-28 10:25:13 +08:00
8d992001f9 chore: 添加 Demo15运行配置文件 2025-07-28 10:00:41 +08:00
4081d7d928 chore: 移除代码覆盖率配置 2025-07-28 10:00:30 +08:00
16a5d8d6ac test: 添加 Demo15 项目 2025-07-28 09:56:09 +08:00
175 changed files with 5650 additions and 1272 deletions

2
.env Normal file
View File

@ -0,0 +1,2 @@
# Auto-generated by build\tools\generate-dotenv.ps1
SNOW_VERSION=0.8.0

View File

@ -69,7 +69,7 @@ body:
attributes:
label: 软件版本/分支
options:
- v0.5.0
- v0.8.0
- main
- dev
- 其他

11
.run/Bug2.run.xml Normal file
View File

@ -0,0 +1,11 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Bug2" type="Application" factoryName="Application" folderName="BugFarm">
<option name="ALTERNATIVE_JRE_PATH" value="graalvm-ce-23" />
<option name="MAIN_CLASS_NAME" value="org.jcnc.snow.cli.SnowCLI" />
<module name="Snow" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/BugFarm/Bug2 -o target/Bug2" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>

11
.run/Bug3.run.xml Normal file
View File

@ -0,0 +1,11 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Bug3" type="Application" factoryName="Application" folderName="BugFarm">
<option name="ALTERNATIVE_JRE_PATH" value="graalvm-ce-23" />
<option name="MAIN_CLASS_NAME" value="org.jcnc.snow.cli.SnowCLI" />
<module name="Snow" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/BugFarm/Bug3 -o target/Bug3 --debug" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>

11
.run/Bug4.run.xml Normal file
View File

@ -0,0 +1,11 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Bug4" type="Application" factoryName="Application" folderName="BugFarm">
<option name="ALTERNATIVE_JRE_PATH" value="graalvm-ce-23" />
<option name="MAIN_CLASS_NAME" value="org.jcnc.snow.cli.SnowCLI" />
<module name="Snow" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/BugFarm/Bug4 -o target/Bug4 --debug" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>

11
.run/Bug5.run.xml Normal file
View File

@ -0,0 +1,11 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Bug5" type="Application" factoryName="Application" folderName="BugFarm">
<option name="ALTERNATIVE_JRE_PATH" value="graalvm-ce-23" />
<option name="MAIN_CLASS_NAME" value="org.jcnc.snow.cli.SnowCLI" />
<module name="Snow" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/BugFarm/Bug5 -o target/Bug5 " />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>

10
.run/Bug6.run.xml Normal file
View File

@ -0,0 +1,10 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Bug6" type="Application" factoryName="Application" folderName="BugFarm">
<option name="MAIN_CLASS_NAME" value="org.jcnc.snow.cli.SnowCLI" />
<module name="Snow" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/BugFarm/Bug6 -o target/Bug6 --debug" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>

View File

@ -3,7 +3,7 @@
<option name="ALTERNATIVE_JRE_PATH" value="graalvm-ce-23" />
<option name="MAIN_CLASS_NAME" value="org.jcnc.snow.cli.SnowCLI" />
<module name="Snow" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo1 -o target/Demo1 -debug" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo1 -o target/Demo1 --debug" />
<method v="2">
<option name="Make" enabled="true" />
</method>

View File

@ -3,7 +3,7 @@
<option name="ALTERNATIVE_JRE_PATH" value="graalvm-ce-23" />
<option name="MAIN_CLASS_NAME" value="org.jcnc.snow.cli.SnowCLI" />
<module name="Snow" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo10 -o target/Demo10 -debug" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo10 -o target/Demo10 --debug" />
<method v="2">
<option name="Make" enabled="true" />
</method>

View File

@ -3,7 +3,7 @@
<option name="ALTERNATIVE_JRE_PATH" value="graalvm-ce-23" />
<option name="MAIN_CLASS_NAME" value="org.jcnc.snow.cli.SnowCLI" />
<module name="Snow" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo11 -o target/Demo11 -debug" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo11 -o target/Demo11 --debug" />
<method v="2">
<option name="Make" enabled="true" />
</method>

View File

@ -3,7 +3,7 @@
<option name="ALTERNATIVE_JRE_PATH" value="graalvm-ce-23" />
<option name="MAIN_CLASS_NAME" value="org.jcnc.snow.cli.SnowCLI" />
<module name="Snow" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo12 -o target/Demo12 -debug" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo12 -o target/Demo12 --debug" />
<method v="2">
<option name="Make" enabled="true" />
</method>

View File

@ -2,7 +2,7 @@
<configuration default="false" name="Demo13" type="Application" factoryName="Application" folderName="Demo">
<option name="MAIN_CLASS_NAME" value="org.jcnc.snow.cli.SnowCLI" />
<module name="Snow" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo13 -o target/Demo13 -debug" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo13 -o target/Demo13 --debug" />
<method v="2">
<option name="Make" enabled="true" />
</method>

View File

@ -2,7 +2,15 @@
<configuration default="false" name="Demo14" type="Application" factoryName="Application" folderName="Demo">
<option name="MAIN_CLASS_NAME" value="org.jcnc.snow.cli.SnowCLI" />
<module name="Snow" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo14 -o target/Demo14 -debug" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo14 -o target/Demo14 --debug" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration default="false" name="Demo14" type="Application" factoryName="Application" folderName="Demo">
<option name="MAIN_CLASS_NAME" value="org.jcnc.snow.cli.SnowCLI" />
<module name="Snow" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo14 -o target/Demo14" />
<method v="2">
<option name="Make" enabled="true" />
</method>

10
.run/Demo15.run.xml Normal file
View File

@ -0,0 +1,10 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Demo15" type="Application" factoryName="Application" folderName="Demo">
<option name="MAIN_CLASS_NAME" value="org.jcnc.snow.cli.SnowCLI" />
<module name="Snow" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo15 -o target/Demo15 --debug" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>

10
.run/Demo16.run.xml Normal file
View File

@ -0,0 +1,10 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Demo16" type="Application" factoryName="Application" folderName="Demo">
<option name="MAIN_CLASS_NAME" value="org.jcnc.snow.cli.SnowCLI" />
<module name="Snow" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo16 -o target/Demo16 --debug" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>

10
.run/Demo17.run.xml Normal file
View File

@ -0,0 +1,10 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Demo17" type="Application" factoryName="Application" folderName="Demo">
<option name="MAIN_CLASS_NAME" value="org.jcnc.snow.cli.SnowCLI" />
<module name="Snow" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo17 -o target/Demo17 --debug" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>

10
.run/Demo18.run.xml Normal file
View File

@ -0,0 +1,10 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Demo18" type="Application" factoryName="Application" folderName="Demo">
<option name="MAIN_CLASS_NAME" value="org.jcnc.snow.cli.SnowCLI" />
<module name="Snow" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo18 -o target/Demo18 --debug" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>

10
.run/Demo19.run.xml Normal file
View File

@ -0,0 +1,10 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Demo19" type="Application" factoryName="Application" folderName="Demo">
<option name="MAIN_CLASS_NAME" value="org.jcnc.snow.cli.SnowCLI" />
<module name="Snow" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo19 -o target/Demo19 --debug" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>

View File

@ -3,7 +3,7 @@
<option name="ALTERNATIVE_JRE_PATH" value="graalvm-ce-23" />
<option name="MAIN_CLASS_NAME" value="org.jcnc.snow.cli.SnowCLI" />
<module name="Snow" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo2 -o target/Demo2 -debug" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo2 -o target/Demo2 --debug" />
<method v="2">
<option name="Make" enabled="true" />
</method>

10
.run/Demo20.run.xml Normal file
View File

@ -0,0 +1,10 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Demo20" type="Application" factoryName="Application" folderName="Demo">
<option name="MAIN_CLASS_NAME" value="org.jcnc.snow.cli.SnowCLI" />
<module name="Snow" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo20 -o target/Demo20 --debug" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>

10
.run/Demo21.run.xml Normal file
View File

@ -0,0 +1,10 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Demo21" type="Application" factoryName="Application" folderName="Demo">
<option name="MAIN_CLASS_NAME" value="org.jcnc.snow.cli.SnowCLI" />
<module name="Snow" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo21 -o target/Demo21 --debug" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>

10
.run/Demo22.run.xml Normal file
View File

@ -0,0 +1,10 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Demo22" type="Application" factoryName="Application" folderName="Demo">
<option name="MAIN_CLASS_NAME" value="org.jcnc.snow.cli.SnowCLI" />
<module name="Snow" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo22 -o target/Demo22" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>

10
.run/Demo23.run.xml Normal file
View File

@ -0,0 +1,10 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Demo23" type="Application" factoryName="Application" folderName="Demo">
<option name="MAIN_CLASS_NAME" value="org.jcnc.snow.cli.SnowCLI" />
<module name="Snow" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo23 -o target/Demo23 --debug" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>

10
.run/Demo24.run.xml Normal file
View File

@ -0,0 +1,10 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Demo24" type="Application" factoryName="Application" folderName="Demo">
<option name="MAIN_CLASS_NAME" value="org.jcnc.snow.cli.SnowCLI" />
<module name="Snow" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo24 -o target/Demo24" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>

10
.run/Demo25.run.xml Normal file
View File

@ -0,0 +1,10 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Demo25" type="Application" factoryName="Application" folderName="Demo">
<option name="MAIN_CLASS_NAME" value="org.jcnc.snow.cli.SnowCLI" />
<module name="Snow" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo25 -o target/Demo25" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>

View File

@ -3,7 +3,7 @@
<option name="ALTERNATIVE_JRE_PATH" value="graalvm-ce-23" />
<option name="MAIN_CLASS_NAME" value="org.jcnc.snow.cli.SnowCLI" />
<module name="Snow" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo3 -o target/Demo3 -debug" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo3 -o target/Demo3 --debug" />
<method v="2">
<option name="Make" enabled="true" />
</method>

View File

@ -3,7 +3,7 @@
<option name="ALTERNATIVE_JRE_PATH" value="graalvm-ce-23" />
<option name="MAIN_CLASS_NAME" value="org.jcnc.snow.cli.SnowCLI" />
<module name="Snow" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo4 -o target/Demo4 -debug" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo4 -o target/Demo4 --debug" />
<method v="2">
<option name="Make" enabled="true" />
</method>

View File

@ -3,7 +3,7 @@
<option name="ALTERNATIVE_JRE_PATH" value="graalvm-ce-23" />
<option name="MAIN_CLASS_NAME" value="org.jcnc.snow.cli.SnowCLI" />
<module name="Snow" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo5 -o target/Demo5 -debug" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo5 -o target/Demo5 --debug" />
<method v="2">
<option name="Make" enabled="true" />
</method>

View File

@ -3,7 +3,7 @@
<option name="ALTERNATIVE_JRE_PATH" value="graalvm-ce-23" />
<option name="MAIN_CLASS_NAME" value="org.jcnc.snow.cli.SnowCLI" />
<module name="Snow" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo6 -o target/Demo6 -debug" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo6 -o target/Demo6 --debug" />
<method v="2">
<option name="Make" enabled="true" />
</method>

View File

@ -3,7 +3,7 @@
<option name="ALTERNATIVE_JRE_PATH" value="graalvm-ce-23" />
<option name="MAIN_CLASS_NAME" value="org.jcnc.snow.cli.SnowCLI" />
<module name="Snow" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo7 -o target/Demo7 -debug" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo7 -o target/Demo7 --debug" />
<method v="2">
<option name="Make" enabled="true" />
</method>

View File

@ -3,7 +3,7 @@
<option name="ALTERNATIVE_JRE_PATH" value="graalvm-ce-23" />
<option name="MAIN_CLASS_NAME" value="org.jcnc.snow.cli.SnowCLI" />
<module name="Snow" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo8 -o target/Demo8 -debug" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo8 -o target/Demo8 --debug" />
<method v="2">
<option name="Make" enabled="true" />
</method>

View File

@ -3,7 +3,7 @@
<option name="ALTERNATIVE_JRE_PATH" value="graalvm-ce-23" />
<option name="MAIN_CLASS_NAME" value="org.jcnc.snow.cli.SnowCLI" />
<module name="Snow" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo9 -o target/Demo9 -debug" />
<option name="PROGRAM_PARAMETERS" value="compile run -d playground/Demo/Demo9 -o target/Demo9 --debug" />
<method v="2">
<option name="Make" enabled="true" />
</method>

View File

@ -1,7 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Run" type="CompoundRunConfigurationType">
<toRun name="build_project2tar.ps1" type="PowerShellRunType" />
<toRun name="Demo1" type="Application" />
<method v="2" />
</configuration>
</component>

View File

@ -0,0 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="build-project2tar.ps1" type="PowerShellRunType" factoryName="PowerShell" scriptUrl="$PROJECT_DIR$/build/build-project2tar.ps1" executablePath="C:/WINDOWS/System32/WindowsPowerShell/v1.0/powershell.exe">
<envs />
<method v="2" />
</configuration>
</component>

View File

@ -1,9 +1,9 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="build_project2tar.ps1" type="PowerShellRunType" factoryName="PowerShell" scriptUrl="$PROJECT_DIR$/build/build_project2tar.ps1" executablePath="C:/WINDOWS/System32/WindowsPowerShell/v1.0/powershell.exe">
<configuration default="false" name="build-release-all.ps1" type="PowerShellRunType" factoryName="PowerShell" scriptUrl="$PROJECT_DIR$/build/build-release-all.ps1" executablePath="C:/WINDOWS/System32/WindowsPowerShell/v1.0/powershell.exe">
<envs />
<method v="2" />
</configuration>
<configuration default="false" name="build_project2tar.ps1" type="PowerShellRunType" factoryName="PowerShell" scriptUrl="$PROJECT_DIR$/build/build_project2tar.ps1" executablePath="C:/WINDOWS/System32/WindowsPowerShell/v1.0/powershell.exe">
<configuration default="false" name="build-release-all.ps1" type="PowerShellRunType" factoryName="PowerShell" scriptUrl="$PROJECT_DIR$/build/build-release-all.ps1" executablePath="C:/WINDOWS/System32/WindowsPowerShell/v1.0/powershell.exe">
<envs />
<method v="2" />
</configuration>

View File

@ -0,0 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="release-linux.ps1" type="PowerShellRunType" factoryName="PowerShell" scriptUrl="$PROJECT_DIR$/build/release-linux.ps1" executablePath="C:/WINDOWS/System32/WindowsPowerShell/v1.0/powershell.exe">
<envs />
<method v="2" />
</configuration>
</component>

View File

@ -0,0 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="release-windows.ps1" type="PowerShellRunType" factoryName="PowerShell" scriptUrl="$PROJECT_DIR$/build/release-windows.ps1" executablePath="C:/WINDOWS/System32/WindowsPowerShell/v1.0/powershell.exe">
<envs />
<method v="2" />
</configuration>
</component>

View File

@ -5,7 +5,19 @@
<toRun name="Demo11" type="Application" />
<toRun name="Demo12" type="Application" />
<toRun name="Demo13" type="Application" />
<toRun name="Demo14" type="Application" />
<toRun name="Demo15" type="Application" />
<toRun name="Demo16" type="Application" />
<toRun name="Demo17" type="Application" />
<toRun name="Demo18" type="Application" />
<toRun name="Demo19" type="Application" />
<toRun name="Demo2" type="Application" />
<toRun name="Demo20" type="Application" />
<toRun name="Demo21" type="Application" />
<toRun name="Demo22" type="Application" />
<toRun name="Demo23" type="Application" />
<toRun name="Demo24" type="Application" />
<toRun name="Demo25" type="Application" />
<toRun name="Demo3" type="Application" />
<toRun name="Demo4" type="Application" />
<toRun name="Demo6" type="Application" />

57
Dockerfile Normal file
View File

@ -0,0 +1,57 @@
# Stage 1: 官方 GraalVM 社区版(已含 native-image
FROM ghcr.io/graalvm/native-image-community:24.0.2 AS builder
RUN microdnf install -y \
gcc gcc-c++ make git wget tar gzip which findutils maven \
&& microdnf clean all
# ---------- 构建 musl ----------
ARG MUSL_VER=1.2.5
WORKDIR /tmp
RUN wget -q https://musl.libc.org/releases/musl-${MUSL_VER}.tar.gz \
&& tar -xzf musl-${MUSL_VER}.tar.gz \
&& cd musl-${MUSL_VER} \
&& ./configure --prefix=/opt/musl-${MUSL_VER} --disable-shared \
&& make -j"$(nproc)" \
&& make install \
&& ln -s /opt/musl-${MUSL_VER} /opt/musl \
&& cd / && rm -rf /tmp/musl-${MUSL_VER}*
RUN ln -s /opt/musl/bin/musl-gcc /usr/local/bin/x86_64-linux-musl-gcc \
&& ln -s /opt/musl/bin/musl-gcc /usr/local/bin/x86_64-linux-musl-cc
ENV PATH="/opt/musl/bin:${PATH}"
ENV CC="musl-gcc"
ENV C_INCLUDE_PATH="/opt/musl/include"
ENV LIBRARY_PATH="/opt/musl/lib"
# ---------- 静态 zlib ----------
ARG ZLIB_VERSION=1.3.1
WORKDIR /tmp
RUN wget -q https://zlib.net/zlib-${ZLIB_VERSION}.tar.gz \
&& tar -xzf zlib-${ZLIB_VERSION}.tar.gz \
&& cd zlib-${ZLIB_VERSION} \
&& CC=musl-gcc ./configure --static --prefix=/opt/musl \
&& make -j"$(nproc)" \
&& make install \
&& cd / && rm -rf /tmp/zlib-${ZLIB_VERSION}*
# ---------- Maven 缓存优化 ----------
WORKDIR /app
COPY pom.xml ./
# 先拉依赖并缓存
RUN mvn -B -P native-linux dependency:go-offline
# ---------- 复制源码 ----------
COPY . /app
# ---------- 编译 native image ----------
RUN mvn -P native-linux -DskipTests clean package
# ------------------------------------------------------------
# Stage 2: 输出产物镜像(可以直接 cp 出二进制)
# ------------------------------------------------------------
FROM busybox AS export
WORKDIR /export
COPY --from=builder /app/org.jcnc.snow.cli.SnowCLI /export/Snow

View File

@ -11,8 +11,8 @@
<a href="https://gitee.com/jcnc-org/snow/blob/main/LICENSE">
<img src="https://img.shields.io/badge/%20license-Apache--2.0%20-blue" alt="">
</a>
<a href="https://gitee.com/jcnc-org/snow/tree/v0.5.0/">
<img src="https://img.shields.io/badge/version-v0.5.0-blue" alt="">
<a href="https://gitee.com/jcnc-org/snow/tree/v0.8.0/">
<img src="https://img.shields.io/badge/version-v0.8.0-blue" alt="">
</a>
</p>
@ -44,7 +44,7 @@ SnowVM) 的完整编译-执行链路。
Snow 语言受到 LLM 驱动代码生成趋势的启发,强调简单而清晰的语法和严格的类型系统,以帮助 LLM 更好地理解程序。
语言使用显式的 `module` 声明来组织代码,用 `function`,`parameter`,`return_type`,`body` 等关键字分隔不同代码块,语法结构固定且易读。此外,Snow
语言使用显式的 `module` 声明来组织代码,用 `function`,`params`,`returns`,`body` 等关键字分隔不同代码块,语法结构固定且易读。此外,Snow
实现了语义分析来检查变量作用域和类型一致性,在编译阶段捕获错误并确保生成的中间代码正确无误。这种自上而下的编译流程,使得代码设计和生成更加模块化,可解释,也有利于调试和优化。
相关背景: [心路历程](docs/Snow-Lang-Journey/Snow-Lang-Journey.md)
@ -111,7 +111,7 @@ Snow 语言受到 LLM 驱动代码生成趋势的启发,强调简单而清晰的
module: Main
import:Math
function: main
return_type: int
returns: int
body:
Math.add(6,1)
return 0
@ -135,7 +135,7 @@ Snow 语言受到 LLM 驱动代码生成趋势的启发,强调简单而清晰的
3 15 IDENTIFIER main
3 19 NEWLINE \n
4 9 KEYWORD return_type
4 9 KEYWORD returns
4 20 COLON :
4 22 TYPE int
4 25 NEWLINE \n
@ -174,10 +174,10 @@ Snow 语言受到 LLM 驱动代码生成趋势的启发,强调简单而清晰的
#### Math.snow
module: Math
function: add
parameter:
params:
declare n1: int
declare n2: int
return_type: int
returns: int
body:
return n1 + n2
end body
@ -195,7 +195,7 @@ Snow 语言受到 LLM 驱动代码生成趋势的启发,强调简单而清晰的
2 15 IDENTIFIER add
2 18 NEWLINE \n
3 9 KEYWORD parameter
3 9 KEYWORD params
3 18 COLON :
3 19 NEWLINE \n
@ -211,7 +211,7 @@ Snow 语言受到 LLM 驱动代码生成趋势的启发,强调简单而清晰的
5 25 TYPE int
5 28 NEWLINE \n
6 9 KEYWORD return_type
6 9 KEYWORD returns
6 20 COLON :
6 22 TYPE int
6 25 NEWLINE \n
@ -494,7 +494,7 @@ Snow 语言受到 LLM 驱动代码生成趋势的启发,强调简单而清晰的
```snow
module: Math
function: main
return_type: int
returns: int
body:
Math.factorial(6)
return 0
@ -502,9 +502,9 @@ module: Math
end function
function: factorial
parameter:
params:
declare n:int
return_type: int
returns: int
body:
declare num1:int = 1
loop:

View File

@ -0,0 +1,48 @@
# Set the tar package name
$tarName = "Snow.tar"
# Get the script's current directory (build folder)
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
# Get the parent directory (the project root)
$parentDir = Split-Path -Parent $scriptDir
# Set the full path to the tar package
$tarPath = Join-Path $parentDir $tarName
# Output message: starting to create tar package
Write-Output "Starting to create tar package: $tarName in $parentDir ..."
# Remove old tar package if it exists
if (Test-Path $tarPath) {
Write-Output "Found an old $tarName, removing it..."
Remove-Item $tarPath -Force
}
# Make sure the tar command is available
$tarCommand = "tar"
if (-not (Get-Command $tarCommand -ErrorAction SilentlyContinue)) {
Write-Error "❌ 'tar' command is not available. Please make sure 'tar' is installed and can be run from PowerShell."
exit 1
}
# Execute tar: change to org\jcnc directory and compress the snow folder
try {
# Build the command and run it
$tarCommandArgs = "-cf", $tarPath, "-C", "$scriptDir\..\src\main\java\org\jcnc", "snow"
Write-Output "Running tar command: tar $tarCommandArgs"
& $tarCommand @tarCommandArgs
} catch {
Write-Error "❌ Failed to create tar package. Error: $_"
exit 1
}
# Check if tar package was created successfully
if (Test-Path $tarPath) {
Write-Output "✅ Successfully created $tarName"
exit 0
} else {
Write-Error "❌ Creation failed. Please check the tar command and paths."
exit 1
}

129
build/build-release-all.ps1 Normal file
View File

@ -0,0 +1,129 @@
param(
[string]$LogDir = (Join-Path $PSScriptRoot 'target\parallel-logs')
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$winScript = Join-Path $PSScriptRoot 'release-windows.ps1'
$linScript = Join-Path $PSScriptRoot 'release-linux.ps1'
if (-not (Test-Path $winScript)) { throw "File not found: $winScript" }
if (-not (Test-Path $linScript)) { throw "File not found: $linScript" }
$winLogOut = [System.IO.Path]::GetTempFileName()
$winLogErr = [System.IO.Path]::GetTempFileName()
$linLogOut = [System.IO.Path]::GetTempFileName()
$linLogErr = [System.IO.Path]::GetTempFileName()
$winProc = Start-Process powershell.exe -ArgumentList @('-NoProfile','-ExecutionPolicy','Bypass','-File',"`"$winScript`"") `
-RedirectStandardOutput $winLogOut -RedirectStandardError $winLogErr -NoNewWindow -PassThru
$linProc = Start-Process powershell.exe -ArgumentList @('-NoProfile','-ExecutionPolicy','Bypass','-File',"`"$linScript`"") `
-RedirectStandardOutput $linLogOut -RedirectStandardError $linLogErr -NoNewWindow -PassThru
$winPosOut = 0
$winPosErr = 0
$linPosOut = 0
$linPosErr = 0
Write-Host "===== Build Started ====="
while (-not $winProc.HasExited -or -not $linProc.HasExited) {
# windows-release stdout
if (Test-Path $winLogOut) {
$size = (Get-Item $winLogOut).Length
if ($size -gt $winPosOut) {
$fs = [System.IO.File]::Open($winLogOut, [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read, [System.IO.FileShare]::ReadWrite)
$fs.Position = $winPosOut
$sr = New-Object System.IO.StreamReader($fs)
while (!$sr.EndOfStream) {
$line = $sr.ReadLine()
if ($line) { Write-Host "[windows-release][OUT] $line" }
}
$winPosOut = $fs.Position
$sr.Close()
$fs.Close()
}
}
# windows-release stderr
if (Test-Path $winLogErr) {
$size = (Get-Item $winLogErr).Length
if ($size -gt $winPosErr) {
$fs = [System.IO.File]::Open($winLogErr, [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read, [System.IO.FileShare]::ReadWrite)
$fs.Position = $winPosErr
$sr = New-Object System.IO.StreamReader($fs)
while (!$sr.EndOfStream) {
$line = $sr.ReadLine()
if ($line) { Write-Host "[windows-release][ERR] $line" -ForegroundColor Red }
}
$winPosErr = $fs.Position
$sr.Close()
$fs.Close()
}
}
# linux-release stdout
if (Test-Path $linLogOut) {
$size = (Get-Item $linLogOut).Length
if ($size -gt $linPosOut) {
$fs = [System.IO.File]::Open($linLogOut, [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read, [System.IO.FileShare]::ReadWrite)
$fs.Position = $linPosOut
$sr = New-Object System.IO.StreamReader($fs)
while (!$sr.EndOfStream) {
$line = $sr.ReadLine()
if ($line) { Write-Host "[linux-release][OUT] $line" }
}
$linPosOut = $fs.Position
$sr.Close()
$fs.Close()
}
}
# linux-release stderr
if (Test-Path $linLogErr) {
$size = (Get-Item $linLogErr).Length
if ($size -gt $linPosErr) {
$fs = [System.IO.File]::Open($linLogErr, [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read, [System.IO.FileShare]::ReadWrite)
$fs.Position = $linPosErr
$sr = New-Object System.IO.StreamReader($fs)
while (!$sr.EndOfStream) {
$line = $sr.ReadLine()
if ($line) { Write-Host "[linux-release][ERR] $line" -ForegroundColor Red }
}
$linPosErr = $fs.Position
$sr.Close()
$fs.Close()
}
}
Start-Sleep -Milliseconds 200
}
# After processes exit, print any remaining output
$tasks = @(
@{proc=$winProc; log=$winLogOut; tag='windows-release'; type='OUT'; skip=$winPosOut},
@{proc=$winProc; log=$winLogErr; tag='windows-release'; type='ERR'; skip=$winPosErr},
@{proc=$linProc; log=$linLogOut; tag='linux-release'; type='OUT'; skip=$linPosOut},
@{proc=$linProc; log=$linLogErr; tag='linux-release'; type='ERR'; skip=$linPosErr}
)
foreach ($item in $tasks) {
if (Test-Path $item.log) {
$fs = [System.IO.File]::Open($item.log, [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read, [System.IO.FileShare]::ReadWrite)
$fs.Position = $item.skip
$sr = New-Object System.IO.StreamReader($fs)
while (!$sr.EndOfStream) {
$line = $sr.ReadLine()
if ($line) {
if ($item.type -eq 'ERR') {
Write-Host "[$($item.tag)][ERR] $line" -ForegroundColor Red
} else {
Write-Host "[$($item.tag)][OUT] $line"
}
}
}
$sr.Close()
$fs.Close()
}
}
Write-Host ""
Write-Host "All tasks completed successfully." -ForegroundColor Green
Remove-Item $winLogOut, $winLogErr, $linLogOut, $linLogErr -Force
exit 0

View File

@ -1,47 +0,0 @@
# 设定 tar 包的名称
$tarName = "Snow.tar"
# 获取脚本当前目录build文件夹
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
# 获取上一级目录snow 根目录)
$parentDir = Split-Path -Parent $scriptDir
# 设置 tar 包的完整路径
$tarPath = Join-Path $parentDir $tarName
# 输出开始创建 tar 包的消息
Write-Output "开始创建 tar 包: $tarName$parentDir ..."
# 如果存在旧 tar 包,先删除它
if (Test-Path $tarPath) {
Write-Output "发现旧的 $tarName,正在删除..."
Remove-Item $tarPath -Force
}
# 确保 tar 命令可用
$tarCommand = "tar"
if (-not (Get-Command $tarCommand -ErrorAction SilentlyContinue)) {
Write-Error "❌ tar 命令不可用。请确保 tar 已安装并可在 PowerShell 中执行。"
exit 1
}
# 执行打包操作: 切换到 org\jcnc 目录下再压缩 snow 文件夹
try {
# 构建命令并执行
$tarCommandArgs = "-cf", $tarPath, "-C", "$scriptDir\..\src\main\java\org\jcnc", "snow"
Write-Output "执行 tar 命令: tar $tarCommandArgs"
& $tarCommand @tarCommandArgs
} catch {
Write-Error "❌ 创建 tar 包失败。错误信息: $_"
exit 1
}
# 检查 tar 包是否创建成功
if (Test-Path $tarPath) {
Write-Output "✅ 成功创建 $tarName"
} else {
Write-Error "❌ 创建失败,请检查 tar 命令和路径是否正确。"
exit 1
}

136
build/release-linux.ps1 Normal file
View File

@ -0,0 +1,136 @@
# run-linux-snow-export.ps1
# Build and package linux-snow-export, version read from SNOW_VERSION in .env
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
# Import shared dotenv parser function
. "$PSScriptRoot\tools\dotenv.ps1"
Write-Host "Step 0: Generate .env..."
try {
& "$PSScriptRoot\tools\generate-dotenv.ps1" -ErrorAction Stop
} catch {
Write-Error "Failed to generate .env: $( $_.Exception.Message )"
exit 1
}
Write-Host "Step 1: Build and run linux-snow-export..."
docker compose run --build --rm linux-snow-export
if ($LASTEXITCODE -ne 0) {
Write-Error "Build & Run failed, exiting script."
exit $LASTEXITCODE
}
Write-Host "Step 2: Run linux-snow-export without rebuild..."
docker compose run --rm linux-snow-export
if ($LASTEXITCODE -ne 0) {
Write-Error "Run without rebuild failed, exiting script."
exit $LASTEXITCODE
}
# ===== Step 3: Read version from .env =====
$projectRoot = Resolve-Path (Join-Path $PSScriptRoot "..")
$dotenvPath = Join-Path $projectRoot ".env"
if (-not (Test-Path -LiteralPath $dotenvPath)) {
Write-Error ".env not found at: $dotenvPath"
exit 1
}
$version = Read-DotEnvValue -FilePath $dotenvPath -Key 'SNOW_VERSION'
if (-not $version) {
Write-Error "SNOW_VERSION not found in .env"
exit 1
}
# ===== Step 4: Define output paths =====
$targetDir = Join-Path $projectRoot "target\release"
$outDir = Join-Path $targetDir "Snow-v$version-linux-x64"
$tgzPath = Join-Path $targetDir "Snow-v$version-linux-x64.tgz"
# ===== Step 5: Package to .tgz (no extra top-level dir, max compression) =====
Write-Host "Step 5: Package to .tgz..."
if (-not (Test-Path -LiteralPath $outDir)) {
Write-Error "Output directory not found: $outDir"
exit 1
}
# Ensure target directory exists
if (-not (Test-Path -LiteralPath $targetDir)) {
New-Item -ItemType Directory -Force -Path $targetDir | Out-Null
}
# Remove old package if exists
if (Test-Path -LiteralPath $tgzPath) {
Write-Host "→ Removing existing tgz: $tgzPath"
Remove-Item -LiteralPath $tgzPath -Force
}
function Invoke-TarGz {
param(
[Parameter(Mandatory = $true)][string]$SourceDir,
[Parameter(Mandatory = $true)][string]$DestTgz
)
$tarExe = "tar"
$isWindows = $env:OS -eq 'Windows_NT'
if ($isWindows) {
$psi = @{
FilePath = $tarExe
ArgumentList= @("-C", $SourceDir, "-czf", $DestTgz, ".")
NoNewWindow = $true
Wait = $true
}
try {
$p = Start-Process @psi -PassThru -ErrorAction Stop
$p.WaitForExit()
if ($p.ExitCode -ne 0) {
throw "tar exited with code $($p.ExitCode)"
}
} catch {
throw "Packaging failed (Windows tar): $($_.Exception.Message)"
}
} else {
try {
$psi = @{
FilePath = $tarExe
ArgumentList= @("-C", $SourceDir, "-c", "-f", $DestTgz, "-I", "gzip -9", ".")
NoNewWindow = $true
Wait = $true
}
$p = Start-Process @psi -PassThru -ErrorAction Stop
$p.WaitForExit()
if ($p.ExitCode -eq 0) { return }
} catch { }
try {
$psi = @{
FilePath = $tarExe
ArgumentList= @("-C", $SourceDir, "-c", "-z", "-f", $DestTgz, ".")
NoNewWindow = $true
Wait = $true
}
$p = Start-Process @psi -PassThru -ErrorAction Stop
$p.WaitForExit()
if ($p.ExitCode -ne 0) {
throw "tar exited with code $($p.ExitCode)"
}
} catch {
throw "Packaging failed (Linux tar): $($_.Exception.Message)"
}
}
}
try {
Invoke-TarGz -SourceDir $outDir -DestTgz $tgzPath
} catch {
Write-Error $_.Exception.Message
exit 1
}
Write-Host ">>> Package ready!" -ForegroundColor Green
Write-Host "Version : $version"
Write-Host "Output Dir : $outDir"
Write-Host "Tgz File : $tgzPath"

117
build/release-windows.ps1 Normal file
View File

@ -0,0 +1,117 @@
# release-windows.ps1
$ErrorActionPreference = 'Stop'
$ProgressPreference = 'SilentlyContinue'
Set-StrictMode -Version Latest
# Import shared dotenv parser function
. "$PSScriptRoot\tools\dotenv.ps1"
# ===== Utility Functions =====
function Find-PomUpwards([string]$startDir) {
$dir = Resolve-Path $startDir
while ($true) {
$pom = Join-Path $dir "pom.xml"
if (Test-Path $pom) { return $pom }
$parent = Split-Path $dir -Parent
if ($parent -eq $dir -or [string]::IsNullOrEmpty($parent)) { return $null }
$dir = $parent
}
}
# ===== Step 0: Generate .env =====
Write-Host "Step 0: Generate .env..."
try {
& "$PSScriptRoot\tools\generate-dotenv.ps1" -ErrorAction Stop
} catch {
Write-Error "Failed to generate .env: $($_.Exception.Message)"
exit 1
}
# ===== Step 1: Locate project root & build =====
Write-Host "Step 1: Locate project root and build..."
$pom = Find-PomUpwards -startDir $PSScriptRoot
if (-not $pom) {
Write-Error "pom.xml not found. Please run this script within the project."
exit 1
}
$projectRoot = Split-Path $pom -Parent
Push-Location $projectRoot
try {
Write-Host "→ Running: mvn clean package"
mvn clean package
if ($LASTEXITCODE -ne 0) {
Write-Error "Maven build failed, exiting script."
exit $LASTEXITCODE
}
# ===== Step 2: Read SNOW_VERSION =====
Write-Host "Step 2: Read SNOW_VERSION from .env..."
$dotenvPath = Join-Path $projectRoot ".env"
$snowVersion = Read-DotEnvValue -FilePath $dotenvPath -Key "SNOW_VERSION"
if (-not $snowVersion) {
Write-Host "SNOW_VERSION not found in .env, using placeholder 0.0.0." -ForegroundColor Yellow
$snowVersion = "0.0.0"
}
Write-Host "SNOW_VERSION = $snowVersion"
# ===== Step 3: Prepare release directory structure =====
Write-Host "Step 3: Prepare release directory structure..."
$targetDir = Join-Path $projectRoot "target"
$exePath = Join-Path $targetDir "Snow.exe"
if (-not (Test-Path $exePath)) {
Write-Error "Expected build artifact not found: $exePath"
exit 1
}
$verName = "Snow-v${snowVersion}-windows-x64"
$releaseRoot = Join-Path $targetDir "release"
$outDir = Join-Path $releaseRoot $verName
$binDir = Join-Path $outDir "bin"
$libDir = Join-Path $outDir "lib"
# Clean old directory
if (Test-Path $outDir) {
Write-Host "→ Cleaning previous output directory..."
Remove-Item $outDir -Recurse -Force
}
New-Item -ItemType Directory -Force -Path $binDir | Out-Null
Copy-Item -Path $exePath -Destination (Join-Path $binDir "Snow.exe") -Force
Write-Host ">>> Collected Snow.exe"
# Optional lib
$projectLib = Join-Path $projectRoot "lib"
if (Test-Path $projectLib) {
New-Item -ItemType Directory -Force -Path $libDir | Out-Null
Copy-Item -Path (Join-Path $projectLib "*") -Destination $libDir -Recurse -Force
Write-Host ">>> Copied lib directory"
} else {
Write-Host ">>> lib directory not found, skipping." -ForegroundColor Yellow
}
# ===== Step 4: Create release zip =====
Write-Host "Step 4: Create release zip..."
New-Item -ItemType Directory -Force -Path $releaseRoot | Out-Null
$zipPath = Join-Path $releaseRoot ("{0}.zip" -f $verName)
if (Test-Path $zipPath) {
Write-Host "→ Removing existing zip: $zipPath"
Remove-Item $zipPath -Force
}
try {
Compress-Archive -Path (Join-Path $outDir '*') -DestinationPath $zipPath -CompressionLevel Optimal -Force
} catch {
Write-Error "Failed to create zip: $($_.Exception.Message)"
exit 1
}
Write-Host ">>> Package ready!" -ForegroundColor Green
Write-Host "Version : $snowVersion"
Write-Host "Output Dir : $outDir"
Write-Host "Zip File : $zipPath"
}
finally {
Pop-Location
}

53
build/tools/dotenv.ps1 Normal file
View File

@ -0,0 +1,53 @@
# tools/dotenv.ps1
# Unified .env reader function:
# - Supports `KEY=VAL` and `export KEY=VAL`
# - Skips blank lines and comments
# - Handles quoted values (single or double quotes)
# - Allows inline comments at the end of a line (space + #)
# - If the same KEY is defined multiple times, the last one takes precedence
Set-StrictMode -Version Latest
function Read-DotEnvValue {
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)][string]$FilePath,
[Parameter(Mandatory=$true)][string]$Key
)
if (-not (Test-Path -LiteralPath $FilePath)) { return $null }
# Match the target key (escaped), allowing optional "export" prefix
$pattern = '^(?:\s*export\s+)?(?<k>' + [regex]::Escape($Key) + ')\s*=\s*(?<v>.*)$'
$value = $null
# Read line by line for large file compatibility
Get-Content -LiteralPath $FilePath | ForEach-Object {
$line = $_
# Skip blank lines and full-line comments
if ($line -match '^\s*$') { return }
if ($line -match '^\s*#') { return }
if ($line -match $pattern) {
$v = $matches['v']
# Remove surrounding quotes if present
$trimmed = $v.Trim()
if ($trimmed -match '^\s*"(.*)"\s*$') {
$v = $matches[1]
} elseif ($trimmed -match "^\s*'(.*)'\s*$") {
$v = $matches[1]
} else {
# Strip inline comments (space + # …), ignoring escaped \#
if ($v -match '^(.*?)(?<!\\)\s+#.*$') {
$v = $matches[1]
}
}
$value = $v.Trim()
}
}
return $value
}

View File

@ -0,0 +1,23 @@
# build\tools\generate-dotenv.ps1
# Repository root: go up two levels from build\tools\
$repoRoot = (Get-Item $PSScriptRoot).Parent.Parent.FullName
$envPath = Join-Path $repoRoot ".env"
$pomPath = Join-Path $repoRoot "pom.xml"
if (-not (Test-Path $pomPath -PathType Leaf)) {
throw "pom.xml not found: $pomPath"
}
[xml]$pom = Get-Content $pomPath -Encoding UTF8
$version = $pom.project.version
$lines = @(
"# Auto-generated by build\tools\generate-dotenv.ps1"
"SNOW_VERSION=$version"
)
$utf8NoBom = New-Object System.Text.UTF8Encoding($false)
[System.IO.File]::WriteAllLines($envPath, $lines, $utf8NoBom)
Write-Host "Generated/overwritten $envPath (version: $version)"
return

24
docker-compose.yml Normal file
View File

@ -0,0 +1,24 @@
services:
# Run with: docker compose run --rm linux-snow-export
linux-snow-export:
build:
context: .
target: export
command:
- /bin/sh
- -c
- |
set -e
ver="Snow-v${SNOW_VERSION}-linux-x64"
mkdir -p "/output/release/$$ver/bin"
cp /export/Snow "/output/release/$$ver/bin/"
if [ -d /export/lib ]; then
mkdir -p "/output/release/$$ver/lib"
cp -a /export/lib/. "/output/release/$$ver/lib/"
fi
tar -C /output/release -czf "/output/release/$$ver.tgz" "$$ver"
volumes:
- ./target:/output
- ./lib:/export/lib:ro
env_file:
- .env

View File

@ -76,8 +76,8 @@
module: Main
import:Math
function: main
parameter:
return_type: int
params:
returns: int
body:
Math.factorial(6L,1L)
@ -90,10 +90,10 @@ end module
## 源代码 (test.snow)
module: Math
function: factorial
parameter:
params:
declare n1: long
declare n2: long
return_type: long
returns: long
body:
return n1+n2
end body

View File

@ -7,7 +7,7 @@
```snow
module: Main
function: main
return_type: int
returns: int
body:
return 1 + 1
@ -57,10 +57,8 @@ bool 类型:
|---------|----|
| b、B | 7b |
| s、S | 7s |
| i、I | 7i |
| l、L | 7l |
| f、F | 7f |
| d、D | 7d |
### 变量
@ -116,7 +114,7 @@ cond 可以是表达式(结果为 bool 类型)或者 bool 字面量
```snow
module: Main
function: main
return_type: int
returns: int
body:
if 5 > 7 then
return 5
@ -154,7 +152,7 @@ end loop
```snow
module: Main
function: main
return_type: int
returns: int
body:
declare sum: int = 0
loop:
@ -179,17 +177,17 @@ end module
函数的形式如下:
```snow
function: add
parameter:
params:
declare a: int
declare b: int
return_type: int
returns: int
body:
return a + b
end body
end function
```
其中 add 是函数名parameter 下面是参数列表(可省略),与变量的定义类似,但是不允许赋初值,
接着 return_type 设置返回值类型,最后的 body 为函数体。
其中 add 是函数名params 下面是参数列表(可省略),与变量的定义类似,但是不允许赋初值,
接着 returns 设置返回值类型,最后的 body 为函数体。
## 模块
@ -202,7 +200,7 @@ snow 会自动将同名模块的函数合并。
```snow
module: Main
function: main
return_type: int
returns: int
body:
return 1 + 1
@ -218,10 +216,10 @@ end module
// Math.snow
module: Math
function: add
parameter:
params:
declare a: int
declare b: int
return_type: int
returns: int
body:
return a + b
end body
@ -235,7 +233,7 @@ end module
module: Main
import: Math
function: main
return_type: int
returns: int
body:
return Math.add(5, 7)
@ -250,7 +248,7 @@ end module
module: Main
import: Math, Time
function: main
return_type: int
returns: int
body:
return Math.add(5, 7)

View File

@ -1,7 +1,7 @@
module: Math
function: main
parameter:
return_type: int
params:
returns: int
body:
Math.factorial(6)
return 0
@ -9,9 +9,9 @@ module: Math
end function
function: factorial
parameter:
params:
declare n:int
return_type: int
returns: int
body:
declare num1:int = 1
loop:

View File

@ -1,9 +1,9 @@
module: os
import: os
function: print
parameter:
params:
declare i1: int
return_type: void
returns: void
body:
syscall("PRINT",i1)
end body

View File

@ -1,6 +1,6 @@
function: main
parameter:
return_type: int
params:
returns: int
body:
loop:
init:

View File

@ -1,6 +1,6 @@
module: Main
function: main
return_type: void
returns: void
body:
declare abc:int =1
end body

View File

@ -0,0 +1,33 @@
module: Main
import: os
function: main
returns: void
body:
loop:
init:
declare outer_i: int = 1
cond:
outer_i <= 10
step:
outer_i = outer_i + 1
body:
print(outer_i)
loop:
init:
// 注意这一行使用了外层循环的变量 outer_i
declare inter_j: int = outer_i
cond:
inter_j <= 10
step:
inter_j = inter_j + 1
body:
end body
end loop
end body
end loop
end body
end function
end module

View File

@ -0,0 +1,11 @@
module: os
import: os
function: print
params:
declare i1: int
returns: void
body:
syscall("PRINT",i1)
end body
end function
end module

View File

@ -0,0 +1,14 @@
module: Main
import: os
function: main
returns: void
body:
// 合法
declare b1: byte = 127b
declare s1: short = 32767s
declare i1: int = 2147483647
declare l1: long = 9223372036854775807L
end body
end function
end module

View File

@ -0,0 +1,11 @@
module: os
import: os
function: print
params:
declare i1: int
returns: void
body:
syscall("PRINT",i1)
end body
end function
end module

View File

@ -0,0 +1,9 @@
module: Main
import: ModuleB
function: main
returns: int
body:
return ModuleB.fun()
end body
end function
end module

View File

@ -0,0 +1,8 @@
module: ModuleA
function: fun
returns: int
body:
return 123
end body
end function
end module

View File

@ -0,0 +1,9 @@
module: ModuleB
import: ModuleA
function: fun
returns: int
body:
return ModuleA.fun() + ModuleA.fun()
end body
end function
end module

View File

@ -0,0 +1,16 @@
module: Main
import: os
globals:
declare sum: int = 0
function: main
params:
returns: int
body:
sum = 20
os.print(sum)
return 0
end body
end function
end module

View File

@ -0,0 +1,11 @@
module: os
import: os
function: print
params:
declare i1: int
returns: void
body:
syscall("PRINT",i1)
end body
end function
end module

View File

@ -0,0 +1,13 @@
module: Main
import: os
globals:
declare sum: int = 123
function: main
params:
returns: int
body:
os.print(sum)
return 0
end body
end function
end module

View File

@ -0,0 +1,11 @@
module: os
import: os
function: print
params:
declare i1: int
returns: void
body:
syscall("PRINT",i1)
end body
end function
end module

View File

@ -1,7 +1,7 @@
module: Main
import:Math
function: main
return_type: int
returns: int
body:
Math.add(6,1)
return 0

View File

@ -1,9 +1,9 @@
module: Math
function: add
parameter:
params:
declare n1: int
declare n2: int
return_type: int
returns: int
body:
return n1 + n2
end body

View File

@ -1,5 +1,5 @@
function: main
return_type: int
returns: int
body:
declare res: boolean = 8L > 7L
if res then

View File

@ -1,5 +1,5 @@
function: main
return_type: int
returns: int
body:
return 65537
end body

View File

@ -1,6 +1,6 @@
module: Main
function: main
return_type: int
returns: int
body:
foo()
@ -9,7 +9,7 @@ module: Main
end function
function: foo
return_type: int
returns: int
body:
if false then
return 1

View File

@ -1,6 +1,6 @@
module: Main
function: main
return_type: int
returns: int
body:
5 == 7
5 == 7s

View File

@ -1,9 +1,9 @@
module: Main
import: os
function: main
return_type: void
returns: void
body:
print(222)
os.print(222)
end body
end function
end module

View File

@ -1,9 +1,9 @@
module: os
import: os
function: print
parameter:
params:
declare i1: int
return_type: void
returns: void
body:
syscall("PRINT",i1)
end body

View File

@ -0,0 +1,20 @@
module: Main
import: os
globals:
declare num2:int=10
function: main
returns: void
body:
declare num1:int=11
os.print(num1+num2+abc())
end body
end function
function: abc
returns: int
body:
return 1
end body
end function
end module

View File

@ -0,0 +1,11 @@
module: os
import: os
function: print
params:
declare i1: int
returns: void
body:
syscall("PRINT",i1)
end body
end function
end module

View File

@ -0,0 +1,22 @@
module: Main
import: os
function: main
returns: int
body:
loop:
init:
declare i:int = 1
cond:
i <= 10
step:
i = i + 1
body:
if i % 2 == 0 then
os.print(i)
end if
end body
end loop
return 0
end body
end function
end module

View File

@ -0,0 +1,11 @@
module: os
import: os
function: print
params:
declare i1: int
returns: void
body:
syscall("PRINT",i1)
end body
end function
end module

View File

@ -0,0 +1,23 @@
module: Main
import: os
function: main
returns: int
body:
loop:
init:
declare i:int = 1
cond:
i <= 10
step:
i = i + 1
body:
if i % 2 == 0 then
os.print(i)
break
end if
end body
end loop
return 0
end body
end function
end module

View File

@ -0,0 +1,11 @@
module: os
import: os
function: print
params:
declare i1: int
returns: void
body:
syscall("PRINT",i1)
end body
end function
end module

View File

@ -0,0 +1,43 @@
module: Main
import: os
function: main
returns: int
body:
loop:
init:
declare i:int = 1
cond:
i <= 5
step:
i = i + 1
body:
if i % 2 == 0 then
continue
end if
if i > 3 then
break
end if
loop:
init:
declare j:int = 1
cond:
j <= 5
step:
j = j + 1
body:
if j == 4 then
break
end if
if j % 2 == 0 then
continue
end if
os.print(i)
os.print(j)
end body
end loop
end body
end loop
return 0
end body
end function
end module

View File

@ -0,0 +1,11 @@
module: os
import: os
function: print
params:
declare i1: int
returns: void
body:
syscall("PRINT",i1)
end body
end function
end module

View File

@ -0,0 +1,26 @@
module: Main
import: os
function: main
returns: void
body:
declare n: int[][][][] = [
[
[ [17, 18], [19, 20] ],
[ [21, 22], [23, 24] ]
],
[
[ [25, 26], [27, 28] ],
[ [29, 30], [31, 32] ]
]
]
declare i: int = 0
declare j: int = 1
declare k: int = 0
declare l: int = 0
declare x: int = n[i][j][k][l]
os.print(x)
end body
end function
end module

View File

@ -0,0 +1,11 @@
module: os
import: os
function: print
params:
declare i1: int
returns: void
body:
syscall("PRINT",i1)
end body
end function
end module

View File

@ -1,7 +1,7 @@
module: Main
function: main
parameter:
return_type: int
params:
returns: int
body:
return (1+2) / 3 * 4 + 2 *2
end body

View File

@ -0,0 +1,12 @@
module: Main
import:os
function: main
returns: void
body:
declare arr: int[] = [1, 2, 3]
arr[0] = 5
os.print(arr[0])
end body
end function
end module

View File

@ -0,0 +1,11 @@
module: os
import: os
function: print
params:
declare i1: int
returns: void
body:
syscall("PRINT",i1)
end body
end function
end module

View File

@ -0,0 +1,35 @@
module: Main
import: os
globals:
declare sum: int = 123
function: main
params:
returns: int
body:
declare arr: int[][][][][][][][][][][][][][][][][][][][][][] = [[[[[[[[[[[[[[[[[[[[[[1], [2], [3]]]]]]]]]]]]]]]]]]]]]]
loop:
init:
declare i: int = 0
cond:
i < 3
step:
i = i + 1
body:
arr[0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][i][0] = arr[0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][i][0] + 1
end body
end loop
loop:
init:
declare i: int = 0
cond:
i < 3
step:
i = i + 1
body:
os.print(arr[0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][i][0])
end body
end loop
return 0
end body
end function
end module

View File

@ -0,0 +1,11 @@
module: os
import: os
function: print
params:
declare i1: int
returns: void
body:
syscall("PRINT",i1)
end body
end function
end module

View File

@ -0,0 +1,15 @@
module: Main
import: ModuleA,os
function: main
returns: void
body:
declare sum: int = ModuleA.a+2
os.print(sum+1)
end body
end function
end module
module: ModuleA
globals:
declare const a: int =10
end module

View File

@ -0,0 +1,11 @@
module: os
import: os
function: print
params:
declare i1: int
returns: void
body:
syscall("PRINT",i1)
end body
end function
end module

View File

@ -0,0 +1,14 @@
module: Main
import: ModuleA
function: main
returns: void
body:
declare sum: byte = ModuleA.a
end body
end function
end module
module: ModuleA
globals:
declare const a: byte = 2b
end module

View File

@ -0,0 +1,26 @@
module: Main
import: ModuleA,os
globals:
declare const c: int = 10
function: main
returns: void
body:
declare a: int = ModuleA.sum(c,2)
os.print(a)
end body
end function
end module
module: ModuleA
globals:
declare const a: int = 10
function: sum
params:
declare a: int
declare b: int
returns: int
body:
return a + b
end body
end function
end module

View File

@ -0,0 +1,11 @@
module: os
import: os
function: print
params:
declare i1: int
returns: void
body:
syscall("PRINT",i1)
end body
end function
end module

View File

@ -0,0 +1,23 @@
module: Main
import: os,ModuleA
globals:
declare c: int = 10
function: main
returns: void
body:
c = ModuleA.getA()
os.print(c)
end body
end function
end module
module: ModuleA
globals:
declare a: int = 2
function: getA
returns: int
body:
return a
end body
end function
end module

View File

@ -0,0 +1,11 @@
module: os
import: os
function: print
params:
declare i1: int
returns: void
body:
syscall("PRINT",i1)
end body
end function
end module

View File

@ -0,0 +1,20 @@
module: Main
function: main
returns: void
body:
// 1. 常见转义符
declare sNewline : string = "换行示例:\n第二行"
declare sTab : string = "制表符示例:\t列二"
declare sBackslash: string = "反斜杠示例: C:\\Snow"
declare sDQuote : string = "双引号示例: \"Snow\""
declare sSQuote : string = "单引号示例: \'Snow\'"
declare sCarriage : string = "回车示例:\rCarriage"
declare sBackspace: string = "退格示例: ABC\bD"
declare sFormFeed : string = "换页示例:\fPage-2"
// 2. Unicode 转义
declare sUnicode : string = "𪚥𠮷: \u4F60\u597D, Snow!"
end body
end function
end module

View File

@ -1,7 +1,7 @@
module: Main
function: main
parameter:
return_type: int
params:
returns: int
body:
declare n1: int =1
declare n2: int =2

View File

@ -1,7 +1,7 @@
module: Main
function: main
parameter:
return_type: boolean
params:
returns: boolean
body:
declare b1: boolean =true

View File

@ -1,7 +1,7 @@
module: Main
function: main
parameter:
return_type: int
params:
returns: int
body:
declare b1: boolean = true
loop:

View File

@ -1,7 +1,7 @@
module: Main
function: main
parameter:
return_type: int
params:
returns: int
body:
declare b1 :int = -1
return b1

Some files were not shown because too many files have changed in this diff Show More