Skip to content

Commit

Permalink
allow rows function pack
Browse files Browse the repository at this point in the history
  • Loading branch information
kaikalii committed Jun 3, 2024
1 parent 479dcf3 commit 286eb24
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
29 changes: 26 additions & 3 deletions src/compile/modifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::format::format_words;
use super::*;

impl Compiler {
fn desugar_operand(
fn desugar_function_pack(
&self,
modifier: &Sp<Modifier>,
operand: Sp<Word>,
Expand Down Expand Up @@ -42,6 +42,29 @@ impl Compiler {
}
Ok(Some(new))
}
Modifier::Primitive(Primitive::Rows) => {
let mut branches = pack.branches.into_iter();
let mut new = Modified {
modifier: modifier.clone(),
operands: vec![branches.next().unwrap().map(Word::Func)],
};
for branch in branches {
let mut lines = branch.value.lines;
(lines.first_mut().unwrap())
.insert(0, span.clone().sp(Word::Modified(Box::new(new))));
new = Modified {
modifier: modifier.clone(),
operands: vec![branch.span.clone().sp(Word::Func(Func {
id: FunctionId::Anonymous(branch.span.clone()),
signature: None,
lines,
closed: true,
}))],
};
}
dbg!(&new);
Ok(Some(new))
}
Modifier::Primitive(
Primitive::Fork | Primitive::Bracket | Primitive::Try | Primitive::Fill,
) => {
Expand Down Expand Up @@ -117,7 +140,7 @@ impl Compiler {
// De-sugar function pack
if op_count == 1 {
let operand = modified.code_operands().next().unwrap().clone();
if let Some(new) = self.desugar_operand(&modified.modifier, operand)? {
if let Some(new) = self.desugar_function_pack(&modified.modifier, operand)? {
return self.modified(new, call);
}
}
Expand Down Expand Up @@ -350,7 +373,7 @@ impl Compiler {
{
let mut m = (**m).clone();
for op in m.operands.iter_mut().filter(|w| w.value.is_code()) {
if let Some(new) = self.desugar_operand(&m.modifier, op.clone())? {
if let Some(new) = self.desugar_function_pack(&m.modifier, op.clone())? {
op.value = Word::Modified(new.into());
}
op.value = Word::Modified(
Expand Down
2 changes: 1 addition & 1 deletion todo.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Uiua Todo

- 0.12
- `rows` function pack
- Improve `un join` chained with other functions
- Show array shape on hover
- Unicode literals
Expand All @@ -15,6 +14,7 @@
- `base` function
- `chunks` function?
- `pull` function?
- Channels
- Plots
- Media window
- Trace images/audio in pad
Expand Down

0 comments on commit 286eb24

Please sign in to comment.