pseudocode splatted dict algo
This commit is contained in:
parent
35d7d3b1c8
commit
4dd4b8ff7e
|
@ -848,6 +848,11 @@ impl<'a> Compiler<'a> {
|
||||||
self.match_depth = match_depth + members.len();
|
self.match_depth = match_depth + members.len();
|
||||||
}
|
}
|
||||||
DictPattern(pairs) => {
|
DictPattern(pairs) => {
|
||||||
|
// here's an algorithm for dealing with splatted dicts
|
||||||
|
// check len to see it's at least as long as the pattern
|
||||||
|
// then, match against all the values
|
||||||
|
// then push the dict itself as last value
|
||||||
|
// and then emit an opcode and constant/keyword to OMIT that key from the dict
|
||||||
self.emit_op(Op::MatchDict);
|
self.emit_op(Op::MatchDict);
|
||||||
self.emit_byte(pairs.len());
|
self.emit_byte(pairs.len());
|
||||||
let before_load_dict_idx = self.stub_jump(Op::JumpIfNoMatch);
|
let before_load_dict_idx = self.stub_jump(Op::JumpIfNoMatch);
|
||||||
|
|
|
@ -75,7 +75,7 @@ pub fn run(src: &'static str) {
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
env::set_var("RUST_BACKTRACE", "1");
|
env::set_var("RUST_BACKTRACE", "1");
|
||||||
let src = "
|
let src = "
|
||||||
let (...y) = (1, 2)
|
let (...y) = (1, 2, 3, 4, 5)
|
||||||
y
|
y
|
||||||
";
|
";
|
||||||
run(src);
|
run(src);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user