mirror of
https://github.com/pocketpy/pocketpy
synced 2026-02-04 06:30:17 +00:00
Compare commits
5 Commits
e23fd85ebd
...
1e2135e153
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1e2135e153 | ||
|
|
d6052da6ab | ||
|
|
16a7fda6c3 | ||
|
|
8ff3f44179 | ||
|
|
ecdea105d6 |
@ -3,7 +3,7 @@ output: .retype
|
||||
url: https://pocketpy.dev
|
||||
branding:
|
||||
title: pocketpy
|
||||
label: v2.1.5
|
||||
label: v2.1.6
|
||||
logo: "./static/logo.png"
|
||||
favicon: "./static/logo.png"
|
||||
meta:
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
// clang-format off
|
||||
|
||||
#define PK_VERSION "2.1.5"
|
||||
#define PK_VERSION "2.1.6"
|
||||
#define PK_VERSION_MAJOR 2
|
||||
#define PK_VERSION_MINOR 1
|
||||
#define PK_VERSION_PATCH 5
|
||||
#define PK_VERSION_PATCH 6
|
||||
|
||||
/*************** feature settings ***************/
|
||||
#ifndef PK_ENABLE_OS // can be overridden by cmake
|
||||
|
||||
@ -1,21 +0,0 @@
|
||||
from typing import Literal
|
||||
from vmath import vec2, color32
|
||||
from cute_png import Image
|
||||
|
||||
def read_axis(self) -> vec2: ...
|
||||
|
||||
def read_button(self, index: Literal[0, 1, 2, 3, 4, 5], ttl_ms: int = 10) -> bool: ...
|
||||
def read_all_buttons(self, out_list: list[bool], ttl_ms: int = 10) -> None: ...
|
||||
def clear_button(self, index: Literal[0, 1, 2, 3, 4, 5]) -> None: ...
|
||||
def clear_all_buttons(self) -> None: ...
|
||||
|
||||
def read_buzzer_freq(self) -> int: ...
|
||||
def read_buzzer_volume(self) -> float: ...
|
||||
def write_buzzer_freq(self, freq: int) -> None: ...
|
||||
def write_buzzer_volume(self, volume: float) -> None: ...
|
||||
|
||||
def write_fb0(self, image: Image) -> None: ...
|
||||
|
||||
def read_led(self, index: Literal[0, 1, 2, 3]) -> color32: ...
|
||||
def write_led(self, index: int, color: color32) -> None: ...
|
||||
def write_leds(self, _0: color32 | None, _1: color32 | None, _2: color32 | None, _3: color32 | None) -> None: ...
|
||||
@ -35,7 +35,7 @@ A new Flutter FFI plugin project.
|
||||
|
||||
s.prepare_command = <<-CMD
|
||||
rm -rf pocketpy
|
||||
git clone --branch v2.1.5 --depth 1 https://github.com/pocketpy/pocketpy.git
|
||||
git clone --branch v2.1.6 --depth 1 https://github.com/pocketpy/pocketpy.git
|
||||
cd pocketpy
|
||||
git submodule update --init --recursive --depth 1
|
||||
bash build_ios_libs.sh
|
||||
|
||||
@ -3865,6 +3865,24 @@ class PocketpyBindings {
|
||||
late final _py_profiler_report =
|
||||
_py_profiler_reportPtr.asFunction<ffi.Pointer<ffi.Char> Function()>();
|
||||
|
||||
/// Others
|
||||
int time_ns() {
|
||||
return _time_ns();
|
||||
}
|
||||
|
||||
late final _time_nsPtr =
|
||||
_lookup<ffi.NativeFunction<ffi.Int64 Function()>>('time_ns');
|
||||
late final _time_ns = _time_nsPtr.asFunction<int Function()>();
|
||||
|
||||
int time_monotonic_ns() {
|
||||
return _time_monotonic_ns();
|
||||
}
|
||||
|
||||
late final _time_monotonic_nsPtr =
|
||||
_lookup<ffi.NativeFunction<ffi.Int64 Function()>>('time_monotonic_ns');
|
||||
late final _time_monotonic_ns =
|
||||
_time_monotonic_nsPtr.asFunction<int Function()>();
|
||||
|
||||
/// An utility function to read a line from stdin for REPL.
|
||||
int py_replinput(
|
||||
ffi.Pointer<ffi.Char> buf,
|
||||
@ -4101,6 +4119,9 @@ final class c11_color32 extends ffi.Union {
|
||||
|
||||
@ffi.Array.multi([4])
|
||||
external ffi.Array<ffi.UnsignedChar> data;
|
||||
|
||||
@ffi.Uint32()
|
||||
external int u32;
|
||||
}
|
||||
|
||||
final class UnnamedStruct5 extends ffi.Struct {
|
||||
@ -4252,18 +4273,35 @@ abstract class py_PredefinedType {
|
||||
static const int tp_AssertionError = 53;
|
||||
static const int tp_KeyError = 54;
|
||||
|
||||
/// stdc
|
||||
static const int tp_stdc_Memory = 55;
|
||||
static const int tp_stdc_Char = 56;
|
||||
static const int tp_stdc_UChar = 57;
|
||||
static const int tp_stdc_Short = 58;
|
||||
static const int tp_stdc_UShort = 59;
|
||||
static const int tp_stdc_Int = 60;
|
||||
static const int tp_stdc_UInt = 61;
|
||||
static const int tp_stdc_Long = 62;
|
||||
static const int tp_stdc_ULong = 63;
|
||||
static const int tp_stdc_LongLong = 64;
|
||||
static const int tp_stdc_ULongLong = 65;
|
||||
static const int tp_stdc_Float = 66;
|
||||
static const int tp_stdc_Double = 67;
|
||||
static const int tp_stdc_Pointer = 68;
|
||||
static const int tp_stdc_Bool = 69;
|
||||
|
||||
/// vmath
|
||||
static const int tp_vec2 = 55;
|
||||
static const int tp_vec3 = 56;
|
||||
static const int tp_vec2i = 57;
|
||||
static const int tp_vec3i = 58;
|
||||
static const int tp_mat3x3 = 59;
|
||||
static const int tp_color32 = 60;
|
||||
static const int tp_vec2 = 70;
|
||||
static const int tp_vec3 = 71;
|
||||
static const int tp_vec2i = 72;
|
||||
static const int tp_vec3i = 73;
|
||||
static const int tp_mat3x3 = 74;
|
||||
static const int tp_color32 = 75;
|
||||
|
||||
/// array2d
|
||||
static const int tp_array2d_like = 61;
|
||||
static const int tp_array2d_like_iterator = 62;
|
||||
static const int tp_array2d = 63;
|
||||
static const int tp_array2d_view = 64;
|
||||
static const int tp_chunked_array2d = 65;
|
||||
static const int tp_array2d_like = 76;
|
||||
static const int tp_array2d_like_iterator = 77;
|
||||
static const int tp_array2d = 78;
|
||||
static const int tp_array2d_view = 79;
|
||||
static const int tp_chunked_array2d = 80;
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@ A new Flutter FFI plugin project.
|
||||
|
||||
s.prepare_command = <<-CMD
|
||||
rm -rf pocketpy
|
||||
git clone --branch v2.1.5 --depth 1 https://github.com/pocketpy/pocketpy.git
|
||||
git clone --branch v2.1.6 --depth 1 https://github.com/pocketpy/pocketpy.git
|
||||
cd pocketpy
|
||||
git submodule update --init --recursive --depth 1
|
||||
bash build_darwin_libs.sh
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
name: pocketpy
|
||||
description: A lightweight Python interpreter for game engines. It supports Android/iOS/Windows/Linux/MacOS.
|
||||
version: 2.1.5
|
||||
version: 2.1.6
|
||||
homepage: https://pocketpy.dev
|
||||
repository: https://github.com/pocketpy/pocketpy
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@ set(PK_BUILD_SHARED_LIB ON CACHE BOOL "" FORCE)
|
||||
FetchContent_Declare(
|
||||
pocketpy
|
||||
GIT_REPOSITORY https://github.com/pocketpy/pocketpy.git
|
||||
GIT_TAG v2.1.5
|
||||
GIT_TAG v2.1.6
|
||||
)
|
||||
|
||||
FetchContent_MakeAvailable(pocketpy)
|
||||
|
||||
@ -1254,6 +1254,10 @@ static int Ctx__add_const(Ctx* self, py_Ref v) {
|
||||
}
|
||||
|
||||
static void Ctx__emit_store_name(Ctx* self, NameScope scope, py_Name name, int line) {
|
||||
if(name == py_name("_")) {
|
||||
Ctx__emit_(self, OP_POP_TOP, BC_NOARG, line);
|
||||
return;
|
||||
}
|
||||
switch(scope) {
|
||||
case NAME_LOCAL: Ctx__emit_(self, OP_STORE_FAST, Ctx__add_varname(self, name), line); break;
|
||||
case NAME_GLOBAL: {
|
||||
@ -1454,11 +1458,9 @@ static Error* EXPR_TUPLE_ALLOW_SLICE(Compiler* self, bool allow_slice) {
|
||||
// tuple expression // (a, )
|
||||
int count = 1;
|
||||
do {
|
||||
if(curr()->brackets_level) match_newlines();
|
||||
if(!is_expression(self, allow_slice)) break;
|
||||
check(parse_expression(self, PREC_LOWEST + 1, allow_slice));
|
||||
count += 1;
|
||||
if(curr()->brackets_level) match_newlines();
|
||||
} while(match(TK_COMMA));
|
||||
// pop `count` expressions from the stack and merge them into a TupleExpr
|
||||
SequenceExpr* e = TupleExpr__new(prev()->line, count);
|
||||
@ -1755,9 +1757,7 @@ static Error* exprGroup(Compiler* self) {
|
||||
Ctx__s_push(ctx(), (Expr*)TupleExpr__new(line, 0));
|
||||
return NULL;
|
||||
}
|
||||
match_newlines();
|
||||
check(EXPR_TUPLE(self)); // () is just for change precedence
|
||||
match_newlines();
|
||||
consume(TK_RPAREN);
|
||||
if(Ctx__s_top(ctx())->vt->is_tuple) return NULL;
|
||||
GroupedExpr* g = GroupedExpr__new(line, Ctx__s_popx(ctx()));
|
||||
@ -1800,7 +1800,6 @@ static Error* consume_comp(Compiler* self, Opcode op0, Opcode op1) {
|
||||
check(EXPR_VARS(self)); // [expr, vars]
|
||||
consume(TK_IN);
|
||||
check(parse_expression(self, PREC_TERNARY + 1, false)); // [expr, vars, iter]
|
||||
match_newlines();
|
||||
if(match(TK_IF)) {
|
||||
check(parse_expression(self, PREC_TERNARY + 1, false)); // [expr, vars, iter, cond]
|
||||
has_cond = true;
|
||||
@ -1811,7 +1810,6 @@ static Error* consume_comp(Compiler* self, Opcode op0, Opcode op1) {
|
||||
ce->vars = Ctx__s_popx(ctx());
|
||||
ce->expr = Ctx__s_popx(ctx());
|
||||
Ctx__s_push(ctx(), (Expr*)ce);
|
||||
match_newlines();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -1820,17 +1818,14 @@ static Error* exprList(Compiler* self) {
|
||||
int line = prev()->line;
|
||||
int count = 0;
|
||||
do {
|
||||
match_newlines();
|
||||
if(curr()->type == TK_RBRACKET) break;
|
||||
check(EXPR(self));
|
||||
count += 1;
|
||||
match_newlines();
|
||||
if(count == 1 && match(TK_FOR)) {
|
||||
check(consume_comp(self, OP_BUILD_LIST, OP_LIST_APPEND));
|
||||
consume(TK_RBRACKET);
|
||||
return NULL;
|
||||
}
|
||||
match_newlines();
|
||||
} while(match(TK_COMMA));
|
||||
consume(TK_RBRACKET);
|
||||
SequenceExpr* e = ListExpr__new(line, count);
|
||||
@ -1847,7 +1842,6 @@ static Error* exprMap(Compiler* self) {
|
||||
bool parsing_dict = false; // {...} may be dict or set
|
||||
int count = 0;
|
||||
do {
|
||||
match_newlines();
|
||||
if(curr()->type == TK_RBRACE) break;
|
||||
check(EXPR(self)); // [key]
|
||||
if(curr()->type == TK_COLON) { parsing_dict = true; }
|
||||
@ -1860,7 +1854,6 @@ static Error* exprMap(Compiler* self) {
|
||||
Ctx__s_push(ctx(), (Expr*)item);
|
||||
}
|
||||
count += 1; // key-value pair count
|
||||
match_newlines();
|
||||
if(count == 1 && match(TK_FOR)) {
|
||||
if(parsing_dict) {
|
||||
check(consume_comp(self, OP_BUILD_DICT, OP_DICT_ADD));
|
||||
@ -1870,7 +1863,6 @@ static Error* exprMap(Compiler* self) {
|
||||
consume(TK_RBRACE);
|
||||
return NULL;
|
||||
}
|
||||
match_newlines();
|
||||
} while(match(TK_COMMA));
|
||||
consume(TK_RBRACE);
|
||||
|
||||
@ -1898,7 +1890,6 @@ static Error* exprCompileTimeCall(Compiler* self, py_ItemRef func, int line) {
|
||||
uint16_t kwargc = 0;
|
||||
// copied from `exprCall`
|
||||
do {
|
||||
match_newlines();
|
||||
if(curr()->type == TK_RPAREN) break;
|
||||
if(curr()->type == TK_ID && next()->type == TK_ASSIGN) {
|
||||
consume(TK_ID);
|
||||
@ -1915,7 +1906,6 @@ static Error* exprCompileTimeCall(Compiler* self, py_ItemRef func, int line) {
|
||||
check(read_literal(self, py_pushtmp()));
|
||||
argc += 1;
|
||||
}
|
||||
match_newlines();
|
||||
} while(match(TK_COMMA));
|
||||
consume(TK_RPAREN);
|
||||
|
||||
@ -1953,7 +1943,6 @@ static Error* exprCall(Compiler* self) {
|
||||
CallExpr* e = CallExpr__new(line, callable);
|
||||
Ctx__s_push(ctx(), (Expr*)e); // push onto the stack in advance
|
||||
do {
|
||||
match_newlines();
|
||||
if(curr()->type == TK_RPAREN) break;
|
||||
if(curr()->type == TK_ID && next()->type == TK_ASSIGN) {
|
||||
consume(TK_ID);
|
||||
@ -1979,7 +1968,6 @@ static Error* exprCall(Compiler* self) {
|
||||
c11_vector__push(Expr*, &e->args, Ctx__s_popx(ctx()));
|
||||
}
|
||||
}
|
||||
match_newlines();
|
||||
} while(match(TK_COMMA));
|
||||
consume(TK_RPAREN);
|
||||
return NULL;
|
||||
@ -2029,9 +2017,7 @@ static Error* exprSlice1(Compiler* self) {
|
||||
static Error* exprSubscr(Compiler* self) {
|
||||
Error* err;
|
||||
int line = prev()->line;
|
||||
match_newlines();
|
||||
check(EXPR_TUPLE_ALLOW_SLICE(self, true));
|
||||
match_newlines();
|
||||
consume(TK_RBRACKET); // [lhs, rhs]
|
||||
SubscrExpr* e = SubscrExpr__new(line);
|
||||
e->rhs = Ctx__s_popx(ctx()); // [lhs]
|
||||
@ -2360,7 +2346,6 @@ static Error* _compile_f_args(Compiler* self, FuncDecl* decl, bool is_lambda) {
|
||||
int state = 0; // 0 for args, 1 for *args, 2 for k=v, 3 for **kwargs
|
||||
Error* err;
|
||||
do {
|
||||
if(!is_lambda) match_newlines();
|
||||
if(state >= 3) return SyntaxError(self, "**kwargs should be the last argument");
|
||||
if(match(TK_MUL)) {
|
||||
if(state < 1)
|
||||
@ -2399,7 +2384,6 @@ static Error* _compile_f_args(Compiler* self, FuncDecl* decl, bool is_lambda) {
|
||||
break;
|
||||
}
|
||||
} while(match(TK_COMMA));
|
||||
if(!is_lambda) match_newlines();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -2603,7 +2587,6 @@ __EAT_DOTS_END:
|
||||
|
||||
bool has_bracket = match(TK_LPAREN);
|
||||
do {
|
||||
if(has_bracket) match_newlines();
|
||||
Ctx__emit_(ctx(), OP_DUP_TOP, BC_NOARG, BC_KEEPLINE);
|
||||
consume(TK_ID);
|
||||
c11_sv name = Token__sv(prev());
|
||||
@ -2614,10 +2597,7 @@ __EAT_DOTS_END:
|
||||
}
|
||||
Ctx__emit_store_name(ctx(), name_scope(self), py_namev(name), prev()->line);
|
||||
} while(match(TK_COMMA));
|
||||
if(has_bracket) {
|
||||
match_newlines();
|
||||
consume(TK_RPAREN);
|
||||
}
|
||||
if(has_bracket) { consume(TK_RPAREN); }
|
||||
Ctx__emit_(ctx(), OP_POP_TOP, BC_NOARG, BC_KEEPLINE);
|
||||
consume_end_stmt();
|
||||
return NULL;
|
||||
|
||||
@ -565,6 +565,7 @@ static Error* lex_one_token(Lexer* self, bool* eof, bool is_fstring) {
|
||||
case ' ':
|
||||
case '\t': eat_spaces(self); break;
|
||||
case '\n': {
|
||||
if(self->brackets_level > 0) return NULL;
|
||||
add_token(self, TK_EOL);
|
||||
if(!eat_indentation(self)) {
|
||||
return LexerError(self, "unindent does not match any outer indentation level");
|
||||
|
||||
@ -28,4 +28,39 @@ else:
|
||||
and 4
|
||||
|
||||
a = 1
|
||||
assert a == 1
|
||||
assert a == 1
|
||||
|
||||
# https://github.com/pocketpy/pocketpy/issues/408
|
||||
x = (
|
||||
1
|
||||
+
|
||||
2
|
||||
)
|
||||
|
||||
# https://peps.python.org/pep-0008/#should-a-line-break-before-or-after-a-binary-operator
|
||||
compile('''
|
||||
income = (gross_wages
|
||||
+ taxable_interest
|
||||
+ (dividends - qualified_dividends)
|
||||
- ira_deduction
|
||||
- student_loan_interest)
|
||||
'''.strip(), 'main.py', 'exec')
|
||||
|
||||
res = []
|
||||
class Thing:
|
||||
def do_a(self):
|
||||
res.append("A")
|
||||
return self
|
||||
def do_b(self):
|
||||
res.append("B")
|
||||
return self
|
||||
def do_c(self):
|
||||
res.append("C")
|
||||
return self
|
||||
|
||||
(Thing()
|
||||
.do_a()
|
||||
.do_b()
|
||||
.do_c())
|
||||
|
||||
assert res == ["A", "B", "C"]
|
||||
|
||||
@ -125,9 +125,8 @@ else:
|
||||
assert x == 2
|
||||
|
||||
# match case
|
||||
|
||||
case, _ = 1, 2
|
||||
assert case == 1 and _ == 2
|
||||
case, _1 = 1, 2
|
||||
assert case == 1 and _1 == 2
|
||||
|
||||
match (404 * 1):
|
||||
case 200:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user