pass by value

This commit is contained in:
blueloveTH 2022-12-08 12:47:31 +08:00
parent bfcec88871
commit 88e1a56150
4 changed files with 11 additions and 9 deletions

View File

@ -4,6 +4,11 @@ const char* __BUILTINS_CODE = R"(
def len(x): def len(x):
return x.__len__() 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)]) str.__mul__ = lambda self, n: ''.join([self for _ in range(n)])
def __str4split(self, sep): def __str4split(self, sep):

View File

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

View File

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

View File

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