添加 _examples 到 ci 测试

This commit is contained in:
chai2010 2023-05-27 11:04:47 +08:00
parent 7cabaa4ade
commit 23cbd05edf
36 changed files with 157 additions and 70 deletions

View File

@ -23,4 +23,8 @@ arduino-build:
ci-test-all:
go test ./...
go run main.go hello.wa
make -C ./_examples ci-test-all
clean:

27
_examples/Makefile Normal file
View File

@ -0,0 +1,27 @@
# 版权 @2023 凹语言 作者。保留所有权利。
default:
ci-test-all:
@echo "== _examples test begin =="
# loop forever
# cd ./arduino && make
# cd ./arduino-wat && make
cd ./brainfuck && make
cd ./expr && make
cd ./hello && make
cd ./pkg && make
cd ./prime && make
cd ./reftoptr && make
# snake
go run ../main.go interface_named.wa
go run ../main.go struct.wa
@echo "== _examples ok =="
clean:

View File

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

View File

@ -0,0 +1,6 @@
# 版权 @2022 凹语言 作者。保留所有权利。
default:
go run ../../main.go
clean:

View File

@ -68,7 +68,7 @@ type exprLexer struct {
pos :int
}
func exprLexer.Lex(yylval *exprSymType) => int {
func exprLexer.Lex(yylval: *exprSymType) => int {
if this.pos >= len(this.tokens) {
return eof
}
@ -79,7 +79,7 @@ func exprLexer.Lex(yylval *exprSymType) => int {
return tok.Kind
}
func exprLexer.Error(s string) {
func exprLexer.Error(s: string) {
println("ERROR:", s)
}

View File

@ -60,7 +60,7 @@ func exprLexer.Error(s: string) {
println("ERROR:", s)
}
func main() {
func main {
print("1+2*(3+4)-10 = ")
exprParse(&exprLexer{
tokens: []exprToken{
@ -164,11 +164,11 @@ type exprParser struct {
char :int
}
func exprParser.Lookahead() => int {
func exprParser.Lookahead => int {
return this.char
}
func exprNewParser() => *exprParser {
func exprNewParser => *exprParser {
return &exprParser{}
}

View File

@ -4,7 +4,7 @@ import "fmt"
import "3rdparty/pkg"
import "myapp/mymath"
func main() {
func main {
fmt.Println(40+2)
pkg.Println(100+2)
println(mymath.I8Max)
@ -21,7 +21,7 @@ func sum(n: int) => int {
return v
}
func heart() {
func 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

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

View File

@ -1,4 +1,4 @@
# 版权 @2021 凹语言 作者。保留所有权利。
// 版权 @2021 凹语言 作者。保留所有权利。
type S1 struct {
a: i32
@ -39,7 +39,7 @@ func main() {
doConcreteType(i1)
i1.f()
var ni interface{} = &v1 //具体类型到空接口
var ni: interface{} = &v1 //具体类型到空接口
i1 = ni.(I1) //接口动态互转
i1.f()
@ -47,7 +47,7 @@ func main() {
i1 = ni.(I1) //接口动态互转
i1.f()
var ival i32 = 777
var ival: i32 = 777
ni = ival
doConcreteType(ni)
@ -58,12 +58,12 @@ func main() {
//i2 := ni.(I2) //接口互转由于v2未实现I2这会触发异常
//i2.f2()
var anoi interface{ f() } = &v1 //具体类型到匿名接口
var anoi: interface{ f() } = &v1 //具体类型到匿名接口
doConcreteType(anoi) //匿名接口向具名接口转换
anoi.f()
}
func doConcreteType(i interface{}) {
func doConcreteType(i: interface{}) {
//接口到具体类型断言
switch c := i.(type){
case *S1:

10
_examples/pkg/Makefile Normal file
View File

@ -0,0 +1,10 @@
# 版权 @2023 凹语言 作者。保留所有权利。
default:
go run ../../main.go run .
test:
go run ../../main.go test .
clean:
-rm a.out*

View File

@ -9,14 +9,14 @@ type ST struct {
B: i32
}
var G ST
var G: ST
func Do() {
func Do {
G.A = "13"
G.B = 1024
}
func main() {
func main {
mypkg.Do(42)
println(mypkg.G.A)
println(mypkg.G.B)

View File

@ -5,9 +5,9 @@ type ST struct {
B: string
}
var G ST
var G: ST
func Do(x i32) {
func Do(x: i32) {
G.A = x
G.B = "Hellow wa"
}

10
_examples/prime/Makefile Normal file
View File

@ -0,0 +1,10 @@
# 版权 @2023 凹语言 作者。保留所有权利。
default:
go run ../../main.go run .
test:
go run ../../main.go test .
clean:
-rm a.out*

View File

@ -1,3 +1,5 @@
// 版权 @2022 凹语言™ 作者。保留所有权利。
func PrintInt(x: int) {
print(x, " ")
}

View File

@ -3,7 +3,7 @@
import "examples/prime/benpkg"
import "joypkg"
func main() {
func main {
for n := 2; n <= 100; n = n + 1 {
if isPrime(n) {
benpkg.PrintInt(n)

View File

@ -1,3 +1,5 @@
// 版权 @2022 凹语言™ 作者。保留所有权利。
func PrintIntComma(x: int) {
print(x, ",")
}

View File

@ -0,0 +1,10 @@
# 版权 @2023 凹语言 作者。保留所有权利。
default:
go run ../../main.go run .
test:
go run ../../main.go test .
clean:
-rm a.out*

View File

@ -1,6 +1,6 @@
# 版权 @2021 凹语言 作者。保留所有权利。
// 版权 @2021 凹语言 作者。保留所有权利。
var Info struct{
var Info: struct{
name: string
age: i32
}

View File

@ -47,6 +47,9 @@ func ExampleRunCode_args() {
args := []string{"aa", "bb"}
output, err := api.RunCode(api.DefaultConfig(), "hello.wa", code, args...)
if err != nil {
if len(output) != 0 {
log.Println(string(output))
}
log.Fatal(err)
}

View File

@ -184,13 +184,15 @@ func Main() {
Action: func(c *cli.Context) error {
outfile := c.String("output")
if c.NArg() == 0 {
fmt.Fprintf(os.Stderr, "no input file")
os.Exit(1)
var input string
if c.NArg() > 0 {
input = c.Args().First()
} else {
input, _ = os.Getwd()
}
ctx := app.NewApp(build_Options(c))
output, err := ctx.WASM(c.Args().First())
output, err := ctx.WASM(input)
if err != nil {
fmt.Println(err)
os.Exit(1)
@ -513,12 +515,14 @@ func build_Options(c *cli.Context, waBackend ...string) *app.Option {
}
func cliRun(c *cli.Context) {
if c.NArg() < 1 {
cli.ShowAppHelpAndExit(c, 0)
var infile string
if c.NArg() > 0 {
infile = c.Args().First()
} else {
infile, _ = os.Getwd()
}
var app = app.NewApp(build_Options(c))
var infile = c.Args().First()
var outfile string
var output []byte
var err error
@ -555,7 +559,11 @@ func cliRun(c *cli.Context) {
}
}
appArgs := c.Args().Slice()[1:]
var appArgs []string
if c.NArg() > 1 {
appArgs = c.Args().Slice()[1:]
}
stdoutStderr, err := apputil.RunWasm(app.GetConfig(), outfile, appArgs...)
if err != nil {
if len(stdoutStderr) > 0 {

View File

@ -18,6 +18,7 @@ file such as NOTICE, LICENCE or COPYING.
Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
Portions Copyright © 2009 The Go Authors. All rights reserved.
Portions Copyright © 2018 The Wa Authors. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@ -1157,7 +1158,7 @@ func emitcode(code []rune, lineno int) {
fmt.Fprintln(ftable, "")
if !fmtImported {
fmt.Fprintln(ftable, `import __yystrconv__ "strconv"`)
fmt.Fprintln(ftable, `import "strconv" => __yystrconv__`)
if !lflag {
fmt.Fprintf(ftable, "//line %v:%v\n\t\t", infile, lineno+len(lines(code)))
}
@ -3266,22 +3267,22 @@ var (
)
type $$Parser struct {
lval $$SymType
stack [$$InitialStackSize]$$SymType
char int
lval :$$SymType
stack :[$$InitialStackSize]$$SymType
char :int
}
func $$Parser.Lookahead() int {
func $$Parser.Lookahead => int {
return this.char
}
func $$NewParser() *$$Parser {
func $$NewParser => *$$Parser {
return &$$Parser{}
}
const $$Flag = -1000
func $$Tokname(c int) string {
func $$Tokname(c: int) => string {
if c >= 1 && c-1 < len($$Toknames) {
if $$Toknames[c-1] != "" {
return $$Toknames[c-1]
@ -3290,7 +3291,7 @@ func $$Tokname(c int) string {
return "tok-" + __yystrconv__.Itoa(c)
}
func $$Statname(s int) string {
func $$Statname(s: int) => string {
if s >= 0 && s < len($$Statenames) {
if $$Statenames[s] != "" {
return $$Statenames[s]
@ -3299,7 +3300,7 @@ func $$Statname(s int) string {
return "state-" + __yystrconv__.Itoa(s)
}
func $$ErrorMessage(state, lookAhead int) string {
func $$ErrorMessage(state, lookAhead: int) => string {
const TOKSTART = 4
if !$$ErrorVerbose {
@ -3363,7 +3364,7 @@ func $$ErrorMessage(state, lookAhead int) string {
return res
}
func $$lex1(lex *$$Lexer, lval *$$SymType) (char, token int) {
func $$lex1(lex: *$$Lexer, lval: *$$SymType) => (char, token: int) {
token = 0
char = lex.Lex(lval)
@ -3402,14 +3403,14 @@ out:
return char, token
}
func $$Parse($$lex *$$Lexer) int {
func $$Parse($$lex: *$$Lexer) => int {
return $$NewParser().Parse($$lex)
}
func $$Parser.Parse($$lex *$$Lexer) int {
var $$n int
var $$VAL $$SymType
var $$Dollar []$$SymType
func $$Parser.Parse($$lex: *$$Lexer) => int {
var $$n: int
var $$VAL: $$SymType
var $$Dollar: []$$SymType
_ = $$Dollar // silence set and not used
$$S := this.stack[:]

View File

@ -2306,7 +2306,9 @@ func (p *parser) parseValueSpec(doc *ast.CommentGroup, keyword token.Token, iota
colonPos = p.pos
p.next()
} else {
p.expect(token.COLON)
if p.tok != token.ASSIGN {
p.expect(token.COLON)
}
}
}
typ := p.tryType()

View File

@ -1,6 +1,6 @@
// 版权 @{{.Year}} {{.Name}} 作者。保留所有权利。
func main() {
func main {
println("你好,凹语言!")
println(sum(100))
heart()
@ -14,7 +14,7 @@ func sum(n: int) => int {
return v
}
func heart() {
func 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

@ -1,7 +1,7 @@
// 版权 @{{.Year}} {{.Name}} 作者。保留所有权利。
// 打印素数
func PrintPrime(max int) {
func PrintPrime(max: int) {
for n := 2; n <= max; n = n + 1 {
isPrime := 1
for i := 2; i*i <= n; i = i + 1 {

View File

@ -1,6 +1,6 @@
// 版权 @{{.Year}} {{.Name}} 作者。保留所有权利。
// 打印整数
func Println(x int) {
func Println(x: int) {
println(x)
}

View File

@ -1,5 +1,5 @@
// 版权 @{{.Year}} {{.Name}} 作者。保留所有权利。
func Println(x int) {
func Println(x: int) {
println(x)
}

View File

@ -2,6 +2,6 @@
#wa:build !fmt_tag
func Println(x int) {
func Println(x: int) {
println(x)
}

View File

@ -2,6 +2,6 @@
#wa:build fmt_tag
func Println(x int) {
func Println(x: int) {
println("fmt_tag:", x)
}

View File

@ -15,7 +15,7 @@ func Sin(x: f64) => f64 {
// Special cases are:
// Cos(±Inf) = NaN
// Cos(NaN) = NaN
func Cos(x float64) float64 {
func Cos(x: float64) => float64 {
return cos(x)
}
@ -40,14 +40,14 @@ func sin(x: f64) => f64 {
sign = true
}
var j uint64
var y, z float64
var j: u64
var y, z: f64
//if x >= reduceThreshold {
// j, z = trigReduce(x)
//} else
{
j = uint64(x * (4 / Pi)) // integer part of x/(Pi/4), as integer for tests on the phase angle
y = float64(j) // integer part of x/(Pi/4), as float
j = u64(x * (4 / Pi)) // integer part of x/(Pi/4), as integer for tests on the phase angle
y = f64(j) // integer part of x/(Pi/4), as float
// map zeros to origin
if j&1 == 1 {
@ -95,7 +95,7 @@ var _cos = [...]f64{
}
func cos(x float64) float64 {
func cos(x: f64) => f64 {
const (
PI4A = 7.85398125648498535156e-1 // 0x3fe921fb40000000, Pi/4 split into three parts
PI4B = 3.77489470793079817668e-8 // 0x3e64442d00000000,
@ -111,8 +111,8 @@ func cos(x float64) float64 {
sign := false
x = Abs(x)
var j uint64
var y, z float64
var j: u64
var y, z: f64
//if x >= reduceThreshold {
// j, z = trigReduce(x)
//} else

View File

@ -1,6 +1,6 @@
// 版权 @2023 凹语言 作者。保留所有权利。
var Args []string
var Args: []string
#wa:linkname runtime.os_get_args
func os_get_args() => []string
@ -15,6 +15,6 @@ func init {
Args = os_get_args()
}
func Environ() []string {
func Environ() => []string {
return os_get_environs()
}

View File

@ -24,7 +24,6 @@ func environGet(result_environv: i32, result_environv_buf: i32) => (errno: i32)
return
}
#wa:linkname $runtime.fdWrite
func fdWrite(fd: i32, io: i32, iovs_len: i32, nwritten: i32) => (written: i32) {
return

View File

@ -72,12 +72,12 @@ type _itab struct {
} //followed by [itype.methodCound]fnID, fnID=>id for call_indirect
#wa:linkname $wa.runtime.getTypePtr
func getTypePtr(hash i32) uintptr {
func getTypePtr(hash: i32) uintptr {
return 0
}
#wa:linkname $wa.runtime.getItab
func getItab(dhash i32, ihash i32, commanok i32) u32 {
func getItab(dhash: i32, ihash: i32, commanok: i32) u32 {
itab := _itabsPtr + ((dhash - 1) * _interfaceCount - ihash - 1) * 4
return getU32(u32(itab))
}
@ -86,10 +86,10 @@ func getItab(dhash i32, ihash i32, commanok i32) u32 {
func getU32(p: u32) => u32
#wa:linkname $wa.runtime._itabsPtr
var _itabsPtr i32
var _itabsPtr: i32
#wa:linkname $wa.runtime._interfaceCount
var _interfaceCount i32
var _interfaceCount: i32
#wa:linkname $wa.runtime._concretTypeCount
var _concretTypeCount i32
var _concretTypeCount: i32

View File

@ -43,7 +43,7 @@ func FdPrestatDirName(fd: i32, path: i32, path_len: i32) => (errno: i32)
func FdPwrite(fd: i32, iovs: i32, iovs_len: i32, offset: i64, result_nwritten: i32) => (errno: i32)
#wa:import wasi_snapshot_preview1 fd_read
func FdRead(fdL i32, iovs: i32, iovs_len: i32, result_size: i32) => (errno: i32)
func FdRead(fd: i32, iovs: i32, iovs_len: i32, result_size: i32) => (errno: i32)
#wa:import wasi_snapshot_preview1 fd_readdir
func FdReaddir(fd: i32, buf: i32, buf_len: i32, cookie: i64, result_bufused: i32) => (errno: i32)
@ -64,7 +64,7 @@ func FdTell(fd: i32, result_offset: i32) => (errno: i32)
func FdWrite(fd: i32, io: i32, iovs_len: i32, nwritten: i32) => (errno: i32)
#wa:import wasi_snapshot_preview1 path_create_directory
func PathCreateDirectory(fd i32, path: i32, path_len: i32) => (errno: i32)
func PathCreateDirectory(fd: i32, path: i32, path_len: i32) => (errno: i32)
#wa:import wasi_snapshot_preview1 path_filestat_get
func PathFilestatGet(fd: i32, flags: i32, path: i32, path_len: i32, result_buf: i32) => (errno: i32)