diff --git a/src/compile/compiler.rs b/src/compile/compiler.rs index 646eca7..6149284 100644 --- a/src/compile/compiler.rs +++ b/src/compile/compiler.rs @@ -108,6 +108,9 @@ impl Compiler { let mut cond_thunk = self.emit_expr(&cond_block.inner().cond); 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); // jump forward by the length of the body cond_thunk.push_back(Inst::JumpRelative( @@ -129,6 +132,9 @@ impl Compiler { let mut cond_thunk = self.emit_expr(&if_true.inner().cond); 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::JumpRelative( // + 1 because otherwise we won't end up on the next instruction diff --git a/src/obj/mod.rs b/src/obj/mod.rs index 97106d0..b34274b 100644 --- a/src/obj/mod.rs +++ b/src/obj/mod.rs @@ -2,13 +2,14 @@ pub mod boolean; pub mod builtin_fun; pub mod builtins; pub mod int; +pub mod names; pub mod none; pub mod str; pub mod user_fun; pub mod prelude { // 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 pub use super::{Attrs, AttrsPtr, Obj, ObjPtr}; // Macros diff --git a/src/obj/names.rs b/src/obj/names.rs new file mode 100644 index 0000000..6856071 --- /dev/null +++ b/src/obj/names.rs @@ -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 = name!(BOOL_METHOD);