feat: 添加 os.snow系统库模块
This commit is contained in:
parent
99345ddd19
commit
80efd7c357
@ -16,7 +16,7 @@ import java.util.List;
|
||||
* <code>main.snow</code>。
|
||||
*
|
||||
* <p>
|
||||
* 生成内容包括:
|
||||
* 生成内容包括:
|
||||
* <ul>
|
||||
* <li><code>src/</code> —— 源码根目录</li>
|
||||
* <li><code>src/{group package}/</code> —— 按 <code>project.group</code> 创建的包路径
|
||||
@ -31,7 +31,9 @@ import java.util.List;
|
||||
*/
|
||||
public final class GenerateTask implements Task {
|
||||
|
||||
/** 项目信息元数据 */
|
||||
/**
|
||||
* 项目信息元数据
|
||||
*/
|
||||
private final Project project;
|
||||
|
||||
/**
|
||||
@ -90,6 +92,13 @@ public final class GenerateTask implements Task {
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package org.jcnc.snow.pkg.utils;
|
||||
|
||||
/**
|
||||
* 示例模块模板工具类,提供 main.snow 的标准示例代码字符串。
|
||||
* 示例模块模板工具类,提供标准的示例 Snow 代码片段。
|
||||
* <p>
|
||||
* 用于项目脚手架生成或帮助用户快速上手 .snow 语言。
|
||||
* </p>
|
||||
@ -23,12 +23,11 @@ public final class SnowExample {
|
||||
public static String getMainModule() {
|
||||
return """
|
||||
module: Math
|
||||
import: os
|
||||
function: main
|
||||
params:
|
||||
returns: int
|
||||
returns: void
|
||||
body:
|
||||
Math.factorial(6)
|
||||
return 0
|
||||
os.print(Math.factorial(6))
|
||||
end body
|
||||
end function
|
||||
|
||||
@ -55,4 +54,25 @@ public final class SnowExample {
|
||||
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
|
||||
""";
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user