doc: make doc testable
This commit is contained in:
10
doc/_readme/llgo_call_c/call_c.go
Normal file
10
doc/_readme/llgo_call_c/call_c.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package main
|
||||
|
||||
import _ "unsafe" // for go:linkname
|
||||
|
||||
//go:linkname Sqrt C.sqrt
|
||||
func Sqrt(x float64) float64
|
||||
|
||||
func main() {
|
||||
println("sqrt(2) =", Sqrt(2))
|
||||
}
|
||||
7
doc/_readme/llgo_call_cmath/call_cmath.go
Normal file
7
doc/_readme/llgo_call_cmath/call_cmath.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package main
|
||||
|
||||
import "github.com/goplus/llgo/c/math"
|
||||
|
||||
func main() {
|
||||
println("sqrt(2) =", math.Sqrt(2))
|
||||
}
|
||||
4
doc/_readme/llgo_call_py/call_math.py
Normal file
4
doc/_readme/llgo_call_py/call_math.py
Normal file
@@ -0,0 +1,4 @@
|
||||
import math
|
||||
|
||||
x = math.sqrt(2)
|
||||
print("sqrt =", x)
|
||||
12
doc/_readme/llgo_call_py/call_py.go
Normal file
12
doc/_readme/llgo_call_py/call_py.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/py"
|
||||
"github.com/goplus/llgo/py/math"
|
||||
"github.com/goplus/llgo/py/std"
|
||||
)
|
||||
|
||||
func main() {
|
||||
x := math.Sqrt(py.Float(2)) // x = sqrt(2)
|
||||
std.Print(py.Str("sqrt(2) ="), x) // print("sqrt(2) =", x)
|
||||
}
|
||||
22
doc/_readme/llgo_py_list/py_list.go
Normal file
22
doc/_readme/llgo_py_list/py_list.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/py"
|
||||
"github.com/goplus/llgo/py/numpy"
|
||||
"github.com/goplus/llgo/py/std"
|
||||
)
|
||||
|
||||
func main() {
|
||||
a := py.List(
|
||||
py.List(1.0, 2.0, 3.0),
|
||||
py.List(4.0, 5.0, 6.0),
|
||||
py.List(7.0, 8.0, 9.0),
|
||||
)
|
||||
b := py.List(
|
||||
py.List(9.0, 8.0, 7.0),
|
||||
py.List(6.0, 5.0, 4.0),
|
||||
py.List(3.0, 2.0, 1.0),
|
||||
)
|
||||
x := numpy.Add(a, b)
|
||||
std.Print(py.Str("a+b ="), x)
|
||||
}
|
||||
7
doc/_readme/llgo_simple/simple.go
Normal file
7
doc/_readme/llgo_simple/simple.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package main
|
||||
|
||||
import "github.com/goplus/llgo/c"
|
||||
|
||||
func main() {
|
||||
c.Printf(c.Str("Hello world\n"))
|
||||
}
|
||||
8
doc/_readme/scripts/install_llgo.sh
Normal file
8
doc/_readme/scripts/install_llgo.sh
Normal file
@@ -0,0 +1,8 @@
|
||||
# shellcheck disable=all
|
||||
git clone https://github.com/goplus/llgo.git
|
||||
cd llgo
|
||||
go install -v ./cmd/...
|
||||
go install -v ./chore/... # compile all tools except pydump
|
||||
cd chore/_xtool
|
||||
llgo install ./... # compile pydump
|
||||
go install github.com/goplus/hdq/chore/pysigfetch@v0.8.1 # compile pysigfetch
|
||||
5
doc/_readme/scripts/install_macos.sh
Normal file
5
doc/_readme/scripts/install_macos.sh
Normal file
@@ -0,0 +1,5 @@
|
||||
# shellcheck disable=all
|
||||
brew update
|
||||
brew install llvm@18 pkg-config bdw-gc openssl cjson
|
||||
brew install python@3.12 # optional
|
||||
go install -v github.com/goplus/llgo/cmd/llgo@latest
|
||||
7
doc/_readme/scripts/install_ubuntu.sh
Normal file
7
doc/_readme/scripts/install_ubuntu.sh
Normal file
@@ -0,0 +1,7 @@
|
||||
# shellcheck disable=all
|
||||
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
|
||||
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 python3.12-dev
|
||||
sudo apt-get install -y python3.12-dev # optional
|
||||
go install -v github.com/goplus/llgo/cmd/llgo@latest
|
||||
10
doc/_readme/scripts/run.sh
Normal file
10
doc/_readme/scripts/run.sh
Normal file
@@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
cd ./doc/_readme/ || exit 1
|
||||
llgo build -v ./...
|
||||
pip3 install --user numpy
|
||||
for dir in ./*/; do
|
||||
if grep -q "func main()" "$dir"/*.go 2>/dev/null; then
|
||||
echo "Running examples in $dir"
|
||||
llgo run "$dir"
|
||||
fi
|
||||
done
|
||||
Reference in New Issue
Block a user