README.md 2.1 KB
Newer Older
3
3dgen 已提交
1 2
# 凹语言™

chai2010's avatar
chai2010 已提交
3 4
[![Build Status](https://github.com/wa-lang/wa/actions/workflows/wa.yml/badge.svg)](https://github.com/wa-lang/wa/actions/workflows/wa.yml)
[![Go Report Card](https://goreportcard.com/badge/github.com/wa-lang/wa)](https://goreportcard.com/report/github.com/wa-lang/wa)
chai2010's avatar
chai2010 已提交
5
[![Coverage Status](https://coveralls.io/repos/github/wa-lang/wa/badge.svg)](https://coveralls.io/github/wa-lang/wa)
chai2010's avatar
chai2010 已提交
6 7
[![GitHub release](https://img.shields.io/github/v/tag/wa-lang/wa.svg?label=release)](https://github.com/wa-lang/wa/releases)

3
3dgen 已提交
8 9 10 11 12 13 14 15 16 17 18 19
凹语言™(凹读音“Wa”)是[柴树杉](https://github.com/chai2010)[丁尔男](https://github.com/3dgen)[史斌](https://github.com/benshi001)设计的实验性编程语言。

```
+---+    +---+
| o |    | o |
|   +----+   |
|            |
|     Wa     |
|            |
+------------+
```

3
3dgen 已提交
20
## 设计目标
3
3dgen 已提交
21

3
3dgen 已提交
22 23
- 披着 Go 和 Rust 语法外衣的 C++ 语言;
- 凹语言™源码文件后缀为 `.wa`
3
3dgen 已提交
24
- 凹语言™编译器兼容 WaGo 语法。WaGo 是 Go 真子集。使用 WaGo 语法的源码文件后缀为 `.wa.go`。凹语法与 WaGo 语法在 AST 层面一致;
3
3dgen 已提交
25
- 凹语言™支持中文/英文双语关键字,即任一关键字均有中文及英文版,二者在语法层面等价。
3
3dgen 已提交
26
- 更多内容位于:docs/goals.md
3
3dgen 已提交
27 28

## 处理过程
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47

```mermaid
graph LR
    wa_ext(.wa);
    wago_ext(.wa.go);

    wa_ast(Wa AST);

    c_cpp(C/C++);
    llir(LLVM IR);
    wasm(WASM);

    wa_ext   --> wa_ast;
    wago_ext --> wa_ast;

    wa_ast --> c_cpp;
    wa_ast --> llir;
    wa_ast --> wasm;
```
3
3dgen 已提交
48

3
zz  
3dgen 已提交
49 50
## 例子: 打印素数

51
打印 30 以内的素数:
3
3dgen 已提交
52 53 54 55

```
// 版权 @2021 凹语言™ 作者。保留所有权利。

3
zz  
3dgen 已提交
56
fn main() {
3
3dgen 已提交
57
	for n := 2; n <= 30; n = n + 1 {
3
zz  
3dgen 已提交
58
		let isPrime int = 1
3
3dgen 已提交
59 60 61 62 63 64 65 66 67 68 69 70
		for i := 2; i*i <= n; i = i + 1 {
			if x := n % i; x == 0 {
				isPrime = 0
			}
		}
		if isPrime != 0 {
			println(n)
		}
	}
}
```

chai2010's avatar
chai2010 已提交
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
输出结果:

```
$ wa run _examples/prime
2
3
5
7
11
13
17
19
23
29
```

## 更多例子

[_examples](_examples)

chai2010's avatar
chai2010 已提交
91
![](https://raw.githubusercontent.com/wa-lang/wa-lang.github.io/master/wa-run-demo.gif)
92

3
3dgen 已提交
93 94 95
## 版权

版权 @2019 凹语言™ 作者。保留所有权利。