mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
up
This commit is contained in:
parent
bc001143f2
commit
40a37d1846
72
.github/workflows/main.yml
vendored
72
.github/workflows/main.yml
vendored
@ -10,39 +10,8 @@ jobs:
|
|||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
CL -std:c++17 -GR- -EHsc -O2 -Fe:pocketpy src/main.cpp
|
CL -std:c++17 -GR- -EHsc -O2 -Fe:pocketpy src/main.cpp
|
||||||
mv src/pocketpy.h src/pocketpy.cpp
|
python3 scripts/run_tests.py
|
||||||
CL -std:c++17 -GR- -EHsc -O2 -LD -Fe:pocketpy src/pocketpy.cpp
|
./pocketpy tests/1.py
|
||||||
mkdir -p output/windows/x86_64
|
|
||||||
mv pocketpy.exe output/windows/x86_64
|
|
||||||
mv pocketpy.dll output/windows/x86_64
|
|
||||||
- uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
path: output
|
|
||||||
build_web:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- name: Setup emsdk
|
|
||||||
uses: mymindstorm/setup-emsdk@v11
|
|
||||||
with:
|
|
||||||
version: 3.1.25
|
|
||||||
actions-cache-folder: 'emsdk-cache'
|
|
||||||
- name: Verify emsdk
|
|
||||||
run: emcc -v
|
|
||||||
- name: Compiling
|
|
||||||
run: |
|
|
||||||
mkdir -p output/web/lib
|
|
||||||
bash build_wasm.sh
|
|
||||||
cp web/lib/* output/web/lib
|
|
||||||
- uses: crazy-max/ghaction-github-pages@v3
|
|
||||||
with:
|
|
||||||
target_branch: gh-pages
|
|
||||||
build_dir: web
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
- uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
path: output
|
|
||||||
build_test_linux:
|
build_test_linux:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
@ -51,39 +20,4 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
bash build_cpp.sh
|
bash build_cpp.sh
|
||||||
python3 scripts/run_tests.py
|
python3 scripts/run_tests.py
|
||||||
./pocketpy tests/1.py
|
./pocketpy tests/1.py
|
||||||
mkdir -p output/linux/x86_64
|
|
||||||
mv pocketpy output/linux/x86_64
|
|
||||||
- uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
path: output
|
|
||||||
build_android:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- uses: subosito/flutter-action@v2
|
|
||||||
with:
|
|
||||||
flutter-version: '3.0.0'
|
|
||||||
channel: 'stable'
|
|
||||||
- run: flutter --version
|
|
||||||
- name: Compiling
|
|
||||||
run: |
|
|
||||||
python3 amalgamate.py
|
|
||||||
cd plugins/flutter/example
|
|
||||||
flutter build apk --split-debug-info=.debug-info --split-per-abi
|
|
||||||
cd build/app/outputs/flutter-apk
|
|
||||||
mkdir -p output/android/arm64-v8a
|
|
||||||
mkdir -p output/android/armeabi-v7a
|
|
||||||
mkdir -p output/android/x86_64
|
|
||||||
unzip -q app-arm64-v8a-release.apk -d tmp
|
|
||||||
mv tmp/lib/arm64-v8a/libpocketpy.so output/android/arm64-v8a/libpocketpy.so
|
|
||||||
rm -rf tmp
|
|
||||||
unzip -q app-armeabi-v7a-release.apk -d tmp
|
|
||||||
mv tmp/lib/armeabi-v7a/libpocketpy.so output/android/armeabi-v7a/libpocketpy.so
|
|
||||||
rm -rf tmp
|
|
||||||
unzip -q app-x86_64-release.apk -d tmp
|
|
||||||
mv tmp/lib/x86_64/libpocketpy.so output/android/x86_64/libpocketpy.so
|
|
||||||
rm -rf tmp
|
|
||||||
- uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
path: plugins/flutter/example/build/app/outputs/flutter-apk/output
|
|
BIN
.github/workflows/main.zip
vendored
Normal file
BIN
.github/workflows/main.zip
vendored
Normal file
Binary file not shown.
@ -264,8 +264,8 @@ public:
|
|||||||
if(new_size < 0) throw std::runtime_error("stack_size() < n");
|
if(new_size < 0) throw std::runtime_error("stack_size() < n");
|
||||||
pkpy::ArgList v(n);
|
pkpy::ArgList v(n);
|
||||||
for(int i=n-1; i>=0; i--){
|
for(int i=n-1; i>=0; i--){
|
||||||
v._index(i) = std::move(s_data[new_size + i]);
|
v[i] = std::move(s_data[new_size + i]);
|
||||||
try_deref(vm, v._index(i));
|
try_deref(vm, v[i]);
|
||||||
}
|
}
|
||||||
s_data.resize(new_size);
|
s_data.resize(new_size);
|
||||||
return v;
|
return v;
|
||||||
@ -279,7 +279,7 @@ public:
|
|||||||
|
|
||||||
pkpy::ArgList pop_n_reversed(int n){
|
pkpy::ArgList pop_n_reversed(int n){
|
||||||
pkpy::ArgList v(n);
|
pkpy::ArgList v(n);
|
||||||
for(int i=n-1; i>=0; i--) v._index(i) = pop();
|
for(int i=n-1; i>=0; i--) v[i] = pop();
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
};
|
};
|
@ -19,10 +19,10 @@ _Code VM::compile(_Str source, _Str filename, CompileMode mode) {
|
|||||||
_vm->bindMethodMulti<1>({"int","float"}, #name, [](VM* vm, const pkpy::ArgList& args){ \
|
_vm->bindMethodMulti<1>({"int","float"}, #name, [](VM* vm, const pkpy::ArgList& args){ \
|
||||||
if(!vm->is_int_or_float(args[0], args[1])) \
|
if(!vm->is_int_or_float(args[0], args[1])) \
|
||||||
vm->typeError("unsupported operand type(s) for " #op ); \
|
vm->typeError("unsupported operand type(s) for " #op ); \
|
||||||
if(args._index(0)->is_type(vm->_tp_int) && args._index(1)->is_type(vm->_tp_int)){ \
|
if(args[0]->is_type(vm->_tp_int) && args[1]->is_type(vm->_tp_int)){ \
|
||||||
return vm->PyInt(vm->PyInt_AS_C(args._index(0)) op vm->PyInt_AS_C(args._index(1))); \
|
return vm->PyInt(vm->PyInt_AS_C(args[0]) op vm->PyInt_AS_C(args[1])); \
|
||||||
}else{ \
|
}else{ \
|
||||||
return vm->PyFloat(vm->num_to_float(args._index(0)) op vm->num_to_float(args._index(1))); \
|
return vm->PyFloat(vm->num_to_float(args[0]) op vm->num_to_float(args[1])); \
|
||||||
} \
|
} \
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ _Code VM::compile(_Str source, _Str filename, CompileMode mode) {
|
|||||||
if constexpr(is_eq) return vm->PyBool(args[0] == args[1]); \
|
if constexpr(is_eq) return vm->PyBool(args[0] == args[1]); \
|
||||||
vm->typeError("unsupported operand type(s) for " #op ); \
|
vm->typeError("unsupported operand type(s) for " #op ); \
|
||||||
} \
|
} \
|
||||||
return vm->PyBool(vm->num_to_float(args._index(0)) op vm->num_to_float(args._index(1))); \
|
return vm->PyBool(vm->num_to_float(args[0]) op vm->num_to_float(args[1])); \
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@ -216,17 +216,17 @@ void __initializeBuiltinFunctions(VM* _vm) {
|
|||||||
_vm->bindMethod<1>("int", "__floordiv__", [](VM* vm, const pkpy::ArgList& args) {
|
_vm->bindMethod<1>("int", "__floordiv__", [](VM* vm, const pkpy::ArgList& args) {
|
||||||
if(!args[0]->is_type(vm->_tp_int) || !args[1]->is_type(vm->_tp_int))
|
if(!args[0]->is_type(vm->_tp_int) || !args[1]->is_type(vm->_tp_int))
|
||||||
vm->typeError("unsupported operand type(s) for " "//" );
|
vm->typeError("unsupported operand type(s) for " "//" );
|
||||||
i64 rhs = vm->PyInt_AS_C(args._index(1));
|
i64 rhs = vm->PyInt_AS_C(args[1]);
|
||||||
if(rhs == 0) vm->zeroDivisionError();
|
if(rhs == 0) vm->zeroDivisionError();
|
||||||
return vm->PyInt(vm->PyInt_AS_C(args._index(0)) / rhs);
|
return vm->PyInt(vm->PyInt_AS_C(args[0]) / rhs);
|
||||||
});
|
});
|
||||||
|
|
||||||
_vm->bindMethod<1>("int", "__mod__", [](VM* vm, const pkpy::ArgList& args) {
|
_vm->bindMethod<1>("int", "__mod__", [](VM* vm, const pkpy::ArgList& args) {
|
||||||
if(!args[0]->is_type(vm->_tp_int) || !args[1]->is_type(vm->_tp_int))
|
if(!args[0]->is_type(vm->_tp_int) || !args[1]->is_type(vm->_tp_int))
|
||||||
vm->typeError("unsupported operand type(s) for " "%" );
|
vm->typeError("unsupported operand type(s) for " "%" );
|
||||||
i64 rhs = vm->PyInt_AS_C(args._index(1));
|
i64 rhs = vm->PyInt_AS_C(args[1]);
|
||||||
if(rhs == 0) vm->zeroDivisionError();
|
if(rhs == 0) vm->zeroDivisionError();
|
||||||
return vm->PyInt(vm->PyInt_AS_C(args._index(0)) % rhs);
|
return vm->PyInt(vm->PyInt_AS_C(args[0]) % rhs);
|
||||||
});
|
});
|
||||||
|
|
||||||
_vm->bindMethod<0>("int", "__repr__", [](VM* vm, const pkpy::ArgList& args) {
|
_vm->bindMethod<0>("int", "__repr__", [](VM* vm, const pkpy::ArgList& args) {
|
||||||
@ -239,7 +239,7 @@ void __initializeBuiltinFunctions(VM* _vm) {
|
|||||||
|
|
||||||
#define __INT_BITWISE_OP(name,op) \
|
#define __INT_BITWISE_OP(name,op) \
|
||||||
_vm->bindMethod<1>("int", #name, [](VM* vm, const pkpy::ArgList& args) { \
|
_vm->bindMethod<1>("int", #name, [](VM* vm, const pkpy::ArgList& args) { \
|
||||||
return vm->PyInt(vm->PyInt_AS_C(args._index(0)) op vm->PyInt_AS_C(args._index(1))); \
|
return vm->PyInt(vm->PyInt_AS_C(args[0]) op vm->PyInt_AS_C(args[1])); \
|
||||||
});
|
});
|
||||||
|
|
||||||
__INT_BITWISE_OP(__lshift__, <<)
|
__INT_BITWISE_OP(__lshift__, <<)
|
||||||
@ -288,7 +288,7 @@ void __initializeBuiltinFunctions(VM* _vm) {
|
|||||||
|
|
||||||
/************ PyString ************/
|
/************ PyString ************/
|
||||||
_vm->bindStaticMethod<1>("str", "__new__", [](VM* vm, const pkpy::ArgList& args) {
|
_vm->bindStaticMethod<1>("str", "__new__", [](VM* vm, const pkpy::ArgList& args) {
|
||||||
return vm->asStr(args._index(0));
|
return vm->asStr(args[0]);
|
||||||
});
|
});
|
||||||
|
|
||||||
_vm->bindMethod<1>("str", "__add__", [](VM* vm, const pkpy::ArgList& args) {
|
_vm->bindMethod<1>("str", "__add__", [](VM* vm, const pkpy::ArgList& args) {
|
||||||
@ -411,7 +411,7 @@ void __initializeBuiltinFunctions(VM* _vm) {
|
|||||||
|
|
||||||
_vm->bindMethod<1>("list", "append", [](VM* vm, const pkpy::ArgList& args) {
|
_vm->bindMethod<1>("list", "append", [](VM* vm, const pkpy::ArgList& args) {
|
||||||
PyVarList& _self = vm->PyList_AS_C(args[0]);
|
PyVarList& _self = vm->PyList_AS_C(args[0]);
|
||||||
_self.push_back(args._index(1));
|
_self.push_back(args[1]);
|
||||||
return vm->None;
|
return vm->None;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -45,15 +45,6 @@ namespace pkpy {
|
|||||||
PyVar* _args = nullptr;
|
PyVar* _args = nullptr;
|
||||||
uint8_t _size = 0;
|
uint8_t _size = 0;
|
||||||
|
|
||||||
inline void __checkIndex(uint8_t i) const {
|
|
||||||
#ifndef PKPY_NO_INDEX_CHECK
|
|
||||||
if (i >= _size){
|
|
||||||
auto msg = "pkpy:ArgList index out of range, " + std::to_string(i) + " not in [0, " + std::to_string(size()) + ")";
|
|
||||||
throw std::out_of_range(msg);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void __tryAlloc(size_t n){
|
void __tryAlloc(size_t n){
|
||||||
if(n > 255) UNREACHABLE();
|
if(n > 255) UNREACHABLE();
|
||||||
if(n >= MAX_POOLING_N || _poolArgList[n].empty()){
|
if(n >= MAX_POOLING_N || _poolArgList[n].empty()){
|
||||||
@ -103,23 +94,8 @@ namespace pkpy {
|
|||||||
other.clear();
|
other.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
PyVar& operator[](uint8_t i){
|
PyVar& operator[](uint8_t i){ return _args[i]; }
|
||||||
__checkIndex(i);
|
const PyVar& operator[](uint8_t i) const { return _args[i]; }
|
||||||
return _args[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
const PyVar& operator[](uint8_t i) const {
|
|
||||||
__checkIndex(i);
|
|
||||||
return _args[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
inline PyVar& _index(uint8_t i){
|
|
||||||
return _args[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
inline const PyVar& _index(uint8_t i) const {
|
|
||||||
return _args[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
// overload = for &&
|
// overload = for &&
|
||||||
ArgList& operator=(ArgList&& other) noexcept {
|
ArgList& operator=(ArgList&& other) noexcept {
|
||||||
@ -164,29 +140,18 @@ namespace pkpy {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArgList oneArg(PyVar&& a) {
|
template<typename T>
|
||||||
|
ArgList oneArg(T&& a) {
|
||||||
ArgList ret(1);
|
ArgList ret(1);
|
||||||
ret[0] = std::move(a);
|
ret[0] = std::forward<T>(a);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArgList oneArg(const PyVar& a) {
|
template<typename T1, typename T2>
|
||||||
ArgList ret(1);
|
ArgList twoArgs(T1&& a, T2&& b) {
|
||||||
ret[0] = a;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
ArgList twoArgs(PyVar&& a, PyVar&& b) {
|
|
||||||
ArgList ret(2);
|
ArgList ret(2);
|
||||||
ret[0] = std::move(a);
|
ret[0] = std::forward<T1>(a);
|
||||||
ret[1] = std::move(b);
|
ret[1] = std::forward<T2>(b);
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
ArgList twoArgs(const PyVar& a, const PyVar& b) {
|
|
||||||
ArgList ret(2);
|
|
||||||
ret[0] = a;
|
|
||||||
ret[1] = b;
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
8
src/vm.h
8
src/vm.h
@ -135,8 +135,8 @@ protected:
|
|||||||
case OP_BINARY_OP:
|
case OP_BINARY_OP:
|
||||||
{
|
{
|
||||||
pkpy::ArgList args(2);
|
pkpy::ArgList args(2);
|
||||||
args._index(1) = frame->pop_value(this);
|
args[1] = frame->pop_value(this);
|
||||||
args._index(0) = frame->top_value(this);
|
args[0] = frame->top_value(this);
|
||||||
frame->top() = fast_call(BINARY_SPECIAL_METHODS[byte.arg], std::move(args));
|
frame->top() = fast_call(BINARY_SPECIAL_METHODS[byte.arg], std::move(args));
|
||||||
} break;
|
} break;
|
||||||
case OP_BITWISE_OP:
|
case OP_BITWISE_OP:
|
||||||
@ -522,7 +522,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
// repl mode is only for setting `frame->id` to 0
|
// repl mode is only for setting `frame->id` to 0
|
||||||
virtual PyVarOrNull exec(_Str source, _Str filename, CompileMode mode, PyVar _module=nullptr){
|
PyVarOrNull exec(_Str source, _Str filename, CompileMode mode, PyVar _module=nullptr){
|
||||||
if(_module == nullptr) _module = _main;
|
if(_module == nullptr) _module = _main;
|
||||||
try {
|
try {
|
||||||
_Code code = compile(source, filename, mode);
|
_Code code = compile(source, filename, mode);
|
||||||
@ -935,7 +935,7 @@ public:
|
|||||||
if(!obj->is_type(type)) typeError("expected '" + UNION_NAME(type) + "', but got '" + UNION_TP_NAME(obj) + "'");
|
if(!obj->is_type(type)) typeError("expected '" + UNION_NAME(type) + "', but got '" + UNION_TP_NAME(obj) + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~VM() {
|
~VM() {
|
||||||
if(!use_stdio){
|
if(!use_stdio){
|
||||||
delete _stdout;
|
delete _stdout;
|
||||||
delete _stderr;
|
delete _stderr;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user