mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 19:40:18 +00:00
fix macrobind
This commit is contained in:
parent
3688f69123
commit
03e368b755
@ -130,9 +130,9 @@ PK_API void py_watchdog_begin(py_i64 timeout);
|
|||||||
PK_API void py_watchdog_end();
|
PK_API void py_watchdog_end();
|
||||||
|
|
||||||
/// Bind a compile-time function via "decl-based" style.
|
/// Bind a compile-time function via "decl-based" style.
|
||||||
PK_API void py_compiletime_bind(const char* sig, py_CFunction f);
|
PK_API void py_macrobind(const char* sig, py_CFunction f);
|
||||||
/// Find a compile-time function by name.
|
/// Get a compile-time function by name.
|
||||||
PK_API py_ItemRef py_compiletime_getfunc(py_Name name);
|
PK_API py_ItemRef py_macroget(py_Name name);
|
||||||
|
|
||||||
/// Get the current source location of the frame.
|
/// Get the current source location of the frame.
|
||||||
PK_API const char* py_Frame_sourceloc(py_Frame* frame, int* lineno);
|
PK_API const char* py_Frame_sourceloc(py_Frame* frame, int* lineno);
|
||||||
|
@ -1935,14 +1935,12 @@ static Error* exprCall(Compiler* self) {
|
|||||||
int line = prev()->line;
|
int line = prev()->line;
|
||||||
if(callable->vt->is_name) {
|
if(callable->vt->is_name) {
|
||||||
NameExpr* ne = (NameExpr*)callable;
|
NameExpr* ne = (NameExpr*)callable;
|
||||||
if(ne->scope == NAME_GLOBAL) {
|
py_ItemRef func = py_macroget(ne->name);
|
||||||
py_ItemRef func = py_compiletime_getfunc(ne->name);
|
if(func != NULL) {
|
||||||
if(func != NULL) {
|
py_StackRef p0 = py_peek(0);
|
||||||
py_StackRef p0 = py_peek(0);
|
err = exprCompileTimeCall(self, func, line);
|
||||||
err = exprCompileTimeCall(self, func, line);
|
if(err != NULL) py_clearexc(p0);
|
||||||
if(err != NULL) py_clearexc(p0);
|
return err;
|
||||||
return err;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,14 +95,14 @@ void py_bind(py_Ref obj, const char* sig, py_CFunction f) {
|
|||||||
py_pop();
|
py_pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void py_compiletime_bind(const char* sig, py_CFunction f) {
|
void py_macrobind(const char* sig, py_CFunction f) {
|
||||||
py_Ref tmp = py_pushtmp();
|
py_Ref tmp = py_pushtmp();
|
||||||
py_Name name = py_newfunction(tmp, sig, f, NULL, 0);
|
py_Name name = py_newfunction(tmp, sig, f, NULL, 0);
|
||||||
NameDict__set(&pk_current_vm->compile_time_funcs, name, tmp);
|
NameDict__set(&pk_current_vm->compile_time_funcs, name, tmp);
|
||||||
py_pop();
|
py_pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
PK_API py_ItemRef py_compiletime_getfunc(py_Name name) {
|
py_ItemRef py_macroget(py_Name name) {
|
||||||
NameDict* d = &pk_current_vm->compile_time_funcs;
|
NameDict* d = &pk_current_vm->compile_time_funcs;
|
||||||
if(d->length == 0) return NULL;
|
if(d->length == 0) return NULL;
|
||||||
return NameDict__try_get(d, name);
|
return NameDict__try_get(d, name);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user