Fix builtin types methods

This commit is contained in:
Shunsuke Shibayama 2023-02-03 00:23:42 +09:00
parent c56ef64576
commit 8cdc735486
12 changed files with 180 additions and 7 deletions

View file

@ -475,6 +475,7 @@ impl PyCodeGenerator {
fn emit_load_const<C: Into<ValueObj>>(&mut self, cons: C) {
let value: ValueObj = cons.into();
let is_str = value.is_str();
let is_float = value.is_float();
let is_int = value.is_int();
let is_nat = value.is_nat();
let is_bool = value.is_bool();
@ -488,12 +489,15 @@ impl PyCodeGenerator {
} else if is_int {
self.emit_push_null();
self.emit_load_name_instr(Identifier::public("Int"));
} else if is_float {
self.emit_push_null();
self.emit_load_name_instr(Identifier::public("Float"));
} else if is_str {
self.emit_push_null();
self.emit_load_name_instr(Identifier::public("Str"));
}
}
let wrapped = is_str || is_int; // is_int => is_nat and is_bool
let wrapped = is_str || is_float; // is_float => is_int && is_nat && is_bool
let idx = self
.mut_cur_block_codeobj()
.consts
@ -678,7 +682,7 @@ impl PyCodeGenerator {
"if__" | "for__" | "while__" | "with__" | "discard__" => {
self.load_control();
}
"int__" | "nat__" => {
"int__" | "nat__" | "str__" | "float__" => {
self.load_convertors();
}
_ => {}