mirror of
https://github.com/pocketpy/pocketpy
synced 2026-02-04 06:30:17 +00:00
Compare commits
3 Commits
8bc7bf3bd7
...
f319fedf7e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f319fedf7e | ||
|
|
32d104039c | ||
|
|
f6f078807d |
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2025 blueloveTH
|
||||
Copyright (c) 2026 blueloveTH
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
@ -51,6 +51,8 @@ These platforms are officially tested.
|
||||
+ Raspberry Pi OS 64-bit
|
||||
+ [Luckfox Pico SDK](https://github.com/LuckfoxTECH/luckfox-pico) 32-bit
|
||||
|
||||
On Windows platform, only MSVC compiler is officially supported.
|
||||
|
||||
## Quick Start
|
||||
|
||||
You have two options to integrate pkpy into your project.
|
||||
|
||||
@ -11,7 +11,7 @@ ROOT = 'include/pocketpy'
|
||||
PUBLIC_HEADERS = ['config.h', 'export.h', 'vmath.h', 'pocketpy.h']
|
||||
|
||||
COPYRIGHT = '''/*
|
||||
* Copyright (c) 2025 blueloveTH
|
||||
* Copyright (c) 2026 blueloveTH
|
||||
* Distributed Under The MIT License
|
||||
* https://github.com/pocketpy/pocketpy
|
||||
*/
|
||||
|
||||
@ -8,7 +8,8 @@ order: 81
|
||||
The feature requires pocketpy version >= `2.1.7`
|
||||
!!!
|
||||
|
||||
You can deploy your pocketpy program as bytecode files, which slightly improves the loading speed of your program.
|
||||
You can deploy your pocketpy program as `.pyc` files, which are compiled bytecodes with necessary metadata.
|
||||
This slightly improves the loading speed of your program.
|
||||
|
||||
It also makes your users unable to get your source code directly, unless they do expensive reverse engineering.
|
||||
|
||||
@ -29,4 +30,24 @@ It compiles all `.py` files in the specified directory into `.pyc` files.
|
||||
|
||||
```sh
|
||||
python compileall.py ./main input_path output_path
|
||||
```
|
||||
```
|
||||
|
||||
## Running `.pyc` files
|
||||
|
||||
The command-line executable `main` can run `.pyc` files directly:
|
||||
|
||||
```sh
|
||||
./main output_file.pyc
|
||||
```
|
||||
|
||||
If you are using C-APIs, you can use the `py_execo()` function.
|
||||
|
||||
```c
|
||||
/// Run a compiled code object.
|
||||
PK_API bool py_execo(const void* data, int size, const char* filename, py_Ref module) PY_RAISE PY_RETURN;
|
||||
```
|
||||
|
||||
## Trackback Support
|
||||
|
||||
Since `.pyc` files do not contain raw sources,
|
||||
trackbacks will show line numbers but not the actual source code lines.
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
icon: dot
|
||||
title: Threading
|
||||
title: Compute Threads
|
||||
---
|
||||
|
||||
pocketpy organizes its state by `VM` structure.
|
||||
|
||||
@ -46,6 +46,8 @@ These platforms are officially tested.
|
||||
+ Raspberry Pi OS 64-bit
|
||||
+ [Luckfox Pico SDK](https://github.com/LuckfoxTECH/luckfox-pico) 32-bit
|
||||
|
||||
On Windows platform, only MSVC compiler is officially supported.
|
||||
|
||||
## Star the repo
|
||||
|
||||
If you find pkpy useful, consider [star this repository](https://github.com/blueloveth/pocketpy) (●'◡'●)
|
||||
|
||||
@ -11,7 +11,7 @@ pkpy is licensed under the [MIT License](http://opensource.org/licenses/MIT).
|
||||
```
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2025 blueloveTH
|
||||
Copyright (c) 2026 blueloveTH
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
@ -357,6 +357,47 @@ class PocketpyBindings {
|
||||
late final _py_compile = _py_compilePtr.asFunction<
|
||||
bool Function(ffi.Pointer<ffi.Char>, ffi.Pointer<ffi.Char>, int, bool)>();
|
||||
|
||||
/// Compile a `.py` file into a `.pyc` file.
|
||||
bool py_compilefile(
|
||||
ffi.Pointer<ffi.Char> src_path,
|
||||
ffi.Pointer<ffi.Char> dst_path,
|
||||
) {
|
||||
return _py_compilefile(
|
||||
src_path,
|
||||
dst_path,
|
||||
);
|
||||
}
|
||||
|
||||
late final _py_compilefilePtr = _lookup<
|
||||
ffi.NativeFunction<
|
||||
ffi.Bool Function(
|
||||
ffi.Pointer<ffi.Char>, ffi.Pointer<ffi.Char>)>>('py_compilefile');
|
||||
late final _py_compilefile = _py_compilefilePtr.asFunction<
|
||||
bool Function(ffi.Pointer<ffi.Char>, ffi.Pointer<ffi.Char>)>();
|
||||
|
||||
/// Run a compiled code object.
|
||||
bool py_execo(
|
||||
ffi.Pointer<ffi.Void> data,
|
||||
int size,
|
||||
ffi.Pointer<ffi.Char> filename,
|
||||
py_Ref module,
|
||||
) {
|
||||
return _py_execo(
|
||||
data,
|
||||
size,
|
||||
filename,
|
||||
module,
|
||||
);
|
||||
}
|
||||
|
||||
late final _py_execoPtr = _lookup<
|
||||
ffi.NativeFunction<
|
||||
ffi.Bool Function(ffi.Pointer<ffi.Void>, ffi.Int,
|
||||
ffi.Pointer<ffi.Char>, py_Ref)>>('py_execo');
|
||||
late final _py_execo = _py_execoPtr.asFunction<
|
||||
bool Function(
|
||||
ffi.Pointer<ffi.Void>, int, ffi.Pointer<ffi.Char>, py_Ref)>();
|
||||
|
||||
/// Run a source string.
|
||||
/// @param source source string.
|
||||
/// @param filename filename (for error messages).
|
||||
@ -960,38 +1001,6 @@ class PocketpyBindings {
|
||||
late final _py_bindmagic =
|
||||
_py_bindmagicPtr.asFunction<void Function(int, py_Name, py_CFunction)>();
|
||||
|
||||
/// Bind a compile-time function via "decl-based" style.
|
||||
void py_macrobind(
|
||||
ffi.Pointer<ffi.Char> sig,
|
||||
py_CFunction f,
|
||||
) {
|
||||
return _py_macrobind(
|
||||
sig,
|
||||
f,
|
||||
);
|
||||
}
|
||||
|
||||
late final _py_macrobindPtr = _lookup<
|
||||
ffi.NativeFunction<
|
||||
ffi.Void Function(
|
||||
ffi.Pointer<ffi.Char>, py_CFunction)>>('py_macrobind');
|
||||
late final _py_macrobind = _py_macrobindPtr
|
||||
.asFunction<void Function(ffi.Pointer<ffi.Char>, py_CFunction)>();
|
||||
|
||||
/// Get a compile-time function by name.
|
||||
py_ItemRef py_macroget(
|
||||
py_Name name,
|
||||
) {
|
||||
return _py_macroget(
|
||||
name,
|
||||
);
|
||||
}
|
||||
|
||||
late final _py_macrogetPtr =
|
||||
_lookup<ffi.NativeFunction<py_ItemRef Function(py_Name)>>('py_macroget');
|
||||
late final _py_macroget =
|
||||
_py_macrogetPtr.asFunction<py_ItemRef Function(py_Name)>();
|
||||
|
||||
/// Convert an `int` object in python to `int64_t`.
|
||||
int py_toint(
|
||||
py_Ref arg0,
|
||||
@ -3946,10 +3955,12 @@ abstract class py_TraceEvent {
|
||||
|
||||
/// A struct contains the callbacks of the VM.
|
||||
final class py_Callbacks extends ffi.Struct {
|
||||
/// Used by `__import__` to load a source module.
|
||||
/// Used by `__import__` to load a source or compiled module.
|
||||
external ffi.Pointer<
|
||||
ffi.NativeFunction<
|
||||
ffi.Pointer<ffi.Char> Function(ffi.Pointer<ffi.Char>)>> importfile;
|
||||
ffi.NativeFunction<
|
||||
ffi.Pointer<ffi.Char> Function(
|
||||
ffi.Pointer<ffi.Char> path, ffi.Pointer<ffi.Int> data_size)>>
|
||||
importfile;
|
||||
|
||||
/// Called before `importfile` to lazy-import a C module.
|
||||
external ffi
|
||||
@ -4035,13 +4046,13 @@ typedef py_CFunction = ffi.Pointer<
|
||||
/// A pointer that represents a python identifier. For fast name resolution.
|
||||
typedef py_Name = ffi.Pointer<py_OpaqueName>;
|
||||
|
||||
/// An item reference to a container object. It invalidates when the container is modified.
|
||||
typedef py_ItemRef = ffi.Pointer<py_TValue>;
|
||||
|
||||
/// A generic destructor function.
|
||||
typedef py_Dtor
|
||||
= ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>;
|
||||
|
||||
/// An item reference to a container object. It invalidates when the container is modified.
|
||||
typedef py_ItemRef = ffi.Pointer<py_TValue>;
|
||||
|
||||
/// A reference which has the same lifespan as the python object.
|
||||
typedef py_ObjectRef = ffi.Pointer<py_TValue>;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user