Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add nice names
  • Loading branch information
Mego committed Dec 3, 2017
1 parent 90d5612 commit eb86a85
Show file tree
Hide file tree
Showing 6 changed files with 290 additions and 2 deletions.
255 changes: 255 additions & 0 deletions docs/nice_names.txt
@@ -0,0 +1,255 @@









read_byte
write
unary_map
binary_map

parallel_map





iterate
read_all








lcm
gcd_reduce
stack_size
factorial

list
str
mod
bitwise_and

stack_rrot
stack_lrot
multiply
add concat
read_line
subtract asymmetric_difference
write_line write_fn
divide list_rrot











copy
less_than
equal
greater_than

swap
abs
binary_randrange
cos
decrement stddev
erf element
fib first
random
hello_world head
conditional
unary_randrange random_choice
ceil
floor
map max
nnbb last
ord ords
nth_prime
quine
scoped_call reverse upper_range
sin sort
tangent set_element
union
random_uniform slices
while_begin while_end
discard
logical_negate fixed_point
zip zip_n

floor_divide list_lrot

xor
ln

stack_invert
bool
chr count
dequeue divmod
exp
fib_index format
gcd
l2_norm
float flatten
join
nest_all
len
modf min
repeat_n iterate_n
append prime_factorization
is_prime pop
enqueue
lower_range
sgn split
tail translate
increment
random_seed
prime_factors_exp
binary_range splat_range
prime_factors
write_many
stack_rrot_n
bitwise_or
stack_lrot_n
bitwise_negate
exit
complex
write_all
discard_all
asin
acos
atan
atan2
asinh
acosh
atanh
repr
imag_unit
imag_mult
inverse numerics
sinh
cosh
tanh
mean
replace strings
strip
lstrip
rstrip
upper
lower
title
swapcase
mode
take_sign
function functions
pair_add
phase
call
complex_conjugate
find
conditional_exit
alpha_lower
enumerate
lists

degrees
int_base
add_two
subtract_two
half
quarter
str_base
stack_insert_up
stack_insert_down
filter
totient
prime_pi
stack_dup
coprime
chunk_number
rindex
reg0_add
reg1_add
pascal_row
middle
reg0_save
reg1_save
reg0_load
reg1_load
regn_save
regn_load

transpose
bin
hex
stack_dup_each
stack_dup_each_n
nest_n
shuffle
uniquify
reg_input
pi
e
is_unique
while_call
combinations
permutations
pow10
log10 log
pow2
log2 lg
ln2
first_n_truthy
re_im
chunk_length
ord_cp437
chr_cp437
nCr
nPr
b64decode
b64encode
base_digits
repeat_each
nth_input
gamma
product
sum
cumulative_sums
rms
double
slice


dig
toggle_preserve preserve_on preserve_off
phi
empty_string
intersection
eval
unary_negate swap_quotes
gte
lte
func_begin
func_end
divisors
int
radians
cartesian_product cartesian_power

sqrt
pow
square
write_all_safe
11 changes: 11 additions & 0 deletions gen_nice_names.py
@@ -0,0 +1,11 @@
#!/usr/bin/env python3

nice_names = {}
with open("docs/nice_names.txt") as f:
for line_num, line in enumerate(f):
for nice_name in line.split():
nice_names[nice_name] = line_num

with open('lib/nicenames.py', 'w') as f:
f.write("#!/usr/bin/env python3\n")
f.write("nice_names = " + repr(nice_names) + "\n")
2 changes: 2 additions & 0 deletions lib/nicenames.py
@@ -0,0 +1,2 @@
#!/usr/bin/env python3
nice_names = {'read_byte': 9, 'write': 10, 'unary_map': 11, 'binary_map': 12, 'parallel_map': 14, 'iterate': 20, 'read_all': 21, 'lcm': 30, 'gcd_reduce': 31, 'stack_size': 32, 'factorial': 33, 'list': 35, 'str': 36, 'mod': 37, 'bitwise_and': 38, 'stack_rrot': 40, 'stack_lrot': 41, 'multiply': 42, 'add': 43, 'concat': 43, 'read_line': 44, 'subtract': 45, 'asymmetric_difference': 45, 'write_line': 46, 'write_fn': 46, 'divide': 47, 'list_rrot': 47, 'copy': 59, 'less_than': 60, 'equal': 61, 'greater_than': 62, 'swap': 64, 'abs': 65, 'binary_randrange': 66, 'cos': 67, 'decrement': 68, 'stddev': 68, 'erf': 69, 'element': 69, 'fib': 70, 'first': 70, 'random': 71, 'hello_world': 72, 'head': 72, 'conditional': 73, 'unary_randrange': 74, 'random_choice': 74, 'ceil': 75, 'floor': 76, 'map': 77, 'max': 77, 'nnbb': 78, 'last': 78, 'ord': 79, 'ords': 79, 'nth_prime': 80, 'quine': 81, 'scoped_call': 82, 'reverse': 82, 'upper_range': 82, 'sin': 83, 'sort': 83, 'tangent': 84, 'set_element': 84, 'union': 85, 'random_uniform': 86, 'slices': 86, 'while_begin': 87, 'while_end': 87, 'discard': 88, 'logical_negate': 89, 'fixed_point': 89, 'zip': 90, 'zip_n': 90, 'floor_divide': 92, 'list_lrot': 92, 'xor': 94, 'ln': 95, 'stack_invert': 97, 'bool': 98, 'chr': 99, 'count': 99, 'dequeue': 100, 'divmod': 100, 'exp': 101, 'fib_index': 102, 'format': 102, 'gcd': 103, 'l2_norm': 104, 'float': 105, 'flatten': 105, 'join': 106, 'nest_all': 107, 'len': 108, 'modf': 109, 'min': 109, 'repeat_n': 110, 'iterate_n': 110, 'append': 111, 'prime_factorization': 111, 'is_prime': 112, 'pop': 112, 'enqueue': 113, 'lower_range': 114, 'sgn': 115, 'split': 115, 'tail': 116, 'translate': 116, 'increment': 117, 'random_seed': 118, 'prime_factors_exp': 119, 'binary_range': 120, 'splat_range': 120, 'prime_factors': 121, 'write_many': 122, 'stack_rrot_n': 123, 'bitwise_or': 124, 'stack_lrot_n': 125, 'bitwise_negate': 126, 'exit': 127, 'complex': 128, 'write_all': 129, 'discard_all': 130, 'asin': 131, 'acos': 132, 'atan': 133, 'atan2': 134, 'asinh': 135, 'acosh': 136, 'atanh': 137, 'repr': 138, 'imag_unit': 139, 'imag_mult': 140, 'inverse': 141, 'numerics': 141, 'sinh': 142, 'cosh': 143, 'tanh': 144, 'mean': 145, 'replace': 146, 'strings': 146, 'strip': 147, 'lstrip': 148, 'rstrip': 149, 'upper': 150, 'lower': 151, 'title': 152, 'swapcase': 153, 'mode': 154, 'take_sign': 155, 'function': 156, 'functions': 156, 'pair_add': 157, 'phase': 158, 'call': 159, 'complex_conjugate': 160, 'find': 161, 'conditional_exit': 162, 'alpha_lower': 163, 'enumerate': 164, 'lists': 165, 'degrees': 167, 'int_base': 168, 'add_two': 169, 'subtract_two': 170, 'half': 171, 'quarter': 172, 'str_base': 173, 'stack_insert_up': 174, 'stack_insert_down': 175, 'filter': 176, 'totient': 177, 'prime_pi': 178, 'stack_dup': 179, 'coprime': 180, 'chunk_number': 181, 'rindex': 182, 'reg0_add': 183, 'reg1_add': 184, 'pascal_row': 185, 'middle': 186, 'reg0_save': 187, 'reg1_save': 188, 'reg0_load': 189, 'reg1_load': 190, 'regn_save': 191, 'regn_load': 192, 'transpose': 194, 'bin': 195, 'hex': 196, 'stack_dup_each': 197, 'stack_dup_each_n': 198, 'nest_n': 199, 'shuffle': 200, 'uniquify': 201, 'reg_input': 202, 'pi': 203, 'e': 204, 'is_unique': 205, 'while_call': 206, 'combinations': 207, 'permutations': 208, 'pow10': 209, 'log10': 210, 'log': 210, 'pow2': 211, 'log2': 212, 'lg': 212, 'ln2': 213, 'first_n_truthy': 214, 're_im': 215, 'chunk_length': 216, 'ord_cp437': 217, 'chr_cp437': 218, 'nCr': 219, 'nPr': 220, 'b64decode': 221, 'b64encode': 222, 'base_digits': 223, 'repeat_each': 224, 'nth_input': 225, 'gamma': 226, 'product': 227, 'sum': 228, 'cumulative_sums': 229, 'rms': 230, 'double': 231, 'slice': 232, 'dig': 235, 'toggle_preserve': 236, 'preserve_on': 236, 'preserve_off': 236, 'phi': 237, 'empty_string': 238, 'intersection': 239, 'eval': 240, 'unary_negate': 241, 'swap_quotes': 241, 'gte': 242, 'lte': 243, 'func_begin': 244, 'func_end': 245, 'divisors': 246, 'int': 247, 'radians': 248, 'cartesian_product': 249, 'cartesian_power': 249, 'sqrt': 251, 'pow': 252, 'square': 253, 'write_all_safe': 254}
13 changes: 13 additions & 0 deletions seriously/seriously.py
Expand Up @@ -17,6 +17,7 @@
from . import SeriouslyCommands
from lib.cp437 import CP437
from lib.iterable import deque, as_list
from lib.nicenames import nice_names

anytype = SeriouslyCommands.anytype

Expand Down Expand Up @@ -262,6 +263,15 @@ def srs_exec(debug_mode=False, file_obj=None, code=None, ide_mode=False): # prag
def ide_mode():
SeriouslyCommands.fn_table[0xF0] = lambda x: x.push(literal_eval(x.pop()))

def minimize(code):
mini_code = ""
for cmd in code.split():
if cmd in nice_names:
mini_code += chr_cp437(nice_names[cmd])
else:
mini_code += cmd
return mini_code

def main(): # pragma: no cover
parser = argparse.ArgumentParser(
description="Run the Seriously interpreter")
Expand All @@ -271,6 +281,7 @@ def main(): # pragma: no cover
help="disable unsafe commands", action="store_true")
parser.add_argument("-N", "--no-input",
help="don't try to read input (equivalent to piping /dev/null)", action="store_true")
parser.add_argument("-n", "--nice-names", help="use nice names for readable code", action="store_true")
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument("-c", "--code", help="run the specified code")
group.add_argument("-f", "--file", help="specify an input file",
Expand All @@ -281,6 +292,8 @@ def main(): # pragma: no cover
if args.no_input:
sys.stdin = open(os.devnull, 'r')
atexit.register(lambda: sys.stdin.close())
if args.nice_names:
args.code = minimize(args.code)
srs_exec(args.debug, args.file, args.code, args.ide)

if __name__ == '__main__':
Expand Down
9 changes: 8 additions & 1 deletion seriously/test/tests.py
Expand Up @@ -9,7 +9,8 @@
import unittest
from lib.cp437 import CP437
from lib.iterable import as_list
from ..seriously import Seriously
from lib.nicenames import nice_names
from ..seriously import Seriously, minimize
from ..SeriouslyCommands import SeriousFunction
from ..probably_prime import probably_prime

Expand Down Expand Up @@ -51,6 +52,12 @@ def test_seriously_class(self):
srs.push(1)
srs.prepend(0)
self.assertEqual(srs.stack, collections.deque([0, 1]))

def test_nice_names(self):
for i, nice_name in enumerate(nice_names):
with self.subTest(i=i):
self.assertEqual(minimize(nice_name), chr_cp437(nice_names[nice_name]))
self.assertEqual(minimize("3 copy add square half"), "3;+²½")


class SeriousTest(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -13,7 +13,7 @@
setup(
name='seriously',

version='2.1.7',
version='2.1.8',

description='A Python-based golfing language',
long_description='Seriously is a Python-based golfing language. See the GitHub page for more details.',
Expand Down

0 comments on commit eb86a85

Please sign in to comment.