mirror of
https://github.com/pocketpy/pocketpy
synced 2025-11-08 12:40:17 +00:00
fix #401
This commit is contained in:
parent
10ce995780
commit
96505249d6
@ -55,4 +55,8 @@ Mark a function that can raise an exception on failure.
|
|||||||
|
|
||||||
### `PY_RETURN` macro
|
### `PY_RETURN` macro
|
||||||
|
|
||||||
Mark a function that can store a value in `py_retval()` on success.
|
Mark a function that can store a value in `py_retval()` on success.
|
||||||
|
|
||||||
|
### `PY_MAYBENULL` macro
|
||||||
|
|
||||||
|
Mark a variable or callback function that may be `NULL`.
|
||||||
|
|||||||
@ -49,6 +49,7 @@ typedef struct c11_sv {
|
|||||||
|
|
||||||
#define PY_RAISE
|
#define PY_RAISE
|
||||||
#define PY_RETURN
|
#define PY_RETURN
|
||||||
|
#define PY_MAYBENULL
|
||||||
|
|
||||||
/// A generic reference to a python object.
|
/// A generic reference to a python object.
|
||||||
typedef py_TValue* py_Ref;
|
typedef py_TValue* py_Ref;
|
||||||
@ -79,7 +80,7 @@ typedef struct py_Callbacks {
|
|||||||
/// Used by `__import__` to load a source module.
|
/// Used by `__import__` to load a source module.
|
||||||
char* (*importfile)(const char*);
|
char* (*importfile)(const char*);
|
||||||
/// Called before `importfile` to lazy-import a C module.
|
/// Called before `importfile` to lazy-import a C module.
|
||||||
py_GlobalRef (*lazyimport)(const char*);
|
PY_MAYBENULL py_GlobalRef (*lazyimport)(const char*);
|
||||||
/// Used by `print` to output a string.
|
/// Used by `print` to output a string.
|
||||||
void (*print)(const char*);
|
void (*print)(const char*);
|
||||||
/// Flush the output buffer of `print`.
|
/// Flush the output buffer of `print`.
|
||||||
@ -87,7 +88,9 @@ typedef struct py_Callbacks {
|
|||||||
/// Used by `input` to get a character.
|
/// Used by `input` to get a character.
|
||||||
int (*getchr)();
|
int (*getchr)();
|
||||||
/// Used by `gc.collect()` to mark extra objects for garbage collection.
|
/// Used by `gc.collect()` to mark extra objects for garbage collection.
|
||||||
void (*gc_mark)(void (*f)(py_Ref val, void* ctx), void* ctx);
|
PY_MAYBENULL void (*gc_mark)(void (*f)(py_Ref val, void* ctx), void* ctx);
|
||||||
|
/// Used by `PRINT_EXPR` bytecode.
|
||||||
|
PY_MAYBENULL bool (*displayhook)(py_Ref val) PY_RAISE;
|
||||||
} py_Callbacks;
|
} py_Callbacks;
|
||||||
|
|
||||||
/// A struct contains the application-level callbacks.
|
/// A struct contains the application-level callbacks.
|
||||||
|
|||||||
@ -152,15 +152,21 @@ __NEXT_STEP:
|
|||||||
*THIRD() = tmp;
|
*THIRD() = tmp;
|
||||||
DISPATCH();
|
DISPATCH();
|
||||||
}
|
}
|
||||||
case OP_PRINT_EXPR:
|
case OP_PRINT_EXPR: {
|
||||||
if(TOP()->type != tp_NoneType) {
|
if(self->callbacks.displayhook) {
|
||||||
bool ok = py_repr(TOP());
|
bool ok = self->callbacks.displayhook(TOP());
|
||||||
if(!ok) goto __ERROR;
|
if(!ok) goto __ERROR;
|
||||||
self->callbacks.print(py_tostr(&self->last_retval));
|
} else {
|
||||||
self->callbacks.print("\n");
|
if(TOP()->type != tp_NoneType) {
|
||||||
|
bool ok = py_repr(TOP());
|
||||||
|
if(!ok) goto __ERROR;
|
||||||
|
self->callbacks.print(py_tostr(&self->last_retval));
|
||||||
|
self->callbacks.print("\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
POP();
|
POP();
|
||||||
DISPATCH();
|
DISPATCH();
|
||||||
|
}
|
||||||
/*****************************************/
|
/*****************************************/
|
||||||
case OP_LOAD_CONST: {
|
case OP_LOAD_CONST: {
|
||||||
PUSH(c11__at(py_TValue, &frame->co->consts, byte.arg));
|
PUSH(c11__at(py_TValue, &frame->co->consts, byte.arg));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user