Finish up old example that shows off basic expressions and funcalls

The VM now supports the various int comparison methods. An example of a
"pow" method is given to show off recursion, which means we're now
TURING COMPLETE!

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-11-09 16:50:16 -08:00
parent 357aad5306
commit c6212f5597
5 changed files with 165 additions and 28 deletions

View File

@@ -337,13 +337,76 @@ impl<'c> Vm<'c> {
};
signal = Some(Signal::Call(fun, vec![rhs]));
}
Inst::BinNeq => todo!(),
Inst::BinLt => todo!(),
Inst::BinLe => todo!(),
Inst::BinGt => todo!(),
Inst::BinGe => todo!(),
Inst::BinAnd => todo!(),
Inst::BinOr => todo!(),
Inst::BinNeq => {
let rhs = self.pop().unwrap();
let lhs = self.pop().unwrap();
let fun = {
read_obj!(let lhs = lhs);
lhs.get_ne()
.expect("TODO: throw an error for missing __ne__ attr")
};
signal = Some(Signal::Call(fun, vec![rhs]));
}
Inst::BinLt => {
let rhs = self.pop().unwrap();
let lhs = self.pop().unwrap();
let fun = {
read_obj!(let lhs = lhs);
lhs.get_lt()
.expect("TODO: throw an error for missing __lt__ attr")
};
signal = Some(Signal::Call(fun, vec![rhs]));
}
Inst::BinLe => {
let rhs = self.pop().unwrap();
let lhs = self.pop().unwrap();
let fun = {
read_obj!(let lhs = lhs);
lhs.get_le()
.expect("TODO: throw an error for missing __le__ attr")
};
signal = Some(Signal::Call(fun, vec![rhs]));
}
Inst::BinGt => {
let rhs = self.pop().unwrap();
let lhs = self.pop().unwrap();
let fun = {
read_obj!(let lhs = lhs);
lhs.get_gt()
.expect("TODO: throw an error for missing __gt__ attr")
};
signal = Some(Signal::Call(fun, vec![rhs]));
}
Inst::BinGe => {
let rhs = self.pop().unwrap();
let lhs = self.pop().unwrap();
let fun = {
read_obj!(let lhs = lhs);
lhs.get_ge()
.expect("TODO: throw an error for missing __ge__ attr")
};
signal = Some(Signal::Call(fun, vec![rhs]));
}
Inst::BinAnd => todo!(), /*{
let rhs = self.pop().unwrap();
let lhs = self.pop().unwrap();
let fun = {
read_obj!(let lhs = lhs);
lhs.get_and()
.expect("TODO: throw an error for missing __and__ attr")
};
signal = Some(Signal::Call(fun, vec![rhs]));
}*/
Inst::BinOr => todo!(), /*{
let rhs = self.pop().unwrap();
let lhs = self.pop().unwrap();
let fun = {
read_obj!(let lhs = lhs);
lhs.get_or()
.expect("TODO: throw an error for missing __or__ attr")
};
signal = Some(Signal::Call(fun, vec![rhs]));
}*/
}
self.set_pc(next_pc);