Skip to content

Commit

Permalink
Merge commit '378ac5e2827d3ab18937eab2de7871b56b2f8150'
Browse files Browse the repository at this point in the history
  • Loading branch information
chai2010 committed Nov 3, 2023
2 parents 7765b51 + 378ac5e commit 2999f2d
Show file tree
Hide file tree
Showing 9 changed files with 670 additions and 9 deletions.
661 changes: 661 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion chs/1.安装及入门/1.1.你好凹语言.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func add(a: i32, b: i32) => i32 {
}
```

其中`//`开始的是行注释,`import`关键字导入了2个包准库的包`global`关键字定义了一个全局变量,并给了2023的初始值。`func`关键字定义了`main`函数和`add`函数。`main`函数是程序的入口,其中通过内置的`println`函数打印了“你好,凹语言!”,同时使用`fmt`包的`Println`字符串和整数表达式的结果。在`main`函数还使用了全局的`year`变量,此外还调用了`add`函数并打印了返回值。`add`函数有2个输入参数和一个返回值。
其中`//`开始的是行注释,`import`关键字导入了2个标准库的包`global`关键字定义了一个全局变量,并给了2023的初始值。`func`关键字定义了`main`函数和`add`函数。`main`函数是程序的入口,其中通过内置的`println`函数打印了“你好,凹语言!”,同时使用`fmt`包的`Println`字符串和整数表达式的结果。在`main`函数还使用了全局的`year`变量,此外还调用了`add`函数并打印了返回值。`add`函数有2个输入参数和一个返回值。

如果在本地已经安装有凹语言的`wa`命令(安装方式参考1.2节),可以输入以下命令执行:

Expand Down
2 changes: 1 addition & 1 deletion chs/1.安装及入门/1.3.命令行功能.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ $ wa run ./output/hello.wasm
...
```

如果不带参赛执行 `wa run` 命令,表示编译并执行当前凹语言工程,会先构建出 `output/hello.wasm` 然后再执行。
如果不带参数执行 `wa run` 命令,表示编译并执行当前凹语言工程,会先构建出 `output/hello.wasm` 然后再执行。

### 1.3.4 格式化代码

Expand Down
4 changes: 2 additions & 2 deletions chs/3.基础数据类型/3.1.局部变量声明.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
局部变量名: 数据类型 = 初始值
```

与全部变量和常量不同的是:局部变量的声明不以关键字开始;在声明局部变量时,如果省略 `= 初始值` 部分,则该变量将以0值初始化,如:
与全局变量和常量不同的是:局部变量的声明不以关键字开始;在声明局部变量时,如果省略 `= 初始值` 部分,则该变量将以0值初始化,如:

```wa
aI32: i32 = 42
aString: string = "你好"
aF32: f32 // 0.0
```

另一种常用的声明局部变量的语法使用快捷定义符 `:=` ,语法如下:
另一种常用的声明局部变量的语法是使用快捷定义符 `:=` ,语法如下:

```wa
局部变量名 := 表达式
Expand Down
2 changes: 1 addition & 1 deletion chs/3.基础数据类型/3.2.整数.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
- `&`:按位取与,两个操作数类型必须一致,返回值类型与操作数一致;
- `|`:按位取或,两个操作数类型必须一致,返回值类型与操作数一致;
- `^`:按位取异或,两个操作数类型必须一致,返回值类型与操作数一致;
- `&^`:按位清空,两个操作数类型必须一致,返回值类型与操作数一致。对 `z = x ^& y`,设 `xn``yn``zn` 分别为 `x``y``z` 的第n位,则当 `yn` 为1时 `zn` 为0,否则 `zn` 等于 `xn`。该运算等价于 `z = x & (^y)`
- `&^`:按位清空,两个操作数类型必须一致,返回值类型与操作数一致。对 `z = x &^ y`,设 `xn``yn``zn` 分别为 `x``y``z` 的第n位,则当 `yn` 为1时 `zn` 为0,否则 `zn` 等于 `xn`。该运算等价于 `z = x & (^y)`
- `<<`:左移,对 `z = x << y``z` 的类型与 `x` 一致,`y` 必须为大于0的整数,移位时低位补0;
- `>>`:右移,对 `z = x >> y``z` 的类型与 `x` 一致,`y` 必须为大于0的整数,移位时高位补0。

Expand Down
2 changes: 1 addition & 1 deletion chs/3.基础数据类型/3.4.字符串.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
println(s[1:3]) // ��
```

`s[m:n]` 用法从第`n`个字节处开始截取,返回的字串长度为 `n-m` 字节。若省略 `m` 则表示从字符串开始截取,若省略 `n` 则表示截取至字符串末尾,例如:
`s[m:n]` 用法从第`m`个字节处开始截取,返回的字串长度为 `n-m` 字节。若省略 `m` 则表示从字符串开始截取,若省略 `n` 则表示截取至字符串末尾,例如:
```wa
s := "abcdefg"
println(s[:3]) // abc
Expand Down
2 changes: 1 addition & 1 deletion chs/9.附录/a-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ImportPath = string_lit .
PackageName = identifier .
```

imort 关键字用于导入包,导入的包还可以被重新命名(对应PackageName)。
import 关键字用于导入包,导入的包还可以被重新命名(对应PackageName)。

以下代码是一个凹源文件的对应例子:

Expand Down
2 changes: 1 addition & 1 deletion en/3.BasicTypes/3.2.Integers.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Integers(except Boolean) support the following binary bit operations:
- `&`: bitwise AND, the two operand types must be consistent, the type of return value is same with operands;
- `|`: Bitwise OR, the two operand types must be consistent, the type of return value is same with operands;
- `^`: Bitwise XOR, the two operand types must be consistent, the type of return value is same with operands;
- `&^`: clear bitwise, the two operand types must be consistent, the type of return value is same with operands. For `z = x ^& y`, let `xn`, `yn`, `zn` be the nth bit of `x`, `y`, `z` respectively, then when `yn` is 1, `zn ` is 0, otherwise `zn` is equal to `xn`. This operation is equivalent to `z = x & (^y)`;
- `&^`: clear bitwise, the two operand types must be consistent, the type of return value is same with operands. For `z = x &^ y`, let `xn`, `yn`, `zn` be the nth bit of `x`, `y`, `z` respectively, then when `yn` is 1, `zn ` is 0, otherwise `zn` is equal to `xn`. This operation is equivalent to `z = x & (^y)`;
- `<<`: Left shift, for `z = x << y`, the type of `z` is consistent with `x`, `y` must be an integer greater than 0, and the low-order bit is filled with 0 when shifting;
- `>>`: Right shift, for `z = x >> y`, the type of `z` is consistent with `x`, `y` must be an integer greater than 0, and the high bit is filled with 0 when shifting.

Expand Down
2 changes: 1 addition & 1 deletion en/3.BasicTypes/3.4.String.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ In this usage, the subscripted units within `[]` are bytes, not characters. If t
println(s[1:3]) // ��
```

`s[m:n]` operation starts from the `n`th byte, and the length of the returned string is `n-m` bytes. If `m` is omitted, it means start from the beginning of the string. If `n` is omitted, it means intercepting to the end of the string. For example:
`s[m:n]` operation starts from the `m`th byte, and the length of the returned string is `n-m` bytes. If `m` is omitted, it means start from the beginning of the string. If `n` is omitted, it means intercepting to the end of the string. For example:
```wa
s := "abcdefg"
println(s[:3]) // abc
Expand Down

0 comments on commit 2999f2d

Please sign in to comment.