mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-21 20:10:17 +00:00
...
This commit is contained in:
parent
b6993532fa
commit
8264f125d6
@ -65,6 +65,9 @@ bool pk__normalize_index(int* index, int length);
|
|||||||
void pk_list__mark(void* ud, void (*marker)(py_TValue*));
|
void pk_list__mark(void* ud, void (*marker)(py_TValue*));
|
||||||
void pk_dict__mark(void* ud, void (*marker)(py_TValue*));
|
void pk_dict__mark(void* ud, void (*marker)(py_TValue*));
|
||||||
|
|
||||||
|
bool pk_wrapper__self(int argc, py_Ref argv);
|
||||||
|
bool pk_wrapper__NotImplementedError(int argc, py_Ref argv);
|
||||||
|
|
||||||
typedef enum FrameResult {
|
typedef enum FrameResult {
|
||||||
RES_RETURN,
|
RES_RETURN,
|
||||||
RES_CALL,
|
RES_CALL,
|
||||||
@ -122,5 +125,6 @@ py_Type pk_super__register();
|
|||||||
py_Type pk_property__register();
|
py_Type pk_property__register();
|
||||||
py_Type pk_staticmethod__register();
|
py_Type pk_staticmethod__register();
|
||||||
py_Type pk_classmethod__register();
|
py_Type pk_classmethod__register();
|
||||||
|
py_Type pk_generator__register();
|
||||||
|
|
||||||
py_TValue pk_builtins__register();
|
py_TValue pk_builtins__register();
|
||||||
|
@ -386,7 +386,6 @@ void py_clearexc(py_StackRef p0);
|
|||||||
#define IndexError(...) py_exception(tp_IndexError, __VA_ARGS__)
|
#define IndexError(...) py_exception(tp_IndexError, __VA_ARGS__)
|
||||||
#define ImportError(...) py_exception(tp_ImportError, __VA_ARGS__)
|
#define ImportError(...) py_exception(tp_ImportError, __VA_ARGS__)
|
||||||
#define ZeroDivisionError(...) py_exception(tp_ZeroDivisionError, __VA_ARGS__)
|
#define ZeroDivisionError(...) py_exception(tp_ZeroDivisionError, __VA_ARGS__)
|
||||||
#define NotImplementedError() py_exception(tp_NotImplementedError, "")
|
|
||||||
#define AttributeError(self, n) \
|
#define AttributeError(self, n) \
|
||||||
py_exception(tp_AttributeError, "'%t' object has no attribute '%n'", (self)->type, (n))
|
py_exception(tp_AttributeError, "'%t' object has no attribute '%n'", (self)->type, (n))
|
||||||
#define UnboundLocalError(n) \
|
#define UnboundLocalError(n) \
|
||||||
|
@ -1,8 +1,22 @@
|
|||||||
#include "pocketpy/interpreter/generator.h"
|
#include "pocketpy/interpreter/generator.h"
|
||||||
#include "pocketpy/interpreter/frame.h"
|
#include "pocketpy/interpreter/frame.h"
|
||||||
|
#include "pocketpy/interpreter/vm.h"
|
||||||
|
#include "pocketpy/pocketpy.h"
|
||||||
|
|
||||||
void pk_newgenerator(py_Ref out, Frame* frame, int slots) {
|
void pk_newgenerator(py_Ref out, Frame* frame, int slots) {
|
||||||
Generator* ud = py_newobject(out, tp_generator, slots, sizeof(Generator));
|
Generator* ud = py_newobject(out, tp_generator, slots, sizeof(Generator));
|
||||||
ud->frame = frame;
|
ud->frame = frame;
|
||||||
ud->state = 0;
|
ud->state = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool generator__next__(int argc, py_Ref argv){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
py_Type pk_generator__register() {
|
||||||
|
py_Type type = pk_newtype("generator", tp_object, NULL, NULL, false, true);
|
||||||
|
|
||||||
|
py_bindmagic(type, __iter__, pk_wrapper__self);
|
||||||
|
py_bindmagic(type, __next__, generator__next__);
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
@ -127,7 +127,7 @@ void VM__ctor(VM* self) {
|
|||||||
validate(tp_NotImplementedType,
|
validate(tp_NotImplementedType,
|
||||||
pk_newtype("NotImplementedType", tp_object, NULL, NULL, false, true));
|
pk_newtype("NotImplementedType", tp_object, NULL, NULL, false, true));
|
||||||
validate(tp_ellipsis, pk_newtype("ellipsis", tp_object, NULL, NULL, false, true));
|
validate(tp_ellipsis, pk_newtype("ellipsis", tp_object, NULL, NULL, false, true));
|
||||||
validate(tp_generator, pk_newtype("generator", tp_object, NULL, NULL, false, true));
|
validate(tp_generator, pk_generator__register());
|
||||||
|
|
||||||
self->builtins = pk_builtins__register();
|
self->builtins = pk_builtins__register();
|
||||||
|
|
||||||
@ -647,4 +647,14 @@ void pk_print_stack(VM* self, Frame* frame, Bytecode byte) {
|
|||||||
byte.arg,
|
byte.arg,
|
||||||
stack_str->data);
|
stack_str->data);
|
||||||
c11_string__delete(stack_str);
|
c11_string__delete(stack_str);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pk_wrapper__self(int argc, py_Ref argv) {
|
||||||
|
PY_CHECK_ARGC(1);
|
||||||
|
py_assign(py_retval(), argv);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pk_wrapper__NotImplementedError(int argc, py_Ref argv){
|
||||||
|
return py_exception(tp_NotImplementedError, "");
|
||||||
}
|
}
|
@ -252,11 +252,6 @@ static bool builtins_print(int argc, py_Ref argv) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool NoneType__repr__(int argc, py_Ref argv) {
|
|
||||||
py_newstr(py_retval(), "None");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool builtins_exec(int argc, py_Ref argv) {
|
static bool builtins_exec(int argc, py_Ref argv) {
|
||||||
PY_CHECK_ARGC(1);
|
PY_CHECK_ARGC(1);
|
||||||
PY_CHECK_ARG_TYPE(0, tp_str);
|
PY_CHECK_ARG_TYPE(0, tp_str);
|
||||||
@ -372,6 +367,21 @@ static bool builtins_ord(int argc, py_Ref argv) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool NoneType__repr__(int argc, py_Ref argv) {
|
||||||
|
py_newstr(py_retval(), "None");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool ellipsis__repr__(int argc, py_Ref argv) {
|
||||||
|
py_newstr(py_retval(), "Ellipsis");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool NotImplementedType__repr__(int argc, py_Ref argv) {
|
||||||
|
py_newstr(py_retval(), "NotImplemented");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
py_TValue pk_builtins__register() {
|
py_TValue pk_builtins__register() {
|
||||||
py_Ref builtins = py_newmodule("builtins");
|
py_Ref builtins = py_newmodule("builtins");
|
||||||
py_bindfunc(builtins, "repr", builtins_repr);
|
py_bindfunc(builtins, "repr", builtins_repr);
|
||||||
@ -400,8 +410,10 @@ py_TValue pk_builtins__register() {
|
|||||||
py_bindfunc(builtins, "chr", builtins_chr);
|
py_bindfunc(builtins, "chr", builtins_chr);
|
||||||
py_bindfunc(builtins, "ord", builtins_ord);
|
py_bindfunc(builtins, "ord", builtins_ord);
|
||||||
|
|
||||||
// None __repr__
|
// some patches
|
||||||
py_bindmagic(tp_NoneType, __repr__, NoneType__repr__);
|
py_bindmagic(tp_NoneType, __repr__, NoneType__repr__);
|
||||||
|
py_bindmagic(tp_ellipsis, __repr__, ellipsis__repr__);
|
||||||
|
py_bindmagic(tp_NotImplementedType, __repr__, NotImplementedType__repr__);
|
||||||
return *builtins;
|
return *builtins;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -457,12 +457,6 @@ py_Type pk_dict__register() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////
|
//////////////////////////
|
||||||
static bool dict_items__iter__(int argc, py_Ref argv) {
|
|
||||||
PY_CHECK_ARGC(1);
|
|
||||||
*py_retval() = *argv;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool dict_items__next__(int argc, py_Ref argv) {
|
static bool dict_items__next__(int argc, py_Ref argv) {
|
||||||
PY_CHECK_ARGC(1);
|
PY_CHECK_ARGC(1);
|
||||||
DictIterator* iter = py_touserdata(py_arg(0));
|
DictIterator* iter = py_touserdata(py_arg(0));
|
||||||
@ -478,7 +472,7 @@ static bool dict_items__next__(int argc, py_Ref argv) {
|
|||||||
|
|
||||||
py_Type pk_dict_items__register() {
|
py_Type pk_dict_items__register() {
|
||||||
py_Type type = pk_newtype("dict_items", tp_object, NULL, NULL, false, true);
|
py_Type type = pk_newtype("dict_items", tp_object, NULL, NULL, false, true);
|
||||||
py_bindmagic(type, __iter__, dict_items__iter__);
|
py_bindmagic(type, __iter__, pk_wrapper__self);
|
||||||
py_bindmagic(type, __next__, dict_items__next__);
|
py_bindmagic(type, __next__, dict_items__next__);
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
@ -36,10 +36,6 @@ py_Type pk_classmethod__register(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* boundmethod */
|
/* boundmethod */
|
||||||
static bool boundmethod__new__(int argc, py_Ref argv) {
|
|
||||||
return NotImplementedError();
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool boundmethod__self__getter(int argc, py_Ref argv) {
|
static bool boundmethod__self__getter(int argc, py_Ref argv) {
|
||||||
PY_CHECK_ARGC(1);
|
PY_CHECK_ARGC(1);
|
||||||
py_assign(py_retval(), py_getslot(argv, 0));
|
py_assign(py_retval(), py_getslot(argv, 0));
|
||||||
@ -55,7 +51,6 @@ static bool boundmethod__func__getter(int argc, py_Ref argv) {
|
|||||||
py_Type pk_boundmethod__register(){
|
py_Type pk_boundmethod__register(){
|
||||||
py_Type type = pk_newtype("boundmethod", tp_object, NULL, NULL, false, true);
|
py_Type type = pk_newtype("boundmethod", tp_object, NULL, NULL, false, true);
|
||||||
|
|
||||||
py_bindmagic(type, __new__, boundmethod__new__);
|
|
||||||
py_bindproperty(type, "__self__", boundmethod__self__getter, NULL);
|
py_bindproperty(type, "__self__", boundmethod__self__getter, NULL);
|
||||||
py_bindproperty(type, "__func__", boundmethod__func__getter, NULL);
|
py_bindproperty(type, "__func__", boundmethod__func__getter, NULL);
|
||||||
return type;
|
return type;
|
||||||
|
@ -68,12 +68,6 @@ static bool range_iterator__new__(int argc, py_Ref argv) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool range_iterator__iter__(int argc, py_Ref argv) {
|
|
||||||
PY_CHECK_ARGC(1);
|
|
||||||
*py_retval() = *py_arg(0);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool range_iterator__next__(int argc, py_Ref argv) {
|
static bool range_iterator__next__(int argc, py_Ref argv) {
|
||||||
PY_CHECK_ARGC(1);
|
PY_CHECK_ARGC(1);
|
||||||
RangeIterator* ud = py_touserdata(py_arg(0));
|
RangeIterator* ud = py_touserdata(py_arg(0));
|
||||||
@ -91,7 +85,7 @@ py_Type pk_range_iterator__register() {
|
|||||||
py_Type type = pk_newtype("range_iterator", tp_object, NULL, NULL, false, true);
|
py_Type type = pk_newtype("range_iterator", tp_object, NULL, NULL, false, true);
|
||||||
|
|
||||||
py_bindmagic(type, __new__, range_iterator__new__);
|
py_bindmagic(type, __new__, range_iterator__new__);
|
||||||
py_bindmagic(type, __iter__, range_iterator__iter__);
|
py_bindmagic(type, __iter__, pk_wrapper__self);
|
||||||
py_bindmagic(type, __next__, range_iterator__next__);
|
py_bindmagic(type, __next__, range_iterator__next__);
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
@ -495,12 +495,6 @@ py_Type pk_str__register() {
|
|||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool str_iterator__iter__(int argc, py_Ref argv) {
|
|
||||||
PY_CHECK_ARGC(1);
|
|
||||||
*py_retval() = argv[0];
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool str_iterator__next__(int argc, py_Ref argv) {
|
static bool str_iterator__next__(int argc, py_Ref argv) {
|
||||||
PY_CHECK_ARGC(1);
|
PY_CHECK_ARGC(1);
|
||||||
int* ud = py_touserdata(&argv[0]);
|
int* ud = py_touserdata(&argv[0]);
|
||||||
@ -517,7 +511,7 @@ static bool str_iterator__next__(int argc, py_Ref argv) {
|
|||||||
py_Type pk_str_iterator__register() {
|
py_Type pk_str_iterator__register() {
|
||||||
py_Type type = pk_newtype("str_iterator", tp_object, NULL, NULL, false, true);
|
py_Type type = pk_newtype("str_iterator", tp_object, NULL, NULL, false, true);
|
||||||
|
|
||||||
py_bindmagic(type, __iter__, str_iterator__iter__);
|
py_bindmagic(type, __iter__, pk_wrapper__self);
|
||||||
py_bindmagic(type, __next__, str_iterator__next__);
|
py_bindmagic(type, __next__, str_iterator__next__);
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user