This commit is contained in:
blueloveTH 2023-06-17 22:35:35 +08:00
parent 97a009dcc9
commit 5e93c0d6e8
4 changed files with 13 additions and 8 deletions

View File

@ -236,6 +236,12 @@ __NEXT_STEP:;
} }
DISPATCH(); DISPATCH();
/*****************************************/ /*****************************************/
TARGET(BUILD_LONG) {
const static StrName m_long("long");
_0 = builtins->attr().try_get(m_long);
if(_0 == nullptr) AttributeError(builtins, m_long);
TOP() = call(_0, TOP());
} DISPATCH();
TARGET(BUILD_TUPLE) TARGET(BUILD_TUPLE)
_0 = VAR(STACK_VIEW(byte.arg).to_tuple()); _0 = VAR(STACK_VIEW(byte.arg).to_tuple());
STACK_SHRINK(byte.arg); STACK_SHRINK(byte.arg);

View File

@ -269,10 +269,8 @@ struct LongExpr: Expr{
void emit(CodeEmitContext* ctx) override { void emit(CodeEmitContext* ctx) override {
VM* vm = ctx->vm; VM* vm = ctx->vm;
PyObject* long_type = vm->builtins->attr().try_get("long"); ctx->emit(OP_LOAD_CONST, ctx->add_const(VAR(s)), line);
PK_ASSERT(long_type != nullptr); ctx->emit(OP_BUILD_LONG, BC_NOARG, line);
PyObject* obj = vm->call(long_type, VAR(s));
ctx->emit(OP_LOAD_CONST, ctx->add_const(obj), line);
} }
}; };

View File

@ -38,6 +38,7 @@ OPCODE(DELETE_GLOBAL)
OPCODE(DELETE_ATTR) OPCODE(DELETE_ATTR)
OPCODE(DELETE_SUBSCR) OPCODE(DELETE_SUBSCR)
/**************************/ /**************************/
OPCODE(BUILD_LONG)
OPCODE(BUILD_TUPLE) OPCODE(BUILD_TUPLE)
OPCODE(BUILD_LIST) OPCODE(BUILD_LIST)
OPCODE(BUILD_DICT) OPCODE(BUILD_DICT)

View File

@ -1565,10 +1565,10 @@ inline void Dict::_probe(PyObject *key, bool &ok, int &i) const{
} }
inline void CodeObjectSerializer::write_object(VM *vm, PyObject *obj){ inline void CodeObjectSerializer::write_object(VM *vm, PyObject *obj){
buffer += 'o'; if(is_int(obj)) write_int(_CAST(i64, obj));
PyObject* s = vm->py_repr(obj); if(is_float(obj)) write_float(_CAST(f64, obj));
buffer += CAST(Str&, s).str(); if(is_type(obj, vm->tp_str)) write_str(_CAST(Str&, obj));
buffer += END; FATAL_ERROR();
} }
} // namespace pkpy } // namespace pkpy