提交 bcf5bd84 编写于 作者: 3 3dgen

Merge branch 'master' of https://gitee.com/wa-lang/wa

...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
[![Go Report Card](https://goreportcard.com/badge/github.com/wa-lang/wa)](https://goreportcard.com/report/github.com/wa-lang/wa) [![Go Report Card](https://goreportcard.com/badge/github.com/wa-lang/wa)](https://goreportcard.com/report/github.com/wa-lang/wa)
[![Coverage Status](https://coveralls.io/repos/github/wa-lang/wa/badge.svg)](https://coveralls.io/github/wa-lang/wa) [![Coverage Status](https://coveralls.io/repos/github/wa-lang/wa/badge.svg)](https://coveralls.io/github/wa-lang/wa)
[![GitHub release](https://img.shields.io/github/v/tag/wa-lang/wa.svg?label=release)](https://github.com/wa-lang/wa/releases) [![GitHub release](https://img.shields.io/github/v/tag/wa-lang/wa.svg?label=release)](https://github.com/wa-lang/wa/releases)
[![Go Reference](https://pkg.go.dev/badge/github.com/wa-lang/wa.svg)](https://pkg.go.dev/github.com/wa-lang/wa) [![Go Reference](https://pkg.go.dev/badge/wa-lang.org/wa.svg)](https://pkg.go.dev/wa-lang.org/wa)
[![license](https://img.shields.io/github/license/wa-lang/wa.svg)](https://github.com/wa-lang/wa/blob/master/LICENSE) [![license](https://img.shields.io/github/license/wa-lang/wa.svg)](https://gitee.com/wa-lang/wa/blob/master/LICENSE)
</div> </div>
...@@ -20,12 +20,12 @@ ...@@ -20,12 +20,12 @@
![](docs/images/logo/logo-animate1.svg) ![](docs/images/logo/logo-animate1.svg)
- 主页: [https://wa-lang.org](https://wa-lang.org) - 主页: [https://wa-lang.org](https://wa-lang.org)
- 代码仓库 (Gitee): [https://gitee.com/wa-lang/wa](https://gitee.com/wa-lang/wa) - 仓库: [https://gitee.com/wa-lang/wa](https://gitee.com/wa-lang/wa)
- 代码仓库 (Github): [https://github.com/wa-lang/wa](https://github.com/wa-lang/wa)
- Go 参考文档: [https://pkg.go.dev/github.com/wa-lang/wa](https://pkg.go.dev/github.com/wa-lang/wa)
- 开发工具: [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) - 开发工具: [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)
- 开发组: [柴树杉(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) - 开发组: [柴树杉(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)
> 说明: 凹语言的主仓库在 https://gitee.com/wa-lang/wa. 在 Github 同时有一个镜像仓库 https://github.com/wa-lang/wa. 凹语言代码除非特别声明,均以 AGPL-v3 开源协议授权, 具体可以参考 LICENSE 文件.
## Playground 在线预览 ## Playground 在线预览
[https://wa-lang.org/playground](https://wa-lang.org/playground) [https://wa-lang.org/playground](https://wa-lang.org/playground)
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
## 本地安装和测试: ## 本地安装和测试:
1. `go install github.com/wa-lang/wa@latest` 1. `go install wa-lang.org/wa@latest`
2. `wa init -name=_examples/hi` 2. `wa init -name=_examples/hi`
3. `wa run _examples/hi` 3. `wa run _examples/hi`
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
[![Go Report Card](https://goreportcard.com/badge/github.com/wa-lang/wa)](https://goreportcard.com/report/github.com/wa-lang/wa) [![Go Report Card](https://goreportcard.com/badge/github.com/wa-lang/wa)](https://goreportcard.com/report/github.com/wa-lang/wa)
[![Coverage Status](https://coveralls.io/repos/github/wa-lang/wa/badge.svg)](https://coveralls.io/github/wa-lang/wa) [![Coverage Status](https://coveralls.io/repos/github/wa-lang/wa/badge.svg)](https://coveralls.io/github/wa-lang/wa)
[![GitHub release](https://img.shields.io/github/v/tag/wa-lang/wa.svg?label=release)](https://github.com/wa-lang/wa/releases) [![GitHub release](https://img.shields.io/github/v/tag/wa-lang/wa.svg?label=release)](https://github.com/wa-lang/wa/releases)
[![Go Reference](https://pkg.go.dev/badge/github.com/wa-lang/wa.svg)](https://pkg.go.dev/github.com/wa-lang/wa) [![Go Reference](https://pkg.go.dev/badge/wa-lang.org/wa.svg)](https://pkg.go.dev/wa-lang.org/wa)
[![license](https://img.shields.io/github/license/wa-lang/wa.svg)](https://github.com/wa-lang/wa/blob/master/LICENSE) [![license](https://img.shields.io/github/license/wa-lang/wa.svg)](https://github.com/wa-lang/wa/blob/master/LICENSE)
</div> </div>
...@@ -22,12 +22,10 @@ Instead of requiring complex toolchains to set up, you can simply go install it ...@@ -22,12 +22,10 @@ Instead of requiring complex toolchains to set up, you can simply go install it
![](docs/images/logo/logo-animate1.svg) ![](docs/images/logo/logo-animate1.svg)
- Homepage: [https://wa-lang.org](https://wa-lang.org) - 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) - 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)
> Note: Our canonical Git repository is located at https://gitee.com/wa-lang/wa. There is a mirror of the repository at https://github.com/wa-lang/wa. Unless otherwise noted, the Wa source files are distributed under the AGPL-v3 license found in the LICENSE file.
## Playground ## Playground
[https://wa-lang.org/playground](https://wa-lang.org/playground) [https://wa-lang.org/playground](https://wa-lang.org/playground)
...@@ -37,7 +35,7 @@ Instead of requiring complex toolchains to set up, you can simply go install it ...@@ -37,7 +35,7 @@ Instead of requiring complex toolchains to set up, you can simply go install it
## Install and Run: ## Install and Run:
1. `go install github.com/wa-lang/wa@latest` 1. `go install wa-lang.org/wa@latest`
2. `wa init -name=_examples/hi` 2. `wa init -name=_examples/hi`
3. `wa run _examples/hi` 3. `wa run _examples/hi`
......
# 版权 @2022 凹语言 作者。保留所有权利。
default:
go run ../../main.go -target=arduino hello.wat
clean:
-rm *.wasm
;; 版权 @2022 凹语言 作者。保留所有权利。
(module $wa-arduino-hello
(import "arduino" "getPinLED" (func $getPinLED (result i32)))
(import "arduino" "pinMode" (func $pinMode (param $pin i32) (param $mode i32)))
(import "arduino" "digitalWrite" (func $digitalWrite (param $pin i32) (param $value i32)))
(import "arduino" "delay" (func $delay (param $ms i32)))
(memory (;0;) 1)
(export "memory" (memory 0))
(export "_start" (func $main))
(func $main (local $tmp i32)
;; var LED i32 = getPinLED()
;; &LED == 1024
i32.const 1024
call $getPinLED
local.tee $tmp
i32.store
;; pinMode(LED, 1)
local.get $tmp
i32.const 1
call $pinMode
;; for {}
loop $label0 ;; label = @1
;; digitalWrite(LED, 1)
i32.const 1024
i32.load
i32.const 1
call $digitalWrite
;; delay(100)
i32.const 100
call $delay
;; digitalWrite(LED, 0)
i32.const 1024
i32.load
i32.const 0
call $digitalWrite
;; delay(900)
i32.const 900
call $delay
;; continue
br $label0 (;@1;)
end
;; panic("unreachable")
unreachable
)
)
<!-- <!--
// 版权 @2019 凹语言 作者。保留所有权利。 // 版权 @2019 凹语言 作者。保留所有权利。
// https://github.com/wa-lang // https://wa-lang.org
--> -->
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 400" width="400" height="400" fill="none"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 400" width="400" height="400" fill="none">
......
<!-- <!--
// 版权 @2019 凹语言 作者。保留所有权利。 // 版权 @2019 凹语言 作者。保留所有权利。
// https://github.com/wa-lang // https://wa-lang.org
--> -->
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 400" width="400" height="400" fill="none"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 400" width="400" height="400" fill="none">
......
<!-- <!--
// 版权 @2019 凹语言 作者。保留所有权利。 // 版权 @2019 凹语言 作者。保留所有权利。
// https://github.com/wa-lang // https://wa-lang.org
--> -->
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 400" width="400" height="400" fill="none"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 400" width="400" height="400" fill="none">
......
<!-- <!--
// 版权 @2019 凹语言 作者。保留所有权利。 // 版权 @2019 凹语言 作者。保留所有权利。
// https://github.com/wa-lang // https://wa-lang.org
--> -->
<svg xmlns="http://www.w3.org/2000/svg" <svg xmlns="http://www.w3.org/2000/svg"
......
<!-- <!--
// 版权 @2019 凹语言 作者。保留所有权利。 // 版权 @2019 凹语言 作者。保留所有权利。
// https://github.com/wa-lang // https://wa-lang.org
--> -->
<svg xmlns="http://www.w3.org/2000/svg" <svg xmlns="http://www.w3.org/2000/svg"
......
<!-- <!--
// 版权 @2019 凹语言 作者。保留所有权利。 // 版权 @2019 凹语言 作者。保留所有权利。
// https://github.com/wa-lang // https://wa-lang.org
--> -->
<svg xmlns="http://www.w3.org/2000/svg" <svg xmlns="http://www.w3.org/2000/svg"
......
...@@ -8,14 +8,26 @@ import ( ...@@ -8,14 +8,26 @@ import (
"wa-lang.org/wa/api" "wa-lang.org/wa/api"
) )
func main() { func waGenerateWat(code string) string {
window := js.Global().Get("window") wat, err := api.BuildFile(api.DefaultConfig(), "hello.wa", code)
waCode := window.Get("waCode").String() if err != nil {
return err.Error()
}
return string(wat)
}
wat, err := api.BuildFile(api.DefaultConfig(), "hello.wa", waCode) func waFormatCode(code string) string {
newCode, err := api.FormatCode("hello.wa", code)
if err != nil { if err != nil {
window.Set("waWat", err.Error()) return err.Error()
} else {
window.Set("waWat", string(wat))
} }
return newCode
}
func main() {
window := js.Global().Get("window")
waCode := window.Get("__WA_CODE__").String()
window.Set("__WA_WAT__", waGenerateWat(waCode))
window.Set("__WA_FMT_CODE__", waFormatCode(waCode))
} }
...@@ -70,38 +70,7 @@ func main() { ...@@ -70,38 +70,7 @@ func main() {
// 没有参数时对应 run 命令 // 没有参数时对应 run 命令
cliApp.Action = func(c *cli.Context) error { cliApp.Action = func(c *cli.Context) error {
if c.NArg() == 0 { cliRun(c)
cli.ShowAppHelpAndExit(c, 0)
}
app := app.NewApp(build_Options(c))
output, err := app.WASM(c.Args().First())
if err != nil {
fmt.Println(err)
os.Exit(1)
}
outfile := "a.out.wat"
if !c.Bool("debug") {
defer os.Remove(outfile)
}
if err = os.WriteFile(outfile, []byte(output), 0666); err != nil {
fmt.Println(err)
os.Exit(1)
}
stdoutStderr, err := apputil.RunWasm(app.GetConfig(), outfile)
if err != nil {
if len(stdoutStderr) > 0 {
fmt.Println(string(stdoutStderr))
}
fmt.Println(err)
os.Exit(1)
}
if len(stdoutStderr) > 0 {
fmt.Println(string(stdoutStderr))
}
return nil return nil
} }
...@@ -172,40 +141,7 @@ func main() { ...@@ -172,40 +141,7 @@ func main() {
}, },
}, },
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
if c.NArg() == 0 { cliRun(c)
fmt.Fprintf(os.Stderr, "no input file")
os.Exit(1)
}
app := app.NewApp(build_Options(c))
output, err := app.WASM(c.Args().First())
if err != nil {
fmt.Println(err)
os.Exit(1)
}
outfile := "a.out.wat"
if !c.Bool("debug") {
defer os.Remove(outfile)
}
if err = os.WriteFile(outfile, []byte(output), 0666); err != nil {
fmt.Println(err)
os.Exit(1)
}
stdoutStderr, err := apputil.RunWasm(app.GetConfig(), outfile)
if err != nil {
if len(stdoutStderr) > 0 {
fmt.Println(string(stdoutStderr))
}
fmt.Println(err)
os.Exit(1)
}
if len(stdoutStderr) > 0 {
fmt.Println(string(stdoutStderr))
}
return nil return nil
}, },
}, },
...@@ -489,3 +425,55 @@ func build_Options(c *cli.Context, isLLVMBackend ...bool) *app.Option { ...@@ -489,3 +425,55 @@ func build_Options(c *cli.Context, isLLVMBackend ...bool) *app.Option {
} }
return opt return opt
} }
func cliRun(c *cli.Context) {
if c.NArg() == 0 {
cli.ShowAppHelpAndExit(c, 0)
}
var app = app.NewApp(build_Options(c))
var infile = c.Args().First()
var outfile string
var output []byte
var err error
if !c.Bool("debug") {
defer os.Remove(outfile)
}
switch {
case strings.HasSuffix(infile, ".wat"):
outfile = infile
output, err = os.ReadFile(infile)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
case strings.HasSuffix(infile, ".wasm"):
outfile = infile
output, err = os.ReadFile(infile)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
default:
outfile = "a.out.wat"
output, err = app.WASM(infile)
if err = os.WriteFile(outfile, []byte(output), 0666); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
stdoutStderr, err := apputil.RunWasm(app.GetConfig(), outfile)
if err != nil {
if len(stdoutStderr) > 0 {
fmt.Println(string(stdoutStderr))
}
fmt.Println(err)
os.Exit(1)
}
if len(stdoutStderr) > 0 {
fmt.Println(string(stdoutStderr))
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册