Fork of daniellemaywood.uk/gleam — Wasm codegen work
2

Configure Feed

Select the types of activity you want to include in your feed.

Allow assignment patterns in bit array segments

+54 -6
+33
compiler-core/src/erlang/pattern.rs
··· 190 190 | Pattern::Float { .. } => { 191 191 print(value, &mut vars.borrow_mut(), env, &mut guards.borrow_mut()) 192 192 } 193 + 194 + Pattern::Assign { name, pattern, .. } => { 195 + vars.borrow_mut().push(name); 196 + let variable_name = env.next_local_var_name(name); 197 + match pattern.as_ref() { 198 + Pattern::Int { value, .. } => { 199 + guards 200 + .borrow_mut() 201 + .push(docvec![variable_name.clone(), " =:= ", int(value)]); 202 + variable_name 203 + } 204 + Pattern::Float { value, .. } => { 205 + guards 206 + .borrow_mut() 207 + .push(docvec![variable_name.clone(), " =:= ", float(value)]); 208 + variable_name 209 + } 210 + 211 + Pattern::String { value, .. } => { 212 + guards.borrow_mut().push(docvec![ 213 + variable_name.clone(), 214 + " =:= ", 215 + string(value) 216 + ]); 217 + docvec![variable_name, ":", string_length_utf8_bytes(value),] 218 + } 219 + 220 + Pattern::Discard { .. } => variable_name, 221 + 222 + _ => panic!("Pattern segment match not recognised"), 223 + } 224 + } 225 + 193 226 _ => panic!("Pattern segment match not recognised"), 194 227 }; 195 228
+21 -6
compiler-core/src/exhaustiveness.rs
··· 877 877 LiteralString(EcoString), 878 878 Variable(EcoString), 879 879 Discard(EcoString), 880 + Assign { 881 + name: EcoString, 882 + pattern_match: Box<BitArrayMatchedValue>, 883 + }, 880 884 } 881 885 882 886 impl BitArrayTest { ··· 2566 2570 2567 2571 // Each segment is also turned into a match test, checking the 2568 2572 // selected bits match with the pattern's value. 2569 - let value = segment_matched_value(segment); 2573 + let value = segment_matched_value(&segment.value); 2570 2574 2571 2575 let type_ = match &segment.type_ { 2572 2576 type_ if type_.is_int() => ReadType::Int, ··· 2588 2592 // Then if the matched value is a variable that is in scope for the 2589 2593 // rest of the pattern we keep track of it, so it can be used in the 2590 2594 // following read actions as a valid size. 2591 - if let BitArrayMatchedValue::Variable(name) = &value { 2592 - let _ = pattern_variables.insert(name.clone(), read_action.clone()); 2593 - }; 2595 + match &value { 2596 + BitArrayMatchedValue::LiteralFloat(_) 2597 + | BitArrayMatchedValue::LiteralInt(_) 2598 + | BitArrayMatchedValue::LiteralString(_) 2599 + | BitArrayMatchedValue::Discard(_) => {} 2600 + BitArrayMatchedValue::Variable(name) 2601 + | BitArrayMatchedValue::Assign { name, .. } => { 2602 + let _ = pattern_variables.insert(name.clone(), read_action.clone()); 2603 + } 2604 + } 2594 2605 2595 2606 tests.push_back(BitArrayTest::Match(MatchTest { value, read_action })); 2596 2607 ··· 2600 2611 } 2601 2612 } 2602 2613 2603 - fn segment_matched_value(segment: &TypedPatternBitArraySegment) -> BitArrayMatchedValue { 2604 - match segment.value.as_ref() { 2614 + fn segment_matched_value(pattern: &TypedPattern) -> BitArrayMatchedValue { 2615 + match pattern { 2605 2616 ast::Pattern::Int { value, .. } => BitArrayMatchedValue::LiteralInt(value.clone()), 2606 2617 ast::Pattern::Float { value, .. } => BitArrayMatchedValue::LiteralFloat(value.clone()), 2607 2618 ast::Pattern::String { value, .. } => BitArrayMatchedValue::LiteralString(value.clone()), 2608 2619 ast::Pattern::Variable { name, .. } => BitArrayMatchedValue::Variable(name.clone()), 2609 2620 ast::Pattern::Discard { name, .. } => BitArrayMatchedValue::Discard(name.clone()), 2621 + ast::Pattern::Assign { name, pattern, .. } => BitArrayMatchedValue::Assign { 2622 + name: name.clone(), 2623 + pattern_match: Box::new(segment_matched_value(pattern)), 2624 + }, 2610 2625 x => panic!("unexpected segment value pattern {:?}", x), 2611 2626 } 2612 2627 }