diff --git a/src/compile/modifier.rs b/src/compile/modifier.rs index 400d8d441..719301b55 100644 --- a/src/compile/modifier.rs +++ b/src/compile/modifier.rs @@ -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(); diff --git a/src/primitive/defs.rs b/src/primitive/defs.rs index b0b5b5966..481b5ab2c 100644 --- a/src/primitive/defs.rs +++ b/src/primitive/defs.rs @@ -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. diff --git a/src/primitive/mod.rs b/src/primitive/mod.rs index be3f9716b..cb55d685f 100644 --- a/src/primitive/mod.rs +++ b/src/primitive/mod.rs @@ -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) ) @@ -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 diff --git a/todo.md b/todo.md index de92ad8f4..d4fe68081 100644 --- a/todo.md +++ b/todo.md @@ -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