Update ceval.c

This commit is contained in:
blueloveTH 2025-09-17 02:00:55 +08:00
parent 985bc29998
commit 6f7df0c3af

View File

@ -11,7 +11,7 @@
#include <assert.h>
#include <time.h>
static bool stack_format_object(VM* self, c11_sv spec);
static bool format_object(VM* self, py_Ref val, c11_sv spec);
#define DISPATCH() \
do { \
@ -1191,7 +1191,7 @@ __NEXT_STEP:
//////////////////
case OP_FORMAT_STRING: {
py_Ref spec = c11__at(py_TValue, &frame->co->consts, byte.arg);
bool ok = stack_format_object(self, py_tosv(spec));
bool ok = format_object(self, TOP(), py_tosv(spec));
if(!ok) goto __ERROR;
DISPATCH();
}
@ -1298,10 +1298,9 @@ bool pk_stack_binaryop(VM* self, py_Name op, py_Name rop) {
rhs_t);
}
static bool stack_format_object(VM* self, c11_sv spec) {
static bool format_object(VM* self, py_Ref val, c11_sv spec) {
// format TOS via `spec` inplace
// spec: '!r:.2f', '.2f'
py_StackRef val = TOP();
if(spec.size == 0) return py_str(val);
if(spec.data[0] == '!') {