docs: 更新 README.md

This commit is contained in:
Luke 2025-06-28 17:19:22 +08:00
parent 26a533adaf
commit a52a941799

138
README.md
View File

@ -100,20 +100,20 @@ Snow 语言受到 LLM 驱动代码生成趋势的启发,强调简单而清晰的
4. **运行成功** 4. **运行成功**
``` snow `````snow
## 编译器输出 ## 编译器输出
### Snow 源代码 ### Snow 源代码
#### Main.snow #### Main.snow
module: Main module: Main
import:Math import:Math
function: main function: main
return_type: void return_type: int
body: body:
Math.add(6,1) Math.add(6,1)
return 0
end body end body
end function end function
end module end module
#### Math.snow #### Math.snow
module: Math module: Math
function: add function: add
@ -122,111 +122,121 @@ Snow 语言受到 LLM 驱动代码生成趋势的启发,强调简单而清晰的
declare n2: int declare n2: int
return_type: int return_type: int
body: body:
return n1 + n2 return n1 + n2
end body end body
end function end function
end module end module
### AST ### AST
[ [
{ {
"type": "Module", "type": "Module",
"name": "Main", "name": "Main",
"imports": [ "imports": [
{ {
"module": "Math", "module": "Math",
"type": "Import" "type": "Import"
} }
], ],
"functions": [ "functions": [
{ {
"type": "Function", "type": "Function",
"name": "main", "name": "main",
"parameters": [ "parameters": [
], ],
"returnType": "void", "returnType": "int",
"body": [ "body": [
{ {
"type": "ExpressionStatement", "type": "ExpressionStatement",
"expression": { "expression": {
"type": "CallExpression", "type": "CallExpression",
"callee": { "callee": {
"type": "MemberExpression", "type": "MemberExpression",
"object": { "object": {
"type": "Identifier", "type": "Identifier",
"name": "Math" "name": "Math"
}, },
"member": "add" "member": "add"
}, },
"arguments": [ "arguments": [
{ {
"type": "NumberLiteral", "type": "NumberLiteral",
"value": "6" "value": "6"
}, },
{ {
"type": "NumberLiteral", "type": "NumberLiteral",
"value": "1" "value": "1"
} }
] ]
} }
} },
{
"type": "Return",
"value": {
"type": "NumberLiteral",
"value": "0"
}
}
] ]
} }
] ]
}, },
{ {
"type": "Module", "type": "Module",
"name": "Math", "name": "Math",
"imports": [ "imports": [
], ],
"functions": [ "functions": [
{ {
"type": "Function", "type": "Function",
"name": "add", "name": "add",
"parameters": [ "parameters": [
{ {
"name": "n1", "name": "n1",
"type": "int" "type": "int"
}, },
{ {
"name": "n2", "name": "n2",
"type": "int" "type": "int"
} }
], ],
"returnType": "int", "returnType": "int",
"body": [ "body": [
{ {
"type": "Return", "type": "Return",
"value": { "value": {
"type": "BinaryExpression", "type": "BinaryExpression",
"left": { "left": {
"type": "Identifier", "type": "Identifier",
"name": "n1" "name": "n1"
}, },
"operator": "+", "operator": "+",
"right": { "right": {
"type": "Identifier", "type": "Identifier",
"name": "n2" "name": "n2"
}
} }
} }
}
] ]
} }
] ]
} }
] ]
### IR ### IR
func main() { func main() {
%0 = CONST 6 %0 = CONST 6
%1 = CONST 1 %1 = CONST 1
%2 = CALL Math.add, %0, %1 %2 = CALL Math.add, %0, %1
%3 = CONST 0
RET %3
} }
func add(%0, %1) { func add(%0, %1) {
%2 = ADD_I32 %0, %1 %2 = ADD_I32 %0, %1
RET %2 RET %2
} }
### VM code ### VM code
0000: I_PUSH 6 0000: I_PUSH 6
0001: I_STORE 0 0001: I_STORE 0
@ -234,26 +244,36 @@ Snow 语言受到 LLM 驱动代码生成趋势的启发,强调简单而清晰的
0003: I_STORE 1 0003: I_STORE 1
0004: I_LOAD 0 0004: I_LOAD 0
0005: I_LOAD 1 0005: I_LOAD 1
0006: CALL 8 2 0006: CALL 12 2
0007: I_STORE 2 0007: I_STORE 2
0008: I_LOAD 0 0008: I_PUSH 0
0009: I_LOAD 1 0009: I_STORE 3
0010: I_ADD 0010: I_LOAD 3
0011: I_STORE 2 0011: HALT
0012: I_LOAD 2 0012: I_LOAD 0
0013: RET 0013: I_LOAD 1
0014: I_ADD
0015: I_STORE 2
0016: I_LOAD 2
0017: RET
Written to D:\Devs\IdeaProjects\Snow\target\Demo1.water Written to D:\Devs\IdeaProjects\Snow\target\Demo1.water
=== Launching VM === === Launching VM ===
Calling function at address: 8 Calling function at address: 12
Return 7 Return 7
Return 2147483647 Process has ended
Operand Stack state:[7]
Operand Stack state:[0]
--- Call Stack State --- --- Call Stack State ---
Local variable table is empty
``` ### VM Local Variable Table:
0: 6
1: 1
2: 7
3: 0
`````
## 编译Snow源代码 ## 编译Snow源代码
@ -269,13 +289,13 @@ Snow 语言受到 LLM 驱动代码生成趋势的启发,强调简单而清晰的
* **单个文件编译:** * **单个文件编译:**
```bash ```bash
Snow [SnowCode].snow Snow complete [SnowCode].snow
``` ```
* **多个文件编译:** * **多个文件编译:**
```bash ```bash
Snow [SnowCode1].snow [SnowCode2].snow [SnowCode3].snow Snow complete [SnowCode1].snow [SnowCode2].snow [SnowCode3].snow -o [Name]
``` ```
* **目录递归编译:** * **目录递归编译:**