mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
...
This commit is contained in:
parent
dd2637fabc
commit
13debcd722
13
build.py
13
build.py
@ -12,12 +12,13 @@ linux_common = "-Wfatal-errors --std=c++17 -O2 -Wall -Wno-sign-compare -Wno-unus
|
||||
linux_cmd = "clang++ -o pocketpy src/main.cpp " + linux_common
|
||||
linux_lib_cmd = "clang++ -fPIC -shared -o pocketpy.so src/tmp.cpp " + linux_common
|
||||
|
||||
|
||||
def lib_pre_build():
|
||||
class LibBuildEnv:
|
||||
def __enter__(self):
|
||||
with open("src/tmp.cpp", "w", encoding='utf-8') as f:
|
||||
f.write('#include "pocketpy.h"')
|
||||
|
||||
def lib_post_build():
|
||||
def __exit__(self, *args):
|
||||
if os.path.exists("src/tmp.cpp"):
|
||||
os.remove("src/tmp.cpp")
|
||||
|
||||
windows_common = "CL -std:c++17 /utf-8 -GR- -EHsc -O2"
|
||||
@ -30,18 +31,16 @@ if sys.argv.__len__() == 1:
|
||||
|
||||
if "windows" in sys.argv:
|
||||
if "-lib" in sys.argv:
|
||||
lib_pre_build()
|
||||
with LibBuildEnv():
|
||||
os.system(windows_lib_cmd)
|
||||
lib_post_build()
|
||||
else:
|
||||
os.system(windows_cmd)
|
||||
DONE()
|
||||
|
||||
if "linux" in sys.argv:
|
||||
if "-lib" in sys.argv:
|
||||
lib_pre_build()
|
||||
with LibBuildEnv():
|
||||
os.system(linux_lib_cmd)
|
||||
lib_post_build()
|
||||
else:
|
||||
os.system(linux_cmd)
|
||||
DONE()
|
||||
|
@ -8,3 +8,5 @@ These are the undefined behaviours of pkpy. The behaviour of pkpy is undefined i
|
||||
1. Delete a builtin object. For example, `del int.__add__`.
|
||||
2. Call an unbound method with the wrong type of `self`. For example, `int.__add__('1', 2)`.
|
||||
3. Use goto statement to jump out of a context block.
|
||||
4. Type `T`'s `__new__` returns an object that is not an instance of `T`.
|
||||
5. Call `__new__` with a type that is not a subclass of `type`.
|
@ -9,7 +9,7 @@ In `VM` class, there are 4 methods to bind native function.
|
||||
+ `VM::bind_func<ARGC>`
|
||||
+ `VM::bind_builtin_func<ARGC>`
|
||||
+ `VM::bind_method<ARGC>`
|
||||
+ `VM::bind_static_method<ARGC>`
|
||||
+ `VM::bind_constructor<ARGC>`
|
||||
|
||||
They are all template methods, the template argument is a `int` number, indicating the argument count. For variadic arguments, use `-1`. For methods, `ARGC` do not include `self`.
|
||||
|
||||
|
@ -25,9 +25,9 @@ struct Vector2 {
|
||||
Vector2(float x, float y) : x(x), y(y) {}
|
||||
|
||||
static void _register(VM* vm, PyObject* mod, PyObject* type){
|
||||
vm->bind_static_method<2>(type, "__new__", [](VM* vm, ArgsView args){
|
||||
float x = vm->num_to_float(args[0]);
|
||||
float y = vm->num_to_float(args[1]);
|
||||
vm->bind_constructor<3>(type, [](VM* vm, ArgsView args){
|
||||
float x = vm->num_to_float(args[1]);
|
||||
float y = vm->num_to_float(args[2]);
|
||||
return VAR_T(Vector2, x, y);
|
||||
});
|
||||
|
||||
|
@ -108,8 +108,6 @@ def str@strip(self, chars=None):
|
||||
return self[i:j+1]
|
||||
|
||||
##### list #####
|
||||
|
||||
list.__new__ = lambda iterable: [x for x in iterable]
|
||||
list.__repr__ = lambda self: '[' + ', '.join([repr(i) for i in self]) + ']'
|
||||
tuple.__repr__ = lambda self: '(' + ', '.join([repr(i) for i in self]) + ')'
|
||||
list.__json__ = lambda self: '[' + ', '.join([i.__json__() for i in self]) + ']'
|
||||
|
Loading…
x
Reference in New Issue
Block a user