README.md 4.0 KB
Newer Older
chai2010's avatar
chai2010 已提交
1
<div align="center">
chai2010's avatar
chai2010 已提交
2
<h1>🇨🇳 The Wa Programming Language</h1>
chai2010's avatar
chai2010 已提交
3

chai2010's avatar
chai2010 已提交
4 5 6
[Document](https://wa-lang.org) | [Playground](https://wa-lang.org/playground) | [Goals](https://wa-lang.org/goals.html) | [Roadmap](https://wa-lang.org/smalltalk/st0002.html) | [Community](https://wa-lang.org/community) | [Changelog](https://wa-lang.org/changelog.html) | [Discussions](https://github.com/wa-lang/wa/discussions)


chai2010's avatar
chai2010 已提交
7 8
</div>
<div align="center">
3
3dgen 已提交
9

chai2010's avatar
chai2010 已提交
10 11
[![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 已提交
12
[![Coverage Status](https://coveralls.io/repos/github/wa-lang/wa/badge.svg)](https://coveralls.io/github/wa-lang/wa)
chai2010's avatar
chai2010 已提交
13
[![GitHub release](https://img.shields.io/github/v/tag/wa-lang/wa.svg?label=release)](https://github.com/wa-lang/wa/releases)
chai2010's avatar
chai2010 已提交
14
[![Go Reference](https://pkg.go.dev/badge/github.com/wa-lang/wa.svg)](https://pkg.go.dev/github.com/wa-lang/wa)
chai2010's avatar
chai2010 已提交
15
[![license](https://img.shields.io/github/license/wa-lang/wa.svg)](https://github.com/wa-lang/wa/blob/master/LICENSE)
chai2010's avatar
chai2010 已提交
16

chai2010's avatar
chai2010 已提交
17 18
</div>

chai2010's avatar
chai2010 已提交
19 20
Wa is a general-purpose programming language designed for developing robustness and maintainability WebAssembly software.
Instead of requiring complex toolchains to set up, you can simply go install it - or run it in a browser.
chai2010's avatar
chai2010 已提交
21

chai2010's avatar
chai2010 已提交
22 23
![](docs/images/logo/logo-animate1-blue.svg)

chai2010's avatar
chai2010 已提交
24 25 26 27 28 29
- Homepage: [https://wa-lang.org](https://wa-lang.org)
- Github: [https://github.com/wa-lang/wa](https://github.com/wa-lang/wa)
- Gitee:  [https://gitee.com/wa-lang/wa](https://gitee.com/wa-lang/wa)
- Go Doc: [https://pkg.go.dev/github.com/wa-lang/wa](https://pkg.go.dev/github.com/wa-lang/wa)
- Develop Tools: [Playground](https://wa-lang.org/playground), [VSCode](https://marketplace.visualstudio.com/items?itemName=xxxDeveloper.vscode-wa), [Fleet](https://github.com/wa-lang/fleet-wa), [Vim](https://github.com/wa-lang/vim-wa)
- Core Team: [柴树杉(chai2010)](https://github.com/chai2010)[丁尔男(Ending)](https://github.com/3dgen)[史斌(Benshi)](https://github.com/benshi001)[扈梦明(xxxDeveloper)](https://github.com/xxxDeveloper)[刘云峰(leaftree)](https://github.com/leaftree)[宋汝阳(ShiinaOrez)](https://github.com/ShiinaOrez)
30

chai2010's avatar
chai2010 已提交
31
## Playground
chai2010's avatar
chai2010 已提交
32 33 34 35 36 37

[https://wa-lang.org/playground](https://wa-lang.org/playground)

![[![](https://wa-lang.org/smalltalk/images/st0011-01.png)](https://wa-lang.org/playground)](https://wa-lang.org/static/images/playground.gif)


chai2010's avatar
chai2010 已提交
38
## Install and Run:
chai2010's avatar
chai2010 已提交
39

40 41 42
1. `go install github.com/wa-lang/wa@latest`
2. `wa init -name=_examples/hi`
3. `wa run _examples/hi`
chai2010's avatar
chai2010 已提交
43

chai2010's avatar
chai2010 已提交
44
> The Wa project is still in very early stage. If you want to submit PR, please read the [Contribution Guide(Chinese)](https://wa-lang.org/community/contribute.html).
chai2010's avatar
chai2010 已提交
45

chai2010's avatar
chai2010 已提交
46
## Example: Print Wa
3
3dgen 已提交
47

chai2010's avatar
chai2010 已提交
48
打印字符和调用函数(Print rune and call function):
chai2010's avatar
chai2010 已提交
49

chai2010's avatar
chai2010 已提交
50
```wa
chai2010's avatar
chai2010 已提交
51 52
# Copyrighe @2019-2022 The Wa author. All rights reserved.

chai2010's avatar
chai2010 已提交
53 54
import "fmt"

55
fn main {
chai2010's avatar
chai2010 已提交
56
	println("hello, Wa!")
chai2010's avatar
chai2010 已提交
57
	println(add(40, 2))
chai2010's avatar
chai2010 已提交
58 59

	fmt.Println(1+1)
chai2010's avatar
chai2010 已提交
60 61 62 63 64 65 66
}

fn add(a: i32, b: i32) => i32 {
	return a+b
}
```

chai2010's avatar
chai2010 已提交
67
Execute the program:
chai2010's avatar
chai2010 已提交
68 69 70

```
$ go run main.go hello.wa 
chai2010's avatar
chai2010 已提交
71
hello, Wa!
chai2010's avatar
chai2010 已提交
72
42
chai2010's avatar
chai2010 已提交
73
2
chai2010's avatar
chai2010 已提交
74 75
```

chai2010's avatar
chai2010 已提交
76
## Example: Print Prime
3
zz  
3dgen 已提交
77

chai2010's avatar
chai2010 已提交
78
Print prime numbers up to 30:
3
3dgen 已提交
79 80

```
81
fn main {
3
3dgen 已提交
82
	for n := 2; n <= 30; n = n + 1 {
83
		var isPrime int = 1
3
3dgen 已提交
84 85 86 87 88 89 90 91 92 93 94 95
		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 已提交
96
Execute the program:
chai2010's avatar
chai2010 已提交
97 98

```
chai2010's avatar
chai2010 已提交
99
$ go run main.go run _examples/prime
chai2010's avatar
chai2010 已提交
100 101 102 103 104 105 106 107 108 109 110 111
2
3
5
7
11
13
17
19
23
29
```

chai2010's avatar
chai2010 已提交
112
More examples [_examples](_examples)
3
3dgen 已提交
113

chai2010's avatar
chai2010 已提交
114
## Execut as a script
chai2010's avatar
chai2010 已提交
115

chai2010's avatar
chai2010 已提交
116
The Wa language itself can also be executed like the Lua language embedded in the Go host locale:
chai2010's avatar
chai2010 已提交
117

chai2010's avatar
chai2010 已提交
118
```
chai2010's avatar
chai2010 已提交
119 120 121 122 123 124 125 126
package main

import (
	"fmt"
	"github.com/wa-lang/wa/api"
)

func main() {
chai2010's avatar
chai2010 已提交
127
	# TODO: fix example
chai2010's avatar
chai2010 已提交
128 129 130 131 132
	output, err := api.RunCode("hello.wa", "fn main() { println(40+2) }")
	fmt.Print(string(output), err)
}
```

chai2010's avatar
chai2010 已提交
133
Note: Executing as a script currently only supports native environments.
3
3dgen 已提交
134

chai2010's avatar
chai2010 已提交
135
## License
3
zz  
3dgen 已提交
136

chai2010's avatar
chai2010 已提交
137
Copyrighe @2019-2022 The Wa author. All rights reserved.