Releases: goplus/gop
v0.7.4
v0.7.3
Design of Go+ lambda functions
See #321. Comments are welcome.
Commands
gop repl (ie. igop)
Run Go+ in REPL/Console mode. Thanks contribution of jiangz222 ([email protected]).
Defer
Currently only available in bytecode backend. Thanks contribution of go-wyvern ([email protected]).
Bugs fix
- Variable scope bug: variable redefinition.
- Array literal is deduced as a pointer.
- Fix inconsistent command line output for different help commands.
- cmd/qexp: fix export mod pkg with version (#501).
Thanks contribution of JessonChan ([email protected]), visualfc ([email protected]), si9ma.
v0.7.2
Git merge mode
We change merge mode
to Squash and merge
. It will combine all commits from the head branch into a single commit in the base branch.
Auto property
Let's see an example written in Go+:
import "github.com/goplus/gop/ast/goptest"
doc := goptest.New(`... Go+ code ...`)!
println(doc.Any().FuncDecl().Name())
In many languages, there is a concept named property
who has get
and set
methods.
Suppose we have get property
, the above example will be:
import "github.com/goplus/gop/ast/goptest"
doc := goptest.New(`... Go+ code ...`)!
println(doc.any.funcDecl.name)
In Go+, we introduce a concept named auto property
. It is a get property
, but is implemented automatically. If we have a method named Bar()
, then we will have a get property
named bar
at the same time.
Go+ related packages
- github.com/goplus/gop/ast/gopq
- github.com/goplus/gop/ast/goptest
See tutorial/22-Auto-Property.
Flow control
- break/continue/return in
for range
statements.
Thanks contribution of JessonChan ([email protected]).
Misc
- Simplify test cases of cl/stmt_test.go.
- Command
gop export
bug fixed. - Getting value from a map panics if the key not exists.
- Export
fmt
package. - Update dependency: github.com/qiniu/x v1.11.5
Thanks contribution of JessonChan ([email protected]), visualfc ([email protected]).
v0.7.1
Organization & Repo
Move github.com/qiniu/goplus to github.com/goplus/gop.
Move github.com/qiniu/goplus-www to github.com/goplus/www.
Move github.com/qiniu/goplus-play to github.com/goplusjs/play.
Thanks contribution of astaxie ([email protected]), visualfc ([email protected]).
Commands
gop run # Run a Go+ program
gop go [-test] # Convert Go+ packages into Go packages. If -test specified, it tests related packages.
gop fmt # Format Go+ packages
gop export # Export Go packages for Go+ programs
gop run (ie. qrun)
Run <gopSrcDir|gopSrcFile> as a Go+ script.
Usage: gop run [-asm -quiet -debug -prof] <gopSrcDir|gopSrcFile>
-asm
generates `asm` code of Go+ bytecode backend
-debug
print debug information
-prof
do profile and generate profile report
-quiet
don't generate any compiling stage log
Here are some examples:
gop run <gopSrcDir|gopSrcFile> # gop run <gopSrcDir | gopSrcFile>
gop run -asm <gopSrcDir|gopSrcFile> # generates `asm` code of Go+ bytecode backend
gop run -quiet <gopSrcDir|gopSrcFile> # don't generate any compiling stage log
gop run -debug <gopSrcDir|gopSrcFile> # print debug information
gop run -prof <gopSrcDir|gopSrcFile> # do profile and generate profile report
gop fmt (ie. qfmt)
Format Go+ packages.
Usage: gop fmt [-w] [path ...]
-w write result to (source) file instead of stdout
gop export (ie. qexp)
Generate a Go+ package that wraps a Go package automatically.
Usage: gop export [-outdir <outRootDir>] <goPkgPath>
-outdir string
optional set export lib path, default is $GoPlusRoot/lib path.
gop go (ie. qgo)
Convert all Go+ packages under into Go packages, recursively.
Usage: gop go [-test] <gopSrcDir>
-test
test Go+ package
Here are some examples:
gop go <gopSrcDir> # gop go <gopSrcDir>
gop go -test <gopSrcDir>
Note:
gop go -test <gopSrcDir>
converts Go+ packages into Go packages, and for every package, it callgo run <gopPkgDir>/gop_autogen.go
andgop run -quiet <gopPkgDir>
to compare their outputs. If their outputs aren't equal, the test case fails.
Simplify test cases
import (
"math/big"
"testing"
"github.com/goplus/gop/cl/cltest"
)
func TestMake(t *testing.T) {
cltest.Expect(t, `
a := make([]int, 0, 4)
a = append(a, [1, 2, 3]...)
println(a)
`,
"[1 2 3]\n",
)
}
func TestPanic(t *testing.T) {
cltest.Expect(t,
`panic("Helo")`, "", "Helo",
)
}
func TestRational(t *testing.T) {
cltest.Call(t, `
a := 3/4r
x := a + 5/7r
x
`).Equal(big.NewRat(41, 28))
}
See https://github.com/qiniu/x/wiki/How-to-write-a-TestCase.
Go+ related packages
Import Go packages
- variables read/write
Thanks contribution of visualfc ([email protected]).
Builtin
- copy
Thanks contribution of JessonChan ([email protected]).
IDE Plugins
Thanks contribution of go-wyvern ([email protected]).
Go+ Badges
Contributing
Where can you start?
Misc
- Simplify test cases of cl/expr_test.go.
- Deduplicate code in package token/scanner.
Thanks contribution of wangkuiyi ([email protected]), tsingbx.
v0.7.0
v0.6.60
Commands
qexp
Usage: qexp [-outdir <outRootDir>] <goPkgPath>
-outdir string
optional set export lib path, default is $GoPlusRoot/lib path.
- Add supporting
-outdir <outRootDir>
flag. - Export constants and variables.
Thanks contribution of visualfc ([email protected]).
qgo
- Format go code
gop_autogen.go
after code generation. - Skip to build _xxx directories.
Thanks contribution of visualfc ([email protected]), tsingbx.
qrun
- Skip to build _xxx.gop files.
Thanks contribution of tsingbx.
qfmt
- Support qfmt from stdin.
Thanks contribution of go-wyvern.
TypeCast
b := []byte("Hello")
println(b)
Flow control
- goto label
- break [label]
- continue [label]
Thanks contribution of JessonChan ([email protected]).
Builtin
delete(mapData, key)
Thanks contribution of JessonChan ([email protected]).
Miscs
- ast.File: Rename HasUnnamed into NoEntrypoint.
- Increase code coverage to 88%+.
Thanks contribution of wangkuiyi ([email protected]), xushiwei ([email protected]).
v0.6.50
Commands
qrun
Enhancement: run <gopSrcFile>
as a Go+ script. See qrun for more detail.
Thanks contribution of jiangz222 ([email protected]).
qfmt
Format Go+ packages, similar to go fmt
. See qfmt for more detail.
Usage: qfmt [flags] [path ...]
-w write result to (source) file instead of stdout
Thanks contribution of visualfc ([email protected]), damonchen.
qexp
Generate a Go+ package that wraps a Go package automatically. See qexp for more detail.
Usage: qexp <goPkgPath>
Thanks contribution of xushiwei ([email protected]), visualfc ([email protected]).
Unix shebang
You can use Go+ programs as shell scripts now. For example:
#!/usr/bin/env qrun
println("Hello, Go+")
println(1r << 129)
println(1/3r + 2/7r*2)
arr := [1, 3, 5, 7, 11, 13, 17, 19]
println(arr)
println([x*x for x <- arr, x > 3])
m := {"Hi": 1, "Go+": 2}
println(m)
println({v: k for k, v <- m})
println([k for k, _ <- m])
println([v for v <- m])
Go tutorial/20-Unix-Shebang/shebang to get the source code.
Thanks contribution of jiangz222 ([email protected]).
Playground
All playgrounds support Go+ code formatting now.
- Playground based on GopherJS: https://qiniu.github.io/goplus-play/
- Playground based on Docker: https://play.goplus.org/
Thanks contribution of visualfc ([email protected]), qiukeren ([email protected]).
For loop
Thanks contribution of JessonChan ([email protected])
sum := 0
x := 0
for _, x = range [1, 3, 5, 7, 11, 13, 17] {
if x > 3 {
sum += x
}
}
println("sum(5,7,11,13,17):", sum)
Flow control
- fallthrough
Thanks contribution of JessonChan ([email protected])
Miscs
- Enrich pre-commit hooks and call them from Travis CI.
- Call gofmt at git commit time.
Thanks contribution of wangkuiyi.
v0.6.40
Playground
Playground based on Docker (See https://github.com/qiniu/goplus-www/tree/master/playground):
Playground based on GopherJS (See https://github.com/qiniu/goplus-play):
Thanks contribution of qiukeren ([email protected]), visualfc ([email protected]).
For loop
Thanks contribution of JessonChan ([email protected])
fns := make([]func() int, 3)
sum := 0
for _, x := range [1, 3, 5, 7, 11, 13, 17] {
if x > 3 {
sum += x
}
}
println("sum(5,7,11,13,17):", sum)
sum = 0
for i, x := range [3, 15, 777] {
v := x
fns[i] = func() int {
return v
}
}
println("values:", fns[0](), fns[1](), fns[2]())
sum = 0
arr := [1, 3, 5, 7, 11, 13, 17]
i := 10
for i = 0; i < len(arr); i++ {
if arr[i] > 3 {
sum += arr[i]
}
}
println("sum(5,7,11,13,17):", sum)
Inc/DecStmt
Thanks contribution of JessonChan ([email protected])
a, b := 2, 3
a++
b--
println(a, b)
v0.6.30
Rational number: bigint, bigrat, bigfloat
We introduce rational number as native Go+ types. We use -r suffix as a rational constant. For example, (1r << 200) means a big int whose value is equal to 2200. And 4/5r means the rational constant 4/5.
a := 1r << 65 // bigint, large than int64
b := 4/5r // bigrat
c := b - 1/3r + 3 * 1/2r
println(a, b, c)
Import go packages
Now we support importing constants/variables of Go packages.
Thanks contribution of visualfc ([email protected]).
Contributing
The Go+ project welcomes all contributors. We appreciate your help!
Here are list of Go+ Contributors. We award an email account ([email protected]) for every contributor. And we suggest you commit code by using this email account:
git config --global user.email [email protected]
What does a contributor of Go+
means? He must meet one of the following conditions:
- At least one pull request of a full feature implemention.
- At least three pull requests of feature enhancements.
- At least ten pull requests of any kind issues.
v0.6.20
Commands
qrun [-debug] [-prof] <qlangSrcDir>
- qrun -debug
<gopSrcDir>
: print debug information - qrun -prof
<gopSrcDir>
: do profile and generate profile report
Error handling
We reinvent error handling specification in Go+. We call them ErrWrap expressions
:
expr! // panic if err
expr? // return if err
expr?:defval // use defval if err
How to use them? Here is an example:
import (
"strconv"
)
func add(x, y string) (int, error) {
return strconv.Atoi(x)? + strconv.Atoi(y)?, nil
}
func addSafe(x, y string) int {
return strconv.Atoi(x)?:0 + strconv.Atoi(y)?:0
}
println(`add("100", "23"):`, add("100", "23")!)
sum, err := add("10", "abc")
println(`add("10", "abc"):`, sum, err)
println(`addSafe("10", "abc"):`, addSafe("10", "abc"))
The output of this example is:
add("100", "23"): 123
add("10", "abc"): 0 strconv.Atoi: parsing "abc": invalid syntax
===> errors stack:
main.add("10", "abc")
/Users/xsw/goplus/tutorial/15-ErrWrap/err_wrap.gop:6 strconv.Atoi(y)?
addSafe("10", "abc"): 10
Compared to corresponding Go code, It is clear and more readable.
And the most interesting thing is, the return error contains the full error stack. When we got an error, it is very easy to position what the root cause is.
How these ErrWrap expressions
work? See Error Handling for more information.