use enum for magic names

This commit is contained in:
blueloveTH 2024-07-02 17:52:09 +08:00
parent cf82c409df
commit 2d9a06a3fc
3 changed files with 9 additions and 9 deletions

View File

@ -326,9 +326,13 @@ bool py_checktype(const py_Ref self, py_Type type);
/// %t: py_Type /// %t: py_Type
/// %n: py_Name /// %n: py_Name
#define MAGIC_METHOD(x) extern uint16_t x;
#include "pocketpy/xmacros/magics.h" enum py_MagicMethods{
#undef MAGIC_METHOD py_MagicMethods__NULL, // 0 is reserved
#define MAGIC_METHOD(x) x,
#include "pocketpy/xmacros/magics.h"
#undef MAGIC_METHOD
};
enum py_PredefinedTypes{ enum py_PredefinedTypes{
tp_object = 1, tp_type, tp_object = 1, tp_type,

View File

@ -20,7 +20,7 @@ void pk_StrName__initialize() {
c11_vector__ctor(&_r_interned, sizeof(c11_sv)); c11_vector__ctor(&_r_interned, sizeof(c11_sv));
_initialized = true; _initialized = true;
#define MAGIC_METHOD(x) x = pk_StrName__map(#x); #define MAGIC_METHOD(x) assert(x == py_name(#x));
#include "pocketpy/xmacros/magics.h" #include "pocketpy/xmacros/magics.h"
#undef MAGIC_METHOD #undef MAGIC_METHOD
@ -94,10 +94,6 @@ bool py_ismagicname(py_Name name){
} }
/////////////////////////////////// ///////////////////////////////////
#define MAGIC_METHOD(x) uint16_t x;
#include "pocketpy/xmacros/magics.h"
#undef MAGIC_METHOD
uint16_t pk_id_add; uint16_t pk_id_add;
uint16_t pk_id_set; uint16_t pk_id_set;
uint16_t pk_id_long; uint16_t pk_id_long;

View File

@ -849,7 +849,7 @@ static void BinaryExpr__dtor(Expr* self_) {
vtdelete(self->rhs); vtdelete(self->rhs);
} }
static Opcode cmp_token2name(TokenIndex token) { static py_Name cmp_token2name(TokenIndex token) {
switch(token) { switch(token) {
case TK_LT: return __lt__; case TK_LT: return __lt__;
case TK_LE: return __le__; case TK_LE: return __le__;