Compare commits
128 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8882c31eb4 | ||
|
|
8455ee8226 | ||
|
|
3f74aded8a | ||
|
|
2e19c2013c | ||
|
|
1edaa2d09b | ||
|
|
beee018287 | ||
|
|
34266ea59d | ||
|
|
f26127ce98 | ||
|
|
ccf321d178 | ||
|
|
355721c47a | ||
|
|
d400663e5d | ||
|
|
2203be945a | ||
|
|
b9a2bf4b42 | ||
|
|
cc08195cf2 | ||
|
|
50c40a7828 | ||
|
|
158be3f949 | ||
|
|
0f87c322ca | ||
|
|
d5dd19b64c | ||
|
|
3032d730b7 | ||
|
|
e93e7126b6 | ||
|
|
9bcf41d28f | ||
|
|
604ce47d5e | ||
|
|
e1ebe150d4 | ||
|
|
ae992737e8 | ||
|
|
c59d609eb8 | ||
|
|
9f26d12a3e | ||
|
|
9102577eba | ||
|
|
f0fcfde22b | ||
|
|
d9d813db56 | ||
|
|
a8808855ae | ||
|
|
5583f9418a | ||
|
|
7369ffd2aa | ||
|
|
ab15f30b13 | ||
|
|
8bff07d66b | ||
|
|
e2e2cb38be | ||
|
|
10d84a6a6b | ||
|
|
a4b4c1574b | ||
|
|
94bc39bdb2 | ||
|
|
7c93b37125 | ||
|
|
4371cc10bd | ||
|
|
eaa2628934 | ||
|
|
30e247186c | ||
|
|
2714da8d98 | ||
|
|
0ef3a7ec25 | ||
|
|
489a0069aa | ||
|
|
a257b7bdfa | ||
|
|
739cc66d0d | ||
|
|
28d944c6af | ||
|
|
19b98393a6 | ||
|
|
5a13e7400e | ||
|
|
a56129d675 | ||
|
|
0d75bbace0 | ||
|
|
29ec4a7a0e | ||
|
|
8b26c48d9b | ||
|
|
ddd0535d30 | ||
|
|
adcd370c27 | ||
|
|
dbead0d725 | ||
|
|
207aea813b | ||
|
|
7a771154a7 | ||
|
|
18c6b9b404 | ||
|
|
3110382d88 | ||
|
|
9ee55896e3 | ||
|
|
ad6f41f312 | ||
|
|
8512395985 | ||
|
|
7284042823 | ||
|
|
0ef683bba9 | ||
|
|
d4bf66936a | ||
|
|
be4737461a | ||
|
|
0d22b3be05 | ||
|
|
7c81d9293b | ||
|
|
d1dce65313 | ||
|
|
641f9bbf7c | ||
|
|
be0e42cf82 | ||
|
|
3a883b8821 | ||
|
|
4bbc58d62d | ||
|
|
5f4b09bede | ||
|
|
f0ade21155 | ||
|
|
f35063ee6e | ||
|
|
e6c7627ee8 | ||
|
|
a85d937482 | ||
|
|
b17632a352 | ||
|
|
b11eb742cb | ||
|
|
b63a7f64fd | ||
|
|
cafc438972 | ||
|
|
33ef7f737b | ||
|
|
3e26685a44 | ||
|
|
6a306be480 | ||
|
|
9defb6289b | ||
|
|
a47ad2886f | ||
|
|
c8d791f206 | ||
|
|
8c5f915569 | ||
|
|
ed366568b4 | ||
|
|
0a8a4eb6a6 | ||
|
|
fdc6cf4838 | ||
|
|
e52af0077b | ||
|
|
847f544839 | ||
|
|
685d3202d0 | ||
|
|
33a2580cc3 | ||
|
|
a8da654597 | ||
|
|
ae01a023ad | ||
|
|
ec20af3c4d | ||
|
|
a6f1ad1c2c | ||
|
|
c3532f17de | ||
|
|
86eac2f04d | ||
|
|
3b9b71643c | ||
|
|
19417cdd52 | ||
|
|
a7c23e25d8 | ||
|
|
f96ab87536 | ||
|
|
d65d49f504 | ||
|
|
8cd5924bf2 | ||
|
|
9f38338c58 | ||
|
|
8c76436d81 | ||
|
|
0e71576265 | ||
|
|
71b34003ca | ||
|
|
2c417d75a2 | ||
|
|
74ededd8c8 | ||
|
|
a732fa237c | ||
|
|
fd4c22308d | ||
|
|
d6f18894e6 | ||
|
|
992d54693f | ||
|
|
9be1bd0775 | ||
|
|
29cc689abd | ||
|
|
39d28e507d | ||
|
|
eacb5bc6f8 | ||
|
|
19658454bd | ||
|
|
02e3a6ae8b | ||
|
|
77376087db | ||
|
|
52a77f9efb |
20
.github/actions/setup-deps/action.yml
vendored
20
.github/actions/setup-deps/action.yml
vendored
@@ -4,7 +4,7 @@ inputs:
|
||||
llvm-version:
|
||||
description: "LLVM version to install"
|
||||
required: true
|
||||
default: "18"
|
||||
default: "19"
|
||||
|
||||
runs:
|
||||
using: "composite"
|
||||
@@ -14,17 +14,17 @@ runs:
|
||||
shell: bash
|
||||
run: |
|
||||
brew update
|
||||
brew install llvm@${{inputs.llvm-version}} bdw-gc openssl libffi libuv
|
||||
brew link --force libffi
|
||||
brew install llvm@${{inputs.llvm-version}} lld@${{inputs.llvm-version}} bdw-gc openssl libffi libuv
|
||||
brew link --overwrite llvm@${{inputs.llvm-version}} lld@${{inputs.llvm-version}} libffi
|
||||
echo "$(brew --prefix llvm@${{inputs.llvm-version}})/bin" >> $GITHUB_PATH
|
||||
|
||||
# Install optional deps for demos.
|
||||
#
|
||||
# NOTE: Keep this list updated as new deps are introduced.
|
||||
opt_deps=(
|
||||
cjson # for github.com/goplus/llgo/c/cjson
|
||||
sqlite # for github.com/goplus/llgo/c/sqlite
|
||||
python@3.12 # for github.com/goplus/llgo/py
|
||||
cjson # for github.com/goplus/lib/c/cjson
|
||||
sqlite # for github.com/goplus/lib/c/sqlite
|
||||
python@3.12 # for github.com/goplus/lib/py
|
||||
)
|
||||
brew install "${opt_deps[@]}"
|
||||
- name: Install Ubuntu dependencies
|
||||
@@ -35,14 +35,14 @@ runs:
|
||||
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y llvm-${{inputs.llvm-version}}-dev clang-${{inputs.llvm-version}} libclang-${{inputs.llvm-version}}-dev lld-${{inputs.llvm-version}} pkg-config libgc-dev libssl-dev zlib1g-dev libffi-dev libcjson-dev libunwind-dev libuv1-dev
|
||||
echo "/usr/lib/llvm-${{inputs.llvm-version}}/bin" >> $GITHUB_PATH
|
||||
echo "PATH=/usr/lib/llvm-${{inputs.llvm-version}}/bin:$PATH" >> $GITHUB_ENV
|
||||
|
||||
# Install optional deps for demos.
|
||||
#
|
||||
# NOTE: Keep this list updated as new deps are introduced.
|
||||
opt_deps=(
|
||||
libcjson-dev # for github.com/goplus/llgo/c/cjson
|
||||
libsqlite3-dev # for github.com/goplus/llgo/c/sqlite
|
||||
python3.12-dev # for github.com/goplus/llgo/py
|
||||
libcjson-dev # for github.com/goplus/lib/c/cjson
|
||||
libsqlite3-dev # for github.com/goplus/lib/c/sqlite
|
||||
python3.12-dev # for github.com/goplus/lib/py
|
||||
)
|
||||
sudo apt-get install -y "${opt_deps[@]}"
|
||||
|
||||
2
.github/actions/test-helloworld/action.yml
vendored
2
.github/actions/test-helloworld/action.yml
vendored
@@ -23,7 +23,7 @@ runs:
|
||||
package main
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/lib/c"
|
||||
)
|
||||
func main() {
|
||||
fmt.Println("Hello, LLGo!")
|
||||
|
||||
16
.github/codecov.yml
vendored
16
.github/codecov.yml
vendored
@@ -1,9 +1,11 @@
|
||||
coverage:
|
||||
ignore:
|
||||
- "compiler/chore"
|
||||
- "compiler/cmd/internal"
|
||||
- "compiler/internal/build"
|
||||
- "compiler/internal/llgen"
|
||||
- "compiler/internal/mockable"
|
||||
- "compiler/internal/packages"
|
||||
- "compiler/internal/typepatch"
|
||||
- "chore"
|
||||
- "cmd"
|
||||
- "internal/build"
|
||||
- "internal/llgen"
|
||||
- "internal/mockable"
|
||||
- "internal/packages"
|
||||
- "internal/typepatch"
|
||||
- "internal/github"
|
||||
- "xtool/cppkg"
|
||||
|
||||
10
.github/dependabot.yml
vendored
10
.github/dependabot.yml
vendored
@@ -17,13 +17,3 @@ updates:
|
||||
directory: "/" # Location of package manifests
|
||||
schedule:
|
||||
interval: "daily"
|
||||
|
||||
- package-ecosystem: "gomod" # See documentation for possible values
|
||||
directory: "/compiler/" # Location of package manifests
|
||||
schedule:
|
||||
interval: "daily"
|
||||
|
||||
- package-ecosystem: "gomod" # See documentation for possible values
|
||||
directory: "/runtime/" # Location of package manifests
|
||||
schedule:
|
||||
interval: "daily"
|
||||
|
||||
18
.github/workflows/doc.yml
vendored
18
.github/workflows/doc.yml
vendored
@@ -2,9 +2,9 @@ name: Docs
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "**" ]
|
||||
branches: ["**"]
|
||||
pull_request:
|
||||
branches: [ "**" ]
|
||||
branches: ["**"]
|
||||
|
||||
jobs:
|
||||
doc_verify:
|
||||
@@ -15,7 +15,7 @@ jobs:
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20'
|
||||
node-version: "20"
|
||||
|
||||
- name: Install embedme
|
||||
run: npm install -g embedme
|
||||
@@ -27,9 +27,10 @@ jobs:
|
||||
id: lychee
|
||||
uses: lycheeverse/lychee-action@v2
|
||||
with:
|
||||
args: README.md
|
||||
args: --max-concurrency 3 --retry-wait-time 15 README.md
|
||||
|
||||
remote_install:
|
||||
continue-on-error: true
|
||||
strategy:
|
||||
matrix:
|
||||
os:
|
||||
@@ -42,7 +43,7 @@ jobs:
|
||||
- name: Set up Go
|
||||
uses: ./.github/actions/setup-go
|
||||
with:
|
||||
go-version: '1.23.6'
|
||||
go-version: "1.24.2"
|
||||
|
||||
- name: Install dependencies on macOS
|
||||
if: startsWith(matrix.os, 'macos')
|
||||
@@ -65,6 +66,7 @@ jobs:
|
||||
source doc/_readme/scripts/run.sh
|
||||
|
||||
local_install:
|
||||
continue-on-error: true
|
||||
strategy:
|
||||
matrix:
|
||||
os:
|
||||
@@ -77,7 +79,7 @@ jobs:
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '1.23'
|
||||
go-version: "1.23"
|
||||
|
||||
- name: Install dependencies on macOS
|
||||
if: startsWith(matrix.os, 'macos')
|
||||
@@ -115,6 +117,7 @@ jobs:
|
||||
source doc/_readme/scripts/run.sh
|
||||
|
||||
local_install_full:
|
||||
continue-on-error: true
|
||||
strategy:
|
||||
matrix:
|
||||
os:
|
||||
@@ -127,7 +130,7 @@ jobs:
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '1.23'
|
||||
go-version: "1.23"
|
||||
|
||||
- name: Install dependencies on macOS
|
||||
if: startsWith(matrix.os, 'macos')
|
||||
@@ -142,6 +145,7 @@ jobs:
|
||||
set -e
|
||||
set -x
|
||||
source doc/_readme/scripts/install_ubuntu.sh
|
||||
echo "PATH=/usr/lib/llvm-19/bin:$PATH" >> $GITHUB_ENV
|
||||
|
||||
- name: Install llgo with tools
|
||||
run: |
|
||||
|
||||
10
.github/workflows/fmt.yml
vendored
10
.github/workflows/fmt.yml
vendored
@@ -2,9 +2,9 @@ name: Format Check
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "**" ]
|
||||
branches: ["**"]
|
||||
pull_request:
|
||||
branches: [ "**" ]
|
||||
branches: ["**"]
|
||||
|
||||
jobs:
|
||||
fmt:
|
||||
@@ -15,13 +15,13 @@ jobs:
|
||||
- name: Set up Go
|
||||
uses: ./.github/actions/setup-go
|
||||
with:
|
||||
go-version: '1.24.0'
|
||||
go-version: "1.24.2"
|
||||
|
||||
- name: Check formatting
|
||||
run: |
|
||||
for dir in . compiler runtime; do
|
||||
for dir in . runtime; do
|
||||
pushd $dir
|
||||
if [ -n "$(go fmt ./...)" ]; then
|
||||
if [ -n "$(go fmt ./... | grep -v gop_autogen.go)" ]; then
|
||||
echo "Some files are not properly formatted. Please run 'go fmt ./...'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
11
.github/workflows/go.yml
vendored
11
.github/workflows/go.yml
vendored
@@ -5,9 +5,9 @@ name: Go
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "**" ]
|
||||
branches: ["**"]
|
||||
pull_request:
|
||||
branches: [ "**" ]
|
||||
branches: ["**"]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
@@ -17,11 +17,8 @@ jobs:
|
||||
os:
|
||||
- macos-latest
|
||||
- ubuntu-24.04
|
||||
llvm: [18]
|
||||
llvm: [19]
|
||||
runs-on: ${{matrix.os}}
|
||||
defaults:
|
||||
run:
|
||||
working-directory: compiler
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Install dependencies
|
||||
@@ -38,7 +35,7 @@ jobs:
|
||||
- name: Set up Go
|
||||
uses: ./.github/actions/setup-go
|
||||
with:
|
||||
go-version: '1.24.0'
|
||||
go-version: "1.24.2"
|
||||
|
||||
- name: Build
|
||||
run: go build -v ./...
|
||||
|
||||
147
.github/workflows/llgo.yml
vendored
147
.github/workflows/llgo.yml
vendored
@@ -5,20 +5,36 @@ name: LLGo
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "**" ]
|
||||
branches: ["**"]
|
||||
pull_request:
|
||||
branches: [ "**" ]
|
||||
branches: ["**"]
|
||||
|
||||
jobs:
|
||||
download-model:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Download model file
|
||||
run: |
|
||||
mkdir -p ./_demo/llama2-c
|
||||
wget -P ./_demo/llama2-c https://huggingface.co/karpathy/tinyllamas/resolve/main/stories15M.bin
|
||||
|
||||
- name: Upload model as artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: llama2-model
|
||||
path: ./_demo/llama2-c/stories15M.bin
|
||||
retention-days: 1
|
||||
|
||||
llgo:
|
||||
needs: download-model
|
||||
continue-on-error: true
|
||||
strategy:
|
||||
matrix:
|
||||
os:
|
||||
- macos-latest
|
||||
- ubuntu-24.04
|
||||
llvm: [18]
|
||||
go: ['1.20.14', '1.21.13', '1.22.12', '1.23.6', '1.24.0']
|
||||
llvm: [19]
|
||||
go: ["1.21.13", "1.22.12", "1.23.6", "1.24.2"]
|
||||
runs-on: ${{matrix.os}}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
@@ -26,22 +42,25 @@ jobs:
|
||||
uses: ./.github/actions/setup-deps
|
||||
with:
|
||||
llvm-version: ${{matrix.llvm}}
|
||||
- name: Download model artifact
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: llama2-model
|
||||
path: ./_demo/llama2-c/
|
||||
- name: Install further optional dependencies for demos
|
||||
run: |
|
||||
wget -P ./_demo/llama2-c https://huggingface.co/karpathy/tinyllamas/resolve/main/stories15M.bin
|
||||
py_deps=(
|
||||
numpy # for github.com/goplus/llgo/py/numpy
|
||||
torch # for github.com/goplus/llgo/py/torch
|
||||
numpy # for github.com/goplus/lib/py/numpy
|
||||
torch # for github.com/goplus/lib/py/torch
|
||||
)
|
||||
pip3.12 install --break-system-packages "${py_deps[@]}"
|
||||
|
||||
- name: Set up Go for build
|
||||
uses: ./.github/actions/setup-go
|
||||
with:
|
||||
go-version: '1.24.0'
|
||||
go-version: "1.24.2"
|
||||
|
||||
- name: Install
|
||||
working-directory: compiler
|
||||
run: |
|
||||
go install ./...
|
||||
echo "LLGO_ROOT=$GITHUB_WORKSPACE" >> $GITHUB_ENV
|
||||
@@ -51,26 +70,11 @@ jobs:
|
||||
with:
|
||||
go-version: ${{matrix.go}}
|
||||
|
||||
- name: Verify Go version
|
||||
run: |
|
||||
go_version=$(go version | cut -d' ' -f3 | sed 's/go//')
|
||||
if [[ "$go_version" != "${{matrix.go}}"* ]]; then
|
||||
echo "Expected Go version ${{matrix.go}}, but got $go_version"
|
||||
exit 1
|
||||
fi
|
||||
echo "Using Go version: $go_version"
|
||||
|
||||
- name: _xtool build tests
|
||||
run: |
|
||||
cd _xtool
|
||||
llgo build -v ./...
|
||||
|
||||
- name: LLGO tests
|
||||
if: ${{!startsWith(matrix.os, 'ubuntu')}}
|
||||
run: |
|
||||
echo "Test result on ${{matrix.os}} with LLVM ${{matrix.llvm}}" > result.md
|
||||
bash ./.github/workflows/test_llgo.sh
|
||||
|
||||
- name: Test demos
|
||||
run: |
|
||||
# TODO(lijie): force python3-embed to be linked with python-3.12-embed
|
||||
@@ -89,7 +93,6 @@ jobs:
|
||||
|
||||
- name: LLDB tests
|
||||
if: ${{startsWith(matrix.os, 'macos')}}
|
||||
working-directory: compiler
|
||||
run: |
|
||||
echo "Test lldb with llgo plugin on ${{matrix.os}} with LLVM ${{matrix.llvm}}"
|
||||
bash _lldb/runtest.sh -v
|
||||
@@ -101,8 +104,8 @@ jobs:
|
||||
os:
|
||||
- macos-latest
|
||||
- ubuntu-24.04
|
||||
llvm: [18]
|
||||
go: ['1.24.0']
|
||||
llvm: [19]
|
||||
go: ["1.24.2"]
|
||||
runs-on: ${{matrix.os}}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
@@ -112,20 +115,18 @@ jobs:
|
||||
llvm-version: ${{matrix.llvm}}
|
||||
- name: Install further optional dependencies for demos
|
||||
run: |
|
||||
wget -P ./_demo/llama2-c https://huggingface.co/karpathy/tinyllamas/resolve/main/stories15M.bin
|
||||
py_deps=(
|
||||
numpy # for github.com/goplus/llgo/py/numpy
|
||||
torch # for github.com/goplus/llgo/py/torch
|
||||
numpy # for github.com/goplus/lib/py/numpy
|
||||
torch # for github.com/goplus/lib/py/torch
|
||||
)
|
||||
pip3.12 install --break-system-packages "${py_deps[@]}"
|
||||
|
||||
- name: Set up Go for build
|
||||
uses: ./.github/actions/setup-go
|
||||
with:
|
||||
go-version: '1.24.0'
|
||||
go-version: "1.24.2"
|
||||
|
||||
- name: Install
|
||||
working-directory: compiler
|
||||
run: |
|
||||
go install ./...
|
||||
echo "LLGO_ROOT=$GITHUB_WORKSPACE" >> $GITHUB_ENV
|
||||
@@ -135,27 +136,17 @@ jobs:
|
||||
with:
|
||||
go-version: ${{matrix.go}}
|
||||
|
||||
- name: Verify Go version
|
||||
run: |
|
||||
go_version=$(go version | cut -d' ' -f3 | sed 's/go//')
|
||||
if [[ "$go_version" != "${{matrix.go}}"* ]]; then
|
||||
echo "Expected Go version ${{matrix.go}}, but got $go_version"
|
||||
exit 1
|
||||
fi
|
||||
echo "Using Go version: $go_version"
|
||||
|
||||
- name: run llgo test
|
||||
run: |
|
||||
cd _demo
|
||||
llgo test -v ./runtest
|
||||
llgo test ./...
|
||||
|
||||
hello:
|
||||
continue-on-error: true
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-24.04, macos-latest]
|
||||
llvm: [18]
|
||||
go: ['1.20.14', '1.21.13', '1.22.12', '1.23.6', '1.24.0']
|
||||
llvm: [19]
|
||||
go: ["1.21.13", "1.22.12", "1.23.6", "1.24.2"]
|
||||
runs-on: ${{matrix.os}}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
@@ -167,10 +158,9 @@ jobs:
|
||||
- name: Set up Go 1.23 for building llgo
|
||||
uses: ./.github/actions/setup-go
|
||||
with:
|
||||
go-version: '1.24.0'
|
||||
go-version: "1.24.2"
|
||||
|
||||
- name: Install llgo
|
||||
working-directory: compiler
|
||||
run: |
|
||||
go install ./...
|
||||
echo "LLGO_ROOT=$GITHUB_WORKSPACE" >> $GITHUB_ENV
|
||||
@@ -180,37 +170,78 @@ jobs:
|
||||
with:
|
||||
go-version: ${{matrix.go}}
|
||||
|
||||
- name: Test Hello World with go.mod 1.20
|
||||
if: startsWith(matrix.go, '1.20') || startsWith(matrix.go, '1.21') || startsWith(matrix.go, '1.22') || startsWith(matrix.go, '1.23') || startsWith(matrix.go, '1.24')
|
||||
uses: ./.github/actions/test-helloworld
|
||||
with:
|
||||
go-version: ${{matrix.go}}
|
||||
mod-version: '1.20'
|
||||
|
||||
- name: Test Hello World with go.mod 1.21
|
||||
if: startsWith(matrix.go, '1.21') || startsWith(matrix.go, '1.22') || startsWith(matrix.go, '1.23') || startsWith(matrix.go, '1.24')
|
||||
uses: ./.github/actions/test-helloworld
|
||||
with:
|
||||
go-version: ${{matrix.go}}
|
||||
mod-version: '1.21'
|
||||
mod-version: "1.21"
|
||||
|
||||
- name: Test Hello World with go.mod 1.22
|
||||
if: startsWith(matrix.go, '1.22') || startsWith(matrix.go, '1.23') || startsWith(matrix.go, '1.24')
|
||||
uses: ./.github/actions/test-helloworld
|
||||
with:
|
||||
go-version: ${{matrix.go}}
|
||||
mod-version: '1.22'
|
||||
mod-version: "1.22"
|
||||
|
||||
- name: Test Hello World with go.mod 1.23
|
||||
if: startsWith(matrix.go, '1.23') || startsWith(matrix.go, '1.24')
|
||||
uses: ./.github/actions/test-helloworld
|
||||
with:
|
||||
go-version: ${{matrix.go}}
|
||||
mod-version: '1.23'
|
||||
mod-version: "1.23"
|
||||
|
||||
- name: Test Hello World with go.mod 1.24
|
||||
if: startsWith(matrix.go, '1.24')
|
||||
uses: ./.github/actions/test-helloworld
|
||||
with:
|
||||
go-version: ${{matrix.go}}
|
||||
mod-version: '1.24'
|
||||
mod-version: "1.24"
|
||||
|
||||
cross-compile:
|
||||
continue-on-error: true
|
||||
strategy:
|
||||
matrix:
|
||||
os: [macos-latest]
|
||||
llvm: [19]
|
||||
runs-on: ${{matrix.os}}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Install dependencies
|
||||
uses: ./.github/actions/setup-deps
|
||||
with:
|
||||
llvm-version: ${{matrix.llvm}}
|
||||
|
||||
- name: Set up Go for building llgo
|
||||
uses: ./.github/actions/setup-go
|
||||
with:
|
||||
go-version: "1.24.2"
|
||||
|
||||
- name: Install wamr
|
||||
run: |
|
||||
git clone https://github.com/bytecodealliance/wasm-micro-runtime.git
|
||||
mkdir wasm-micro-runtime/product-mini/platforms/darwin/build
|
||||
cd wasm-micro-runtime/product-mini/platforms/darwin/build
|
||||
cmake -D WAMR_BUILD_EXCE_HANDLING=1 -D WAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_SHARED_MEMORY=1 -DWAMR_BUILD_LIB_WASI_THREADS=1 -DWAMR_BUILD_LIB_PTHREAD=1 -DCMAKE_BUILD_TYPE=Debug -DWAMR_BUILD_DEBUG_INTERP=1 ..
|
||||
make -j8
|
||||
echo "$PWD" >> $GITHUB_PATH
|
||||
|
||||
- name: Install llgo
|
||||
run: |
|
||||
go install ./...
|
||||
echo "LLGO_ROOT=$GITHUB_WORKSPACE" >> $GITHUB_ENV
|
||||
|
||||
- name: Test Cross Compilation (wasm)
|
||||
shell: bash
|
||||
working-directory: _demo
|
||||
run: |
|
||||
echo "Testing cross-compilation wasm with Go 1.24.2"
|
||||
|
||||
# Compile for wasm architecture
|
||||
GOOS=wasip1 GOARCH=wasm llgo build -o hello -tags=nogc -v ./helloc
|
||||
|
||||
# Check file type
|
||||
file hello.wasm
|
||||
|
||||
# Run the wasm binary using llgo_wasm
|
||||
iwasm --stack-size=819200000 --heap-size=800000000 hello.wasm
|
||||
|
||||
6
.github/workflows/populate_darwin_sysroot.sh
vendored
6
.github/workflows/populate_darwin_sysroot.sh
vendored
@@ -6,12 +6,12 @@ TMPDIR="$(mktemp -d)"
|
||||
export TMPDIR
|
||||
trap 'rm -rf "${TMPDIR}"' EXIT
|
||||
|
||||
DARWIN_AMD64_LLVM_PREFIX=.sysroot/darwin/amd64/usr/local/opt/llvm@18
|
||||
DARWIN_ARM64_LLVM_PREFIX=.sysroot/darwin/arm64/opt/homebrew/opt/llvm@18
|
||||
DARWIN_AMD64_LLVM_PREFIX=.sysroot/darwin/amd64/usr/local/opt/llvm@19
|
||||
DARWIN_ARM64_LLVM_PREFIX=.sysroot/darwin/arm64/opt/homebrew/opt/llvm@19
|
||||
mkdir -p "${DARWIN_AMD64_LLVM_PREFIX}" "${DARWIN_ARM64_LLVM_PREFIX}"
|
||||
|
||||
BREW_LLVM_FORMULA_JSON="$(mktemp)"
|
||||
curl -fsSL https://formulae.brew.sh/api/formula/llvm@18.json > "${BREW_LLVM_FORMULA_JSON}"
|
||||
curl -fsSL https://formulae.brew.sh/api/formula/llvm@19.json > "${BREW_LLVM_FORMULA_JSON}"
|
||||
BREW_LLVM_AMD64_BOTTLE_URL=$(jq -r '.bottle.stable.files.sonoma.url' "${BREW_LLVM_FORMULA_JSON}")
|
||||
BREW_LLVM_ARM64_BOTTLE_URL=$(jq -r '.bottle.stable.files.arm64_sonoma.url' "${BREW_LLVM_FORMULA_JSON}")
|
||||
curl -fsSL -H "Authorization: Bearer QQ==" "${BREW_LLVM_AMD64_BOTTLE_URL}" | tar -xzf - --strip-components=2 -C "${DARWIN_AMD64_LLVM_PREFIX}"
|
||||
|
||||
5
.github/workflows/populate_linux_sysroot.sh
vendored
5
.github/workflows/populate_linux_sysroot.sh
vendored
@@ -19,10 +19,10 @@ export DEBIAN_FRONTEND=noninteractive
|
||||
apt-get update
|
||||
apt-get install -y lsb-release gnupg2 wget rsync
|
||||
|
||||
echo "deb http://apt.llvm.org/\$(lsb_release -cs)/ llvm-toolchain-\$(lsb_release -cs)-18 main" | tee /etc/apt/sources.list.d/llvm.list
|
||||
echo "deb http://apt.llvm.org/\$(lsb_release -cs)/ llvm-toolchain-\$(lsb_release -cs)-19 main" | tee /etc/apt/sources.list.d/llvm.list
|
||||
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
|
||||
apt-get update
|
||||
apt-get install -y llvm-18-dev
|
||||
apt-get install -y llvm-19-dev
|
||||
|
||||
error() {
|
||||
echo -e "\$1" >&2
|
||||
@@ -106,7 +106,6 @@ do-sync() {
|
||||
args+=(-d)
|
||||
args+=(-h)
|
||||
args+=(--keep-dirlinks)
|
||||
args+=("--info=progress2")
|
||||
args+=(--delete)
|
||||
args+=(--prune-empty-dirs)
|
||||
args+=(--sparse)
|
||||
|
||||
36
.github/workflows/test_llgo.sh
vendored
36
.github/workflows/test_llgo.sh
vendored
@@ -1,36 +0,0 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
testcmd=/tmp/test
|
||||
llgo build -o $testcmd ./c/bdwgc/_test
|
||||
cases=$($testcmd)
|
||||
total=$(echo "$cases" | wc -l | tr -d ' ')
|
||||
failed=0
|
||||
failed_cases=""
|
||||
|
||||
for idx in $(seq 1 $((total))); do
|
||||
case=$(echo "$cases" | sed -n "${idx}p")
|
||||
case_name=$(echo "$case" | cut -d',' -f2)
|
||||
echo "=== Test case: $case_name"
|
||||
set +e
|
||||
out=$("$testcmd" "$((idx-1))" 2>&1)
|
||||
exit_code=$?
|
||||
set -e
|
||||
if [ "${exit_code:-0}" -ne 0 ]; then
|
||||
echo "failed: $out"
|
||||
failed=$((failed+1))
|
||||
failed_cases="$failed_cases\n* :x: $case_name"
|
||||
else
|
||||
echo "passed"
|
||||
fi
|
||||
done
|
||||
echo "=== Done"
|
||||
echo "$((total-failed))/$total tests passed"
|
||||
|
||||
if [ "$failed" -ne 0 ]; then
|
||||
echo ":bangbang: Failed llgo cases:" | tee -a result.md
|
||||
echo -e "$failed_cases" | tee -a result.md
|
||||
exit 1
|
||||
else
|
||||
echo ":white_check_mark: All llgo tests passed" | tee -a result.md
|
||||
fi
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -22,6 +22,7 @@ _tinygo/
|
||||
_output/
|
||||
build.dir/
|
||||
.vscode/
|
||||
.venv/
|
||||
|
||||
# Test binary, built with `go test -c`
|
||||
*.test
|
||||
|
||||
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -1,3 +0,0 @@
|
||||
[submodule "c/llama2/llama2.c"]
|
||||
path = c/llama2/llama2.c
|
||||
url = https://github.com/karpathy/llama2.c.git
|
||||
|
||||
@@ -16,74 +16,70 @@ before:
|
||||
|
||||
builds:
|
||||
- id: llgo-darwin-amd64
|
||||
dir: compiler
|
||||
main: ./cmd/llgo
|
||||
binary: bin/llgo
|
||||
flags:
|
||||
- -tags=darwin,amd64,byollvm
|
||||
ldflags:
|
||||
- -X github.com/goplus/llgo/compiler/internal/env.buildVersion=v{{.Version}}
|
||||
- -X github.com/goplus/llgo/compiler/internal/env.buildTime={{.Date}}
|
||||
- -X github.com/goplus/llgo/xtool/env/llvm.ldLLVMConfigBin=/usr/local/opt/llvm@18/bin/llvm-config
|
||||
- -X github.com/goplus/llgo/internal/env.buildVersion=v{{.Version}}
|
||||
- -X github.com/goplus/llgo/internal/env.buildTime={{.Date}}
|
||||
- -X github.com/goplus/llgo/xtool/env/llvm.ldLLVMConfigBin=/usr/local/opt/llvm@19/bin/llvm-config
|
||||
env:
|
||||
- CC=o64-clang
|
||||
- CXX=o64-clang++
|
||||
- CGO_CPPFLAGS=-I{{.Env.SYSROOT_DARWIN_AMD64}}/usr/local/opt/llvm@18/include -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
|
||||
- CGO_LDFLAGS=-L{{.Env.SYSROOT_DARWIN_AMD64}}/usr/local/opt/llvm@18/lib -Wl,-search_paths_first -Wl,-headerpad_max_install_names -lLLVM-18 -lz -lm
|
||||
- CGO_CPPFLAGS=-I{{.Env.SYSROOT_DARWIN_AMD64}}/usr/local/opt/llvm@19/include -mmacosx-version-min=10.13 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
|
||||
- CGO_LDFLAGS=-L{{.Env.SYSROOT_DARWIN_AMD64}}/usr/local/opt/llvm@19/lib -mmacosx-version-min=10.13 -Wl,-search_paths_first -Wl,-headerpad_max_install_names -lLLVM-19 -lz -lm
|
||||
targets:
|
||||
- darwin_amd64
|
||||
mod_timestamp: "{{.CommitTimestamp}}"
|
||||
- id: llgo-darwin-arm64
|
||||
dir: compiler
|
||||
main: ./cmd/llgo
|
||||
binary: bin/llgo
|
||||
flags:
|
||||
- -tags=darwin,arm64,byollvm
|
||||
ldflags:
|
||||
- -X github.com/goplus/llgo/compiler/internal/env.buildVersion=v{{.Version}}
|
||||
- -X github.com/goplus/llgo/compiler/internal/env.buildTime={{.Date}}
|
||||
- -X github.com/goplus/llgo/xtool/env/llvm.ldLLVMConfigBin=/opt/homebrew/opt/llvm@18/bin/llvm-config
|
||||
- -X github.com/goplus/llgo/internal/env.buildVersion=v{{.Version}}
|
||||
- -X github.com/goplus/llgo/internal/env.buildTime={{.Date}}
|
||||
- -X github.com/goplus/llgo/xtool/env/llvm.ldLLVMConfigBin=/opt/homebrew/opt/llvm@19/bin/llvm-config
|
||||
env:
|
||||
- CC=oa64-clang
|
||||
- CXX=oa64-clang++
|
||||
- CGO_CPPFLAGS=-I{{.Env.SYSROOT_DARWIN_ARM64}}/opt/homebrew/opt/llvm@18/include -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
|
||||
- CGO_LDFLAGS=-L{{.Env.SYSROOT_DARWIN_ARM64}}/opt/homebrew/opt/llvm@18/lib -Wl,-search_paths_first -Wl,-headerpad_max_install_names -lLLVM-18 -lz -lm
|
||||
- CGO_CPPFLAGS=-I{{.Env.SYSROOT_DARWIN_ARM64}}/opt/homebrew/opt/llvm@19/include -mmacosx-version-min=10.13 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
|
||||
- CGO_LDFLAGS=-L{{.Env.SYSROOT_DARWIN_ARM64}}/opt/homebrew/opt/llvm@19/lib -mmacosx-version-min=10.13 -Wl,-search_paths_first -Wl,-headerpad_max_install_names -lLLVM-19 -lz -lm
|
||||
targets:
|
||||
- darwin_arm64
|
||||
mod_timestamp: "{{.CommitTimestamp}}"
|
||||
- id: llgo-linux-amd64
|
||||
dir: compiler
|
||||
main: ./cmd/llgo
|
||||
binary: bin/llgo
|
||||
flags:
|
||||
- -tags=linux,amd64,byollvm
|
||||
ldflags:
|
||||
- -X github.com/goplus/llgo/compiler/internal/env.buildVersion=v{{.Version}}
|
||||
- -X github.com/goplus/llgo/compiler/internal/env.buildTime={{.Date}}
|
||||
- -X github.com/goplus/llgo/xtool/env/llvm.ldLLVMConfigBin=/usr/lib/llvm-18/bin/llvm-config
|
||||
- -X github.com/goplus/llgo/internal/env.buildVersion=v{{.Version}}
|
||||
- -X github.com/goplus/llgo/internal/env.buildTime={{.Date}}
|
||||
- -X github.com/goplus/llgo/xtool/env/llvm.ldLLVMConfigBin=/usr/lib/llvm-19/bin/llvm-config
|
||||
env:
|
||||
- CC=x86_64-linux-gnu-gcc
|
||||
- CXX=x86_64-linux-gnu-g++
|
||||
- CGO_CPPFLAGS=--sysroot={{.Env.SYSROOT_LINUX_AMD64}} -I{{.Env.SYSROOT_LINUX_AMD64}}/usr/include/llvm-18 -I{{.Env.SYSROOT_LINUX_AMD64}}/usr/include/llvm-c-18 -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
|
||||
- CGO_LDFLAGS=--sysroot={{.Env.SYSROOT_LINUX_AMD64}} -L{{.Env.SYSROOT_LINUX_AMD64}}/usr/lib/llvm-18/lib -lLLVM-18
|
||||
- CGO_CPPFLAGS=--sysroot={{.Env.SYSROOT_LINUX_AMD64}} -I{{.Env.SYSROOT_LINUX_AMD64}}/usr/include/llvm-19 -I{{.Env.SYSROOT_LINUX_AMD64}}/usr/include/llvm-c-19 -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
|
||||
- CGO_LDFLAGS=--sysroot={{.Env.SYSROOT_LINUX_AMD64}} -L{{.Env.SYSROOT_LINUX_AMD64}}/usr/lib/llvm-19/lib -lLLVM-19
|
||||
targets:
|
||||
- linux_amd64
|
||||
mod_timestamp: "{{.CommitTimestamp}}"
|
||||
- id: llgo-linux-arm64
|
||||
dir: compiler
|
||||
main: ./cmd/llgo
|
||||
binary: bin/llgo
|
||||
flags:
|
||||
- -tags=linux,arm64,byollvm
|
||||
ldflags:
|
||||
- -X github.com/goplus/llgo/compiler/internal/env.buildVersion=v{{.Version}}
|
||||
- -X github.com/goplus/llgo/compiler/internal/env.buildTime={{.Date}}
|
||||
- -X github.com/goplus/llgo/xtool/env/llvm.ldLLVMConfigBin=/usr/lib/llvm-18/bin/llvm-config
|
||||
- -X github.com/goplus/llgo/internal/env.buildVersion=v{{.Version}}
|
||||
- -X github.com/goplus/llgo/internal/env.buildTime={{.Date}}
|
||||
- -X github.com/goplus/llgo/xtool/env/llvm.ldLLVMConfigBin=/usr/lib/llvm-19/bin/llvm-config
|
||||
env:
|
||||
- CC=aarch64-linux-gnu-gcc
|
||||
- CXX=aarch64-linux-gnu-g++
|
||||
- CGO_CPPFLAGS=--sysroot={{.Env.SYSROOT_LINUX_ARM64}} -I{{.Env.SYSROOT_LINUX_ARM64}}/usr/include/llvm-18 -I{{.Env.SYSROOT_LINUX_ARM64}}/usr/include/llvm-c-18 -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
|
||||
- CGO_LDFLAGS=--sysroot={{.Env.SYSROOT_LINUX_ARM64}} -L{{.Env.SYSROOT_LINUX_ARM64}}/usr/lib/llvm-18/lib -lLLVM-18
|
||||
- CGO_CPPFLAGS=--sysroot={{.Env.SYSROOT_LINUX_ARM64}} -I{{.Env.SYSROOT_LINUX_ARM64}}/usr/include/llvm-19 -I{{.Env.SYSROOT_LINUX_ARM64}}/usr/include/llvm-c-19 -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
|
||||
- CGO_LDFLAGS=--sysroot={{.Env.SYSROOT_LINUX_ARM64}} -L{{.Env.SYSROOT_LINUX_ARM64}}/usr/lib/llvm-19/lib -lLLVM-19
|
||||
targets:
|
||||
- linux_arm64
|
||||
mod_timestamp: "{{.CommitTimestamp}}"
|
||||
|
||||
141
README.md
141
README.md
@@ -31,19 +31,19 @@ LLGo is compatible with C and Python through the language's **Application Binary
|
||||
|
||||
You can import a C/C++ standard library in LLGo!
|
||||
|
||||
* [c](https://pkg.go.dev/github.com/goplus/llgo/c)
|
||||
* [c/syscall](https://pkg.go.dev/github.com/goplus/llgo/c/syscall)
|
||||
* [c/sys](https://pkg.go.dev/github.com/goplus/llgo/c/sys)
|
||||
* [c/os](https://pkg.go.dev/github.com/goplus/llgo/c/os)
|
||||
* [c/math](https://pkg.go.dev/github.com/goplus/llgo/c/math)
|
||||
* [c/math/cmplx](https://pkg.go.dev/github.com/goplus/llgo/c/math/cmplx)
|
||||
* [c/math/rand](https://pkg.go.dev/github.com/goplus/llgo/c/math/rand)
|
||||
* [c/pthread](https://pkg.go.dev/github.com/goplus/llgo/c/pthread)
|
||||
* [c/pthread/sync](https://pkg.go.dev/github.com/goplus/llgo/c/pthread/sync)
|
||||
* [c/sync/atomic](https://pkg.go.dev/github.com/goplus/llgo/c/sync/atomic)
|
||||
* [c/time](https://pkg.go.dev/github.com/goplus/llgo/c/time)
|
||||
* [c/net](https://pkg.go.dev/github.com/goplus/llgo/c/net)
|
||||
* [cpp/std](https://pkg.go.dev/github.com/goplus/llgo/cpp/std)
|
||||
* [c](https://pkg.go.dev/github.com/goplus/lib/c)
|
||||
* [c/syscall](https://pkg.go.dev/github.com/goplus/lib/c/syscall)
|
||||
* [c/sys](https://pkg.go.dev/github.com/goplus/lib/c/sys)
|
||||
* [c/os](https://pkg.go.dev/github.com/goplus/lib/c/os)
|
||||
* [c/math](https://pkg.go.dev/github.com/goplus/lib/c/math)
|
||||
* [c/math/cmplx](https://pkg.go.dev/github.com/goplus/lib/c/math/cmplx)
|
||||
* [c/math/rand](https://pkg.go.dev/github.com/goplus/lib/c/math/rand)
|
||||
* [c/pthread](https://pkg.go.dev/github.com/goplus/lib/c/pthread)
|
||||
* [c/pthread/sync](https://pkg.go.dev/github.com/goplus/lib/c/pthread/sync)
|
||||
* [c/sync/atomic](https://pkg.go.dev/github.com/goplus/lib/c/sync/atomic)
|
||||
* [c/time](https://pkg.go.dev/github.com/goplus/lib/c/time)
|
||||
* [c/net](https://pkg.go.dev/github.com/goplus/lib/c/net)
|
||||
* [cpp/std](https://pkg.go.dev/github.com/goplus/lib/cpp/std)
|
||||
|
||||
Here is a simple example:
|
||||
|
||||
@@ -52,7 +52,7 @@ Here is a simple example:
|
||||
```go
|
||||
package main
|
||||
|
||||
import "github.com/goplus/llgo/c"
|
||||
import "github.com/goplus/lib/c"
|
||||
|
||||
func main() {
|
||||
c.Printf(c.Str("Hello world\n"))
|
||||
@@ -105,14 +105,14 @@ func main() {
|
||||
}
|
||||
```
|
||||
|
||||
Or put it into a package (see [c/math](c/math/math.go)):
|
||||
Or put it into a package (see [c/math](https://github.com/goplus/lib/tree/main/c/math/math.go)):
|
||||
|
||||
<!-- embedme doc/_readme/llgo_call_cmath/call_cmath.go -->
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import "github.com/goplus/llgo/c/math"
|
||||
import "github.com/goplus/lib/c/math"
|
||||
|
||||
func main() {
|
||||
println("sqrt(2) =", math.Sqrt(2))
|
||||
@@ -126,18 +126,18 @@ You can import a Python library in LLGo!
|
||||
|
||||
And you can import any Python library into `llgo` through a program called `llpyg` (see [Development tools](#development-tools)). The following libraries have been included in `llgo`:
|
||||
|
||||
* [py](https://pkg.go.dev/github.com/goplus/llgo/py) (abi)
|
||||
* [py/std](https://pkg.go.dev/github.com/goplus/llgo/py/std) (builtins)
|
||||
* [py/sys](https://pkg.go.dev/github.com/goplus/llgo/py/sys)
|
||||
* [py/os](https://pkg.go.dev/github.com/goplus/llgo/py/os)
|
||||
* [py/math](https://pkg.go.dev/github.com/goplus/llgo/py/math)
|
||||
* [py/json](https://pkg.go.dev/github.com/goplus/llgo/py/json)
|
||||
* [py/inspect](https://pkg.go.dev/github.com/goplus/llgo/py/inspect)
|
||||
* [py/statistics](https://pkg.go.dev/github.com/goplus/llgo/py/statistics)
|
||||
* [py/numpy](https://pkg.go.dev/github.com/goplus/llgo/py/numpy)
|
||||
* [py/pandas](https://pkg.go.dev/github.com/goplus/llgo/py/pandas)
|
||||
* [py/torch](https://pkg.go.dev/github.com/goplus/llgo/py/torch)
|
||||
* [py/matplotlib](https://pkg.go.dev/github.com/goplus/llgo/py/matplotlib)
|
||||
* [py](https://pkg.go.dev/github.com/goplus/lib/py) (abi)
|
||||
* [py/std](https://pkg.go.dev/github.com/goplus/lib/py/std) (builtins)
|
||||
* [py/sys](https://pkg.go.dev/github.com/goplus/lib/py/sys)
|
||||
* [py/os](https://pkg.go.dev/github.com/goplus/lib/py/os)
|
||||
* [py/math](https://pkg.go.dev/github.com/goplus/lib/py/math)
|
||||
* [py/json](https://pkg.go.dev/github.com/goplus/lib/py/json)
|
||||
* [py/inspect](https://pkg.go.dev/github.com/goplus/lib/py/inspect)
|
||||
* [py/statistics](https://pkg.go.dev/github.com/goplus/lib/py/statistics)
|
||||
* [py/numpy](https://pkg.go.dev/github.com/goplus/lib/py/numpy)
|
||||
* [py/pandas](https://pkg.go.dev/github.com/goplus/lib/py/pandas)
|
||||
* [py/torch](https://pkg.go.dev/github.com/goplus/lib/py/torch)
|
||||
* [py/matplotlib](https://pkg.go.dev/github.com/goplus/lib/py/matplotlib)
|
||||
|
||||
Note: For third-party libraries (such as pandas and pytorch), you still need to install the library files.
|
||||
|
||||
@@ -149,9 +149,9 @@ Here is an example:
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/py"
|
||||
"github.com/goplus/llgo/py/math"
|
||||
"github.com/goplus/llgo/py/std"
|
||||
"github.com/goplus/lib/py"
|
||||
"github.com/goplus/lib/py/math"
|
||||
"github.com/goplus/lib/py/std"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -181,9 +181,9 @@ Let's look at a slightly more complex example. For example, we use `numpy` to ca
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/py"
|
||||
"github.com/goplus/llgo/py/numpy"
|
||||
"github.com/goplus/llgo/py/std"
|
||||
"github.com/goplus/lib/py"
|
||||
"github.com/goplus/lib/py/numpy"
|
||||
"github.com/goplus/lib/py/std"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -225,27 +225,27 @@ LLGo can easily import any libraries from the C ecosystem. Currently, this impor
|
||||
|
||||
The currently supported libraries include:
|
||||
|
||||
* [c/bdwgc](https://pkg.go.dev/github.com/goplus/llgo/c/bdwgc)
|
||||
* [c/cjson](https://pkg.go.dev/github.com/goplus/llgo/c/cjson)
|
||||
* [c/clang](https://pkg.go.dev/github.com/goplus/llgo/c/clang)
|
||||
* [c/ffi](https://pkg.go.dev/github.com/goplus/llgo/c/ffi)
|
||||
* [c/libuv](https://pkg.go.dev/github.com/goplus/llgo/c/libuv)
|
||||
* [c/llama2](https://pkg.go.dev/github.com/goplus/llgo/c/llama2)
|
||||
* [c/lua](https://pkg.go.dev/github.com/goplus/llgo/c/lua)
|
||||
* [c/neco](https://pkg.go.dev/github.com/goplus/llgo/c/neco)
|
||||
* [c/openssl](https://pkg.go.dev/github.com/goplus/llgo/c/openssl)
|
||||
* [c/raylib](https://pkg.go.dev/github.com/goplus/llgo/c/raylib)
|
||||
* [c/sqlite](https://pkg.go.dev/github.com/goplus/llgo/c/sqlite)
|
||||
* [c/zlib](https://pkg.go.dev/github.com/goplus/llgo/c/zlib)
|
||||
* [cpp/inih](https://pkg.go.dev/github.com/goplus/llgo/cpp/inih)
|
||||
* [cpp/llvm](https://pkg.go.dev/github.com/goplus/llgo/cpp/llvm)
|
||||
* [c/bdwgc](https://pkg.go.dev/github.com/goplus/lib/c/bdwgc)
|
||||
* [c/cjson](https://pkg.go.dev/github.com/goplus/lib/c/cjson)
|
||||
* [c/clang](https://pkg.go.dev/github.com/goplus/lib/c/clang)
|
||||
* [c/ffi](https://pkg.go.dev/github.com/goplus/lib/c/ffi)
|
||||
* [c/libuv](https://pkg.go.dev/github.com/goplus/lib/c/libuv)
|
||||
* [c/llama2](https://pkg.go.dev/github.com/goplus/lib/c/llama2)
|
||||
* [c/lua](https://pkg.go.dev/github.com/goplus/lib/c/lua)
|
||||
* [c/neco](https://pkg.go.dev/github.com/goplus/lib/c/neco)
|
||||
* [c/openssl](https://pkg.go.dev/github.com/goplus/lib/c/openssl)
|
||||
* [c/raylib](https://pkg.go.dev/github.com/goplus/lib/c/raylib)
|
||||
* [c/sqlite](https://pkg.go.dev/github.com/goplus/lib/c/sqlite)
|
||||
* [c/zlib](https://pkg.go.dev/github.com/goplus/lib/c/zlib)
|
||||
* [cpp/inih](https://pkg.go.dev/github.com/goplus/lib/cpp/inih)
|
||||
* [cpp/llvm](https://pkg.go.dev/github.com/goplus/lib/cpp/llvm)
|
||||
|
||||
Here are some examples related to them:
|
||||
|
||||
* [llama2-c](_demo/llama2-c): inference Llama 2 (It's the first llgo AI example)
|
||||
* [mkjson](c/cjson/_demo/mkjson/mkjson.go): create a json object and print it
|
||||
* [sqlitedemo](c/sqlite/_demo/sqlitedemo/demo.go): a basic sqlite demo
|
||||
* [tetris](c/raylib/_demo/tetris/tetris.go): a tetris game based on raylib
|
||||
* [mkjson](https://github.com/goplus/lib/tree/main/c/cjson/_demo/mkjson/mkjson.go): create a json object and print it
|
||||
* [sqlitedemo](https://github.com/goplus/lib/tree/main/c/sqlite/_demo/sqlitedemo/demo.go): a basic sqlite demo
|
||||
* [tetris](https://github.com/goplus/lib/tree/main/c/raylib/_demo/tetris/tetris.go): a tetris game based on raylib
|
||||
|
||||
|
||||
## Go syntax support
|
||||
@@ -335,11 +335,12 @@ Here are the Go packages that can be imported correctly:
|
||||
* [regexp/syntax](https://pkg.go.dev/regexp/syntax)
|
||||
* [go/token](https://pkg.go.dev/go/token)
|
||||
* [go/scanner](https://pkg.go.dev/go/scanner)
|
||||
* [go/parser](https://pkg.go.dev/go/parser)
|
||||
|
||||
|
||||
## Dependencies
|
||||
|
||||
- [Go 1.20+](https://go.dev)
|
||||
- [Go 1.21+](https://go.dev)
|
||||
- [LLVM 18](https://llvm.org)
|
||||
- [Clang 18](https://clang.llvm.org)
|
||||
- [LLD 18](https://lld.llvm.org)
|
||||
@@ -347,7 +348,7 @@ Here are the Go packages that can be imported correctly:
|
||||
- [bdwgc/libgc 8.0+](https://www.hboehm.info/gc/)
|
||||
- [OpenSSL 3.0+](https://www.openssl.org/)
|
||||
- [zlib 1.2+](https://www.zlib.net)
|
||||
- [Python 3.12+](https://www.python.org) (optional, for [github.com/goplus/llgo/py](https://pkg.go.dev/github.com/goplus/llgo/py))
|
||||
- [Python 3.12+](https://www.python.org) (optional, for [github.com/goplus/lib/py](https://pkg.go.dev/github.com/goplus/lib/py))
|
||||
|
||||
## How to install
|
||||
|
||||
@@ -359,11 +360,11 @@ Follow these steps to generate the `llgo` command (its usage is the same as the
|
||||
|
||||
```sh
|
||||
brew update
|
||||
brew install llvm@18 bdw-gc openssl cjson libffi libuv pkg-config
|
||||
brew install llvm@19 lld@19 bdw-gc openssl cjson libffi libuv pkg-config
|
||||
brew install python@3.12 # optional
|
||||
brew link --force libffi
|
||||
curl https://raw.githubusercontent.com/goplus/llgo/refs/heads/main/install.sh | bash
|
||||
|
||||
brew link --overwrite llvm@19 lld@19 libffi
|
||||
# curl https://raw.githubusercontent.com/goplus/llgo/refs/heads/main/install.sh | bash
|
||||
./install.sh
|
||||
```
|
||||
|
||||
### on Linux
|
||||
@@ -373,12 +374,13 @@ curl https://raw.githubusercontent.com/goplus/llgo/refs/heads/main/install.sh |
|
||||
<!-- embedme doc/_readme/scripts/install_ubuntu.sh#L2-L1000 -->
|
||||
|
||||
```sh
|
||||
echo "deb http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs)-18 main" | sudo tee /etc/apt/sources.list.d/llvm.list
|
||||
echo "deb http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs)-19 main" | sudo tee /etc/apt/sources.list.d/llvm.list
|
||||
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y llvm-18-dev clang-18 libclang-18-dev lld-18 pkg-config libgc-dev libssl-dev zlib1g-dev libcjson-dev libsqlite3-dev libunwind-dev libuv1-dev
|
||||
sudo apt-get install -y llvm-19-dev clang-19 libclang-19-dev lld-19 pkg-config libgc-dev libssl-dev zlib1g-dev libcjson-dev libsqlite3-dev libunwind-dev libuv1-dev
|
||||
sudo apt-get install -y python3.12-dev # optional
|
||||
curl https://raw.githubusercontent.com/goplus/llgo/refs/heads/main/install.sh | bash
|
||||
#curl https://raw.githubusercontent.com/goplus/llgo/refs/heads/main/install.sh | bash
|
||||
./install.sh
|
||||
```
|
||||
|
||||
#### Alpine Linux
|
||||
@@ -412,9 +414,9 @@ cd llgo
|
||||
|
||||
* [pydump](_xtool/pydump): It's the first program compiled by `llgo` (NOT `go`) in a production environment. It outputs symbol information (functions, variables, and constants) from a Python library in JSON format, preparing for the generation of corresponding packages in `llgo`.
|
||||
* [pysigfetch](https://github.com/goplus/hdq/tree/main/chore/pysigfetch): It generates symbol information by extracting information from Python's documentation site. This tool is not part of the `llgo` project, but we depend on it.
|
||||
* [llpyg](compiler/chore/llpyg): It is used to automatically convert Python libraries into Go packages that `llgo` can import. It depends on `pydump` and `pysigfetch` to accomplish the task.
|
||||
* [llgen](compiler/chore/llgen): It is used to compile Go packages into LLVM IR files (*.ll).
|
||||
* [ssadump](compiler/chore/ssadump): It is a Go SSA builder and interpreter.
|
||||
* [llpyg](chore/llpyg): It is used to automatically convert Python libraries into Go packages that `llgo` can import. It depends on `pydump` and `pysigfetch` to accomplish the task.
|
||||
* [llgen](chore/llgen): It is used to compile Go packages into LLVM IR files (*.ll).
|
||||
* [ssadump](chore/ssadump): It is a Go SSA builder and interpreter.
|
||||
|
||||
How do I generate these tools?
|
||||
|
||||
@@ -422,19 +424,20 @@ How do I generate these tools?
|
||||
|
||||
```sh
|
||||
git clone https://github.com/goplus/llgo.git
|
||||
cd llgo/compiler
|
||||
cd llgo
|
||||
go install -v ./cmd/...
|
||||
go install -v ./chore/... # compile all tools except pydump
|
||||
export LLGO_ROOT=$PWD/..
|
||||
cd ../_xtool
|
||||
export LLGO_ROOT=$PWD
|
||||
cd _xtool
|
||||
llgo install ./... # compile pydump
|
||||
go install github.com/goplus/hdq/chore/pysigfetch@v0.8.1 # compile pysigfetch
|
||||
|
||||
```
|
||||
|
||||
## Key modules
|
||||
|
||||
Below are the key modules for understanding the implementation principles of `llgo`:
|
||||
|
||||
* [ssa](https://pkg.go.dev/github.com/goplus/llgo/compiler/ssa): It generates LLVM IR files (LLVM SSA) using the semantics (interfaces) of Go SSA. Although `LLVM SSA` and `Go SSA` are both IR languages, they work at completely different levels. `LLVM SSA` is closer to machine code, which abstracts different instruction sets. While `Go SSA` is closer to a high-level language. We can think of it as the instruction set of the `Go computer`. `llgo/ssa` is not just limited to the `llgo` compiler. If we view it as the high-level expressive power of `LLVM`, you'll find it very useful. Prior to `llgo/ssa`, you had to operate `LLVM` using machine code semantics. But now, with the advanced SSA form (in the semantics of Go SSA), you can conveniently utilize `LLVM`.
|
||||
* [cl](https://pkg.go.dev/github.com/goplus/llgo/compiler/cl): It is the core of the llgo compiler. It converts a Go package into LLVM IR files. It depends on `llgo/ssa`.
|
||||
* [internal/build](https://pkg.go.dev/github.com/goplus/llgo/compiler/internal/build): It strings together the entire compilation process of `llgo`. It depends on `llgo/ssa` and `llgo/cl`.
|
||||
* [ssa](https://pkg.go.dev/github.com/goplus/llgo/ssa): It generates LLVM IR files (LLVM SSA) using the semantics (interfaces) of Go SSA. Although `LLVM SSA` and `Go SSA` are both IR languages, they work at completely different levels. `LLVM SSA` is closer to machine code, which abstracts different instruction sets. While `Go SSA` is closer to a high-level language. We can think of it as the instruction set of the `Go computer`. `llgo/ssa` is not just limited to the `llgo` compiler. If we view it as the high-level expressive power of `LLVM`, you'll find it very useful. Prior to `llgo/ssa`, you had to operate `LLVM` using machine code semantics. But now, with the advanced SSA form (in the semantics of Go SSA), you can conveniently utilize `LLVM`.
|
||||
* [cl](https://pkg.go.dev/github.com/goplus/llgo/cl): It is the core of the llgo compiler. It converts a Go package into LLVM IR files. It depends on `llgo/ssa`.
|
||||
* [internal/build](https://pkg.go.dev/github.com/goplus/llgo/internal/build): It strings together the entire compilation process of `llgo`. It depends on `llgo/ssa` and `llgo/cl`.
|
||||
|
||||
33
_cmptest/_goconstdemo/goconst.go
Normal file
33
_cmptest/_goconstdemo/goconst.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go/constant"
|
||||
"go/token"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Create the complex number 2.3 + 5i.
|
||||
ar := constant.MakeFloat64(2.3)
|
||||
ai := constant.MakeImag(constant.MakeInt64(5))
|
||||
a := constant.BinaryOp(ar, token.ADD, ai)
|
||||
|
||||
// Compute (2.3 + 5i) * 11.
|
||||
b := constant.MakeUint64(11)
|
||||
c := constant.BinaryOp(a, token.MUL, b)
|
||||
|
||||
// Convert c into a complex128.
|
||||
Ar, exact := constant.Float64Val(constant.Real(c))
|
||||
if !exact {
|
||||
fmt.Printf("Could not represent real part %s exactly as float64\n", constant.Real(c))
|
||||
}
|
||||
Ai, exact := constant.Float64Val(constant.Imag(c))
|
||||
if !exact {
|
||||
fmt.Printf("Could not represent imaginary part %s as exactly as float64\n", constant.Imag(c))
|
||||
}
|
||||
C := complex(Ar, Ai)
|
||||
|
||||
fmt.Println("literal", 25.3+55i)
|
||||
fmt.Println("go/constant", c)
|
||||
fmt.Println("complex128", C)
|
||||
}
|
||||
25
_cmptest/mathbigdemo/big.go
Normal file
25
_cmptest/mathbigdemo/big.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Initialize two big ints with the first two numbers in the sequence.
|
||||
a := big.NewInt(0)
|
||||
b := big.NewInt(1)
|
||||
|
||||
// Initialize limit as 10^99, the smallest integer with 100 digits.
|
||||
var limit big.Int
|
||||
limit.Exp(big.NewInt(10), big.NewInt(99), nil)
|
||||
|
||||
// Loop while a is smaller than 1e100.
|
||||
for a.Cmp(&limit) < 0 {
|
||||
// Compute the next Fibonacci number, storing it in a.
|
||||
a.Add(a, b)
|
||||
// Swap a and b so that b is the next number in the sequence.
|
||||
a, b = b, a
|
||||
}
|
||||
fmt.Println(a) // 100-digit Fibonacci number
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c/sync/atomic"
|
||||
"github.com/goplus/lib/c/sync/atomic"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/os"
|
||||
"github.com/goplus/lib/c"
|
||||
"github.com/goplus/lib/c/os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/lib/c"
|
||||
)
|
||||
|
||||
func concat(args ...string) (ret string) {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/lib/c"
|
||||
"github.com/goplus/lib/c/math"
|
||||
"github.com/goplus/llgo/_demo/cppintf/foo"
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/math"
|
||||
)
|
||||
|
||||
type Bar struct {
|
||||
|
||||
@@ -3,9 +3,9 @@ package main
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/goplus/lib/c"
|
||||
"github.com/goplus/lib/c/math"
|
||||
"github.com/goplus/llgo/_demo/cppmintf/foo"
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/math"
|
||||
)
|
||||
|
||||
type Bar struct {
|
||||
|
||||
@@ -3,9 +3,9 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/math/rand"
|
||||
"github.com/goplus/llgo/c/time"
|
||||
"github.com/goplus/lib/c"
|
||||
"github.com/goplus/lib/c/math/rand"
|
||||
"github.com/goplus/lib/c/time"
|
||||
)
|
||||
|
||||
func fastrand64() uint64 {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package main
|
||||
|
||||
import "github.com/goplus/llgo/c/time"
|
||||
import "github.com/goplus/lib/c/time"
|
||||
|
||||
func main() {
|
||||
var tv time.Timespec
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/os"
|
||||
"unsafe"
|
||||
|
||||
"github.com/goplus/lib/c"
|
||||
"github.com/goplus/lib/c/os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -45,8 +46,6 @@ func main() {
|
||||
}
|
||||
c.Printf(c.Str("set file status successfully\n"))
|
||||
|
||||
|
||||
|
||||
c.Printf(c.Str("111"))
|
||||
// Close file
|
||||
os.Close(fd)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/lib/c"
|
||||
)
|
||||
|
||||
type generator struct {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/os"
|
||||
"github.com/goplus/lib/c"
|
||||
"github.com/goplus/lib/c/os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
5
_demo/go.mod
Normal file
5
_demo/go.mod
Normal file
@@ -0,0 +1,5 @@
|
||||
module github.com/goplus/llgo/_demo
|
||||
|
||||
go 1.20
|
||||
|
||||
require github.com/goplus/lib v0.2.0
|
||||
2
_demo/go.sum
Normal file
2
_demo/go.sum
Normal file
@@ -0,0 +1,2 @@
|
||||
github.com/goplus/lib v0.2.0 h1:AjqkN1XK5H23wZMMlpaUYAMCDAdSBQ2NMFrLtSh7W4g=
|
||||
github.com/goplus/lib v0.2.0/go.mod h1:SgJv3oPqLLHCu0gcL46ejOP3x7/2ry2Jtxu7ta32kp0=
|
||||
@@ -3,7 +3,7 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/lib/c"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -11,7 +11,3 @@ func main() {
|
||||
fmt.Println("hello world by fmt.Println")
|
||||
c.Printf(c.Str("Hello world by c.Printf\n"))
|
||||
}
|
||||
|
||||
/* Expected output:
|
||||
Hello world
|
||||
*/
|
||||
|
||||
15
_demo/helloc/helloc.go
Normal file
15
_demo/helloc/helloc.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/goplus/lib/c"
|
||||
)
|
||||
|
||||
func main() {
|
||||
c.Printf(c.Str("Hello world by c.Printf\n"))
|
||||
c.Printf(c.Str("%ld\n"), unsafe.Sizeof(int(0)))
|
||||
c.Printf(c.Str("%ld\n"), unsafe.Sizeof(uintptr(0)))
|
||||
// var v any = int(0)
|
||||
// c.Printf(c.Str("%ld\n"), unsafe.Sizeof(v))
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/llama2"
|
||||
"github.com/goplus/llgo/c/time"
|
||||
"github.com/goplus/lib/c"
|
||||
"github.com/goplus/lib/c/llama2"
|
||||
"github.com/goplus/lib/c/time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/net"
|
||||
"github.com/goplus/lib/c"
|
||||
"github.com/goplus/lib/c/net"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -3,7 +3,7 @@ package main
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/lib/c"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c/setjmp"
|
||||
"github.com/goplus/lib/c/setjmp"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -3,9 +3,9 @@ package main
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/net"
|
||||
"github.com/goplus/llgo/c/os"
|
||||
"github.com/goplus/lib/c"
|
||||
"github.com/goplus/lib/c/net"
|
||||
"github.com/goplus/lib/c/os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -3,9 +3,9 @@ package main
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/net"
|
||||
"github.com/goplus/llgo/c/os"
|
||||
"github.com/goplus/lib/c"
|
||||
"github.com/goplus/lib/c/net"
|
||||
"github.com/goplus/lib/c/os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"sync"
|
||||
"unsafe"
|
||||
|
||||
llsync "github.com/goplus/llgo/c/pthread/sync"
|
||||
llsync "github.com/goplus/lib/c/pthread/sync"
|
||||
)
|
||||
|
||||
type L struct {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/pthread"
|
||||
"github.com/goplus/lib/c"
|
||||
"github.com/goplus/lib/c/pthread"
|
||||
)
|
||||
|
||||
var key pthread.Key
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
### Build with debug info
|
||||
|
||||
```shell
|
||||
LLGO_DEBUG=1 llgo build -o cl/_testdata/debug/out ./cl/_testdata/debug
|
||||
LLGO_DEBUG_SYMBOLS=1 llgo build -o cl/_testdata/debug/out ./cl/_testdata/debug
|
||||
```
|
||||
|
||||
### Debug with lldb
|
||||
@@ -44,7 +44,7 @@ build_project() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
LLGO_DEBUG=1 llgo build -o "debug.out" . || {
|
||||
LLGO_DEBUG_SYMBOLS=1 llgo build -o "debug.out" . || {
|
||||
local ret=$?
|
||||
cd "$current_dir" || return
|
||||
return $ret
|
||||
@@ -1,9 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/py"
|
||||
"github.com/goplus/llgo/py/math"
|
||||
"github.com/goplus/llgo/py/std"
|
||||
"github.com/goplus/lib/py"
|
||||
"github.com/goplus/lib/py/math"
|
||||
"github.com/goplus/lib/py/std"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
5
_pydemo/go.mod
Normal file
5
_pydemo/go.mod
Normal file
@@ -0,0 +1,5 @@
|
||||
module github.com/goplus/llgo/_pydemo
|
||||
|
||||
go 1.20
|
||||
|
||||
require github.com/goplus/lib v0.2.0
|
||||
2
_pydemo/go.sum
Normal file
2
_pydemo/go.sum
Normal file
@@ -0,0 +1,2 @@
|
||||
github.com/goplus/lib v0.2.0 h1:AjqkN1XK5H23wZMMlpaUYAMCDAdSBQ2NMFrLtSh7W4g=
|
||||
github.com/goplus/lib v0.2.0/go.mod h1:SgJv3oPqLLHCu0gcL46ejOP3x7/2ry2Jtxu7ta32kp0=
|
||||
@@ -1,9 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/py"
|
||||
"github.com/goplus/llgo/py/numpy"
|
||||
"github.com/goplus/llgo/py/std"
|
||||
"github.com/goplus/lib/py"
|
||||
"github.com/goplus/lib/py/numpy"
|
||||
"github.com/goplus/lib/py/std"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/py"
|
||||
"github.com/goplus/llgo/py/std"
|
||||
"github.com/goplus/lib/py"
|
||||
"github.com/goplus/lib/py/std"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/py/math"
|
||||
"github.com/goplus/lib/c"
|
||||
"github.com/goplus/lib/py/math"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/py"
|
||||
"github.com/goplus/llgo/py/std"
|
||||
"github.com/goplus/lib/py"
|
||||
"github.com/goplus/lib/py/std"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/py"
|
||||
"github.com/goplus/llgo/py/statistics"
|
||||
"github.com/goplus/lib/c"
|
||||
"github.com/goplus/lib/py"
|
||||
"github.com/goplus/lib/py/statistics"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/py"
|
||||
"github.com/goplus/llgo/py/std"
|
||||
"github.com/goplus/llgo/py/torch"
|
||||
"github.com/goplus/lib/py"
|
||||
"github.com/goplus/lib/py/std"
|
||||
"github.com/goplus/lib/py/torch"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"strings"
|
||||
"unsafe"
|
||||
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/clang"
|
||||
"github.com/goplus/lib/c"
|
||||
"github.com/goplus/lib/c/clang"
|
||||
)
|
||||
|
||||
type Data struct {
|
||||
|
||||
5
_xtool/go.mod
Normal file
5
_xtool/go.mod
Normal file
@@ -0,0 +1,5 @@
|
||||
module github.com/goplus/llgo/_xtool
|
||||
|
||||
go 1.20
|
||||
|
||||
require github.com/goplus/lib v0.2.0
|
||||
2
_xtool/go.sum
Normal file
2
_xtool/go.sum
Normal file
@@ -0,0 +1,2 @@
|
||||
github.com/goplus/lib v0.2.0 h1:AjqkN1XK5H23wZMMlpaUYAMCDAdSBQ2NMFrLtSh7W4g=
|
||||
github.com/goplus/lib v0.2.0/go.mod h1:SgJv3oPqLLHCu0gcL46ejOP3x7/2ry2Jtxu7ta32kp0=
|
||||
@@ -17,10 +17,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/cjson"
|
||||
"github.com/goplus/llgo/py"
|
||||
"github.com/goplus/llgo/py/inspect"
|
||||
"github.com/goplus/lib/c"
|
||||
"github.com/goplus/lib/c/cjson"
|
||||
"github.com/goplus/lib/py"
|
||||
"github.com/goplus/lib/py/inspect"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/bdwgc"
|
||||
"github.com/goplus/llgo/c/bdwgc/_test/testing"
|
||||
)
|
||||
|
||||
// ------ Test malloc ------
|
||||
|
||||
func TestMalloc(t *testing.T) {
|
||||
pn := (*int)(bdwgc.Malloc(unsafe.Sizeof(int(0))))
|
||||
*pn = 1 << 30
|
||||
c.Printf(c.Str("value: %d, %x, %p, %p\n"), *pn, *pn, pn, &pn)
|
||||
|
||||
pl := (*int64)(bdwgc.Realloc(c.Pointer(pn), unsafe.Sizeof(int64(0))))
|
||||
*pl = 1 << 60
|
||||
c.Printf(c.Str("value: %lld, %llx, %p, %p\n"), *pl, *pl, pl, &pl)
|
||||
|
||||
bdwgc.Free(c.Pointer(pl))
|
||||
}
|
||||
|
||||
// ------ Test finalizer ------
|
||||
|
||||
const (
|
||||
RETURN_VALUE_FREED = 1 << 31
|
||||
)
|
||||
|
||||
var called uint = 0
|
||||
|
||||
func setReturnValueFreed(pobj c.Pointer, clientData c.Pointer) {
|
||||
called |= RETURN_VALUE_FREED
|
||||
c.Printf(c.Str("called: %x\n"), called)
|
||||
}
|
||||
|
||||
func setLoopValueFreed(pobj c.Pointer, clientData c.Pointer) {
|
||||
pmask := (*uint)(clientData)
|
||||
called |= *pmask
|
||||
c.Printf(c.Str("called: %x\n"), called)
|
||||
}
|
||||
|
||||
func isCalled(mask uint) bool {
|
||||
return called&mask != 0
|
||||
}
|
||||
|
||||
func returnValue() *int {
|
||||
pn := bdwgc.Malloc(unsafe.Sizeof(int(0)))
|
||||
bdwgc.RegisterFinalizer(pn, setReturnValueFreed, nil, nil, nil)
|
||||
return (*int)(pn)
|
||||
}
|
||||
|
||||
func callFunc() {
|
||||
pn := returnValue()
|
||||
*pn = 1 << 30
|
||||
c.Printf(c.Str("value: %d, %x, %p, %p\n"), *pn, *pn, pn, &pn)
|
||||
bdwgc.Gcollect()
|
||||
check(!isCalled(RETURN_VALUE_FREED), c.Str("finalizer should not be called"))
|
||||
}
|
||||
|
||||
func loop() {
|
||||
for i := 0; i < 5; i++ {
|
||||
p := bdwgc.Malloc(unsafe.Sizeof(int(0)))
|
||||
pn := (*int)(p)
|
||||
*pn = i
|
||||
c.Printf(c.Str("value: %d, %x, %p, %p\n"), *pn, *pn, pn, &pn)
|
||||
pflag := (*uint)(c.Malloc(unsafe.Sizeof(uint(0))))
|
||||
*pflag = 1 << i
|
||||
bdwgc.RegisterFinalizer(p, setLoopValueFreed, c.Pointer(pflag), nil, nil)
|
||||
bdwgc.Gcollect()
|
||||
check(!isCalled(1<<i), c.Str("finalizer should not be called"))
|
||||
for j := 0; j < i; j++ {
|
||||
check(isCalled(1<<j), c.Str("finalizers of previous objects should be called"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Clear stack to avoid reference
|
||||
func clearStack() {
|
||||
p := c.Alloca(128)
|
||||
c.Memset(p, 0, 128)
|
||||
}
|
||||
|
||||
func check(b bool, msg *c.Char) {
|
||||
if !b {
|
||||
c.Printf(c.Str("check failed: %s\n"), msg)
|
||||
panic("check failed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFinalizer(t *testing.T) {
|
||||
bdwgc.Init()
|
||||
|
||||
callFunc()
|
||||
clearStack()
|
||||
bdwgc.Gcollect()
|
||||
check(isCalled(RETURN_VALUE_FREED), c.Str("finalizer should be called"))
|
||||
|
||||
loop()
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/bdwgc/_test/testing"
|
||||
)
|
||||
|
||||
type TestCase struct {
|
||||
Name string
|
||||
F func(*testing.T)
|
||||
}
|
||||
|
||||
func main() {
|
||||
tests := []TestCase{
|
||||
{"TestMalloc", TestMalloc},
|
||||
{"TestFinalizer", TestFinalizer},
|
||||
}
|
||||
if c.Argc == 1 {
|
||||
for _, test := range tests {
|
||||
c.Printf(c.Str("%s\n"), c.AllocaCStr(test.Name))
|
||||
}
|
||||
return
|
||||
}
|
||||
c.Fprintf(c.Stderr, c.Str("arg: %s\n"), c.Index(c.Argv, 1))
|
||||
idx := int(c.Atoi(c.Index(c.Argv, 1)))
|
||||
if idx < 0 || idx >= len(tests) {
|
||||
c.Printf(c.Str("invalid test index %d"), idx)
|
||||
panic("invalid test index")
|
||||
}
|
||||
tests[idx].F(nil)
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package testing
|
||||
|
||||
type T struct {
|
||||
}
|
||||
103
c/bdwgc/bdwgc.go
103
c/bdwgc/bdwgc.go
@@ -1,103 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package bdwgc
|
||||
|
||||
import (
|
||||
_ "unsafe"
|
||||
|
||||
"github.com/goplus/llgo/c"
|
||||
)
|
||||
|
||||
const (
|
||||
LLGoPackage = "link: $(pkg-config --libs bdw-gc); -lgc"
|
||||
)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Init C.GC_init
|
||||
func Init()
|
||||
|
||||
//go:linkname Malloc C.GC_malloc
|
||||
func Malloc(size uintptr) c.Pointer
|
||||
|
||||
//go:linkname Realloc C.GC_realloc
|
||||
func Realloc(ptr c.Pointer, size uintptr) c.Pointer
|
||||
|
||||
//go:linkname Free C.GC_free
|
||||
func Free(ptr c.Pointer)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname RegisterFinalizer C.GC_register_finalizer
|
||||
func RegisterFinalizer(
|
||||
obj c.Pointer,
|
||||
fn func(c.Pointer, c.Pointer), cd c.Pointer,
|
||||
oldFn *func(c.Pointer, c.Pointer), oldCd *c.Pointer)
|
||||
|
||||
//go:linkname RegisterFinalizerNoOrder C.GC_register_finalizer_no_order
|
||||
func RegisterFinalizerNoOrder(
|
||||
obj c.Pointer,
|
||||
fn func(c.Pointer, c.Pointer), cd c.Pointer,
|
||||
oldFn *func(c.Pointer, c.Pointer), oldCd *c.Pointer)
|
||||
|
||||
//go:linkname RegisterFinalizerIgnoreSelf C.GC_register_finalizer_ignore_self
|
||||
func RegisterFinalizerIgnoreSelf(
|
||||
obj c.Pointer,
|
||||
fn func(c.Pointer, c.Pointer), cd c.Pointer,
|
||||
oldFn *func(c.Pointer, c.Pointer), oldCd *c.Pointer)
|
||||
|
||||
//go:linkname RegisterFinalizerUnreachable C.GC_register_finalizer_unreachable
|
||||
func RegisterFinalizerUnreachable(
|
||||
obj c.Pointer,
|
||||
fn func(c.Pointer, c.Pointer), cd c.Pointer,
|
||||
oldFn *func(c.Pointer, c.Pointer), oldCd *c.Pointer)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Enable C.GC_enable
|
||||
func Enable()
|
||||
|
||||
//go:linkname Disable C.GC_disable
|
||||
func Disable()
|
||||
|
||||
//go:linkname IsDisabled C.GC_is_disabled
|
||||
func IsDisabled() c.Int
|
||||
|
||||
//go:linkname Gcollect C.GC_gcollect
|
||||
func Gcollect()
|
||||
|
||||
//go:linkname GetMemoryUse C.GC_get_memory_use
|
||||
func GetMemoryUse() uintptr
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname EnableIncremental C.GC_enable_incremental
|
||||
func EnableIncremental()
|
||||
|
||||
//go:linkname IsIncrementalMode C.GC_is_incremental_mode
|
||||
func IsIncrementalMode() c.Int
|
||||
|
||||
//go:linkname IncrementalProtectionNeeds C.GC_incremental_protection_needs
|
||||
func IncrementalProtectionNeeds() c.Int
|
||||
|
||||
//go:linkname StartIncrementalCollection C.GC_start_incremental_collection
|
||||
func StartIncrementalCollection()
|
||||
|
||||
//go:linkname CollectALittle C.GC_collect_a_little
|
||||
func CollectALittle()
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -1,29 +0,0 @@
|
||||
typedef union {
|
||||
double d;
|
||||
float f;
|
||||
long v;
|
||||
} castUnion;
|
||||
|
||||
double llgoToFloat64(long v) {
|
||||
castUnion k;
|
||||
k.v = v;
|
||||
return k.d;
|
||||
}
|
||||
|
||||
float llgoToFloat32(long v) {
|
||||
castUnion k;
|
||||
k.v = v;
|
||||
return k.f;
|
||||
}
|
||||
|
||||
long llgoFromFloat64(double v) {
|
||||
castUnion k;
|
||||
k.d = v;
|
||||
return k.v;
|
||||
}
|
||||
|
||||
long llgoFromFloat32(float v) {
|
||||
castUnion k;
|
||||
k.f = v;
|
||||
return k.v;
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package bitcast
|
||||
|
||||
import _ "unsafe"
|
||||
|
||||
const (
|
||||
LLGoFiles = "_cast/cast.c"
|
||||
LLGoPackage = "link"
|
||||
)
|
||||
|
||||
//go:linkname ToFloat64 C.llgoToFloat64
|
||||
func ToFloat64(v uintptr) float64
|
||||
|
||||
//go:linkname ToFloat32 C.llgoToFloat32
|
||||
func ToFloat32(v uintptr) float32
|
||||
|
||||
//go:linkname FromFloat64 C.llgoFromFloat64
|
||||
func FromFloat64(v float64) uintptr
|
||||
|
||||
//go:linkname FromFloat32 C.llgoFromFloat32
|
||||
func FromFloat32(v float32) uintptr
|
||||
313
c/c.go
313
c/c.go
@@ -1,313 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package c
|
||||
|
||||
// typedef unsigned int uint;
|
||||
// typedef unsigned long ulong;
|
||||
// typedef unsigned long long ulonglong;
|
||||
// typedef long long longlong;
|
||||
import "C"
|
||||
import "unsafe"
|
||||
|
||||
const (
|
||||
LLGoPackage = "decl"
|
||||
)
|
||||
|
||||
type (
|
||||
Void = [0]byte
|
||||
Char = int8
|
||||
Float = float32
|
||||
Double = float64
|
||||
Pointer = unsafe.Pointer
|
||||
FilePtr = *FILE
|
||||
)
|
||||
|
||||
type FILE struct {
|
||||
Unused [8]byte
|
||||
}
|
||||
|
||||
type (
|
||||
Int C.int
|
||||
Uint C.uint
|
||||
|
||||
Long C.long
|
||||
Ulong C.ulong
|
||||
|
||||
LongLong C.longlong
|
||||
UlongLong C.ulonglong
|
||||
)
|
||||
|
||||
type integer interface {
|
||||
~int | ~uint | ~uintptr | ~int32 | ~uint32 | ~int64 | ~uint64
|
||||
}
|
||||
|
||||
type SizeT = uintptr
|
||||
type SsizeT = Long
|
||||
|
||||
type IntptrT = uintptr
|
||||
type UintptrT = uintptr
|
||||
type Int8T = int8
|
||||
type Int16T = int16
|
||||
type Int32T = int32
|
||||
type Int64T = int64
|
||||
|
||||
type Uint8T = uint8
|
||||
type Uint16T = uint16
|
||||
type Uint32T = uint32
|
||||
type Uint64T = uint64
|
||||
|
||||
type IntmaxT = LongLong
|
||||
type UintmaxT = UlongLong
|
||||
|
||||
type VaList = Pointer
|
||||
|
||||
//go:linkname Str llgo.cstr
|
||||
func Str(string) *Char
|
||||
|
||||
//go:linkname Func llgo.funcAddr
|
||||
func Func(any) Pointer
|
||||
|
||||
// llgo:link Advance llgo.advance
|
||||
func Advance[PtrT any, I integer](ptr PtrT, offset I) PtrT { return ptr }
|
||||
|
||||
// llgo:link Index llgo.index
|
||||
func Index[T any, I integer](ptr *T, offset I) T { return *ptr }
|
||||
|
||||
//go:linkname Alloca llgo.alloca
|
||||
func Alloca(size uintptr) Pointer
|
||||
|
||||
//go:linkname AllocaCStr llgo.allocaCStr
|
||||
func AllocaCStr(s string) *Char
|
||||
|
||||
//go:linkname AllocaCStrs llgo.allocaCStrs
|
||||
func AllocaCStrs(strs []string, endWithNil bool) **Char
|
||||
|
||||
// TODO(xsw):
|
||||
// llgo:link AllocaNew llgo.allocaNew
|
||||
func AllocaNew[T any]() *T { return nil }
|
||||
|
||||
//go:linkname Malloc C.malloc
|
||||
func Malloc(size uintptr) Pointer
|
||||
|
||||
//go:linkname Calloc C.calloc
|
||||
func Calloc(num uintptr, size uintptr) Pointer
|
||||
|
||||
//go:linkname Free C.free
|
||||
func Free(ptr Pointer)
|
||||
|
||||
//go:linkname Realloc C.realloc
|
||||
func Realloc(ptr Pointer, size uintptr) Pointer
|
||||
|
||||
//go:linkname Memcpy C.memcpy
|
||||
func Memcpy(dst, src Pointer, n uintptr) Pointer
|
||||
|
||||
//go:linkname Memmove C.memmove
|
||||
func Memmove(dst, src Pointer, n uintptr) Pointer
|
||||
|
||||
//go:linkname Memset C.memset
|
||||
func Memset(s Pointer, c Int, n uintptr) Pointer
|
||||
|
||||
//go:linkname Memchr C.memchr
|
||||
func Memchr(s Pointer, c Int, n uintptr) Pointer
|
||||
|
||||
//go:linkname Memcmp C.memcmp
|
||||
func Memcmp(s1, s2 Pointer, n uintptr) Int
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Strlen C.strlen
|
||||
func Strlen(s *Char) uintptr
|
||||
|
||||
//go:linkname Strcpy C.strcpy
|
||||
func Strcpy(dst, src *Char) *Char
|
||||
|
||||
//go:linkname Strncpy C.strncpy
|
||||
func Strncpy(dst, src *Char, n uintptr) *Char
|
||||
|
||||
//go:linkname Strcat C.strcat
|
||||
func Strcat(dst, src *Char) *Char
|
||||
|
||||
//go:linkname Strncat C.strncat
|
||||
func Strncat(dst, src *Char, n uintptr) *Char
|
||||
|
||||
//go:linkname Strcmp C.strcmp
|
||||
func Strcmp(s1, s2 *Char) Int
|
||||
|
||||
//go:linkname Strncmp C.strncmp
|
||||
func Strncmp(s1, s2 *Char, n uintptr) Int
|
||||
|
||||
//go:linkname Strchr C.strchr
|
||||
func Strchr(s *Char, c Int) *Char
|
||||
|
||||
//go:linkname Strrchr C.strrchr
|
||||
func Strrchr(s *Char, c Int) *Char
|
||||
|
||||
//go:linkname Strstr C.strstr
|
||||
func Strstr(s1, s2 *Char) *Char
|
||||
|
||||
//go:linkname Strdup C.strdup
|
||||
func Strdup(s *Char) *Char
|
||||
|
||||
//go:linkname Strndup C.strndup
|
||||
func Strndup(s *Char, n uintptr) *Char
|
||||
|
||||
//go:linkname Strtok C.strtok
|
||||
func Strtok(s, delim *Char) *Char
|
||||
|
||||
//go:linkname Strerror C.strerror
|
||||
func Strerror(errnum Int) *Char
|
||||
|
||||
//go:linkname Sprintf C.sprintf
|
||||
func Sprintf(s *Char, format *Char, __llgo_va_list ...any) Int
|
||||
|
||||
//go:linkname Snprintf C.snprintf
|
||||
func Snprintf(s *Char, n uintptr, format *Char, __llgo_va_list ...any) Int
|
||||
|
||||
//go:linkname Vsnprintf C.vsnprintf
|
||||
func Vsnprintf(s *Char, n uintptr, format *Char, ap Pointer) Int
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// GoString converts a C string to a Go string.
|
||||
// TODO(xsw): any => int
|
||||
//
|
||||
//go:linkname GoString llgo.string
|
||||
func GoString(cstr *Char, __llgo_va_list /* n */ ...any) string
|
||||
|
||||
//go:linkname GoStringData llgo.stringData
|
||||
func GoStringData(string) *Char
|
||||
|
||||
//go:linkname GoDeferData llgo.deferData
|
||||
func GoDeferData() Pointer
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname AllocaSigjmpBuf llgo.sigjmpbuf
|
||||
func AllocaSigjmpBuf() Pointer
|
||||
|
||||
//go:linkname Sigsetjmp llgo.sigsetjmp
|
||||
func Sigsetjmp(jb Pointer, savemask Int) Int
|
||||
|
||||
//go:linkname Siglongjmp llgo.siglongjmp
|
||||
func Siglongjmp(jb Pointer, retval Int)
|
||||
|
||||
//go:linkname Unreachable llgo.unreachable
|
||||
func Unreachable()
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Exit C.exit
|
||||
func Exit(Int)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Rand C.rand
|
||||
func Rand() Int
|
||||
|
||||
//go:linkname Qsort C.qsort
|
||||
func Qsort(base Pointer, count, elem uintptr, compar func(a, b Pointer) Int)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Atoi C.atoi
|
||||
func Atoi(s *Char) Int
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Printf C.printf
|
||||
func Printf(format *Char, __llgo_va_list ...any) Int
|
||||
|
||||
//go:linkname Fprintf C.fprintf
|
||||
func Fprintf(fp FilePtr, format *Char, __llgo_va_list ...any) Int
|
||||
|
||||
//go:linkname Fwrite C.fwrite
|
||||
func Fwrite(data Pointer, size, count uintptr, fp FilePtr) uintptr
|
||||
|
||||
//go:linkname Fputc C.fputc
|
||||
func Fputc(c Int, fp FilePtr) Int
|
||||
|
||||
//go:linkname Fputs C.fputs
|
||||
func Fputs(s *Char, fp FilePtr) Int
|
||||
|
||||
//go:linkname Fread C.fread
|
||||
func Fread(data Pointer, size, count uintptr, fp FilePtr) uintptr
|
||||
|
||||
//go:linkname Fflush C.fflush
|
||||
func Fflush(fp FilePtr) Int
|
||||
|
||||
//go:linkname Fopen C.fopen
|
||||
func Fopen(c *Char, mod *Char) FilePtr
|
||||
|
||||
//go:linkname Fclose C.fclose
|
||||
func Fclose(fp FilePtr) Int
|
||||
|
||||
//go:linkname Perror C.perror
|
||||
func Perror(s *Char)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
type IconvT = Pointer
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
type LocaleT = Pointer
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Usleep C.usleep
|
||||
func Usleep(useconds Uint) Int
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
type Option struct {
|
||||
Name *Char
|
||||
HasArg Int
|
||||
Flag *Int
|
||||
Val Int
|
||||
}
|
||||
|
||||
//go:linkname Argc __llgo_argc
|
||||
var Argc Int
|
||||
|
||||
//go:linkname Argv __llgo_argv
|
||||
var Argv **Char
|
||||
|
||||
//go:linkname Optarg optarg
|
||||
var Optarg *Char
|
||||
|
||||
//go:linkname Optind optind
|
||||
var Optind Int
|
||||
|
||||
//go:linkname Opterr opterr
|
||||
var Opterr Int
|
||||
|
||||
//go:linkname Optopt optopt
|
||||
var Optopt Int
|
||||
|
||||
//go:linkname Getopt C.getopt
|
||||
func Getopt(argc Int, argv **Char, optstring *Char) Int
|
||||
|
||||
//go:linkname GetoptLong C.getopt_long
|
||||
func GetoptLong(argc Int, argv **Char, optstring *Char, longopts *Option, longindex *Int) Int
|
||||
|
||||
//go:linkname GetoptLongOnly C.getopt_long_only
|
||||
func GetoptLongOnly(argc Int, argv **Char, optstring *Char, longopts *Option, longindex *Int) Int
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Sysconf C.sysconf
|
||||
func Sysconf(name Int) Long
|
||||
@@ -1,31 +0,0 @@
|
||||
LLGo wrapper of DaveGamble/cJSON
|
||||
=====
|
||||
|
||||
## How to install
|
||||
|
||||
### on macOS (Homebrew)
|
||||
|
||||
```sh
|
||||
brew install cjson
|
||||
```
|
||||
|
||||
### on Linux (Debian/Ubuntu)
|
||||
|
||||
```sh
|
||||
apt-get install -y libcjson-dev
|
||||
```
|
||||
|
||||
## Demos
|
||||
|
||||
The `_demo` directory contains our demos (it start with `_` to prevent the `go` command from compiling it):
|
||||
|
||||
* [mkjson](_demo/mkjson/mkjson.go): create a json object and print it
|
||||
|
||||
### How to run demos
|
||||
|
||||
To run the demos in directory `_demo`:
|
||||
|
||||
```sh
|
||||
cd <demo-directory> # eg. cd _demo/mkjson
|
||||
llgo run .
|
||||
```
|
||||
@@ -1,43 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/cjson"
|
||||
)
|
||||
|
||||
func main() {
|
||||
mod := cjson.Object()
|
||||
mod.SetItem(c.Str("name"), cjson.String(c.Str("math")))
|
||||
|
||||
syms := cjson.Array()
|
||||
|
||||
fn := cjson.Object()
|
||||
fn.SetItem(c.Str("name"), cjson.String(c.Str("sqrt")))
|
||||
fn.SetItem(c.Str("sig"), cjson.String(c.Str("(x, /)")))
|
||||
syms.AddItem(fn)
|
||||
|
||||
v := cjson.Object()
|
||||
v.SetItem(c.Str("name"), cjson.String(c.Str("pi")))
|
||||
syms.AddItem(v)
|
||||
|
||||
mod.SetItem(c.Str("items"), syms)
|
||||
|
||||
cstr := mod.CStr()
|
||||
str := c.GoString(cstr)
|
||||
c.Printf(c.Str("%s\n"), cstr)
|
||||
cjson.FreeCStr(cstr)
|
||||
|
||||
mod.Delete()
|
||||
|
||||
cjsonLoad(str)
|
||||
}
|
||||
|
||||
func cjsonLoad(str string) {
|
||||
mod := cjson.ParseString(str)
|
||||
|
||||
cstr := mod.Print()
|
||||
c.Printf(c.Str("%s\n"), cstr)
|
||||
cjson.FreeCStr(cstr)
|
||||
|
||||
mod.Delete()
|
||||
}
|
||||
670
c/cjson/cjson.go
670
c/cjson/cjson.go
@@ -1,670 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package cjson
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/goplus/llgo/c"
|
||||
)
|
||||
|
||||
const (
|
||||
LLGoPackage = "link: $(pkg-config --libs libcjson); -lcjson"
|
||||
)
|
||||
|
||||
type Bool c.Int
|
||||
|
||||
// llgo:type C
|
||||
type JSON struct {
|
||||
Unused [0]byte
|
||||
}
|
||||
|
||||
func ParseBytes(value []byte) *JSON {
|
||||
return ParseWithLength((*c.Char)(unsafe.Pointer(unsafe.SliceData(value))), uintptr(len(value)))
|
||||
}
|
||||
|
||||
func ParseString(value string) *JSON {
|
||||
return ParseWithLength((*c.Char)(unsafe.Pointer(unsafe.StringData(value))), uintptr(len(value)))
|
||||
}
|
||||
|
||||
// CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item);
|
||||
//
|
||||
// Render a cJSON entity to text for transfer/storage without any formatting.
|
||||
//
|
||||
// llgo:link (*JSON).CStr C.cJSON_PrintUnformatted
|
||||
func (o *JSON) CStr() *c.Char { return nil }
|
||||
|
||||
// Same as CStr. Provided for Go+.
|
||||
//
|
||||
// llgo:link (*JSON).Cstr C.cJSON_PrintUnformatted
|
||||
func (o *JSON) Cstr() *c.Char { return nil }
|
||||
|
||||
// malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks
|
||||
//
|
||||
//go:linkname FreeCStr C.cJSON_free
|
||||
func FreeCStr(*c.Char)
|
||||
|
||||
// CJSON_PUBLIC(const char*) cJSON_Version(void);
|
||||
//
|
||||
// returns the version of cJSON as a string
|
||||
//
|
||||
//go:linkname Version C.cJSON_Version
|
||||
func Version() *c.Char
|
||||
|
||||
// CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value);
|
||||
//
|
||||
// Memory Management: the caller is always responsible to free
|
||||
// the results from all variants of cJSON_Parse (with cJSON_Delete)
|
||||
// and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or
|
||||
// cJSON_free as appropriate). The exception is cJSON_PrintPreallocated,
|
||||
// where the caller has full responsibility of the buffer.
|
||||
//
|
||||
//go:linkname Parse C.cJSON_Parse
|
||||
func Parse(value *c.Char) *JSON
|
||||
|
||||
// CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length);
|
||||
//
|
||||
// Memory Management: the caller is always responsible to free
|
||||
// the results from all variants of cJSON_Parse (with cJSON_Delete)
|
||||
// and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or
|
||||
// cJSON_free as appropriate). The exception is cJSON_PrintPreallocated,
|
||||
// where the caller has full responsibility of the buffer.
|
||||
//
|
||||
//go:linkname ParseWithLength C.cJSON_ParseWithLength
|
||||
func ParseWithLength(value *c.Char, valueLength uintptr) *JSON
|
||||
|
||||
// CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_Bool require_null_terminated);
|
||||
//
|
||||
// ParseWithOpts allows you to require (and check) that the JSON is null terminated,
|
||||
// and to retrieve the pointer to the final byte parsed.
|
||||
// If you supply a ptr in return_parse_end and parsing fails, then
|
||||
// return_parse_end will contain a pointer to the error so will match
|
||||
// cJSON_GetErrorPtr().
|
||||
//
|
||||
//go:linkname ParseWithOpts C.cJSON_ParseWithOpts
|
||||
func ParseWithOpts(value *c.Char, return_parse_end **c.Char, require_null_terminated Bool) *JSON
|
||||
|
||||
// CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_Bool require_null_terminated);
|
||||
//
|
||||
// ParseWithOpts allows you to require (and check) that the JSON is null terminated,
|
||||
// and to retrieve the pointer to the final byte parsed.
|
||||
// If you supply a ptr in return_parse_end and parsing fails, then
|
||||
// return_parse_end will contain a pointer to the error so will match
|
||||
// cJSON_GetErrorPtr().
|
||||
//
|
||||
//go:linkname ParseWithLengthOpts C.cJSON_ParseWithLengthOpts
|
||||
func ParseWithLengthOpts(value *c.Char, buffer_length uintptr, return_parse_end **c.Char, require_null_terminated Bool) *JSON
|
||||
|
||||
// CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item);
|
||||
// Render a JSON entity to text for transfer/storage.
|
||||
//
|
||||
// llgo:link (*JSON).Print C.cJSON_Print
|
||||
func (o *JSON) Print() *c.Char { return nil }
|
||||
|
||||
// CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item);
|
||||
// Render a JSON entity to text for transfer/storage without any formatting.
|
||||
//
|
||||
// llgo:link (*JSON).PrintUnformatted C.cJSON_PrintUnformatted
|
||||
func (o *JSON) PrintUnformatted() *c.Char { return nil }
|
||||
|
||||
// CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_Bool fmt);
|
||||
//
|
||||
// Render a JSON entity to text using a buffered strategy.
|
||||
// prebuffer is a guess at the final size. guessing well reduces reallocation.
|
||||
// fmt=0 gives unformatted, =1 gives formatted.
|
||||
//
|
||||
// llgo:link (*JSON).PrintBuffered C.cJSON_PrintBuffered
|
||||
func (o *JSON) PrintBuffered(prebuffer c.Int, fmt Bool) *c.Char { return nil }
|
||||
|
||||
// CJSON_PUBLIC(cJSON_Bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_Bool format);
|
||||
//
|
||||
// Render a cJSON entity to text using a buffer already allocated in memory with given
|
||||
// length. Returns 1 on success and 0 on failure.
|
||||
// note that cJSON is not always 100% accurate in estimating how much memory it will use,
|
||||
// so to be safe allocate 5 bytes more than you actually need
|
||||
//
|
||||
// llgo:link (*JSON).PrintPreallocated C.cJSON_PrintPreallocated
|
||||
func (o *JSON) PrintPreallocated(buffer *c.Char, length c.Int, format Bool) Bool {
|
||||
return Bool(0)
|
||||
}
|
||||
|
||||
// CJSON_PUBLIC(void) cJSON_Delete(cJSON *item);
|
||||
// Delete a JSON entity and all subentities.
|
||||
//
|
||||
// llgo:link (*JSON).Delete C.cJSON_Delete
|
||||
func (o *JSON) Delete() {}
|
||||
|
||||
// CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array);
|
||||
//
|
||||
// Returns the number of items in an array (or object).
|
||||
//
|
||||
// llgo:link (*JSON).GetArraySize C.cJSON_GetArraySize
|
||||
func (o *JSON) GetArraySize() c.Int { return 0 }
|
||||
|
||||
// CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index);
|
||||
//
|
||||
// Retrieve item number "index" from array "array". Returns NULL if unsuccessful.
|
||||
//
|
||||
// llgo:link (*JSON).GetArrayItem C.cJSON_GetArrayItem
|
||||
func (o *JSON) GetArrayItem(index c.Int) *JSON { return nil }
|
||||
|
||||
// CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string);
|
||||
//
|
||||
// Get item "string" from object. Case insensitive.
|
||||
//
|
||||
// llgo:link (*JSON).GetObjectItem C.cJSON_GetObjectItem
|
||||
func (o *JSON) GetObjectItem(s *c.Char) *JSON { return nil }
|
||||
|
||||
// CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string);
|
||||
//
|
||||
// Get item "string" from object. Case sensitive.
|
||||
//
|
||||
// llgo:link (*JSON).GetObjectItemCaseSensitive C.cJSON_GetObjectItemCaseSensitive
|
||||
func (o *JSON) GetObjectItemCaseSensitive(key *c.Char) *JSON { return nil }
|
||||
|
||||
// CJSON_PUBLIC(cJSON_Bool) cJSON_HasObjectItem(const cJSON *object, const char *string);
|
||||
//
|
||||
// llgo:link (*JSON).HasObjectItem C.cJSON_HasObjectItem
|
||||
func (o *JSON) HasObjectItem(s *c.Char) Bool { return Bool(0) }
|
||||
|
||||
// CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void);
|
||||
//
|
||||
// For analysing failed parses. This returns a pointer to the parse error.
|
||||
// You'll probably need to look a few chars back to make sense of it.
|
||||
// Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds.
|
||||
//
|
||||
//go:linkname GetErrorPtr C.cJSON_GetErrorPtr
|
||||
func GetErrorPtr() *c.Char
|
||||
|
||||
// CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item);
|
||||
//
|
||||
// Check item type and return its value
|
||||
//
|
||||
// llgo:link (*JSON).GetStringValue C.cJSON_GetStringValue
|
||||
func (o *JSON) GetStringValue() *c.Char { return nil }
|
||||
|
||||
// CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item);
|
||||
//
|
||||
// Check item type and return its value
|
||||
//
|
||||
// llgo:link (*JSON).GetNumberValue C.cJSON_GetNumberValue
|
||||
func (o *JSON) GetNumberValue() c.Double { return 0 }
|
||||
|
||||
// CJSON_PUBLIC(cJSON_Bool) cJSON_IsInvalid(const cJSON * const item);
|
||||
//
|
||||
// These functions check the type of an item
|
||||
//
|
||||
// llgo:link (*JSON).IsInvalid C.cJSON_IsInvalid
|
||||
func (o *JSON) IsInvalid() Bool { return Bool(0) }
|
||||
|
||||
// CJSON_PUBLIC(cJSON_Bool) cJSON_IsFalse(const cJSON * const item);
|
||||
//
|
||||
// These functions check the type of an item
|
||||
//
|
||||
// llgo:link (*JSON).IsFalse C.cJSON_IsFalse
|
||||
func (o *JSON) IsFalse() Bool { return Bool(0) }
|
||||
|
||||
// CJSON_PUBLIC(cJSON_Bool) cJSON_IsTrue(const cJSON * const item);
|
||||
//
|
||||
// These functions check the type of an item
|
||||
//
|
||||
// llgo:link (*JSON).IsTrue C.cJSON_IsTrue
|
||||
func (o *JSON) IsTrue() Bool { return Bool(0) }
|
||||
|
||||
// CJSON_PUBLIC(cJSON_Bool) cJSON_IsBool(const cJSON * const item);
|
||||
//
|
||||
// These functions check the type of an item
|
||||
//
|
||||
// llgo:link (*JSON).IsBool C.cJSON_IsBool
|
||||
func (o *JSON) IsBool() Bool { return Bool(0) }
|
||||
|
||||
// CJSON_PUBLIC(cJSON_Bool) cJSON_IsNull(const cJSON * const item);
|
||||
//
|
||||
// These functions check the type of an item
|
||||
//
|
||||
// llgo:link (*JSON).IsNull C.cJSON_IsNull
|
||||
func (o *JSON) IsNull() Bool { return Bool(0) }
|
||||
|
||||
// CJSON_PUBLIC(cJSON_Bool) cJSON_IsNumber(const cJSON * const item);
|
||||
//
|
||||
// These functions check the type of an item
|
||||
//
|
||||
// llgo:link (*JSON).IsNumber C.cJSON_IsNumber
|
||||
func (o *JSON) IsNumber() Bool { return Bool(0) }
|
||||
|
||||
// CJSON_PUBLIC(cJSON_Bool) cJSON_IsString(const cJSON * const item);
|
||||
//
|
||||
// These functions check the type of an item
|
||||
//
|
||||
// llgo:link (*JSON).IsString C.cJSON_IsString
|
||||
func (o *JSON) IsString() Bool { return Bool(0) }
|
||||
|
||||
// CJSON_PUBLIC(cJSON_Bool) cJSON_IsArray(const cJSON * const item);
|
||||
//
|
||||
// These functions check the type of an item
|
||||
//
|
||||
// llgo:link (*JSON).IsArray C.cJSON_IsArray
|
||||
func (o *JSON) IsArray() Bool { return Bool(0) }
|
||||
|
||||
// CJSON_PUBLIC(cJSON_Bool) cJSON_IsObject(const cJSON * const item);
|
||||
//
|
||||
// These functions check the type of an item
|
||||
//
|
||||
// llgo:link (*JSON).IsObject C.cJSON_IsObject
|
||||
func (o *JSON) IsObject() Bool { return Bool(0) }
|
||||
|
||||
// CJSON_PUBLIC(cJSON_Bool) cJSON_IsRaw(const cJSON * const item);
|
||||
//
|
||||
// These functions check the type of an item
|
||||
//
|
||||
// llgo:link (*JSON).IsRaw C.cJSON_IsRaw
|
||||
func (o *JSON) IsRaw() Bool { return Bool(0) }
|
||||
|
||||
// CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void);
|
||||
//
|
||||
// These calls create a cJSON item of the appropriate type.
|
||||
//
|
||||
//go:linkname Null C.cJSON_CreateNull
|
||||
func Null() *JSON
|
||||
|
||||
// CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void);
|
||||
//
|
||||
// same as Null func
|
||||
//
|
||||
//go:linkname CreateNull C.cJSON_CreateNull
|
||||
func CreateNull() *JSON
|
||||
|
||||
// CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void);
|
||||
//
|
||||
//go:linkname True C.cJSON_CreateTrue
|
||||
func True() *JSON
|
||||
|
||||
// CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void);
|
||||
//
|
||||
// same as True func
|
||||
//
|
||||
//go:linkname CreateTrue C.cJSON_CreateTrue
|
||||
func CreateTrue() *JSON
|
||||
|
||||
// CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void);
|
||||
//
|
||||
//go:linkname False C.cJSON_CreateFalse
|
||||
func False() *JSON
|
||||
|
||||
// CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void);
|
||||
//
|
||||
// same as False func
|
||||
//
|
||||
//go:linkname CreateFalse C.cJSON_CreateFalse
|
||||
func CreateFalse() *JSON
|
||||
|
||||
// CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_Bool boolean);
|
||||
//
|
||||
// same as Bool func
|
||||
//
|
||||
//go:linkname CreateBool C.cJSON_CreateBool
|
||||
func CreateBool(boolean c.Int) *JSON
|
||||
|
||||
// CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num);
|
||||
//
|
||||
//go:linkname Number C.cJSON_CreateNumber
|
||||
func Number(num float64) *JSON
|
||||
|
||||
// CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num);
|
||||
//
|
||||
// same as Number func
|
||||
//
|
||||
//go:linkname CreateNumber C.cJSON_CreateNumber
|
||||
func CreateNumber(num float64) *JSON
|
||||
|
||||
// CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string);
|
||||
//
|
||||
//go:linkname String C.cJSON_CreateString
|
||||
func String(str *c.Char) *JSON
|
||||
|
||||
// CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string);
|
||||
//
|
||||
// same as String func
|
||||
//
|
||||
//go:linkname CreateString C.cJSON_CreateString
|
||||
func CreateString(str *c.Char) *JSON
|
||||
|
||||
// CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw);
|
||||
// raw json
|
||||
//
|
||||
//go:linkname Raw C.cJSON_CreateRaw
|
||||
func Raw(raw *c.Char) *JSON
|
||||
|
||||
// CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw);
|
||||
//
|
||||
// same as Raw func
|
||||
//
|
||||
//go:linkname CreateRaw C.cJSON_CreateRaw
|
||||
func CreateRaw(raw *c.Char) *JSON
|
||||
|
||||
// CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void);
|
||||
//
|
||||
//go:linkname Array C.cJSON_CreateArray
|
||||
func Array() *JSON
|
||||
|
||||
// CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void);
|
||||
//
|
||||
// same as Array func
|
||||
//
|
||||
//go:linkname CreateArray C.cJSON_CreateArray
|
||||
func CreateArray() *JSON
|
||||
|
||||
// CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void);
|
||||
//
|
||||
//go:linkname Object C.cJSON_CreateObject
|
||||
func Object() *JSON
|
||||
|
||||
// CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void);
|
||||
//
|
||||
// same as Object func
|
||||
//
|
||||
//go:linkname CreateObject C.cJSON_CreateObject
|
||||
func CreateObject() *JSON
|
||||
|
||||
// CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string);
|
||||
//
|
||||
// Create a string where valuestring references a string so
|
||||
// it will not be freed by Delete
|
||||
//
|
||||
//go:linkname StringRef C.cJSON_CreateStringReference
|
||||
func StringRef(str *c.Char) *JSON
|
||||
|
||||
// CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string);
|
||||
//
|
||||
// same as StringRef func
|
||||
//
|
||||
//go:linkname CreateStringReference C.cJSON_CreateStringReference
|
||||
func CreateStringReference(str *c.Char) *JSON
|
||||
|
||||
// CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child);
|
||||
//
|
||||
// Create an object that only references it's elements so
|
||||
// they will not be freed by Delete
|
||||
//
|
||||
//go:linkname ObjectRef C.cJSON_CreateObjectReference
|
||||
func ObjectRef(child *JSON) *JSON
|
||||
|
||||
// CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child);
|
||||
//
|
||||
// same as ObjectRef func
|
||||
//
|
||||
//go:linkname CreateObjectReference C.cJSON_CreateObjectReference
|
||||
func CreateObjectReference(child *JSON) *JSON
|
||||
|
||||
// CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child);
|
||||
//
|
||||
// Create an array that only references it's elements so
|
||||
// they will not be freed by Delete
|
||||
//
|
||||
//go:linkname ArrayRef C.cJSON_CreateArrayReference
|
||||
func ArrayRef(child *JSON) *JSON
|
||||
|
||||
// CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child);
|
||||
//
|
||||
// same as ArrayRef func
|
||||
//
|
||||
//go:linkname CreateArrayReference C.cJSON_CreateArrayReference
|
||||
func CreateArrayReference(child *JSON) *JSON
|
||||
|
||||
// CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count);
|
||||
//
|
||||
//go:linkname CreateIntArray C.cJSON_CreateIntArray
|
||||
func CreateIntArray(numbers *c.Int, count c.Int) *JSON
|
||||
|
||||
// CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count);
|
||||
//
|
||||
//go:linkname CreateFloatArray C.cJSON_CreateFloatArray
|
||||
func CreateFloatArray(numbers *c.Float, count c.Int) *JSON
|
||||
|
||||
// CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count);
|
||||
//
|
||||
//go:linkname CreateDoubleArray C.cJSON_CreateDoubleArray
|
||||
func CreateDoubleArray(numbers *c.Double, count c.Int) *JSON
|
||||
|
||||
// CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int count);
|
||||
//
|
||||
//go:linkname CreateStringArray C.cJSON_CreateStringArray
|
||||
func CreateStringArray(strings *c.Char, count c.Int) *JSON
|
||||
|
||||
// CJSON_PUBLIC(cJSON_Bool) cJSON_AddItemToArray(cJSON *array, cJSON *item);
|
||||
//
|
||||
// Append item to the specified array.
|
||||
//
|
||||
// llgo:link (*JSON).AddItem C.cJSON_AddItemToArray
|
||||
func (o *JSON) AddItem(item *JSON) Bool { return Bool(0) }
|
||||
|
||||
// CJSON_PUBLIC(cJSON_Bool) cJSON_AddItemToArray(cJSON *array, cJSON *item);
|
||||
//
|
||||
// same as AddItem func
|
||||
//
|
||||
// llgo:link (*JSON).AddItemToArray C.cJSON_AddItemToArray
|
||||
func (o *JSON) AddItemToArray(item *JSON) Bool { return Bool(0) }
|
||||
|
||||
// CJSON_PUBLIC(cJSON_Bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item);
|
||||
//
|
||||
// Append item to the specified object.
|
||||
//
|
||||
// llgo:link (*JSON).SetItem C.cJSON_AddItemToObject
|
||||
func (o *JSON) SetItem(key *c.Char, item *JSON) Bool { return Bool(0) }
|
||||
|
||||
// CJSON_PUBLIC(cJSON_Bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item);
|
||||
//
|
||||
// same as SetItem func
|
||||
//
|
||||
// llgo:link (*JSON).AddItemToObject C.cJSON_AddItemToObject
|
||||
func (o *JSON) AddItemToObject(key *c.Char, item *JSON) Bool { return Bool(0) }
|
||||
|
||||
// CJSON_PUBLIC(cJSON_Bool) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item);
|
||||
//
|
||||
// Use this when string is definitely const (i.e. a literal, or as good as),
|
||||
// and will definitely survive the cJSON object.
|
||||
// warning that When this function was used, make sure to always check that
|
||||
// (item->type & cJSON_StringIsConst) is zero before writing to `item->string`
|
||||
//
|
||||
// llgo:link (*JSON).AddItemToObjectCS C.cJSON_AddItemToObjectCS
|
||||
func (o *JSON) AddItemToObjectCS(s *c.Char, item *JSON) Bool { return Bool(0) }
|
||||
|
||||
// CJSON_PUBLIC(cJSON_Bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
|
||||
//
|
||||
// Append reference to item to the specified array/object.
|
||||
// Use this when you want to add an existing cJSON to a new cJSON,
|
||||
// but don't want to corrupt your existing cJSON.
|
||||
//
|
||||
// llgo:link (*JSON).AddItemReferenceToArray C.cJSON_AddItemReferenceToArray
|
||||
func (o *JSON) AddItemReferenceToArray(item *JSON) Bool { return Bool(0) }
|
||||
|
||||
// CJSON_PUBLIC(cJSON_Bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item);
|
||||
//
|
||||
// llgo:link (*JSON).AddItemReferenceToObject C.cJSON_AddItemReferenceToObject
|
||||
func (o *JSON) AddItemReferenceToObject(s *c.Char, item *JSON) Bool { return Bool(0) }
|
||||
|
||||
// CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item);
|
||||
//
|
||||
// Remove/Detach items from Arrays/Objects.
|
||||
//
|
||||
// llgo:link (*JSON).DetachItemViaPointer C.cJSON_DetachItemViaPointer
|
||||
func (o *JSON) DetachItemViaPointer(item *JSON) *JSON { return nil }
|
||||
|
||||
// CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which);
|
||||
//
|
||||
// llgo:link (*JSON).DetachItemFromArray C.cJSON_DetachItemFromArray
|
||||
func (o *JSON) DetachItemFromArray(which c.Int) *JSON { return nil }
|
||||
|
||||
// CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which);
|
||||
//
|
||||
// llgo:link (*JSON).DeleteItemFromArray C.cJSON_DeleteItemFromArray
|
||||
func (o *JSON) DeleteItemFromArray(which c.Int) {}
|
||||
|
||||
// CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string);
|
||||
//
|
||||
// llgo:link (*JSON).DetachItemFromObject C.cJSON_DetachItemFromObject
|
||||
func (o *JSON) DetachItemFromObject(s *c.Char) *JSON { return nil }
|
||||
|
||||
// CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string);
|
||||
//
|
||||
// llgo:link (*JSON).DetachItemFromObjectCaseSensitive C.cJSON_DetachItemFromObjectCaseSensitive
|
||||
func (o *JSON) DetachItemFromObjectCaseSensitive(s *c.Char) *JSON { return nil }
|
||||
|
||||
// CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string);
|
||||
//
|
||||
// llgo:link (*JSON).DeleteItemFromObject C.cJSON_DeleteItemFromObject
|
||||
func (o *JSON) DeleteItemFromObject(s *c.Char) {}
|
||||
|
||||
// CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string);
|
||||
//
|
||||
// llgo:link (*JSON).DeleteItemFromObjectCaseSensitive C.cJSON_DeleteItemFromObjectCaseSensitive
|
||||
func (o *JSON) DeleteItemFromObjectCaseSensitive(s *c.Char) {}
|
||||
|
||||
// CJSON_PUBLIC(cJSON_Bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem);
|
||||
//
|
||||
// Update array items.
|
||||
// Shifts pre-existing items to the right.
|
||||
//
|
||||
// llgo:link (*JSON).InsertItemInArray C.cJSON_InsertItemInArray
|
||||
func (o *JSON) InsertItemInArray(which c.Int, newitem *JSON) Bool { return Bool(0) }
|
||||
|
||||
// CJSON_PUBLIC(cJSON_Bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement);
|
||||
//
|
||||
// llgo:link (*JSON).ReplaceItemViaPointer C.cJSON_ReplaceItemViaPointer
|
||||
func (o *JSON) ReplaceItemViaPointer(item *JSON, replacement *JSON) Bool { return Bool(0) }
|
||||
|
||||
// CJSON_PUBLIC(cJSON_Bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem);
|
||||
//
|
||||
// llgo:link (*JSON).ReplaceItemInArray C.cJSON_ReplaceItemInArray
|
||||
func (o *JSON) ReplaceItemInArray(which c.Int, newitem *JSON) Bool { return Bool(0) }
|
||||
|
||||
// CJSON_PUBLIC(cJSON_Bool) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem);
|
||||
//
|
||||
// llgo:link (*JSON).ReplaceItemInObject C.cJSON_ReplaceItemInObject
|
||||
func (o *JSON) ReplaceItemInObject(s *c.Char, newitem *JSON) Bool { return Bool(0) }
|
||||
|
||||
// CJSON_PUBLIC(cJSON_Bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object,const char *string,cJSON *newitem);
|
||||
//
|
||||
// llgo:link (*JSON).ReplaceItemInObjectCaseSensitive C.cJSON_ReplaceItemInObjectCaseSensitive
|
||||
func (o *JSON) ReplaceItemInObjectCaseSensitive(s *c.Char, newitem *JSON) Bool {
|
||||
return Bool(0)
|
||||
}
|
||||
|
||||
// CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_Bool recurse);
|
||||
//
|
||||
// Duplicate a cJSON item
|
||||
//
|
||||
// Duplicate will create a new, identical cJSON item to the one you pass,
|
||||
// in new memory that will need to be released. With recurse!=0,
|
||||
// it will duplicate any children connected to the item.
|
||||
// The item->next and ->prev pointers are always zero on return from Duplicate.
|
||||
//
|
||||
// llgo:link (*JSON).Duplicate C.cJSON_Duplicate
|
||||
func (o *JSON) Duplicate(recurse Bool) *JSON { return nil }
|
||||
|
||||
// CJSON_PUBLIC(cJSON_Bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_Bool case_sensitive);
|
||||
//
|
||||
// Recursively compare two cJSON items for equality. If either a or b is NULL or invalid,
|
||||
// they will be considered unequal. case_sensitive determines if object keys are treated
|
||||
// case sensitive (1) or case insensitive (0)
|
||||
//
|
||||
// llgo:link (*JSON).Compare C.cJSON_Compare
|
||||
func (o *JSON) Compare(b *JSON, case_sensitive Bool) Bool { return Bool(0) }
|
||||
|
||||
// CJSON_PUBLIC(void) cJSON_Minify(char *json);
|
||||
//
|
||||
// Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from strings.
|
||||
// The input pointer json cannot point to a read-only address area, such as a string constant,
|
||||
// but should point to a readable and writable address area.
|
||||
//
|
||||
//go:linkname Minify C.cJSON_Minify
|
||||
func Minify()
|
||||
|
||||
// CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name);
|
||||
//
|
||||
// Helper functions for creating and adding items to an object at the same time.
|
||||
// They return the added item or NULL on failure.
|
||||
//
|
||||
// llgo:link (*JSON).AddNullToObject C.cJSON_AddNullToObject
|
||||
func (o *JSON) AddNullToObject(name *c.Char) *JSON { return nil }
|
||||
|
||||
// CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name);
|
||||
//
|
||||
// llgo:link (*JSON).AddTrueToObject C.cJSON_AddTrueToObject
|
||||
func (o *JSON) AddTrueToObject(name *c.Char) *JSON { return nil }
|
||||
|
||||
// CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name);
|
||||
//
|
||||
// llgo:link (*JSON).AddFalseToObject C.cJSON_AddFalseToObject
|
||||
func (o *JSON) AddFalseToObject(name *c.Char) *JSON { return nil }
|
||||
|
||||
// CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_Bool boolean);
|
||||
//
|
||||
// llgo:link (*JSON).AddBoolToObject C.cJSON_AddBoolToObject
|
||||
func (o *JSON) AddBoolToObject(name *c.Char, b Bool) *JSON { return nil }
|
||||
|
||||
// CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number);
|
||||
//
|
||||
// llgo:link (*JSON).AddNumberToObject C.cJSON_AddNumberToObject
|
||||
func (o *JSON) AddNumberToObject(name *c.Char, num c.Double) *JSON { return nil }
|
||||
|
||||
// CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string);
|
||||
//
|
||||
// llgo:link (*JSON).AddStringToObject C.cJSON_AddStringToObject
|
||||
func (o *JSON) AddStringToObject(name *c.Char, s *c.Char) *JSON { return nil }
|
||||
|
||||
// CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw);
|
||||
//
|
||||
// llgo:link (*JSON).AddRawToObject C.cJSON_AddRawToObject
|
||||
func (o *JSON) AddRawToObject(name *c.Char, raw *c.Char) *JSON { return nil }
|
||||
|
||||
// CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name);
|
||||
//
|
||||
// llgo:link (*JSON).AddObjectToObject C.cJSON_AddObjectToObject
|
||||
func (o *JSON) AddObjectToObject(name *c.Char) *JSON { return nil }
|
||||
|
||||
// CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name);
|
||||
//
|
||||
// llgo:link (*JSON).AddArrayToObject C.cJSON_AddArrayToObject
|
||||
func (o *JSON) AddArrayToObject(name *c.Char) *JSON { return nil }
|
||||
|
||||
// CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number);
|
||||
//
|
||||
// helper for the cJSON_SetNumberValue macro
|
||||
//
|
||||
// llgo:link (*JSON).SetNumberHelper C.cJSON_SetNumberHelper
|
||||
func (o *JSON) SetNumberHelper(number c.Double) c.Double { return 0 }
|
||||
|
||||
// CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring);
|
||||
//
|
||||
// Change the valuestring of a cJSON_String object, only takes effect when type of
|
||||
// object is cJSON_String
|
||||
//
|
||||
// llgo:link (*JSON).SetValuestring C.cJSON_SetValuestring
|
||||
func (o *JSON) SetValuestring(v *c.Char) *c.Char { return nil }
|
||||
|
||||
// CJSON_PUBLIC(void *) cJSON_malloc(size_t size);
|
||||
//
|
||||
// malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks
|
||||
//
|
||||
//go:linkname Malloc C.cJSON_malloc
|
||||
func Malloc(size uintptr)
|
||||
|
||||
// CJSON_PUBLIC(void) cJSON_free(void *object);
|
||||
//
|
||||
//go:linkname Free C.cJSON_free
|
||||
func Free(ptr unsafe.Pointer)
|
||||
@@ -1,35 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/clang"
|
||||
"github.com/goplus/llgo/compiler/chore/_xtool/llcppsymg/clangutils"
|
||||
)
|
||||
|
||||
func main() {
|
||||
_, unit, err := clangutils.CreateTranslationUnit(&clangutils.Config{
|
||||
File: "#include <stddef.h>",
|
||||
Temp: true,
|
||||
IsCpp: false,
|
||||
})
|
||||
if err != nil {
|
||||
println(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
clang.GetInclusions(unit, func(included_file clang.File, inclusion_stack *clang.SourceLocation, include_len c.Uint, client_data c.Pointer) {
|
||||
filename := included_file.FileName()
|
||||
c.Printf(c.Str("Included file: %s Include length: %d\n"), filename.CStr(), include_len)
|
||||
inclusions := unsafe.Slice(inclusion_stack, include_len)
|
||||
for i := range inclusions {
|
||||
loc := inclusions[i]
|
||||
var file clang.File
|
||||
var line, column c.Uint
|
||||
loc.SpellingLocation(&file, &line, &column, nil)
|
||||
filename = file.FileName()
|
||||
c.Printf(c.Str(" included from: %s:%d:%d\n"), filename.CStr(), line, column)
|
||||
}
|
||||
}, nil)
|
||||
}
|
||||
@@ -1,172 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"unsafe"
|
||||
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/clang"
|
||||
)
|
||||
|
||||
type Context struct {
|
||||
namespaceName string
|
||||
className string
|
||||
unit *clang.TranslationUnit
|
||||
}
|
||||
|
||||
func newContext() *Context {
|
||||
return &Context{}
|
||||
}
|
||||
|
||||
func (c *Context) setNamespaceName(name string) {
|
||||
c.namespaceName = name
|
||||
}
|
||||
|
||||
func (c *Context) setClassName(name string) {
|
||||
c.className = name
|
||||
}
|
||||
|
||||
func (c *Context) setUnit(unit *clang.TranslationUnit) {
|
||||
c.unit = unit
|
||||
}
|
||||
|
||||
var context = newContext()
|
||||
|
||||
func printCursorLocation(cursor clang.Cursor) {
|
||||
loc := cursor.Location()
|
||||
var file clang.File
|
||||
var line, column, presumedLine, presumedColumn c.Uint
|
||||
var presumedFilename clang.String
|
||||
|
||||
loc.SpellingLocation(&file, &line, &column, nil)
|
||||
loc.PresumedLocation(&presumedFilename, &presumedLine, &presumedColumn)
|
||||
filename := file.FileName()
|
||||
defer filename.Dispose()
|
||||
|
||||
c.Printf(c.Str("Location: %s:%d:%d\n"), filename.CStr(), line, column)
|
||||
c.Printf(c.Str("Presumed Location: %s:%d:%d\n"), presumedFilename.CStr(), presumedLine, presumedColumn)
|
||||
}
|
||||
|
||||
func printMarcoInfo(cursor clang.Cursor) {
|
||||
printCursorLocation(cursor)
|
||||
name := cursor.String()
|
||||
c.Printf(c.Str("Marco Name: %s\n"), name.CStr())
|
||||
ran := cursor.Extent()
|
||||
var numTokens c.Uint
|
||||
var tokens *clang.Token
|
||||
context.unit.Tokenize(ran, &tokens, &numTokens)
|
||||
c.Printf(c.Str("Content: "))
|
||||
|
||||
tokensSlice := unsafe.Slice(tokens, int(numTokens))
|
||||
for _, tok := range tokensSlice {
|
||||
tokStr := context.unit.Token(tok)
|
||||
c.Printf(c.Str("%s "), tokStr.CStr())
|
||||
tokStr.Dispose()
|
||||
}
|
||||
|
||||
c.Printf(c.Str("\n"))
|
||||
println("--------------------------------")
|
||||
}
|
||||
func printFuncInfo(cursor clang.Cursor) {
|
||||
printCursorLocation(cursor)
|
||||
|
||||
cursorStr := cursor.String()
|
||||
symbol := cursor.Mangling()
|
||||
defer symbol.Dispose()
|
||||
defer cursorStr.Dispose()
|
||||
|
||||
if context.namespaceName != "" && context.className != "" {
|
||||
fmt.Printf("%s:%s:", context.namespaceName, context.className)
|
||||
} else if context.namespaceName != "" {
|
||||
fmt.Printf("%s:", context.namespaceName)
|
||||
}
|
||||
c.Printf(c.Str("%s\n"), cursorStr.CStr())
|
||||
|
||||
if cursor.Kind == clang.CursorCXXMethod || cursor.Kind == clang.CursorFunctionDecl {
|
||||
c.Printf(c.Str("symbol:%s\n"), symbol.CStr())
|
||||
|
||||
typeStr := cursor.ResultType().String()
|
||||
defer typeStr.Dispose()
|
||||
c.Printf(c.Str("Return Type: %s\n"), typeStr.CStr())
|
||||
c.Printf(c.Str("Parameters(%d): ( "), cursor.NumArguments())
|
||||
|
||||
for i := 0; i < int(cursor.NumArguments()); i++ {
|
||||
argCurSor := cursor.Argument(c.Uint(i))
|
||||
argType := argCurSor.Type().String()
|
||||
argName := argCurSor.String()
|
||||
c.Printf(c.Str("%s %s"), argType.CStr(), argName.CStr())
|
||||
if i < int(cursor.NumArguments())-1 {
|
||||
c.Printf(c.Str(", "))
|
||||
}
|
||||
|
||||
argType.Dispose()
|
||||
argName.Dispose()
|
||||
}
|
||||
|
||||
c.Printf(c.Str(" )\n"))
|
||||
println("--------------------------------")
|
||||
}
|
||||
}
|
||||
|
||||
func visit(cursor, parent clang.Cursor, clientData c.Pointer) clang.ChildVisitResult {
|
||||
switch cursor.Kind {
|
||||
case clang.CursorMacroDefinition:
|
||||
printMarcoInfo(cursor)
|
||||
case clang.CursorNamespace:
|
||||
nameStr := cursor.String()
|
||||
context.setNamespaceName(c.GoString(nameStr.CStr()))
|
||||
clang.VisitChildren(cursor, visit, nil)
|
||||
context.setNamespaceName("")
|
||||
case clang.CursorClassDecl:
|
||||
nameStr := cursor.String()
|
||||
context.setClassName(c.GoString(nameStr.CStr()))
|
||||
clang.VisitChildren(cursor, visit, nil)
|
||||
context.setClassName("")
|
||||
case clang.CursorCXXMethod, clang.CursorFunctionDecl:
|
||||
printFuncInfo(cursor)
|
||||
case clang.CursorEnumDecl, clang.CursorStructDecl, clang.CursorUnionDecl, clang.CursorTypedefDecl:
|
||||
nameStr := cursor.String()
|
||||
printCursorLocation(cursor)
|
||||
c.Printf(c.Str("Name: %s\n"), nameStr.CStr())
|
||||
println("--------------------------------")
|
||||
}
|
||||
|
||||
return clang.ChildVisit_Continue
|
||||
}
|
||||
|
||||
func parse(filename *c.Char) {
|
||||
index := clang.CreateIndex(0, 0)
|
||||
args := make([]*c.Char, 3)
|
||||
args[0] = c.Str("-x")
|
||||
args[1] = c.Str("c++")
|
||||
args[2] = c.Str("-std=c++11")
|
||||
unit := index.ParseTranslationUnit(
|
||||
filename,
|
||||
unsafe.SliceData(args), 3,
|
||||
nil, 0,
|
||||
clang.DetailedPreprocessingRecord,
|
||||
)
|
||||
|
||||
if unit == nil {
|
||||
println("Unable to parse translation unit. Quitting.")
|
||||
c.Exit(1)
|
||||
}
|
||||
|
||||
context.setUnit(unit)
|
||||
cursor := unit.Cursor()
|
||||
|
||||
clang.VisitChildren(cursor, visit, nil)
|
||||
unit.Dispose()
|
||||
index.Dispose()
|
||||
}
|
||||
|
||||
func main() {
|
||||
if c.Argc != 2 {
|
||||
fmt.Fprintln(os.Stderr, "Usage: <C++ header file>\n")
|
||||
return
|
||||
} else {
|
||||
sourceFile := *c.Advance(c.Argv, 1)
|
||||
parse(sourceFile)
|
||||
}
|
||||
}
|
||||
@@ -1,224 +0,0 @@
|
||||
#include <clang-c/Index.h>
|
||||
#include <stdio.h>
|
||||
|
||||
typedef enum CXChildVisitResult (*wrap_CXCursorVisitor)(CXCursor *cursor, CXCursor *parent, CXClientData client_data);
|
||||
|
||||
typedef struct {
|
||||
CXClientData data;
|
||||
wrap_CXCursorVisitor visitor;
|
||||
} wrap_data;
|
||||
|
||||
CXChildVisitResult wrap_visitor(CXCursor cursor, CXCursor parent, CXClientData data) {
|
||||
wrap_data *d = (wrap_data *)(data);
|
||||
return d->visitor(&cursor, &parent, d->data);
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
void wrap_clang_getLocation(CXTranslationUnit tu, CXFile file, unsigned line, unsigned column, CXSourceLocation *loc) {
|
||||
*loc = clang_getLocation(tu, file, line, column);
|
||||
}
|
||||
|
||||
void wrap_clang_getLocationForOffset(CXTranslationUnit tu, CXFile file, unsigned offset, CXSourceLocation *loc) {
|
||||
*loc = clang_getLocationForOffset(tu, file, offset);
|
||||
}
|
||||
|
||||
void wrap_clang_getTranslationUnitCursor(CXTranslationUnit uint, CXCursor *cur) {
|
||||
*cur = clang_getTranslationUnitCursor(uint);
|
||||
}
|
||||
|
||||
unsigned wrap_clang_equalCursors(CXCursor *cursor1, CXCursor *cursor2) {
|
||||
return clang_equalCursors(*cursor1, *cursor2);
|
||||
}
|
||||
|
||||
int wrap_clang_Cursor_isNull(CXCursor *cursor) { return clang_Cursor_isNull(*cursor); }
|
||||
|
||||
void wrap_clang_getCursorSemanticParent(CXCursor *C, CXCursor *parent) { *parent = clang_getCursorSemanticParent(*C); }
|
||||
|
||||
void wrap_clang_getCursorDefinition(CXCursor *C, CXCursor *def) { *def = clang_getCursorDefinition(*C); }
|
||||
|
||||
void wrap_clang_getCursorLexicalParent(CXCursor *C, CXCursor *parent) { *parent = clang_getCursorLexicalParent(*C); }
|
||||
|
||||
void wrap_clang_getOverriddenCursors(CXCursor *cursor, CXCursor **overridden, unsigned *num_overridden) {
|
||||
clang_getOverriddenCursors(*cursor, overridden, num_overridden);
|
||||
}
|
||||
|
||||
CXFile wrap_clang_getIncludedFile(CXCursor *cursor) { return clang_getIncludedFile(*cursor); }
|
||||
|
||||
void wrap_clang_getCursor(CXTranslationUnit uint, CXSourceLocation *loc, CXCursor *cur) {
|
||||
*cur = clang_getCursor(uint, *loc);
|
||||
}
|
||||
|
||||
void wrap_clang_getCursorLocation(CXCursor *cur, CXSourceLocation *loc) { *loc = clang_getCursorLocation(*cur); }
|
||||
|
||||
void wrap_clang_getCursorExtent(CXCursor *cur, CXSourceRange *range) { *range = clang_getCursorExtent(*cur); }
|
||||
|
||||
void wrap_clang_getCursorType(CXCursor *cur, CXType *typ) { *typ = clang_getCursorType(*cur); }
|
||||
|
||||
CXString wrap_clang_getTypeSpelling(CXType *typ) { return clang_getTypeSpelling(*typ); }
|
||||
|
||||
void wrap_clang_getTypedefDeclUnderlyingType(CXCursor *cur, CXType *typ) {
|
||||
*typ = clang_getTypedefDeclUnderlyingType(*cur);
|
||||
}
|
||||
|
||||
long long wrap_clang_getEnumConstantDeclValue(CXCursor *cur) { return clang_getEnumConstantDeclValue(*cur); }
|
||||
|
||||
int wrap_clang_Cursor_getNumArguments(CXCursor *cur) { return clang_Cursor_getNumArguments(*cur); }
|
||||
|
||||
void wrap_clang_Cursor_getArgument(CXCursor *C, unsigned i, CXCursor *argCur) {
|
||||
*argCur = clang_Cursor_getArgument(*C, i);
|
||||
}
|
||||
|
||||
void wrap_clang_getCanonicalType(CXType *typ, CXType *canonicalType) { *canonicalType = clang_getCanonicalType(*typ); }
|
||||
|
||||
unsigned wrap_clang_isConstQualifiedType(CXType *typ) { return clang_isConstQualifiedType(*typ); }
|
||||
|
||||
unsigned wrap_clang_Cursor_isMacroFunctionLike(CXCursor *cur) { return clang_Cursor_isMacroFunctionLike(*cur); }
|
||||
|
||||
unsigned wrap_clang_Cursor_isMacroBuiltin(CXCursor *cur) { return clang_Cursor_isMacroBuiltin(*cur); }
|
||||
|
||||
unsigned wrap_clang_Cursor_isFunctionInlined(CXCursor *cur) { return clang_Cursor_isFunctionInlined(*cur); }
|
||||
|
||||
unsigned wrap_clang_isVolatileQualifiedType(CXType *T) { return clang_isVolatileQualifiedType(*T); }
|
||||
|
||||
unsigned wrap_clang_isRestrictQualifiedType(CXType *T) { return clang_isRestrictQualifiedType(*T); }
|
||||
|
||||
void wrap_clang_getPointeeType(CXType *pointerTyp, CXType *pointeeTyp) {
|
||||
*pointeeTyp = clang_getPointeeType(*pointerTyp);
|
||||
}
|
||||
|
||||
void wrap_clang_getNonReferenceType(CXType *typ, CXType *nonRefTyp) { *nonRefTyp = clang_getNonReferenceType(*typ); }
|
||||
|
||||
void wrap_clang_getTypeDeclaration(CXType *typ, CXCursor *cur) { *cur = clang_getTypeDeclaration(*typ); }
|
||||
|
||||
void wrap_clang_getResultType(CXType *typ, CXType *resultTyp) { *resultTyp = clang_getResultType(*typ); }
|
||||
|
||||
int wrap_clang_getNumArgTypes(CXType *typ) { return clang_getNumArgTypes(*typ); }
|
||||
|
||||
void wrap_clang_getArgType(CXType *typ, unsigned i, CXType *argTyp) { *argTyp = clang_getArgType(*typ, i); }
|
||||
|
||||
unsigned wrap_clang_isFunctionTypeVariadic(CXType *typ) { return clang_isFunctionTypeVariadic(*typ); }
|
||||
|
||||
void wrap_clang_getCursorResultType(CXCursor *cur, CXType *typ) { *typ = clang_getCursorResultType(*cur); }
|
||||
|
||||
void wrap_clang_getElementType(CXType *Typ, CXType *elemTyp) { *elemTyp = clang_getElementType(*Typ); }
|
||||
|
||||
void wrap_clang_getArrayElementType(CXType *arrayTyp, CXType *elemTyp) {
|
||||
*elemTyp = clang_getArrayElementType(*arrayTyp);
|
||||
}
|
||||
|
||||
long long wrap_clang_getArraySize(CXType *arrayTyp) { return clang_getArraySize(*arrayTyp); }
|
||||
|
||||
void wrap_clang_Type_getNamedType(CXType *typ, CXType *namedTyp) { *namedTyp = clang_Type_getNamedType(*typ); }
|
||||
|
||||
long long wrap_clang_Type_getSizeOf(CXType *typ) { return clang_Type_getSizeOf(*typ); }
|
||||
|
||||
unsigned wrap_clang_Cursor_isAnonymous(CXCursor *cursor) { return clang_Cursor_isAnonymous(*cursor); }
|
||||
|
||||
unsigned wrap_clang_Cursor_isAnonymousRecordDecl(CXCursor *cursor) {
|
||||
return clang_Cursor_isAnonymousRecordDecl(*cursor);
|
||||
}
|
||||
|
||||
enum CX_CXXAccessSpecifier wrap_clang_getCXXAccessSpecifier(CXCursor *cursor) {
|
||||
return clang_getCXXAccessSpecifier(*cursor);
|
||||
}
|
||||
|
||||
enum CX_StorageClass wrap_clang_Cursor_getStorageClass(CXCursor *cursor) {
|
||||
return clang_Cursor_getStorageClass(*cursor);
|
||||
}
|
||||
|
||||
CXString wrap_clang_getCursorUSR(CXCursor *cur) { return clang_getCursorUSR(*cur); }
|
||||
|
||||
CXString wrap_clang_getCursorSpelling(CXCursor *cur) { return clang_getCursorSpelling(*cur); }
|
||||
|
||||
CXString wrap_clang_getCursorDisplayName(CXCursor *cur) { return clang_getCursorDisplayName(*cur); }
|
||||
|
||||
void wrap_clang_getCursorReferenced(CXCursor *cur, CXCursor *referenced) {
|
||||
*referenced = clang_getCursorReferenced(*cur);
|
||||
}
|
||||
|
||||
unsigned wrap_clang_Cursor_isVariadic(CXCursor *cur) { return clang_Cursor_isVariadic(*cur); }
|
||||
|
||||
void wrap_clang_Cursor_getCommentRange(CXCursor *cur, CXSourceRange *range) {
|
||||
*range = clang_Cursor_getCommentRange(*cur);
|
||||
}
|
||||
|
||||
CXString wrap_clang_Cursor_getRawCommentText(CXCursor *cursor) { return clang_Cursor_getRawCommentText(*cursor); }
|
||||
|
||||
CXString wrap_clang_Cursor_getMangling(CXCursor *cur) { return clang_Cursor_getMangling(*cur); }
|
||||
|
||||
unsigned wrap_clang_CXXConstructor_isConvertingConstructor(CXCursor *cursor) {
|
||||
return clang_CXXConstructor_isConvertingConstructor(*cursor);
|
||||
}
|
||||
|
||||
unsigned wrap_clang_CXXConstructor_isCopyConstructor(CXCursor *cursor) {
|
||||
return clang_CXXConstructor_isCopyConstructor(*cursor);
|
||||
}
|
||||
|
||||
unsigned wrap_clang_CXXConstructor_isDefaultConstructor(CXCursor *cursor) {
|
||||
return clang_CXXConstructor_isDefaultConstructor(*cursor);
|
||||
}
|
||||
|
||||
unsigned wrap_clang_CXXConstructor_isMoveConstructor(CXCursor *cursor) {
|
||||
return clang_CXXConstructor_isMoveConstructor(*cursor);
|
||||
}
|
||||
|
||||
unsigned wrap_clang_CXXField_isMutable(CXCursor *cursor) { return clang_CXXField_isMutable(*cursor); }
|
||||
|
||||
unsigned wrap_clang_CXXMethod_isDefaulted(CXCursor *cursor) { return clang_CXXMethod_isDefaulted(*cursor); }
|
||||
|
||||
unsigned wrap_clang_CXXMethod_isDeleted(CXCursor *cursor) { return clang_CXXMethod_isDeleted(*cursor); }
|
||||
|
||||
unsigned wrap_clang_CXXMethod_isPureVirtual(CXCursor *cursor) { return clang_CXXMethod_isPureVirtual(*cursor); }
|
||||
|
||||
unsigned wrap_clang_CXXMethod_isStatic(CXCursor *cursor) { return clang_CXXMethod_isStatic(*cursor); }
|
||||
|
||||
unsigned wrap_clang_CXXMethod_isVirtual(CXCursor *cursor) { return clang_CXXMethod_isVirtual(*cursor); }
|
||||
|
||||
unsigned wrap_clang_CXXMethod_isCopyAssignmentOperator(CXCursor *cursor) {
|
||||
return clang_CXXMethod_isCopyAssignmentOperator(*cursor);
|
||||
}
|
||||
|
||||
unsigned wrap_clang_CXXMethod_isMoveAssignmentOperator(CXCursor *cursor) {
|
||||
return clang_CXXMethod_isMoveAssignmentOperator(*cursor);
|
||||
}
|
||||
|
||||
unsigned wrap_clang_CXXMethod_isExplicit(CXCursor *cursor) { return clang_CXXMethod_isExplicit(*cursor); }
|
||||
|
||||
unsigned wrap_clang_CXXRecord_isAbstract(CXCursor *cursor) { return clang_CXXRecord_isAbstract(*cursor); }
|
||||
|
||||
unsigned wrap_clang_EnumDecl_isScoped(CXCursor *cursor) { return clang_EnumDecl_isScoped(*cursor); }
|
||||
|
||||
unsigned wrap_clang_CXXMethod_isConst(CXCursor *cursor) { return clang_CXXMethod_isConst(*cursor); }
|
||||
|
||||
CXTokenKind wrap_clang_getTokenKind(CXToken *token) { return clang_getTokenKind(*token); }
|
||||
|
||||
CXString wrap_clang_getTokenSpelling(CXTranslationUnit unit, CXToken *token) {
|
||||
return clang_getTokenSpelling(unit, *token);
|
||||
}
|
||||
|
||||
void wrap_clang_tokenize(CXTranslationUnit unit, CXSourceRange *Range, CXToken **Tokens, unsigned *NumTokens) {
|
||||
clang_tokenize(unit, *Range, Tokens, NumTokens);
|
||||
}
|
||||
|
||||
unsigned wrap_clang_visitChildren(CXCursor *parent, wrap_CXCursorVisitor visitor, CXClientData client_data) {
|
||||
wrap_data data = {client_data, visitor};
|
||||
return clang_visitChildren(*parent, wrap_visitor, CXClientData(&data));
|
||||
}
|
||||
|
||||
int wrap_clang_Location_isInSystemHeader(CXSourceLocation *loc) { return clang_Location_isInSystemHeader(*loc); }
|
||||
|
||||
void wrap_clang_getSpellingLocation(CXSourceLocation *loc, CXFile *file, unsigned *line, unsigned *column,
|
||||
unsigned *offset) {
|
||||
clang_getSpellingLocation(*loc, file, line, column, offset);
|
||||
}
|
||||
|
||||
void wrap_clang_getPresumedLocation(CXSourceLocation *loc, CXString *filename, unsigned *line, unsigned *column) {
|
||||
clang_getPresumedLocation(*loc, filename, line, column);
|
||||
}
|
||||
|
||||
void wrap_clang_getRangeStart(CXSourceRange *range, CXSourceLocation *loc) { *loc = clang_getRangeStart(*range); }
|
||||
|
||||
void wrap_clang_getRangeEnd(CXSourceRange *range, CXSourceLocation *loc) { *loc = clang_getRangeEnd(*range); }
|
||||
|
||||
} // extern "C"
|
||||
@@ -1,7 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <clang-c/Index.h>
|
||||
|
||||
int main() {
|
||||
printf("sizeof(clang.Cursor) = %lu\n", sizeof(CXCursor));
|
||||
return 0;
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/clang"
|
||||
)
|
||||
|
||||
const (
|
||||
LLGoCFlags = "-I$(llvm-config --includedir)"
|
||||
)
|
||||
|
||||
func main() {
|
||||
c.Printf(c.Str("sizeof(clang.Cursor) = %lu\n"), unsafe.Sizeof(clang.Cursor{}))
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package clang
|
||||
|
||||
import (
|
||||
_ "unsafe"
|
||||
|
||||
"github.com/goplus/llgo/c"
|
||||
)
|
||||
|
||||
/**
|
||||
* A character string.
|
||||
*
|
||||
* The \c CXString type is used to return strings from the interface when
|
||||
* the ownership of that string might differ from one call to the next.
|
||||
* Use \c clang_getCString() to retrieve the string data and, once finished
|
||||
* with the string data, call \c clang_disposeString() to free the string.
|
||||
*/
|
||||
type String struct {
|
||||
Data c.Pointer
|
||||
PrivateFlags c.Uint
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the character data associated with the given string.
|
||||
*/
|
||||
// llgo:link String.CStr C.clang_getCString
|
||||
func (String) CStr() *c.Char { return nil }
|
||||
|
||||
/**
|
||||
* Free the given string.
|
||||
*/
|
||||
// llgo:link String.Dispose C.clang_disposeString
|
||||
func (String) Dispose() {}
|
||||
|
||||
type StringSet struct {
|
||||
Strings *String
|
||||
Count c.Uint
|
||||
}
|
||||
|
||||
/**
|
||||
* Free the given string set.
|
||||
*/
|
||||
// llgo:link (*StringSet).Dispose C.clang_disposeStringSet
|
||||
func (*StringSet) Dispose() {}
|
||||
|
||||
func GoString(clangStr String) (str string) {
|
||||
defer clangStr.Dispose()
|
||||
cstr := clangStr.CStr()
|
||||
if cstr != nil {
|
||||
str = c.GoString(cstr)
|
||||
}
|
||||
return
|
||||
}
|
||||
2953
c/clang/clang.go
2953
c/clang/clang.go
File diff suppressed because it is too large
Load Diff
@@ -1,27 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/debug"
|
||||
)
|
||||
|
||||
type T struct {
|
||||
n int
|
||||
}
|
||||
|
||||
func (t *T) Demo() {
|
||||
println(t.n)
|
||||
addr := debug.Address()
|
||||
c.Printf(c.Str("addr:0x%x\n"), addr)
|
||||
var info debug.Info
|
||||
r := debug.Addrinfo(addr, &info)
|
||||
if r == 0 {
|
||||
panic("not found info")
|
||||
}
|
||||
c.Printf(c.Str("func file:%s name:%s base:0x%x addr:0x%x\n"), info.Fname, info.Sname, info.Fbase, info.Saddr)
|
||||
}
|
||||
|
||||
func main() {
|
||||
t := &T{100}
|
||||
t.Demo()
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/goplus/llgo/c/debug"
|
||||
)
|
||||
|
||||
type T struct {
|
||||
n int
|
||||
}
|
||||
|
||||
func (t *T) Demo() {
|
||||
println(t.n)
|
||||
debug.StackTrace(0, func(fr *debug.Frame) bool {
|
||||
var info debug.Info
|
||||
debug.Addrinfo(unsafe.Pointer(fr.PC), &info)
|
||||
println("[", fr.PC, "]", fr.Name, "+", fr.Offset, ", SP =", fr.SP)
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
func main() {
|
||||
t := &T{100}
|
||||
t.Demo()
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
#if defined(__linux__)
|
||||
#define UNW_LOCAL_ONLY
|
||||
#define _GNU_SOURCE
|
||||
#include <features.h>
|
||||
#endif
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <libunwind.h>
|
||||
|
||||
void *llgo_address() {
|
||||
return __builtin_return_address(0);
|
||||
}
|
||||
|
||||
int llgo_addrinfo(void *addr, Dl_info *info) {
|
||||
return dladdr(addr, info);
|
||||
}
|
||||
|
||||
void llgo_stacktrace(int skip, void *ctx, int (*fn)(void *ctx, void *pc, void *offset, void *sp, char *name)) {
|
||||
unw_cursor_t cursor;
|
||||
unw_context_t context;
|
||||
unw_word_t offset, pc, sp;
|
||||
char fname[256];
|
||||
unw_getcontext(&context);
|
||||
unw_init_local(&cursor, &context);
|
||||
int depth = 0;
|
||||
while (unw_step(&cursor) > 0) {
|
||||
if (depth < skip) {
|
||||
depth++;
|
||||
continue;
|
||||
}
|
||||
if (unw_get_reg(&cursor, UNW_REG_IP, &pc) == 0) {
|
||||
unw_get_proc_name(&cursor, fname, sizeof(fname), &offset);
|
||||
unw_get_reg(&cursor, UNW_REG_SP, &sp);
|
||||
if (fn(ctx, (void*)pc, (void*)offset, (void*)sp, fname) == 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package debug
|
||||
|
||||
/*
|
||||
#cgo linux LDFLAGS: -lunwind
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/goplus/llgo/c"
|
||||
)
|
||||
|
||||
const (
|
||||
LLGoPackage = "link"
|
||||
LLGoFiles = "_wrap/debug.c"
|
||||
)
|
||||
|
||||
type Info struct {
|
||||
Fname *c.Char
|
||||
Fbase c.Pointer
|
||||
Sname *c.Char
|
||||
Saddr c.Pointer
|
||||
}
|
||||
|
||||
//go:linkname Address C.llgo_address
|
||||
func Address() unsafe.Pointer
|
||||
|
||||
//go:linkname Addrinfo C.llgo_addrinfo
|
||||
func Addrinfo(addr unsafe.Pointer, info *Info) c.Int
|
||||
|
||||
//go:linkname stacktrace C.llgo_stacktrace
|
||||
func stacktrace(skip c.Int, ctx unsafe.Pointer, fn func(ctx, pc, offset, sp unsafe.Pointer, name *c.Char) c.Int)
|
||||
|
||||
type Frame struct {
|
||||
PC uintptr
|
||||
Offset uintptr
|
||||
SP unsafe.Pointer
|
||||
Name string
|
||||
}
|
||||
|
||||
func StackTrace(skip int, fn func(fr *Frame) bool) {
|
||||
stacktrace(c.Int(1+skip), unsafe.Pointer(&fn), func(ctx, pc, offset, sp unsafe.Pointer, name *c.Char) c.Int {
|
||||
fn := *(*func(fr *Frame) bool)(ctx)
|
||||
if !fn(&Frame{uintptr(pc), uintptr(offset), sp, c.GoString(name)}) {
|
||||
return 0
|
||||
}
|
||||
return 1
|
||||
})
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
#include <stdio.h>
|
||||
|
||||
struct array
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
int z;
|
||||
int k;
|
||||
};
|
||||
|
||||
int demo1(struct array a)
|
||||
{
|
||||
printf("c.demo1: %d %d %d %d\n",a.x,a.y,a.z,a.k);
|
||||
return a.x+a.y+a.z+a.k;
|
||||
}
|
||||
|
||||
int demo2( int (*fn)(struct array)) {
|
||||
printf("c.demo2: %p\n",fn);
|
||||
struct array a;
|
||||
a.x = 1;
|
||||
a.y = 2;
|
||||
a.z = 3;
|
||||
a.k = 4;
|
||||
return (*fn)(a);
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/ffi"
|
||||
)
|
||||
|
||||
const (
|
||||
LLGoPackage = "link"
|
||||
LLGoFiles = "../_wrap/wrap.c"
|
||||
)
|
||||
|
||||
//llgo:type C
|
||||
type Callback func(array) c.Int
|
||||
|
||||
//go:linkname demo1 C.demo1
|
||||
func demo1(array) c.Int
|
||||
|
||||
//go:linkname demo2 C.demo2
|
||||
func demo2(fn Callback) c.Int
|
||||
|
||||
//llgo:type C
|
||||
type array struct {
|
||||
x c.Int
|
||||
y c.Int
|
||||
z c.Int
|
||||
k c.Int
|
||||
}
|
||||
|
||||
var (
|
||||
typeInt32 = &ffi.Type{4, 4, ffi.Sint32, nil}
|
||||
typePointer = &ffi.Type{unsafe.Sizeof(0), uint16(unsafe.Alignof(0)), ffi.Pointer, nil}
|
||||
)
|
||||
|
||||
func main() {
|
||||
cdemo1()
|
||||
cdemo2()
|
||||
}
|
||||
|
||||
func cdemo1() {
|
||||
var cif ffi.Cif
|
||||
tarray := &ffi.Type{0, 0, ffi.Struct, &[]*ffi.Type{typeInt32, typeInt32, typeInt32, typeInt32, nil}[0]}
|
||||
status := ffi.PrepCif(&cif, ffi.DefaultAbi, 1, typeInt32, &[]*ffi.Type{tarray}[0])
|
||||
if status != ffi.OK {
|
||||
panic(status)
|
||||
}
|
||||
ar := array{1, 2, 3, 4}
|
||||
var ret int32
|
||||
ffi.Call(&cif, c.Func(demo1), unsafe.Pointer(&ret), &[]unsafe.Pointer{unsafe.Pointer(&ar)}[0])
|
||||
c.Printf(c.Str("ret: %d\n"), ret)
|
||||
}
|
||||
|
||||
func cdemo2() {
|
||||
var cif ffi.Cif
|
||||
status := ffi.PrepCif(&cif, ffi.DefaultAbi, 1, typeInt32, &[]*ffi.Type{typePointer}[0])
|
||||
if status != ffi.OK {
|
||||
panic(status)
|
||||
}
|
||||
var ret int32
|
||||
fn := c.Func(demo1)
|
||||
ffi.Call(&cif, c.Func(demo2), unsafe.Pointer(&ret), &[]unsafe.Pointer{unsafe.Pointer(&fn)}[0])
|
||||
c.Printf(c.Str("ret: %d\n"), ret)
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/ffi"
|
||||
)
|
||||
|
||||
const (
|
||||
LLGoPackage = "link"
|
||||
LLGoFiles = "../_wrap/wrap.c"
|
||||
)
|
||||
|
||||
//llgo:type C
|
||||
type Callback func(array) c.Int
|
||||
|
||||
//go:linkname demo1 C.demo1
|
||||
func demo1(array) c.Int
|
||||
|
||||
//go:linkname demo2 C.demo2
|
||||
func demo2(fn Callback) c.Int
|
||||
|
||||
//llgo:type C
|
||||
type array struct {
|
||||
x c.Int
|
||||
y c.Int
|
||||
z c.Int
|
||||
k c.Int
|
||||
}
|
||||
|
||||
func demo(a array) c.Int {
|
||||
c.Printf(c.Str("go.demo %d %d %d %d\n"), a.x, a.y, a.z, a.k)
|
||||
return a.x + a.y + a.z + a.k
|
||||
}
|
||||
|
||||
var (
|
||||
typeInt32 = &ffi.Type{4, 4, ffi.Sint32, nil}
|
||||
typePointer = &ffi.Type{unsafe.Sizeof(0), uint16(unsafe.Alignof(0)), ffi.Pointer, nil}
|
||||
)
|
||||
|
||||
func main() {
|
||||
gofn()
|
||||
c.Printf(c.Str("\n"))
|
||||
goclosure()
|
||||
}
|
||||
|
||||
func gofn() {
|
||||
var cif ffi.Cif
|
||||
status := ffi.PrepCif(&cif, ffi.DefaultAbi, 1, typeInt32, &[]*ffi.Type{typePointer}[0])
|
||||
if status != ffi.OK {
|
||||
panic(status)
|
||||
}
|
||||
var fncode unsafe.Pointer
|
||||
closure := ffi.ClosureAlloc(&fncode)
|
||||
defer ffi.ClosureFree(closure)
|
||||
status = ffi.PreClosureLoc(closure, &cif, func(cif *ffi.Cif, ret unsafe.Pointer, args *unsafe.Pointer, userdata unsafe.Pointer) {
|
||||
ar := *(*array)(ffi.Index(args, 0))
|
||||
*(*c.Int)(ret) = demo(ar)
|
||||
}, nil, fncode)
|
||||
if status != ffi.OK {
|
||||
panic(status)
|
||||
}
|
||||
var ret int32
|
||||
ffi.Call(&cif, c.Func(demo2), unsafe.Pointer(&ret), &[]unsafe.Pointer{unsafe.Pointer(&fncode)}[0])
|
||||
c.Printf(c.Str("ret: %d\n"), ret)
|
||||
}
|
||||
|
||||
func goclosure() {
|
||||
var cif ffi.Cif
|
||||
status := ffi.PrepCif(&cif, ffi.DefaultAbi, 1, typeInt32, &[]*ffi.Type{typePointer}[0])
|
||||
if status != ffi.OK {
|
||||
panic(status)
|
||||
}
|
||||
fn := func(ar array) c.Int {
|
||||
c.Printf(c.Str("call closure %d\n"), cif.NArgs)
|
||||
return demo(ar)
|
||||
}
|
||||
var fncode unsafe.Pointer
|
||||
closure := ffi.ClosureAlloc(&fncode)
|
||||
defer ffi.ClosureFree(closure)
|
||||
status = ffi.PreClosureLoc(closure, &cif, func(cif *ffi.Cif, ret unsafe.Pointer, args *unsafe.Pointer, userdata unsafe.Pointer) {
|
||||
ar := *(*array)(ffi.Index(args, 0))
|
||||
fn := *(*func(array) c.Int)(userdata)
|
||||
*(*c.Int)(ret) = fn(ar)
|
||||
}, unsafe.Pointer(&fn), fncode)
|
||||
if status != ffi.OK {
|
||||
panic(status)
|
||||
}
|
||||
var ret int32
|
||||
ffi.Call(&cif, c.Func(demo2), unsafe.Pointer(&ret), &[]unsafe.Pointer{unsafe.Pointer(&fncode)}[0])
|
||||
c.Printf(c.Str("ret: %d\n"), ret)
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/ffi"
|
||||
)
|
||||
|
||||
var (
|
||||
typeInt32 = &ffi.Type{4, 4, ffi.Sint32, nil}
|
||||
typePointer = &ffi.Type{unsafe.Sizeof(0), uint16(unsafe.Alignof(0)), ffi.Pointer, nil}
|
||||
)
|
||||
|
||||
func main() {
|
||||
var cif ffi.Cif
|
||||
status := ffi.PrepCifVar(&cif, ffi.DefaultAbi, 1, 2, typeInt32, &[]*ffi.Type{typePointer, typeInt32}[0])
|
||||
if status != ffi.OK {
|
||||
panic(status)
|
||||
}
|
||||
var ret int32
|
||||
text := c.Str("hello world: %d\n")
|
||||
var n int32 = 100
|
||||
ffi.Call(&cif, c.Func(c.Printf), unsafe.Pointer(&ret), &[]unsafe.Pointer{unsafe.Pointer(&text), unsafe.Pointer(&n)}[0])
|
||||
c.Printf(c.Str("ret: %d\n"), ret)
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
#include <ffi.h>
|
||||
|
||||
void *llog_ffi_closure_alloc(void **code) {
|
||||
return ffi_closure_alloc(sizeof(ffi_closure), code);
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
//go:build ((freebsd || linux || darwin) && arm64) || (windows && (amd64 || arm64))
|
||||
|
||||
package ffi
|
||||
|
||||
const (
|
||||
DefaultAbi = 1
|
||||
)
|
||||
@@ -1,7 +0,0 @@
|
||||
//go:build freebsd || linux || darwin
|
||||
|
||||
package ffi
|
||||
|
||||
const (
|
||||
DefaultAbi = 2
|
||||
)
|
||||
@@ -1,44 +0,0 @@
|
||||
LLGo wrapper of libuv
|
||||
=====
|
||||
|
||||
## How to install
|
||||
|
||||
### on macOS (Homebrew)
|
||||
|
||||
```sh
|
||||
brew install libuv
|
||||
```
|
||||
|
||||
### on Linux (Debian/Ubuntu)
|
||||
|
||||
```sh
|
||||
apt-get install -y libuv1-dev
|
||||
```
|
||||
|
||||
### on Linux (CentOS/RHEL)
|
||||
|
||||
```sh
|
||||
yum install -y libuv-devel
|
||||
```
|
||||
|
||||
### on Linux (Arch Linux)
|
||||
|
||||
```sh
|
||||
pacman -S libuv
|
||||
```
|
||||
|
||||
## Demos
|
||||
|
||||
The `_demo` directory contains our demos (it start with `_` to prevent the `go` command from compiling it):
|
||||
|
||||
* [async_fs](_demo/async_fs/async_fs.go): a simple async file read demo
|
||||
* [echo_server](_demo/echo_server/echo_server.go): a basic async tcp echo server
|
||||
|
||||
### How to run demos
|
||||
|
||||
To run the demos in directory `_demo`:
|
||||
|
||||
```sh
|
||||
cd <demo-directory> # eg. cd _demo/sqlitedemo
|
||||
llgo run .
|
||||
```
|
||||
@@ -1,41 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/libuv"
|
||||
)
|
||||
|
||||
func ensure(b bool, msg string) {
|
||||
if !b {
|
||||
panic(msg)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
loop := libuv.LoopNew()
|
||||
defer loop.Close()
|
||||
|
||||
a := &libuv.Async{}
|
||||
r := loop.Async(a, func(a *libuv.Async) {
|
||||
println("async callback")
|
||||
a.Close(nil) // or loop.Stop()
|
||||
})
|
||||
ensure(r == 0, "Async failed")
|
||||
|
||||
go func() {
|
||||
println("begin async task")
|
||||
c.Usleep(100 * 1000)
|
||||
println("send async event")
|
||||
ensure(a.Send() == 0, "Send failed")
|
||||
}()
|
||||
|
||||
loop.Run(libuv.RUN_DEFAULT)
|
||||
println("done")
|
||||
}
|
||||
|
||||
/*Expected Output:
|
||||
begin async task
|
||||
send async event
|
||||
async callback
|
||||
done
|
||||
*/
|
||||
@@ -1,116 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/libuv"
|
||||
"github.com/goplus/llgo/c/os"
|
||||
)
|
||||
|
||||
const BUFFER_SIZE = 1024
|
||||
|
||||
var (
|
||||
loop *libuv.Loop
|
||||
openReq libuv.Fs
|
||||
closeReq libuv.Fs
|
||||
|
||||
buffer [BUFFER_SIZE]c.Char
|
||||
iov libuv.Buf
|
||||
file libuv.File
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Print the libuv version
|
||||
c.Printf(c.Str("libuv version: %d\n"), libuv.Version())
|
||||
|
||||
// Initialize the loop
|
||||
loop = libuv.DefaultLoop()
|
||||
|
||||
// Open the file
|
||||
libuv.FsOpen(loop, &openReq, c.Str("example.txt"), os.O_RDONLY, 0, onOpen)
|
||||
|
||||
// Run the loop
|
||||
result := loop.Run(libuv.RUN_DEFAULT)
|
||||
|
||||
if result != 0 {
|
||||
c.Fprintf(c.Stderr, c.Str("Error in Run: %s\n"), libuv.Strerror(libuv.Errno(result)))
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
defer cleanup()
|
||||
}
|
||||
|
||||
func onOpen(req *libuv.Fs) {
|
||||
// Check for errors
|
||||
if req.GetResult() < 0 {
|
||||
c.Fprintf(c.Stderr, c.Str("Error opening file: %s\n"), libuv.Strerror(libuv.Errno(req.GetResult())))
|
||||
loop.Close()
|
||||
return
|
||||
}
|
||||
|
||||
// Store the file descriptor
|
||||
file = libuv.File(req.GetResult())
|
||||
|
||||
// Init buffer
|
||||
iov = libuv.InitBuf((*c.Char)(unsafe.Pointer(&buffer[0])), c.Uint(unsafe.Sizeof(buffer)))
|
||||
|
||||
// Read the file
|
||||
readFile()
|
||||
|
||||
}
|
||||
|
||||
func readFile() {
|
||||
// Initialize the request every time
|
||||
var readReq libuv.Fs
|
||||
|
||||
// Read the file
|
||||
readRes := libuv.FsRead(loop, &readReq, file, &iov, 1, -1, onRead)
|
||||
if readRes != 0 {
|
||||
c.Printf(c.Str("Error in FsRead: %s (code: %d)\n"), libuv.Strerror(libuv.Errno(readRes)), readRes)
|
||||
readReq.ReqCleanup()
|
||||
loop.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func onRead(req *libuv.Fs) {
|
||||
// Cleanup the request
|
||||
defer req.ReqCleanup()
|
||||
// Check for errors
|
||||
if req.GetResult() < 0 {
|
||||
c.Fprintf(c.Stderr, c.Str("Read error: %s\n"), libuv.Strerror(libuv.Errno(req.GetResult())))
|
||||
} else if req.GetResult() == 0 {
|
||||
// Close the file
|
||||
closeRes := libuv.FsClose(loop, &closeReq, libuv.File(openReq.GetResult()), onClose)
|
||||
if closeRes != 0 {
|
||||
c.Printf(c.Str("Error in FsClose: %s (code: %d)\n"), libuv.Strerror(libuv.Errno(closeRes)), closeRes)
|
||||
loop.Close()
|
||||
return
|
||||
}
|
||||
} else {
|
||||
c.Printf(c.Str("Read %d bytes\n"), req.GetResult())
|
||||
c.Printf(c.Str("Read content: %.*s\n"), req.GetResult(), (*c.Char)(unsafe.Pointer(&buffer[0])))
|
||||
// Read the file again
|
||||
readFile()
|
||||
}
|
||||
}
|
||||
|
||||
func onClose(req *libuv.Fs) {
|
||||
// Check for errors
|
||||
if req.GetResult() < 0 {
|
||||
c.Fprintf(c.Stderr, c.Str("Error closing file: %s\n"), libuv.Strerror(libuv.Errno(req.GetResult())))
|
||||
} else {
|
||||
c.Printf(c.Str("\nFile closed successfully.\n"))
|
||||
}
|
||||
}
|
||||
|
||||
func cleanup() {
|
||||
// Cleanup the requests
|
||||
openReq.ReqCleanup()
|
||||
closeReq.ReqCleanup()
|
||||
// Close the loop
|
||||
result := loop.Close()
|
||||
if result != 0 {
|
||||
c.Fprintf(c.Stderr, c.Str("Error in LoopClose: %s\n"), libuv.Strerror(libuv.Errno(result)))
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
123
|
||||
@@ -1,112 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/libuv"
|
||||
"github.com/goplus/llgo/c/net"
|
||||
)
|
||||
|
||||
var DEFAULT_PORT c.Int = 8080
|
||||
var DEFAULT_BACKLOG c.Int = 128
|
||||
|
||||
type WriteReq struct {
|
||||
Req libuv.Write
|
||||
Buf libuv.Buf
|
||||
}
|
||||
|
||||
func main() {
|
||||
// Initialize the default event loop
|
||||
var loop = libuv.DefaultLoop()
|
||||
|
||||
// Initialize a TCP server
|
||||
server := &libuv.Tcp{}
|
||||
libuv.InitTcp(loop, server)
|
||||
|
||||
// Set up the address to bind the server to
|
||||
var addr net.SockaddrIn
|
||||
libuv.Ip4Addr(c.Str("0.0.0.0"), DEFAULT_PORT, &addr)
|
||||
c.Printf(c.Str("Listening on %s:%d\n"), c.Str("0.0.0.0"), DEFAULT_PORT)
|
||||
|
||||
// Bind the server to the specified address and port
|
||||
server.Bind((*net.SockAddr)(c.Pointer(&addr)), 0)
|
||||
res := (*libuv.Stream)(server).Listen(DEFAULT_BACKLOG, OnNewConnection)
|
||||
if res != 0 {
|
||||
c.Fprintf(c.Stderr, c.Str("Listen error: %s\n"), libuv.Strerror(libuv.Errno(res)))
|
||||
return
|
||||
}
|
||||
|
||||
// Start listening for incoming connections
|
||||
loop.Run(libuv.RUN_DEFAULT)
|
||||
}
|
||||
|
||||
func FreeWriteReq(req *libuv.Write) {
|
||||
wr := (*WriteReq)(c.Pointer(req))
|
||||
// Free the buffer base.
|
||||
if wr.Buf.Base != nil {
|
||||
c.Free(c.Pointer(wr.Buf.Base))
|
||||
wr.Buf.Base = nil
|
||||
}
|
||||
}
|
||||
|
||||
func AllocBuffer(handle *libuv.Handle, suggestedSize uintptr, buf *libuv.Buf) {
|
||||
// Allocate memory for the buffer based on the suggested size.
|
||||
buf.Base = (*c.Char)(c.Malloc(suggestedSize))
|
||||
buf.Len = suggestedSize
|
||||
}
|
||||
|
||||
func EchoWrite(req *libuv.Write, status c.Int) {
|
||||
if status != 0 {
|
||||
c.Fprintf(c.Stderr, c.Str("Write error: %s\n"), libuv.Strerror(libuv.Errno(status)))
|
||||
}
|
||||
FreeWriteReq(req)
|
||||
}
|
||||
|
||||
func EchoRead(client *libuv.Stream, nread c.Long, buf *libuv.Buf) {
|
||||
if nread > 0 {
|
||||
req := new(WriteReq)
|
||||
// Initialize the buffer with the data read.
|
||||
req.Buf = libuv.InitBuf(buf.Base, c.Uint(nread))
|
||||
// Write the data back to the client.
|
||||
req.Req.Write(client, &req.Buf, 1, EchoWrite)
|
||||
return
|
||||
}
|
||||
if nread < 0 {
|
||||
// Handle read errors and EOF.
|
||||
if (libuv.Errno)(nread) != libuv.EOF {
|
||||
c.Fprintf(c.Stderr, c.Str("Read error: %s\n"), libuv.Strerror(libuv.Errno(nread)))
|
||||
}
|
||||
(*libuv.Handle)(c.Pointer(client)).Close(nil)
|
||||
}
|
||||
// Free the buffer if it's no longer needed.
|
||||
if buf.Base != nil {
|
||||
c.Free(c.Pointer(buf.Base))
|
||||
}
|
||||
}
|
||||
|
||||
func OnNewConnection(server *libuv.Stream, status c.Int) {
|
||||
if status < 0 {
|
||||
c.Fprintf(c.Stderr, c.Str("New connection error: %s\n"), libuv.Strerror(libuv.Errno(status)))
|
||||
return
|
||||
}
|
||||
|
||||
// Allocate memory for a new client.
|
||||
client := &libuv.Tcp{}
|
||||
|
||||
if client == nil {
|
||||
c.Fprintf(c.Stderr, c.Str("Failed to allocate memory for client\n"))
|
||||
return
|
||||
}
|
||||
|
||||
// Initialize the client TCP handle.
|
||||
if libuv.InitTcp(libuv.DefaultLoop(), client) < 0 {
|
||||
c.Fprintf(c.Stderr, c.Str("Failed to initialize client\n"))
|
||||
return
|
||||
}
|
||||
|
||||
// Accept the new connection and start reading data.
|
||||
if server.Accept((*libuv.Stream)(client)) == 0 {
|
||||
(*libuv.Stream)(client).StartRead(AllocBuffer, EchoRead)
|
||||
} else {
|
||||
(*libuv.Handle)(c.Pointer(client)).Close(nil)
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
#include <uv.h>
|
||||
|
||||
int uv_tcp_get_io_watcher_fd (uv_tcp_t* handle) {
|
||||
return handle->io_watcher.fd;
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package libuv
|
||||
|
||||
import (
|
||||
_ "unsafe"
|
||||
|
||||
"github.com/goplus/llgo/c"
|
||||
)
|
||||
|
||||
// struct uv_async_t
|
||||
type Async struct {
|
||||
Handle
|
||||
// On macOS arm64, sizeof uv_async_t is 128 bytes.
|
||||
// Handle is 92 bytes, so we need 36 bytes to fill the gap.
|
||||
// Maybe reserve more for future use.
|
||||
Unused [36]byte
|
||||
}
|
||||
|
||||
// typedef void (*uv_async_cb)(uv_async_t* handle);
|
||||
// llgo:type C
|
||||
type AsyncCb func(*Async)
|
||||
|
||||
// int uv_async_init(uv_loop_t*, uv_async_t* async, uv_async_cb async_cb);
|
||||
//
|
||||
// llgo:link (*Loop).Async C.uv_async_init
|
||||
func (loop *Loop) Async(a *Async, cb AsyncCb) c.Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
// int uv_async_send(uv_async_t* async);
|
||||
//
|
||||
// llgo:link (*Async).Send C.uv_async_send
|
||||
func (a *Async) Send() c.Int {
|
||||
return 0
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package libuv
|
||||
|
||||
import (
|
||||
_ "unsafe"
|
||||
|
||||
"github.com/goplus/llgo/c"
|
||||
)
|
||||
|
||||
/* Handle types. */
|
||||
|
||||
type Check struct {
|
||||
Unused [120]byte
|
||||
}
|
||||
|
||||
/* Function type */
|
||||
|
||||
// llgo:type C
|
||||
type CheckCb func(Check *Check)
|
||||
|
||||
//go:linkname InitCheck C.uv_check_init
|
||||
func InitCheck(loop *Loop, Check *Check) c.Int
|
||||
|
||||
// llgo:link (*Check).Start C.uv_check_start
|
||||
func (Check *Check) Start(CheckCb CheckCb) c.Int { return 0 }
|
||||
|
||||
// llgo:link (*Check).Stop C.uv_check_stop
|
||||
func (Check *Check) Stop() c.Int { return 0 }
|
||||
118
c/libuv/error.go
118
c/libuv/error.go
@@ -1,118 +0,0 @@
|
||||
package libuv
|
||||
|
||||
import (
|
||||
_ "unsafe"
|
||||
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/net"
|
||||
"github.com/goplus/llgo/c/syscall"
|
||||
)
|
||||
|
||||
const (
|
||||
E2BIG = Errno(syscall.E2BIG)
|
||||
EACCES = Errno(syscall.EACCES)
|
||||
EADDRINUSE = Errno(syscall.EADDRINUSE)
|
||||
EADDRNOTAVAIL = Errno(syscall.EADDRNOTAVAIL)
|
||||
EAFNOSUPPORT = Errno(syscall.EAFNOSUPPORT)
|
||||
EAGAIN = Errno(syscall.EAGAIN)
|
||||
EALREADY = Errno(syscall.EALREADY)
|
||||
EBADF = Errno(syscall.EBADF)
|
||||
EBUSY = Errno(syscall.EBUSY)
|
||||
ECANCELED = Errno(syscall.ECANCELED)
|
||||
ECONNABORTED = Errno(syscall.ECONNABORTED)
|
||||
ECONNREFUSED = Errno(syscall.ECONNREFUSED)
|
||||
ECONNRESET = Errno(syscall.ECONNRESET)
|
||||
EDESTADDRREQ = Errno(syscall.EDESTADDRREQ)
|
||||
EEXIST = Errno(syscall.EEXIST)
|
||||
EFAULT = Errno(syscall.EFAULT)
|
||||
EFBIG = Errno(syscall.EFBIG)
|
||||
EHOSTUNREACH = Errno(syscall.EHOSTUNREACH)
|
||||
EINTR = Errno(syscall.EINTR)
|
||||
EINVAL = Errno(syscall.EINVAL)
|
||||
EIO = Errno(syscall.EIO)
|
||||
EISCONN = Errno(syscall.EISCONN)
|
||||
EISDIR = Errno(syscall.EISDIR)
|
||||
ELOOP = Errno(syscall.ELOOP)
|
||||
EMFILE = Errno(syscall.EMFILE)
|
||||
EMSGSIZE = Errno(syscall.EMSGSIZE)
|
||||
ENAMETOOLONG = Errno(syscall.ENAMETOOLONG)
|
||||
ENETDOWN = Errno(syscall.ENETDOWN)
|
||||
ENETUNREACH = Errno(syscall.ENETUNREACH)
|
||||
ENFILE = Errno(syscall.ENFILE)
|
||||
ENOBUFS = Errno(syscall.ENOBUFS)
|
||||
ENODEV = Errno(syscall.ENODEV)
|
||||
ENOENT = Errno(syscall.ENOENT)
|
||||
ENOMEM = Errno(syscall.ENOMEM)
|
||||
ENOPROTOOPT = Errno(syscall.ENOPROTOOPT)
|
||||
ENOSPC = Errno(syscall.ENOSPC)
|
||||
ENOSYS = Errno(syscall.ENOSYS)
|
||||
ENOTCONN = Errno(syscall.ENOTCONN)
|
||||
ENOTDIR = Errno(syscall.ENOTDIR)
|
||||
ENOTEMPTY = Errno(syscall.ENOTEMPTY)
|
||||
ENOTSOCK = Errno(syscall.ENOTSOCK)
|
||||
ENOTSUP = Errno(syscall.ENOTSUP)
|
||||
EOVERFLOW = Errno(syscall.EOVERFLOW)
|
||||
EPERM = Errno(syscall.EPERM)
|
||||
EPIPE = Errno(syscall.EPIPE)
|
||||
EPROTO = Errno(syscall.EPROTO)
|
||||
EPROTONOSUPPORT = Errno(syscall.EPROTONOSUPPORT)
|
||||
EPROTOTYPE = Errno(syscall.EPROTOTYPE)
|
||||
ERANGE = Errno(syscall.ERANGE)
|
||||
EROFS = Errno(syscall.EROFS)
|
||||
ESHUTDOWN = Errno(syscall.ESHUTDOWN)
|
||||
ESPIPE = Errno(syscall.ESPIPE)
|
||||
ESRCH = Errno(syscall.ESRCH)
|
||||
ETIMEDOUT = Errno(syscall.ETIMEDOUT)
|
||||
ETXTBSY = Errno(syscall.ETXTBSY)
|
||||
EXDEV = Errno(syscall.EXDEV)
|
||||
ENXIO = Errno(syscall.ENXIO)
|
||||
EMLINK = Errno(syscall.EMLINK)
|
||||
EHOSTDOWN = Errno(syscall.EHOSTDOWN)
|
||||
ENOTTY = Errno(syscall.ENOTTY)
|
||||
//EFTYPE = Errno(syscall.EFTYPE)
|
||||
EILSEQ = Errno(syscall.EILSEQ)
|
||||
ESOCKTNOSUPPORT = Errno(syscall.ESOCKTNOSUPPORT)
|
||||
)
|
||||
|
||||
const (
|
||||
EAI_ADDRFAMILY = Errno(net.EAI_ADDRFAMILY)
|
||||
EAI_AGAIN = Errno(net.EAI_AGAIN)
|
||||
EAI_BADFLAGS = Errno(net.EAI_BADFLAGS)
|
||||
EAI_BADHINTS = Errno(net.EAI_BADHINTS)
|
||||
EAI_FAIL = Errno(net.EAI_FAIL)
|
||||
EAI_FAMILY = Errno(net.EAI_FAMILY)
|
||||
EAI_MEMORY = Errno(net.EAI_MEMORY)
|
||||
EAI_NODATA = Errno(net.EAI_NODATA)
|
||||
EAI_NONAME = Errno(net.EAI_NONAME)
|
||||
EAI_OVERFLOW = Errno(net.EAI_OVERFLOW)
|
||||
EAI_PROTOCOL = Errno(net.EAI_PROTOCOL)
|
||||
EAI_SERVICE = Errno(net.EAI_SERVICE)
|
||||
EAI_SOCKTYPE = Errno(net.EAI_SOCKTYPE)
|
||||
)
|
||||
|
||||
const (
|
||||
EAI_CANCELED Errno = -3003
|
||||
ECHARSET Errno = -4080
|
||||
ENONET Errno = -4056
|
||||
UNKNOWN Errno = -4094
|
||||
EOF Errno = -4095
|
||||
EREMOTEIO Errno = -4030
|
||||
ERRNO_MAX Errno = EOF - 1
|
||||
)
|
||||
|
||||
type Errno c.Int
|
||||
|
||||
//go:linkname TranslateSysError C.uv_translate_sys_error
|
||||
func TranslateSysError(sysErrno c.Int) Errno
|
||||
|
||||
//go:linkname Strerror C.uv_strerror
|
||||
func Strerror(err Errno) *c.Char
|
||||
|
||||
//go:linkname StrerrorR C.uv_strerror_r
|
||||
func StrerrorR(err Errno, buf *c.Char, bufLen uintptr) *c.Char
|
||||
|
||||
//go:linkname ErrName C.uv_err_name
|
||||
func ErrName(err Errno) *c.Char
|
||||
|
||||
//go:linkname ErrNameR C.uv_err_name_r
|
||||
func ErrNameR(err Errno, buf *c.Char, bufLen uintptr) *c.Char
|
||||
307
c/libuv/fs.go
307
c/libuv/fs.go
@@ -1,307 +0,0 @@
|
||||
package libuv
|
||||
|
||||
import (
|
||||
_ "unsafe"
|
||||
|
||||
"github.com/goplus/llgo/c"
|
||||
)
|
||||
|
||||
const (
|
||||
FS_UNKNOWN FsType = -1
|
||||
FS_CUSTOM FsType = 0
|
||||
FS_OPEN FsType = 1
|
||||
FS_CLOSE FsType = 2
|
||||
FS_READ FsType = 3
|
||||
FS_WRITE FsType = 4
|
||||
FS_SENDFILE FsType = 5
|
||||
FS_STAT FsType = 6
|
||||
FS_LSTAT FsType = 7
|
||||
FS_FSTAT FsType = 8
|
||||
FS_FTRUNCATE FsType = 9
|
||||
FS_UTIME FsType = 10
|
||||
FS_FUTIME FsType = 11
|
||||
FS_ACCESS FsType = 12
|
||||
FS_CHMOD FsType = 13
|
||||
FS_FCHMOD FsType = 14
|
||||
FS_FSYNC FsType = 15
|
||||
FS_FDATASYNC FsType = 16
|
||||
FS_UNLINK FsType = 17
|
||||
FS_RMDIR FsType = 18
|
||||
FS_MKDIR FsType = 19
|
||||
FS_MKDTEMP FsType = 20
|
||||
FS_RENAME FsType = 21
|
||||
FS_SCANDIR FsType = 22
|
||||
FS_LINK FsType = 23
|
||||
FS_SYMLINK FsType = 24
|
||||
FS_READLINK FsType = 25
|
||||
FS_CHOWN FsType = 26
|
||||
FS_FCHOWN FsType = 27
|
||||
FS_REALPATH FsType = 28
|
||||
FS_COPYFILE FsType = 29
|
||||
FS_LCHOWN FsType = 30
|
||||
FS_OPENDIR FsType = 31
|
||||
FS_READDIR FsType = 32
|
||||
FS_CLOSEDIR FsType = 33
|
||||
FS_STATFS FsType = 34
|
||||
FS_MKSTEMP FsType = 35
|
||||
FS_LUTIME FsType = 36
|
||||
)
|
||||
|
||||
const (
|
||||
DirentUnknown DirentType = iota
|
||||
DirentFile
|
||||
DirentDir
|
||||
DirentLink
|
||||
DirentFifo
|
||||
DirentSocket
|
||||
DirentChar
|
||||
DirentBlock
|
||||
)
|
||||
|
||||
type FsType c.Int
|
||||
|
||||
type DirentType c.Int
|
||||
|
||||
type File c.Int
|
||||
|
||||
// ----------------------------------------------
|
||||
|
||||
/* Handle types. */
|
||||
|
||||
type Fs struct {
|
||||
Unused [440]byte
|
||||
}
|
||||
|
||||
type FsEvent struct {
|
||||
Unused [0]byte
|
||||
}
|
||||
|
||||
type FsPoll struct {
|
||||
Unused [0]byte
|
||||
}
|
||||
|
||||
type Dirent struct {
|
||||
Name *c.Char
|
||||
Type DirentType
|
||||
}
|
||||
|
||||
type Stat struct {
|
||||
Unused [0]byte
|
||||
}
|
||||
|
||||
// ----------------------------------------------
|
||||
|
||||
/* Function type */
|
||||
|
||||
// llgo:type C
|
||||
type FsCb func(req *Fs)
|
||||
|
||||
// llgo:type C
|
||||
type FsEventCb func(handle *FsEvent, filename *c.Char, events c.Int, status c.Int)
|
||||
|
||||
// llgo:type C
|
||||
type FsPollCb func(handle *FsPoll, status c.Int, events c.Int)
|
||||
|
||||
// ----------------------------------------------
|
||||
|
||||
/* Fs related function and method */
|
||||
|
||||
// llgo:link (*Fs).GetType C.uv_fs_get_type
|
||||
func (req *Fs) GetType() FsType {
|
||||
return 0
|
||||
}
|
||||
|
||||
// llgo:link (*Fs).GetPath C.uv_fs_get_path
|
||||
func (req *Fs) GetPath() *c.Char {
|
||||
return nil
|
||||
}
|
||||
|
||||
// llgo:link (*Fs).GetResult C.uv_fs_get_result
|
||||
func (req *Fs) GetResult() c.Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
// llgo:link (*Fs).GetPtr C.uv_fs_get_ptr
|
||||
func (req *Fs) GetPtr() c.Pointer {
|
||||
return nil
|
||||
}
|
||||
|
||||
// llgo:link (*Fs).GetSystemError C.uv_fs_get_system_error
|
||||
func (req *Fs) GetSystemError() c.Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
// llgo:link (*Fs).GetStatBuf C.uv_fs_get_statbuf
|
||||
func (req *Fs) GetStatBuf() *Stat {
|
||||
return nil
|
||||
}
|
||||
|
||||
// llgo:link (*Fs).ReqCleanup C.uv_fs_req_cleanup
|
||||
func (req *Fs) ReqCleanup() {
|
||||
// No return value needed for this method
|
||||
}
|
||||
|
||||
//go:linkname FsOpen C.uv_fs_open
|
||||
func FsOpen(loop *Loop, req *Fs, path *c.Char, flags c.Int, mode c.Int, cb FsCb) c.Int
|
||||
|
||||
//go:linkname FsClose C.uv_fs_close
|
||||
func FsClose(loop *Loop, req *Fs, file File, cb FsCb) c.Int
|
||||
|
||||
//go:linkname FsRead C.uv_fs_read
|
||||
func FsRead(loop *Loop, req *Fs, file File, bufs *Buf, nbufs c.Uint, offset c.LongLong, cb FsCb) c.Int
|
||||
|
||||
//go:linkname FsWrite C.uv_fs_write
|
||||
func FsWrite(loop *Loop, req *Fs, file File, bufs *Buf, nbufs c.Uint, offset c.LongLong, cb FsCb) c.Int
|
||||
|
||||
//go:linkname FsUnlink C.uv_fs_unlink
|
||||
func FsUnlink(loop *Loop, req *Fs, path *c.Char, cb FsCb) c.Int
|
||||
|
||||
//go:linkname FsMkdir C.uv_fs_mkdir
|
||||
func FsMkdir(loop *Loop, req *Fs, path *c.Char, mode c.Int, cb FsCb) c.Int
|
||||
|
||||
//go:linkname FsMkdtemp C.uv_fs_mkdtemp
|
||||
func FsMkdtemp(loop *Loop, req *Fs, tpl *c.Char, cb FsCb) c.Int
|
||||
|
||||
//go:linkname FsMkStemp C.uv_fs_mkstemp
|
||||
func FsMkStemp(loop *Loop, req *Fs, tpl *c.Char, cb FsCb) c.Int
|
||||
|
||||
//go:linkname FsRmdir C.uv_fs_rmdir
|
||||
func FsRmdir(loop *Loop, req *Fs, path *c.Char, cb FsCb) c.Int
|
||||
|
||||
//go:linkname FsStat C.uv_fs_stat
|
||||
func FsStat(loop *Loop, req *Fs, path *c.Char, cb FsCb) c.Int
|
||||
|
||||
//go:linkname FsFstat C.uv_fs_fstat
|
||||
func FsFstat(loop *Loop, req *Fs, file File, cb FsCb) c.Int
|
||||
|
||||
//go:linkname FsRename C.uv_fs_rename
|
||||
func FsRename(loop *Loop, req *Fs, path *c.Char, newPath *c.Char, cb FsCb) c.Int
|
||||
|
||||
//go:linkname FsFsync C.uv_fs_fsync
|
||||
func FsFsync(loop *Loop, req *Fs, file File, cb FsCb) c.Int
|
||||
|
||||
//go:linkname FsFdatasync C.uv_fs_fdatasync
|
||||
func FsFdatasync(loop *Loop, req *Fs, file File, cb FsCb) c.Int
|
||||
|
||||
//go:linkname FsFtruncate C.uv_fs_ftruncate
|
||||
func FsFtruncate(loop *Loop, req *Fs, file File, offset c.LongLong, cb FsCb) c.Int
|
||||
|
||||
//go:linkname FsSendfile C.uv_fs_sendfile
|
||||
func FsSendfile(loop *Loop, req *Fs, outFd c.Int, inFd c.Int, inOffset c.LongLong, length c.Int, cb FsCb) c.Int
|
||||
|
||||
//go:linkname FsAccess C.uv_fs_access
|
||||
func FsAccess(loop *Loop, req *Fs, path *c.Char, flags c.Int, cb FsCb) c.Int
|
||||
|
||||
//go:linkname FsChmod C.uv_fs_chmod
|
||||
func FsChmod(loop *Loop, req *Fs, path *c.Char, mode c.Int, cb FsCb) c.Int
|
||||
|
||||
//go:linkname FsFchmod C.uv_fs_fchmod
|
||||
func FsFchmod(loop *Loop, req *Fs, file File, mode c.Int, cb FsCb) c.Int
|
||||
|
||||
//go:linkname FsUtime C.uv_fs_utime
|
||||
func FsUtime(loop *Loop, req *Fs, path *c.Char, atime c.Int, mtime c.Int, cb FsCb) c.Int
|
||||
|
||||
//go:linkname FsFutime C.uv_fs_futime
|
||||
func FsFutime(loop *Loop, req *Fs, file File, atime c.Int, mtime c.Int, cb FsCb) c.Int
|
||||
|
||||
//go:linkname FsLutime C.uv_fs_lutime
|
||||
func FsLutime(loop *Loop, req *Fs, path *c.Char, atime c.Int, mtime c.Int, cb FsCb) c.Int
|
||||
|
||||
//go:linkname FsLink C.uv_fs_link
|
||||
func FsLink(loop *Loop, req *Fs, path *c.Char, newPath *c.Char, cb FsCb) c.Int
|
||||
|
||||
//go:linkname FsSymlink C.uv_fs_symlink
|
||||
func FsSymlink(loop *Loop, req *Fs, path *c.Char, newPath *c.Char, flags c.Int, cb FsCb) c.Int
|
||||
|
||||
//go:linkname FsReadlink C.uv_fs_read
|
||||
func FsReadlink(loop *Loop, req *Fs, path *c.Char, cb FsCb) c.Int
|
||||
|
||||
//go:linkname FsRealpath C.uv_fs_realpath
|
||||
func FsRealpath(loop *Loop, req *Fs, path *c.Char, cb FsCb) c.Int
|
||||
|
||||
//go:linkname FsCopyfile C.uv_fs_copyfile
|
||||
func FsCopyfile(loop *Loop, req *Fs, path *c.Char, newPath *c.Char, flags c.Int, cb FsCb) c.Int
|
||||
|
||||
//go:linkname FsScandir C.uv_fs_scandir
|
||||
func FsScandir(loop *Loop, req *Fs, path *c.Char, flags c.Int, cb FsCb) c.Int
|
||||
|
||||
//go:linkname FsScandirNext C.uv_fs_scandir_next
|
||||
func FsScandirNext(req *Fs, ent *Dirent) c.Int
|
||||
|
||||
//go:linkname FsOpenDir C.uv_fs_opendir
|
||||
func FsOpenDir(loop *Loop, req *Fs, path *c.Char, cb FsCb) c.Int
|
||||
|
||||
//go:linkname FsReaddir C.uv_fs_readdir
|
||||
func FsReaddir(loop *Loop, req *Fs, dir c.Int, cb FsCb) c.Int
|
||||
|
||||
//go:linkname FsCloseDir C.uv_fs_closedir
|
||||
func FsCloseDir(loop *Loop, req *Fs) c.Int
|
||||
|
||||
//go:linkname FsStatfs C.uv_fs_statfs
|
||||
func FsStatfs(loop *Loop, req *Fs, path *c.Char, cb FsCb) c.Int
|
||||
|
||||
//go:linkname FsChown C.uv_fs_chown
|
||||
func FsChown(loop *Loop, req *Fs, path *c.Char, uid c.Int, gid c.Int, cb FsCb) c.Int
|
||||
|
||||
//go:linkname FsFchown C.uv_fs_fchown
|
||||
func FsFchown(loop *Loop, req *Fs, file File, uid c.Int, gid c.Int, cb FsCb) c.Int
|
||||
|
||||
//go:linkname FsLchown C.uv_fs_lchown
|
||||
func FsLchown(loop *Loop, req *Fs, path *c.Char, uid c.Int, gid c.Int, cb FsCb) c.Int
|
||||
|
||||
//go:linkname FsLstat C.uv_fs_lstat
|
||||
func FsLstat(loop *Loop, req *Fs, path *c.Char, cb FsCb) c.Int
|
||||
|
||||
// ----------------------------------------------
|
||||
|
||||
/* FsEvent related function and method */
|
||||
|
||||
//go:linkname FsEventInit C.uv_fs_event_init
|
||||
func FsEventInit(loop *Loop, handle *FsEvent) c.Int
|
||||
|
||||
// llgo:link (*FsEvent).Start C.uv_fs_event_start
|
||||
func (handle *FsEvent) Start(cb FsEventCb, path *c.Char, flags c.Int) c.Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
// llgo:link (*FsEvent).Stop C.uv_fs_event_stop
|
||||
func (handle *FsEvent) Stop() c.Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
// llgo:link (*FsEvent).Close C.uv_fs_event_close
|
||||
func (handle *FsEvent) Close() c.Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
// llgo:link (*FsEvent).Getpath C.uv_fs_event_getpath
|
||||
func (handle *FsEvent) Getpath() *c.Char {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ----------------------------------------------
|
||||
|
||||
/* FsPoll related function and method */
|
||||
|
||||
//go:linkname FsPollInit C.uv_fs_poll_init
|
||||
func FsPollInit(loop *Loop, handle *FsPoll) c.Int
|
||||
|
||||
// llgo:link (*FsPoll).Start C.uv_fs_poll_start
|
||||
func (handle *FsPoll) Start(cb FsPollCb, path *c.Char, interval uint) c.Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
// llgo:link (*FsPoll).Stop C.uv_fs_poll_stop
|
||||
func (handle *FsPoll) Stop() c.Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
// llgo:link (*FsPoll).Close C.uv_fs_poll_close
|
||||
func (handle *FsPoll) Close() c.Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
// llgo:link (*FsPoll).GetPath C.uv_fs_poll_getpath
|
||||
func (handle *FsPoll) GetPath() *c.Char {
|
||||
return nil
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package libuv
|
||||
|
||||
import (
|
||||
_ "unsafe"
|
||||
|
||||
"github.com/goplus/llgo/c"
|
||||
)
|
||||
|
||||
/* Handle types. */
|
||||
|
||||
type Idle struct {
|
||||
Unused [120]byte
|
||||
}
|
||||
|
||||
/* Function type */
|
||||
|
||||
// llgo:type C
|
||||
type IdleCb func(idle *Idle)
|
||||
|
||||
//go:linkname InitIdle C.uv_idle_init
|
||||
func InitIdle(loop *Loop, idle *Idle) c.Int
|
||||
|
||||
// llgo:link (*Idle).Start C.uv_idle_start
|
||||
func (idle *Idle) Start(idleCb IdleCb) c.Int { return 0 }
|
||||
|
||||
// llgo:link (*Idle).Stop C.uv_idle_stop
|
||||
func (idle *Idle) Stop() c.Int { return 0 }
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user