_xtool: llpyg

This commit is contained in:
xushiwei
2024-05-13 18:24:00 +08:00
parent fa3149c660
commit b20ad7047f
7 changed files with 225 additions and 1 deletions

View File

@@ -16,6 +16,8 @@
package py
/*
import (
_ "unsafe"
@@ -44,3 +46,5 @@ func (o *Object) CStr() *c.Char { return nil }
// llgo:link (*Object).Strlen C.PyBytes_Size
func (o *Object) Strlen() uintptr { return 0 }
*/

45
py/dict.go Normal file
View File

@@ -0,0 +1,45 @@
/*
* 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 py
import (
_ "unsafe"
)
// https://docs.python.org/3/c-api/dict.html
// Return a new empty dictionary, or nil on failure.
//
//go:linkname NewDict C.PyDict_New
func NewDict() *Object
// Return a ListObject containing all the keys from the dictionary.
//
// llgo:link (*Object).DictKeys C.PyDict_Keys
func (d *Object) DictKeys() *Object { return nil }
// Return a ListObject containing all the values from the dictionary.
//
// llgo:link (*Object).DictValues C.PyDict_Values
func (d *Object) DictValues() *Object { return nil }
// Return a ListObject containing all the items from the dictionary.
//
// llgo:link (*Object).DictItems C.PyDict_Items
func (d *Object) DictItems() *Object { return nil }
// -----------------------------------------------------------------------------

41
py/list.go Normal file
View File

@@ -0,0 +1,41 @@
/*
* 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 py
import (
_ "unsafe"
)
// https://docs.python.org/3/c-api/list.html
// Return a new list of length len on success, or nil on failure.
//
//go:linkname NewList C.PyList_New
func NewList(len uintptr) *Object
// Return the length of the list object in list; this is equivalent to len(list)
// on a list object.
//
// llgo:link (*Object).ListLen C.PyList_Size
func (l *Object) ListLen() uintptr { return 0 }
// Return the object at position index in the list pointed to by list. The position
// must be non-negative; indexing from the end of the list is not supported. If index
// is out of bounds (<0 or >=len(list)), return nil and set an IndexError exception.
//
// llgo:link (*Object).ListItem C.PyList_GetItem
func (l *Object) ListItem(index uintptr) *Object { return nil }

View File

@@ -22,7 +22,7 @@ import (
"github.com/goplus/llgo/c"
)
// -----------------------------------------------------------------------------
// https://docs.python.org/3/c-api/module.html
// This is a wrapper around py.Import which takes a const char* as an argument
// instead of an Object.

39
py/tuple.go Normal file
View File

@@ -0,0 +1,39 @@
/*
* 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 py
import (
_ "unsafe"
)
// https://docs.python.org/3/c-api/tuple.html
// Return a new tuple object of size len, or nil on failure.
//
//go:linkname NewTuple C.PyTuple_New
func NewTuple(len uintptr) *Object
// Take a pointer to a tuple object, and return the size of that tuple.
//
// llgo:link (*Object).TupleLen C.PyTuple_Size
func (t *Object) TupleLen() uintptr { return 0 }
// Return the object at position pos in the tuple pointed to by p. If pos is
// negative or out of bounds, return nil and set an IndexError exception.
//
// llgo:link (*Object).TupleItem C.PyTuple_GetItem
func (t *Object) TupleItem(index uintptr) *Object { return nil }

47
py/unicode.go Normal file
View File

@@ -0,0 +1,47 @@
/*
* 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 py
import (
_ "unsafe"
"github.com/goplus/llgo/c"
)
// https://docs.python.org/3/c-api/unicode.html
// Return a pointer to the UTF-8 encoding of the Unicode object, and store the
// size of the encoded representation (in bytes) in size. The size argument can
// be nil; in this case no size will be stored. The returned buffer always has
// an extra null byte appended (not included in size), regardless of whether
// there are any other null code points.
//
// In the case of an error, nil is returned with an exception set and no size is
// stored.
//
// This caches the UTF-8 representation of the string in the Unicode object, and
// subsequent calls will return a pointer to the same buffer. The caller is not
// responsible for deallocating the buffer. The buffer is deallocated and pointers
// to it become invalid when the Unicode object is garbage collected.
//
// llgo:link (*Object).CStrAndLen C.PyUnicode_AsUTF8AndSize
func (o *Object) CStrAndLen() (*c.Char, uintptr) { return nil, 0 }
// As CStrAndLen, but does not store the len.
//
// llgo:link (*Object).CStr C.PyUnicode_AsUTF8
func (o *Object) CStr() *c.Char { return nil }