mirror of
https://github.com/HigherOrderCO/Bend.git
synced 2024-09-11 11:56:54 +03:00
Implement getter generation for map setter keys
This commit is contained in:
parent
cfd9b03efd
commit
b436232a3f
@ -15,14 +15,22 @@ impl Definition {
|
||||
impl Stmt {
|
||||
fn gen_map_get(&mut self, id: &mut usize) {
|
||||
match self {
|
||||
Stmt::Assign { pat: _, val, nxt } => {
|
||||
Stmt::Assign { pat, val, nxt } => {
|
||||
let key_substitutions =
|
||||
if let AssignPattern::MapSet(_, key) = pat { key.substitute_map_gets(id) } else { Vec::new() };
|
||||
|
||||
if let Some(nxt) = nxt {
|
||||
nxt.gen_map_get(id);
|
||||
}
|
||||
|
||||
let substitutions = val.substitute_map_gets(id);
|
||||
if !substitutions.is_empty() {
|
||||
*self = gen_get(self, substitutions);
|
||||
}
|
||||
|
||||
if !key_substitutions.is_empty() {
|
||||
*self = gen_get(self, key_substitutions);
|
||||
}
|
||||
}
|
||||
Stmt::Ask { pat: _, val, nxt } => {
|
||||
nxt.gen_map_get(id);
|
||||
|
@ -46,9 +46,10 @@ pub struct MatchArm {
|
||||
pub rgt: Stmt,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub enum AssignPattern {
|
||||
// "*"
|
||||
#[default]
|
||||
Eraser,
|
||||
// [a-zA-Z_]+
|
||||
Var(Name),
|
||||
|
5
tests/golden_tests/run_file/nested_map_set.bend
Normal file
5
tests/golden_tests/run_file/nested_map_set.bend
Normal file
@ -0,0 +1,5 @@
|
||||
def main():
|
||||
map = { 0: 1, 1: 10, 2: 0, 3: 1, 4: 3 }
|
||||
map[map[0]] = 99
|
||||
map[map[2]] = 1
|
||||
return map[map[map[4]]] + map[map[2]]
|
9
tests/snapshots/run_file__nested_map_set.bend.snap
Normal file
9
tests/snapshots/run_file__nested_map_set.bend.snap
Normal file
@ -0,0 +1,9 @@
|
||||
---
|
||||
source: tests/golden_tests.rs
|
||||
input_file: tests/golden_tests/run_file/nested_map_set.bend
|
||||
---
|
||||
NumScott:
|
||||
100
|
||||
|
||||
Scott:
|
||||
100
|
Loading…
Reference in New Issue
Block a user