Skip to content

Releases: goplus/gop

Release v0.7.4

02 Aug 10:54
e0242e1
Compare
Choose a tag to compare
  • This is a temporary release for iGo+

Release v0.7.3

26 Jul 14:28
7c49512
Compare
Choose a tag to compare

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 (jiangzhi@goplus.org).

Defer

Currently only available in bytecode backend. Thanks contribution of go-wyvern (wuxinyi@goplus.org).

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 (chendongpo@goplus.org), visualfc (visualfc@goplus.org), si9ma.

Release v0.7.2

20 Jul 16:25
693b169
Compare
Choose a tag to compare

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 (chendongpo@goplus.org).

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 (chendongpo@goplus.org), visualfc (visualfc@goplus.org).

Release v0.7.1

12 Jul 16:07
c80ac57
Compare
Choose a tag to compare

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 (astaxie@goplus.org), visualfc (visualfc@goplus.org).

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 call go run <gopPkgDir>/gop_autogen.go and gop 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 (visualfc@goplus.org).

Builtin

  • copy

Thanks contribution of JessonChan (chendongpo@goplus.org).

IDE Plugins

Thanks contribution of go-wyvern (wuxinyi@goplus.org).

Go+ Badges

Hacker News Playground VSCode

Contributing

Where can you start?

  • Issues
  • Issues
  • Issues
  • TODOs

Misc

  • Simplify test cases of cl/expr_test.go.
  • Deduplicate code in package token/scanner.

Thanks contribution of wangkuiyi (wangyi@goplus.org), tsingbx.

Relese v0.7.0

07 Jul 19:01
6c75eee
Compare
Choose a tag to compare
  • github.com/qiniu/goplus => github.com/goplus/gop

Release v0.6.60

05 Jul 23:24
1055cd3
Compare
Choose a tag to compare

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 (visualfc@goplus.org).

qgo

  • Format go code gop_autogen.go after code generation.
  • Skip to build _xxx directories.

Thanks contribution of visualfc (visualfc@goplus.org), 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 (chendongpo@goplus.org).

Builtin

delete(mapData, key)

Thanks contribution of JessonChan (chendongpo@goplus.org).

Miscs

  • ast.File: Rename HasUnnamed into NoEntrypoint.
  • Increase code coverage to 88%+.

Thanks contribution of wangkuiyi (wangyi@goplus.org), xushiwei (x@goplus.org).

Release v0.6.50

28 Jun 16:03
251e782
Compare
Choose a tag to compare

Commands

qrun

Enhancement: run <gopSrcFile> as a Go+ script. See qrun for more detail.

Thanks contribution of jiangz222 (jiangzhi@goplus.org).

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 (visualfc@goplus.org), damonchen.

qexp

Generate a Go+ package that wraps a Go package automatically. See qexp for more detail.

Usage: qexp <goPkgPath>

Thanks contribution of xushiwei (x@goplus.org), visualfc (visualfc@goplus.org).

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 (jiangzhi@goplus.org).

Playground

All playgrounds support Go+ code formatting now.

Thanks contribution of visualfc (visualfc@goplus.org), qiukeren (qiukeren@goplus.org).

For loop

Thanks contribution of JessonChan (chendongpo@goplus.org)

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 (chendongpo@goplus.org)

Miscs

  • Enrich pre-commit hooks and call them from Travis CI.
  • Call gofmt at git commit time.

Thanks contribution of wangkuiyi.

Release v0.6.40

22 Jun 00:06
cb62569
Compare
Choose a tag to compare

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 (qiukeren@goplus.org), visualfc (visualfc@goplus.org).

For loop

Thanks contribution of JessonChan (chendongpo@goplus.org)

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 (chendongpo@goplus.org)

a, b := 2, 3
a++
b--
println(a, b)

Release v0.6.30

14 Jun 15:17
e58baf8
Compare
Choose a tag to compare

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 (visualfc@goplus.org).

Contributing

The Go+ project welcomes all contributors. We appreciate your help!

Here are list of Go+ Contributors. We award an email account (XXX@goplus.org) for every contributor. And we suggest you commit code by using this email account:

git config --global user.email XXX@goplus.org

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.

Release v0.6.20

07 Jun 13:59
ee2702d
Compare
Choose a tag to compare

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.

History Version (qlang)