Add __bool__ method call to branch conditions
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -108,6 +108,9 @@ impl Compiler {
|
|||||||
|
|
||||||
let mut cond_thunk = self.emit_expr(&cond_block.inner().cond);
|
let mut cond_thunk = self.emit_expr(&cond_block.inner().cond);
|
||||||
cond_thunk.push_front(Inst::Comment("elseif compare ".to_string()));
|
cond_thunk.push_front(Inst::Comment("elseif compare ".to_string()));
|
||||||
|
cond_thunk.push_back(Inst::Dupe);
|
||||||
|
cond_thunk.push_back(Inst::GetAttr(self.intern_attr(BOOL_METHOD)));
|
||||||
|
cond_thunk.push_back(Inst::Call(1));
|
||||||
cond_thunk.push_back(Inst::Compare);
|
cond_thunk.push_back(Inst::Compare);
|
||||||
// jump forward by the length of the body
|
// jump forward by the length of the body
|
||||||
cond_thunk.push_back(Inst::JumpRelative(
|
cond_thunk.push_back(Inst::JumpRelative(
|
||||||
@@ -129,6 +132,9 @@ impl Compiler {
|
|||||||
|
|
||||||
let mut cond_thunk = self.emit_expr(&if_true.inner().cond);
|
let mut cond_thunk = self.emit_expr(&if_true.inner().cond);
|
||||||
cond_thunk.push_front(Inst::Comment("if compare".to_string()));
|
cond_thunk.push_front(Inst::Comment("if compare".to_string()));
|
||||||
|
cond_thunk.push_back(Inst::Dupe);
|
||||||
|
cond_thunk.push_back(Inst::GetAttr(self.intern_attr(BOOL_METHOD)));
|
||||||
|
cond_thunk.push_back(Inst::Call(1));
|
||||||
cond_thunk.push_back(Inst::Compare);
|
cond_thunk.push_back(Inst::Compare);
|
||||||
cond_thunk.push_back(Inst::JumpRelative(
|
cond_thunk.push_back(Inst::JumpRelative(
|
||||||
// + 1 because otherwise we won't end up on the next instruction
|
// + 1 because otherwise we won't end up on the next instruction
|
||||||
|
|||||||
@@ -2,13 +2,14 @@ pub mod boolean;
|
|||||||
pub mod builtin_fun;
|
pub mod builtin_fun;
|
||||||
pub mod builtins;
|
pub mod builtins;
|
||||||
pub mod int;
|
pub mod int;
|
||||||
|
pub mod names;
|
||||||
pub mod none;
|
pub mod none;
|
||||||
pub mod str;
|
pub mod str;
|
||||||
pub mod user_fun;
|
pub mod user_fun;
|
||||||
|
|
||||||
pub mod prelude {
|
pub mod prelude {
|
||||||
// Module types
|
// Module types
|
||||||
pub use super::{boolean::*, builtin_fun::*, int::*, none::*, str::*, user_fun::*};
|
pub use super::{boolean::*, builtin_fun::*, int::*, names::*, none::*, str::*, user_fun::*};
|
||||||
// Local types
|
// Local types
|
||||||
pub use super::{Attrs, AttrsPtr, Obj, ObjPtr};
|
pub use super::{Attrs, AttrsPtr, Obj, ObjPtr};
|
||||||
// Macros
|
// Macros
|
||||||
|
|||||||
13
src/obj/names.rs
Normal file
13
src/obj/names.rs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
/*
|
||||||
|
use crate::obj::prelude::*;
|
||||||
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
|
macro_rules! name {
|
||||||
|
($name:expr) => {
|
||||||
|
LazyLock::new(|| ObjPtr::new(Str::new($name)))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
pub const BOOL_METHOD: &str = "__bool__";
|
||||||
|
//pub static BOOL_METHOD_NAME: LazyLock<ObjPtr> = name!(BOOL_METHOD);
|
||||||
Reference in New Issue
Block a user