This commit is contained in:
blueloveTH 2023-06-26 19:45:49 +08:00
parent 3738d07941
commit 37c46fda68
4 changed files with 18 additions and 12 deletions

View File

@ -141,7 +141,6 @@ __NEXT_STEP:;
_0 = vm->builtins->attr().try_get(_name);
if(_0 != nullptr) { PUSH(_0); DISPATCH(); }
vm->NameError(_name);
DISPATCH();
} DISPATCH();
TARGET(LOAD_GLOBAL)
heap._auto_collect();

View File

@ -707,8 +707,8 @@ __SUBSCR_END:
// stack size is n+1
Expr_ val = ctx()->s_expr.popx();
val->emit(ctx());
for(int i=1; i<n; i++) ctx()->emit(OP_DUP_TOP, BC_NOARG, BC_KEEPLINE);
for(int i=0; i<n; i++){
for(int j=1; j<n; j++) ctx()->emit(OP_DUP_TOP, BC_NOARG, BC_KEEPLINE);
for(int j=0; j<n; j++){
auto e = ctx()->s_expr.popx();
if(e->is_starred()) SyntaxError();
bool ok = e->emit_store(ctx());

View File

@ -28,10 +28,16 @@ struct Expr{
bool is_starred() const { return star_level() > 0; }
// for OP_DELETE_XXX
[[nodiscard]] virtual bool emit_del(CodeEmitContext* ctx) { return false; }
[[nodiscard]] virtual bool emit_del(CodeEmitContext* ctx) {
PK_UNUSED(ctx);
return false;
}
// for OP_STORE_XXX
[[nodiscard]] virtual bool emit_store(CodeEmitContext* ctx) { return false; }
[[nodiscard]] virtual bool emit_store(CodeEmitContext* ctx) {
PK_UNUSED(ctx);
return false;
}
};
struct CodeEmitContext{

View File

@ -962,6 +962,7 @@ inline PyObject* VM::format(Str spec, PyObject* obj){
}
}catch(...){
ValueError("invalid format specifer");
UNREACHABLE();
}
if(type != 'f' && dot >= 0) ValueError("precision not allowed in the format specifier");
@ -1307,18 +1308,18 @@ inline PyObject* VM::vectorcall(int ARGC, int KWARGC, bool op_call){
vkwargs = nullptr;
}
for(int i=0; i<kwargs.size(); i+=2){
StrName key(CAST(int, kwargs[i]));
for(int j=0; j<kwargs.size(); j+=2){
StrName key(CAST(int, kwargs[j]));
int index = co->varnames_inv.try_get(key);
if(index < 0){
if(vkwargs == nullptr){
TypeError(fmt(key.escape(), " is an invalid keyword argument for ", co->name, "()"));
}else{
Dict& dict = _CAST(Dict&, vkwargs);
dict.set(VAR(key.sv()), kwargs[i+1]);
dict.set(VAR(key.sv()), kwargs[j+1]);
}
}else{
buffer[index] = kwargs[i+1];
buffer[index] = kwargs[j+1];
}
}
@ -1332,7 +1333,7 @@ inline PyObject* VM::vectorcall(int ARGC, int KWARGC, bool op_call){
// copy buffer back to stack
s_data.reset(args.begin());
for(int i=0; i<co_nlocals; i++) PUSH(buffer[i]);
for(int j=0; j<co_nlocals; j++) PUSH(buffer[j]);
callstack.emplace(&s_data, p0, co, fn._module, callable, FastLocals(co, args.begin()));
if(op_call) return PY_OP_CALL;
return _run_top_frame();
@ -1357,8 +1358,8 @@ inline PyObject* VM::vectorcall(int ARGC, int KWARGC, bool op_call){
PUSH(new_f);
PUSH(PY_NULL);
PUSH(callable); // cls
for(PyObject* obj: args) PUSH(obj);
for(PyObject* obj: kwargs) PUSH(obj);
for(PyObject* o: args) PUSH(o);
for(PyObject* o: kwargs) PUSH(o);
// if obj is not an instance of callable, the behavior is undefined
obj = vectorcall(ARGC+1, KWARGC);
}