Skip to content

Commit

Permalink
allow combined local values
Browse files Browse the repository at this point in the history
  • Loading branch information
kaikalii committed Jan 9, 2024
1 parent df3dd09 commit c66271e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
13 changes: 6 additions & 7 deletions src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1000,14 +1000,13 @@ code:
Ok(())
}
fn ident(&mut self, ident: Ident, span: CodeSpan, call: bool) -> UiuaResult {
if let (Some(locals), true) = (
self.scope.locals.last_mut(),
ident.len() == 1 && ident.chars().next().unwrap().is_ascii_lowercase(),
) {
let index = ident.chars().next().unwrap() as usize - 'a' as usize;
locals.insert(index);
if !self.scope.locals.is_empty() && ident.chars().all(|c| c.is_ascii_lowercase()) {
let span = self.add_span(span);
self.push_instr(Instr::GetLocal { index, span });
for c in ident.chars().rev() {
let index = c as usize - 'a' as usize;
self.scope.locals.last_mut().unwrap().insert(index);
self.push_instr(Instr::GetLocal { index, span });
}
} else if let Some(index) = (self.scope.names.get(&ident))
.or_else(|| self.higher_scopes.last()?.names.get(&ident))
.copied()
Expand Down
5 changes: 4 additions & 1 deletion src/primitive/defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1619,9 +1619,12 @@ primitive!(
/// The values can be accessed in the function with lowercase letters.
/// ex: # Experimental!
/// : bind(⊂ b + a c) 1 2 3
/// Adjacent letters can be part of a single identifier.
/// ex: # Experimental!
/// : bind[[beef][babe]] 1 2 3 4 5 6
/// Here is a simple quadratic formula function.
/// ex: # Experimental!
/// : Quad ← bind(÷×2a -b ⊟¯.√ -××4 a c ×.b)
/// : Quad ← bind(÷×2a -b ⊟¯.√ -××4ac ×.b)
/// : Quad 1 2 0
([1], Bind, OtherModifier, "bind"),
/// Memoize a function
Expand Down

0 comments on commit c66271e

Please sign in to comment.