mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-21 20:10:17 +00:00
...
This commit is contained in:
parent
0581fb50a7
commit
974cfebbb6
@ -1019,16 +1019,16 @@ inline void init_builtins(VM* _vm) {
|
|||||||
inline void add_module_time(VM* vm){
|
inline void add_module_time(VM* vm){
|
||||||
PyObject* mod = vm->new_module("time");
|
PyObject* mod = vm->new_module("time");
|
||||||
vm->bind_func<0>(mod, "time", [](VM* vm, ArgsView args) {
|
vm->bind_func<0>(mod, "time", [](VM* vm, ArgsView args) {
|
||||||
auto now = std::chrono::high_resolution_clock::now();
|
auto now = std::chrono::system_clock::now();
|
||||||
return VAR(std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count() / 1000000.0);
|
return VAR(std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count() / 1000.0);
|
||||||
});
|
});
|
||||||
|
|
||||||
vm->bind_func<1>(mod, "sleep", [](VM* vm, ArgsView args) {
|
vm->bind_func<1>(mod, "sleep", [](VM* vm, ArgsView args) {
|
||||||
f64 seconds = CAST_F(args[0]);
|
f64 seconds = CAST_F(args[0]);
|
||||||
auto begin = std::chrono::high_resolution_clock::now();
|
auto begin = std::chrono::system_clock::now();
|
||||||
while(true){
|
while(true){
|
||||||
auto now = std::chrono::high_resolution_clock::now();
|
auto now = std::chrono::system_clock::now();
|
||||||
f64 elapsed = std::chrono::duration_cast<std::chrono::microseconds>(now - begin).count() / 1000000.0;
|
f64 elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(now - begin).count() / 1000.0;
|
||||||
if(elapsed >= seconds) break;
|
if(elapsed >= seconds) break;
|
||||||
}
|
}
|
||||||
return vm->None;
|
return vm->None;
|
||||||
|
4
src/vm.h
4
src/vm.h
@ -1156,9 +1156,9 @@ inline PyObject* VM::vectorcall(int ARGC, int KWARGC, bool op_call){
|
|||||||
if(args.size() < fn.argc){
|
if(args.size() < fn.argc){
|
||||||
vm->TypeError(fmt(
|
vm->TypeError(fmt(
|
||||||
"expected ",
|
"expected ",
|
||||||
fn.argc,
|
fn.argc - (int)method_call,
|
||||||
" positional arguments, but got ",
|
" positional arguments, but got ",
|
||||||
args.size(),
|
args.size() - (int)method_call,
|
||||||
" (", fn.decl->code->name, ')'
|
" (", fn.decl->code->name, ')'
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user