fix abs name

This commit is contained in:
blueloveTH 2026-01-06 14:32:00 +08:00
parent 45f18f8431
commit 82bd2838ce
4 changed files with 15 additions and 2 deletions

View File

@ -16,6 +16,7 @@ OPCODE(LOAD_TRUE)
OPCODE(LOAD_FALSE)
/**************************/
OPCODE(LOAD_SMALL_INT)
OPCODE(LOAD_NAME_AS_INT)
/**************************/
OPCODE(LOAD_ELLIPSIS)
OPCODE(LOAD_FUNCTION)

View File

@ -77,6 +77,7 @@ static int Ctx__enter_block(Ctx* self, CodeBlockType type);
static void Ctx__exit_block(Ctx* self);
static int Ctx__emit_(Ctx* self, Opcode opcode, uint16_t arg, int line);
static int Ctx__emit_int(Ctx* self, int64_t value, int line);
static int Ctx__emit_name(Ctx* self, py_Name name, int line);
static void Ctx__patch_jump(Ctx* self, int index);
static void Ctx__emit_jump(Ctx* self, int target, int line);
static int Ctx__add_varname(Ctx* self, py_Name name);
@ -1070,7 +1071,7 @@ void CallExpr__emit_(Expr* self_, Ctx* ctx) {
c11__foreach(Expr*, &self->args, e) { vtemit_(*e, ctx); }
c11__foreach(CallExprKwArg, &self->kwargs, e) {
Ctx__emit_int(ctx, (uintptr_t)e->key, self->line);
Ctx__emit_name(ctx, e->key, self->line);
vtemit_(e->val, ctx);
}
int KWARGC = self->kwargs.length;
@ -1196,6 +1197,12 @@ static int Ctx__emit_int(Ctx* self, int64_t value, int line) {
}
}
static int Ctx__emit_name(Ctx* self, py_Name name, int line) {
int index = Ctx__add_name(self, name);
assert(index <= UINT16_MAX);
return Ctx__emit_(self, OP_LOAD_NAME_AS_INT, (uint16_t)index, line);
}
static void Ctx__patch_jump(Ctx* self, int index) {
Bytecode* co_codes = (Bytecode*)self->co->codes.data;
int target = self->co->codes.length;

View File

@ -189,6 +189,11 @@ __NEXT_STEP:
py_newint(SP()++, (int16_t)byte.arg);
DISPATCH();
}
case OP_LOAD_NAME_AS_INT: {
py_Name name = co_names[byte.arg];
py_newint(SP()++, (uintptr_t)name);
DISPATCH();
}
/*****************************************/
case OP_LOAD_ELLIPSIS: {
py_newellipsis(SP()++);

View File

@ -72,7 +72,7 @@ static bool disassemble(CodeObject* co) {
pk_sprintf(&ss, " (%q)", py_tosv(path));
break;
}
case OP_LOAD_NAME:
case OP_LOAD_NAME: case OP_LOAD_NAME_AS_INT:
case OP_LOAD_GLOBAL:
case OP_LOAD_NONLOCAL:
case OP_STORE_GLOBAL: