Compare commits

..

No commits in common. "master" and "v0.4.1" have entirely different histories.

480 changed files with 10508 additions and 50728 deletions

View File

@ -1,17 +0,0 @@
# 版权 @2022 凹语言 作者。保留所有权利。
name: Close PRs
on:
pull_request_target:
types: [opened]
jobs:
run:
runs-on: ubuntu-latest
steps:
- uses: superbrothers/close-pull-request@v3
with:
# Optional. Post a issue comment just before closing a pull request.
comment: "这里是镜像仓库, 不接受 PR, 请移步 https://gitee.com/wa-lang"

View File

@ -23,7 +23,7 @@ jobs:
go-version: 1.17
- run: make -C internal/app/wawasm
- run: make -C waroot/examples/snake publish
- run: make -C _examples/snake publish
- name: Deploy
uses: peaceiris/actions-gh-pages@v3

View File

@ -1,45 +0,0 @@
# https://github.com/goreleaser/goreleaser-action
name: Release
on:
push:
tags:
- "v*"
permissions:
contents: write
jobs:
Test:
runs-on: ubuntu-latest
if: ${{github.repository == 'wa-lang/wa'}}
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17
- run: make ci-test-all
Publish:
runs-on: ubuntu-latest
if: ${{github.repository == 'wa-lang/wa'}}
needs: [Test]
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.WA_DEPLOY }}

View File

@ -23,17 +23,14 @@ jobs:
- run: go version
- run: go env
- run: make ci-test-all
- run: go test -v -coverprofile=profile.cov ./...
- run: go install
- run: wa -h
- run: cd waroot && wa hello.wa
- run: cd waroot && wa run examples/prime
- run: cd waroot && wa run hello.wa
- run: cd waroot && wa run -target=chrome hello.wa
- run: wa hello.wa
- run: wa run _examples/prime
- run: wa run hello.wa
- uses: shogo82148/actions-goveralls@v1
with:
@ -53,17 +50,14 @@ jobs:
- run: go version
- run: go env
- run: make ci-test-all
- run: go test -v ./...
- run: go install
- run: wa -h
- run: cd waroot && wa hello.wa
- run: cd waroot && wa run examples/prime
- run: cd waroot && wa run hello.wa
- run: cd waroot && wa run -target=chrome hello.wa
- run: wa hello.wa
- run: wa run _examples/prime
- run: wa run hello.wa
build-and-test-macos:
runs-on: macos-12
@ -79,14 +73,11 @@ jobs:
- run: go version
- run: go env
- run: make ci-test-all
- run: go test -v ./...
- run: go install
- run: wa -h
- run: cd waroot && wa hello.wa
- run: cd waroot && wa run examples/prime
- run: cd waroot && wa run hello.wa
- run: cd waroot && wa run -target=chrome hello.wa
- run: wa hello.wa
- run: wa run _examples/prime
- run: wa run hello.wa

3
.gitignore vendored
View File

@ -1,7 +1,5 @@
/.fleet
/.vscode
/_build*
/hello
wa
wa.exe
@ -18,7 +16,6 @@ wat2wasm.exe
*.out*
*.wasm
*.wasm.*
y.wa.*
/docs/snake/*

View File

@ -1,70 +0,0 @@
version: '1.0'
name: branch-pipeline
displayName: BranchPipeline
stages:
- stage:
name: compile
displayName: 编译
steps:
- step: build@golang
name: build_golang
displayName: Golang 构建
# 支持1.8、1.10、1.11、1.12、1.13、1.14、1.15、1.16八个版本
golangVersion: 1.17
# 构建命令
commands: |
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct
go test -v ./...
mkdir -p output/wa-lang-darwin
mkdir -p output/wa-lang-linux64
mkdir -p output/wa-lang-win64
GOOS=darwin GOARCH=amd64 go build -o output/wa-lang-darwin/wa main.go
GOOS=linux GOARCH=amd64 go build -o output/wa-lang-linux64/wa main.go
GOOS=windows GOARCH=amd64 go build -o output/wa-lang-win64/wa.exe main.go
chmod +X output/wa-lang-linux64/wa
./output/wa-lang-linux64/wa
./output/wa-lang-linux64/wa -h
#./output/wa-lang-linux64/wa waroot/hello.wa
#./output/wa-lang-linux64/wa run waroot/examples/prime
#./output/wa-lang-linux64/wa run waroot/hello.wa
# 非必填字段开启后表示将构建产物暂存但不会上传到制品库中7天后自动清除
artifacts:
# 构建产物名字作为产物的唯一标识可向下传递支持自定义默认为BUILD_ARTIFACT。在下游可以通过${BUILD_ARTIFACT}方式引用来获取构建物地址
- name: BUILD_ARTIFACT
# 构建产物获取路径,是指代码编译完毕之后构建物的所在路径
path:
- ./output
- step: publish@general_artifacts
name: publish_general_artifacts
displayName: 上传制品
# 上游构建任务定义的产物名默认BUILD_ARTIFACT
dependArtifact: BUILD_ARTIFACT
# 上传到制品库时的制品命名默认output
artifactName: output
dependsOn: build_golang
- stage:
name: release
displayName: 发布
steps:
- step: publish@release_artifacts
name: publish_release_artifacts
displayName: '发布'
# 上游上传制品任务的产出
dependArtifact: output
# 发布制品版本号
version: '1.0.0.0'
# 是否开启版本号自增,默认开启
autoIncrement: true
triggers:
push:
branches:
exclude:
- master
include:
- .*

View File

@ -1,68 +0,0 @@
version: '1.0'
name: master-pipeline
displayName: MasterPipeline
stages:
- stage:
name: compile
displayName: 编译
steps:
- step: build@golang
name: build_golang
displayName: Golang 构建
# 支持1.8、1.10、1.11、1.12、1.13、1.14、1.15、1.16八个版本
golangVersion: 1.17
# 构建命令
commands: |
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,
go test -v ./...
mkdir -p output/wa-lang-darwin
mkdir -p output/wa-lang-linux64
mkdir -p output/wa-lang-win64
GOOS=darwin GOARCH=amd64 go build -o output/wa-lang-darwin/wa main.go
GOOS=linux GOARCH=amd64 go build -o output/wa-lang-linux64/wa main.go
GOOS=windows GOARCH=amd64 go build -o output/wa-lang-win64/wa.exe main.go
chmod +X output/wa-lang-linux64/wa
./output/wa-lang-linux64/wa
./output/wa-lang-linux64/wa -h
#./output/wa-lang-linux64/wa waroot/hello.wa
#./output/wa-lang-linux64/wa run waroot/examples/prime
#./output/wa-lang-linux64/wa run waroot/hello.wa
# 非必填字段开启后表示将构建产物暂存但不会上传到制品库中24小时后自动清除
artifacts:
# 构建产物名字作为产物的唯一标识可向下传递支持自定义默认为BUILD_ARTIFACT。在下游可以通过${BUILD_ARTIFACT}方式引用来获取构建物地址
- name: BUILD_ARTIFACT
# 构建产物获取路径,是指代码编译完毕之后构建物的所在路径
path:
- ./output
- step: publish@general_artifacts
name: publish_general_artifacts
displayName: 上传制品
# 上游构建任务定义的产物名默认BUILD_ARTIFACT
dependArtifact: BUILD_ARTIFACT
# 上传到制品库时的制品命名默认output
artifactName: output
dependsOn: build_golang
- stage:
name: release
displayName: 发布
steps:
- step: publish@release_artifacts
name: publish_release_artifacts
displayName: '发布'
# 上游上传制品任务的产出
dependArtifact: output
# 发布制品版本号
version: '1.0.0.0'
# 是否开启版本号自增,默认开启
autoIncrement: true
triggers:
push:
branches:
include:
- master

View File

@ -1,55 +0,0 @@
version: '1.0'
name: pr-pipeline
displayName: PRPipeline
stages:
- stage:
name: compile
displayName: 编译
steps:
- step: build@golang
name: build_golang
displayName: Golang 构建
# 支持1.8、1.10、1.11、1.12、1.13、1.14、1.15、1.16八个版本
golangVersion: 1.17
# 构建命令
commands: |
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,
go test -v ./...
mkdir -p output/wa-lang-darwin
mkdir -p output/wa-lang-linux64
mkdir -p output/wa-lang-win64
GOOS=darwin GOARCH=amd64 go build -o output/wa-lang-darwin/wa main.go
GOOS=linux GOARCH=amd64 go build -o output/wa-lang-linux64/wa main.go
GOOS=windows GOARCH=amd64 go build -o output/wa-lang-win64/wa.exe main.go
chmod +X output/wa-lang-linux64/wa
./output/wa-lang-linux64/wa
./output/wa-lang-linux64/wa -h
#./output/wa-lang-linux64/wa waroot/hello.wa
#./output/wa-lang-linux64/wa run waroot/examples/prime
#./output/wa-lang-linux64/wa run waroot/hello.wa
# 非必填字段开启后表示将构建产物暂存但不会上传到制品库中7天后自动清除
artifacts:
# 构建产物名字作为产物的唯一标识可向下传递支持自定义默认为BUILD_ARTIFACT。在下游可以通过${BUILD_ARTIFACT}方式引用来获取构建物地址
- name: BUILD_ARTIFACT
# 构建产物获取路径,是指代码编译完毕之后构建物的所在路径
path:
- ./output
- step: publish@general_artifacts
name: publish_general_artifacts
displayName: 上传制品
# 上游构建任务定义的产物名默认BUILD_ARTIFACT
dependArtifact: BUILD_ARTIFACT
# 上传到制品库时的制品命名默认output
artifactName: output
dependsOn: build_golang
triggers:
pr:
branches:
include:
- master

View File

@ -1,15 +1,17 @@
# 版权 @2019 凹语言 作者。保留所有权利。
hello:
go install
cd waroot && go run ../main.go run hello.wa
go run main.go run hello.wa
prime:
cd waroot && go run ../main.go run examples/prime
go run main.go run _examples/prime
build-wasm:
GOARCH=wasm GOOS=js go build -o wa.out.wasm ./main_wasm.go
win-exe-icon:
windres -o main_rc_windows.syso main.rc
arduino-run:
go run main.go -target=arduino arduino.wa
@ -18,18 +20,4 @@ arduino-build:
wat2wasm a.out.wat -o a.out.wasm
xxd -i a.out.wasm > app.wasm.h
ci-test-all:
go install
go test ./...
@echo "== std test begin =="
go run main.go test std
@echo "== std ok =="
go run main.go run ./waroot/hello.wa
cd waroot && go run ../main.go run hello.wa
make -C ./waroot/examples ci-test-all
clean:
-rm a.out*

View File

@ -1,11 +1,11 @@
<div align="center">
<h1>凹语言</h1>
<h1>🇨🇳 凹语言</h1>
[主页](https://wa-lang.org) | [Playground](https://wa-lang.org/playground) | [路线](https://wa-lang.org/smalltalk/st0001.html) | [社区](https://wa-lang.org/community) | [日志](https://wa-lang.org/guide/changelog.html)
[主页](https://wa-lang.org) | [Playground](https://wa-lang.org/playground) | [目标](https://wa-lang.org/goals.html) | [路线](https://wa-lang.org/smalltalk/st0002.html) | [社区](https://wa-lang.org/community) | [日志](https://wa-lang.org/changelog.html) | [论坛](https://github.com/wa-lang/wa/discussions)
</div>
凹语言凹读音“Wā”)是 针对 WASM 平台设计的通用编程语言,同时支持 Linux、macOS 和 Windows 等主流操作系统和 Chrome 等浏览器环境,同时也支持作为独立 Shell 脚本和被嵌入脚本模式执行。
凹语言凹读音“Wa”)是 针对 WASM 平台设计的通用编程语言,同时支持 Linux、macOS 和 Windows 等主流操作系统和 Chrome 等浏览器环境同时也支持作为独立Shell脚本和被嵌入脚本模式执行。
![](docs/images/logo/logo-animate1.svg)
@ -14,7 +14,7 @@
- 仓库(Github): [https://github.com/wa-lang/wa](https://github.com/wa-lang/wa)
- Playground: [https://wa-lang.org/playground](https://wa-lang.org/playground)
> 说明: 除非特别声明,凹语言代码均以 AGPL-v3 开源协议授权, 具体可以参考 LICENSE 文件。
> 说明: 凹语言的主仓库位于: https://gitee.com/wa-lang/wa ,镜像仓库位于: https://github.com/wa-lang/wa 。凹语言代码除非特别声明,均以 AGPL-v3 开源协议授权, 具体可以参考 LICENSE 文件。
## 如何参与开发
@ -27,25 +27,21 @@
[https://wa-lang.org/playground](https://wa-lang.org/playground)
![](https://wa-lang.org/playground-01.png)
![[![](https://wa-lang.org/smalltalk/images/st0011-01.png)](https://wa-lang.org/playground)](https://wa-lang.org/st0011-03.png)
## 贪吃蛇游戏
- [https://wa-lang.org/wa/snake/](https://wa-lang.org/wa/snake/)
- [https://wa-lang.org/smalltalk/st0018.html](https://wa-lang.org/smalltalk/st0018.html)
![](https://wa-lang.org/st0018-03.jpg)
![](_examples/snake/web/snake.jpg)
## 本地安装和测试:
有 2 种安装方式: 1 是直接从 Github [下载最新的二进制文件](https://github.com/wa-lang/wa/releases); 2 是通过 Go 语言从源码安装.
通过 Go 语言安装需要执行以下命令 (Go >= 1.17):
1. `go install wa-lang.org/wa@latest`
2. `cd waroot`
3. `wa init -name=examples/hi`
4. `wa run examples/hi`
2. `wa init -name=_examples/hi`
3. `wa run _examples/hi`
## 例子: 凹语言
@ -54,16 +50,14 @@
```wa
import "fmt"
global year: i32 = 2023
func main {
println("hello, Wa!")
println(add(40, 2), year)
fn main {
println("你好,凹语言!")
println(add(40, 2))
fmt.Println(1+1)
}
func add(a: i32, b: i32) => i32 {
fn add(a: i32, b: i32) => i32 {
return a+b
}
```
@ -73,7 +67,7 @@ func add(a: i32, b: i32) => i32 {
```
$ go run main.go hello.wa
你好,凹语言!
42 2023
42
2
```
@ -81,12 +75,12 @@ $ go run main.go hello.wa
打印 30 以内的素数:
```wa
// 版权 @2021 凹语言™ 作者。保留所有权利。
```
# 版权 @2021 凹语言™ 作者。保留所有权利。
func main {
fn main {
for n := 2; n <= 30; n = n + 1 {
isPrime: int = 1
var isPrime int = 1
for i := 2; i*i <= n; i = i + 1 {
if x := n % i; x == 0 {
isPrime = 0
@ -102,7 +96,7 @@ func main {
运行并输出结果:
```
$ cd waroot && go run ../main.go run examples/prime
$ go run main.go run _examples/prime
2
3
5
@ -115,47 +109,24 @@ $ cd waroot && go run ../main.go run examples/prime
29
```
## 例子:用中文语法打印素数
更多例子 [_examples](_examples)
```wz
引于 "书"
## 作为脚本执行
【启】:
// 打印30以内的素数
从n=2到n>30有n++
设素=1
从i=2到i*i>n有i++
设x=n%i
若x==0则
素=0
若素!=0则
书·曰n
凹语言本身也可以像 Lua 语言被嵌入 Go 宿主语言环境执行:
```
package main
import (
"fmt"
"wa-lang.org/wa/api"
)
func main() {
output, err := api.RunCode(api.DefaultConfig(), "hello.wa", code)
fmt.Print(string(output), err)
}
```
运行的结果和英文语法的示例相同。
更多例子 [waroot/examples](waroot/examples)
## 贡献者名单
|贡献者|贡献点|
| --- | --- |
|柴树杉| 35000|
|丁尔男| 42500|
|史斌 | 29000|
|扈梦明| 14000|
|赵普明| 17000|
|宋汝阳| 2000|
|刘云峰| 1000|
|王湘南| 1000|
|王泽龙| 1000|
|吴烜 | 3000|
|刘斌 | 2500|
|尹贻浩| 2000|
贡献点变更记录见 [waroot/cplog](waroot/cplog) 目录。
注:作为脚本执行目前只支持本地环境。

View File

@ -1,9 +1,6 @@
<div align="center">
<h1>The Wa Programming Language</h1>
[简体中文](https://github.com/wa-lang/wa/blob/master/README-zh.md) | [English](https://github.com/wa-lang/wa/blob/master/README.md)
</div>
<div align="center">
@ -31,25 +28,21 @@ Instead of requiring complex toolchains to set up, you can simply go install it
[https://wa-lang.org/playground](https://wa-lang.org/playground)
![](https://wa-lang.org/playground-01.png)
![[![](https://wa-lang.org/smalltalk/images/st0011-01.png)](https://wa-lang.org/playground)](https://wa-lang.org/st0011-03.png)
## Snake Game
- Play: [https://wa-lang.org/wa/snake/](https://wa-lang.org/wa/snake/)
- Code: [waroot/examples/snake/README-en.md](waroot/examples/snake/README-en.md)
- Code: [_examples/snake/README-en.md](_examples/snake/README-en.md)
![](_examples/snake/web/snake.jpg)
![](https://wa-lang.org/st0018-03.jpg)
## Install and Run:
Install from binary: download `wa` command from https://github.com/wa-lang/wa/releases, and set `$PATH` env.
Or install from Go (Go >= 1.17):
1. `go install wa-lang.org/wa@latest`
2. `cd waroot`
2. `wa init -name=examples/hi`
3. `wa run examples/hi`
2. `wa init -name=_examples/hi`
3. `wa run _examples/hi`
> 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). We do not accept PR only about 3rdparty changes.
@ -58,18 +51,18 @@ Or install from Go (Go >= 1.17):
Print rune and call function
```wa
# Copyright @2019-2022 The Wa author. All rights reserved.
import "fmt"
global year: i32 = 2023
func main {
fn main {
println("hello, Wa!")
println(add(40, 2), year)
println(add(40, 2))
fmt.Println(1+1)
}
func add(a: i32, b: i32) => i32 {
fn add(a: i32, b: i32) => i32 {
return a+b
}
```
@ -79,7 +72,7 @@ Execute the program:
```
$ go run main.go hello.wa
hello, Wa!
42 2023
42
2
```
@ -87,10 +80,10 @@ hello, Wa!
Print prime numbers up to 30:
```wa
func main {
```
fn main {
for n := 2; n <= 30; n = n + 1 {
isPrime: int = 1
var isPrime int = 1
for i := 2; i*i <= n; i = i + 1 {
if x := n % i; x == 0 {
isPrime = 0
@ -106,7 +99,7 @@ func main {
Execute the program:
```
$ cd waroot && go run ../main.go run examples/prime
$ go run main.go run _examples/prime
2
3
5
@ -119,47 +112,24 @@ $ cd waroot && go run ../main.go run examples/prime
29
```
## Example: Print Prime with Chinese syntax
More examples [_examples](_examples)
Print prime numbers up to 30:
## Execut as a script
```wz
引于 "书"
The Wa language itself can also be executed like the Lua language embedded in the Go host locale:
【启】:
// 输出30以内的素数
从n=2到n>30有n++
设素=1
从i=2到i*i>n有i++
设x=n%i
若x==0则
素=0
若素!=0则
书·曰n
```
package main
import (
"fmt"
"wa-lang.org/wa/api"
)
func main() {
output, err := api.RunCode(api.DefaultConfig(), "hello.wa", code)
fmt.Print(string(output), err)
}
```
Output is the same as the previous example.
More examples [waroot/examples](waroot/examples)
## Contributors
|Contributor|Contribution points|
| --- | --- |
|柴树杉| 35000|
|丁尔男| 42500|
|史斌 | 29000|
|扈梦明| 14000|
|赵普明| 17000|
|宋汝阳| 2000|
|刘云峰| 1000|
|王湘南| 1000|
|王泽龙| 1000|
|吴烜 | 3000|
|刘斌 | 2500|
|尹贻浩| 2000|
Note: Executing as a script currently only supports native environments.

View File

@ -1,7 +1,7 @@
# 版权 @2022 凹语言 作者。保留所有权利。
default:
go run ../../../main.go run -target=arduino hello.wat
go run ../../main.go -target=arduino hello.wat
clean:
-rm *.wasm

View File

@ -0,0 +1,7 @@
default:
go run ../../main.go build -target=arduino app.wa
wat2wasm a.out.wat -o app.wasm
xxd -i app.wasm > app.wasm.h
clean:
-rm *.h *.wasm *.out*

View File

@ -1,16 +1,16 @@
// 版权 @2022 凹语言 作者。保留所有权利。
# 版权 @2022 凹语言 作者。保留所有权利。
import "syscall/arduino"
var LED = arduino.GetPinLED()
func init {
fn init() {
arduino.PinMode(LED, 1)
arduino.Print("凹语言(Wa)/Arduino is running ...\n")
arduino.Print("https://wa-lang.org\n")
}
func main {
fn main() {
for {
arduino.DigitalWrite(LED, arduino.HIGH)
arduino.Delay(100)

View File

@ -0,0 +1,132 @@
unsigned char app_wasm[] = {
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x2a, 0x08, 0x60,
0x01, 0x7f, 0x00, 0x60, 0x02, 0x7f, 0x7f, 0x00, 0x60, 0x00, 0x01, 0x7f,
0x60, 0x01, 0x7f, 0x01, 0x7f, 0x60, 0x04, 0x7f, 0x7f, 0x7f, 0x7f, 0x01,
0x7f, 0x60, 0x01, 0x7f, 0x02, 0x7f, 0x7f, 0x60, 0x00, 0x00, 0x60, 0x03,
0x7f, 0x7f, 0x7f, 0x00, 0x02, 0x6f, 0x06, 0x07, 0x61, 0x72, 0x64, 0x75,
0x69, 0x6e, 0x6f, 0x05, 0x64, 0x65, 0x6c, 0x61, 0x79, 0x00, 0x00, 0x07,
0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x07, 0x70, 0x69, 0x6e, 0x4d,
0x6f, 0x64, 0x65, 0x00, 0x01, 0x07, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e,
0x6f, 0x0c, 0x64, 0x69, 0x67, 0x69, 0x74, 0x61, 0x6c, 0x57, 0x72, 0x69,
0x74, 0x65, 0x00, 0x01, 0x07, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f,
0x06, 0x6d, 0x69, 0x6c, 0x6c, 0x69, 0x73, 0x00, 0x02, 0x07, 0x61, 0x72,
0x64, 0x75, 0x69, 0x6e, 0x6f, 0x09, 0x67, 0x65, 0x74, 0x50, 0x69, 0x6e,
0x4c, 0x45, 0x44, 0x00, 0x02, 0x07, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e,
0x6f, 0x05, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x00, 0x01, 0x03, 0x13, 0x12,
0x03, 0x00, 0x04, 0x05, 0x03, 0x00, 0x06, 0x06, 0x00, 0x00, 0x01, 0x06,
0x06, 0x06, 0x06, 0x07, 0x07, 0x06, 0x04, 0x04, 0x01, 0x70, 0x00, 0x01,
0x05, 0x03, 0x01, 0x00, 0x01, 0x06, 0x43, 0x0d, 0x7f, 0x01, 0x41, 0x80,
0x10, 0x0b, 0x7f, 0x01, 0x41, 0x00, 0x0b, 0x7f, 0x01, 0x41, 0x00, 0x0b,
0x7f, 0x01, 0x41, 0x00, 0x0b, 0x7f, 0x01, 0x41, 0x00, 0x0b, 0x7f, 0x01,
0x41, 0x00, 0x0b, 0x7f, 0x01, 0x41, 0x00, 0x0b, 0x7f, 0x01, 0x41, 0x00,
0x0b, 0x7f, 0x01, 0x41, 0x00, 0x0b, 0x7f, 0x01, 0x41, 0x00, 0x0b, 0x7f,
0x01, 0x41, 0x00, 0x0b, 0x7f, 0x01, 0x41, 0x00, 0x0b, 0x7f, 0x01, 0x41,
0x00, 0x0b, 0x07, 0xdc, 0x01, 0x0c, 0x06, 0x6d, 0x65, 0x6d, 0x6f, 0x72,
0x79, 0x02, 0x00, 0x0c, 0x72, 0x75, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x2e,
0x69, 0x6e, 0x69, 0x74, 0x00, 0x0d, 0x13, 0x24, 0x72, 0x75, 0x6e, 0x74,
0x69, 0x6d, 0x65, 0x2e, 0x77, 0x61, 0x50, 0x72, 0x69, 0x6e, 0x74, 0x49,
0x33, 0x32, 0x00, 0x0e, 0x14, 0x24, 0x72, 0x75, 0x6e, 0x74, 0x69, 0x6d,
0x65, 0x2e, 0x77, 0x61, 0x50, 0x72, 0x69, 0x6e, 0x74, 0x52, 0x75, 0x6e,
0x65, 0x00, 0x0f, 0x0f, 0x24, 0x72, 0x75, 0x6e, 0x74, 0x69, 0x6d, 0x65,
0x2e, 0x77, 0x61, 0x50, 0x75, 0x74, 0x73, 0x00, 0x10, 0x0f, 0x5f, 0x5f,
0x6d, 0x61, 0x69, 0x6e, 0x5f, 0x5f, 0x2e, 0x69, 0x6e, 0x69, 0x74, 0x23,
0x31, 0x00, 0x11, 0x0d, 0x5f, 0x5f, 0x6d, 0x61, 0x69, 0x6e, 0x5f, 0x5f,
0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x12, 0x0d, 0x5f, 0x5f, 0x6d, 0x61,
0x69, 0x6e, 0x5f, 0x5f, 0x2e, 0x69, 0x6e, 0x69, 0x74, 0x00, 0x13, 0x14,
0x73, 0x79, 0x73, 0x63, 0x61, 0x6c, 0x6c, 0x24, 0x61, 0x72, 0x64, 0x75,
0x69, 0x6e, 0x6f, 0x2e, 0x69, 0x6e, 0x69, 0x74, 0x00, 0x14, 0x17, 0x73,
0x79, 0x73, 0x63, 0x61, 0x6c, 0x6c, 0x24, 0x61, 0x72, 0x64, 0x75, 0x69,
0x6e, 0x6f, 0x2e, 0x50, 0x72, 0x69, 0x6e, 0x74, 0x6c, 0x6e, 0x00, 0x15,
0x15, 0x73, 0x79, 0x73, 0x63, 0x61, 0x6c, 0x6c, 0x24, 0x61, 0x72, 0x64,
0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x50, 0x72, 0x69, 0x6e, 0x74, 0x00, 0x16,
0x06, 0x5f, 0x73, 0x74, 0x61, 0x72, 0x74, 0x00, 0x17, 0x0a, 0xcb, 0x07,
0x12, 0x0b, 0x00, 0x23, 0x00, 0x23, 0x00, 0x20, 0x00, 0x6a, 0x24, 0x00,
0x0b, 0x02, 0x00, 0x0b, 0x25, 0x00, 0x20, 0x00, 0x20, 0x00, 0x04, 0x40,
0x20, 0x00, 0x41, 0x01, 0x36, 0x00, 0x00, 0x20, 0x00, 0x20, 0x01, 0x36,
0x00, 0x04, 0x20, 0x00, 0x20, 0x02, 0x36, 0x00, 0x08, 0x20, 0x00, 0x20,
0x03, 0x36, 0x00, 0x0c, 0x0b, 0x0b, 0x06, 0x00, 0x20, 0x00, 0x20, 0x00,
0x0b, 0x16, 0x00, 0x20, 0x00, 0x20, 0x00, 0x04, 0x40, 0x20, 0x00, 0x20,
0x00, 0x28, 0x00, 0x00, 0x41, 0x01, 0x6a, 0x36, 0x00, 0x00, 0x0b, 0x0b,
0x6d, 0x01, 0x05, 0x7f, 0x20, 0x00, 0x41, 0x00, 0x46, 0x04, 0x40, 0x0f,
0x0b, 0x20, 0x00, 0x28, 0x00, 0x00, 0x41, 0x01, 0x6b, 0x21, 0x01, 0x20,
0x01, 0x04, 0x40, 0x20, 0x00, 0x20, 0x01, 0x36, 0x00, 0x00, 0x05, 0x20,
0x00, 0x28, 0x00, 0x08, 0x21, 0x03, 0x20, 0x03, 0x04, 0x40, 0x20, 0x00,
0x28, 0x00, 0x04, 0x21, 0x02, 0x20, 0x02, 0x04, 0x40, 0x20, 0x00, 0x28,
0x00, 0x0c, 0x21, 0x04, 0x20, 0x00, 0x41, 0x10, 0x6a, 0x21, 0x05, 0x03,
0x40, 0x20, 0x05, 0x20, 0x03, 0x11, 0x00, 0x00, 0x20, 0x02, 0x41, 0x01,
0x6b, 0x21, 0x02, 0x20, 0x02, 0x04, 0x40, 0x20, 0x05, 0x20, 0x04, 0x6a,
0x21, 0x05, 0x0c, 0x01, 0x0b, 0x0b, 0x0b, 0x0b, 0x20, 0x00, 0x10, 0x07,
0x0b, 0x0b, 0x2c, 0x00, 0x41, 0x04, 0x10, 0x06, 0x24, 0x03, 0x41, 0x04,
0x10, 0x06, 0x24, 0x04, 0x41, 0x04, 0x10, 0x06, 0x24, 0x05, 0x41, 0x04,
0x10, 0x06, 0x24, 0x07, 0x41, 0x04, 0x10, 0x06, 0x24, 0x08, 0x41, 0x0c,
0x10, 0x06, 0x24, 0x09, 0x41, 0x04, 0x10, 0x06, 0x24, 0x0b, 0x0b, 0x6c,
0x01, 0x03, 0x7f, 0x41, 0x00, 0x21, 0x00, 0x41, 0x00, 0x21, 0x01, 0x41,
0x00, 0x21, 0x02, 0x02, 0x40, 0x03, 0x40, 0x02, 0x40, 0x02, 0x40, 0x02,
0x40, 0x02, 0x40, 0x20, 0x00, 0x0e, 0x03, 0x00, 0x01, 0x02, 0x00, 0x0b,
0x41, 0x00, 0x21, 0x01, 0x23, 0x0a, 0x21, 0x02, 0x20, 0x02, 0x04, 0x40,
0x0c, 0x02, 0x05, 0x0c, 0x01, 0x0b, 0x0b, 0x41, 0x01, 0x21, 0x01, 0x41,
0x01, 0x24, 0x0a, 0x10, 0x14, 0x23, 0x09, 0x41, 0x00, 0x10, 0x0a, 0x23,
0x09, 0x28, 0x00, 0x00, 0x10, 0x0b, 0x36, 0x00, 0x00, 0x23, 0x09, 0x41,
0x08, 0x36, 0x00, 0x04, 0x23, 0x09, 0x41, 0x07, 0x36, 0x00, 0x08, 0x0c,
0x00, 0x0b, 0x41, 0x02, 0x21, 0x01, 0x0c, 0x02, 0x0b, 0x0b, 0x0b, 0x0b,
0x24, 0x01, 0x02, 0x7f, 0x41, 0x00, 0x21, 0x01, 0x41, 0x00, 0x21, 0x02,
0x02, 0x40, 0x03, 0x40, 0x02, 0x40, 0x02, 0x40, 0x20, 0x01, 0x0e, 0x01,
0x00, 0x00, 0x0b, 0x41, 0x00, 0x21, 0x02, 0x0c, 0x02, 0x0b, 0x0b, 0x0b,
0x0b, 0x24, 0x01, 0x02, 0x7f, 0x41, 0x00, 0x21, 0x01, 0x41, 0x00, 0x21,
0x02, 0x02, 0x40, 0x03, 0x40, 0x02, 0x40, 0x02, 0x40, 0x20, 0x01, 0x0e,
0x01, 0x00, 0x00, 0x0b, 0x41, 0x00, 0x21, 0x02, 0x0c, 0x02, 0x0b, 0x0b,
0x0b, 0x0b, 0x2a, 0x01, 0x02, 0x7f, 0x41, 0x00, 0x21, 0x02, 0x41, 0x00,
0x21, 0x03, 0x02, 0x40, 0x03, 0x40, 0x02, 0x40, 0x02, 0x40, 0x20, 0x02,
0x0e, 0x01, 0x00, 0x00, 0x0b, 0x41, 0x00, 0x21, 0x03, 0x20, 0x00, 0x20,
0x01, 0x10, 0x05, 0x0c, 0x02, 0x0b, 0x0b, 0x0b, 0x0b, 0x49, 0x01, 0x03,
0x7f, 0x41, 0x00, 0x21, 0x00, 0x41, 0x00, 0x21, 0x01, 0x41, 0x00, 0x21,
0x02, 0x02, 0x40, 0x03, 0x40, 0x02, 0x40, 0x02, 0x40, 0x20, 0x00, 0x0e,
0x01, 0x00, 0x00, 0x0b, 0x41, 0x00, 0x21, 0x01, 0x23, 0x0b, 0x28, 0x00,
0x00, 0x21, 0x02, 0x20, 0x02, 0x41, 0x01, 0x10, 0x01, 0x41, 0x00, 0x10,
0x0a, 0x41, 0x0f, 0x41, 0x25, 0x10, 0x16, 0x41, 0x00, 0x10, 0x0a, 0x41,
0x34, 0x41, 0x14, 0x10, 0x16, 0x0c, 0x02, 0x0b, 0x0b, 0x0b, 0x0b, 0x74,
0x01, 0x06, 0x7f, 0x41, 0x00, 0x21, 0x00, 0x41, 0x00, 0x21, 0x01, 0x41,
0x00, 0x21, 0x02, 0x41, 0x00, 0x21, 0x03, 0x41, 0x00, 0x21, 0x04, 0x41,
0x00, 0x21, 0x05, 0x02, 0x40, 0x03, 0x40, 0x02, 0x40, 0x02, 0x40, 0x02,
0x40, 0x20, 0x00, 0x0e, 0x02, 0x00, 0x01, 0x00, 0x0b, 0x41, 0x00, 0x21,
0x01, 0x0c, 0x00, 0x0b, 0x41, 0x01, 0x21, 0x01, 0x23, 0x0b, 0x28, 0x00,
0x00, 0x21, 0x02, 0x23, 0x05, 0x28, 0x00, 0x00, 0x21, 0x03, 0x20, 0x02,
0x20, 0x03, 0x10, 0x02, 0x41, 0xe4, 0x00, 0x10, 0x00, 0x23, 0x0b, 0x28,
0x00, 0x00, 0x21, 0x04, 0x23, 0x03, 0x28, 0x00, 0x00, 0x21, 0x05, 0x20,
0x04, 0x20, 0x05, 0x10, 0x02, 0x41, 0x84, 0x07, 0x10, 0x00, 0x41, 0x01,
0x21, 0x00, 0x0c, 0x01, 0x0b, 0x0b, 0x0b, 0x0b, 0x5f, 0x01, 0x04, 0x7f,
0x41, 0x00, 0x21, 0x00, 0x41, 0x00, 0x21, 0x01, 0x41, 0x00, 0x21, 0x02,
0x41, 0x00, 0x21, 0x03, 0x02, 0x40, 0x03, 0x40, 0x02, 0x40, 0x02, 0x40,
0x02, 0x40, 0x02, 0x40, 0x20, 0x00, 0x0e, 0x03, 0x00, 0x01, 0x02, 0x00,
0x0b, 0x41, 0x00, 0x21, 0x01, 0x23, 0x0c, 0x21, 0x02, 0x20, 0x02, 0x04,
0x40, 0x0c, 0x02, 0x05, 0x0c, 0x01, 0x0b, 0x0b, 0x41, 0x01, 0x21, 0x01,
0x41, 0x01, 0x24, 0x0c, 0x10, 0x14, 0x10, 0x04, 0x21, 0x03, 0x23, 0x0b,
0x20, 0x03, 0x36, 0x00, 0x00, 0x10, 0x11, 0x0c, 0x00, 0x0b, 0x41, 0x02,
0x21, 0x01, 0x0c, 0x02, 0x0b, 0x0b, 0x0b, 0x0b, 0x6f, 0x01, 0x03, 0x7f,
0x41, 0x00, 0x21, 0x00, 0x41, 0x00, 0x21, 0x01, 0x41, 0x00, 0x21, 0x02,
0x02, 0x40, 0x03, 0x40, 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0x02, 0x40,
0x20, 0x00, 0x0e, 0x03, 0x00, 0x01, 0x02, 0x00, 0x0b, 0x41, 0x00, 0x21,
0x01, 0x23, 0x06, 0x21, 0x02, 0x20, 0x02, 0x04, 0x40, 0x0c, 0x02, 0x05,
0x0c, 0x01, 0x0b, 0x0b, 0x41, 0x01, 0x21, 0x01, 0x41, 0x01, 0x24, 0x06,
0x23, 0x03, 0x41, 0x00, 0x36, 0x00, 0x00, 0x23, 0x05, 0x41, 0x01, 0x36,
0x00, 0x00, 0x23, 0x04, 0x41, 0x00, 0x36, 0x00, 0x00, 0x23, 0x08, 0x41,
0x01, 0x36, 0x00, 0x00, 0x23, 0x07, 0x41, 0x02, 0x36, 0x00, 0x00, 0x0c,
0x00, 0x0b, 0x41, 0x02, 0x21, 0x01, 0x0c, 0x02, 0x0b, 0x0b, 0x0b, 0x0b,
0x32, 0x01, 0x02, 0x7f, 0x41, 0x00, 0x21, 0x03, 0x41, 0x00, 0x21, 0x04,
0x02, 0x40, 0x03, 0x40, 0x02, 0x40, 0x02, 0x40, 0x20, 0x03, 0x0e, 0x01,
0x00, 0x00, 0x0b, 0x41, 0x00, 0x21, 0x04, 0x20, 0x01, 0x20, 0x02, 0x10,
0x10, 0x41, 0x0a, 0x10, 0x0f, 0x0c, 0x02, 0x0b, 0x0b, 0x0b, 0x20, 0x00,
0x10, 0x0b, 0x0b, 0x2e, 0x01, 0x02, 0x7f, 0x41, 0x00, 0x21, 0x03, 0x41,
0x00, 0x21, 0x04, 0x02, 0x40, 0x03, 0x40, 0x02, 0x40, 0x02, 0x40, 0x20,
0x03, 0x0e, 0x01, 0x00, 0x00, 0x0b, 0x41, 0x00, 0x21, 0x04, 0x20, 0x01,
0x20, 0x02, 0x10, 0x10, 0x0c, 0x02, 0x0b, 0x0b, 0x0b, 0x20, 0x00, 0x10,
0x0b, 0x0b, 0x08, 0x00, 0x10, 0x0c, 0x10, 0x13, 0x10, 0x12, 0x0b, 0x0b,
0x4e, 0x01, 0x00, 0x41, 0x00, 0x0b, 0x48, 0x24, 0x24, 0x77, 0x61, 0x64,
0x73, 0x24, 0x24, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0xe5, 0x87,
0xb9, 0xe8, 0xaf, 0xad, 0xe8, 0xa8, 0x80, 0x28, 0x57, 0x61, 0x29, 0x2f,
0x41, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x20, 0x69, 0x73, 0x20, 0x72,
0x75, 0x6e, 0x6e, 0x69, 0x6e, 0x67, 0x20, 0x2e, 0x2e, 0x2e, 0x0a, 0x68,
0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f, 0x77, 0x61, 0x2d, 0x6c, 0x61,
0x6e, 0x67, 0x2e, 0x6f, 0x72, 0x67, 0x0a
};
unsigned int app_wasm_len = 1543;

View File

@ -1,7 +1,7 @@
// 版权 @2022 凹语言 作者。保留所有权利。
// Wa/Arduino 源代码位置
// https://gitee.com/wa-lang/wa/tree/master/waroot/examples/arduino
// https://gitee.com/wa-lang/wa/tree/master/_examples/arduino
// 导入 Wasm3 头文件
//

View File

@ -1,18 +1,18 @@
// 版权 @2022 凹语言 作者。保留所有权利。
# 版权 @2022 凹语言 作者。保留所有权利。
// BF 虚拟机
# BF 虚拟机
type BrainFuck struct {
mem: [30000]byte
code: string
pos: int
pc: int
mem :[30000]byte
code :string
pos :int
pc :int
}
func NewBrainFuck(code: string) => *BrainFuck {
fn NewBrainFuck(code: string) => *BrainFuck {
return &BrainFuck{code: code}
}
func BrainFuck.Run() {
fn BrainFuck.Run() {
for ; this.pc != len(this.code); this.pc++ {
switch x := this.code[this.pc]; x {
case '>':
@ -34,13 +34,13 @@ func BrainFuck.Run() {
case '.':
print(rune(this.mem[this.pos]))
case ',':
// TODO: support read byte
# TODO: support read byte
}
}
return
}
func BrainFuck.loop(inc: int) {
fn BrainFuck.loop(inc: int) {
for i := inc; i != 0; this.pc += inc {
switch this.code[this.pc+inc] {
case '[':

View File

@ -1,9 +1,9 @@
// 版权 @2019 凹语言 作者。保留所有权利。
# 版权 @2019 凹语言 作者。保留所有权利。
import "brainfuck/bfpkg"
func main() {
// print hi
fn main() {
# print hi
const code = "++++++++++[>++++++++++<-]>++++.+."
vm := bfpkg.NewBrainFuck(code)
vm.Run()

View File

@ -1,27 +1,27 @@
// 版权 @2022 _examples/hello 作者。保留所有权利。
# 版权 @2022 _examples/hello 作者。保留所有权利。
import "fmt"
import "3rdparty/pkg"
import "myapp/mymath"
func main {
fmt.Println(40 + 2)
pkg.Println(100 + 2)
fn main() {
fmt.Println(40+2)
pkg.Println(100+2)
println(mymath.I8Max)
println(sum(100))
heart()
}
func sum(n: int) => int {
v: int
fn sum(n: int) => int {
var v: int
for i := 1; i <= n; i++ {
v += i
}
return v
}
func heart {
fn heart() {
a := 0.0
for y := 1.5; y > -1.5; y = y - 0.1 {
for x := -1.5; x < 1.5; x = x + 0.05 {

View File

@ -0,0 +1,3 @@
# 版权 @2021 凹语言 作者。保留所有权利。
const I8Max = 127

View File

@ -0,0 +1,5 @@
# 版权 @2022 _examples/hello 作者。保留所有权利。
fn Println(x int) {
println(x)
}

View File

@ -0,0 +1,31 @@
# Test the llvm backend.
# Make Arduino's builtin LED blinking.
# `wa native --target=avr arduino_blink.wa`
#wa:linkname __avr_write_port__
fn write_port(p: i16, v: i8)
# Delay a period of time
var cnt: i8
fn delay(n: i32) {
for i := i32(0); i < n; i++ {
cnt++
}
}
fn main() {
# Set Pin #5 (connected with the builtin LED) of Port B to output mode.
write_port(0x24, 0x20)
for b := 0; ; b++ {
if (b % 2) == 0 {
# Turn on the LED.
write_port(0x25, 0x20)
} else {
# Turn off the LED.
write_port(0x25, 0x00)
}
# Delay a period of time
delay(99999)
}
}

View File

@ -1,13 +1,13 @@
// Test the llvm backend.
// Test read/write arrays.
# Test the llvm backend.
# Test read/write arrays.
func main() {
fn main() {
test_array(2, 4)
test_array(7, 9)
}
func test_array(a: int, b: int) {
arr: [10][10]int
fn test_array(a: int, b: int) {
var arr: [10][10]int
for i := 0; i < 10; i++ {
for j := 0; j < 10; j++ {
arr[i][j] = i * j

View File

@ -1,5 +1,5 @@
// Test the llvm backend.
// Test passing array type parameters.
# Test the llvm backend.
# Test passing array type parameters.
const size = 32
@ -8,21 +8,21 @@ type fff32 f32
var arr0: [size]fff32
var arr1: [size]fff32
func test_init() {
fn test_init() {
for i := 0; i < size; i++ {
arr0[i] = fff32(i * i)
}
}
func getarr0a(arr: [size]fff32, i: int) => fff32 {
fn getarr0a(arr: [size]fff32, i: int) => fff32 {
return arr[i]
}
func getarr0b(arr: *[size]fff32, i: int) => fff32 {
fn getarr0b(arr: *[size]fff32, i: int) => fff32 {
return arr[i]
}
func main() {
fn main() {
test_init()
for i := 6; i < 20; i += 2 {
println(getarr0a(arr0, i), ", ", getarr0b(&arr0, i+1))

View File

@ -1,5 +1,5 @@
// Test the llvm backend.
// Test return array type values.
# Test the llvm backend.
# Test return array type values.
const size = 32
@ -7,22 +7,22 @@ type fff32 f32
var arr1: [size]fff32
func makearr0a(i: int) => [size]fff32 {
r: [size]fff32
fn makearr0a(i: int) => [size]fff32 {
var r: [size]fff32
for j := 0; j < size; j++ {
r[j] = fff32(i * j)
}
return r
}
func makearr0b(i: int) => *[size]fff32 {
fn makearr0b(i: int) => *[size]fff32 {
for j := 0; j < size; j++ {
arr1[j] = 2000 - fff32(i*j)
}
return &arr1
}
func main() {
fn main() {
r0, r1 := makearr0a(10), makearr0b(20)
for i := 6; i < 20; i += 2 {
println(r0[i], ", ", r1[i])

View File

@ -1,5 +1,5 @@
// Test the llvm backend.
// Test bitwise logic.
# Test the llvm backend.
# Test bitwise logic.
var a: i64 = 0x55555555
var b: i64 = 0x33333333
@ -8,7 +8,7 @@ var d: i16 = 0x3333
var e: u8 = 0x55
var f: u8 = 0x33
func main() {
fn main() {
println("not ", 0x55555555, " = ", bw_not(0x55555555))
println("not ", 0xaaaaaaaa, " = ", bw_not(0xaaaaaaaa))
println(a, " and ", b, " = ", bw_and(a, b), "(", 0x11111111, ")")
@ -16,18 +16,18 @@ func main() {
println(e, " xor ", f, " = ", bw_xor(e, f), "(", 0x66, ")")
}
func bw_not(a: u32) => u32 {
fn bw_not(a: u32) => u32 {
return ^a
}
func bw_and(a: i64, b: i64) => i64 {
fn bw_and(a: i64, b: i64) => i64 {
return a & b
}
func bw_or(a: i16, b: i16) => i16 {
fn bw_or(a: i16, b: i16) => i16 {
return a | b
}
func bw_xor(a: u8, b: u8) => u8 {
fn bw_xor(a: u8, b: u8) => u8 {
return a ^ b
}

View File

@ -1,7 +1,7 @@
// Test the llvm backend.
// Test comparasions.
# Test the llvm backend.
# Test comparasions.
func main() {
fn main() {
test_cmp0(20, 19)
test_cmp0(20, 20)
test_cmp1(-3, -3)
@ -10,7 +10,7 @@ func main() {
test_cmp2(10, 10.0001)
}
func test_cmp0(a: u16, b: u16) {
fn test_cmp0(a: u16, b: u16) {
if a > b {
println(a, " > ", b)
} else {
@ -18,7 +18,7 @@ func test_cmp0(a: u16, b: u16) {
}
}
func test_cmp1(a: i64, b: i64) {
fn test_cmp1(a: i64, b: i64) {
if a <= b {
println(a, " <= ", b)
} else {
@ -26,7 +26,7 @@ func test_cmp1(a: i64, b: i64) {
}
}
func test_cmp2(a: f64, b: f64) {
fn test_cmp2(a: f64, b: f64) {
if a != b {
println(a, " != ", b)
} else {

View File

@ -1,7 +1,7 @@
// Test the llvm backend.
// Test integer -> integer convertion.
# Test the llvm backend.
# Test integer -> integer convertion.
func main() {
fn main() {
println(i32(convert_i32_to_i16(65537)))
println(u32(convert_i32_to_u16(65537)))
println(convert_i16_to_i32(100))
@ -10,18 +10,18 @@ func main() {
println(convert_u16_to_i32(65530))
}
func convert_i32_to_i16(a: i32) => i16 {
fn convert_i32_to_i16(a: i32) => i16 {
return i16(a)
}
func convert_i32_to_u16(a: i32) => u16 {
fn convert_i32_to_u16(a: i32) => u16 {
return u16(a)
}
func convert_i16_to_i32(a: i16) => i32 {
fn convert_i16_to_i32(a: i16) => i32 {
return i32(a)
}
func convert_u16_to_i32(a: u16) => i32 {
fn convert_u16_to_i32(a: u16) => i32 {
return i32(a)
}

View File

@ -0,0 +1,10 @@
# Test the llvm backend.
# Test 'floating point' -> 'floating point' convertion.
fn convert_f64_to_f32(a: f64) => f32 {
return f32(a)
}
fn main() {
println(convert_f64_to_f32(3.1415926535))
}

View File

@ -1,17 +1,17 @@
// Test the llvm backend.
// Test integer -> 'floating point' convertion.
# Test the llvm backend.
# Test integer -> 'floating point' convertion.
func main() {
fn main() {
println(convert_i16_to_f64(100))
println(convert_i16_to_f64(-100))
println(convert_u16_to_f64(100))
println(convert_u16_to_f64(65530))
}
func convert_i16_to_f64(a: i16) => f64 {
fn convert_i16_to_f64(a: i16) => f64 {
return f64(a)
}
func convert_u16_to_f64(a: u16) => f64 {
fn convert_u16_to_f64(a: u16) => f64 {
return f64(a)
}

View File

@ -1,7 +1,7 @@
// Test the llvm backend.
// Test 'floating point' -> integer convertion.
# Test the llvm backend.
# Test 'floating point' -> integer convertion.
func main() {
fn main() {
println(convert_f64_to_i32(100.001))
println(convert_f64_to_u32(100.001))
println(convert_f64_to_i32(99.99))
@ -10,10 +10,10 @@ func main() {
println(convert_f64_to_u32(-100.001))
}
func convert_f64_to_i32(a: f64) => i32 {
fn convert_f64_to_i32(a: f64) => i32 {
return i32(a)
}
func convert_f64_to_u32(a: f64) => u32 {
fn convert_f64_to_u32(a: f64) => u32 {
return u32(a)
}

View File

@ -1,25 +1,25 @@
// Test the llvm backend.
// Test f32 operations.
# Test the llvm backend.
# Test float32 operations.
type fff32 f32
func getPi() => fff32 {
fn getPi() => fff32 {
return 3.1415926535
}
func getE() => fff32 {
fn getE() => fff32 {
return 2.71828
}
func minusf32(a: fff32) => fff32 {
fn minusf32(a: fff32) => fff32 {
return 0 - a
}
func circle_area(r: fff32) => fff32 {
fn circle_area(r: fff32) => fff32 {
return r * r * 3.1415926
}
func main() {
fn main() {
println(getPi())
println(getE())
println(minusf32(getPi()))

View File

@ -1,15 +1,15 @@
// Test the llvm backend.
// Test global constants.
# Test the llvm backend.
# Test global constants.
const gbegin = 10
const gend = 20
func test_global_consts() {
fn test_global_consts() {
for i := gbegin; i < gend; i++ {
println(i, " - ", gbegin, " = ", i-gbegin)
}
}
func main() {
fn main() {
test_global_consts()
}

View File

@ -1,19 +1,19 @@
// Test the llvm backend.
// Test read/write global variables.
# Test the llvm backend.
# Test read/write global variables.
type ty0 struct {
v0: int
v1: f64
v0 :int
v1 :float64
}
var gv0: ty0 = ty0{5555, 3.1415926}
var gv1: [4]int = [4]int{81, 82, 17, 76}
func test_global_variable() {
fn test_global_variable() {
println("gv0: {", gv0.v0, ", ", gv0.v1, "}")
println("gv1: {", gv1[0], ", ", gv1[1], ", ", gv1[2], ", ", gv1[3], "}")
}
func main() {
fn main() {
test_global_variable()
}

View File

@ -1,15 +1,15 @@
// Test the llvm backend.
// Test read/write global variables.
# Test the llvm backend.
# Test read/write global variables.
type ty0 struct {
v0: int
v1: f64
v0 :int
v1 :float64
}
var gv0: ty0 = ty0{5555, 3.1415926}
var gv1: [4]int = [4]int{81, 82, 17, 76}
func test_global_variable() {
fn test_global_variable() {
gv0.v0 = 8888
gv0.v1 = 2.71828
gv1[0] += 2
@ -20,6 +20,6 @@ func test_global_variable() {
println("gv1: {", gv1[0], ", ", gv1[1], ", ", gv1[2], ", ", gv1[3], "}")
}
func main() {
fn main() {
test_global_variable()
}

View File

@ -1,6 +1,6 @@
// Test the llvm backend.
# Test the llvm backend.
func main() {
fn main() {
a := 0.0
for y := 1.5; y > -1.5; y = y - 0.2 {
for x := -1.5; x < 1.5; x = x + 0.1 {

View File

@ -1,21 +1,21 @@
// Test the llvm backend.
// Test anonymous functions and closure functions.
# Test the llvm backend.
# Test anonymous functions and closure functions.
type pair struct {
i: f32
j: f32
i :f32
j :f32
}
func main() {
fn main() {
print("Hello, ")
func() {
fn() {
println("World!")
}()
i: int = 31
j: [4]f32 = [4]f32{1, 2.2, 5.5, 9.8}
k: pair = pair{3.14, 2.718}
show := func(q: int) {
var i: int = 31
var j: [4]f32 = [4]f32{1, 2.2, 5.5, 9.8}
var k: pair = pair{3.14, 2.718}
show := fn(q: int) {
println(i, " + ", q, " = ", i+q)
println("{", j[0], ", ", j[1], ", ", j[2], ", ", j[3], "}")
println("{", k.i, ", ", k.j, "}")

View File

@ -1,11 +1,11 @@
// Test the llvm backend.
// Test loops.
# Test the llvm backend.
# Test loops.
func main() {
fn main() {
test_loop(10)
}
func test_loop(a: i16) {
fn test_loop(a: i16) {
for i := i16(0); i < a; i++ {
println(i, " * ", i, " = ", i*i)
}

View File

@ -1,11 +1,11 @@
// Test the llvm backend.
// Test loops.
# Test the llvm backend.
# Test loops.
func main() {
fn main() {
test_loop(10, 10)
}
func test_loop(a: u64, b: u64) {
fn test_loop(a: u64, b: u64) {
for i := u64(0); i < a; i++ {
for j := u64(0); j < b; j++ {
println(i, " * ", j, " = ", i*j)

View File

@ -1,18 +1,18 @@
// Test the llvm backend.
// Test multiple return values.
# Test the llvm backend.
# Test multiple return values.
type pair struct {
a: f32
b: f32
a :f32
b :f32
}
func calc() => ([4]f32, pair, f32) {
fn calc() => ([4]f32, pair, f32) {
a := [4]f32{1.1, 2.11, 3.111, 4.1111}
b := pair{-10.123, 0.123}
return a, b, 2.4 + 1.3
}
func main() {
fn main() {
a, b, c := calc()
println("{", a[0], ", ", a[1], ", ", a[2], ", ", a[3], "}")
println("{", b.a, ", ", b.b, "}")

View File

@ -1,10 +1,10 @@
// Test the llvm backend.
// Test read/write via a pointer.
# Test the llvm backend.
# Test read/write via a pointer.
var gint0: int = 100
var gint1: int = 200
func get_int_addr(a: int) => *int {
fn get_int_addr(a: int) => *int {
if a > 0 {
return &gint0
} else {
@ -12,18 +12,18 @@ func get_int_addr(a: int) => *int {
}
}
func set_int(a: *int) {
fn set_int(a: *int) {
*a += 10
}
func test_pointer(a: int) {
fn test_pointer(a: int) {
println(gint0, ", ", gint1)
p := get_int_addr(a)
set_int(p)
println(gint0, ", ", gint1)
}
func main() {
fn main() {
test_pointer(1)
test_pointer(-1)
}

View File

@ -1,8 +1,8 @@
// Test the llvm backend.
# Test the llvm backend.
func main() {
fn main() {
for n := 2; n <= 30; n = n + 1 {
isPrime: int = 1
var isPrime: int = 1
for i := 2; i*i <= n; i = i + 1 {
if x := n % i; x == 0 {
isPrime = 0

View File

@ -0,0 +1,6 @@
# Test the llvm backend.
# Test printing strings.
fn main() {
println("您好,凹语言!\n\"Hello, wa-lang!\"")
}

22
_examples/llvm/print_1.wa Normal file
View File

@ -0,0 +1,22 @@
# Test the llvm backend.
# Test printing integers.
fn main() {
println(test_calc1(6, 9, 8), ", ", 5, ", ", test_calc5(6, 9, 8))
}
fn test_calc0(a: i32, b: i32, c: i32) => i32 {
return (-a) * 5 / (b - c + 2)
}
fn test_calc1(a: i32, b: i32, c: i32) => i32 {
return test_calc0(a, b, c)
}
fn test_calc4(a: u16, b: u16, c: u16) => u16 {
return (-a) * 5 / (b - c + 2)
}
fn test_calc5(a: u16, b: u16, c: u16) => u16 {
return test_calc4(-a, b, c)
}

14
_examples/llvm/print_2.wa Normal file
View File

@ -0,0 +1,14 @@
# Test the llvm backend.
# Test printing float64 values.
fn main() {
println(5.44, ", ", test_calc3(6, 9, 8))
}
fn test_calc2(a: f64, b: f64, c: f64) => f64 {
return (-a) * 5 / (b - c + 2)
}
fn test_calc3(a: f64, b: f64, c: f64) => f64 {
return test_calc2(a, b, c)
}

10
_examples/llvm/print_3.wa Normal file
View File

@ -0,0 +1,10 @@
# Test the llvm backend.
# Test printing small type values.
fn main() {
test_print(-100, 100, -100, 100, 5)
}
fn test_print(a: i16, b: u16, c: i8, d: u8, e: f32) {
println(a, ", ", b, ", ", c, ", ", d, ", ", e/2)
}

View File

@ -1,5 +1,5 @@
// Test the llvm backend.
// Test logical/arithmetic shift operations.
# Test the llvm backend.
# Test logical/arithmetic shift operations.
var ga: i32 = -15
var gb: i32 = 15
@ -7,7 +7,7 @@ var gc: i64 = -15
var gd: i64 = 15
var ge: u16 = 0xffcc
func main() {
fn main() {
println(ga, " << ", 2, " = ", test_shl_0(ga, 2))
println(gb, " << ", 2, " = ", test_shl_1(gb, 2))
println(ga, " << ", 2, " = ", test_shl_2(ga, 2))
@ -17,30 +17,30 @@ func main() {
println(ge, " >> ", 2, " = ", test_lshr_1(ge, 2), "(", 0x3ff3, ")")
}
func test_shl_0(a: i32, b: i64) => i32 {
fn test_shl_0(a: i32, b: i64) => i32 {
return a << b
}
func test_shl_1(a: i32, b: i16) => i32 {
fn test_shl_1(a: i32, b: i16) => i32 {
return a << b
}
func test_shl_2(a: i32, b: u16) => i32 {
fn test_shl_2(a: i32, b: u16) => i32 {
return a << b
}
func test_ashr_0(a: i64, b: i64) => i64 {
fn test_ashr_0(a: i64, b: i64) => i64 {
return a >> b
}
func test_ashr_1(a: i64, b: u32) => i64 {
fn test_ashr_1(a: i64, b: u32) => i64 {
return a >> b
}
func test_lshr_0(a: u16, b: i32) => u16 {
fn test_lshr_0(a: u16, b: i32) => u16 {
return a >> b
}
func test_lshr_1(a: u16, b: u8) => u16 {
fn test_lshr_1(a: u16, b: u8) => u16 {
return a >> b
}

View File

@ -1,7 +1,7 @@
// Test the llvm backend.
// Test read/write structs.
# Test the llvm backend.
# Test read/write structs.
func main() {
fn main() {
test_struct(10)
test_struct(11)
test_struct(2)
@ -10,13 +10,13 @@ func main() {
}
type t0 struct {
a: i64
b: i32
c: [4]f64
d: u32
a :int64
b :int32
c :[4]f64
d :uint32
}
func test_struct(a: int) {
fn test_struct(a: int) {
s0 := t0{17, -668, [4]f64{2.71828, 0.717, 3.14159}, 234}
switch a {
case 10:

View File

@ -1,7 +1,7 @@
// Test the llvm backend.
// Test read/write structs.
# Test the llvm backend.
# Test read/write structs.
func main() {
fn main() {
test_struct1(10, 0, 0)
test_struct1(11, 1, 0)
test_struct1(2, 0, 1)
@ -10,13 +10,13 @@ func main() {
}
type t0 struct {
a: i64
b: i32
c: [4]f64
d: u32
a :int64
b :int32
c :[4]f64
d :uint32
}
func test_struct1(a: int, b: int, c: int) {
fn test_struct1(a: int, b: int, c: int) {
s0 := [2]t0{{11, -12, [4]f64{0.1, -0.2}, 13}, {21, -22, [4]f64{1.1, -1.2}, 24}}
switch a {
case 10:

View File

@ -1,33 +1,33 @@
// Test the llvm backend.
// Test passing struct type parameters.
# Test the llvm backend.
# Test passing struct type parameters.
type fff32 f32
const size = 16
type struct_t0 struct {
arr0: [size]int
arr1: [size]fff32
arr0 :[size]int
arr1 :[size]fff32
}
var st0: struct_t0
func test_init() {
fn test_init() {
for i := 0; i < size; i++ {
st0.arr0[i] = i * i
st0.arr1[i] = fff32(i) * 2.0
}
}
func getst0int(st0: struct_t0, i: int) => int {
fn getst0int(st0: struct_t0, i: int) => int {
return st0.arr0[i]
}
func getst0f32(st0: *struct_t0, i: int) => fff32 {
fn getst0f32(st0: *struct_t0, i: int) => fff32 {
return st0.arr1[i]
}
func main() {
fn main() {
test_init()
for i := 6; i < 14; i += 2 {
println(getst0int(st0, i), ", ", getst0f32(&st0, i+1))

View File

@ -1,17 +1,17 @@
// Test the llvm backend.
// Test return struct type values.
# Test the llvm backend.
# Test return struct type values.
const size = 16
type struct_t0 struct {
arr0: [size]int
arr1: [size]f32
arr0 :[size]int
arr1 :[size]f32
}
var st1: struct_t0
func maket0a(i: int) => struct_t0 {
r: struct_t0
fn maket0a(i: int) => struct_t0 {
var r: struct_t0
for j := 0; j < 16; j++ {
r.arr0[j] = 100 - j - i
r.arr1[j] = 200.0 - f32(j+i)
@ -19,7 +19,7 @@ func maket0a(i: int) => struct_t0 {
return r
}
func maket0b(i: int) => *struct_t0 {
fn maket0b(i: int) => *struct_t0 {
for j := 0; j < 16; j++ {
st1.arr0[j] = 100 - j - i
st1.arr1[j] = 200.0 - f32(j+i)
@ -27,7 +27,7 @@ func maket0b(i: int) => *struct_t0 {
return &st1
}
func main() {
fn main() {
r0, r1 := maket0a(20), maket0b(30)
for i := 0; i < 16; i++ {
println(r0.arr0[i], ", ", r0.arr1[i], " : ", r1.arr0[i], ", ", r1.arr1[i])

View File

@ -0,0 +1,16 @@
# Test the llvm backend.
# Test unconditional jump.
fn main() {
test_jmp(4)
}
fn test_jmp(a: i32) {
for {
if a > 10 {
return
}
println(a)
a++
}
}

19
_examples/misc/array.wa Normal file
View File

@ -0,0 +1,19 @@
# 版权 @2021 凹语言 作者。保留所有权利。
package main
var I [8]i32
fn Gen_arr(param: [8]i32) => [8]i32 {
param[3] += 2
return param
}
fn main() {
var j [8]i32
j[3] = 40
I = Gen_arr(j)
println(j[3])
println(I[3])
}

18
_examples/misc/array_1.wa Normal file
View File

@ -0,0 +1,18 @@
# 版权 @2022 凹语言 作者。保留所有权利。
fn main {
test_array(2, 4)
test_array(7, 9)
}
fn test_array(a: int, b: int) {
var arr [10][10]int
for i := 0; i < 10; i++ {
for j := 0; j < 10; j++ {
arr[i][j] = i * j
}
}
println("arr[", a, "][", b, "] = ", arr[a][b])
println("arr[", b, "][", a, "] = ", arr[b][a])
}

50
_examples/misc/closure.wa Normal file
View File

@ -0,0 +1,50 @@
# 版权 @2021 凹语言 作者。保留所有权利。
type FP fn (i: i32) => i32
type ST struct {
i: i32
}
fn (t *ST) meth_p(p: i32) => i32 {
t.i += p
return t.i
}
fn (t ST) meth_v(p: i32) => i32 {
t.i += p
return t.i
}
var g_f: FP
fn main() {
var o ST
o.i = 11
g_f = o.meth_p
println(g_f(11))
println(o.i)
g_f = o.meth_v
println(g_f(11))
println(o.i)
n := i32(21)
g_f = fn(i: i32) => i32{
n += i
return n
}
println(g_f(22))
println(n)
fn(i: i32) {
n += i
}(22)
println(n)
g_f = Double
println(g_f(13))
}
fn Double(i: i32) => i32 {
return i * 2
}

20
_examples/misc/global.wa Normal file
View File

@ -0,0 +1,20 @@
# 版权 @2021 凹语言 作者。保留所有权利。
package main
var counter i32 = 13
var G *i32
fn gen_i() => *i32{
var i i32
i = counter
counter++
return &i
}
fn main() {
G = gen_i()
println(*G)
G = gen_i()
println(*G)
G = nil
}

View File

@ -1,6 +1,6 @@
// 版权 @2021 凹语言 作者。保留所有权利。
# 版权 @2021 凹语言 作者。保留所有权利。
func main {
fn main {
a := 0.0
for y := 1.5; y > -1.5; y = y - 0.2 {
for x := -1.5; x < 1.5; x = x + 0.1 {

View File

@ -0,0 +1,19 @@
# 版权 @2021 凹语言 作者。保留所有权利。
fn main() {
i := ST{i: 1, j:2}
j := ST{i: 3, j:4}
i, j = Swap(i, j)
println(i.i)
println(i.j)
println(j.i)
println(j.j)
}
fn Swap(i, j: ST) => (ST, ST){
return j, i
}
type ST struct{
i, j: i32
}

View File

@ -0,0 +1,428 @@
# 版权 @2022 凹语言 作者。保留所有权利。
fn main {
println("您好,凹语言!\nHello, wa-lang!")
println("幸运整数:", test_calc1(6, 9, 8), ", ", 5, ", ", test_calc5(6, 9, 8))
println("幸运浮点数:", 5.44, ", ", test_calc3(6, 9, 8))
test_print(-100, 100, -100, 100, 5)
test_cmp0(20, 19)
test_cmp0(20, 20)
test_cmp1(-3, -3)
test_cmp1(-3, -4)
test_cmp2(10, 10)
test_cmp2(10, 10.0001)
test_jmp(4)
test_loop0(10)
test_loop1(10, 10)
test_array(2, 4)
test_array(7, 9)
test_struct0(10)
test_struct0(11)
test_struct0(2)
test_struct0(13)
test_struct0(0)
test_struct1(10, 0, 0)
test_struct1(11, 1, 0)
test_struct1(2, 0, 1)
test_struct1(13, 1, 0)
test_struct1(2, 1, 0)
test_convert0()
test_convert1()
test_convert2()
test_convert3()
test_global_consts()
test_global_variables_0()
test_global_variables_1()
test_pointer(1)
test_pointer(-1)
test_f32()
test_struct2()
test_struct3()
test_struct4()
test_array2()
test_array3()
test_array4()
bye()
}
fn bye() {
println("再见!\nbye!")
}
fn test_calc0(a i32, b i32, c i32) i32 {
return (-a) * 5 / (b - c + 2)
}
fn test_calc1(a i32, b i32, c i32) i32 {
return test_calc0(a, b, c)
}
fn test_calc2(a f64, b f64, c f64) f64 {
return (-a) * 5 / (b - c + 2)
}
fn test_calc3(a f64, b f64, c f64) f64 {
return test_calc2(a, b, c)
}
fn test_calc4(a u16, b u16, c u16) u16 {
return (-a) * 5 / (b - c + 2)
}
fn test_calc5(a u16, b u16, c u16) u16 {
return test_calc4(-a, b, c)
}
fn test_cmp0(a u16, b u16) {
if a > b {
println(a, " > ", b)
} else {
println(a, " <= ", b)
}
}
fn test_cmp1(a i64, b i64) {
if a <= b {
println(a, " <= ", b)
} else {
println(a, " > ", b)
}
}
fn test_cmp2(a f64, b f64) {
if a != b {
println(a, " != ", b)
} else {
println(a, " == ", b)
}
}
fn test_jmp(a i32) {
for {
if a > 10 {
return
}
println(a)
a++
}
}
fn test_loop0(a i16) {
for i := i16(0); i < a; i++ {
println(i, " * ", i, " = ", i * i)
}
}
fn test_loop1(a u64, b u64) {
for i := u64(0); i < a; i++ {
for j := u64(0); j < b; j++ {
println(i, " * ", j, " = ", i * j)
}
}
}
fn test_array(a int, b int) {
var arr [10][10]int
for i := 0; i < 10; i++ {
for j := 0; j < 10; j++ {
arr[i][j] = i * j
}
}
println("arr[", a, "][", b, "] = ", arr[a][b])
println("arr[", b, "][", a, "] = ", arr[b][a])
}
type t0 struct {
a int64
b int32
c [4]f64
d uint32
}
fn test_struct0(a int) {
s0 := t0{17, -668, [4]f64{2.71828, 0.717, 3.14159}, 234}
switch a {
case 10:
println(s0.a)
case 11:
println(s0.b)
case 13:
println(s0.d)
default:
println(s0.c[a])
}
}
fn test_struct1(a int, b int, c int) {
s0 := [2]t0{{11, -12, [4]f64{0.1, -0.2}, 13}, {21, -22, [4]f64{1.1, -1.2}, 24}}
switch a {
case 10:
println(s0[b].a)
case 11:
println(s0[b].b)
case 13:
println(s0[b].d)
default:
println(s0[b].c[c])
}
}
type struct_t0 struct {
arr0 [16]int
arr1 [16]f32
}
var st0 struct_t0
var st1 struct_t0
fn test_struct2() {
for i := 0; i < 16; i++ {
st0.arr0[i] = i * i
st0.arr1[i] = f32(i) * 2.0
}
}
fn getst0int(st0 struct_t0, i int) int {
return st0.arr0[i]
}
fn getst0f32(st0 *struct_t0, i int) f32 {
return st0.arr1[i]
}
fn test_struct3() {
for i := 6; i < 14; i += 2 {
println(getst0int(st0, i), ", ", getst0f32(&st0, i + 1))
}
}
fn maket0a(i int) struct_t0 {
var r struct_t0
for j := 0; j < 16; j++ {
r.arr0[j] = 100 - j - i
r.arr1[j] = 200.0 - f32(j + i)
}
return r
}
fn maket0b(i int) *struct_t0 {
for j := 0; j < 16; j++ {
st1.arr0[j] = 100 - j - i
st1.arr1[j] = 200.0 - f32(j + i)
}
return &st1
}
fn test_struct4() {
r0, r1 := maket0a(20), maket0b(30)
for i := 0; i < 16; i++ {
println(r0.arr0[i], ", ", r0.arr1[i], " : ", r1.arr0[i], ", ", r1.arr1[i])
}
}
type fff32 f32
var arr0 [32]fff32
var arr1 [32]fff32
fn test_array2() {
for i := 0; i < 32; i++ {
arr0[i] = fff32(i * i)
}
}
fn getarr0a(arr [32]fff32, i int) fff32 {
return arr[i]
}
fn getarr0b(arr *[32]fff32, i int) fff32 {
return arr[i]
}
fn makearr0a(i int) [32]fff32 {
var r [32]fff32
for j := 0; j < 32; j++ {
r[j] = fff32(i * j)
}
return r
}
fn makearr0b(i int) *[32]fff32 {
for j := 0; j < 32; j++ {
arr1[j] = 2000 - fff32(i * j)
}
return &arr1
}
fn test_array3() {
for i := 6; i < 20; i += 2 {
println(getarr0a(arr0, i), ", ", getarr0b(&arr0, i + 1))
}
}
fn test_array4() {
r0, r1 := makearr0a(10), makearr0b(20)
for i := 6; i < 20; i += 2 {
println(r0[i], ", ", r1[i])
}
}
fn convert_i32_to_i16(a i32) i16 {
return i16(a)
}
fn convert_i32_to_u16(a i32) u16 {
return u16(a)
}
fn convert_i16_to_i32(a i16) i32 {
return i32(a)
}
fn convert_u16_to_i32(a u16) i32 {
return i32(a)
}
fn test_convert0() {
println(i32(convert_i32_to_i16(65537)))
println(u32(convert_i32_to_u16(65537)))
println(convert_i16_to_i32(100))
println(convert_i16_to_i32(-100))
println(convert_u16_to_i32(100))
println(convert_u16_to_i32(65530))
}
fn convert_f64_to_f32(a f64) f32 {
return f32(a)
}
fn test_convert1() {
println(f64(convert_f64_to_f32(3.1415926535)))
}
fn convert_i16_to_f64(a i16) f64 {
return f64(a)
}
fn convert_u16_to_f64(a u16) f64 {
return f64(a)
}
fn test_convert2() {
println(convert_i16_to_f64(100))
println(convert_i16_to_f64(-100))
println(convert_u16_to_f64(100))
println(convert_u16_to_f64(65530))
}
fn convert_f64_to_i32(a f64) i32 {
return i32(a)
}
fn convert_f64_to_u32(a f64) u32 {
return u32(a)
}
fn test_convert3() {
println(convert_f64_to_i32(100.001))
println(convert_f64_to_u32(100.001))
println(convert_f64_to_i32(99.99))
println(convert_f64_to_u32(99.99))
println(convert_f64_to_i32(-100.001))
println(convert_f64_to_u32(-100.001))
}
fn test_print(a i16, b u16, c i8, d u8, e f32) {
println(a, ", ", b, ", ", c, ", ", d, ", ", e/2)
}
const gbegin = 10
const gend = 20
fn test_global_consts() {
for i := gbegin; i < gend; i++ {
println(i, " - ", gbegin, " = ", i - gbegin)
}
}
type ty0 struct {
v0 int
v1 float64
}
var gv0 ty0 = ty0{5555, 3.1415926}
var gv1 [4]int = [4]int{81, 82, 17, 76}
fn test_global_variables_0() {
println("gv0: {", gv0.v0, ", ", gv0.v1, "}")
println("gv1: {", gv1[0], ", ", gv1[1], ", ", gv1[2], ", ", gv1[3], "}")
}
fn test_global_variables_1() {
gv0.v0 = 8888
gv0.v1 = 2.71828
gv1[0] += 2
gv1[1] += 3
gv1[2] += 4
gv1[3] += 5
println("gv0: {", gv0.v0, ", ", gv0.v1, "}")
println("gv1: {", gv1[0], ", ", gv1[1], ", ", gv1[2], ", ", gv1[3], "}")
}
var gint0 int = 100
var gint1 int = 200
fn get_int_addr(a int) *int {
if a > 0 {
return &gint0
} else {
return &gint1
}
}
fn set_int(a *int) {
*a += 10
}
fn test_pointer(a int) {
println(gint0, ", ", gint1)
p := get_int_addr(a)
set_int(p)
println(gint0, ", ", gint1)
}
fn getPi() f32 {
return 3.1415926535
}
fn getE() f32 {
return 2.71828
}
fn minusf32(a f32) f32 {
return 0 - a
}
fn circle_area(r f32) f32 {
return r * r * 3.1415926
}
fn test_f32() {
println(getPi())
println(getE())
println(minusf32(getPi()))
println(minusf32(-1.3))
println(circle_area(1.1))
println(circle_area(getE()))
}

View File

@ -1,8 +1,8 @@
// 版权 @2019 凹语言 作者。保留所有权利。
# 版权 @2019 凹语言 作者。保留所有权利。
func main() {
fn main() {
for n := 2; n <= 30; n = n + 1 {
isPrime: int = 1
var isPrime int = 1
for i := 2; i*i <= n; i = i + 1 {
if x := n % i; x == 0 {
isPrime = 0

18
_examples/misc/ref.wa Normal file
View File

@ -0,0 +1,18 @@
# 版权 @2021 凹语言 作者。保留所有权利。
fn main() {
p := new_int()
println(*p)
proc(p)
println(*p)
}
fn new_int() => *i32 {
var i: i32
i = 42
return &i
}
fn proc(i: *i32) {
*i = 13
}

View File

@ -1,6 +1,6 @@
// 版权 @2021 凹语言 作者。保留所有权利。
# 版权 @2021 凹语言 作者。保留所有权利。
func main() {
fn main() {
a := [4]i32{12, 34, 56, 78}
s := a[0:1]
s[0] = 42
@ -9,7 +9,7 @@ func main() {
println(a[1]) # 13
println(len(s)) # 2
k: []i32
var k: []i32
k = append(k, 99, 81, 170)
println(k[0]) # 99
@ -22,4 +22,4 @@ func main() {
l[0] = 111
println(l[0]) #111
println(k[0]) #99
}
}

View File

@ -1,13 +1,14 @@
func gen_str() => string {
fn gen_str() => string {
return "123456"
}
func main() {
fn main() {
println("你好,凹语言!")
s1 := gen_str()
s2 := s1[0:3]
s2 = s2 + "abc"
println(s1)
println(s2)
println(s2)
}

View File

@ -1,6 +1,6 @@
// 版权 @2021 凹语言 作者。保留所有权利。
# 版权 @2021 凹语言 作者。保留所有权利。
func main() {
fn main() {
i := gen_scref()
println(*i.a)
println(i.b)
@ -19,18 +19,18 @@ type sc struct {
sp
}
func gen_scref() => *sc {
v: sc
i: i32
fn gen_scref() => *sc {
var v: sc
var i: i32
i = 13
v.a = &i
v.b = 42
return &v
}
func gen_sc() => sc {
i: i32 = 26
v: sc
fn gen_sc() => sc {
var i: i32 = 26
var v: sc
v.a = &i
v.b = 58
return v

View File

@ -1,4 +1,4 @@
// 版权 @2022 _examples/hello 作者。保留所有权利。
# 版权 @2022 _examples/hello 作者。保留所有权利。
import (
"pkg/mypkg"
@ -9,14 +9,14 @@ type ST struct {
B: i32
}
var G: ST
var G ST
func Do {
fn Do() {
G.A = "13"
G.B = 1024
}
func main {
fn main() {
mypkg.Do(42)
println(mypkg.G.A)
println(mypkg.G.B)
@ -24,7 +24,7 @@ func main {
Do()
println(G.A)
println(G.B)
println(mypkg.G.A)
println(mypkg.G.B)
}

View File

@ -0,0 +1,13 @@
# 版权 @2022 _examples/hello 作者。保留所有权利。
type ST struct {
A: i32
B: string
}
var G ST
fn Do(x i32) {
G.A = x
G.B = "Hellow wa"
}

View File

@ -0,0 +1,5 @@
# 版权 @2022 _examples/hello 作者。保留所有权利。
fn Println(x int) {
println(x)
}

View File

@ -0,0 +1,3 @@
fn PrintInt(x: int) {
print(x, " ")
}

View File

@ -0,0 +1,10 @@
# 版权 @2022 凹语言™ 作者。保留所有权利。
fn isPrime(n: int) => bool {
for i := 2; i*i <= n; i = i + 1 {
if n%i == 0 {
return false
}
}
return true
}

View File

@ -1,9 +1,9 @@
// 版权 @2022 凹语言™ 作者。保留所有权利。
# 版权 @2022 凹语言™ 作者。保留所有权利。
import "examples/prime/benpkg"
import "joypkg"
func main {
fn main() {
for n := 2; n <= 100; n = n + 1 {
if isPrime(n) {
benpkg.PrintInt(n)

View File

@ -0,0 +1,3 @@
fn PrintIntComma(x: int) {
print(x, ",")
}

18
_examples/snake/Makefile Normal file
View File

@ -0,0 +1,18 @@
build:
-@rm ./web/*.wasm
go run ../../main.go fmt ./src/main.wa
go run ../../main.go fmt ./src/canvas/canvas.wa
go run ../../main.go build -o ./web/snake.wasm .
run:
make build
cd web && python3 -m http.server
publish:
make build
-rm -rf ../../docs/snake/
mkdir -p ../../docs/snake
cp ./web/* ../../docs/snake/
clean:

View File

@ -0,0 +1,3 @@
wa build _examples/snake
wat2wasm a.out.wat
copy a.out.wasm _examples/snake/web/snake.wasm

View File

@ -1,4 +1,4 @@
// 版权 @2022 凹语言 作者。保留所有权利。
# 版权 @2022 凹语言 作者。保留所有权利。
/*
创建html.canvas的函数由JS环境导入
@ -6,7 +6,7 @@ w、h为画布以像素为单位的宽高
返回值为画布对象对应的网页DOM对象id
*/
#wa:import wa_js_env newCanvas
func newCanvas_JS(w, h: u32) => u32
fn newCanvas_JS(w, h: u32) => u32
/*
将帧缓存更新至html.canvas的函数由JS环境导入
@ -14,80 +14,80 @@ id为画布对象对应的网页DOM对象id
buf为帧缓存指针
*/
#wa:import wa_js_env updateCanvas
func updateCanvas_JS(id: u32, buf: *u32)
fn updateCanvas_JS(id: u32, buf: *u32)
//画布事件回调函数原型
type OnTouch func(x, y: u32)
type OnKey func(key: u32)
type OnTouch fn (x, y: u32)
type OnKey fn(key: u32)
//画布对象
type Canvas struct {
device_id: u32 //画布对象对应的网页DOM对象id
width: u32 //画布宽度,以像素为单位
height: u32 //画布高度,以像素为单位
frame_buf: []u32 //画布帧缓存容量为Width * Height
device_id: u32 //画布对象对应的网页DOM对象id
width: u32 //画布宽度,以像素为单位
height: u32 //画布高度,以像素为单位
frame_buf: []u32 //画布帧缓存容量为Width * Height
}
//画布事件
type CanvasEvents struct {
Device_id: u32 //画布设备ID
OnMouseDown: OnTouch //鼠标按下时的回调处理函数
OnMouseUp: OnTouch //鼠标松开时的回调处理函数
OnMouseDown: OnTouch //鼠标按下时的回调处理函数
OnMouseUp: OnTouch //鼠标松开时的回调处理函数
OnKeyDown: OnKey //键盘按下时的回调处理函数
OnKeyUp: OnKey //键盘弹起时的回调处理函数
}
//创建一个宽度为w像素、高度为h像素的画布对象
func NewCanvas(w, h: u32) => *Canvas {
canvas: Canvas
fn NewCanvas(w, h: u32) => *Canvas {
var canvas Canvas
canvas.device_id = newCanvas_JS(w, h)
canvas.width = w
canvas.height = h
canvas.frame_buf = make([]u32, w*h)
canvas.frame_buf = make([]u32, w * h)
return &canvas
}
//获取画布设备ID
func Canvas.GetDeviceID() => u32 {
fn Canvas.GetDeviceID() => u32 {
return this.device_id
}
//获取画布宽度
func Canvas.GetWidth() => u32 {
fn Canvas.GetWidth() => u32 {
return this.width
}
//获取画布高度
func Canvas.GetHeight() => u32 {
fn Canvas.GetHeight() => u32 {
return this.height
}
//获取画布对象坐标为(x, y)处的像素颜色值
func Canvas.GetPixel(x, y: u32) => u32 {
return this.frame_buf[y*this.width+x]
fn Canvas.GetPixel(x, y: u32) => u32 {
return this.frame_buf[y * this.width + x]
}
//设置画布对象坐标(x, y)处的颜色值为color
func Canvas.SetPixel(x, y, color: u32) {
this.frame_buf[y*this.width+x] = color
fn Canvas.SetPixel(x, y, color: u32) {
this.frame_buf[y * this.width + x] = color
}
//用color指定的颜色清除整个画布
func Canvas.Clear(color: u32) {
fn Canvas.Clear(color: u32) {
for i := range this.frame_buf {
this.frame_buf[i] = color
}
}
//将画布对象的帧缓存更新至网页DOM对象
func Canvas.Flush() {
updateCanvas_JS(this.device_id, &this.frame_buf[0])
fn Canvas.Flush() {
updateCanvas_JS(this.device_id, &this.frame_buf[0])
}
var canvas_events: []CanvasEvents
func AttachCanvasEvents(e: CanvasEvents) {
fn AttachCanvasEvents(e: CanvasEvents) {
for i := range canvas_events {
if canvas_events[i].Device_id == e.Device_id {
canvas_events[i] = e
@ -103,8 +103,8 @@ func AttachCanvasEvents(e: CanvasEvents) {
id为画布DOM对象对应的Canvas对象id
(x, y)为画布像素坐标系坐标
*/
func OnMouseDown(id: u32, x, y: u32) {
for _, i := range canvas_events {
fn OnMouseDown(id: u32, x, y:u32) {
for _, i := range canvas_events {
if i.Device_id == id {
i.OnMouseDown(x, y)
return
@ -117,8 +117,8 @@ func OnMouseDown(id: u32, x, y: u32) {
id为画布DOM对象对应的Canvas对象id
(x, y)为画布像素坐标系坐标
*/
func OnMouseUp(id: u32, x, y: u32) {
for _, i := range canvas_events {
fn OnMouseUp(id: u32, x, y:u32) {
for _, i := range canvas_events {
if i.Device_id == id {
i.OnMouseUp(x, y)
return
@ -131,8 +131,8 @@ func OnMouseUp(id: u32, x, y: u32) {
id为画布DOM对象对应的Canvas对象id
key为键位。37=← 38=↑ 39=→ 40=↓
*/
func OnKeyDown(id, key: u32) {
for _, i := range canvas_events {
fn OnKeyDown(id, key:u32) {
for _, i := range canvas_events {
if i.Device_id == id {
i.OnKeyDown(key)
return
@ -145,8 +145,8 @@ func OnKeyDown(id, key: u32) {
id为画布DOM对象对应的Canvas对象id
key为键位
*/
func OnKeyUp(id, key: u32) {
for _, i := range canvas_events {
fn OnKeyUp(id, key:u32) {
for _, i := range canvas_events {
if i.Device_id == id {
i.OnKeyUp(key)
return

View File

@ -1,11 +1,41 @@
// 版权 @2019 凹语言 作者。保留所有权利。
# 版权 @2019 凹语言 作者。保留所有权利。
import "snake/canvas"
var ca: *canvas.Canvas
fn Test() {
println(42)
ca = canvas.NewCanvas(255, 255)
var i, j: u32
for i = 0; i < 255; i++ {
for j = 0; j < 255; j++ {
ca.SetPixel(i, j, 0xFF000000+i+j*256)
}
}
ca.Flush()
var caev: canvas.CanvasEvents
caev.Device_id = ca.GetDeviceID()
caev.OnMouseDown = fn(x, y: u32) {
println("OnMouseDown: ", x, " ", y)
}
caev.OnMouseUp = fn(x, y: u32) {
println("OnMouseUp: ", x, " ", y)
}
caev.OnKeyDown = fn(key: u32) {
println("OnKeyDown: ", key)
}
caev.OnKeyUp = fn(key: u32) {
println("OnKeyUp: ", key)
}
canvas.AttachCanvasEvents(caev)
}
type Position struct {
x, y: i32
x, y :i32
}
const DefaultColor = 0x00000000
@ -13,13 +43,13 @@ const BodyColor = 0xFF202020
const FoodColor = 0xFF00FF00
const (
GridNull :u8 = iota
GridNull i8 = iota
GridBody
GridFood
)
const (
DirNull :i32 = iota
DirNull i32 = iota
DirLeft
DirUp
DirRight
@ -29,29 +59,29 @@ const (
var Dirs: [5]Position
type GameState struct {
w, h: i32
scale: i32
grid: []u8
body: []Position
dir: i32
w, h :i32
scale :i32
grid :[]i8
body :[]Position
dir :i32
ca: *canvas.Canvas
ca :*canvas.Canvas
}
var gameState: GameState
func GameState.Init(w, h: i32, scale: i32) {
fn GameState.Init(w, h: i32, scale: i32) {
this.w = w
this.h = h
this.scale = scale
this.grid = make([]u8, u32(w*h))
this.grid = make([]i8, u32(w*h))
this.ca = canvas.NewCanvas(u32(w*scale), u32(h*scale))
caev: canvas.CanvasEvents
var caev: canvas.CanvasEvents
caev.Device_id = this.ca.GetDeviceID()
caev.OnMouseDown = func(x, y: u32) {}
caev.OnMouseUp = func(x, y: u32) {}
caev.OnKeyUp = func(key: u32) {}
caev.OnMouseDown = fn(x, y: u32) {}
caev.OnMouseUp = fn(x, y: u32) {}
caev.OnKeyUp = fn(key: u32) {}
caev.OnKeyDown = this.OnKeyDown
Dirs[DirNull] = Position{x: 0, y: 0}
@ -63,7 +93,7 @@ func GameState.Init(w, h: i32, scale: i32) {
canvas.AttachCanvasEvents(caev)
}
func GameState.Start() {
fn GameState.Start() {
for i := range this.grid {
this.grid[i] = GridNull
}
@ -78,9 +108,9 @@ func GameState.Start() {
this.ca.Flush()
}
func GameState.SetGridType(p: Position, t: u8) {
fn GameState.SetGridType(p: Position, t: i8) {
this.grid[p.y*this.w+p.x] = t
color: u32
var color: u32
switch t {
case GridBody:
color = BodyColor
@ -92,7 +122,7 @@ func GameState.SetGridType(p: Position, t: u8) {
color = DefaultColor
}
x, y: i32
var x, y: i32
for y = 0; y < this.scale; y++ {
for x = 0; x < this.scale; x++ {
this.ca.SetPixel(u32(p.x*this.scale+x), u32(p.y*this.scale+y), color)
@ -101,9 +131,9 @@ func GameState.SetGridType(p: Position, t: u8) {
}
#wa:import wa_js_env rand
func rand_JS(_: i32) => i32
func GameState.GenFood() => Position {
p: Position
fn rand_JS(i32) => i32
fn GameState.GenFood() => Position {
var p: Position
for {
p = Position{x: rand_JS(this.w), y: rand_JS(this.h)}
if this.grid[p.y*this.w+p.x] == GridNull {
@ -113,7 +143,7 @@ func GameState.GenFood() => Position {
}
}
func GameState.OnKeyDown(key: u32) {
fn GameState.OnKeyDown(key: u32) {
switch key {
case 37:
if this.dir == DirNull || this.dir == DirUp || this.dir == DirDown {
@ -137,7 +167,7 @@ func GameState.OnKeyDown(key: u32) {
}
}
func GameState.Step() {
fn GameState.Step() {
if this.dir == DirNull {
return
}
@ -146,8 +176,23 @@ func GameState.Step() {
newHead.x += Dirs[this.dir].x
newHead.y += Dirs[this.dir].y
newHead.x = (newHead.x + this.w) % this.w
newHead.y = (newHead.y + this.h) % this.h
if newHead.x < 0 {
newHead.x = this.w - 1
}
if newHead.x >= this.w {
newHead.x = 0
}
if newHead.y < 0 {
newHead.y = this.h - 1
}
if newHead.y >= this.h {
newHead.y = 0
}
//if newHead.x < 0 || newHead.x >= this.w || newHead.y < 0 || newHead.y >= this.h {
// this.Start()
// return
//}
switch this.grid[newHead.y*this.w+newHead.x] {
case GridBody:
@ -169,11 +214,11 @@ func GameState.Step() {
this.ca.Flush()
}
func Step() {
fn Step() {
gameState.Step()
}
func main() {
fn main() {
gameState.Init(32, 32, 10)
gameState.Start()
}

View File

Before

Width:  |  Height:  |  Size: 174 KiB

After

Width:  |  Height:  |  Size: 174 KiB

View File

@ -8,56 +8,6 @@
init(url) {
let app = this;
let importsObject = {
wasi_snapshot_preview1: new function () {
this.args_get = () => { return 0; }
this.args_sizes_get = () => { return 0; }
this.clock_res_get = () => { return 0; }
this.clock_time_get = () => { return 0; }
this.environ_get = () => { return 0; }
this.environ_sizes_get = () => { return 0; }
this.fd_advise = () => { return 0; }
this.fd_allocate = () => { return 0; }
this.fd_close = () => { return 0; }
this.fd_datasync = () => { return 0; }
this.fd_fdstat_get = () => { return 0; }
this.fd_fdstat_set_flags = () => { return 0; }
this.fd_fdstat_set_rights = () => { return 0; }
this.fd_filestat_get = () => { return 0; }
this.fd_filestat_set_size = () => { return 0; }
this.fd_filestat_set_times = () => { return 0; }
this.fd_pread = () => { return 0; }
this.fd_prestat_get = () => { return 0; }
this.fd_prestat_dir_name = () => { return 0; }
this.fd_pwrite = () => { return 0; }
this.fd_read = () => { return 0; }
this.fd_readdir = () => { return 0; }
this.fd_renumber = () => { return 0; }
this.fd_seek = () => { return 0; }
this.fd_sync = () => { return 0; }
this.fd_tell = () => { return 0; }
this.fd_write = () => { return 0; }
this.path_create_directory = () => { return 0; }
this.path_filestat_get = () => { return 0; }
this.path_filestat_set_times = () => { return 0; }
this.path_link = () => { return 0; }
this.path_open = () => { return 0; }
this.path_readlink = () => { return 0; }
this.path_remove_directory = () => { return 0; }
this.path_rename = () => { return 0; }
this.path_symlink = () => { return 0; }
this.path_unlink_file = () => { return 0; }
this.poll_oneoff = () => { return 0; }
this.proc_exit = () => { return 0; }
this.random_get = () => { return 0; }
this.sched_yield = () => { return 0; }
this.sock_accept = () => { return 0; }
this.sock_recv = () => { return 0; }
this.sock_send = () => { return 0; }
this.sock_shutdown = () => { return 0; }
},
wa_js_env: new function () {
this.waPrintI32 = (i) => {
app._wa_print_buf += i
@ -151,7 +101,6 @@
WebAssembly.instantiateStreaming(fetch(url), importsObject).then(res => {
this._inst = res.instance;
this._inst.exports._start();
const timer = setInterval(gameLoop, 150);
})
}
@ -184,4 +133,5 @@
window['waApp'] = new WaApp();
window['waApp'].init("./snake.wasm")
const timer = setInterval(gameLoop, IS_MOBILE ? 150 : 100);
})()

7
_examples/wz/1.你好.wz Normal file
View File

@ -0,0 +1,7 @@
# 版权 @2022 凹语言 作者。保留所有权利。
引于 "书"
【启】:
书·说:"你好,凹语言!"

12
_examples/wz/2.加法.wz Normal file
View File

@ -0,0 +1,12 @@
# 版权 @2022 凹语言 作者。保留所有权利。
引于 "书"
【启】:
书·说:"你好,凹语言!"
书·曰40、2
【加】(甲, 乙之数) => 数
归于:甲+乙

14
_examples/wz/3.条件.wz Normal file
View File

@ -0,0 +1,14 @@
# 版权 @2022 凹语言 作者。保留所有权利。
引于 "书"
【启】:
书·说:"你好,凹语言!"
设零之数 = 0
若零==1则
书·说:"是的零和1是相等的。"
否则:
书·说:"错了零和1是不同的。"

16
_examples/wz/4.类型.wz Normal file
View File

@ -0,0 +1,16 @@
# 版权 @2022 凹语言 作者。保留所有权利。
引于 "书"
【启】:
书·说:"你好,凹语言!"
设某=点{横:10, 纵:2}
书·曰:某·横 + 某·纵
《点》:
横之数
纵之数

Some files were not shown because too many files have changed in this diff Show More