mirror of
https://github.com/HigherOrderCO/Bend.git
synced 2024-09-11 11:56:54 +03:00
Merge pull request #490 from HigherOrderCO/489-nested-map-setters
#489 Map setters using map getters
This commit is contained in:
commit
534e71dc55
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -68,7 +68,7 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711"
|
||||
|
||||
[[package]]
|
||||
name = "bend-lang"
|
||||
version = "0.2.19"
|
||||
version = "0.2.20"
|
||||
dependencies = [
|
||||
"TSPL",
|
||||
"arrayvec",
|
||||
|
@ -2,7 +2,7 @@
|
||||
name = "bend-lang"
|
||||
description = "A high-level, massively parallel programming language"
|
||||
license = "Apache-2.0"
|
||||
version = "0.2.19"
|
||||
version = "0.2.20"
|
||||
edition = "2021"
|
||||
exclude = ["tests/snapshots/"]
|
||||
|
||||
|
@ -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