pocketpy / pocketpy Goto Github PK
View Code? Open in Web Editor NEWOpen Source Python Interpreter in 1 File for Game Scripting
Home Page: https://pocketpy.dev/
License: MIT License
Open Source Python Interpreter in 1 File for Game Scripting
Home Page: https://pocketpy.dev/
License: MIT License
I wanted to get a quick idea about performance in a one liner, compared to python (3.10.6):
$ time (echo -e "def f(x): return 1 if x <= 2 else f(x-1) + f(x-2)\n\nfor i in range(1,34): print (f(i))" | python3)
real 0m0,935s
user 0m0,934s
sys 0m0,000s
But that fails to run in pocketpy atm:
File "main.py", line 1
def f(x): return 1 if x <= 2 else f(x-1) + f(x-2)
^
SyntaxError: expected statement end
So here's the pocketpy version with traditional if:
// == pocketpy-fib.cc ==
#include "pocketpy.h"
int main (int argc, const char *argv[]) {
VM *vm = pkpy_new_vm (true);
const char *fib = "def f(x):\n"
" if x <= 2: return 1\n"
" return f(x-1) + f(x-2) \n"
"\n"
"for i in range(1,34): print (f(i))\n";
pkpy_vm_exec (vm, fib);
pkpy_delete (vm);
return 0;
}
$ g++ -std=gnu++17 -Wall -O3 -march=native pocketpy-fib.cc && time ./a.out
real 0m4,976s
user 0m4,975s
sys 0m0,000s
Nice tiny interpreter! ;-)
There's a common use case of wanting to use the pocketpy.h
header as a header (without implementation) and also as a header (with implementation): basically to compile the implementation part into a dynamic or static library and then use it with only the header part.
Currently the header is really just the implementation:
#ifndef POCKETPY_H
#define POCKETPY_H
// ... header + implementation
#endif // POCKETPY_H
whereas I suggest to change it to a classic split structure:
#ifndef POCKETPY_H
#define POCKETPY_H
// ... only header part
#endif // POCKETPY_H
#ifdef POCKETPY_IMPLEMENTATION
// ... only implementation part
#endif // POCKETPY_IMPLEMENTATION
In the latter case, I can use pocketpy.h
in header-only mode as follows:
#include "pocketpy.h"
and as header + implementation mode as follows:
#include "pocketpy.h"
#define POCKETPY_IMPLEMENTATION
Would be cool to have support for the walrus operator 😁
Hi,
Thanks very much for creating this project. I'm really enjoying using your library in a max external plugin, I have been working on recently:
I'm really interested in setting the working directory for imports (like a pythonpath) or in some kind of execfile(path) support where path is python script.
Is this something already available or planned?
After 0.9.5
, PocketPy will change its memory management strategy from reference counting to garbage collection.
Currently, only the first two args of slice()
is handled.
Hello @blueloveTH,
I've been playing with pocketpy
and here are some syntax errors that are valid in cpython but not in pkpy.
1-tuple or empty tuple:
(1,) # SyntaxError
1, # SyntaxError
() # SyntaxError
tuple() # TypeError
Empty list slice:
[][:-1] # std::exception
One line if/function:
if 1: pass # SyntaxError
def f(): pass # SyntaxError
Do you think they should be valid pkpy code as well?
Hi, when I try below code, it throws an error.
d = r"=function\(\w\)\{[a-z=\.\(\)\"]*;(.*);"
Error: SyntaxError: expected statement end
flutter build apk
Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!
💪 Building with sound null safety 💪
Building with Flutter multidex support enabled.
FAILURE: Build failed with an exception.
Build command failed.
Error while executing process /home/mkw/Android/Sdk/cmake/3.18.1/bin/ninja with arguments {-C /home/mkw/.pub-cache/hosted/pub.dev/pocketpy-0.9.3/android/.cxx/RelWithDebInfo/161p5t12/arm64-v8a pocketpy}
ninja: Entering directory `/home/mkw/.pub-cache/hosted/pub.dev/pocketpy-0.9.3/android/.cxx/RelWithDebInfo/161p5t12/arm64-v8a'
[1/2] Building CXX object CMakeFiles/pocketpy.dir/pocketpy.cpp.o
FAILED: CMakeFiles/pocketpy.dir/pocketpy.cpp.o
/home/mkw/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=aarch64-none-linux-android21 --gcc-toolchain=/home/mkw/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/home/mkw/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot -DDART_SHARED_LIB -Dpocketpy_EXPORTS -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -O2 -g -DNDEBUG -fPIC -fno-rtti -std=gnu++17 -MD -MT CMakeFiles/pocketpy.dir/pocketpy.cpp.o -MF CMakeFiles/pocketpy.dir/pocketpy.cpp.o.d -o CMakeFiles/pocketpy.dir/pocketpy.cpp.o -c /home/mkw/.pub-cache/hosted/pub.dev/pocketpy-0.9.3/src/pocketpy.cpp
In file included from /home/mkw/.pub-cache/hosted/pub.dev/pocketpy-0.9.3/src/pocketpy.cpp:1:
In file included from /home/mkw/.pub-cache/hosted/pub.dev/pocketpy-0.9.3/src/pocketpy.h:19:
In file included from /snap/flutter/current/usr/include/c++/9/regex:45:
/snap/flutter/current/usr/include/c++/9/memory:121:25: error: cast from pointer to smaller type 'uintptr_t' (aka 'unsigned int') loses information
const auto __intptr = reinterpret_cast<uintptr_t>(__ptr);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/mkw/.pub-cache/hosted/pub.dev/pocketpy-0.9.3/src/pocketpy.cpp:1:
/home/mkw/.pub-cache/hosted/pub.dev/pocketpy-0.9.3/src/pocketpy.h:5353:54: error: cast from pointer to smaller type 'uintptr_t' (aka 'unsigned int') loses information
std::uintptr_t addr = self.is_tagged() ? 0 : (uintptr_t)self.get();
^~~~~~~~~~~~~~~~~~~~~
2 errors generated.
ninja: build stopped: subcommand failed.
Run with --stacktrace option to get the stack trace.
Run with --info or --debug option to get more log output.
Run with --scan to get full insights.
BUILD FAILED in 7s
Running Gradle task 'assembleRelease'... 8.5s
Gradle task assembleRelease failed with exit code 1
https://en.cppreference.com/w/cpp/language/identifiers
When I used this interpreter to calculate 99**99
, there was an overflow. Do you need to solve this problem? I know this is a lightweight interpreter, and I'm not a game developer, just a simple curiosity, thanks.
https://docs.python.org/3/c-api/call.html#the-tp-call-protocol
We plan to impl tp_call protocol, whenever a function contains *args
or **kwargs
, tp_call will be used instead of vectorcall.
The pickle module implements binary protocols for serializing and de-serializing a Python object structure. “Pickling” is the process whereby a Python object hierarchy is converted into a byte stream, and “unpickling” is the inverse operation, whereby a bytes
object is converted back into an object hierarchy.
Currently, the bytes
class in pkpy has been implemented. A serialization mechanism similar to pickle
is highly needed to achieve deep copying of objects. Our pickle mechanism should have similar functionality to cpython, but it does not necessarily need to be compatible (if achieving compatibility is complex)
checking out the repository and running the command
g++ --std=c++17 main.cpp
in the src/ directory does not successfully compile, it fails with this error :
In file included from ceval.h:3,
from pocketpy.h:3,
from main.cpp:4:
lexer.h: In function ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’:
common.h:127:23: error: expression ‘<throw-expression>’ is not a constant expression
127 | #define FATAL_ERROR() throw std::runtime_error( __FILE__ + std::string(":") + std::to_string(__LINE__) + " FATAL_ERROR()!");
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lexer.h:41:5: note: in expansion of macro ‘FATAL_ERROR’
41 | FATAL_ERROR();
| ^~~~~~~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h: In member function ‘void pkpy::Lexer::add_token(pkpy::TokenIndex, pkpy::TokenValue)’:
lexer.h:264:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
264 | case TK("{"): case TK("["): case TK("("): brackets_level++; break;
| ~~^~~~~
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
lexer.h:264:34: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
264 | case TK("{"): case TK("["): case TK("("): brackets_level++; break;
| ~~^~~~~
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
lexer.h:264:48: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
264 | case TK("{"): case TK("["): case TK("("): brackets_level++; break;
| ~~^~~~~
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
lexer.h:265:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
265 | case TK(")"): case TK("]"): case TK("}"): brackets_level--; break;
| ~~^~~~~
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
lexer.h:265:34: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
265 | case TK(")"): case TK("]"): case TK("}"): brackets_level--; break;
| ~~^~~~~
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
lexer.h:265:48: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
265 | case TK(")"): case TK("]"): case TK("}"): brackets_level--; break;
| ~~^~~~~
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
expr.h: In member function ‘virtual void pkpy::Literal0Expr::emit(pkpy::CodeEmitContext*)’:
expr.h:247:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
247 | case TK("None"): ctx->emit(OP_LOAD_NONE, BC_NOARG, line); break;
| ~~^~~~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
expr.h:248:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
248 | case TK("True"): ctx->emit(OP_LOAD_TRUE, BC_NOARG, line); break;
| ~~^~~~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
expr.h:249:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
249 | case TK("False"): ctx->emit(OP_LOAD_FALSE, BC_NOARG, line); break;
| ~~^~~~~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
expr.h:250:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
250 | case TK("..."): ctx->emit(OP_LOAD_ELLIPSIS, BC_NOARG, line); break;
| ~~^~~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
expr.h: In member function ‘virtual void pkpy::BinaryExpr::emit(pkpy::CodeEmitContext*)’:
expr.h:673:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
673 | case TK("+"): ctx->emit(OP_BINARY_ADD, BC_NOARG, line); break;
| ~~^~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
expr.h:674:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
674 | case TK("-"): ctx->emit(OP_BINARY_SUB, BC_NOARG, line); break;
| ~~^~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
expr.h:675:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
675 | case TK("*"): ctx->emit(OP_BINARY_MUL, BC_NOARG, line); break;
| ~~^~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
expr.h:676:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
676 | case TK("/"): ctx->emit(OP_BINARY_OP, 3, line); break;
| ~~^~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
expr.h:677:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
677 | case TK("//"): ctx->emit(OP_BINARY_FLOORDIV, BC_NOARG, line); break;
| ~~^~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
expr.h:678:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
678 | case TK("%"): ctx->emit(OP_BINARY_MOD, BC_NOARG, line); break;
| ~~^~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
expr.h:679:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
679 | case TK("**"): ctx->emit(OP_BINARY_OP, 6, line); break;
| ~~^~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
expr.h:681:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
681 | case TK("<"): ctx->emit(OP_COMPARE_LT, BC_NOARG, line); break;
| ~~^~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
expr.h:682:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
682 | case TK("<="): ctx->emit(OP_COMPARE_LE, BC_NOARG, line); break;
| ~~^~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
expr.h:683:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
683 | case TK("=="): ctx->emit(OP_COMPARE_EQ, BC_NOARG, line); break;
| ~~^~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
expr.h:684:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
684 | case TK("!="): ctx->emit(OP_COMPARE_NE, BC_NOARG, line); break;
| ~~^~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
expr.h:685:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
685 | case TK(">"): ctx->emit(OP_COMPARE_GT, BC_NOARG, line); break;
| ~~^~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
expr.h:686:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
686 | case TK(">="): ctx->emit(OP_COMPARE_GE, BC_NOARG, line); break;
| ~~^~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
expr.h:687:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
687 | case TK("in"): ctx->emit(OP_CONTAINS_OP, 0, line); break;
| ~~^~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
expr.h:688:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
688 | case TK("not in"): ctx->emit(OP_CONTAINS_OP, 1, line); break;
| ~~^~~~~~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
expr.h:689:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
689 | case TK("is"): ctx->emit(OP_IS_OP, 0, line); break;
| ~~^~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
expr.h:690:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
690 | case TK("is not"): ctx->emit(OP_IS_OP, 1, line); break;
| ~~^~~~~~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
expr.h:692:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
692 | case TK("<<"): ctx->emit(OP_BITWISE_LSHIFT, BC_NOARG, line); break;
| ~~^~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
expr.h:693:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
693 | case TK(">>"): ctx->emit(OP_BITWISE_RSHIFT, BC_NOARG, line); break;
| ~~^~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
expr.h:694:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
694 | case TK("&"): ctx->emit(OP_BITWISE_AND, BC_NOARG, line); break;
| ~~^~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
expr.h:695:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
695 | case TK("|"): ctx->emit(OP_BITWISE_OR, BC_NOARG, line); break;
| ~~^~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
expr.h:696:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
696 | case TK("^"): ctx->emit(OP_BITWISE_XOR, BC_NOARG, line); break;
| ~~^~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h: In member function ‘void pkpy::Compiler::exprUnaryOp()’:
compiler.h:287:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
287 | case TK("-"):
| ~~^~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h:290:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
290 | case TK("*"):
| ~~^~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h: In member function ‘bool pkpy::Compiler::try_compile_assignment()’:
compiler.h:666:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
666 | case TK("+="): case TK("-="): case TK("*="): case TK("/="): case TK("//="): case TK("%="):
| ~~^~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h:666:35: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
666 | case TK("+="): case TK("-="): case TK("*="): case TK("/="): case TK("//="): case TK("%="):
| ~~^~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h:666:50: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
666 | case TK("+="): case TK("-="): case TK("*="): case TK("/="): case TK("//="): case TK("%="):
| ~~^~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h:666:65: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
666 | case TK("+="): case TK("-="): case TK("*="): case TK("/="): case TK("//="): case TK("%="):
| ~~^~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h:666:80: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
666 | case TK("+="): case TK("-="): case TK("*="): case TK("/="): case TK("//="): case TK("%="):
| ~~^~~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h:666:96: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
666 | case TK("+="): case TK("-="): case TK("*="): case TK("/="): case TK("//="): case TK("%="):
| ~~^~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h:667:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
667 | case TK("<<="): case TK(">>="): case TK("&="): case TK("|="): case TK("^="): {
| ~~^~~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h:667:36: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
667 | case TK("<<="): case TK(">>="): case TK("&="): case TK("|="): case TK("^="): {
| ~~^~~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h:667:52: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
667 | case TK("<<="): case TK(">>="): case TK("&="): case TK("|="): case TK("^="): {
| ~~^~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h:667:67: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
667 | case TK("<<="): case TK(">>="): case TK("&="): case TK("|="): case TK("^="): {
| ~~^~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h:667:82: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
667 | case TK("<<="): case TK(">>="): case TK("&="): case TK("|="): case TK("^="): {
| ~~^~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h:678:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
678 | case TK("="):
| ~~^~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h: In member function ‘void pkpy::Compiler::compile_stmt()’:
compiler.h:703:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
703 | case TK("break"):
| ~~^~~~~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h:708:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
708 | case TK("continue"):
| ~~^~~~~~~~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h:713:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
713 | case TK("yield"):
| ~~^~~~~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h:721:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
721 | case TK("yield from"):
| ~~^~~~~~~~~~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h:734:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
734 | case TK("return"):
| ~~^~~~~~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h:745:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
745 | case TK("if"): compile_if_stmt(); break;
| ~~^~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h:746:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
746 | case TK("while"): compile_while_loop(); break;
| ~~^~~~~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h:747:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
747 | case TK("for"): compile_for_loop(); break;
| ~~^~~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h:748:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
748 | case TK("import"): compile_normal_import(); break;
| ~~^~~~~~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h:749:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
749 | case TK("from"): compile_from_import(); break;
| ~~^~~~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h:750:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
750 | case TK("def"): compile_function(); break;
| ~~^~~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h:751:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
751 | case TK("@"): compile_decorated(); break;
| ~~^~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h:752:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
752 | case TK("try"): compile_try_except(); break;
| ~~^~~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h:753:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
753 | case TK("pass"): consume_end_stmt(); break;
| ~~^~~~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h:755:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
755 | case TK("assert"):
| ~~^~~~~~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h:760:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
760 | case TK("global"):
| ~~^~~~~~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h:767:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
767 | case TK("raise"): {
| ~~^~~~~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h:778:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
778 | case TK("del"): {
| ~~^~~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h:785:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
785 | case TK("with"): {
| ~~^~~~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h:799:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
799 | case TK("label"): {
| ~~^~~~~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h:806:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
806 | case TK("goto"):
| ~~^~~~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h: In member function ‘pkpy::PyObject* pkpy::Compiler::read_literal()’:
compiler.h:980:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
980 | case TK("-"): {
| ~~^~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h:985:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
985 | case TK("@num"): return to_object(prev().value);
| ~~^~~~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h:986:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
986 | case TK("@str"): return to_object(prev().value);
| ~~^~~~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h:987:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
987 | case TK("True"): return VAR(true);
| ~~^~~~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h:988:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
988 | case TK("False"): return VAR(false);
| ~~^~~~~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h:989:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
989 | case TK("None"): return vm->None;
| ~~^~~~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:4,
from main.cpp:4:
compiler.h:990:20: error: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ called in a constant expression
990 | case TK("..."): return vm->Ellipsis;
| ~~^~~~~~~
In file included from expr.h:5,
from compiler.h:5,
from pocketpy.h:4,
from main.cpp:4:
lexer.h:34:22: note: ‘constexpr pkpy::TokenIndex pkpy::TK(const char*)’ declared here
34 | constexpr TokenIndex TK(const char token[]) {
| ^~
In file included from pocketpy.h:9,
from main.cpp:4:
io.h: In constructor ‘pkpy::FileIO::FileIO(pkpy::VM*, pkpy::Str, pkpy::Str)’:
io.h:34:41: error: invalid conversion from ‘int’ to ‘std::ios_base::openmode’ [-fpermissive]
34 | std::ios_base::openmode extra = 0;
| ^
| |
| int
io.h:39:53: error: no matching function for call to ‘std::basic_fstream<char>::open(std::string_view, std::_Ios_Openmode)’
39 | _fs.open(file.sv(), std::ios::in | extra);
| ^
In file included from main.cpp:1:
/usr/include/c++/10/fstream:1177:7: note: candidate: ‘void std::basic_fstream<_CharT, _Traits>::open(const char*, std::ios_base::openmode) [with _CharT = char; _Traits = std::char_traits<char>; std::ios_base::openmode = std::ios_base::openmode]’
1177 | open(const char* __s,
| ^~~~
/usr/include/c++/10/fstream:1177:24: note: no known conversion for argument 1 from ‘std::string_view’ {aka ‘std::basic_string_view<char>’} to ‘const char*’
1177 | open(const char* __s,
| ~~~~~~~~~~~~^~~
/usr/include/c++/10/fstream:1218:7: note: candidate: ‘void std::basic_fstream<_CharT, _Traits>::open(const string&, std::ios_base::openmode) [with _CharT = char; _Traits = std::char_traits<char>; std::string = std::__cxx11::basic_string<char>; std::ios_base::openmode = std::ios_base::openmode]’
1218 | open(const std::string& __s,
| ^~~~
/usr/include/c++/10/fstream:1218:31: note: no known conversion for argument 1 from ‘std::string_view’ {aka ‘std::basic_string_view<char>’} to ‘const string&’ {aka ‘const std::__cxx11::basic_string<char>&’}
1218 | open(const std::string& __s,
| ~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/fstream:1240:2: note: candidate: ‘template<class _Path> std::_If_fs_path<_Path, void> std::basic_fstream<_CharT, _Traits>::open(const _Path&, std::ios_base::openmode) [with _Path = _Path; _CharT = char; _Traits = std::char_traits<char>]’
1240 | open(const _Path& __s,
| ^~~~
/usr/include/c++/10/fstream:1240:2: note: template argument deduction/substitution failed:
/usr/include/c++/10/fstream: In substitution of ‘template<class _Path> std::_If_fs_path<_Path, void, decltype (declval<_Path&>().make_preferred().filename())> std::basic_fstream<char>::open<_Path>(const _Path&, std::ios_base::openmode) [with _Path = std::basic_string_view<char>]’:
io.h:39:53: required from here
/usr/include/c++/10/fstream:1240:2: error: ‘class std::basic_string_view<char>’ has no member named ‘make_preferred’
In file included from pocketpy.h:9,
from main.cpp:4:
io.h:41:54: error: no matching function for call to ‘std::basic_fstream<char>::open(std::string_view, std::_Ios_Openmode)’
41 | _fs.open(file.sv(), std::ios::out | extra);
| ^
In file included from main.cpp:1:
/usr/include/c++/10/fstream:1177:7: note: candidate: ‘void std::basic_fstream<_CharT, _Traits>::open(const char*, std::ios_base::openmode) [with _CharT = char; _Traits = std::char_traits<char>; std::ios_base::openmode = std::ios_base::openmode]’
1177 | open(const char* __s,
| ^~~~
/usr/include/c++/10/fstream:1177:24: note: no known conversion for argument 1 from ‘std::string_view’ {aka ‘std::basic_string_view<char>’} to ‘const char*’
1177 | open(const char* __s,
| ~~~~~~~~~~~~^~~
/usr/include/c++/10/fstream:1218:7: note: candidate: ‘void std::basic_fstream<_CharT, _Traits>::open(const string&, std::ios_base::openmode) [with _CharT = char; _Traits = std::char_traits<char>; std::string = std::__cxx11::basic_string<char>; std::ios_base::openmode = std::ios_base::openmode]’
1218 | open(const std::string& __s,
| ^~~~
/usr/include/c++/10/fstream:1218:31: note: no known conversion for argument 1 from ‘std::string_view’ {aka ‘std::basic_string_view<char>’} to ‘const string&’ {aka ‘const std::__cxx11::basic_string<char>&’}
1218 | open(const std::string& __s,
| ~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/fstream:1240:2: note: candidate: ‘template<class _Path> std::_If_fs_path<_Path, void> std::basic_fstream<_CharT, _Traits>::open(const _Path&, std::ios_base::openmode) [with _Path = _Path; _CharT = char; _Traits = std::char_traits<char>]’
1240 | open(const _Path& __s,
| ^~~~
/usr/include/c++/10/fstream:1240:2: note: template argument deduction/substitution failed:
/usr/include/c++/10/fstream: In substitution of ‘template<class _Path> std::_If_fs_path<_Path, void, decltype (declval<_Path&>().make_preferred().filename())> std::basic_fstream<char>::open<_Path>(const _Path&, std::ios_base::openmode) [with _Path = std::basic_string_view<char>]’:
io.h:41:54: required from here
/usr/include/c++/10/fstream:1240:2: error: ‘class std::basic_string_view<char>’ has no member named ‘make_preferred’
In file included from pocketpy.h:9,
from main.cpp:4:
io.h:43:54: error: no matching function for call to ‘std::basic_fstream<char>::open(std::string_view, std::_Ios_Openmode)’
43 | _fs.open(file.sv(), std::ios::app | extra);
| ^
In file included from main.cpp:1:
/usr/include/c++/10/fstream:1177:7: note: candidate: ‘void std::basic_fstream<_CharT, _Traits>::open(const char*, std::ios_base::openmode) [with _CharT = char; _Traits = std::char_traits<char>; std::ios_base::openmode = std::ios_base::openmode]’
1177 | open(const char* __s,
| ^~~~
/usr/include/c++/10/fstream:1177:24: note: no known conversion for argument 1 from ‘std::string_view’ {aka ‘std::basic_string_view<char>’} to ‘const char*’
1177 | open(const char* __s,
| ~~~~~~~~~~~~^~~
/usr/include/c++/10/fstream:1218:7: note: candidate: ‘void std::basic_fstream<_CharT, _Traits>::open(const string&, std::ios_base::openmode) [with _CharT = char; _Traits = std::char_traits<char>; std::string = std::__cxx11::basic_string<char>; std::ios_base::openmode = std::ios_base::openmode]’
1218 | open(const std::string& __s,
| ^~~~
/usr/include/c++/10/fstream:1218:31: note: no known conversion for argument 1 from ‘std::string_view’ {aka ‘std::basic_string_view<char>’} to ‘const string&’ {aka ‘const std::__cxx11::basic_string<char>&’}
1218 | open(const std::string& __s,
| ~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/fstream:1240:2: note: candidate: ‘template<class _Path> std::_If_fs_path<_Path, void> std::basic_fstream<_CharT, _Traits>::open(const _Path&, std::ios_base::openmode) [with _Path = _Path; _CharT = char; _Traits = std::char_traits<char>]’
1240 | open(const _Path& __s,
| ^~~~
/usr/include/c++/10/fstream:1240:2: note: template argument deduction/substitution failed:
/usr/include/c++/10/fstream: In substitution of ‘template<class _Path> std::_If_fs_path<_Path, void, decltype (declval<_Path&>().make_preferred().filename())> std::basic_fstream<char>::open<_Path>(const _Path&, std::ios_base::openmode) [with _Path = std::basic_string_view<char>]’:
io.h:43:54: required from here
/usr/include/c++/10/fstream:1240:2: error: ‘class std::basic_string_view<char>’ has no member named ‘make_preferred’
this is on a raspberry pi 4b, with gcc version 10.2.1
attempting to compile the main.cpp with the release pocketpy.h results in the same issue
I think that pocketpy is awesome, but i really would like to have a more efficient edit-compile-run cycle, I was thinking of bridging this to c++20 modules, but im not sure it would work bc of static members and stuff.
Hello @blueloveTH
I hope this message finds you well. First and foremost, I want to express my appreciation for the work you've done on the pocketpy project. I believe it's a valuable tool that has been beneficial to many users in the Python community.
I'm writing this issue to let you know that I would like to provide sponsorship to the pocketpy project. While I may not be able to contribute a significant amount, I would still like to offer some support to help the project continue to grow and thrive.
In addition to this, I would also like to extend an invitation for you to become a technical advisor for the pikapython project (https://github.com/pikastech/pikapython). Your expertise and experience with pocketpy could be extremely valuable for our team as we continue to develop and improve our project.
Please note that the sponsorship offer stands regardless of whether you accept the technical advisor invitation or not.
Please let me know how I can proceed with the sponsorship and if you're interested in becoming a technical advisor for pikapython. I look forward to hearing from you soon.
Thank you for your time and consideration.
I recently found PocketPy through Flutter but ran into issues building it with Flutter. It looks like the API was removed.
Are there plans to bring it back to life or is Flutter officially dropped as a supported target?
__mod__
for str
format
for str
Thank for this clever python alike library! This could be useful for many applications, not only gaming.
Sorry for my ignorance: What is the easiest way to exchange scalar data (float, int) beside of chars with the help of the C-API? And is there a way to exchange arrays of data of uniform data types?
And as I'm curious: what is the meaning of pkpy_setup_callbacks
?
I'm thinking of using pocketpy as a kind of programmable input-file for data processing.
Just like python2's long
.
If you define a function that pushes a value and then falls off the end, it returns the value:
>>> def foo(): 1
>>> foo()
1
>>>
This should probably return None
instead.
I would like to get a better sense of how PocketPy intends to develop as a language. Does it aim to strictly retain as close a relationship to Python as possible, in terms of syntax and functionality? Or, does it aim to simply be Python-like in spirit?
For example, here are some non-Python features / syntax I would like to see (and will probably try to implement on my fork):
d = {"a": 1} ; assert d.a == 1
lambda
syntax. One idea:add = x, y -> x + y
const = None -> 1
((x, y, z) -> x + y + z)(1,1,1)
for
loops. One idea:for x in Iter1 as outer:
for y in Iter2 as inner:
if f(x, y):
break outer # Break out of both loops
Another thing I noticed is that dict
is implemented in Pocketpy, instead of in CPP. Could you explain the motivation for this? Is this motivated by keeping the language core as small as possible?
Generally, I am trying to gauge what sort of contributions that extend the language, would be welcome.
I've been recently converting my project's pocketpy code to the latest pocketpy 1.0 version and I found (at least for me) what looks like a bug or a feature regression:
In the older 0.9.5 code, I could a bind a builtin function like this without issues:
x->py->vm->bind_builtin_func<1>("out_int", [x](VM* vm, Args& args) {
i64 a = CAST(i64, args[0]);
outlet_int(x->outlet, a);
return vm->None;
});
When I translated the same code to the new 1.0+ idioms:
x->py->vm->bind_builtin_func<1>("out_int", [x](VM* vm, ArgsView args) {
i64 a = CAST(i64, args[0]);
outlet_int(x->outlet, a);
return vm->None;
});
I cannot compile it and I get the following error:
src/pktpy/pktpy.cpp:436:16: fatal error: no matching member function for call to 'bind_builtin_func'
x->py->vm->bind_builtin_func<1>("out_int", [x](VM* vm, ArgsView args) {
~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
src/pktpy/pocketpy.h:3727:15: note: candidate function template not viable:
no known conversion from '(lambda at src/pktpy/pktpy.cpp:436:48)' to 'pkpy::NativeFuncC' (aka 'pkpy::PyObject *(*)(pkpy::VM *, pkpy::ArgsView)') for 2nd argument
PyObject* bind_builtin_func(Str name, NativeFuncC fn) {
^
Is there any way to resolve this?
Idk how hard it would be to implement, but here is my idea:
Instead of executing whole code at once add a function that will work something like this:
auto code = vm->compile("some long python code", EXEC_MODE)
auto max_pass_bytecode_instructions = 1000 // maximum amount of instructions that vm can execute in one pass
while (true) {
//nullptr because code is not finished executing
if (vm->_exec_partial(max_pass_bytecode_instructions, code, vm->_main) != nullptr) {break;}
}
This will allow to have several separate VM's running on one thread without making several threads for each VM.
See https://peps.python.org/pep-0590/.
We will implement a similar protocol and it should lead to huge performance gain.
map(lambda x: x**2, [1, 2, 3, 4, 5] )
~~~~~~~~~~~~~~~~~~~~~
Will be interpreted as a tuple
and cause a TypeError
.
Hello, I was playing with the REPL and when I type the following code, it gives segmentation fault:
>>> dir("s")
[1] 144790 segmentation fault (core dumped) ./pocketpy
And this one as well:
>>> s = "s"
>>> dir(s)
[1] 144790 segmentation fault (core dumped) ./pocketpy
I only got this error when using dir
with strings, it seems to work properly for other types.
Add full platform support for flutter, such as Linux and Mac
Will __getattr__
be available for overriding? Would this amount to binding the CPP method when classes are instantiated?
Why was the Godot plugin removed?
Currently, several of the Python files do not conform to standard formatting. We can implement pre-commit hooks and also use GitHub Actions if desired.
D:\artifact\windows\x86_64>pocketpy.exe 2.py
Traceback (most recent call last):
File "2.py", line 1
import demo
ImportError: module 'demo' not found
you can define maco EMH_WYHASH_HASH before including head file hash_table8.hpp
which is more efficient than std::hash
We'd like to use an online judge dataset to evaluate the interpreter in a more comprehensive way.
We want to provide a minimum set of datetime
.
See https://pocketpy.dev/modules/datetime/ for the api set.
Assets\PocketPy\FFI.cs(27,52):
error CS0656: Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create'
Reproducible by creating an empty 3d project in Unity 2021.3.15f1 and importing PocketPy from the Asset Store.
Setting the 'Api Compatibility Level' option in Player settings from .NET Standard 2.1 (default) to .NET Framework fixes this error.
The code referenced:
static object invoke_f_any(string s)
{
var parts = s.Split(' ');
List<dynamic> args = new List<dynamic>();
for (int i = 1; i < parts.Length; i++) args.Add(parse(parts[i]));
var f = mappings[parts[0]];
return f.DynamicInvoke(args.ToArray());
}
I believe it could be related to List args being dynamic
The docs for the internal C++ APIs are missing. Some game developers need them.
it seems like _exec should give you the pyobject that results from the last statement it runs, but instead it seems like it always returns None.
This might be intended behavior and if it is that is fine, I just figured I would check
Currently, user defined classes are not able to derive from a c implemented type (unsafe).
We are planning a feature. One can mark a c implemented type as subclass enabled. And provide a special CAST macro for this case.
The access of local variables is really fast in cpython via OP_LOAD_FAST
.
We should implement it.
Hi @blueloveTH
Very cool project. Thanks very sharing!
Incidentally, I had trouble compiling the c-example on macOS 12.6.3 (Monterey) x86_64 without changing this line
VM* vm = pkpy_new_vm(true);
to
pkpy::VM* vm = pkpy_new_vm(true);
using
clang++ --std=c++17 -o demo demo.cpp
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.