docs: 更新 README.md
This commit is contained in:
parent
26a533adaf
commit
a52a941799
212
README.md
212
README.md
@ -99,21 +99,21 @@ 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",
|
|
||||||
"body": [
|
|
||||||
{
|
|
||||||
"type": "ExpressionStatement",
|
|
||||||
"expression": {
|
|
||||||
"type": "CallExpression",
|
|
||||||
"callee": {
|
|
||||||
"type": "MemberExpression",
|
|
||||||
"object": {
|
|
||||||
"type": "Identifier",
|
|
||||||
"name": "Math"
|
|
||||||
},
|
|
||||||
"member": "add"
|
|
||||||
},
|
|
||||||
"arguments": [
|
|
||||||
{
|
|
||||||
"type": "NumberLiteral",
|
|
||||||
"value": "6"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "NumberLiteral",
|
|
||||||
"value": "1"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "Module",
|
|
||||||
"name": "Math",
|
|
||||||
"imports": [
|
|
||||||
|
|
||||||
],
|
|
||||||
"functions": [
|
|
||||||
{
|
|
||||||
"type": "Function",
|
|
||||||
"name": "add",
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"name": "n1",
|
|
||||||
"type": "int"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "n2",
|
|
||||||
"type": "int"
|
|
||||||
}
|
|
||||||
],
|
],
|
||||||
"returnType": "int",
|
"returnType": "int",
|
||||||
"body": [
|
"body": [
|
||||||
{
|
{
|
||||||
|
"type": "ExpressionStatement",
|
||||||
|
"expression": {
|
||||||
|
"type": "CallExpression",
|
||||||
|
"callee": {
|
||||||
|
"type": "MemberExpression",
|
||||||
|
"object": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"name": "Math"
|
||||||
|
},
|
||||||
|
"member": "add"
|
||||||
|
},
|
||||||
|
"arguments": [
|
||||||
|
{
|
||||||
|
"type": "NumberLiteral",
|
||||||
|
"value": "6"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "NumberLiteral",
|
||||||
|
"value": "1"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
"type": "Return",
|
"type": "Return",
|
||||||
"value": {
|
"value": {
|
||||||
"type": "BinaryExpression",
|
"type": "NumberLiteral",
|
||||||
"left": {
|
"value": "0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "Module",
|
||||||
|
"name": "Math",
|
||||||
|
"imports": [
|
||||||
|
|
||||||
|
],
|
||||||
|
"functions": [
|
||||||
|
{
|
||||||
|
"type": "Function",
|
||||||
|
"name": "add",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "n1",
|
||||||
|
"type": "int"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "n2",
|
||||||
|
"type": "int"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"returnType": "int",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "Return",
|
||||||
|
"value": {
|
||||||
|
"type": "BinaryExpression",
|
||||||
|
"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,27 +244,37 @@ 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 ===
|
|
||||||
Calling function at address: 8
|
|
||||||
Return 7
|
|
||||||
Return 2147483647
|
|
||||||
Operand Stack state:[7]
|
|
||||||
|
|
||||||
--- Call Stack State ---
|
|
||||||
|
|
||||||
Local variable table is empty
|
|
||||||
```
|
|
||||||
|
|
||||||
|
=== Launching VM ===
|
||||||
|
Calling function at address: 12
|
||||||
|
Return 7
|
||||||
|
Process has ended
|
||||||
|
|
||||||
|
Operand Stack state:[0]
|
||||||
|
|
||||||
|
--- Call Stack State ---
|
||||||
|
|
||||||
|
|
||||||
|
### VM Local Variable Table:
|
||||||
|
0: 6
|
||||||
|
1: 1
|
||||||
|
2: 7
|
||||||
|
3: 0
|
||||||
|
`````
|
||||||
|
|
||||||
## 编译Snow源代码
|
## 编译Snow源代码
|
||||||
|
|
||||||
### 1. 独立编译 (Standalone Compilation)
|
### 1. 独立编译 (Standalone Compilation)
|
||||||
@ -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]
|
||||||
```
|
```
|
||||||
|
|
||||||
* **目录递归编译:**
|
* **目录递归编译:**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user