mirror of
https://github.com/pocketpy/pocketpy
synced 2025-11-09 21:20:17 +00:00
some fix
This commit is contained in:
parent
5726826f74
commit
db86ecdcb1
@ -105,6 +105,7 @@ struct CodeEmitContext{
|
|||||||
void exit_block();
|
void exit_block();
|
||||||
void emit_expr(); // clear the expression stack and generate bytecode
|
void emit_expr(); // clear the expression stack and generate bytecode
|
||||||
int emit_(Opcode opcode, uint16_t arg, int line, bool is_virtual=false);
|
int emit_(Opcode opcode, uint16_t arg, int line, bool is_virtual=false);
|
||||||
|
int emit_int(i64 value, int line);
|
||||||
void patch_jump(int index);
|
void patch_jump(int index);
|
||||||
bool add_label(StrName name);
|
bool add_label(StrName name);
|
||||||
int add_varname(StrName name);
|
int add_varname(StrName name);
|
||||||
|
|||||||
26
src/expr.cpp
26
src/expr.cpp
@ -64,6 +64,14 @@ namespace pkpy{
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CodeEmitContext::emit_int(i64 _val, int line){
|
||||||
|
if(is_imm_int(_val)){
|
||||||
|
return emit_(OP_LOAD_INTEGER, (uint16_t)_val, line);
|
||||||
|
}else{
|
||||||
|
return emit_(OP_LOAD_CONST, add_const(VAR(_val)), line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CodeEmitContext::patch_jump(int index) {
|
void CodeEmitContext::patch_jump(int index) {
|
||||||
int target = co->codes.size();
|
int target = co->codes.size();
|
||||||
co->codes[index].arg = target;
|
co->codes[index].arg = target;
|
||||||
@ -246,11 +254,7 @@ namespace pkpy{
|
|||||||
VM* vm = ctx->vm;
|
VM* vm = ctx->vm;
|
||||||
if(std::holds_alternative<i64>(value)){
|
if(std::holds_alternative<i64>(value)){
|
||||||
i64 _val = std::get<i64>(value);
|
i64 _val = std::get<i64>(value);
|
||||||
if(is_imm_int(_val)){
|
ctx->emit_int(_val, line);
|
||||||
ctx->emit_(OP_LOAD_INTEGER, (uint16_t)_val, line);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ctx->emit_(OP_LOAD_CONST, ctx->add_const(VAR(_val)), line);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(std::holds_alternative<f64>(value)){
|
if(std::holds_alternative<f64>(value)){
|
||||||
@ -272,11 +276,7 @@ namespace pkpy{
|
|||||||
LiteralExpr* lit = static_cast<LiteralExpr*>(child.get());
|
LiteralExpr* lit = static_cast<LiteralExpr*>(child.get());
|
||||||
if(std::holds_alternative<i64>(lit->value)){
|
if(std::holds_alternative<i64>(lit->value)){
|
||||||
i64 _val = -std::get<i64>(lit->value);
|
i64 _val = -std::get<i64>(lit->value);
|
||||||
if(is_imm_int(_val)){
|
ctx->emit_int(_val, line);
|
||||||
ctx->emit_(OP_LOAD_INTEGER, (uint16_t)_val, line);
|
|
||||||
}else{
|
|
||||||
ctx->emit_(OP_LOAD_CONST, ctx->add_const(VAR(_val)), line);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(std::holds_alternative<f64>(lit->value)){
|
if(std::holds_alternative<f64>(lit->value)){
|
||||||
@ -595,11 +595,7 @@ namespace pkpy{
|
|||||||
for(auto& item: args) item->emit_(ctx);
|
for(auto& item: args) item->emit_(ctx);
|
||||||
for(auto& item: kwargs){
|
for(auto& item: kwargs){
|
||||||
i64 _val = StrName(item.first.sv()).index;
|
i64 _val = StrName(item.first.sv()).index;
|
||||||
if(is_imm_int(_val)){
|
ctx->emit_int(_val, line);
|
||||||
ctx->emit_(OP_LOAD_INTEGER, (uint16_t)_val, line);
|
|
||||||
}else{
|
|
||||||
ctx->emit_(OP_LOAD_CONST, ctx->add_const(py_var(ctx->vm, _val)), line);
|
|
||||||
}
|
|
||||||
item.second->emit_(ctx);
|
item.second->emit_(ctx);
|
||||||
}
|
}
|
||||||
int KWARGC = kwargs.size();
|
int KWARGC = kwargs.size();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user