diff --git a/joy/gui/main.py b/joy/gui/main.py index eba355d..17539a3 100755 --- a/joy/gui/main.py +++ b/joy/gui/main.py @@ -20,9 +20,9 @@ from joy.utils.stack import stack_to_string tb = TEXT_BINDINGS.copy() tb.update({ '': lambda tv: tv.copy_selection_to_stack, - '': lambda tv: tv.cut, - # '': lambda tv: tv.pastecut, - # '': lambda tv: tv.copyto, + '': lambda tv: tv.cut, + '': lambda tv: tv.copyto, + '': lambda tv: tv.pastecut, }) defaults = dict(text_bindings=tb, width=80, height=25) @@ -30,20 +30,15 @@ defaults = dict(text_bindings=tb, width=80, height=25) GLOBAL_COMMANDS = { '': 'swap', '': 'dup', - '': 'roll<', '': 'roll>', - '': 'over', '': 'tuck', - - '': 'parse', - + '': 'parse', '': 'words', '': 'reset_log show_log', '': 'clear reset_log show_log', '': 'pop', - '': 'popd', } @@ -55,14 +50,16 @@ def repo_relative_path(path): def key_bindings(*args): - print dedent(''' - Ctrl-Enter - Run the selection as Joy code. - - F1 - Reset and show (if hidden) the log. - Esc - Like F1 but also clears the stack. - ... - F12 - print a list of all command words, or right-click "words". - ''') + commands = [ + 'Control-Enter - Run the selection as Joy code.', + 'F3 - Copy selection to stack.', + 'Shift-F3 - Cut selection to stack.', + 'F4 - Paste item on top of stack to insertion cursor.', + 'Shift-F4 - Pop and paste top of stack to insertion cursor.', + ] + for key, command in GLOBAL_COMMANDS.iteritems(): + commands.append('%s - %s' % (key.strip('<>'), command)) + print '\n'.join([''] + sorted(commands)) return args @@ -127,7 +124,8 @@ FONT = get_font('Iosevka', size=14) # Requires Tk root already set up. log.init('Log', LOG_FN, repo_relative_path(LOG_FN), repo, FONT) t.init('Joy - ' + JOY_HOME, JOY_FN, repo_relative_path(JOY_FN), repo, FONT) for event, command in GLOBAL_COMMANDS.items(): - t.bind_all(event, lambda _, _command=command: world.interpret(_command)) + t.bind(event, lambda _, _command=command: world.interpret(_command)) + log.bind(event, lambda _, _command=command: world.interpret(_command)) def main(): diff --git a/joy/gui/textwidget.py b/joy/gui/textwidget.py index d9cc1f3..47e3db6 100644 --- a/joy/gui/textwidget.py +++ b/joy/gui/textwidget.py @@ -439,7 +439,6 @@ class TextViewerWidget(tk.Text, MouseBindingsMixin, SavingMixin): self.delete('0.0', tk.END) self.insert(tk.END, data) - def popupTB(self, tb): top = tk.Toplevel() T = TextViewerWidget( diff --git a/joy/library.py b/joy/library.py index 168b655..6fa287a 100644 --- a/joy/library.py +++ b/joy/library.py @@ -71,6 +71,7 @@ ALIASES = ( ('pred', ['--']), ('rolldown', ['roll<']), ('rollup', ['roll>']), + ('eh', ['?']), ('id', [u'•']), ) diff --git a/joy/utils/polytypes.py b/joy/utils/polytypes.py index 58f80d7..b836a41 100644 --- a/joy/utils/polytypes.py +++ b/joy/utils/polytypes.py @@ -396,15 +396,7 @@ Ss = map(StackStarJoyType, _R) FUNCTIONS = { name: SymbolJoyType(name, [DEFS[name]], i) - for i, name in enumerate(''' - ccons cons divmod dup dupd dupdd first first_two fourth over pop - popd popdd popop popopd popopdd rest rrest rolldown rollup second - stack swaack swap swons third tuck uncons unswons stuncons - stununcons unit eq ge gt le lt ne and bool not - _Tree_add_Ee _Tree_delete_R0 _Tree_delete_clear_stuff _Tree_get_E - add mul sub floordiv modulus div truediv pow - neg pred succ - '''.strip().split()) + for i, name in enumerate(sorted(DEFS)) } '''Docstring for functions in Sphinx?''' @@ -414,7 +406,7 @@ def defs(): Return a dict of FunctionJoyType instances to be used with ``infer()``. ''' - sum_ = product = [(((Ns[1], s1), s0), (n0, s0))] + average = sum_ = product = min_ = max_ = [(((Ns[1], s1), s0), (n0, s0))] clear = [(s0, s1)] @@ -467,6 +459,9 @@ FUNCTIONS.update({ joy.library.i, joy.library.infra, joy.library._dictionary['nullary'], + joy.library._dictionary['unary'], + joy.library._dictionary['binary'], + joy.library._dictionary['ternary'], joy.library.x, )) }) @@ -504,6 +499,9 @@ def set_expectations(): branch.expect = s7, (s6, (b1, s5)) loop.expect = s6, (b1, s5) i.expect = nullary.expect = x.expect = s7, s6 + unary.expect = (s1, (a1, s2)) + binary.expect = (s1, (a1, (a2, s2))) + ternary.expect = (s1, (a1, (a2, (a3, s2)))) dip.expect = dupdip.expect = s8, (a8, s7) dipd.expect = s8, (a8, (a7, s7)) dipdd.expect = s8, (a8, (a7, (a6, s7))) diff --git a/joy/utils/types.py b/joy/utils/types.py index be59109..01abd9a 100644 --- a/joy/utils/types.py +++ b/joy/utils/types.py @@ -325,11 +325,12 @@ def defs(): and_ = __(b1, b2), __(b3) bool_ = not_ = __(a1), __(b1) + eh = compose(dup, bool_) - add = div = floordiv = modulus = mul = pow_ = sub = truediv = \ + add = div = floordiv = mod = mul = pow_ = sub = truediv = \ lshift = rshift = __(n1, n2), __(n3,) - sqrt = compose(dup, mul) - succ = pred = neg = __(n1,), __(n2,) + sqr = compose(dup, mul) + abs_ = floor = succ = pred = neg = __(n1,), __(n2,) divmod_ = pm = __(n2, n1), __(n4, n3) first_two = compose(uncons, uncons, pop)