More stack effects, and modify the key bindings.

This commit is contained in:
Simon Forman 2018-07-16 18:43:40 -07:00
parent 612d48d8cc
commit 043acd685c
5 changed files with 29 additions and 32 deletions

View File

@ -20,9 +20,9 @@ from joy.utils.stack import stack_to_string
tb = TEXT_BINDINGS.copy()
tb.update({
'<F3>': lambda tv: tv.copy_selection_to_stack,
'<F4>': lambda tv: tv.cut,
# '<F-->': lambda tv: tv.pastecut,
# '<F6>': lambda tv: tv.copyto,
'<Shift-F3>': lambda tv: tv.cut,
'<F4>': lambda tv: tv.copyto,
'<Shift-F4>': 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 = {
'<F5>': 'swap',
'<F6>': 'dup',
'<Shift-F5>': 'roll<',
'<Shift-F6>': 'roll>',
'<F7>': 'over',
'<Shift-F7>': 'tuck',
'<Shift-F3>': 'parse',
'<F8>': 'parse',
'<F12>': 'words',
'<F1>': 'reset_log show_log',
'<Escape>': 'clear reset_log show_log',
'<Control-Delete>': 'pop',
'<Control-Shift-Delete>': '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():

View File

@ -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(

View File

@ -71,6 +71,7 @@ ALIASES = (
('pred', ['--']),
('rolldown', ['roll<']),
('rollup', ['roll>']),
('eh', ['?']),
('id', [u'']),
)

View File

@ -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)))

View File

@ -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)