From 5e93c0d6e8aa8b9b6813b976158d28cd850f32dc Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sat, 17 Jun 2023 22:35:35 +0800 Subject: [PATCH] ... --- src/ceval.h | 6 ++++++ src/expr.h | 6 ++---- src/opcodes.h | 1 + src/vm.h | 8 ++++---- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/ceval.h b/src/ceval.h index 7b321c72..bcc5b3b4 100644 --- a/src/ceval.h +++ b/src/ceval.h @@ -236,6 +236,12 @@ __NEXT_STEP:; } 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) _0 = VAR(STACK_VIEW(byte.arg).to_tuple()); STACK_SHRINK(byte.arg); diff --git a/src/expr.h b/src/expr.h index 98f218d1..b56264cc 100644 --- a/src/expr.h +++ b/src/expr.h @@ -269,10 +269,8 @@ struct LongExpr: Expr{ void emit(CodeEmitContext* ctx) override { VM* vm = ctx->vm; - PyObject* long_type = vm->builtins->attr().try_get("long"); - PK_ASSERT(long_type != nullptr); - PyObject* obj = vm->call(long_type, VAR(s)); - ctx->emit(OP_LOAD_CONST, ctx->add_const(obj), line); + ctx->emit(OP_LOAD_CONST, ctx->add_const(VAR(s)), line); + ctx->emit(OP_BUILD_LONG, BC_NOARG, line); } }; diff --git a/src/opcodes.h b/src/opcodes.h index 8733c230..bf2f37ff 100644 --- a/src/opcodes.h +++ b/src/opcodes.h @@ -38,6 +38,7 @@ OPCODE(DELETE_GLOBAL) OPCODE(DELETE_ATTR) OPCODE(DELETE_SUBSCR) /**************************/ +OPCODE(BUILD_LONG) OPCODE(BUILD_TUPLE) OPCODE(BUILD_LIST) OPCODE(BUILD_DICT) diff --git a/src/vm.h b/src/vm.h index 6a16249e..d3ee334e 100644 --- a/src/vm.h +++ b/src/vm.h @@ -1565,10 +1565,10 @@ inline void Dict::_probe(PyObject *key, bool &ok, int &i) const{ } inline void CodeObjectSerializer::write_object(VM *vm, PyObject *obj){ - buffer += 'o'; - PyObject* s = vm->py_repr(obj); - buffer += CAST(Str&, s).str(); - buffer += END; + if(is_int(obj)) write_int(_CAST(i64, obj)); + if(is_float(obj)) write_float(_CAST(f64, obj)); + if(is_type(obj, vm->tp_str)) write_str(_CAST(Str&, obj)); + FATAL_ERROR(); } } // namespace pkpy \ No newline at end of file