|
|
@@ -4,12 +4,15 @@
|
|
|
#include "compiler.h"
|
|
|
#include "repl.h"
|
|
|
#include "iter.h"
|
|
|
+#include "cffi.h"
|
|
|
+
|
|
|
+namespace pkpy {
|
|
|
|
|
|
CodeObject_ VM::compile(Str source, Str filename, CompileMode mode) {
|
|
|
Compiler compiler(this, source.c_str(), filename, mode);
|
|
|
try{
|
|
|
return compiler.compile();
|
|
|
- }catch(pkpy::Exception& e){
|
|
|
+ }catch(Exception& e){
|
|
|
// std::cout << e.summary() << std::endl;
|
|
|
_error(e);
|
|
|
return nullptr;
|
|
|
@@ -17,7 +20,7 @@ CodeObject_ VM::compile(Str source, Str filename, CompileMode mode) {
|
|
|
}
|
|
|
|
|
|
#define BIND_NUM_ARITH_OPT(name, op) \
|
|
|
- _vm->_bind_methods<1>({"int","float"}, #name, [](VM* vm, pkpy::Args& args){ \
|
|
|
+ _vm->_bind_methods<1>({"int","float"}, #name, [](VM* vm, Args& args){ \
|
|
|
if(is_both_int(args[0], args[1])){ \
|
|
|
return vm->PyInt(vm->_PyInt_AS_C(args[0]) op vm->_PyInt_AS_C(args[1])); \
|
|
|
}else{ \
|
|
|
@@ -26,7 +29,7 @@ CodeObject_ VM::compile(Str source, Str filename, CompileMode mode) {
|
|
|
});
|
|
|
|
|
|
#define BIND_NUM_LOGICAL_OPT(name, op, is_eq) \
|
|
|
- _vm->_bind_methods<1>({"int","float"}, #name, [](VM* vm, pkpy::Args& args){ \
|
|
|
+ _vm->_bind_methods<1>({"int","float"}, #name, [](VM* vm, Args& args){ \
|
|
|
if(!is_both_int_or_float(args[0], args[1])){ \
|
|
|
if constexpr(is_eq) return vm->PyBool(args[0] op args[1]); \
|
|
|
vm->TypeError("unsupported operand type(s) for " #op ); \
|
|
|
@@ -52,40 +55,40 @@ void init_builtins(VM* _vm) {
|
|
|
#undef BIND_NUM_ARITH_OPT
|
|
|
#undef BIND_NUM_LOGICAL_OPT
|
|
|
|
|
|
- _vm->bind_builtin_func<1>("__sys_stdout_write", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->bind_builtin_func<1>("__sys_stdout_write", [](VM* vm, Args& args) {
|
|
|
(*vm->_stdout) << vm->PyStr_AS_C(args[0]);
|
|
|
return vm->None;
|
|
|
});
|
|
|
|
|
|
- // _vm->bind_builtin_func<1>("test", [](VM* vm, pkpy::Args& args) {
|
|
|
+ // _vm->bind_builtin_func<1>("test", [](VM* vm, Args& args) {
|
|
|
// args[0]->attr().print_stats();
|
|
|
// return vm->None;
|
|
|
// });
|
|
|
|
|
|
- _vm->bind_builtin_func<0>("super", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->bind_builtin_func<0>("super", [](VM* vm, Args& args) {
|
|
|
const PyVar* self = vm->top_frame()->f_locals().try_get(m_self);
|
|
|
if(self == nullptr) vm->TypeError("super() can only be called in a class");
|
|
|
return vm->new_object(vm->tp_super, *self);
|
|
|
});
|
|
|
|
|
|
- _vm->bind_builtin_func<1>("id", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->bind_builtin_func<1>("id", [](VM* vm, Args& args) {
|
|
|
const PyVar& obj = args[0];
|
|
|
if(obj.is_tagged()) return vm->PyInt((i64)0);
|
|
|
return vm->PyInt(obj.bits);
|
|
|
});
|
|
|
|
|
|
- _vm->bind_builtin_func<1>("eval", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->bind_builtin_func<1>("eval", [](VM* vm, Args& args) {
|
|
|
CodeObject_ 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->bind_builtin_func<1>("exec", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->bind_builtin_func<1>("exec", [](VM* vm, Args& args) {
|
|
|
CodeObject_ 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;
|
|
|
});
|
|
|
|
|
|
- _vm->bind_builtin_func<-1>("exit", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->bind_builtin_func<-1>("exit", [](VM* vm, Args& args) {
|
|
|
if(args.size() == 0) std::exit(0);
|
|
|
else if(args.size() == 1) std::exit((int)vm->PyInt_AS_C(args[0]));
|
|
|
else vm->TypeError("exit() takes at most 1 argument");
|
|
|
@@ -93,61 +96,61 @@ void init_builtins(VM* _vm) {
|
|
|
});
|
|
|
|
|
|
_vm->bind_builtin_func<1>("repr", CPP_LAMBDA(vm->asRepr(args[0])));
|
|
|
- _vm->bind_builtin_func<1>("len", CPP_LAMBDA(vm->call(args[0], __len__, pkpy::no_arg())));
|
|
|
+ _vm->bind_builtin_func<1>("len", CPP_LAMBDA(vm->call(args[0], __len__, no_arg())));
|
|
|
|
|
|
- _vm->bind_builtin_func<1>("hash", [](VM* vm, pkpy::Args& args){
|
|
|
+ _vm->bind_builtin_func<1>("hash", [](VM* vm, Args& args){
|
|
|
i64 value = vm->hash(args[0]);
|
|
|
if(((value << 2) >> 2) != value) value >>= 2;
|
|
|
return vm->PyInt(value);
|
|
|
});
|
|
|
|
|
|
- _vm->bind_builtin_func<1>("chr", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->bind_builtin_func<1>("chr", [](VM* vm, 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->bind_builtin_func<1>("ord", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->bind_builtin_func<1>("ord", [](VM* vm, 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->bind_builtin_func<2>("hasattr", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->bind_builtin_func<2>("hasattr", [](VM* vm, Args& args) {
|
|
|
return vm->PyBool(vm->getattr(args[0], vm->PyStr_AS_C(args[1]), false) != nullptr);
|
|
|
});
|
|
|
|
|
|
- _vm->bind_builtin_func<3>("setattr", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->bind_builtin_func<3>("setattr", [](VM* vm, Args& args) {
|
|
|
vm->setattr(args[0], vm->PyStr_AS_C(args[1]), args[2]);
|
|
|
return vm->None;
|
|
|
});
|
|
|
|
|
|
- _vm->bind_builtin_func<2>("getattr", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->bind_builtin_func<2>("getattr", [](VM* vm, Args& args) {
|
|
|
Str name = vm->PyStr_AS_C(args[1]);
|
|
|
return vm->getattr(args[0], name);
|
|
|
});
|
|
|
|
|
|
- _vm->bind_builtin_func<1>("hex", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->bind_builtin_func<1>("hex", [](VM* vm, Args& args) {
|
|
|
std::stringstream ss;
|
|
|
ss << std::hex << vm->PyInt_AS_C(args[0]);
|
|
|
return vm->PyStr("0x" + ss.str());
|
|
|
});
|
|
|
|
|
|
- _vm->bind_builtin_func<1>("dir", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->bind_builtin_func<1>("dir", [](VM* vm, Args& args) {
|
|
|
std::set<StrName> names;
|
|
|
if(args[0]->is_attr_valid()){
|
|
|
std::vector<StrName> keys = args[0]->attr().keys();
|
|
|
names.insert(keys.begin(), keys.end());
|
|
|
}
|
|
|
- const pkpy::NameDict& t_attr = vm->_t(args[0])->attr();
|
|
|
+ const NameDict& t_attr = vm->_t(args[0])->attr();
|
|
|
std::vector<StrName> keys = t_attr.keys();
|
|
|
names.insert(keys.begin(), keys.end());
|
|
|
- pkpy::List ret;
|
|
|
+ List ret;
|
|
|
for (StrName name : names) ret.push_back(vm->PyStr(name.str()));
|
|
|
return vm->PyList(std::move(ret));
|
|
|
});
|
|
|
|
|
|
- _vm->bind_method<0>("object", "__repr__", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->bind_method<0>("object", "__repr__", [](VM* vm, Args& args) {
|
|
|
PyVar self = args[0];
|
|
|
std::uintptr_t addr = self.is_tagged() ? 0 : (uintptr_t)self.get();
|
|
|
StrStream ss;
|
|
|
@@ -161,8 +164,8 @@ void init_builtins(VM* _vm) {
|
|
|
|
|
|
_vm->bind_static_method<1>("type", "__new__", CPP_LAMBDA(vm->_t(args[0])));
|
|
|
|
|
|
- _vm->bind_static_method<-1>("range", "__new__", [](VM* vm, pkpy::Args& args) {
|
|
|
- pkpy::Range r;
|
|
|
+ _vm->bind_static_method<-1>("range", "__new__", [](VM* vm, Args& args) {
|
|
|
+ Range r;
|
|
|
switch (args.size()) {
|
|
|
case 1: r.stop = vm->PyInt_AS_C(args[0]); break;
|
|
|
case 2: r.start = vm->PyInt_AS_C(args[0]); r.stop = vm->PyInt_AS_C(args[1]); break;
|
|
|
@@ -179,13 +182,13 @@ void init_builtins(VM* _vm) {
|
|
|
_vm->bind_method<0>("NoneType", "__repr__", CPP_LAMBDA(vm->PyStr("None")));
|
|
|
_vm->bind_method<0>("NoneType", "__json__", CPP_LAMBDA(vm->PyStr("null")));
|
|
|
|
|
|
- _vm->_bind_methods<1>({"int", "float"}, "__truediv__", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->_bind_methods<1>({"int", "float"}, "__truediv__", [](VM* vm, 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->_bind_methods<1>({"int", "float"}, "__pow__", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->_bind_methods<1>({"int", "float"}, "__pow__", [](VM* vm, Args& args) {
|
|
|
if(is_both_int(args[0], args[1])){
|
|
|
i64 lhs = vm->_PyInt_AS_C(args[0]);
|
|
|
i64 rhs = vm->_PyInt_AS_C(args[1]);
|
|
|
@@ -205,7 +208,7 @@ void init_builtins(VM* _vm) {
|
|
|
});
|
|
|
|
|
|
/************ PyInt ************/
|
|
|
- _vm->bind_static_method<1>("int", "__new__", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->bind_static_method<1>("int", "__new__", [](VM* vm, Args& args) {
|
|
|
if (is_type(args[0], vm->tp_int)) return args[0];
|
|
|
if (is_type(args[0], vm->tp_float)) return vm->PyInt((i64)vm->PyFloat_AS_C(args[0]));
|
|
|
if (is_type(args[0], vm->tp_bool)) return vm->PyInt(vm->_PyBool_AS_C(args[0]) ? 1 : 0);
|
|
|
@@ -224,13 +227,13 @@ void init_builtins(VM* _vm) {
|
|
|
return vm->None;
|
|
|
});
|
|
|
|
|
|
- _vm->bind_method<1>("int", "__floordiv__", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->bind_method<1>("int", "__floordiv__", [](VM* vm, 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->bind_method<1>("int", "__mod__", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->bind_method<1>("int", "__mod__", [](VM* vm, 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);
|
|
|
@@ -251,10 +254,10 @@ void init_builtins(VM* _vm) {
|
|
|
#undef INT_BITWISE_OP
|
|
|
|
|
|
/************ PyFloat ************/
|
|
|
- _vm->bind_static_method<1>("float", "__new__", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->bind_static_method<1>("float", "__new__", [](VM* vm, Args& args) {
|
|
|
if (is_type(args[0], vm->tp_int)) return vm->PyFloat((f64)vm->PyInt_AS_C(args[0]));
|
|
|
if (is_type(args[0], vm->tp_float)) return args[0];
|
|
|
- if (is_type(args[0], vm->tp_bool)) return vm->PyFloat(vm->PyBool_AS_C(args[0]) ? 1.0 : 0.0);
|
|
|
+ if (is_type(args[0], vm->tp_bool)) return vm->PyFloat(vm->_PyBool_AS_C(args[0]) ? 1.0 : 0.0);
|
|
|
if (is_type(args[0], vm->tp_str)) {
|
|
|
const Str& s = vm->PyStr_AS_C(args[0]);
|
|
|
if(s == "inf") return vm->PyFloat(INFINITY);
|
|
|
@@ -270,7 +273,7 @@ void init_builtins(VM* _vm) {
|
|
|
return vm->None;
|
|
|
});
|
|
|
|
|
|
- _vm->bind_method<0>("float", "__repr__", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->bind_method<0>("float", "__repr__", [](VM* vm, 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;
|
|
|
@@ -280,7 +283,7 @@ void init_builtins(VM* _vm) {
|
|
|
return vm->PyStr(s);
|
|
|
});
|
|
|
|
|
|
- _vm->bind_method<0>("float", "__json__", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->bind_method<0>("float", "__json__", [](VM* vm, 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));
|
|
|
@@ -289,18 +292,18 @@ void init_builtins(VM* _vm) {
|
|
|
/************ PyString ************/
|
|
|
_vm->bind_static_method<1>("str", "__new__", CPP_LAMBDA(vm->asStr(args[0])));
|
|
|
|
|
|
- _vm->bind_method<1>("str", "__add__", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->bind_method<1>("str", "__add__", [](VM* vm, 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->bind_method<0>("str", "__len__", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->bind_method<0>("str", "__len__", [](VM* vm, Args& args) {
|
|
|
const Str& self = vm->PyStr_AS_C(args[0]);
|
|
|
return vm->PyInt(self.u8_length());
|
|
|
});
|
|
|
|
|
|
- _vm->bind_method<1>("str", "__contains__", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->bind_method<1>("str", "__contains__", [](VM* vm, 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);
|
|
|
@@ -309,33 +312,33 @@ void init_builtins(VM* _vm) {
|
|
|
_vm->bind_method<0>("str", "__str__", CPP_LAMBDA(args[0]));
|
|
|
_vm->bind_method<0>("str", "__iter__", CPP_LAMBDA(vm->PyIter(StringIter(vm, args[0]))));
|
|
|
|
|
|
- _vm->bind_method<0>("str", "__repr__", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->bind_method<0>("str", "__repr__", [](VM* vm, Args& args) {
|
|
|
const Str& _self = vm->PyStr_AS_C(args[0]);
|
|
|
return vm->PyStr(_self.escape(true));
|
|
|
});
|
|
|
|
|
|
- _vm->bind_method<0>("str", "__json__", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->bind_method<0>("str", "__json__", [](VM* vm, Args& args) {
|
|
|
const Str& _self = vm->PyStr_AS_C(args[0]);
|
|
|
return vm->PyStr(_self.escape(false));
|
|
|
});
|
|
|
|
|
|
- _vm->bind_method<1>("str", "__eq__", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->bind_method<1>("str", "__eq__", [](VM* vm, Args& args) {
|
|
|
if(is_type(args[0], vm->tp_str) && is_type(args[1], 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->bind_method<1>("str", "__ne__", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->bind_method<1>("str", "__ne__", [](VM* vm, Args& args) {
|
|
|
if(is_type(args[0], vm->tp_str) && is_type(args[1], 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->bind_method<1>("str", "__getitem__", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->bind_method<1>("str", "__getitem__", [](VM* vm, Args& args) {
|
|
|
const Str& self (vm->PyStr_AS_C(args[0]));
|
|
|
|
|
|
if(is_type(args[1], vm->tp_slice)){
|
|
|
- pkpy::Slice s = vm->PySlice_AS_C(args[1]);
|
|
|
+ Slice s = vm->PySlice_AS_C(args[1]);
|
|
|
s.normalize(self.u8_length());
|
|
|
return vm->PyStr(self.u8_substr(s.start, s.stop));
|
|
|
}
|
|
|
@@ -345,19 +348,19 @@ void init_builtins(VM* _vm) {
|
|
|
return vm->PyStr(self.u8_getitem(index));
|
|
|
});
|
|
|
|
|
|
- _vm->bind_method<1>("str", "__gt__", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->bind_method<1>("str", "__gt__", [](VM* vm, 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->bind_method<1>("str", "__lt__", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->bind_method<1>("str", "__lt__", [](VM* vm, 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->bind_method<2>("str", "replace", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->bind_method<2>("str", "replace", [](VM* vm, 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]);
|
|
|
@@ -371,23 +374,23 @@ void init_builtins(VM* _vm) {
|
|
|
return vm->PyStr(_copy);
|
|
|
});
|
|
|
|
|
|
- _vm->bind_method<1>("str", "startswith", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->bind_method<1>("str", "startswith", [](VM* vm, 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->bind_method<1>("str", "endswith", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->bind_method<1>("str", "endswith", [](VM* vm, 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->bind_method<1>("str", "join", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->bind_method<1>("str", "join", [](VM* vm, Args& args) {
|
|
|
const Str& self = vm->PyStr_AS_C(args[0]);
|
|
|
StrStream ss;
|
|
|
PyVar obj = vm->asList(args[1]);
|
|
|
- const pkpy::List& list = vm->PyList_AS_C(obj);
|
|
|
+ const List& list = vm->PyList_AS_C(obj);
|
|
|
for (int i = 0; i < list.size(); ++i) {
|
|
|
if (i > 0) ss << self;
|
|
|
ss << vm->PyStr_AS_C(list[i]);
|
|
|
@@ -396,29 +399,29 @@ void init_builtins(VM* _vm) {
|
|
|
});
|
|
|
|
|
|
/************ PyList ************/
|
|
|
- _vm->bind_method<1>("list", "append", [](VM* vm, pkpy::Args& args) {
|
|
|
- pkpy::List& self = vm->PyList_AS_C(args[0]);
|
|
|
+ _vm->bind_method<1>("list", "append", [](VM* vm, Args& args) {
|
|
|
+ List& self = vm->PyList_AS_C(args[0]);
|
|
|
self.push_back(args[1]);
|
|
|
return vm->None;
|
|
|
});
|
|
|
|
|
|
- _vm->bind_method<0>("list", "reverse", [](VM* vm, pkpy::Args& args) {
|
|
|
- pkpy::List& self = vm->PyList_AS_C(args[0]);
|
|
|
+ _vm->bind_method<0>("list", "reverse", [](VM* vm, Args& args) {
|
|
|
+ List& self = vm->PyList_AS_C(args[0]);
|
|
|
std::reverse(self.begin(), self.end());
|
|
|
return vm->None;
|
|
|
});
|
|
|
|
|
|
- _vm->bind_method<1>("list", "__mul__", [](VM* vm, pkpy::Args& args) {
|
|
|
- const pkpy::List& self = vm->PyList_AS_C(args[0]);
|
|
|
+ _vm->bind_method<1>("list", "__mul__", [](VM* vm, Args& args) {
|
|
|
+ const List& self = vm->PyList_AS_C(args[0]);
|
|
|
int n = (int)vm->PyInt_AS_C(args[1]);
|
|
|
- pkpy::List result;
|
|
|
+ List result;
|
|
|
result.reserve(self.size() * n);
|
|
|
for(int i = 0; i < n; i++) result.insert(result.end(), self.begin(), self.end());
|
|
|
return vm->PyList(std::move(result));
|
|
|
});
|
|
|
|
|
|
- _vm->bind_method<2>("list", "insert", [](VM* vm, pkpy::Args& args) {
|
|
|
- pkpy::List& _self = vm->PyList_AS_C(args[0]);
|
|
|
+ _vm->bind_method<2>("list", "insert", [](VM* vm, Args& args) {
|
|
|
+ List& _self = vm->PyList_AS_C(args[0]);
|
|
|
int index = (int)vm->PyInt_AS_C(args[1]);
|
|
|
if(index < 0) index += _self.size();
|
|
|
if(index < 0) index = 0;
|
|
|
@@ -427,37 +430,37 @@ void init_builtins(VM* _vm) {
|
|
|
return vm->None;
|
|
|
});
|
|
|
|
|
|
- _vm->bind_method<0>("list", "clear", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->bind_method<0>("list", "clear", [](VM* vm, Args& args) {
|
|
|
vm->PyList_AS_C(args[0]).clear();
|
|
|
return vm->None;
|
|
|
});
|
|
|
|
|
|
_vm->bind_method<0>("list", "copy", CPP_LAMBDA(vm->PyList(vm->PyList_AS_C(args[0]))));
|
|
|
|
|
|
- _vm->bind_method<1>("list", "__add__", [](VM* vm, pkpy::Args& args) {
|
|
|
- const pkpy::List& self = vm->PyList_AS_C(args[0]);
|
|
|
- const pkpy::List& obj = vm->PyList_AS_C(args[1]);
|
|
|
- pkpy::List new_list = self;
|
|
|
+ _vm->bind_method<1>("list", "__add__", [](VM* vm, Args& args) {
|
|
|
+ const List& self = vm->PyList_AS_C(args[0]);
|
|
|
+ const List& obj = vm->PyList_AS_C(args[1]);
|
|
|
+ List new_list = self;
|
|
|
new_list.insert(new_list.end(), obj.begin(), obj.end());
|
|
|
return vm->PyList(new_list);
|
|
|
});
|
|
|
|
|
|
- _vm->bind_method<0>("list", "__len__", [](VM* vm, pkpy::Args& args) {
|
|
|
- const pkpy::List& self = vm->PyList_AS_C(args[0]);
|
|
|
+ _vm->bind_method<0>("list", "__len__", [](VM* vm, Args& args) {
|
|
|
+ const List& self = vm->PyList_AS_C(args[0]);
|
|
|
return vm->PyInt(self.size());
|
|
|
});
|
|
|
|
|
|
- _vm->bind_method<0>("list", "__iter__", [](VM* vm, pkpy::Args& args) {
|
|
|
- return vm->PyIter(ArrayIter<pkpy::List>(vm, args[0]));
|
|
|
+ _vm->bind_method<0>("list", "__iter__", [](VM* vm, Args& args) {
|
|
|
+ return vm->PyIter(ArrayIter<List>(vm, args[0]));
|
|
|
});
|
|
|
|
|
|
- _vm->bind_method<1>("list", "__getitem__", [](VM* vm, pkpy::Args& args) {
|
|
|
- const pkpy::List& self = vm->PyList_AS_C(args[0]);
|
|
|
+ _vm->bind_method<1>("list", "__getitem__", [](VM* vm, Args& args) {
|
|
|
+ const List& self = vm->PyList_AS_C(args[0]);
|
|
|
|
|
|
if(is_type(args[1], vm->tp_slice)){
|
|
|
- pkpy::Slice s = vm->PySlice_AS_C(args[1]);
|
|
|
+ Slice s = vm->PySlice_AS_C(args[1]);
|
|
|
s.normalize(self.size());
|
|
|
- pkpy::List new_list;
|
|
|
+ List new_list;
|
|
|
for(size_t i = s.start; i < s.stop; i++) new_list.push_back(self[i]);
|
|
|
return vm->PyList(std::move(new_list));
|
|
|
}
|
|
|
@@ -467,16 +470,16 @@ void init_builtins(VM* _vm) {
|
|
|
return self[index];
|
|
|
});
|
|
|
|
|
|
- _vm->bind_method<2>("list", "__setitem__", [](VM* vm, pkpy::Args& args) {
|
|
|
- pkpy::List& self = vm->PyList_AS_C(args[0]);
|
|
|
+ _vm->bind_method<2>("list", "__setitem__", [](VM* vm, Args& args) {
|
|
|
+ List& self = vm->PyList_AS_C(args[0]);
|
|
|
int index = (int)vm->PyInt_AS_C(args[1]);
|
|
|
index = vm->normalized_index(index, self.size());
|
|
|
self[index] = args[2];
|
|
|
return vm->None;
|
|
|
});
|
|
|
|
|
|
- _vm->bind_method<1>("list", "__delitem__", [](VM* vm, pkpy::Args& args) {
|
|
|
- pkpy::List& self = vm->PyList_AS_C(args[0]);
|
|
|
+ _vm->bind_method<1>("list", "__delitem__", [](VM* vm, Args& args) {
|
|
|
+ List& self = vm->PyList_AS_C(args[0]);
|
|
|
int index = (int)vm->PyInt_AS_C(args[1]);
|
|
|
index = vm->normalized_index(index, self.size());
|
|
|
self.erase(self.begin() + index);
|
|
|
@@ -484,22 +487,22 @@ void init_builtins(VM* _vm) {
|
|
|
});
|
|
|
|
|
|
/************ PyTuple ************/
|
|
|
- _vm->bind_static_method<1>("tuple", "__new__", [](VM* vm, pkpy::Args& args) {
|
|
|
- pkpy::List list = vm->PyList_AS_C(vm->asList(args[0]));
|
|
|
+ _vm->bind_static_method<1>("tuple", "__new__", [](VM* vm, Args& args) {
|
|
|
+ List list = vm->PyList_AS_C(vm->asList(args[0]));
|
|
|
return vm->PyTuple(std::move(list));
|
|
|
});
|
|
|
|
|
|
- _vm->bind_method<0>("tuple", "__iter__", [](VM* vm, pkpy::Args& args) {
|
|
|
- return vm->PyIter(ArrayIter<pkpy::Args>(vm, args[0]));
|
|
|
+ _vm->bind_method<0>("tuple", "__iter__", [](VM* vm, Args& args) {
|
|
|
+ return vm->PyIter(ArrayIter<Args>(vm, args[0]));
|
|
|
});
|
|
|
|
|
|
- _vm->bind_method<1>("tuple", "__getitem__", [](VM* vm, pkpy::Args& args) {
|
|
|
- const pkpy::Tuple& self = vm->PyTuple_AS_C(args[0]);
|
|
|
+ _vm->bind_method<1>("tuple", "__getitem__", [](VM* vm, Args& args) {
|
|
|
+ const Tuple& self = vm->PyTuple_AS_C(args[0]);
|
|
|
|
|
|
if(is_type(args[1], vm->tp_slice)){
|
|
|
- pkpy::Slice s = vm->PySlice_AS_C(args[1]);
|
|
|
+ Slice s = vm->PySlice_AS_C(args[1]);
|
|
|
s.normalize(self.size());
|
|
|
- pkpy::List new_list;
|
|
|
+ List new_list;
|
|
|
for(size_t i = s.start; i < s.stop; i++) new_list.push_back(self[i]);
|
|
|
return vm->PyTuple(std::move(new_list));
|
|
|
}
|
|
|
@@ -509,25 +512,25 @@ void init_builtins(VM* _vm) {
|
|
|
return self[index];
|
|
|
});
|
|
|
|
|
|
- _vm->bind_method<0>("tuple", "__len__", [](VM* vm, pkpy::Args& args) {
|
|
|
- const pkpy::Tuple& self = vm->PyTuple_AS_C(args[0]);
|
|
|
+ _vm->bind_method<0>("tuple", "__len__", [](VM* vm, Args& args) {
|
|
|
+ const Tuple& self = vm->PyTuple_AS_C(args[0]);
|
|
|
return vm->PyInt(self.size());
|
|
|
});
|
|
|
|
|
|
/************ PyBool ************/
|
|
|
_vm->bind_static_method<1>("bool", "__new__", CPP_LAMBDA(vm->asBool(args[0])));
|
|
|
|
|
|
- _vm->bind_method<0>("bool", "__repr__", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->bind_method<0>("bool", "__repr__", [](VM* vm, Args& args) {
|
|
|
bool val = vm->PyBool_AS_C(args[0]);
|
|
|
return vm->PyStr(val ? "True" : "False");
|
|
|
});
|
|
|
|
|
|
- _vm->bind_method<0>("bool", "__json__", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->bind_method<0>("bool", "__json__", [](VM* vm, Args& args) {
|
|
|
bool val = vm->PyBool_AS_C(args[0]);
|
|
|
return vm->PyStr(val ? "true" : "false");
|
|
|
});
|
|
|
|
|
|
- _vm->bind_method<1>("bool", "__xor__", [](VM* vm, pkpy::Args& args) {
|
|
|
+ _vm->bind_method<1>("bool", "__xor__", [](VM* vm, Args& args) {
|
|
|
bool self = vm->PyBool_AS_C(args[0]);
|
|
|
bool other = vm->PyBool_AS_C(args[1]);
|
|
|
return vm->PyBool(self ^ other);
|
|
|
@@ -552,7 +555,7 @@ void init_builtins(VM* _vm) {
|
|
|
|
|
|
void add_module_time(VM* vm){
|
|
|
PyVar mod = vm->new_module("time");
|
|
|
- vm->bind_func<0>(mod, "time", [](VM* vm, pkpy::Args& args) {
|
|
|
+ vm->bind_func<0>(mod, "time", [](VM* vm, 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);
|
|
|
});
|
|
|
@@ -565,7 +568,7 @@ void add_module_sys(VM* vm){
|
|
|
vm->bind_func<1>(mod, "getrefcount", CPP_LAMBDA(vm->PyInt(args[0].use_count())));
|
|
|
vm->bind_func<0>(mod, "getrecursionlimit", CPP_LAMBDA(vm->PyInt(vm->recursionlimit)));
|
|
|
|
|
|
- vm->bind_func<1>(mod, "setrecursionlimit", [](VM* vm, pkpy::Args& args) {
|
|
|
+ vm->bind_func<1>(mod, "setrecursionlimit", [](VM* vm, Args& args) {
|
|
|
vm->recursionlimit = (int)vm->PyInt_AS_C(args[0]);
|
|
|
return vm->None;
|
|
|
});
|
|
|
@@ -573,7 +576,7 @@ void add_module_sys(VM* vm){
|
|
|
|
|
|
void add_module_json(VM* vm){
|
|
|
PyVar mod = vm->new_module("json");
|
|
|
- vm->bind_func<1>(mod, "loads", [](VM* vm, pkpy::Args& args) {
|
|
|
+ vm->bind_func<1>(mod, "loads", [](VM* vm, Args& args) {
|
|
|
const Str& expr = vm->PyStr_AS_C(args[0]);
|
|
|
CodeObject_ code = vm->compile(expr, "<json>", JSON_MODE);
|
|
|
return vm->_exec(code, vm->top_frame()->_module, vm->top_frame()->_locals);
|
|
|
@@ -603,7 +606,7 @@ void add_module_math(VM* vm){
|
|
|
|
|
|
void add_module_dis(VM* vm){
|
|
|
PyVar mod = vm->new_module("dis");
|
|
|
- vm->bind_func<1>(mod, "dis", [](VM* vm, pkpy::Args& args) {
|
|
|
+ vm->bind_func<1>(mod, "dis", [](VM* vm, Args& args) {
|
|
|
PyVar f = args[0];
|
|
|
if(is_type(f, vm->tp_bound_method)) f = vm->PyBoundMethod_AS_C(args[0]).method;
|
|
|
CodeObject_ code = vm->PyFunction_AS_C(f).code;
|
|
|
@@ -632,32 +635,32 @@ struct FileIO {
|
|
|
}
|
|
|
|
|
|
static void _register(VM* vm, PyVar mod, PyVar type){
|
|
|
- vm->bind_static_method<2>(type, "__new__", [](VM* vm, pkpy::Args& args){
|
|
|
+ vm->bind_static_method<2>(type, "__new__", [](VM* vm, Args& args){
|
|
|
return vm->new_object<FileIO>(
|
|
|
vm, vm->PyStr_AS_C(args[0]), vm->PyStr_AS_C(args[1])
|
|
|
);
|
|
|
});
|
|
|
|
|
|
- vm->bind_method<0>(type, "read", [](VM* vm, pkpy::Args& args){
|
|
|
+ vm->bind_method<0>(type, "read", [](VM* vm, Args& args){
|
|
|
FileIO& io = vm->py_cast<FileIO>(args[0]);
|
|
|
std::string buffer;
|
|
|
io._fs >> buffer;
|
|
|
return vm->PyStr(buffer);
|
|
|
});
|
|
|
|
|
|
- vm->bind_method<1>(type, "write", [](VM* vm, pkpy::Args& args){
|
|
|
+ vm->bind_method<1>(type, "write", [](VM* vm, Args& args){
|
|
|
FileIO& io = vm->py_cast<FileIO>(args[0]);
|
|
|
io._fs << vm->PyStr_AS_C(args[1]);
|
|
|
return vm->None;
|
|
|
});
|
|
|
|
|
|
- vm->bind_method<0>(type, "close", [](VM* vm, pkpy::Args& args){
|
|
|
+ vm->bind_method<0>(type, "close", [](VM* vm, Args& args){
|
|
|
FileIO& io = vm->py_cast<FileIO>(args[0]);
|
|
|
io._fs.close();
|
|
|
return vm->None;
|
|
|
});
|
|
|
|
|
|
- vm->bind_method<0>(type, "__exit__", [](VM* vm, pkpy::Args& args){
|
|
|
+ vm->bind_method<0>(type, "__exit__", [](VM* vm, Args& args){
|
|
|
FileIO& io = vm->py_cast<FileIO>(args[0]);
|
|
|
io._fs.close();
|
|
|
return vm->None;
|
|
|
@@ -669,7 +672,7 @@ struct FileIO {
|
|
|
void add_module_io(VM* vm){
|
|
|
PyVar mod = vm->new_module("io");
|
|
|
PyVar type = vm->register_class<FileIO>(mod);
|
|
|
- vm->bind_builtin_func<2>("open", [type](VM* vm, const pkpy::Args& args){
|
|
|
+ vm->bind_builtin_func<2>("open", [type](VM* vm, const Args& args){
|
|
|
return vm->call(type, args);
|
|
|
});
|
|
|
}
|
|
|
@@ -689,12 +692,12 @@ struct ReMatch {
|
|
|
vm->bind_method<0>(type, "start", CPP_LAMBDA(vm->PyInt(vm->py_cast<ReMatch>(args[0]).start)));
|
|
|
vm->bind_method<0>(type, "end", CPP_LAMBDA(vm->PyInt(vm->py_cast<ReMatch>(args[0]).end)));
|
|
|
|
|
|
- vm->bind_method<0>(type, "span", [](VM* vm, pkpy::Args& args) {
|
|
|
+ vm->bind_method<0>(type, "span", [](VM* vm, Args& args) {
|
|
|
auto& self = vm->py_cast<ReMatch>(args[0]);
|
|
|
return vm->PyTuple({ vm->PyInt(self.start), vm->PyInt(self.end) });
|
|
|
});
|
|
|
|
|
|
- vm->bind_method<1>(type, "group", [](VM* vm, pkpy::Args& args) {
|
|
|
+ vm->bind_method<1>(type, "group", [](VM* vm, Args& args) {
|
|
|
auto& self = vm->py_cast<ReMatch>(args[0]);
|
|
|
int index = (int)vm->PyInt_AS_C(args[1]);
|
|
|
index = vm->normalized_index(index, self.m.size());
|
|
|
@@ -719,19 +722,19 @@ void add_module_re(VM* vm){
|
|
|
PyVar mod = vm->new_module("re");
|
|
|
vm->register_class<ReMatch>(mod);
|
|
|
|
|
|
- vm->bind_func<2>(mod, "match", [](VM* vm, pkpy::Args& args) {
|
|
|
+ vm->bind_func<2>(mod, "match", [](VM* vm, 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->bind_func<2>(mod, "search", [](VM* vm, pkpy::Args& args) {
|
|
|
+ vm->bind_func<2>(mod, "search", [](VM* vm, 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->bind_func<3>(mod, "sub", [](VM* vm, pkpy::Args& args) {
|
|
|
+ vm->bind_func<3>(mod, "sub", [](VM* vm, 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]);
|
|
|
@@ -739,13 +742,13 @@ void add_module_re(VM* vm){
|
|
|
return vm->PyStr(std::regex_replace(string, re, repl));
|
|
|
});
|
|
|
|
|
|
- vm->bind_func<2>(mod, "split", [](VM* vm, pkpy::Args& args) {
|
|
|
+ vm->bind_func<2>(mod, "split", [](VM* vm, Args& args) {
|
|
|
const Str& pattern = vm->PyStr_AS_C(args[0]);
|
|
|
const Str& string = vm->PyStr_AS_C(args[1]);
|
|
|
std::regex re(pattern);
|
|
|
std::sregex_token_iterator it(string.begin(), string.end(), re, -1);
|
|
|
std::sregex_token_iterator end;
|
|
|
- pkpy::List vec;
|
|
|
+ List vec;
|
|
|
for(; it != end; ++it){
|
|
|
vec.push_back(vm->PyStr(it->str()));
|
|
|
}
|
|
|
@@ -756,20 +759,20 @@ void add_module_re(VM* vm){
|
|
|
void add_module_random(VM* vm){
|
|
|
PyVar mod = vm->new_module("random");
|
|
|
std::srand(std::time(0));
|
|
|
- vm->bind_func<1>(mod, "seed", [](VM* vm, pkpy::Args& args) {
|
|
|
+ vm->bind_func<1>(mod, "seed", [](VM* vm, Args& args) {
|
|
|
std::srand((unsigned int)vm->PyInt_AS_C(args[0]));
|
|
|
return vm->None;
|
|
|
});
|
|
|
|
|
|
vm->bind_func<0>(mod, "random", CPP_LAMBDA(vm->PyFloat(std::rand() / (f64)RAND_MAX)));
|
|
|
- vm->bind_func<2>(mod, "randint", [](VM* vm, pkpy::Args& args) {
|
|
|
+ vm->bind_func<2>(mod, "randint", [](VM* vm, Args& args) {
|
|
|
i64 a = vm->PyInt_AS_C(args[0]);
|
|
|
i64 b = vm->PyInt_AS_C(args[1]);
|
|
|
if(a > b) std::swap(a, b);
|
|
|
return vm->PyInt(a + std::rand() % (b - a + 1));
|
|
|
});
|
|
|
|
|
|
- vm->bind_func<2>(mod, "uniform", [](VM* vm, pkpy::Args& args) {
|
|
|
+ vm->bind_func<2>(mod, "uniform", [](VM* vm, Args& args) {
|
|
|
f64 a = vm->PyFloat_AS_C(args[0]);
|
|
|
f64 b = vm->PyFloat_AS_C(args[1]);
|
|
|
if(a > b) std::swap(a, b);
|
|
|
@@ -786,8 +789,6 @@ void add_module_functools(VM* vm){
|
|
|
vm->_exec(code, mod);
|
|
|
}
|
|
|
|
|
|
-#include "cffi.h"
|
|
|
-
|
|
|
void VM::post_init(){
|
|
|
init_builtins(this);
|
|
|
add_module_sys(this);
|
|
|
@@ -806,17 +807,15 @@ void VM::post_init(){
|
|
|
this->_exec(code, this->builtins);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-class _PkExported{
|
|
|
+class PkExportedBase{
|
|
|
public:
|
|
|
- virtual ~_PkExported() = default;
|
|
|
+ virtual ~PkExportedBase() = default;
|
|
|
virtual void* get() = 0;
|
|
|
};
|
|
|
|
|
|
-static std::vector<_PkExported*> _pk_lookup_table;
|
|
|
-
|
|
|
+static std::vector<PkExportedBase*> _pk_lookup_table;
|
|
|
template<typename T>
|
|
|
-class PkExported : public _PkExported{
|
|
|
+class PkExported : public PkExportedBase{
|
|
|
T* _ptr;
|
|
|
public:
|
|
|
template<typename... Args>
|
|
|
@@ -832,7 +831,6 @@ public:
|
|
|
|
|
|
#define PKPY_ALLOCATE(T, ...) *(new PkExported<T>(__VA_ARGS__))
|
|
|
|
|
|
-
|
|
|
extern "C" {
|
|
|
__EXPORT
|
|
|
/// Delete a pointer allocated by `pkpy_xxx_xxx`.
|
|
|
@@ -947,12 +945,12 @@ extern "C" {
|
|
|
|
|
|
__EXPORT
|
|
|
/// Setup the callback functions.
|
|
|
- void pkpy_setup_callbacks(f_int_t f_int, f_float_t f_float, f_bool_t f_bool, f_str_t f_str, f_None_t f_None){
|
|
|
- ::f_int = f_int;
|
|
|
- ::f_float = f_float;
|
|
|
- ::f_bool = f_bool;
|
|
|
- ::f_str = f_str;
|
|
|
- ::f_None = f_None;
|
|
|
+ void pkpy_setup_callbacks(f_int_t _f_int, f_float_t _f_float, f_bool_t _f_bool, f_str_t _f_str, f_None_t _f_None){
|
|
|
+ f_int = _f_int;
|
|
|
+ f_float = _f_float;
|
|
|
+ f_bool = _f_bool;
|
|
|
+ f_str = _f_str;
|
|
|
+ f_None = _f_None;
|
|
|
}
|
|
|
|
|
|
__EXPORT
|
|
|
@@ -964,7 +962,7 @@ extern "C" {
|
|
|
for(int i=0; name[i]; i++) if(name[i] == ' ') return nullptr;
|
|
|
std::string f_header = std::string(mod) + '.' + name + '#' + std::to_string(kGlobalBindId++);
|
|
|
PyVar obj = vm->_modules.contains(mod) ? vm->_modules[mod] : vm->new_module(mod);
|
|
|
- vm->bind_func<-1>(obj, name, [ret_code, f_header](VM* vm, const pkpy::Args& args){
|
|
|
+ vm->bind_func<-1>(obj, name, [ret_code, f_header](VM* vm, const Args& args){
|
|
|
StrStream ss;
|
|
|
ss << f_header;
|
|
|
for(int i=0; i<args.size(); i++){
|
|
|
@@ -990,4 +988,6 @@ extern "C" {
|
|
|
});
|
|
|
return strdup(f_header.c_str());
|
|
|
}
|
|
|
-}
|
|
|
+}
|
|
|
+
|
|
|
+} // namespace pkpy
|