mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 19:40:18 +00:00
up
This commit is contained in:
parent
3d40a3d51f
commit
22e909d7e1
@ -28,10 +28,10 @@ struct Expr{
|
||||
};
|
||||
|
||||
struct CodeEmitContext{
|
||||
CodeObject_ co;
|
||||
VM* vm;
|
||||
CodeObject_ co;
|
||||
stack<Expr_> s_expr;
|
||||
CodeEmitContext(VM* vm, CodeObject_ co): co(co) {}
|
||||
CodeEmitContext(VM* vm, CodeObject_ co): vm(vm), co(co) {}
|
||||
|
||||
int curr_block_i = 0;
|
||||
bool is_compiling_class = false;
|
||||
@ -65,7 +65,10 @@ struct CodeEmitContext{
|
||||
Bytecode{(uint16_t)opcode, (uint16_t)curr_block_i, arg, line}
|
||||
);
|
||||
int i = co->codes.size() - 1;
|
||||
if(line==BC_KEEPLINE && i>=1) co->codes[i].line = co->codes[i-1].line;
|
||||
if(line==BC_KEEPLINE){
|
||||
if(i>=1) co->codes[i].line = co->codes[i-1].line;
|
||||
else co->codes[i].line = 1;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
|
6
src/vm.h
6
src/vm.h
@ -568,12 +568,9 @@ inline Str VM::disassemble(CodeObject_ co){
|
||||
}
|
||||
}
|
||||
StrStream ss;
|
||||
ss << std::string(54, '-') << '\n';
|
||||
ss << co->name << ":\n";
|
||||
int prev_line = -1;
|
||||
for(int i=0; i<co->codes.size(); i++){
|
||||
const Bytecode& byte = co->codes[i];
|
||||
if(byte.op == OP_NO_OP) continue;
|
||||
Str line = std::to_string(byte.line);
|
||||
if(byte.line == prev_line) line = "";
|
||||
else{
|
||||
@ -626,12 +623,13 @@ inline Str VM::disassemble(CodeObject_ co){
|
||||
list.push_back(VAR(co->names[i].str()));
|
||||
}
|
||||
names << CAST(Str, asRepr(VAR(list)));
|
||||
ss << '\n' << consts.str() << '\n' << names.str() << '\n';
|
||||
ss << '\n' << consts.str() << '\n' << names.str();
|
||||
|
||||
for(int i=0; i<co->consts.size(); i++){
|
||||
PyObject* obj = co->consts[i];
|
||||
if(is_type(obj, tp_function)){
|
||||
const auto& f = CAST(Function&, obj);
|
||||
ss << "\n\n" << "Disassembly of " << f.name.str() << ":\n";
|
||||
ss << disassemble(f.code);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user