blueloveTH 8 месяцев назад
Родитель
Сommit
03e368b755
3 измененных файлов с 11 добавлено и 13 удалено
  1. 3 3
      include/pocketpy/pocketpy.h
  2. 6 8
      src/compiler/compiler.c
  3. 2 2
      src/public/values.c

+ 3 - 3
include/pocketpy/pocketpy.h

@@ -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);

+ 6 - 8
src/compiler/compiler.c

@@ -1935,14 +1935,12 @@ 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);
-            if(func != NULL) {
-                py_StackRef p0 = py_peek(0);
-                err = exprCompileTimeCall(self, func, line);
-                if(err != NULL) py_clearexc(p0);
-                return err;
-            }
+        py_ItemRef func = py_macroget(ne->name);
+        if(func != NULL) {
+            py_StackRef p0 = py_peek(0);
+            err = exprCompileTimeCall(self, func, line);
+            if(err != NULL) py_clearexc(p0);
+            return err;
         }
     }
 

+ 2 - 2
src/public/values.c

@@ -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);