mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-24 13:30:18 +00:00
fix neg constant
This commit is contained in:
parent
6067436e46
commit
ce0ba313d1
@ -65,6 +65,8 @@ struct CodeObject {
|
||||
std::vector<CodeBlock> blocks = { CodeBlock{NO_BLOCK, -1} };
|
||||
emhash8::HashMap<Str, int> labels;
|
||||
|
||||
void optimize(VM* vm);
|
||||
|
||||
bool add_label(const Str& label){
|
||||
if(labels.contains(label)) return false;
|
||||
labels[label] = codes.size();
|
||||
@ -86,8 +88,6 @@ struct CodeObject {
|
||||
return consts.size() - 1;
|
||||
}
|
||||
|
||||
void optimize(VM* vm);
|
||||
|
||||
/************************************************/
|
||||
int _curr_block_i = 0;
|
||||
bool _rvalue = false;
|
||||
|
||||
9
src/vm.h
9
src/vm.h
@ -1129,9 +1129,10 @@ PyVar pkpy::NativeFunc::operator()(VM* vm, const pkpy::Args& args) const{
|
||||
|
||||
void CodeObject::optimize(VM* vm){
|
||||
for(int i=1; i<codes.size(); i++){
|
||||
if(codes[i].op == OP_UNARY_NEGATIVE && codes[i-1].op == OP_LOAD_CONST){
|
||||
codes[i].op = OP_NO_OP;
|
||||
int pos = codes[i-1].arg;
|
||||
consts[pos] = vm->num_negated(consts[pos]);
|
||||
if(codes[i].op == OP_UNARY_NEGATIVE && codes[i-1].op == OP_LOAD_CONST){
|
||||
codes[i].op = OP_NO_OP;
|
||||
int pos = codes[i-1].arg;
|
||||
consts[pos] = vm->num_negated(consts[pos]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user