blueloveTH 2 лет назад
Родитель
Сommit
5e93c0d6e8
4 измененных файлов с 13 добавлено и 8 удалено
  1. 6 0
      src/ceval.h
  2. 2 4
      src/expr.h
  3. 1 0
      src/opcodes.h
  4. 4 4
      src/vm.h

+ 6 - 0
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);

+ 2 - 4
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);
     }
 };
 

+ 1 - 0
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)

+ 4 - 4
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