reorganize: consolidate demo directories
- Consolidate _demo, _pydemo, _embdemo into single _demo directory structure
- Organize demos by language: _demo/{go,py,c,embed}/
- Categorize demos based on imports:
- Python library demos (py imports) → _demo/py/
- C/C++ library demos (c/cpp imports) → _demo/c/
- Go-specific demos → _demo/go/
- Embedded demos → _demo/embed/
- Move C-related demos (asm*, cabi*, cgo*, linkname, targetsbuild) from go/ to c/
- Update all path references in README.md and GitHub workflows
- Improve demo organization and navigation as requested in #1256
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -106,8 +106,8 @@ import (
|
||||
"fmt"
|
||||
"unsafe"
|
||||
|
||||
"github.com/goplus/llgo/_demo/cgofull/pymod1"
|
||||
"github.com/goplus/llgo/_demo/cgofull/pymod2"
|
||||
"github.com/goplus/llgo/_demo/c/cgofull/pymod1"
|
||||
"github.com/goplus/llgo/_demo/c/cgofull/pymod2"
|
||||
)
|
||||
|
||||
//export go_callback_not_use_in_go
|
||||
@@ -3,7 +3,7 @@ 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/_demo/c/cppintf/foo"
|
||||
)
|
||||
|
||||
type Bar struct {
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"github.com/goplus/lib/c"
|
||||
"github.com/goplus/lib/c/math"
|
||||
"github.com/goplus/llgo/_demo/cppmintf/foo"
|
||||
"github.com/goplus/llgo/_demo/c/cppmintf/foo"
|
||||
)
|
||||
|
||||
type Bar struct {
|
||||
5
_demo/c/go.mod
Normal file
5
_demo/c/go.mod
Normal file
@@ -0,0 +1,5 @@
|
||||
module github.com/goplus/llgo/_demo/c
|
||||
|
||||
go 1.20
|
||||
|
||||
require github.com/goplus/lib v0.3.0
|
||||
2
_demo/c/go.sum
Normal file
2
_demo/c/go.sum
Normal file
@@ -0,0 +1,2 @@
|
||||
github.com/goplus/lib v0.3.0 h1:y0ZGb5Q/RikW1oMMB4Di7XIZIpuzh/7mlrR8HNbxXCA=
|
||||
github.com/goplus/lib v0.3.0/go.mod h1:SgJv3oPqLLHCu0gcL46ejOP3x7/2ry2Jtxu7ta32kp0=
|
||||
|
Before Width: | Height: | Size: 183 KiB After Width: | Height: | Size: 183 KiB |
@@ -36,7 +36,6 @@ loop: // parse command line arguments
|
||||
// build the Tokenizer via the tokenizer .bin file
|
||||
var tokenizer llama2.Tokenizer
|
||||
llama2.BuildTokenizer(&tokenizer, tokenizerPath, transformer.Config.VocabSize)
|
||||
|
||||
// build the Sampler
|
||||
var sampler llama2.Sampler
|
||||
llama2.BuildSampler(&sampler, transformer.Config.VocabSize, temperature, topp, rngSeed)
|
||||
5
_demo/embed/go.mod
Normal file
5
_demo/embed/go.mod
Normal file
@@ -0,0 +1,5 @@
|
||||
module github.com/goplus/llgo/_demo/embed
|
||||
|
||||
go 1.20
|
||||
|
||||
require github.com/goplus/lib v0.3.0
|
||||
2
_demo/embed/go.sum
Normal file
2
_demo/embed/go.sum
Normal file
@@ -0,0 +1,2 @@
|
||||
github.com/goplus/lib v0.3.0 h1:y0ZGb5Q/RikW1oMMB4Di7XIZIpuzh/7mlrR8HNbxXCA=
|
||||
github.com/goplus/lib v0.3.0/go.mod h1:SgJv3oPqLLHCu0gcL46ejOP3x7/2ry2Jtxu7ta32kp0=
|
||||
16
_demo/embed/hello-esp32/main.go
Normal file
16
_demo/embed/hello-esp32/main.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package main
|
||||
|
||||
import "github.com/goplus/lib/c"
|
||||
|
||||
func myprint(s *c.Char) {
|
||||
for i := 0; i < int(c.Strlen(s)); i++ {
|
||||
WriteByte(byte(c.Index(s, i)))
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
for {
|
||||
myprint(c.Str("hello world"))
|
||||
sleep(1)
|
||||
}
|
||||
}
|
||||
13
_demo/embed/hello-esp32/uart.go
Normal file
13
_demo/embed/hello-esp32/uart.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
_ "unsafe"
|
||||
|
||||
"github.com/goplus/lib/c"
|
||||
)
|
||||
|
||||
//go:linkname WriteByte C.board_uart_write_char
|
||||
func WriteByte(b byte)
|
||||
|
||||
//go:linkname sleep sleep
|
||||
func sleep(c c.Int)
|
||||
@@ -111,7 +111,7 @@ if [ $# -eq 1 ]; then
|
||||
done < "$target_file"
|
||||
else
|
||||
# Use targets from *.json files
|
||||
for target_file in ../../targets/*.json; do
|
||||
for target_file in ../../../targets/*.json; do
|
||||
# Extract target name from filename (remove path and .json extension)
|
||||
target=$(basename "$target_file" .json)
|
||||
targets_to_build+=("$target")
|
||||
@@ -127,9 +127,9 @@ for target in "${targets_to_build[@]}"; do
|
||||
continue
|
||||
fi
|
||||
|
||||
output=$(../../llgo.sh build -target $target -o hello.out . 2>&1)
|
||||
output=$(../../../llgo.sh build -target $target -o hello.elf . 2>&1)
|
||||
if [ $? -eq 0 ]; then
|
||||
echo ✅ $target `file hello.out`
|
||||
echo ✅ $target `file hello.elf`
|
||||
successful_targets+=("$target")
|
||||
else
|
||||
# Check if output contains warning messages
|
||||
6
_demo/embed/targetsbuild/empty.go
Normal file
6
_demo/embed/targetsbuild/empty.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package main
|
||||
|
||||
import _ "github.com/goplus/llgo/_demo/embed/targetsbuild/C"
|
||||
|
||||
func main() {
|
||||
}
|
||||
31
_demo/embed/write-esp32/main.go
Normal file
31
_demo/embed/write-esp32/main.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
_ "unsafe"
|
||||
|
||||
"github.com/goplus/lib/c"
|
||||
)
|
||||
|
||||
//go:linkname write C.write
|
||||
func write(c.Int, *c.Char, c.SizeT) int
|
||||
|
||||
func main() {
|
||||
buf := c.Malloc(6)
|
||||
c.Memset(buf, 0, 6)
|
||||
c.Strncpy((*c.Char)(buf), c.Str("abcde"), 5)
|
||||
|
||||
if c.Strcmp((*c.Char)(buf), c.Str("abcde")) == 0 {
|
||||
write(1, c.Str("pass strcmp"), 11)
|
||||
}
|
||||
|
||||
if byte(c.Index((*c.Char)(buf), 0)) == 'a' {
|
||||
write(1, c.Str("pass index"), 10)
|
||||
}
|
||||
|
||||
c.Memset(buf, c.Int('A'), 5)
|
||||
if c.Strcmp((*c.Char)(buf), c.Str("AAAAA")) == 0 {
|
||||
write(1, c.Str("pass memeset"), 11)
|
||||
}
|
||||
|
||||
write(1, (*c.Char)(buf), 5)
|
||||
}
|
||||
@@ -3,8 +3,8 @@ package main
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/goplus/llgo/_demo/async/async"
|
||||
"github.com/goplus/llgo/_demo/async/timeout"
|
||||
"github.com/goplus/llgo/_demo/go/async/async"
|
||||
"github.com/goplus/llgo/_demo/go/async/timeout"
|
||||
)
|
||||
|
||||
func Sleep(i int, d time.Duration) async.Future[int] {
|
||||
@@ -3,7 +3,7 @@ package timeout
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/goplus/llgo/_demo/async/async"
|
||||
"github.com/goplus/llgo/_demo/go/async/async"
|
||||
)
|
||||
|
||||
func Timeout(d time.Duration) async.Future[async.Void] {
|
||||
3
_demo/go/go.mod
Normal file
3
_demo/go/go.mod
Normal file
@@ -0,0 +1,3 @@
|
||||
module github.com/goplus/llgo/_demo/go
|
||||
|
||||
go 1.20
|
||||
0
_demo/go/go.sum
Normal file
0
_demo/go/go.sum
Normal file
12
_demo/py/callpy/callpy.go
Normal file
12
_demo/py/callpy/callpy.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/lib/py"
|
||||
"github.com/goplus/lib/py/math"
|
||||
"github.com/goplus/lib/py/std"
|
||||
)
|
||||
|
||||
func main() {
|
||||
x := math.Sqrt(py.Float(2)) // x = sqrt(2)
|
||||
std.Print(py.Str("sqrt(2) ="), x) // print("sqrt(2) =", x)
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
module github.com/goplus/llgo/_demo
|
||||
module github.com/goplus/llgo/_demo/py
|
||||
|
||||
go 1.20
|
||||
|
||||
22
_demo/py/matrix/matrix.go
Normal file
22
_demo/py/matrix/matrix.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/lib/py"
|
||||
"github.com/goplus/lib/py/numpy"
|
||||
"github.com/goplus/lib/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)
|
||||
}
|
||||
15
_demo/py/max/max.go
Normal file
15
_demo/py/max/max.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/lib/py"
|
||||
"github.com/goplus/lib/py/std"
|
||||
)
|
||||
|
||||
func main() {
|
||||
x := std.Max(py.Float(3.0), py.Float(9.0), py.Float(23.0), py.Float(100.0))
|
||||
std.Print(x)
|
||||
|
||||
list := py.List(3.0, 9.0, 23.0, 100.0)
|
||||
y := std.Max(std.Iter(list))
|
||||
std.Print(y)
|
||||
}
|
||||
10
_demo/py/pi/pi.go
Normal file
10
_demo/py/pi/pi.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/lib/c"
|
||||
"github.com/goplus/lib/py/math"
|
||||
)
|
||||
|
||||
func main() {
|
||||
c.Printf(c.Str("pi = %f\n"), math.Pi.Float64())
|
||||
}
|
||||
11
_demo/py/print/print.go
Normal file
11
_demo/py/print/print.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/lib/py"
|
||||
"github.com/goplus/lib/py/std"
|
||||
)
|
||||
|
||||
func main() {
|
||||
x := py.Float(3.14)
|
||||
std.Print(x)
|
||||
}
|
||||
13
_demo/py/statistics/statistics.go
Normal file
13
_demo/py/statistics/statistics.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/lib/c"
|
||||
"github.com/goplus/lib/py"
|
||||
"github.com/goplus/lib/py/statistics"
|
||||
)
|
||||
|
||||
func main() {
|
||||
list := py.List(1.0, 2.0, 3.0, 4.0, 4.0)
|
||||
mean := statistics.Mean(list)
|
||||
c.Printf(c.Str("mean(1, 2, 3, 4, 4) = %f\n"), mean.Float64())
|
||||
}
|
||||
16
_demo/py/tensor/tensor.go
Normal file
16
_demo/py/tensor/tensor.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/lib/py"
|
||||
"github.com/goplus/lib/py/std"
|
||||
"github.com/goplus/lib/py/torch"
|
||||
)
|
||||
|
||||
func main() {
|
||||
data := py.List(
|
||||
py.List(1.0, 2.0),
|
||||
py.List(3.0, 4.0),
|
||||
)
|
||||
x := torch.Tensor(data)
|
||||
std.Print(x)
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
package main
|
||||
|
||||
import _ "github.com/goplus/llgo/_demo/targetsbuild/C"
|
||||
|
||||
func main() {
|
||||
}
|
||||
Reference in New Issue
Block a user