11
README.md
11
README.md
@@ -185,6 +185,17 @@ Here are some examples related to Go syntax:
|
||||
* [goroutine](_demo/goroutine/goroutine.go): goroutine demo
|
||||
|
||||
|
||||
### Garbage Collection (GC)
|
||||
|
||||
By default, LLGo implements `gc` based on [bdwgc](https://www.hboehm.info/gc/).
|
||||
|
||||
However, you can disable gc by specifying the `nogc` tag. For example:
|
||||
|
||||
```sh
|
||||
llgo run -tags nogc .
|
||||
```
|
||||
|
||||
|
||||
## Go packages support
|
||||
|
||||
Here are the Go packages that can be imported correctly:
|
||||
|
||||
@@ -1,6 +1,22 @@
|
||||
//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"
|
||||
|
||||
16
c/c_linux.go
16
c/c_linux.go
@@ -1,6 +1,22 @@
|
||||
//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"
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* 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 (
|
||||
|
||||
@@ -1,6 +1,22 @@
|
||||
//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"
|
||||
|
||||
@@ -1,6 +1,22 @@
|
||||
//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"
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
package runtime
|
||||
|
||||
type errorString string
|
||||
|
||||
func (e errorString) RuntimeError() {}
|
||||
|
||||
func (e errorString) Error() string {
|
||||
return "runtime error: " + string(e)
|
||||
}
|
||||
|
||||
func AssertRuntimeError(b bool, msg string) {
|
||||
if b {
|
||||
panic(errorString(msg).Error())
|
||||
}
|
||||
}
|
||||
|
||||
func AssertNegativeShift(b bool) {
|
||||
if b {
|
||||
panic(errorString("negative shift amount").Error())
|
||||
}
|
||||
}
|
||||
|
||||
func AssertIndexRange(b bool) {
|
||||
if b {
|
||||
panic(errorString("index out of range").Error())
|
||||
}
|
||||
}
|
||||
43
internal/runtime/z_error.go
Normal file
43
internal/runtime/z_error.go
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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 runtime
|
||||
|
||||
type errorString string
|
||||
|
||||
func (e errorString) RuntimeError() {}
|
||||
|
||||
func (e errorString) Error() string {
|
||||
return "runtime error: " + string(e)
|
||||
}
|
||||
|
||||
func AssertRuntimeError(b bool, msg string) {
|
||||
if b {
|
||||
panic(errorString(msg).Error())
|
||||
}
|
||||
}
|
||||
|
||||
func AssertNegativeShift(b bool) {
|
||||
if b {
|
||||
panic(errorString("negative shift amount").Error())
|
||||
}
|
||||
}
|
||||
|
||||
func AssertIndexRange(b bool) {
|
||||
if b {
|
||||
panic(errorString("index out of range").Error())
|
||||
}
|
||||
}
|
||||
38
internal/runtime/z_gc.go
Normal file
38
internal/runtime/z_gc.go
Normal file
@@ -0,0 +1,38 @@
|
||||
//go:build !nogc
|
||||
// +build !nogc
|
||||
|
||||
/*
|
||||
* 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 runtime
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/goplus/llgo/internal/runtime/bdwgc"
|
||||
"github.com/goplus/llgo/internal/runtime/c"
|
||||
)
|
||||
|
||||
// AllocU allocates uninitialized memory.
|
||||
func AllocU(size uintptr) unsafe.Pointer {
|
||||
return bdwgc.Malloc(size)
|
||||
}
|
||||
|
||||
// AllocZ allocates zero-initialized memory.
|
||||
func AllocZ(size uintptr) unsafe.Pointer {
|
||||
ret := bdwgc.Malloc(size)
|
||||
return c.Memset(ret, 0, size)
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
//go:build nogc
|
||||
// +build nogc
|
||||
|
||||
/*
|
||||
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
|
||||
*
|
||||
@@ -16,9 +19,19 @@
|
||||
|
||||
package runtime
|
||||
|
||||
// Defer presents defer statements in a function.
|
||||
type Defer struct {
|
||||
Bits uintptr
|
||||
Link *Defer
|
||||
Rund int // index of RunDefers
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/goplus/llgo/internal/runtime/c"
|
||||
)
|
||||
|
||||
// AllocU allocates uninitialized memory.
|
||||
func AllocU(size uintptr) unsafe.Pointer {
|
||||
return c.Malloc(size)
|
||||
}
|
||||
|
||||
// AllocZ allocates zero-initialized memory.
|
||||
func AllocZ(size uintptr) unsafe.Pointer {
|
||||
ret := c.Malloc(size)
|
||||
return c.Memset(ret, 0, size)
|
||||
}
|
||||
@@ -20,20 +20,19 @@ import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/goplus/llgo/internal/abi"
|
||||
"github.com/goplus/llgo/internal/runtime/bdwgc"
|
||||
"github.com/goplus/llgo/internal/runtime/c"
|
||||
)
|
||||
|
||||
// AllocU allocates uninitialized memory.
|
||||
func AllocU(size uintptr) unsafe.Pointer {
|
||||
return bdwgc.Malloc(size)
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Defer presents defer statements in a function.
|
||||
type Defer struct {
|
||||
Bits uintptr
|
||||
Link *Defer
|
||||
Rund int // index of RunDefers
|
||||
}
|
||||
|
||||
// AllocZ allocates zero-initialized memory.
|
||||
func AllocZ(size uintptr) unsafe.Pointer {
|
||||
ret := bdwgc.Malloc(size)
|
||||
return c.Memset(ret, 0, size)
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Zeroinit initializes memory to zero.
|
||||
func Zeroinit(p unsafe.Pointer, size uintptr) unsafe.Pointer {
|
||||
@@ -54,3 +53,5 @@ func stringTracef(fp c.FilePtr, format *c.Char, s String) {
|
||||
cs := c.Alloca(uintptr(s.len) + 1)
|
||||
c.Fprintf(fp, format, CStrCopy(cs, s))
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
Reference in New Issue
Block a user