Skip to content

Commit

Permalink
Merge pull request #1733 from goplus/main
Browse files Browse the repository at this point in the history
v1.2.1
  • Loading branch information
xushiwei authored Feb 12, 2024
2 parents d343372 + b90d48d commit 6a18888
Show file tree
Hide file tree
Showing 49 changed files with 918 additions and 280 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ jobs:
run: go test -v -coverprofile="coverage.txt" -covermode=atomic ./...

- name: Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
10 changes: 10 additions & 0 deletions .github/workflows/release-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ jobs:
echo "TAG: $tag"
exit 1
fi
- name: Check pre-release
run: |
version=$(cat VERSION)
# check stable version format x.x.x
if ! [[ $version =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "This is a pre-release"
echo "IS_PRERELEASE=true" >> $GITHUB_ENV
fi
- name: Set up Go
uses: actions/setup-go@v5
Expand All @@ -53,6 +62,7 @@ jobs:
WINGET_PKGS_PRIVATE_KEY: ${{ secrets.WINGET_PKGS_PRIVATE_KEY }}

- name: Upload deb/rpm to Fury.io
if: env.IS_PRERELEASE != 'true'
run: |
for file in dist/*.{deb,rpm}
do
Expand Down
4 changes: 2 additions & 2 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ winget:
- For STEM education: studying an engineering language that can be used for work in the future.
- For data science: communicating with engineers in the same language.
license: Apache-2.0
skip_upload: false
skip_upload: auto
release_notes: "{{.Changelog}}"
release_notes_url: "https://github.com/{{ .Env.GITHUB_REPOSITORY_OWNER }}/gop/releases/tag/v{{.Version}}"
dependencies:
Expand All @@ -109,7 +109,7 @@ winget:
private_key: "{{ .Env.WINGET_PKGS_PRIVATE_KEY }}"
pull_request:
enabled: true
draft: false
draft: true
base:
owner: microsoft
name: winget-pkgs
Expand Down
54 changes: 53 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,59 @@ Don't define a language for specific domain.
Abstract domain knowledge for it.
```

Go+ introduces `classfile` to abstract domain knowledge. See [Go+ Classfiles](doc/classfile.md).
Go+ introduces `classfile` to abstract domain knowledge.

Sound a bit abstract? Let's take web programming as an example. First let us initialize a hello project:

```sh
gop mod init hello
```

Then we have it reference a classfile called `yap` as the HTTP Web Framework:

```sh
gop get github.com/goplus/yap@latest
```

We can use it to implement a static file server:

```coffee
static "/foo", FS("public")
static "/" # Equivalent to static "/", FS("static")

run ":8080"
```

We can also add the ability to handle dynamic GET/POST requests:

```coffee
static "/foo", FS("public")
static "/" # Equivalent to static "/", FS("static")

get "/p/:id", ctx => {
ctx.json {
"id": ctx.param("id"),
}
}

run ":8080"
```

Save this code to `hello_yap.gox` file and execute:

```sh
mkdir -p yap/static yap/public # Static resources can be placed in these directories
gop mod tidy
gop run .
```

A simplest web program is running now. At this time, if you visit http://localhost:8080/p/123, you will get:

```
{"id":"123"}
```

Why is `yap` so easy to use? How does it do it? Click here to learn more about the [Go+ Classfiles](doc/classfile.md) mechanism and [YAP HTTP Web Framework](https://github.com/goplus/yap).


## Key Features of Go+
Expand Down
2 changes: 1 addition & 1 deletion ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ type (
Body *BlockStmt // CommClauses only
}

// A ForStmt represents a for statement.
// A ForStmt represents a `for init; cond; post { ... }` statement.
ForStmt struct {
For token.Pos // position of "for" keyword
Init Stmt // initialization statement; or nil
Expand Down
2 changes: 1 addition & 1 deletion ast/ast_gop.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (*LambdaExpr2) exprNode() {}

// -----------------------------------------------------------------------------

// ForPhrase represents `for k, v <- container, cond` phrase.
// ForPhrase represents `for k, v <- container if init; cond` phrase.
type ForPhrase struct {
For token.Pos // position of "for" keyword
Key, Value *Ident // Key may be nil
Expand Down
15 changes: 15 additions & 0 deletions cl/builtin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ func getGoxConf() *gox.Config {
return &gox.Config{Fset: fset, Importer: imp}
}

func TestCompileFuncAlias(t *testing.T) {
ctx := &blockCtx{
pkgCtx: &pkgCtx{
syms: map[string]loader{"Foo": &baseLoader{
fn: func() {},
}},
},
}
scope := types.NewScope(nil, 0, 0, "")
x := ast.NewIdent("foo")
if compileFuncAlias(ctx, scope, x, 0) {
t.Fatal("compileFuncAlias: ok?")
}
}

func TestErrStringLit(t *testing.T) {
defer func() {
if e := recover(); e == nil {
Expand Down
53 changes: 22 additions & 31 deletions cl/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package cl

import (
"fmt"
"go/constant"
"go/types"
"log"
"reflect"
Expand Down Expand Up @@ -175,9 +174,6 @@ type Config struct {
// Fset provides source position information for syntax trees and types (required).
Fset *token.FileSet

// Context represents all things between packages (optional).
Context *gox.Context

// RelativeBase is the root directory of relative path.
RelativeBase string

Expand All @@ -193,9 +189,6 @@ type Config struct {
// See (*github.com/goplus/mod/gopmod.Module).LookupClass.
LookupClass func(ext string) (c *Project, ok bool)

// IsPkgtStandard checks a pkgPath is a Go standard package or not.
IsPkgtStandard func(pkgPath string) bool

// An Importer resolves import paths to Packages (optional).
Importer types.Importer

Expand Down Expand Up @@ -253,20 +246,21 @@ type baseLoader struct {
start token.Pos
}

func initLoader(ctx *pkgCtx, syms map[string]loader, start token.Pos, name string, fn func(), genBody bool) {
func initLoader(ctx *pkgCtx, syms map[string]loader, start token.Pos, name string, fn func(), genBody bool) bool {
if name == "_" {
if genBody {
ctx.inits = append(ctx.inits, fn)
}
return
return false
}
if old, ok := syms[name]; ok {
oldpos := ctx.Position(old.pos())
ctx.handleErrorf(
start, "%s redeclared in this block\n\tprevious declaration at %v", name, oldpos)
return
return false
}
syms[name] = &baseLoader{start: start, fn: fn}
return true
}

func (p *baseLoader) load() {
Expand Down Expand Up @@ -490,8 +484,6 @@ func NewPackage(pkgPath string, pkg *ast.Package, conf *Config) (p *gox.Package,
confGox := &gox.Config{
Types: conf.Types,
Fset: fset,
Context: conf.Context,
IsPkgtStandard: conf.IsPkgtStandard,
Importer: conf.Importer,
LoadNamed: ctx.loadNamed,
HandleErr: ctx.handleErr,
Expand Down Expand Up @@ -525,15 +517,6 @@ func NewPackage(pkgPath string, pkg *ast.Package, conf *Config) (p *gox.Package,
Pkg: p, LookupPub: conf.LookupPub,
})

for file, gmx := range files {
if gmx.IsClass && !gmx.IsNormalGox {
if debugLoad {
log.Println("==> File", file, "normalGox:", gmx.IsNormalGox)
}
loadClass(ctx, p, file, gmx, conf)
}
}

// sort files
type File struct {
*ast.File
Expand All @@ -547,6 +530,16 @@ func NewPackage(pkgPath string, pkg *ast.Package, conf *Config) (p *gox.Package,
return sfiles[i].path < sfiles[j].path
})

for _, f := range sfiles {
gmx := f.File
if gmx.IsClass && !gmx.IsNormalGox {
if debugLoad {
log.Println("==> File", f.path, "normalGox:", gmx.IsNormalGox)
}
loadClass(ctx, p, f.path, gmx, conf)
}
}

for _, f := range sfiles {
fileLine := !conf.NoFileLine
fileScope := types.NewScope(p.Types.Scope(), f.Pos(), f.End(), f.path)
Expand Down Expand Up @@ -624,10 +617,6 @@ func NewPackage(pkgPath string, pkg *ast.Package, conf *Config) (p *gox.Package,
return
}

const (
gopPackage = "GopPackage"
)

func isOverloadFunc(name string) bool {
n := len(name)
return n > 3 && name[n-3:n-1] == "__"
Expand All @@ -651,9 +640,6 @@ func initGopPkg(ctx *pkgCtx, pkg *gox.Package, gopSyms map[string]bool) {
ctx.loadType(lbi.(*ast.Ident).Name)
}
}
if pkg.Types.Scope().Lookup(gopPackage) == nil {
pkg.Types.Scope().Insert(types.NewConst(token.NoPos, pkg.Types, gopPackage, types.Typ[types.UntypedBool], constant.MakeBool(true)))
}
gox.InitThisGopPkg(pkg.Types)
}

Expand Down Expand Up @@ -920,7 +906,8 @@ func preloadFile(p *gox.Package, ctx *blockCtx, file string, f *ast.File, goFile
defer p.RestoreCurFile(old)
loadFunc(ctx, nil, d, genFnBody)
}
if name.Name == "init" {
fname := name.Name
if fname == "init" {
if genFnBody {
if debugLoad {
log.Println("==> Preload func init")
Expand All @@ -929,9 +916,13 @@ func preloadFile(p *gox.Package, ctx *blockCtx, file string, f *ast.File, goFile
}
} else {
if debugLoad {
log.Println("==> Preload func", name.Name)
log.Println("==> Preload func", fname)
}
if initLoader(parent, syms, name.Pos(), fname, fn, genFnBody) {
if strings.HasPrefix(fname, "Gopx_") { // Gopx_xxx func
ctx.lbinames = append(ctx.lbinames, fname)
}
}
initLoader(parent, syms, name.Pos(), name.Name, fn, genFnBody)
}
} else {
if name, ok := getRecvTypeName(parent, d.Recv, true); ok {
Expand Down
Loading

0 comments on commit 6a18888

Please sign in to comment.