mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30: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();
|
||||
|
||||
/// Bind a compile-time function via "decl-based" style.
|
||||
PK_API void py_compiletime_bind(const char* sig, py_CFunction f);
|
||||
/// Find a compile-time function by name.
|
||||
PK_API py_ItemRef py_compiletime_getfunc(py_Name name);
|
||||
PK_API void py_macrobind(const char* sig, py_CFunction f);
|
||||
/// Get a compile-time function by name.
|
||||
PK_API py_ItemRef py_macroget(py_Name name);
|
||||
|
||||
/// Get the current source location of the frame.
|
||||
PK_API const char* py_Frame_sourceloc(py_Frame* frame, int* lineno);
|
||||
|
@ -1935,8 +1935,7 @@ static Error* exprCall(Compiler* self) {
|
||||
int line = prev()->line;
|
||||
if(callable->vt->is_name) {
|
||||
NameExpr* ne = (NameExpr*)callable;
|
||||
if(ne->scope == NAME_GLOBAL) {
|
||||
py_ItemRef func = py_compiletime_getfunc(ne->name);
|
||||
py_ItemRef func = py_macroget(ne->name);
|
||||
if(func != NULL) {
|
||||
py_StackRef p0 = py_peek(0);
|
||||
err = exprCompileTimeCall(self, func, line);
|
||||
@ -1944,7 +1943,6 @@ static Error* exprCall(Compiler* self) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CallExpr* e = CallExpr__new(line, callable);
|
||||
Ctx__s_push(ctx(), (Expr*)e); // push onto the stack in advance
|
||||
|
@ -95,14 +95,14 @@ void py_bind(py_Ref obj, const char* sig, py_CFunction f) {
|
||||
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_Name name = py_newfunction(tmp, sig, f, NULL, 0);
|
||||
NameDict__set(&pk_current_vm->compile_time_funcs, name, tmp);
|
||||
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;
|
||||
if(d->length == 0) return NULL;
|
||||
return NameDict__try_get(d, name);
|
||||
|
Loading…
x
Reference in New Issue
Block a user