diff --git a/_test/bdwgc.go b/_test/bdwgc.go index 01bdcb2f..17d2759f 100644 --- a/_test/bdwgc.go +++ b/_test/bdwgc.go @@ -5,7 +5,7 @@ import ( "github.com/goplus/llgo/_test/testing" "github.com/goplus/llgo/c" - "github.com/goplus/llgo/internal/runtime/bdwgc" + "github.com/goplus/llgo/c/bdwgc" ) // ------ Test malloc ------ diff --git a/internal/runtime/bdwgc/bdwgc.go b/c/bdwgc/bdwgc.go similarity index 95% rename from internal/runtime/bdwgc/bdwgc.go rename to c/bdwgc/bdwgc.go index 6b947962..f939dffb 100644 --- a/internal/runtime/bdwgc/bdwgc.go +++ b/c/bdwgc/bdwgc.go @@ -23,7 +23,7 @@ import ( ) const ( - LLGoPackage = "link: $LLGO_LIB_BDWGC; $(pkg-config --libs bdw-gc); -lgc" + LLGoPackage = "link: $(pkg-config --libs bdw-gc); -lgc" ) // ----------------------------------------------------------------------------- @@ -99,3 +99,5 @@ func StartIncrementalCollection() //go:linkname CollectALittle C.GC_collect_a_little func CollectALittle() + +// ----------------------------------------------------------------------------- diff --git a/internal/runtime/bdwgc/llgo_autogen.lla b/c/bdwgc/llgo_autogen.lla similarity index 100% rename from internal/runtime/bdwgc/llgo_autogen.lla rename to c/bdwgc/llgo_autogen.lla diff --git a/c/c.go b/c/c.go index a38958ed..ed2d4cff 100644 --- a/c/c.go +++ b/c/c.go @@ -77,6 +77,9 @@ func Memset(s Pointer, c Int, n uintptr) Pointer //go:linkname GoStringData llgo.stringData func GoStringData(string) *Char +//go:linkname GoDeferData llgo.deferData +func GoDeferData() Pointer + // ----------------------------------------------------------------------------- //go:linkname AllocaSigjmpBuf llgo.sigjmpbuf diff --git a/cl/_testdata/print/in.go b/cl/_testdata/print/in.go index c258a02e..99682586 100644 --- a/cl/_testdata/print/in.go +++ b/cl/_testdata/print/in.go @@ -3,7 +3,7 @@ package main import ( "unsafe" - "github.com/goplus/llgo/internal/runtime/c" + "github.com/goplus/llgo/c" ) func gwrite(b []byte) { diff --git a/cl/_testdata/vargs/in.go b/cl/_testdata/vargs/in.go index 417911cb..8f7c3ac4 100644 --- a/cl/_testdata/vargs/in.go +++ b/cl/_testdata/vargs/in.go @@ -1,6 +1,6 @@ package main -import "github.com/goplus/llgo/internal/runtime/c" +import "github.com/goplus/llgo/c" func test(a ...any) { for _, v := range a { diff --git a/cl/_testlibc/defer/in.go b/cl/_testlibc/defer/in.go index ab8362c3..592ac32d 100644 --- a/cl/_testlibc/defer/in.go +++ b/cl/_testlibc/defer/in.go @@ -1,6 +1,6 @@ package main -import "github.com/goplus/llgo/internal/runtime/c" +import "github.com/goplus/llgo/c" func f(s string) bool { return len(s) > 2 diff --git a/cl/_testrt/alloca/in.go b/cl/_testrt/alloca/in.go index 95a3dcf1..c16d07b8 100644 --- a/cl/_testrt/alloca/in.go +++ b/cl/_testrt/alloca/in.go @@ -1,7 +1,7 @@ package main import ( - "github.com/goplus/llgo/internal/runtime/c" + "github.com/goplus/llgo/c" ) func main() { diff --git a/cl/_testrt/allocstr/in.go b/cl/_testrt/allocstr/in.go index 41bcdd61..d97577d2 100644 --- a/cl/_testrt/allocstr/in.go +++ b/cl/_testrt/allocstr/in.go @@ -1,7 +1,7 @@ package main import ( - "github.com/goplus/llgo/internal/runtime/c" + "github.com/goplus/llgo/c" ) func hello() string { diff --git a/cl/_testrt/any/in.go b/cl/_testrt/any/in.go index 4120c735..0edaadad 100644 --- a/cl/_testrt/any/in.go +++ b/cl/_testrt/any/in.go @@ -1,7 +1,7 @@ package main import ( - "github.com/goplus/llgo/internal/runtime/c" + "github.com/goplus/llgo/c" ) func hi(a any) *c.Char { diff --git a/cl/_testrt/callback/in.go b/cl/_testrt/callback/in.go index 833bb900..5bd17e57 100644 --- a/cl/_testrt/callback/in.go +++ b/cl/_testrt/callback/in.go @@ -1,7 +1,7 @@ package main import ( - "github.com/goplus/llgo/internal/runtime/c" + "github.com/goplus/llgo/c" ) func callback(msg *c.Char, f func(*c.Char)) { diff --git a/cl/_testrt/cast/in.go b/cl/_testrt/cast/in.go index 7d3a846e..89196f62 100644 --- a/cl/_testrt/cast/in.go +++ b/cl/_testrt/cast/in.go @@ -1,6 +1,6 @@ package main -//"github.com/goplus/llgo/internal/runtime/c" +//"github.com/goplus/llgo/c" func main() { cvt64to8(0, 0) diff --git a/cl/_testrt/closure/in.go b/cl/_testrt/closure/in.go index 0db4b4cd..85eb0a4e 100644 --- a/cl/_testrt/closure/in.go +++ b/cl/_testrt/closure/in.go @@ -1,7 +1,7 @@ package main import ( - "github.com/goplus/llgo/internal/runtime/c" + "github.com/goplus/llgo/c" ) func main() { diff --git a/cl/_testrt/gblarray/in.go b/cl/_testrt/gblarray/in.go index dcb43160..067f60ca 100644 --- a/cl/_testrt/gblarray/in.go +++ b/cl/_testrt/gblarray/in.go @@ -1,8 +1,8 @@ package main import ( + "github.com/goplus/llgo/c" "github.com/goplus/llgo/internal/abi" - "github.com/goplus/llgo/internal/runtime/c" ) func Basic(kind abi.Kind) *abi.Type { diff --git a/cl/_testrt/index/in.go b/cl/_testrt/index/in.go index af7c83e2..db5019e1 100644 --- a/cl/_testrt/index/in.go +++ b/cl/_testrt/index/in.go @@ -1,6 +1,6 @@ package main -import "github.com/goplus/llgo/internal/runtime/c" +import "github.com/goplus/llgo/c" type point struct { x int diff --git a/cl/_testrt/intgen/in.go b/cl/_testrt/intgen/in.go index 7e43a06b..12a5b034 100644 --- a/cl/_testrt/intgen/in.go +++ b/cl/_testrt/intgen/in.go @@ -1,7 +1,7 @@ package main import ( - "github.com/goplus/llgo/internal/runtime/c" + "github.com/goplus/llgo/c" ) type generator struct { diff --git a/cl/_testrt/linkname/in.go b/cl/_testrt/linkname/in.go index cc4f836e..26c3b75f 100644 --- a/cl/_testrt/linkname/in.go +++ b/cl/_testrt/linkname/in.go @@ -3,8 +3,8 @@ package main import ( _ "unsafe" + "github.com/goplus/llgo/c" _ "github.com/goplus/llgo/cl/internal/linktarget" - "github.com/goplus/llgo/internal/runtime/c" ) //go:linkname print github.com/goplus/llgo/cl/internal/linktarget.F diff --git a/cl/_testrt/map/in.go b/cl/_testrt/map/in.go index 34b98520..826ba8aa 100644 --- a/cl/_testrt/map/in.go +++ b/cl/_testrt/map/in.go @@ -1,7 +1,7 @@ package main import ( - "github.com/goplus/llgo/internal/runtime/c" + "github.com/goplus/llgo/c" ) func main() { diff --git a/cl/_testrt/named/in.go b/cl/_testrt/named/in.go index 9a958d8d..658cdfe7 100644 --- a/cl/_testrt/named/in.go +++ b/cl/_testrt/named/in.go @@ -1,6 +1,6 @@ package main -import "github.com/goplus/llgo/internal/runtime/c" +import "github.com/goplus/llgo/c" type mSpanList struct { first *mspan diff --git a/cl/_testrt/qsort/in.go b/cl/_testrt/qsort/in.go index b4c65417..8fa4f775 100644 --- a/cl/_testrt/qsort/in.go +++ b/cl/_testrt/qsort/in.go @@ -3,7 +3,7 @@ package main import ( "unsafe" - "github.com/goplus/llgo/internal/runtime/c" + "github.com/goplus/llgo/c" ) //go:linkname qsort C.qsort diff --git a/cl/_testrt/result/in.go b/cl/_testrt/result/in.go index e4e9ec7d..15bcb81b 100644 --- a/cl/_testrt/result/in.go +++ b/cl/_testrt/result/in.go @@ -1,7 +1,7 @@ package main import ( - "github.com/goplus/llgo/internal/runtime/c" + "github.com/goplus/llgo/c" ) func main() { diff --git a/cl/_testrt/sum/in.go b/cl/_testrt/sum/in.go index 435310bd..c3536fa8 100644 --- a/cl/_testrt/sum/in.go +++ b/cl/_testrt/sum/in.go @@ -1,7 +1,7 @@ package main import ( - "github.com/goplus/llgo/internal/runtime/c" + "github.com/goplus/llgo/c" ) func sum(args ...int) (ret int) { diff --git a/cl/_testrt/unreachable/in.go b/cl/_testrt/unreachable/in.go index 3f62b8a8..8a6dbdc6 100644 --- a/cl/_testrt/unreachable/in.go +++ b/cl/_testrt/unreachable/in.go @@ -1,7 +1,7 @@ package main import ( - "github.com/goplus/llgo/internal/runtime/c" + "github.com/goplus/llgo/c" ) func foo() { diff --git a/cl/internal/linktarget/foo.go b/cl/internal/linktarget/foo.go index b3eb725c..fa89c8e8 100644 --- a/cl/internal/linktarget/foo.go +++ b/cl/internal/linktarget/foo.go @@ -1,7 +1,7 @@ package linktarget import ( - "github.com/goplus/llgo/internal/runtime/c" + "github.com/goplus/llgo/c" ) func F(a, b *c.Char) { diff --git a/internal/runtime/c/c.go b/internal/runtime/c/c.go deleted file mode 100644 index cea55d8b..00000000 --- a/internal/runtime/c/c.go +++ /dev/null @@ -1,91 +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 - -import "C" -import "unsafe" - -const ( - LLGoPackage = "decl" -) - -type ( - Char = int8 - Int = C.int - Pointer = unsafe.Pointer - FilePtr = unsafe.Pointer -) - -//go:linkname Str llgo.cstr -func Str(string) *Char - -// llgo:link Advance llgo.advance -func Advance[PtrT any](ptr PtrT, offset int) PtrT { return ptr } - -//go:linkname Alloca llgo.alloca -func Alloca(size uintptr) Pointer - -//go:linkname AllocaCStr llgo.allocaCStr -func AllocaCStr(s string) *Char - -//go:linkname GoDeferData llgo.deferData -func GoDeferData() Pointer - -//go:linkname Unreachable llgo.unreachable -func Unreachable() - -//go:linkname Exit C.exit -func Exit(Int) - -//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 Rand C.rand -func Rand() Int - -//go:linkname Malloc C.malloc -func Malloc(size uintptr) Pointer - -//go:linkname Free C.free -func Free(ptr 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 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 diff --git a/internal/runtime/c/c_default.go b/internal/runtime/c/c_default.go deleted file mode 100644 index 45286fe9..00000000 --- a/internal/runtime/c/c_default.go +++ /dev/null @@ -1,31 +0,0 @@ -//go:build !linux -// +build !linux - -/* - * 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 - -import _ "unsafe" - -//go:linkname Stdin __stdinp -var Stdin FilePtr - -//go:linkname Stdout __stdoutp -var Stdout FilePtr - -//go:linkname Stderr __stderrp -var Stderr FilePtr diff --git a/internal/runtime/c/c_linux.go b/internal/runtime/c/c_linux.go deleted file mode 100644 index 70cc9bea..00000000 --- a/internal/runtime/c/c_linux.go +++ /dev/null @@ -1,31 +0,0 @@ -//go:build linux -// +build linux - -/* - * 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 - -import _ "unsafe" - -//go:linkname Stdin stdin -var Stdin FilePtr - -//go:linkname Stdout stdout -var Stdout FilePtr - -//go:linkname Stderr stderr -var Stderr FilePtr diff --git a/internal/runtime/z_face.go b/internal/runtime/z_face.go index 7542aa5d..b81dc818 100644 --- a/internal/runtime/z_face.go +++ b/internal/runtime/z_face.go @@ -19,8 +19,8 @@ package runtime import ( "unsafe" + "github.com/goplus/llgo/c" "github.com/goplus/llgo/internal/abi" - "github.com/goplus/llgo/internal/runtime/c" ) type eface struct { diff --git a/internal/runtime/z_gc.go b/internal/runtime/z_gc.go index 3eb1c856..6f5a8d88 100644 --- a/internal/runtime/z_gc.go +++ b/internal/runtime/z_gc.go @@ -22,8 +22,8 @@ package runtime import ( "unsafe" - "github.com/goplus/llgo/internal/runtime/bdwgc" - "github.com/goplus/llgo/internal/runtime/c" + "github.com/goplus/llgo/c" + "github.com/goplus/llgo/c/bdwgc" ) // AllocU allocates uninitialized memory. diff --git a/internal/runtime/z_nogc.go b/internal/runtime/z_nogc.go index 1c591387..81261bd6 100644 --- a/internal/runtime/z_nogc.go +++ b/internal/runtime/z_nogc.go @@ -22,7 +22,7 @@ package runtime import ( "unsafe" - "github.com/goplus/llgo/internal/runtime/c" + "github.com/goplus/llgo/c" ) // AllocU allocates uninitialized memory. diff --git a/internal/runtime/z_print.go b/internal/runtime/z_print.go index 65a5a9a4..cbf9d83d 100644 --- a/internal/runtime/z_print.go +++ b/internal/runtime/z_print.go @@ -19,7 +19,7 @@ package runtime import ( "unsafe" - "github.com/goplus/llgo/internal/runtime/c" + "github.com/goplus/llgo/c" ) func PrintByte(v byte) { diff --git a/internal/runtime/z_rt.go b/internal/runtime/z_rt.go index 222c6e5c..9d9eea33 100644 --- a/internal/runtime/z_rt.go +++ b/internal/runtime/z_rt.go @@ -19,9 +19,9 @@ package runtime import ( "unsafe" + "github.com/goplus/llgo/c" "github.com/goplus/llgo/c/pthread" "github.com/goplus/llgo/internal/abi" - "github.com/goplus/llgo/internal/runtime/c" ) // ----------------------------------------------------------------------------- diff --git a/internal/runtime/z_slice.go b/internal/runtime/z_slice.go index f4711e47..f2934822 100644 --- a/internal/runtime/z_slice.go +++ b/internal/runtime/z_slice.go @@ -19,7 +19,7 @@ package runtime import ( "unsafe" - "github.com/goplus/llgo/internal/runtime/c" + "github.com/goplus/llgo/c" ) // ----------------------------------------------------------------------------- diff --git a/internal/runtime/z_string.go b/internal/runtime/z_string.go index e34ae730..da56b161 100644 --- a/internal/runtime/z_string.go +++ b/internal/runtime/z_string.go @@ -19,7 +19,7 @@ package runtime import ( "unsafe" - "github.com/goplus/llgo/internal/runtime/c" + "github.com/goplus/llgo/c" ) // -----------------------------------------------------------------------------