Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

README: Support for C/C++ and Python #1925

Merged
merged 2 commits into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 81 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ The Go+ programming language is designed for engineering, STEM education, and da
For more details, see [Quick Start](doc/docs.md).


## Key Features of Go+

* Approaching natural language expression and intuitive (see [Command Style Code](#command-style-code)).
* Fully compatible with [Go](https://github.com/golang/go) and can mix Go/Go+ code in the same package (see [Go/Go+ Hybrid Programming](doc/docs.md#gogo-hybrid-programming)).
* Integrating with the C ecosystem including Python and providing limitless possibilities (see [Support for C/C++ and Python](#support-for-cc-and-python)).
* Does not support DSL (Domain-Specific Languages), but supports SDF (Specific Domain Friendliness) (see [Go+ Classfiles](#go-classfiles)).


## Command Style Code

Different from the function call style of most languages, Go+ recommends command style code:
Expand All @@ -61,6 +69,79 @@ echo "Hello world"
For more discussion on coding style, see https://tutorial.goplus.org/hello-world.


## Support for C/C++ and Python

Go+ can choose different Go compilers as its underlying support. Currently known supported Go compilers include:

* [go](https://go.dev/) (The official Go compiler supported by Google)
* [llgo](https://github.com/goplus/llgo) (The Go compiler supported by the Go+ team)
* [tinygo](https://tinygo.org/) (A Go compiler for small places)

Currently, Go+ defaults to using [go](https://go.dev/) as its underlying support, but in the future, it will be [llgo](https://github.com/goplus/llgo).

LLGo is a Go compiler based on [LLVM](https://llvm.org/) in order to better integrate Go with the C ecosystem including Python. It aims to expand the boundaries of Go/Go+, providing limitless possibilities such as:

* Game development
* AI and data science
* WebAssembly
* Embedded development
* ...

If you wish to use [llgo](https://github.com/goplus/llgo), specify the `-llgo` flag when initializing a Go+ module:

```sh
gop mod init -llgo YourModulePath
```

This will generate a `go.mod` file with the following contents (It may vary slightly depending on the versions of local Go+ and LLGo):

```go
module YourModulePath

go 1.21 // llgo 1.0

require github.com/goplus/llgo v0.9.1
```

Based on LLGo, Go+ can support importing libraries written in C/C++ and Python.

Here is an example (see [chello](demo/_llgo/chello/hello.gop)) of printing `Hello world` using C's `printf`:

```go
import "c"

c.printf c"Hello world\n"
```

Here, `c"Hello world\n"` is a syntax supported by Go+, representing a null-terminated C-style string.

To run this example, you can:

```sh
cd YourModulePath # set work directory to your module
gop mod tidy # for generating go.sum file
gop run .
```

And here is an example (see [pyhello](demo/_llgo/pyhello/hello.gop)) of printing `Hello world` using Python's `print`:

```go
import "py/std"

std.print py"Hello world"
```

Here, `py"Hello world"` is a syntax supported by Go+, representing a Python string.

Here are more examples of Go+ calling C/C++ and Python libraries:

* [pytensor](demo/_llgo/pytensor/tensor.gop): a simple demo using [py/torch](https://pkg.go.dev/github.com/goplus/llgo/py/torch)
* [tetris](demo/_llgo/tetris/tetris.gop): a tetris game based on [c/raylib](https://pkg.go.dev/github.com/goplus/llgo/c/raylib)
* [sqlitedemo](demo/_llgo/sqlitedemo/sqlitedemo.gop): a demo using [c/sqlite](https://pkg.go.dev/github.com/goplus/llgo/c/sqlite)

To find out more about LLGo/Go+'s support for C/C++ and Python in detail, please refer to homepage of [llgo](https://github.com/goplus/llgo).


## Go+ Classfiles

```
Expand Down Expand Up @@ -189,18 +270,6 @@ Don't need a `go.mod` file, just enter `gop run ./example.gsh` directly to run.
See [gsh: Go+ DevOps Tools](https://github.com/qiniu/x/tree/main/gsh) for more details.


## Key Features of Go+

* A static typed language.
* The simplest engineering language that can be mastered by children (script-like style).
* Performance: as fast as Go (Go+'s main backend compiles to human-readable Go).
* Fully compatible with [Go](https://github.com/golang/go) and can mix Go/Go+ code in the same package (see [Go/Go+ hybrid programming](doc/docs.md#gogo-hybrid-programming)).
* No DSL (Domain Specific Language) support, but SDF ([Specific Domain Friendliness](doc/classfile.md)).
* Support Go code generation (main backend) and [bytecode backend](https://github.com/goplus/igop) (REPL: see [iGo+](https://repl.goplus.org/)).
* [Simplest way to interaction with C](doc/docs.md#calling-c-from-go) (cgo is supported but not recommended).
* [Powerful built-in data processing capabilities](doc/docs.md#data-processing).


## How to install

Note: Requires go1.19 or later
Expand Down
File renamed without changes.