blueloveTH пре 3 година
родитељ
комит
27f6290605
8 измењених фајлова са 224 додато и 224 уклоњено
  1. 1 1
      scripts/moc.py
  2. 112 112
      src/_bindings.h
  3. 4 4
      src/codeobject.h
  4. 1 1
      src/common.h
  5. 3 3
      src/obj.h
  6. 69 69
      src/pocketpy.h
  7. 21 21
      src/safestl.h
  8. 13 13
      src/vm.h

+ 1 - 1
scripts/moc.py

@@ -46,7 +46,7 @@ for n in [4,3,2,1]:
         impl = '\n'.join([' '*8 + i for i in impl])
         s += f'''__EXPORT\nvoid pkpy_vm_bind{name[3:]}(VM* vm, const char* mod, const char* name, {name} f) {{
     PyVar obj = vm->new_module_if_not_existed(mod);
-    vm->bindFunc<{len(p_args)}>(obj, name, [f](VM* vm, const pkpy::ArgList& args) {{
+    vm->bindFunc<{len(p_args)}>(obj, name, [f](VM* vm, const pkpy::Args& args) {{
 {impl}
     }});
 }}''' + '\n'

Разлика између датотеке није приказан због своје велике величине
+ 112 - 112
src/_bindings.h


+ 4 - 4
src/codeobject.h

@@ -263,10 +263,10 @@ public:
         }
     }
 
-    pkpy::ArgList pop_n_values_reversed(VM* vm, int n){
+    pkpy::Args pop_n_values_reversed(VM* vm, int n){
         int new_size = s_data.size() - n;
         if(new_size < 0) throw std::runtime_error("stack_size() < n");
-        pkpy::ArgList v(n);
+        pkpy::Args v(n);
         for(int i=n-1; i>=0; i--){
             v[i] = std::move(s_data[new_size + i]);
             try_deref(vm, v[i]);
@@ -275,8 +275,8 @@ public:
         return v;
     }
 
-    pkpy::ArgList pop_n_reversed(int n){
-        pkpy::ArgList v(n);
+    pkpy::Args pop_n_reversed(int n){
+        pkpy::Args v(n);
         for(int i=n-1; i>=0; i--) v[i] = pop();
         return v;
     }

+ 1 - 1
src/common.h

@@ -41,4 +41,4 @@ typedef int64_t i64;
 typedef double f64;
 #define DUMMY_VAL (i64)0
 
-#define CPP_LAMBDA(x) ([](VM* vm, const pkpy::ArgList& args) { return x; })
+#define CPP_LAMBDA(x) ([](VM* vm, const pkpy::Args& args) { return x; })

+ 3 - 3
src/obj.h

@@ -7,8 +7,8 @@ struct BaseRef;
 class VM;
 class Frame;
 
-//typedef PyVar (*_CppFuncRaw)(VM*, const pkpy::ArgList&);
-typedef std::function<PyVar(VM*, const pkpy::ArgList&)> _CppFuncRaw;
+//typedef PyVar (*_CppFuncRaw)(VM*, const pkpy::Args&);
+typedef std::function<PyVar(VM*, const pkpy::Args&)> _CppFuncRaw;
 typedef pkpy::shared_ptr<CodeObject> _Code;
 
 struct _CppFunc {
@@ -17,7 +17,7 @@ struct _CppFunc {
     bool method;
     
     _CppFunc(_CppFuncRaw f, int argc, bool method) : f(f), argc(argc), method(method) {}
-    inline PyVar operator()(VM* vm, const pkpy::ArgList& args) const;
+    inline PyVar operator()(VM* vm, const pkpy::Args& args) const;
 };
 
 struct Function {

+ 69 - 69
src/pocketpy.h

@@ -17,7 +17,7 @@ _Code VM::compile(_Str source, _Str filename, CompileMode mode) {
 }
 
 #define BIND_NUM_ARITH_OPT(name, op)                                                                    \
-    _vm->bindMethodMulti<1>({"int","float"}, #name, [](VM* vm, const pkpy::ArgList& args){              \
+    _vm->bindMethodMulti<1>({"int","float"}, #name, [](VM* vm, const pkpy::Args& args){                 \
         if(args[0]->is_type(vm->_tp_int) && args[1]->is_type(vm->_tp_int)){                             \
             return vm->PyInt(vm->PyInt_AS_C(args[0]) op vm->PyInt_AS_C(args[1]));                       \
         }else{                                                                                          \
@@ -26,7 +26,7 @@ _Code VM::compile(_Str source, _Str filename, CompileMode mode) {
     });
 
 #define BIND_NUM_LOGICAL_OPT(name, op, is_eq)                                                           \
-    _vm->bindMethodMulti<1>({"int","float"}, #name, [](VM* vm, const pkpy::ArgList& args){              \
+    _vm->bindMethodMulti<1>({"int","float"}, #name, [](VM* vm, const pkpy::Args& args){                 \
         bool _0 = args[0]->is_type(vm->_tp_int) || args[0]->is_type(vm->_tp_float);                     \
         bool _1 = args[1]->is_type(vm->_tp_int) || args[1]->is_type(vm->_tp_float);                     \
         if(!_0 || !_1){                                                                                 \
@@ -52,23 +52,23 @@ void __initializeBuiltinFunctions(VM* _vm) {
 #undef BIND_NUM_ARITH_OPT
 #undef BIND_NUM_LOGICAL_OPT
 
-    _vm->bindBuiltinFunc<1>("__sys_stdout_write", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindBuiltinFunc<1>("__sys_stdout_write", [](VM* vm, const pkpy::Args& args) {
         (*vm->_stdout) << vm->PyStr_AS_C(args[0]);
         return vm->None;
     });
 
-    _vm->bindBuiltinFunc<0>("super", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindBuiltinFunc<0>("super", [](VM* vm, const pkpy::Args& args) {
         auto it = vm->top_frame()->f_locals().find(m_self);
         if(it == vm->top_frame()->f_locals().end()) vm->typeError("super() can only be called in a class method");
         return vm->new_object(vm->_tp_super, it->second);
     });
 
-    _vm->bindBuiltinFunc<1>("eval", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindBuiltinFunc<1>("eval", [](VM* vm, const pkpy::Args& args) {
         _Code code = vm->compile(vm->PyStr_AS_C(args[0]), "<eval>", EVAL_MODE);
         return vm->_exec(code, vm->top_frame()->_module, vm->top_frame()->_locals);
     });
 
-    _vm->bindBuiltinFunc<1>("exec", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindBuiltinFunc<1>("exec", [](VM* vm, const pkpy::Args& args) {
         _Code code = vm->compile(vm->PyStr_AS_C(args[0]), "<exec>", EXEC_MODE);
         vm->_exec(code, vm->top_frame()->_module, vm->top_frame()->_locals);
         return vm->None;
@@ -78,40 +78,40 @@ void __initializeBuiltinFunctions(VM* _vm) {
     _vm->bindBuiltinFunc<1>("hash", CPP_LAMBDA(vm->PyInt(vm->hash(args[0]))));
     _vm->bindBuiltinFunc<1>("len", CPP_LAMBDA(vm->call(args[0], __len__, pkpy::noArg())));
 
-    _vm->bindBuiltinFunc<1>("chr", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindBuiltinFunc<1>("chr", [](VM* vm, const pkpy::Args& args) {
         i64 i = vm->PyInt_AS_C(args[0]);
         if (i < 0 || i > 128) vm->valueError("chr() arg not in range(128)");
         return vm->PyStr(std::string(1, (char)i));
     });
 
-    _vm->bindBuiltinFunc<1>("ord", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindBuiltinFunc<1>("ord", [](VM* vm, const pkpy::Args& args) {
         _Str s = vm->PyStr_AS_C(args[0]);
         if (s.size() != 1) vm->typeError("ord() expected an ASCII character");
         return vm->PyInt((i64)(s.c_str()[0]));
     });
 
-    _vm->bindBuiltinFunc<2>("hasattr", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindBuiltinFunc<2>("hasattr", [](VM* vm, const pkpy::Args& args) {
         return vm->PyBool(vm->getattr(args[0], vm->PyStr_AS_C(args[1]), false) != nullptr);
     });
 
-    _vm->bindBuiltinFunc<3>("setattr", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindBuiltinFunc<3>("setattr", [](VM* vm, const pkpy::Args& args) {
         PyVar obj = args[0];
         vm->setattr(obj, vm->PyStr_AS_C(args[1]), args[2]);
         return vm->None;
     });
 
-    _vm->bindBuiltinFunc<2>("getattr", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindBuiltinFunc<2>("getattr", [](VM* vm, const pkpy::Args& args) {
         _Str name = vm->PyStr_AS_C(args[1]);
         return vm->getattr(args[0], name);
     });
 
-    _vm->bindBuiltinFunc<1>("hex", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindBuiltinFunc<1>("hex", [](VM* vm, const pkpy::Args& args) {
         std::stringstream ss;
         ss << std::hex << vm->PyInt_AS_C(args[0]);
         return vm->PyStr("0x" + ss.str());
     });
 
-    _vm->bindBuiltinFunc<1>("dir", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindBuiltinFunc<1>("dir", [](VM* vm, const pkpy::Args& args) {
         std::vector<_Str> names;
         for (auto& [k, _] : args[0]->attribs) names.push_back(k);
         for (auto& [k, _] : args[0]->_type->attribs) {
@@ -126,7 +126,7 @@ void __initializeBuiltinFunctions(VM* _vm) {
         return vm->PyList(ret);
     });
 
-    _vm->bindMethod<0>("object", "__repr__", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindMethod<0>("object", "__repr__", [](VM* vm, const pkpy::Args& args) {
         PyVar _self = args[0];
         std::stringstream ss;
         ss << std::hex << (uintptr_t)_self.get();
@@ -138,7 +138,7 @@ void __initializeBuiltinFunctions(VM* _vm) {
     _vm->bindMethod<1>("object", "__ne__", CPP_LAMBDA(vm->PyBool(args[0] != args[1])));
     _vm->bindStaticMethod<1>("type", "__new__", CPP_LAMBDA(args[0]->_type));
 
-    _vm->bindStaticMethod<-1>("range", "__new__", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindStaticMethod<-1>("range", "__new__", [](VM* vm, const pkpy::Args& args) {
         _Range r;
         switch (args.size()) {
             case 1: r.stop = vm->PyInt_AS_C(args[0]); break;
@@ -156,13 +156,13 @@ void __initializeBuiltinFunctions(VM* _vm) {
     _vm->bindMethod<0>("NoneType", "__repr__", CPP_LAMBDA(vm->PyStr("None")));
     _vm->bindMethod<0>("NoneType", "__json__", CPP_LAMBDA(vm->PyStr("null")));
 
-    _vm->bindMethodMulti<1>({"int", "float"}, "__truediv__", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindMethodMulti<1>({"int", "float"}, "__truediv__", [](VM* vm, const pkpy::Args& args) {
         f64 rhs = vm->num_to_float(args[1]);
         if (rhs == 0) vm->zeroDivisionError();
         return vm->PyFloat(vm->num_to_float(args[0]) / rhs);
     });
 
-    _vm->bindMethodMulti<1>({"int", "float"}, "__pow__", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindMethodMulti<1>({"int", "float"}, "__pow__", [](VM* vm, const pkpy::Args& args) {
         if(args[0]->is_type(vm->_tp_int) && args[1]->is_type(vm->_tp_int)){
             return vm->PyInt((i64)round(pow(vm->PyInt_AS_C(args[0]), vm->PyInt_AS_C(args[1]))));
         }else{
@@ -171,7 +171,7 @@ void __initializeBuiltinFunctions(VM* _vm) {
     });
 
     /************ PyInt ************/
-    _vm->bindStaticMethod<1>("int", "__new__", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindStaticMethod<1>("int", "__new__", [](VM* vm, const pkpy::Args& args) {
         if (args[0]->is_type(vm->_tp_int)) return args[0];
         if (args[0]->is_type(vm->_tp_float)) return vm->PyInt((i64)vm->PyFloat_AS_C(args[0]));
         if (args[0]->is_type(vm->_tp_bool)) return vm->PyInt(vm->PyBool_AS_C(args[0]) ? 1 : 0);
@@ -190,28 +190,28 @@ void __initializeBuiltinFunctions(VM* _vm) {
         return vm->None;
     });
 
-    _vm->bindMethod<1>("int", "__floordiv__", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindMethod<1>("int", "__floordiv__", [](VM* vm, const pkpy::Args& args) {
         i64 rhs = vm->PyInt_AS_C(args[1]);
         if(rhs == 0) vm->zeroDivisionError();
         return vm->PyInt(vm->PyInt_AS_C(args[0]) / rhs);
     });
 
-    _vm->bindMethod<1>("int", "__mod__", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindMethod<1>("int", "__mod__", [](VM* vm, const pkpy::Args& args) {
         i64 rhs = vm->PyInt_AS_C(args[1]);
         if(rhs == 0) vm->zeroDivisionError();
         return vm->PyInt(vm->PyInt_AS_C(args[0]) % rhs);
     });
 
-    _vm->bindMethod<0>("int", "__repr__", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindMethod<0>("int", "__repr__", [](VM* vm, const pkpy::Args& args) {
         return vm->PyStr(std::to_string(vm->PyInt_AS_C(args[0])));
     });
 
-    _vm->bindMethod<0>("int", "__json__", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindMethod<0>("int", "__json__", [](VM* vm, const pkpy::Args& args) {
         return vm->PyStr(std::to_string((int)vm->PyInt_AS_C(args[0])));
     });
 
 #define __INT_BITWISE_OP(name,op) \
-    _vm->bindMethod<1>("int", #name, [](VM* vm, const pkpy::ArgList& args) {                    \
+    _vm->bindMethod<1>("int", #name, [](VM* vm, const pkpy::Args& args) {                    \
         return vm->PyInt(vm->PyInt_AS_C(args[0]) op vm->PyInt_AS_C(args[1]));     \
     });
 
@@ -224,7 +224,7 @@ void __initializeBuiltinFunctions(VM* _vm) {
 #undef __INT_BITWISE_OP
 
     /************ PyFloat ************/
-    _vm->bindStaticMethod<1>("float", "__new__", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindStaticMethod<1>("float", "__new__", [](VM* vm, const pkpy::Args& args) {
         if (args[0]->is_type(vm->_tp_int)) return vm->PyFloat((f64)vm->PyInt_AS_C(args[0]));
         if (args[0]->is_type(vm->_tp_float)) return args[0];
         if (args[0]->is_type(vm->_tp_bool)) return vm->PyFloat(vm->PyBool_AS_C(args[0]) ? 1.0 : 0.0);
@@ -243,7 +243,7 @@ void __initializeBuiltinFunctions(VM* _vm) {
         return vm->None;
     });
 
-    _vm->bindMethod<0>("float", "__repr__", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindMethod<0>("float", "__repr__", [](VM* vm, const pkpy::Args& args) {
         f64 val = vm->PyFloat_AS_C(args[0]);
         if(std::isinf(val) || std::isnan(val)) return vm->PyStr(std::to_string(val));
         _StrStream ss;
@@ -253,7 +253,7 @@ void __initializeBuiltinFunctions(VM* _vm) {
         return vm->PyStr(s);
     });
 
-    _vm->bindMethod<0>("float", "__json__", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindMethod<0>("float", "__json__", [](VM* vm, const pkpy::Args& args) {
         f64 val = vm->PyFloat_AS_C(args[0]);
         if(std::isinf(val) || std::isnan(val)) vm->valueError("cannot jsonify 'nan' or 'inf'");
         return vm->PyStr(std::to_string(val));
@@ -262,18 +262,18 @@ void __initializeBuiltinFunctions(VM* _vm) {
     /************ PyString ************/
     _vm->bindStaticMethod<1>("str", "__new__", CPP_LAMBDA(vm->asStr(args[0])));
 
-    _vm->bindMethod<1>("str", "__add__", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindMethod<1>("str", "__add__", [](VM* vm, const pkpy::Args& args) {
         const _Str& lhs = vm->PyStr_AS_C(args[0]);
         const _Str& rhs = vm->PyStr_AS_C(args[1]);
         return vm->PyStr(lhs + rhs);
     });
 
-    _vm->bindMethod<0>("str", "__len__", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindMethod<0>("str", "__len__", [](VM* vm, const pkpy::Args& args) {
         const _Str& _self = vm->PyStr_AS_C(args[0]);
         return vm->PyInt(_self.u8_length());
     });
 
-    _vm->bindMethod<1>("str", "__contains__", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindMethod<1>("str", "__contains__", [](VM* vm, const pkpy::Args& args) {
         const _Str& _self = vm->PyStr_AS_C(args[0]);
         const _Str& _other = vm->PyStr_AS_C(args[1]);
         return vm->PyBool(_self.find(_other) != _Str::npos);
@@ -285,29 +285,29 @@ void __initializeBuiltinFunctions(VM* _vm) {
         vm->PyIter(pkpy::make_shared<BaseIterator, StringIterator>(vm, args[0]))
     ));
 
-    _vm->bindMethod<0>("str", "__repr__", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindMethod<0>("str", "__repr__", [](VM* vm, const pkpy::Args& args) {
         const _Str& _self = vm->PyStr_AS_C(args[0]);
         return vm->PyStr(_self.__escape(true));
     });
 
-    _vm->bindMethod<0>("str", "__json__", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindMethod<0>("str", "__json__", [](VM* vm, const pkpy::Args& args) {
         const _Str& _self = vm->PyStr_AS_C(args[0]);
         return vm->PyStr(_self.__escape(false));
     });
 
-    _vm->bindMethod<1>("str", "__eq__", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindMethod<1>("str", "__eq__", [](VM* vm, const pkpy::Args& args) {
         if(args[0]->is_type(vm->_tp_str) && args[1]->is_type(vm->_tp_str))
             return vm->PyBool(vm->PyStr_AS_C(args[0]) == vm->PyStr_AS_C(args[1]));
         return vm->PyBool(args[0] == args[1]);
     });
 
-    _vm->bindMethod<1>("str", "__ne__", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindMethod<1>("str", "__ne__", [](VM* vm, const pkpy::Args& args) {
         if(args[0]->is_type(vm->_tp_str) && args[1]->is_type(vm->_tp_str))
             return vm->PyBool(vm->PyStr_AS_C(args[0]) != vm->PyStr_AS_C(args[1]));
         return vm->PyBool(args[0] != args[1]);
     });
 
-    _vm->bindMethod<1>("str", "__getitem__", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindMethod<1>("str", "__getitem__", [](VM* vm, const pkpy::Args& args) {
         const _Str& _self (vm->PyStr_AS_C(args[0]));
 
         if(args[1]->is_type(vm->_tp_slice)){
@@ -321,19 +321,19 @@ void __initializeBuiltinFunctions(VM* _vm) {
         return vm->PyStr(_self.u8_getitem(_index));
     });
 
-    _vm->bindMethod<1>("str", "__gt__", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindMethod<1>("str", "__gt__", [](VM* vm, const pkpy::Args& args) {
         const _Str& _self (vm->PyStr_AS_C(args[0]));
         const _Str& _obj (vm->PyStr_AS_C(args[1]));
         return vm->PyBool(_self > _obj);
     });
 
-    _vm->bindMethod<1>("str", "__lt__", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindMethod<1>("str", "__lt__", [](VM* vm, const pkpy::Args& args) {
         const _Str& _self (vm->PyStr_AS_C(args[0]));
         const _Str& _obj (vm->PyStr_AS_C(args[1]));
         return vm->PyBool(_self < _obj);
     });
 
-    _vm->bindMethod<2>("str", "replace", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindMethod<2>("str", "replace", [](VM* vm, const pkpy::Args& args) {
         const _Str& _self = vm->PyStr_AS_C(args[0]);
         const _Str& _old = vm->PyStr_AS_C(args[1]);
         const _Str& _new = vm->PyStr_AS_C(args[2]);
@@ -347,19 +347,19 @@ void __initializeBuiltinFunctions(VM* _vm) {
         return vm->PyStr(_copy);
     });
 
-    _vm->bindMethod<1>("str", "startswith", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindMethod<1>("str", "startswith", [](VM* vm, const pkpy::Args& args) {
         const _Str& _self = vm->PyStr_AS_C(args[0]);
         const _Str& _prefix = vm->PyStr_AS_C(args[1]);
         return vm->PyBool(_self.find(_prefix) == 0);
     });
 
-    _vm->bindMethod<1>("str", "endswith", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindMethod<1>("str", "endswith", [](VM* vm, const pkpy::Args& args) {
         const _Str& _self = vm->PyStr_AS_C(args[0]);
         const _Str& _suffix = vm->PyStr_AS_C(args[1]);
         return vm->PyBool(_self.rfind(_suffix) == _self.length() - _suffix.length());
     });
 
-    _vm->bindMethod<1>("str", "join", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindMethod<1>("str", "join", [](VM* vm, const pkpy::Args& args) {
         const _Str& _self = vm->PyStr_AS_C(args[0]);
         PyVarList* _list;
         if(args[1]->is_type(vm->_tp_list)){
@@ -378,19 +378,19 @@ void __initializeBuiltinFunctions(VM* _vm) {
     });
 
     /************ PyList ************/
-    _vm->bindMethod<0>("list", "__iter__", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindMethod<0>("list", "__iter__", [](VM* vm, const pkpy::Args& args) {
         return vm->PyIter(
             pkpy::make_shared<BaseIterator, VectorIterator>(vm, args[0])
         );
     });
 
-    _vm->bindMethod<1>("list", "append", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindMethod<1>("list", "append", [](VM* vm, const pkpy::Args& args) {
         PyVarList& _self = vm->PyList_AS_C(args[0]);
         _self.push_back(args[1]);
         return vm->None;
     });
 
-    _vm->bindMethod<2>("list", "insert", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindMethod<2>("list", "insert", [](VM* vm, const pkpy::Args& args) {
         PyVarList& _self = vm->PyList_AS_C(args[0]);
         int _index = (int)vm->PyInt_AS_C(args[1]);
         if(_index < 0) _index += _self.size();
@@ -400,16 +400,16 @@ void __initializeBuiltinFunctions(VM* _vm) {
         return vm->None;
     });
 
-    _vm->bindMethod<0>("list", "clear", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindMethod<0>("list", "clear", [](VM* vm, const pkpy::Args& args) {
         vm->PyList_AS_C(args[0]).clear();
         return vm->None;
     });
 
-    _vm->bindMethod<0>("list", "copy", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindMethod<0>("list", "copy", [](VM* vm, const pkpy::Args& args) {
         return vm->PyList(vm->PyList_AS_C(args[0]));
     });
 
-    _vm->bindMethod<1>("list", "__add__", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindMethod<1>("list", "__add__", [](VM* vm, const pkpy::Args& args) {
         const PyVarList& _self = vm->PyList_AS_C(args[0]);
         const PyVarList& _obj = vm->PyList_AS_C(args[1]);
         PyVarList _new_list = _self;
@@ -417,12 +417,12 @@ void __initializeBuiltinFunctions(VM* _vm) {
         return vm->PyList(_new_list);
     });
 
-    _vm->bindMethod<0>("list", "__len__", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindMethod<0>("list", "__len__", [](VM* vm, const pkpy::Args& args) {
         const PyVarList& _self = vm->PyList_AS_C(args[0]);
         return vm->PyInt(_self.size());
     });
 
-    _vm->bindMethodMulti<1>({"list", "tuple"}, "__getitem__", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindMethodMulti<1>({"list", "tuple"}, "__getitem__", [](VM* vm, const pkpy::Args& args) {
         bool list = args[0]->is_type(vm->_tp_list);
         const PyVarList& _self = list ? vm->PyList_AS_C(args[0]) : vm->PyTuple_AS_C(args[0]);
 
@@ -439,7 +439,7 @@ void __initializeBuiltinFunctions(VM* _vm) {
         return _self[_index];
     });
 
-    _vm->bindMethod<2>("list", "__setitem__", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindMethod<2>("list", "__setitem__", [](VM* vm, const pkpy::Args& args) {
         PyVarList& _self = vm->PyList_AS_C(args[0]);
         int _index = (int)vm->PyInt_AS_C(args[1]);
         _index = vm->normalized_index(_index, _self.size());
@@ -447,7 +447,7 @@ void __initializeBuiltinFunctions(VM* _vm) {
         return vm->None;
     });
 
-    _vm->bindMethod<1>("list", "__delitem__", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindMethod<1>("list", "__delitem__", [](VM* vm, const pkpy::Args& args) {
         PyVarList& _self = vm->PyList_AS_C(args[0]);
         int _index = (int)vm->PyInt_AS_C(args[1]);
         _index = vm->normalized_index(_index, _self.size());
@@ -456,16 +456,16 @@ void __initializeBuiltinFunctions(VM* _vm) {
     });
 
     /************ PyTuple ************/
-    _vm->bindStaticMethod<1>("tuple", "__new__", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindStaticMethod<1>("tuple", "__new__", [](VM* vm, const pkpy::Args& args) {
         PyVarList _list = vm->PyList_AS_C(vm->call(vm->builtins->attribs["list"], args));
         return vm->PyTuple(_list);
     });
 
-    _vm->bindMethod<0>("tuple", "__iter__", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindMethod<0>("tuple", "__iter__", [](VM* vm, const pkpy::Args& args) {
         return vm->PyIter(pkpy::make_shared<BaseIterator, VectorIterator>(vm, args[0]));
     });
 
-    _vm->bindMethod<0>("tuple", "__len__", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindMethod<0>("tuple", "__len__", [](VM* vm, const pkpy::Args& args) {
         const PyVarList& _self = vm->PyTuple_AS_C(args[0]);
         return vm->PyInt(_self.size());
     });
@@ -473,17 +473,17 @@ void __initializeBuiltinFunctions(VM* _vm) {
     /************ PyBool ************/
     _vm->bindStaticMethod<1>("bool", "__new__", CPP_LAMBDA(vm->asBool(args[0])));
 
-    _vm->bindMethod<0>("bool", "__repr__", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindMethod<0>("bool", "__repr__", [](VM* vm, const pkpy::Args& args) {
         bool val = vm->PyBool_AS_C(args[0]);
         return vm->PyStr(val ? "True" : "False");
     });
 
-    _vm->bindMethod<0>("bool", "__json__", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindMethod<0>("bool", "__json__", [](VM* vm, const pkpy::Args& args) {
         bool val = vm->PyBool_AS_C(args[0]);
         return vm->PyStr(val ? "true" : "false");
     });
 
-    _vm->bindMethod<1>("bool", "__xor__", [](VM* vm, const pkpy::ArgList& args) {
+    _vm->bindMethod<1>("bool", "__xor__", [](VM* vm, const pkpy::Args& args) {
         bool _self = vm->PyBool_AS_C(args[0]);
         bool _obj = vm->PyBool_AS_C(args[1]);
         return vm->PyBool(_self ^ _obj);
@@ -508,7 +508,7 @@ void __initializeBuiltinFunctions(VM* _vm) {
 
 void __add_module_time(VM* vm){
     PyVar mod = vm->new_module("time");
-    vm->bindFunc<0>(mod, "time", [](VM* vm, const pkpy::ArgList& args) {
+    vm->bindFunc<0>(mod, "time", [](VM* vm, const pkpy::Args& args) {
         auto now = std::chrono::high_resolution_clock::now();
         return vm->PyFloat(std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count() / 1000000.0);
     });
@@ -516,15 +516,15 @@ void __add_module_time(VM* vm){
 
 void __add_module_sys(VM* vm){
     PyVar mod = vm->new_module("sys");
-    vm->bindFunc<1>(mod, "getrefcount", [](VM* vm, const pkpy::ArgList& args) {
+    vm->bindFunc<1>(mod, "getrefcount", [](VM* vm, const pkpy::Args& args) {
         return vm->PyInt(args[0].use_count());
     });
 
-    vm->bindFunc<0>(mod, "getrecursionlimit", [](VM* vm, const pkpy::ArgList& args) {
+    vm->bindFunc<0>(mod, "getrecursionlimit", [](VM* vm, const pkpy::Args& args) {
         return vm->PyInt(vm->maxRecursionDepth);
     });
 
-    vm->bindFunc<1>(mod, "setrecursionlimit", [](VM* vm, const pkpy::ArgList& args) {
+    vm->bindFunc<1>(mod, "setrecursionlimit", [](VM* vm, const pkpy::Args& args) {
         vm->maxRecursionDepth = (int)vm->PyInt_AS_C(args[0]);
         return vm->None;
     });
@@ -534,13 +534,13 @@ void __add_module_sys(VM* vm){
 
 void __add_module_json(VM* vm){
     PyVar mod = vm->new_module("json");
-    vm->bindFunc<1>(mod, "loads", [](VM* vm, const pkpy::ArgList& args) {
+    vm->bindFunc<1>(mod, "loads", [](VM* vm, const pkpy::Args& args) {
         const _Str& expr = vm->PyStr_AS_C(args[0]);
         _Code code = vm->compile(expr, "<json>", JSON_MODE);
         return vm->_exec(code, vm->top_frame()->_module, vm->top_frame()->_locals);
     });
 
-    vm->bindFunc<1>(mod, "dumps", [](VM* vm, const pkpy::ArgList& args) {
+    vm->bindFunc<1>(mod, "dumps", [](VM* vm, const pkpy::Args& args) {
         return vm->asJson(args[0]);
     });
 }
@@ -562,7 +562,7 @@ void __add_module_math(VM* vm){
 
 void __add_module_dis(VM* vm){
     PyVar mod = vm->new_module("dis");
-    vm->bindFunc<1>(mod, "dis", [](VM* vm, const pkpy::ArgList& args) {
+    vm->bindFunc<1>(mod, "dis", [](VM* vm, const pkpy::Args& args) {
         _Code code = vm->PyFunction_AS_C(args[0])->code;
         (*vm->_stdout) << vm->disassemble(code);
         return vm->None;
@@ -584,12 +584,12 @@ struct ReMatch {
         vm->bindMethod<0>(_tp_match, "start", CPP_LAMBDA(vm->PyInt(UNION_GET(ReMatch, args[0]).start)));
         vm->bindMethod<0>(_tp_match, "end", CPP_LAMBDA(vm->PyInt(UNION_GET(ReMatch, args[0]).end)));
 
-        vm->bindMethod<0>(_tp_match, "span", [](VM* vm, const pkpy::ArgList& args) {
+        vm->bindMethod<0>(_tp_match, "span", [](VM* vm, const pkpy::Args& args) {
             auto& m = UNION_GET(ReMatch, args[0]);
             return vm->PyTuple({ vm->PyInt(m.start), vm->PyInt(m.end) });
         });
 
-        vm->bindMethod<1>(_tp_match, "group", [](VM* vm, const pkpy::ArgList& args) {
+        vm->bindMethod<1>(_tp_match, "group", [](VM* vm, const pkpy::Args& args) {
             auto& m = UNION_GET(ReMatch, args[0]);
             int index = (int)vm->PyInt_AS_C(args[1]);
             index = vm->normalized_index(index, m.m.size());
@@ -615,19 +615,19 @@ void __add_module_re(VM* vm){
     PyVar mod = vm->new_module("re");
     ReMatch::_bind(vm);
 
-    vm->bindFunc<2>(mod, "match", [](VM* vm, const pkpy::ArgList& args) {
+    vm->bindFunc<2>(mod, "match", [](VM* vm, const pkpy::Args& args) {
         const _Str& pattern = vm->PyStr_AS_C(args[0]);
         const _Str& string = vm->PyStr_AS_C(args[1]);
         return __regex_search(pattern, string, true, vm);
     });
 
-    vm->bindFunc<2>(mod, "search", [](VM* vm, const pkpy::ArgList& args) {
+    vm->bindFunc<2>(mod, "search", [](VM* vm, const pkpy::Args& args) {
         const _Str& pattern = vm->PyStr_AS_C(args[0]);
         const _Str& string = vm->PyStr_AS_C(args[1]);
         return __regex_search(pattern, string, false, vm);
     });
 
-    vm->bindFunc<3>(mod, "sub", [](VM* vm, const pkpy::ArgList& args) {
+    vm->bindFunc<3>(mod, "sub", [](VM* vm, const pkpy::Args& args) {
         const _Str& pattern = vm->PyStr_AS_C(args[0]);
         const _Str& repl = vm->PyStr_AS_C(args[1]);
         const _Str& string = vm->PyStr_AS_C(args[2]);
@@ -635,7 +635,7 @@ void __add_module_re(VM* vm){
         return vm->PyStr(std::regex_replace(string, re, repl));
     });
 
-    vm->bindFunc<2>(mod, "split", [](VM* vm, const pkpy::ArgList& args) {
+    vm->bindFunc<2>(mod, "split", [](VM* vm, const pkpy::Args& args) {
         const _Str& pattern = vm->PyStr_AS_C(args[0]);
         const _Str& string = vm->PyStr_AS_C(args[1]);
         std::regex re(pattern);

+ 21 - 21
src/safestl.h

@@ -37,9 +37,9 @@ typedef emhash8::HashMap<_Str, PyVar> PyVarDict;
 
 namespace pkpy {
     const int MAX_POOLING_N = 10;
-    static thread_local std::vector<PyVar*>* _poolArgList = new std::vector<PyVar*>[MAX_POOLING_N];
+    static thread_local std::vector<PyVar*>* _poolArgs = new std::vector<PyVar*>[MAX_POOLING_N];
 
-    class ArgList {
+    class Args {
         PyVar* _args;
         int _size;
 
@@ -49,44 +49,44 @@ namespace pkpy {
                 this->_size = 0;
                 return;
             }
-            if(n >= MAX_POOLING_N || _poolArgList[n].empty()){
+            if(n >= MAX_POOLING_N || _poolArgs[n].empty()){
                 this->_args = new PyVar[n];
                 this->_size = n;
             }else{
-                this->_args = _poolArgList[n].back();
+                this->_args = _poolArgs[n].back();
                 this->_size = n;
-                _poolArgList[n].pop_back();
+                _poolArgs[n].pop_back();
             }
         }
 
         void __tryRelease(){
             if(_size == 0 || _args == nullptr) return;
-            if(_size >= MAX_POOLING_N || _poolArgList[_size].size() > 32){
+            if(_size >= MAX_POOLING_N || _poolArgs[_size].size() > 32){
                 delete[] _args;
             }else{
                 for(int i = 0; i < _size; i++) _args[i].reset();
-                _poolArgList[_size].push_back(_args);
+                _poolArgs[_size].push_back(_args);
             }
         }
 
     public:
-        ArgList(size_t n){
+        Args(size_t n){
             __tryAlloc(n);
         }
 
-        ArgList(const ArgList& other){
+        Args(const Args& other){
             __tryAlloc(other._size);
             for(int i=0; i<_size; i++) _args[i] = other._args[i];
         }
 
-        ArgList(ArgList&& other) noexcept {
+        Args(Args&& other) noexcept {
             this->_args = other._args;
             this->_size = other._size;
             other._args = nullptr;
             other._size = 0;
         }
 
-        ArgList(PyVarList&& other) noexcept {
+        Args(PyVarList&& other) noexcept {
             __tryAlloc(other.size());
             for(int i=0; i<_size; i++){
                 _args[i] = std::move(other[i]);
@@ -97,7 +97,7 @@ namespace pkpy {
         PyVar& operator[](int i){ return _args[i]; }
         const PyVar& operator[](int i) const { return _args[i]; }
 
-        ArgList& operator=(ArgList&& other) noexcept {
+        Args& operator=(Args&& other) noexcept {
             __tryRelease();
             this->_args = other._args;
             this->_size = other._size;
@@ -124,33 +124,33 @@ namespace pkpy {
 
             memcpy((void*)(_args+1), (void*)old_args, sizeof(PyVar)*old_size);
             memset((void*)old_args, 0, sizeof(PyVar)*old_size);
-            if(old_size >= MAX_POOLING_N || _poolArgList[old_size].size() > 32){
+            if(old_size >= MAX_POOLING_N || _poolArgs[old_size].size() > 32){
                 delete[] old_args;
             }else{
-                _poolArgList[old_size].push_back(old_args);
+                _poolArgs[old_size].push_back(old_args);
             }
         }
 
-        ~ArgList(){
+        ~Args(){
             __tryRelease();
         }
     };
 
-    const ArgList& noArg(){
-        static const ArgList ret(0);
+    const Args& noArg(){
+        static const Args ret(0);
         return ret;
     }
 
     template<typename T>
-    ArgList oneArg(T&& a) {
-        ArgList ret(1);
+    Args oneArg(T&& a) {
+        Args ret(1);
         ret[0] = std::forward<T>(a);
         return ret;
     }
 
     template<typename T1, typename T2>
-    ArgList twoArgs(T1&& a, T2&& b) {
-        ArgList ret(2);
+    Args twoArgs(T1&& a, T2&& b) {
+        Args ret(2);
         ret[0] = std::forward<T1>(a);
         ret[1] = std::forward<T2>(b);
         return ret;

+ 13 - 13
src/vm.h

@@ -71,7 +71,7 @@ protected:
             } break;
             case OP_BUILD_SMART_TUPLE:
             {
-                pkpy::ArgList items = frame->pop_n_reversed(byte.arg);
+                pkpy::Args items = frame->pop_n_reversed(byte.arg);
                 bool done = false;
                 for(int i=0; i<items.size(); i++){
                     if(!items[i]->is_type(_tp_ref)) {
@@ -87,7 +87,7 @@ protected:
             } break;
             case OP_BUILD_STRING:
             {
-                pkpy::ArgList items = frame->pop_n_values_reversed(this, byte.arg);
+                pkpy::Args items = frame->pop_n_values_reversed(this, byte.arg);
                 _StrStream ss;
                 for(int i=0; i<items.size(); i++) ss << PyStr_AS_C(asStr(items[i]));
                 frame->push(PyStr(ss.str()));
@@ -96,7 +96,7 @@ protected:
                 frame->push(builtins->attribs[m_eval]);
             } break;
             case OP_LIST_APPEND: {
-                pkpy::ArgList args(2);
+                pkpy::Args args(2);
                 args[1] = frame->pop_value(this);            // obj
                 args[0] = frame->top_value_offset(this, -2);     // list
                 fast_call(m_append, std::move(args));
@@ -133,7 +133,7 @@ protected:
             case OP_POP_TOP: frame->__pop(); break;
             case OP_BINARY_OP:
                 {
-                    pkpy::ArgList args(2);
+                    pkpy::Args args(2);
                     args[1] = frame->pop_value(this);
                     args[0] = frame->top_value(this);
                     frame->top() = fast_call(BINARY_SPECIAL_METHODS[byte.arg], std::move(args));
@@ -147,7 +147,7 @@ protected:
                 } break;
             case OP_COMPARE_OP:
                 {
-                    pkpy::ArgList args(2);
+                    pkpy::Args args(2);
                     args[1] = frame->pop_value(this);
                     args[0] = frame->top_value(this);
                     frame->top() = fast_call(CMP_SPECIAL_METHODS[byte.arg], std::move(args));
@@ -201,7 +201,7 @@ protected:
                 break;
             case OP_BUILD_MAP:
                 {
-                    pkpy::ArgList items = frame->pop_n_values_reversed(this, byte.arg*2);
+                    pkpy::Args items = frame->pop_n_values_reversed(this, byte.arg*2);
                     PyVar obj = call(builtins->attribs["dict"]);
                     for(int i=0; i<items.size(); i+=2){
                         call(obj, __setitem__, pkpy::twoArgs(items[i], items[i+1]));
@@ -221,9 +221,9 @@ protected:
                 {
                     int ARGC = byte.arg & 0xFFFF;
                     int KWARGC = (byte.arg >> 16) & 0xFFFF;
-                    pkpy::ArgList kwargs(0);
+                    pkpy::Args kwargs(0);
                     if(KWARGC > 0) kwargs = frame->pop_n_values_reversed(this, KWARGC*2);
-                    pkpy::ArgList args = frame->pop_n_values_reversed(this, ARGC);
+                    pkpy::Args args = frame->pop_n_values_reversed(this, ARGC);
                     PyVar callable = frame->pop_value(this);
                     PyVar ret = call(callable, std::move(args), kwargs, true);
                     if(ret == __py2py_call_signal) return ret;
@@ -397,7 +397,7 @@ public:
         return True;
     }
 
-    PyVar fast_call(const _Str& name, pkpy::ArgList&& args){
+    PyVar fast_call(const _Str& name, pkpy::Args&& args){
         PyObject* cls = args[0]->_type.get();
         while(cls != None.get()) {
             PyVar* val = cls->attribs.try_get(name);
@@ -413,13 +413,13 @@ public:
     }
 
     template<typename ArgT>
-    inline std::enable_if_t<std::is_same_v<std::remove_const_t<std::remove_reference_t<ArgT>>, pkpy::ArgList>, PyVar>
+    inline std::enable_if_t<std::is_same_v<std::remove_const_t<std::remove_reference_t<ArgT>>, pkpy::Args>, PyVar>
     call(const PyVar& _callable, ArgT&& args){
         return call(_callable, std::forward<ArgT>(args), pkpy::noArg(), false);
     }
 
     template<typename ArgT>
-    inline std::enable_if_t<std::is_same_v<std::remove_const_t<std::remove_reference_t<ArgT>>, pkpy::ArgList>, PyVar>
+    inline std::enable_if_t<std::is_same_v<std::remove_const_t<std::remove_reference_t<ArgT>>, pkpy::Args>, PyVar>
     call(const PyVar& obj, const _Str& func, ArgT&& args){
         return call(getattr(obj, func), std::forward<ArgT>(args), pkpy::noArg(), false);
     }
@@ -428,7 +428,7 @@ public:
         return call(getattr(obj, func), pkpy::noArg(), pkpy::noArg(), false);
     }
 
-    PyVar call(const PyVar& _callable, pkpy::ArgList args, const pkpy::ArgList& kwargs, bool opCall){
+    PyVar call(const PyVar& _callable, pkpy::Args args, const pkpy::Args& kwargs, bool opCall){
         if(_callable->is_type(_tp_type)){
             auto it = _callable->attribs.find(__new__);
             PyVar obj;
@@ -1056,7 +1056,7 @@ PyVar StringIterator::next(){
     return vm->PyStr(str.u8_getitem(index++));
 }
 
-PyVar _CppFunc::operator()(VM* vm, const pkpy::ArgList& args) const{
+PyVar _CppFunc::operator()(VM* vm, const pkpy::Args& args) const{
     int args_size = args.size() - (int)method;  // remove self
     if(argc != -1 && args_size != argc) {
         vm->typeError("expected " + std::to_string(argc) + " arguments, but got " + std::to_string(args_size));

Неке датотеке нису приказане због велике количине промена