blueloveTH 3 лет назад
Родитель
Сommit
88e1a56150
4 измененных файлов с 11 добавлено и 9 удалено
  1. 5 0
      src/builtins.h
  2. 3 6
      src/pocketpy.h
  3. 1 1
      src/safestl.h
  4. 2 2
      src/str.h

+ 5 - 0
src/builtins.h

@@ -4,6 +4,11 @@ const char* __BUILTINS_CODE = R"(
 def len(x):
     return x.__len__()
 
+def print(*args, sep=' ', end='\n'):
+    s = sep.join([str(i) for i in args])
+    __sys_stdout_write(s + end)
+
+
 str.__mul__ = lambda self, n: ''.join([self for _ in range(n)])
 
 def __str4split(self, sep):

+ 3 - 6
src/pocketpy.h

@@ -39,12 +39,9 @@ void __initializeBuiltinFunctions(VM* _vm) {
 #undef BIND_NUM_ARITH_OPT
 #undef BIND_NUM_LOGICAL_OPT
 
-    _vm->bindBuiltinFunc("print", [](VM* vm, const pkpy::ArgList& args) {
-        _StrStream ss;
-        for(int i=0; i<args.size(); i++){
-            ss << vm->PyStr_AS_C(vm->asStr(args[i])) << " ";
-        }
-        (*vm->_stdout) << ss.str() << '\n';
+    _vm->bindBuiltinFunc("__sys_stdout_write", [](VM* vm, const pkpy::ArgList& args) {
+        vm->__checkArgSize(args, 1);
+        (*vm->_stdout) << vm->PyStr_AS_C(args[0]);
         return vm->None;
     });
 

+ 1 - 1
src/safestl.h

@@ -58,7 +58,7 @@ public:
     }
 #endif
 
-    PyVarDict() : emhash8::HashMap<_Str, PyVar>(5) {}
+    PyVarDict() : emhash8::HashMap<_Str, PyVar>() {}
 };
 
 

+ 2 - 2
src/str.h

@@ -72,7 +72,7 @@ private:
     pkpy::shared_ptr<_StrMemory> _s;
     bool interned = false;
 public:
-    _Str(const _StrLiteral& s){
+    _Str(_StrLiteral s){
         construct(s);
         intern();
     }
@@ -95,7 +95,7 @@ public:
         this->_s = pkpy::make_shared<_StrMemory>(std::move(s));
     }
 
-    void construct(const std::string_view& sv){
+    void construct(std::string_view sv){
         auto it = _strIntern.find(sv);
         if(it != _strIntern.end()){
             this->_s = it->second;