fix docs with pocketpy

This commit is contained in:
blueloveTH 2024-02-05 16:15:00 +08:00
parent cc076bbc00
commit 2c8a8732f0
17 changed files with 37 additions and 37 deletions

View File

@ -1,9 +1,9 @@
# pocketpy: python interpreter in 1 file # pocketpy: python interpreter in 1 file
<p> <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 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/blueloveTH/pocketpy" > <a href="https://codecov.io/gh/pocketpy/pocketpy" >
<img src="https://codecov.io/gh/blueloveTH/pocketpy/branch/main/graph/badge.svg?token=TI9KAFL0RG"/> <img src="https://codecov.io/gh/pocketpy/pocketpy/branch/main/graph/badge.svg?token=TI9KAFL0RG"/>
</a> </a>
<a href="https://en.wikipedia.org/wiki/C%2B%2B#Standardization"> <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> <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 ## 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. 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: These variables can be set to control the build process:
+ `PK_BUILD_STATIC_LIB` - Build the static library (default, recommended) + `PK_BUILD_STATIC_LIB` - Build the static library (default, recommended)
+ `PK_BUILD_SHARED_LIB` - Build the shared library + `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 | | name | version | time | file |
| ---- | ---- | ---- | ---- | | ---- | ---- | ---- | ---- |
| c++ | gnu++11 | `0.104s ■□□□□□□□□□□□□□□□` | [benchmarks/primes.cpp](https://github.com/blueloveTH/pocketpy/blob/9481d653b60b81f4590a4d48f2be496f6962261e/benchmarks/primes.cpp) | | 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/blueloveTH/pocketpy/blob/9481d653b60b81f4590a4d48f2be496f6962261e/benchmarks/primes.lua) | | 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/blueloveTH/pocketpy/blob/9481d653b60b81f4590a4d48f2be496f6962261e/benchmarks/primes.py) | | 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/blueloveTH/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 ## Used By

View File

@ -1,9 +1,9 @@
# pocketpy: python interpreter in 1 file # pocketpy: python interpreter in 1 file
<p> <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 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/blueloveTH/pocketpy" > <a href="https://codecov.io/gh/pocketpy/pocketpy" >
<img src="https://codecov.io/gh/blueloveTH/pocketpy/branch/main/graph/badge.svg?token=TI9KAFL0RG"/> <img src="https://codecov.io/gh/pocketpy/pocketpy/branch/main/graph/badge.svg?token=TI9KAFL0RG"/>
</a> </a>
<a href="https://github.com/blueloveth/pocketpy/blob/main/LICENSE"> <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> <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 以获取更详细的文档。 并加入到你的工程中。请参阅 https://pocketpy.dev 以获取更详细的文档。
```cpp ```cpp

View File

@ -65,7 +65,7 @@ with open("amalgamated/pocketpy.h", "wt", encoding='utf-8') as f:
r'''/* r'''/*
* Copyright (c) 2023 blueloveTH * Copyright (c) 2023 blueloveTH
* Distributed Under The MIT License * Distributed Under The MIT License
* https://github.com/blueloveTH/pocketpy * https://github.com/pocketpy/pocketpy
*/ */
#ifndef POCKETPY_H #ifndef POCKETPY_H

View File

@ -262,6 +262,6 @@ It takes a C header file and generates a python module stub (`*.pyi`) and a C++
## Further reading ## 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`.

View File

@ -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 It allows you to run lua code and call lua functions in python
by embedding a lua virtual machine. 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 Make sure `lua.h`, `lualib.h` and `lauxlib.h` are in your include path
because `lua_bridge.hpp` needs them. because `lua_bridge.hpp` needs them.

View File

@ -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`. 4. `int` does not derive from `bool`.
5. `int` is 64-bit. You can use `long` type explicitly for arbitrary sized integers. 5. `int` is 64-bit. You can use `long` type explicitly for arbitrary sized integers.
6. `__ne__` is not required. Define `__eq__` is enough. 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. 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. 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. 10. `%`, `&`, `//`, `^` and `|` for `int` behave the same as C, not python.

View File

@ -6,7 +6,7 @@ title: Arbitrary Sized Integers
Unlike cpython, pkpy's `int` is of limited precision (64-bit). 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`. 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. This feature is still under development.

View File

@ -39,7 +39,7 @@ It hides the details of Box2D's API and provides a high-level interface.
## APIs ## APIs
https://github.com/blueloveTH/pocketpy/blob/main/include/typings/box2d.pyi https://github.com/pocketpy/pocketpy/blob/main/include/typings/box2d.pyi
## Example ## Example

View File

@ -5,4 +5,4 @@ label: c
Interop with pointers and C structs. 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

View File

@ -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. 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 ```python
from typing import overload from typing import overload

View File

@ -126,7 +126,7 @@ Testing directory: benchmarks/
ALL TESTS PASSED 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 ## 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 | | name | version | time | file |
| ---- | ---- | ---- | ---- | | ---- | ---- | ---- | ---- |
| c++ | gnu++11 | `0.104s ■□□□□□□□□□□□□□□□` | [benchmarks/primes.cpp](https://github.com/blueloveTH/pocketpy/blob/9481d653b60b81f4590a4d48f2be496f6962261e/benchmarks/primes.cpp) | | 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/blueloveTH/pocketpy/blob/9481d653b60b81f4590a4d48f2be496f6962261e/benchmarks/primes.lua) | | 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/blueloveTH/pocketpy/blob/9481d653b60b81f4590a4d48f2be496f6962261e/benchmarks/primes.py) | | 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/blueloveTH/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 ```sh
$ time lua benchmarks/primes.lua $ time lua benchmarks/primes.lua

View File

@ -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. 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`. 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. 3. Edit `user_config.h` to override default settings.

View File

@ -8,7 +8,7 @@ You have two options to integrate pkpy into your project.
#### Use the single header file #### 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. And `#include` it in your project. It is recommended to use the latest dev version.
#### Use CMake #### 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_STATIC_LIB` - Build the static library
+ `PK_BUILD_SHARED_LIB` - Build the shared 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. It is safe to use `main` branch in production.
@ -52,7 +52,7 @@ See https://emscripten.org/docs/porting/exceptions.html.
### Get prebuilt binaries ### Get prebuilt binaries
We have 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. You can download an artifact there which contains the following files.

View File

@ -20,12 +20,12 @@ You cannot use it to run NumPy, OpenCV, or any other CPython extension modules.
### Python 3.x Syntax ### 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. as frontend to parse and compile Python source code.
It supports most of the Python 3.x syntax. It supports most of the Python 3.x syntax.
The following table shows a feature comparison of PocketPython 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. The features marked with `YES` are supported, and the features marked with `NO` are not supported.
| Name | Example | Cpp | Unity | | Name | Example | Cpp | Unity |

View File

@ -39,7 +39,7 @@ struct ManagedHeap{
template<typename T, typename... Args> template<typename T, typename... Args>
PyObject* gcnew(Type type, Args&&... args){ PyObject* gcnew(Type type, Args&&... args){
using __T = Py_<std::decay_t<T>>; 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)...); PyObject* obj = new(pool64_alloc<__T>()) Py_<std::decay_t<T>>(type, std::forward<Args>(args)...);
gen.push_back(obj); gen.push_back(obj);
gc_counter++; gc_counter++;
@ -49,7 +49,7 @@ struct ManagedHeap{
template<typename T, typename... Args> template<typename T, typename... Args>
PyObject* _new(Type type, Args&&... args){ PyObject* _new(Type type, Args&&... args){
using __T = Py_<std::decay_t<T>>; 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)...); PyObject* obj = new(pool64_alloc<__T>()) Py_<std::decay_t<T>>(type, std::forward<Args>(args)...);
obj->gc.enabled = false; obj->gc.enabled = false;
_no_gc.push_back(obj); _no_gc.push_back(obj);

View File

@ -223,7 +223,7 @@ namespace pkpy{
_compile_f_args(e->decl, false); _compile_f_args(e->decl, false);
consume(TK(":")); consume(TK(":"));
} }
// https://github.com/blueloveTH/pocketpy/issues/37 // https://github.com/pocketpy/pocketpy/issues/37
parse_expression(PREC_LAMBDA + 1); parse_expression(PREC_LAMBDA + 1);
ctx()->emit_expr(); ctx()->emit_expr();
ctx()->emit_(OP_RETURN_VALUE, BC_NOARG, BC_KEEPLINE); ctx()->emit_(OP_RETURN_VALUE, BC_NOARG, BC_KEEPLINE);

View File

@ -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] ) mp = map(lambda x: x**2, [1, 2, 3, 4, 5] )
assert list(mp) == [1, 4, 9, 16, 25] assert list(mp) == [1, 4, 9, 16, 25]