mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-19 19:10:17 +00:00
fix docs with pocketpy
This commit is contained in:
parent
cc076bbc00
commit
2c8a8732f0
18
README.md
18
README.md
@ -1,9 +1,9 @@
|
||||
# pocketpy: python interpreter in 1 file
|
||||
|
||||
<p>
|
||||
<a title="Build" href="https://github.com/blueloveTH/pocketpy/actions/workflows" ><img src="https://github.com/blueloveTH/pocketpy/actions/workflows/main.yml/badge.svg" /></a>
|
||||
<a href="https://codecov.io/gh/blueloveTH/pocketpy" >
|
||||
<img src="https://codecov.io/gh/blueloveTH/pocketpy/branch/main/graph/badge.svg?token=TI9KAFL0RG"/>
|
||||
<a title="Build" href="https://github.com/pocketpy/pocketpy/actions/workflows" ><img src="https://github.com/pocketpy/pocketpy/actions/workflows/main.yml/badge.svg" /></a>
|
||||
<a href="https://codecov.io/gh/pocketpy/pocketpy" >
|
||||
<img src="https://codecov.io/gh/pocketpy/pocketpy/branch/main/graph/badge.svg?token=TI9KAFL0RG"/>
|
||||
</a>
|
||||
<a href="https://en.wikipedia.org/wiki/C%2B%2B#Standardization">
|
||||
<img alt="C++17" src="https://img.shields.io/badge/C%2B%2B-17-blue.svg"></a>
|
||||
@ -42,10 +42,10 @@ These platforms are officially tested.
|
||||
|
||||
## Quick Start
|
||||
|
||||
Download the `pocketpy.h` on our [GitHub Release](https://github.com/blueloveTH/pocketpy/releases) page.
|
||||
Download the `pocketpy.h` on our [GitHub Release](https://github.com/pocketpy/pocketpy/releases) page.
|
||||
And `#include` it in your project.
|
||||
|
||||
You can also use cmake to build it from source. See [CMakeLists.txt](https://github.com/blueloveTH/pocketpy/blob/main/CMakeLists.txt) for details.
|
||||
You can also use cmake to build it from source. See [CMakeLists.txt](https://github.com/pocketpy/pocketpy/blob/main/CMakeLists.txt) for details.
|
||||
These variables can be set to control the build process:
|
||||
+ `PK_BUILD_STATIC_LIB` - Build the static library (default, recommended)
|
||||
+ `PK_BUILD_SHARED_LIB` - Build the shared library
|
||||
@ -149,10 +149,10 @@ And these are the results of the primes benchmark on Intel i5-12400F, WSL (Ubunt
|
||||
|
||||
| name | version | time | file |
|
||||
| ---- | ---- | ---- | ---- |
|
||||
| c++ | gnu++11 | `0.104s ■□□□□□□□□□□□□□□□` | [benchmarks/primes.cpp](https://github.com/blueloveTH/pocketpy/blob/9481d653b60b81f4590a4d48f2be496f6962261e/benchmarks/primes.cpp) |
|
||||
| lua | 5.3.3 | `1.576s ■■■■■■■■■□□□□□□□` | [benchmarks/primes.lua](https://github.com/blueloveTH/pocketpy/blob/9481d653b60b81f4590a4d48f2be496f6962261e/benchmarks/primes.lua) |
|
||||
| pkpy | 1.2.7 | `2.385s ■■■■■■■■■■■■■□□□` | [benchmarks/primes.py](https://github.com/blueloveTH/pocketpy/blob/9481d653b60b81f4590a4d48f2be496f6962261e/benchmarks/primes.py) |
|
||||
| cpython | 3.8.10 | `2.871s ■■■■■■■■■■■■■■■■` | [benchmarks/primes.py](https://github.com/blueloveTH/pocketpy/blob/9481d653b60b81f4590a4d48f2be496f6962261e/benchmarks/primes.py) |
|
||||
| c++ | gnu++11 | `0.104s ■□□□□□□□□□□□□□□□` | [benchmarks/primes.cpp](https://github.com/pocketpy/pocketpy/blob/9481d653b60b81f4590a4d48f2be496f6962261e/benchmarks/primes.cpp) |
|
||||
| lua | 5.3.3 | `1.576s ■■■■■■■■■□□□□□□□` | [benchmarks/primes.lua](https://github.com/pocketpy/pocketpy/blob/9481d653b60b81f4590a4d48f2be496f6962261e/benchmarks/primes.lua) |
|
||||
| pkpy | 1.2.7 | `2.385s ■■■■■■■■■■■■■□□□` | [benchmarks/primes.py](https://github.com/pocketpy/pocketpy/blob/9481d653b60b81f4590a4d48f2be496f6962261e/benchmarks/primes.py) |
|
||||
| cpython | 3.8.10 | `2.871s ■■■■■■■■■■■■■■■■` | [benchmarks/primes.py](https://github.com/pocketpy/pocketpy/blob/9481d653b60b81f4590a4d48f2be496f6962261e/benchmarks/primes.py) |
|
||||
|
||||
## Used By
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
# pocketpy: python interpreter in 1 file
|
||||
|
||||
<p>
|
||||
<a title="Build" href="https://github.com/blueloveTH/pocketpy/actions/workflows" ><img src="https://github.com/blueloveTH/pocketpy/actions/workflows/main.yml/badge.svg" /></a>
|
||||
<a href="https://codecov.io/gh/blueloveTH/pocketpy" >
|
||||
<img src="https://codecov.io/gh/blueloveTH/pocketpy/branch/main/graph/badge.svg?token=TI9KAFL0RG"/>
|
||||
<a title="Build" href="https://github.com/pocketpy/pocketpy/actions/workflows" ><img src="https://github.com/pocketpy/pocketpy/actions/workflows/main.yml/badge.svg" /></a>
|
||||
<a href="https://codecov.io/gh/pocketpy/pocketpy" >
|
||||
<img src="https://codecov.io/gh/pocketpy/pocketpy/branch/main/graph/badge.svg?token=TI9KAFL0RG"/>
|
||||
</a>
|
||||
<a href="https://github.com/blueloveth/pocketpy/blob/main/LICENSE">
|
||||
<img alt="GitHub" src="https://img.shields.io/github/license/blueloveth/pocketpy.svg?color=blue"></a>
|
||||
@ -31,7 +31,7 @@ pkpy 支持任何拥有 C++17 编译器的平台。
|
||||
|
||||
## 快速上手
|
||||
|
||||
你可以在 [Github Release](https://github.com/blueloveTH/pocketpy/releases) 页面下载 `pocketpy.h`,
|
||||
你可以在 [Github Release](https://github.com/pocketpy/pocketpy/releases) 页面下载 `pocketpy.h`,
|
||||
并加入到你的工程中。请参阅 https://pocketpy.dev 以获取更详细的文档。
|
||||
|
||||
```cpp
|
||||
|
@ -65,7 +65,7 @@ with open("amalgamated/pocketpy.h", "wt", encoding='utf-8') as f:
|
||||
r'''/*
|
||||
* Copyright (c) 2023 blueloveTH
|
||||
* Distributed Under The MIT License
|
||||
* https://github.com/blueloveTH/pocketpy
|
||||
* https://github.com/pocketpy/pocketpy
|
||||
*/
|
||||
|
||||
#ifndef POCKETPY_H
|
||||
|
@ -262,6 +262,6 @@ It takes a C header file and generates a python module stub (`*.pyi`) and a C++
|
||||
|
||||
## Further reading
|
||||
|
||||
See [random.cpp](https://github.com/blueloveTH/pocketpy/blob/main/src/random.cpp) for an example used by `random` module.
|
||||
See [random.cpp](https://github.com/pocketpy/pocketpy/blob/main/src/random.cpp) for an example used by `random` module.
|
||||
|
||||
See [collections.cpp](https://github.com/blueloveTH/pocketpy/blob/main/src/collections.cpp) for a modern implementation of `collections.deque`.
|
||||
See [collections.cpp](https://github.com/pocketpy/pocketpy/blob/main/src/collections.cpp) for a modern implementation of `collections.deque`.
|
@ -12,7 +12,7 @@ pkpy provides a lua bridge to reuse lua bindings.
|
||||
It allows you to run lua code and call lua functions in python
|
||||
by embedding a lua virtual machine.
|
||||
|
||||
Add `lua_bridge.hpp` and `lua_bridge.cpp` in [3rd/lua_bridge](https://github.com/blueloveTH/pocketpy/tree/main/3rd/lua_bridge) to your project.
|
||||
Add `lua_bridge.hpp` and `lua_bridge.cpp` in [3rd/lua_bridge](https://github.com/pocketpy/pocketpy/tree/main/3rd/lua_bridge) to your project.
|
||||
Make sure `lua.h`, `lualib.h` and `lauxlib.h` are in your include path
|
||||
because `lua_bridge.hpp` needs them.
|
||||
|
||||
|
@ -35,7 +35,7 @@ The easiest way to test a feature is to [try it on your browser](https://pocketp
|
||||
4. `int` does not derive from `bool`.
|
||||
5. `int` is 64-bit. You can use `long` type explicitly for arbitrary sized integers.
|
||||
6. `__ne__` is not required. Define `__eq__` is enough.
|
||||
7. Raw string cannot have boundary quotes in it, even escaped. See [#55](https://github.com/blueloveTH/pocketpy/issues/55).
|
||||
7. Raw string cannot have boundary quotes in it, even escaped. See [#55](https://github.com/pocketpy/pocketpy/issues/55).
|
||||
8. In a starred unpacked assignment, e.g. `a, b, *c = x`, the starred variable can only be presented in the last position. `a, *b, c = x` is not supported.
|
||||
9. A `Tab` is equivalent to 4 spaces. You can mix `Tab` and spaces in indentation, but it is not recommended.
|
||||
10. `%`, `&`, `//`, `^` and `|` for `int` behave the same as C, not python.
|
||||
|
@ -6,7 +6,7 @@ title: Arbitrary Sized Integers
|
||||
Unlike cpython, pkpy's `int` is of limited precision (64-bit).
|
||||
|
||||
For arbitrary sized integers, we provide a builtin `long` type, just like python2's `long`.
|
||||
`long` is implemented via pure python in [_long.py](https://github.com/blueloveTH/pocketpy/blob/main/python/_long.py).
|
||||
`long` is implemented via pure python in [_long.py](https://github.com/pocketpy/pocketpy/blob/main/python/_long.py).
|
||||
|
||||
!!!
|
||||
This feature is still under development.
|
||||
|
@ -39,7 +39,7 @@ It hides the details of Box2D's API and provides a high-level interface.
|
||||
|
||||
## APIs
|
||||
|
||||
https://github.com/blueloveTH/pocketpy/blob/main/include/typings/box2d.pyi
|
||||
https://github.com/pocketpy/pocketpy/blob/main/include/typings/box2d.pyi
|
||||
|
||||
## Example
|
||||
|
||||
|
@ -5,4 +5,4 @@ label: c
|
||||
|
||||
Interop with pointers and C structs.
|
||||
|
||||
https://github.com/blueloveTH/pocketpy/blob/main/include/typings/c.pyi
|
||||
https://github.com/pocketpy/pocketpy/blob/main/include/typings/c.pyi
|
@ -7,7 +7,7 @@ Provide `mat3x3`, `vec2`, `vec3` and `vec4` types.
|
||||
|
||||
This classes adopt `torch`'s naming convention. Methods with `_` suffix will modify the instance itself.
|
||||
|
||||
https://github.com/blueloveTH/pocketpy/blob/main/include/typings/linalg.pyi
|
||||
https://github.com/pocketpy/pocketpy/blob/main/include/typings/linalg.pyi
|
||||
|
||||
```python
|
||||
from typing import overload
|
||||
|
@ -126,7 +126,7 @@ Testing directory: benchmarks/
|
||||
ALL TESTS PASSED
|
||||
```
|
||||
|
||||
See [actions/runs](https://github.com/blueloveTH/pocketpy/actions/runs/6511071423/job/17686074263).
|
||||
See [actions/runs](https://github.com/pocketpy/pocketpy/actions/runs/6511071423/job/17686074263).
|
||||
|
||||
## Primes benchmarks
|
||||
|
||||
@ -134,10 +134,10 @@ These are the results of the primes benchmark on Intel i5-12400F, WSL (Ubuntu 20
|
||||
|
||||
| name | version | time | file |
|
||||
| ---- | ---- | ---- | ---- |
|
||||
| c++ | gnu++11 | `0.104s ■□□□□□□□□□□□□□□□` | [benchmarks/primes.cpp](https://github.com/blueloveTH/pocketpy/blob/9481d653b60b81f4590a4d48f2be496f6962261e/benchmarks/primes.cpp) |
|
||||
| lua | 5.3.3 | `1.576s ■■■■■■■■■□□□□□□□` | [benchmarks/primes.lua](https://github.com/blueloveTH/pocketpy/blob/9481d653b60b81f4590a4d48f2be496f6962261e/benchmarks/primes.lua) |
|
||||
| pkpy | 1.2.7 | `2.385s ■■■■■■■■■■■■■□□□` | [benchmarks/primes.py](https://github.com/blueloveTH/pocketpy/blob/9481d653b60b81f4590a4d48f2be496f6962261e/benchmarks/primes.py) |
|
||||
| cpython | 3.8.10 | `2.871s ■■■■■■■■■■■■■■■■` | [benchmarks/primes.py](https://github.com/blueloveTH/pocketpy/blob/9481d653b60b81f4590a4d48f2be496f6962261e/benchmarks/primes.py) |
|
||||
| c++ | gnu++11 | `0.104s ■□□□□□□□□□□□□□□□` | [benchmarks/primes.cpp](https://github.com/pocketpy/pocketpy/blob/9481d653b60b81f4590a4d48f2be496f6962261e/benchmarks/primes.cpp) |
|
||||
| lua | 5.3.3 | `1.576s ■■■■■■■■■□□□□□□□` | [benchmarks/primes.lua](https://github.com/pocketpy/pocketpy/blob/9481d653b60b81f4590a4d48f2be496f6962261e/benchmarks/primes.lua) |
|
||||
| pkpy | 1.2.7 | `2.385s ■■■■■■■■■■■■■□□□` | [benchmarks/primes.py](https://github.com/pocketpy/pocketpy/blob/9481d653b60b81f4590a4d48f2be496f6962261e/benchmarks/primes.py) |
|
||||
| cpython | 3.8.10 | `2.871s ■■■■■■■■■■■■■■■■` | [benchmarks/primes.py](https://github.com/pocketpy/pocketpy/blob/9481d653b60b81f4590a4d48f2be496f6962261e/benchmarks/primes.py) |
|
||||
|
||||
```sh
|
||||
$ time lua benchmarks/primes.lua
|
||||
|
@ -27,6 +27,6 @@ You can do the following to ensure thread safety for `VM` instances:
|
||||
|
||||
You can create a `user_config.h` in the same directory as `pocketpy.h` to override some default settings.
|
||||
|
||||
1. Copy [src/config.h](https://github.com/blueloveTH/pocketpy/blob/main/include/pocketpy/config.h) and rename it to `user_config.h`.
|
||||
1. Copy [src/config.h](https://github.com/pocketpy/pocketpy/blob/main/include/pocketpy/config.h) and rename it to `user_config.h`.
|
||||
2. Define a macro `PK_USER_CONFIG_H` in `user_config.h`. This invalidates the default `config.h` and enables your `user_config.h`.
|
||||
3. Edit `user_config.h` to override default settings.
|
||||
|
@ -8,7 +8,7 @@ You have two options to integrate pkpy into your project.
|
||||
|
||||
#### Use the single header file
|
||||
|
||||
Download the `pocketpy.h` on our [GitHub Release](https://github.com/blueloveTH/pocketpy/releases) page.
|
||||
Download the `pocketpy.h` on our [GitHub Release](https://github.com/pocketpy/pocketpy/releases) page.
|
||||
And `#include` it in your project. It is recommended to use the latest dev version.
|
||||
|
||||
#### Use CMake
|
||||
@ -34,7 +34,7 @@ These variables can be set to control the build process:
|
||||
+ `PK_BUILD_STATIC_LIB` - Build the static library
|
||||
+ `PK_BUILD_SHARED_LIB` - Build the shared library
|
||||
|
||||
See [CMakeLists.txt](https://github.com/blueloveTH/pocketpy/blob/main/CMakeLists.txt) for details.
|
||||
See [CMakeLists.txt](https://github.com/pocketpy/pocketpy/blob/main/CMakeLists.txt) for details.
|
||||
|
||||
It is safe to use `main` branch in production.
|
||||
|
||||
@ -52,7 +52,7 @@ See https://emscripten.org/docs/porting/exceptions.html.
|
||||
### Get prebuilt binaries
|
||||
|
||||
We have prebuilt binaries,
|
||||
check them out on our [GitHub Actions](https://github.com/blueloveTH/pocketpy/actions/workflows/main.yml).
|
||||
check them out on our [GitHub Actions](https://github.com/pocketpy/pocketpy/actions/workflows/main.yml).
|
||||
|
||||
You can download an artifact there which contains the following files.
|
||||
|
||||
|
@ -20,12 +20,12 @@ You cannot use it to run NumPy, OpenCV, or any other CPython extension modules.
|
||||
|
||||
### Python 3.x Syntax
|
||||
|
||||
PocketPython uses [pocketpy](https://github.com/blueloveTH/pocketpy)
|
||||
PocketPython uses [pocketpy](https://github.com/pocketpy/pocketpy)
|
||||
as frontend to parse and compile Python source code.
|
||||
It supports most of the Python 3.x syntax.
|
||||
|
||||
The following table shows a feature comparison of PocketPython
|
||||
with respect to the original [pocketpy](https://github.com/blueloveTH/pocketpy).
|
||||
with respect to the original [pocketpy](https://github.com/pocketpy/pocketpy).
|
||||
The features marked with `YES` are supported, and the features marked with `NO` are not supported.
|
||||
|
||||
| Name | Example | Cpp | Unity |
|
||||
|
@ -39,7 +39,7 @@ struct ManagedHeap{
|
||||
template<typename T, typename... Args>
|
||||
PyObject* gcnew(Type type, Args&&... args){
|
||||
using __T = Py_<std::decay_t<T>>;
|
||||
// https://github.com/blueloveTH/pocketpy/issues/94#issuecomment-1594784476
|
||||
// https://github.com/pocketpy/pocketpy/issues/94#issuecomment-1594784476
|
||||
PyObject* obj = new(pool64_alloc<__T>()) Py_<std::decay_t<T>>(type, std::forward<Args>(args)...);
|
||||
gen.push_back(obj);
|
||||
gc_counter++;
|
||||
@ -49,7 +49,7 @@ struct ManagedHeap{
|
||||
template<typename T, typename... Args>
|
||||
PyObject* _new(Type type, Args&&... args){
|
||||
using __T = Py_<std::decay_t<T>>;
|
||||
// https://github.com/blueloveTH/pocketpy/issues/94#issuecomment-1594784476
|
||||
// https://github.com/pocketpy/pocketpy/issues/94#issuecomment-1594784476
|
||||
PyObject* obj = new(pool64_alloc<__T>()) Py_<std::decay_t<T>>(type, std::forward<Args>(args)...);
|
||||
obj->gc.enabled = false;
|
||||
_no_gc.push_back(obj);
|
||||
|
@ -223,7 +223,7 @@ namespace pkpy{
|
||||
_compile_f_args(e->decl, false);
|
||||
consume(TK(":"));
|
||||
}
|
||||
// https://github.com/blueloveTH/pocketpy/issues/37
|
||||
// https://github.com/pocketpy/pocketpy/issues/37
|
||||
parse_expression(PREC_LAMBDA + 1);
|
||||
ctx()->emit_expr();
|
||||
ctx()->emit_(OP_RETURN_VALUE, BC_NOARG, BC_KEEPLINE);
|
||||
|
@ -1,4 +1,4 @@
|
||||
# https://github.com/blueloveTH/pocketpy/issues/37
|
||||
# https://github.com/pocketpy/pocketpy/issues/37
|
||||
|
||||
mp = map(lambda x: x**2, [1, 2, 3, 4, 5] )
|
||||
assert list(mp) == [1, 4, 9, 16, 25]
|
||||
|
Loading…
x
Reference in New Issue
Block a user