Add base object function stubs(!)
Big step here, we have function stubs available for everybody. Most of them panic. Each type will eventually have its own implementations for different operators. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -705,8 +705,8 @@ impl StmtVisitor for Compiler<'_> {
|
||||
fn visit_if_stmt(&mut self, stmt: &IfStmt) -> Result<()> {
|
||||
// condition
|
||||
self.compile_expr(&stmt.condition)?;
|
||||
// call obj.__bool__()
|
||||
let bool_attr = self.insert_constant(self.create_str("__bool__"))?;
|
||||
// call obj.to_bool()
|
||||
let bool_attr = self.insert_constant(self.create_str("to_bool"))?;
|
||||
self.emit(expr_line_number(&*stmt.condition), Op::GetAttr(bool_attr));
|
||||
self.emit(expr_line_number(&*stmt.condition), Op::Call(0));
|
||||
let condition_patch_index = self.chunk().code.len();
|
||||
@@ -778,7 +778,7 @@ impl ExprVisitor for Compiler<'_> {
|
||||
let mut exit_patch_index = 0;
|
||||
|
||||
if let TokenKind::And | TokenKind::Or = expr.op.kind {
|
||||
let constant_id = self.insert_constant(self.create_str("__bool__"))?;
|
||||
let constant_id = self.insert_constant(self.create_str("to_bool"))?;
|
||||
self.emit(expr_line_number(&*expr.lhs), Op::GetAttr(constant_id));
|
||||
self.emit(expr_line_number(&*expr.lhs), Op::Call(0));
|
||||
exit_patch_index = self.chunk().code.len();
|
||||
@@ -797,7 +797,7 @@ impl ExprVisitor for Compiler<'_> {
|
||||
|
||||
// convert RHS to a bool if we're doing AND or OR
|
||||
if let TokenKind::And | TokenKind::Or = expr.op.kind {
|
||||
let constant_id = self.insert_constant(self.create_str("__bool__"))?;
|
||||
let constant_id = self.insert_constant(self.create_str("to_bool"))?;
|
||||
self.emit(expr_line_number(&*expr.rhs), Op::GetAttr(constant_id));
|
||||
self.emit(expr_line_number(&*expr.rhs), Op::Call(0));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user