Skip to content

Commit

Permalink
add flop modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
kaikalii committed Jun 20, 2024
1 parent 1bc8e1e commit 026f975
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
23 changes: 23 additions & 0 deletions src/compile/modifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,29 @@ impl Compiler {
self.push_instr(Instr::PushFunc(func));
}
}
Flop => {
let operand = modified.code_operands().next().unwrap().clone();
let (mut instrs, sig) = self.compile_operand_word(operand)?;
if sig.args != 2 {
self.add_error(
modified.modifier.span.clone(),
format!(
"{}'s function must be dyadic, but its signature is {}",
prim, sig
),
);
}
let spandex = self.add_span(modified.modifier.span.clone());
instrs.insert(0, Instr::Prim(Flip, spandex));
let sig = self.sig_of(&instrs, &modified.modifier.span)?;
if call {
self.push_all_instrs(instrs);
} else {
let func =
self.make_function(modified.modifier.span.clone().into(), sig, instrs);
self.push_instr(Instr::PushFunc(func));
}
}
Fork => {
let mut operands = modified.code_operands().cloned();
let first_op = operands.next().unwrap();
Expand Down
7 changes: 7 additions & 0 deletions src/primitive/defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1787,6 +1787,13 @@ primitive!(
/// : [⫯⊙⊙⊙∘ 1 2 3 4]
/// : [⫯⊙⊙⊙◌ 1 2 3 4]
([1], But, Stack, ("but", '⫯')),
/// Call a function with its arguments reversed
///
/// This is a modifier version of [flip].
/// It is experimental because it is unclear whether this is a desirable direction for the language.
/// ex: # Experimental!
/// : ¨⊂ 1 2
([1], Flop, Stack, ("flop", '¨')),
/// Call a function on two sets of values
///
/// For monadic functions, [both] calls its function on each of the top 2 values on the stack.
Expand Down
6 changes: 4 additions & 2 deletions src/primitive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,8 @@ impl Primitive {
use SysOp::*;
matches!(
self,
But | (Orient | Coordinate | Astar | Fft | Triangle | Case)
(But | Flop)
| (Orient | Coordinate | Astar | Fft | Triangle | Case)
| Sys(Ffi | MemCopy | MemFree | TlsListen)
| (Stringify | Quote | Sig)
)
Expand Down Expand Up @@ -848,8 +849,9 @@ impl Primitive {
| Primitive::Dip
| Primitive::On
| Primitive::By
| Primitive::But
| Primitive::Gap
| Primitive::But
| Primitive::Flop
| Primitive::Un
| Primitive::Under
| Primitive::Content
Expand Down
1 change: 0 additions & 1 deletion todo.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Uiua Todo

- 0.12
- `flop` modifier
- Stabilize labels
- `branch:` and `commit:` specifiers for imports
- Goto definition/Ctrl+click on git imports to go to the URL
Expand Down

0 comments on commit 026f975

Please sign in to comment.