feat: 添加 os.snow系统库模块

This commit is contained in:
Luke 2025-08-24 12:13:23 +08:00
parent 99345ddd19
commit 80efd7c357
2 changed files with 36 additions and 7 deletions

View File

@ -31,7 +31,9 @@ import java.util.List;
*/ */
public final class GenerateTask implements Task { public final class GenerateTask implements Task {
/** 项目信息元数据 */ /**
* 项目信息元数据
*/
private final Project project; private final Project project;
/** /**
@ -90,6 +92,13 @@ public final class GenerateTask implements Task {
System.out.println("[generate] created " + root.relativize(mainSnow)); System.out.println("[generate] created " + root.relativize(mainSnow));
} }
/* ---------- 5. 写入系统库文件 os.snow ---------- */
Path osSnow = packageDir.resolve("OS.snow");
if (Files.notExists(osSnow)) {
Files.writeString(osSnow, SnowExample.getOsModule());
System.out.println("[generate] created " + root.relativize(osSnow));
}
System.out.println("[generate] project scaffold is ready."); System.out.println("[generate] project scaffold is ready.");
} }
} }

View File

@ -1,7 +1,7 @@
package org.jcnc.snow.pkg.utils; package org.jcnc.snow.pkg.utils;
/** /**
* 示例模块模板工具类提供 main.snow 的标准示例代码字符串 * 示例模块模板工具类提供标准的示例 Snow 代码片段
* <p> * <p>
* 用于项目脚手架生成或帮助用户快速上手 .snow 语言 * 用于项目脚手架生成或帮助用户快速上手 .snow 语言
* </p> * </p>
@ -23,12 +23,11 @@ public final class SnowExample {
public static String getMainModule() { public static String getMainModule() {
return """ return """
module: Math module: Math
import: os
function: main function: main
params: returns: void
returns: int
body: body:
Math.factorial(6) os.print(Math.factorial(6))
return 0
end body end body
end function end function
@ -55,4 +54,25 @@ public final class SnowExample {
end module end module
"""; """;
} }
/**
* 获取系统库 os.snow 模块的内容字符串
*
* @return os.snow 模块的完整代码
*/
public static String getOsModule() {
return """
module: os
import: os
function: print
params:
declare i1: int
returns: void
body:
syscall("PRINT", i1)
end body
end function
end module
""";
}
} }