Skip to content

Commit

Permalink
Change the _$rapyd$_ prefix to ρσ -- makes the output javascript a bi…
Browse files Browse the repository at this point in the history
…t easier on the eyes
  • Loading branch information
kovidgoyal committed Apr 4, 2016
1 parent 2deceb4 commit ce061ef
Show file tree
Hide file tree
Showing 28 changed files with 4,055 additions and 4,035 deletions.
1,809 changes: 907 additions & 902 deletions release/baselib-plain-pretty.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion release/baselib-plain-ugly.js

Large diffs are not rendered by default.

5,357 changes: 2,680 additions & 2,677 deletions release/compiler.js

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions release/signatures.json
@@ -1,29 +1,29 @@
{
"ast": "2ffb06bfac170055031655fbf1fb6b2c60c318c1",
"baselib-builtins": "7622ded7ac7554284091fa3448f6872f3af3203e",
"baselib-containers": "0a6a18e0b083bd80a71c9eabe4b3d7a7f1636303",
"baselib-builtins": "b0fe2ee19fe9e5f1a680144a799673d6176ea7ff",
"baselib-containers": "c7c6167f1fbe64a9eea1b2f660ad16ac07ec1b76",
"baselib-errors": "d89289f661d151bdf13e4c9fbaa190f6a47ef9b4",
"baselib-internal": "bbe182a48607408fc9f822a770c3413a8718b8ac",
"baselib-itertools": "b2e1f37770fbce50d73c1d517239906a791234d0",
"baselib-str": "c94c2809d5732e2ff4706560bcc963cbf5b39ca0",
"compiler": "a8c4f5c83735825d001338b2ac512455df815ea2",
"baselib-internal": "131c8f21e91570dd1c82123e5212517de2a0a279",
"baselib-itertools": "59cb238f416d6aa870b3a23103eb0db3ec21c358",
"baselib-str": "984918972c49d5e696d65042bd191b0be8ec199d",
"compiler": "1025d6c09b50693390fc2f9e2ebf1a21ae6e7ddd",
"errors": "eb15520287db559585bbc9bdb934f9dc7f593f0a",
"output/__init__": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
"output/classes": "db67442888cf47d4eadecbfefd2ed667789bc2e0",
"output/classes": "b847ec63aa802df3eed2351435c5cb6598765d02",
"output/codegen": "50888c9a644d13b54a2172d97f90c6d370954dfe",
"output/exceptions": "01fd24b1988189c262920ef3eed4146116299388",
"output/functions": "07c28eeac2459eff035dbc21b1de16a633900489",
"output/literals": "676edde0f3bda8cf6859c7153f7f41edf4aaa405",
"output/loops": "e79ed218f3093848e312471e06b6f4cf71663fab",
"output/modules": "0eeedbe99a346ced44cda15dd4e946a27ec43219",
"output/operators": "682149c4fdbd7800b48aeaca18e840b2bc315c80",
"output/statements": "acfd075a5a5b22887f19cf00a0bbf7a02fdfd05f",
"output/stream": "1f4ba7755d3b895b33c8879129d72caba6ad3407",
"output/exceptions": "52eed88cebe6256639486ec4eb58fb237088a21d",
"output/functions": "1bff87504c4c88de5f79aa3a68cca0bdd126e065",
"output/literals": "8826871917ae49b68bd4f65d833cdab97371dfc6",
"output/loops": "b74d0059c66ee0a047fa0585392948dd85da7077",
"output/modules": "e0c3485de6a68a3bb74a8848a64deda97969a520",
"output/operators": "ab41febe915eaf902a4e8a0b8ef72efdb2162632",
"output/statements": "8cea61995f40ce7a69623055ce4353976addff85",
"output/stream": "234e1c59f9ae5df09137e5328257ca50bbc98fc0",
"output/utils": "4b13b86ab7e79d421105e6a75eabfd51c128d059",
"parse": "bc945d6ef6a60f0a83ab35e9330af9906c932d4a",
"parse": "e4c55e0f34978fafafd55d21598ca7bcaa32577d",
"tokenizer": "e9e533c7df7e260e082a2a89f8b56277e8a3678b",
"unicode_aliases": "79ac6eaa5e6be44a5397d62c561f854a8fe7528e",
"utils": "e48872a930dbc0c840e4c70dda2600a98a860a4d",
"#compiler#": "2acebc9789c6fc6a7b6efeb95703d502c2d83256",
"#compiled_with#": "2acebc9789c6fc6a7b6efeb95703d502c2d83256"
"#compiler#": "41cbb4c5d1a64543dcd986cd012dcd5380685903",
"#compiled_with#": "41cbb4c5d1a64543dcd986cd012dcd5380685903"
}
2 changes: 2 additions & 0 deletions session.vim
@@ -1,2 +1,4 @@
set wildignore+=*.pyj-cached
set wildignore+=node_modules
imap <F4> ρσ_
cmap <F4> ρσ_
94 changes: 47 additions & 47 deletions src/baselib-builtins.pyj
Expand Up @@ -2,12 +2,12 @@
# License: BSD
# Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>

# globals: exports, console, _$rapyd$_iterator_symbol, _$rapyd$_kwargs_symbol, _$rapyd$_arraylike, _$rapyd$_list_contains
# globals: exports, console, ρσ_iterator_symbol, ρσ_kwargs_symbol, ρσ_arraylike, ρσ_list_contains

def _$rapyd$_bool(val):
def ρσ_bool(val):
return v'!!val'

def _$rapyd$_eslice(arr, step, start, end):
def ρσ_eslice(arr, step, start, end):
arr = arr[:]
if type(arr) is 'string' or isinstance(arr, String):
isString = True
Expand All @@ -24,26 +24,26 @@ def _$rapyd$_eslice(arr, step, start, end):
arr = arr.slice(start, end).filter(def(e, i): return i % step is 0;)
return isString ? arr.join('') : arr

def _$rapyd$_print():
def ρσ_print():
if v'typeof console' is 'object':
parts = v'[]'
for v'var i = 0; i < arguments.length; i++':
parts.push(_$rapyd$_str(arguments[i])) # noqa: undef
parts.push(ρσ_str(arguments[i])) # noqa: undef
console.log(parts.join(' '))

def _$rapyd$_int(val, base):
def ρσ_int(val, base):
ans = parseInt(val, base or 10)
if isNaN(ans):
raise ValueError('Invalid literal for int with base ' + (base or 10) + ': ' + val)
return ans

def _$rapyd$_float():
def ρσ_float():
ans = parseFloat.apply(None, arguments)
if isNaN(ans):
raise ValueError('Could not convert string to float: ' + arguments[0])
return ans

def _$rapyd$_arraylike_creator():
def ρσ_arraylike_creator():
names = 'Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array'.split(' ')
if type(HTMLCollection) is 'function':
names = names.concat('HTMLCollection NodeList NamedNodeMap'.split(' '))
Expand All @@ -55,21 +55,21 @@ def _$rapyd$_arraylike_creator():
def options_object(f):
return def():
if v'typeof arguments[arguments.length - 1] === "object"':
arguments[arguments.length - 1][_$rapyd$_kwargs_symbol] = True
arguments[arguments.length - 1][ρσ_kwargs_symbol] = True
return f.apply(this, arguments)

def _$rapyd$_id(x):
return x._$rapyd$_object_id
def ρσ_id(x):
return x.ρσ_object_id

def _$rapyd$_dir(item):
def ρσ_dir(item):
# TODO: this isn't really representative of real Python's dir(), nor is it
# an intuitive replacement for "for ... in" loop, need to update this logic
# and introduce a different way of achieving "for ... in"
arr = []
for v'var i in item': arr.push(i) # noqa:undef
return arr

def _$rapyd$_ord(x):
def ρσ_ord(x):
ans = x.charCodeAt(0)
if 0xD800 <= ans <= 0xDBFF:
second = x.charCodeAt(1)
Expand All @@ -78,16 +78,16 @@ def _$rapyd$_ord(x):
raise TypeError('string is missing the low surrogate char')
return ans

def _$rapyd$_chr(code):
def ρσ_chr(code):
if code <= 0xFFFF:
return String.fromCharCode(code)
code -= 0x10000
return String.fromCharCode(0xD800+(code>>10), 0xDC00+(code&0x3FF))

def _$rapyd$_callable(x):
def ρσ_callable(x):
return v'typeof x === "function"'

def _$rapyd$_bin(x):
def ρσ_bin(x):
if type(x) is not 'number' or x % 1 is not 0:
raise TypeError('integer required')
ans = x.toString(2)
Expand All @@ -97,7 +97,7 @@ def _$rapyd$_bin(x):
ans = '0b' + ans
return ans

def _$rapyd$_hex(x):
def ρσ_hex(x):
if type(x) is not 'number' or x % 1 is not 0:
raise TypeError('integer required')
ans = x.toString(16)
Expand All @@ -107,8 +107,8 @@ def _$rapyd$_hex(x):
ans = '0x' + ans
return ans

def _$rapyd$_enumerate(iterable):
if _$rapyd$_arraylike(iterable):
def ρσ_enumerate(iterable):
if ρσ_arraylike(iterable):
ans = {
'_i': -1,
'next':def():
Expand All @@ -117,11 +117,11 @@ def _$rapyd$_enumerate(iterable):
return {'done':False, 'value':[this._i, iterable[this._i]]}
return {'done':True}
}
ans[_$rapyd$_iterator_symbol] = def():
ans[ρσ_iterator_symbol] = def():
return this
return ans
if type(iterable[_$rapyd$_iterator_symbol]) is 'function':
iterator = (type(Map) is 'function' and isinstance(iterable, Map)) ? iterable.keys() : iterable[_$rapyd$_iterator_symbol]()
if type(iterable[ρσ_iterator_symbol]) is 'function':
iterator = (type(Map) is 'function' and isinstance(iterable, Map)) ? iterable.keys() : iterable[ρσ_iterator_symbol]()
ans = {
'_iterator':iterator,
'_i': -1,
Expand All @@ -132,13 +132,13 @@ def _$rapyd$_enumerate(iterable):
this._i += 1
return {'done':False, 'value':[this._i, r.value]}
}
ans[_$rapyd$_iterator_symbol] = def():
ans[ρσ_iterator_symbol] = def():
return this
return ans
return _$rapyd$_enumerate(Object.keys(iterable))
return ρσ_enumerate(Object.keys(iterable))

def _$rapyd$_reversed(iterable):
if _$rapyd$_arraylike(iterable):
def ρσ_reversed(iterable):
if ρσ_arraylike(iterable):
ans = {
'_i': iterable.length,
'next':def():
Expand All @@ -147,16 +147,16 @@ def _$rapyd$_reversed(iterable):
return {'done':False, 'value':iterable[this._i]}
return {'done':True}
}
ans[_$rapyd$_iterator_symbol] = def():
ans[ρσ_iterator_symbol] = def():
return this
return ans
raise TypeError('reversed() can only be called on arrays or strings')

def _$rapyd$_iter(iterable):
def ρσ_iter(iterable):
# Generate a JavaScript iterator object from iterable
if type(iterable[_$rapyd$_iterator_symbol]) is 'function':
return (type(Map) is 'function' and isinstance(iterable, Map)) ? iterable.keys() : iterable[_$rapyd$_iterator_symbol]()
if _$rapyd$_arraylike(iterable):
if type(iterable[ρσ_iterator_symbol]) is 'function':
return (type(Map) is 'function' and isinstance(iterable, Map)) ? iterable.keys() : iterable[ρσ_iterator_symbol]()
if ρσ_arraylike(iterable):
ans = {
'_i': -1,
'next':def():
Expand All @@ -165,19 +165,19 @@ def _$rapyd$_iter(iterable):
return {'done':False, 'value':iterable[this._i]}
return {'done':True}
}
ans[_$rapyd$_iterator_symbol] = def():
ans[ρσ_iterator_symbol] = def():
return this
return ans
return _$rapyd$_iter(Object.keys(iterable))
return ρσ_iter(Object.keys(iterable))

def _$rapyd$_range(start, stop, step):
def ρσ_range(start, stop, step):
if arguments.length <= 1:
stop = start or 0
start = 0
step = arguments[2] or 1
length = Math.max(Math.ceil((stop - start) / step), 0)
return {
_$rapyd$_iterator_symbol: def(): return this;,
ρσ_iterator_symbol: def(): return this;,
'_i': start - step,
'_idx': -1,
'next': def():
Expand All @@ -189,7 +189,7 @@ def _$rapyd$_range(start, stop, step):
,
}

def _$rapyd$_getattr(obj, name, defval):
def ρσ_getattr(obj, name, defval):
try:
ret = obj[name]
except TypeError:
Expand All @@ -202,32 +202,32 @@ def _$rapyd$_getattr(obj, name, defval):
ret = defval
return ret

def _$rapyd$_setattr(obj, name, value):
def ρσ_setattr(obj, name, value):
obj[name] = value

def _$rapyd$_hasattr(obj, name):
def ρσ_hasattr(obj, name):
return v'name in obj'

_$rapyd$_len = (def ():
ρσ_len = (def ():

def len(obj):
if _$rapyd$_arraylike(obj): return obj.length
if ρσ_arraylike(obj): return obj.length
if type(obj.__len__) is 'function': return obj.__len__()
if v'obj instanceof Set' or v'obj instanceof Map': return obj.size
return Object.keys(obj).length

def len5(obj):
if _$rapyd$_arraylike(obj): return obj.length
if ρσ_arraylike(obj): return obj.length
if type(obj.__len__) is 'function': return obj.__len__()
return Object.keys(obj).length

return len if v'typeof Set' is 'function' and v'typeof Map' is 'function' else len5
)()


v'var abs = Math.abs, max = Math.max, min = Math.min, bool = _$rapyd$_bool'
v'var float = _$rapyd$_float, int = _$rapyd$_int, arraylike = _$rapyd$_arraylike_creator(), _$rapyd$_arraylike = arraylike'
v'var print = _$rapyd$_print, eslice = _$rapyd$_eslice, id = _$rapyd$_id'
v'var dir = _$rapyd$_dir, ord = _$rapyd$_ord, chr = _$rapyd$_chr, bin = _$rapyd$_bin, hex = _$rapyd$_hex, callable = _$rapyd$_callable'
v'var enumerate = _$rapyd$_enumerate, iter = _$rapyd$_iter, reversed = _$rapyd$_reversed, len = _$rapyd$_len'
v'var range = _$rapyd$_range, getattr = _$rapyd$_getattr, setattr = _$rapyd$_setattr, hasattr = _$rapyd$_hasattr'
v'var abs = Math.abs, max = Math.max, min = Math.min, bool = ρσ_bool'
v'var float = ρσ_float, int = ρσ_int, arraylike = ρσ_arraylike_creator(), ρσ_arraylike = arraylike'
v'var print = ρσ_print, eslice = ρσ_eslice, id = ρσ_id'
v'var dir = ρσ_dir, ord = ρσ_ord, chr = ρσ_chr, bin = ρσ_bin, hex = ρσ_hex, callable = ρσ_callable'
v'var enumerate = ρσ_enumerate, iter = ρσ_iter, reversed = ρσ_reversed, len = ρσ_len'
v'var range = ρσ_range, getattr = ρσ_getattr, setattr = ρσ_setattr, hasattr = ρσ_hasattr'

0 comments on commit ce061ef

Please sign in to comment.