2020-12-28 14:38:26 +03:00
|
|
|
class list():
|
2020-12-30 10:59:21 +03:00
|
|
|
"Resizable array with direct constant-time indexing."
|
2020-12-30 04:08:21 +03:00
|
|
|
def extend(i):
|
2020-12-30 10:59:21 +03:00
|
|
|
"Add all entries from an iterable to the end of this list."
|
2020-12-30 04:08:21 +03:00
|
|
|
for v in i:
|
|
|
|
self.append(v)
|
2020-12-30 09:50:26 +03:00
|
|
|
return self.__len__()
|
2021-01-02 08:28:37 +03:00
|
|
|
def __str__(self): return self.__repr__()
|
|
|
|
def __repr__(self):
|
|
|
|
if self.__inrepr: return "[...]"
|
|
|
|
self.__inrepr=1
|
2021-01-01 04:42:16 +03:00
|
|
|
let b="["
|
|
|
|
let l=self.__len__()
|
2020-12-30 04:08:21 +03:00
|
|
|
for i=0,i<l,i=i+1:
|
|
|
|
if i>0:
|
2021-01-01 04:42:16 +03:00
|
|
|
b+=", "
|
2021-01-01 14:52:18 +03:00
|
|
|
b+=repr(self[i])
|
2021-01-02 08:28:37 +03:00
|
|
|
self.__inrepr=0
|
2020-12-30 04:08:21 +03:00
|
|
|
return b+"]"
|
|
|
|
def __iter__(self):
|
|
|
|
let m = self
|
|
|
|
def I(i):
|
|
|
|
let e=m
|
2020-12-30 09:50:26 +03:00
|
|
|
let l=e.__len__()
|
2020-12-30 04:08:21 +03:00
|
|
|
let x=i
|
|
|
|
def _():
|
|
|
|
if x>=l:
|
|
|
|
return _
|
|
|
|
let o=e[x]
|
2021-01-01 04:42:16 +03:00
|
|
|
x++
|
2020-12-30 04:08:21 +03:00
|
|
|
return o
|
|
|
|
return _
|
|
|
|
return I(0)
|
2020-12-28 13:25:33 +03:00
|
|
|
|
2020-12-28 14:38:26 +03:00
|
|
|
class dict():
|
2020-12-30 10:59:21 +03:00
|
|
|
"Hashmap of arbitrary keys to arbitrary values."
|
2021-01-02 08:28:37 +03:00
|
|
|
def __str__(self): return self.__repr__()
|
|
|
|
def __repr__(self):
|
|
|
|
if self.__inrepr: return "{...}"
|
|
|
|
self.__inrepr = 1
|
2020-12-30 04:08:21 +03:00
|
|
|
let out = "{"
|
|
|
|
let first = True
|
|
|
|
for v in self.keys():
|
|
|
|
if not first:
|
2021-01-01 04:42:16 +03:00
|
|
|
out += ", "
|
2020-12-30 04:08:21 +03:00
|
|
|
first = False
|
2021-01-02 08:28:37 +03:00
|
|
|
out += v.__repr__() + ": " + self[v].__repr__()
|
2021-01-01 04:42:16 +03:00
|
|
|
out += "}"
|
2021-01-02 08:28:37 +03:00
|
|
|
self.__inrepr = 0
|
2020-12-30 04:08:21 +03:00
|
|
|
return out
|
|
|
|
def keys(self):
|
2020-12-30 10:59:21 +03:00
|
|
|
"Returns an iterable of the keys in this dictionary."
|
2020-12-30 04:08:21 +03:00
|
|
|
class KeyIterator():
|
|
|
|
def __init__(self, target):
|
|
|
|
self.target = target
|
|
|
|
def __iter__(self):
|
|
|
|
let me = self
|
|
|
|
def makeIter(ind):
|
|
|
|
let m = me.target
|
|
|
|
let c = m.capacity()
|
|
|
|
let i = ind
|
|
|
|
def iter():
|
|
|
|
let out = None
|
|
|
|
while out == None and i < c:
|
2021-01-01 14:52:18 +03:00
|
|
|
out = m._key_at_index(i)
|
2021-01-01 04:42:16 +03:00
|
|
|
i++
|
2020-12-30 04:08:21 +03:00
|
|
|
if out == None:
|
|
|
|
return iter
|
|
|
|
else:
|
|
|
|
return out
|
|
|
|
return iter
|
|
|
|
return makeIter(0)
|
|
|
|
return KeyIterator(self)
|
2020-12-28 13:25:33 +03:00
|
|
|
|
|
|
|
class range:
|
2020-12-30 10:59:21 +03:00
|
|
|
"Helpful iterable."
|
2020-12-30 04:08:21 +03:00
|
|
|
def __init__(self, min, max):
|
|
|
|
self.min = min
|
|
|
|
self.max = max
|
|
|
|
def __iter__(self):
|
|
|
|
let me = self
|
|
|
|
def makeIter(ind):
|
|
|
|
let l = me
|
|
|
|
let i = ind
|
|
|
|
def iter():
|
|
|
|
if i >= l.max:
|
|
|
|
return iter
|
|
|
|
let out = i
|
2021-01-01 04:42:16 +03:00
|
|
|
i++
|
2020-12-30 04:08:21 +03:00
|
|
|
return out
|
|
|
|
return iter
|
|
|
|
return makeIter(self.min)
|
2020-12-28 13:25:33 +03:00
|
|
|
|
2020-12-30 09:50:26 +03:00
|
|
|
def len(obj=None): return (obj and obj.__len__()) or 0
|
2021-01-01 10:01:58 +03:00
|
|
|
def str(obj=None): return (obj and obj.__str__()) or ""
|
|
|
|
def repr(obj): return obj.__repr__()
|
2020-12-30 06:28:18 +03:00
|
|
|
def int(obj=None): return (obj and obj.__int__()) or 0
|
|
|
|
def float(obj=None): return (obj and obj.__float__()) or 0.0
|
2021-01-01 10:01:58 +03:00
|
|
|
def type(obj): return obj.__class__
|
2020-12-30 06:28:18 +03:00
|
|
|
def dir(obj): return obj.__dir__()
|
2020-12-28 13:25:33 +03:00
|
|
|
|
2020-12-30 10:59:21 +03:00
|
|
|
def help(obj=None):
|
|
|
|
if not obj:
|
|
|
|
print "Kuroko - Interpreted bytecode VM."
|
|
|
|
print " usage:"
|
|
|
|
print " help() - Displays this message."
|
|
|
|
print " help(func) - Displays docstring for function, if present."
|
|
|
|
print " help(class) - Displays docstring for class, if present."
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
print obj.__doc__
|
|
|
|
except:
|
|
|
|
print "No docstring available for", obj
|
|
|
|
|
2021-01-01 10:01:58 +03:00
|
|
|
export list,dict,range,len,str,repr,int,float,dir,help
|
2020-12-28 13:25:33 +03:00
|
|
|
|
2020-12-31 09:48:39 +03:00
|
|
|
__builtins__.module_paths = ["./","./modules/","/home/klange/Projects/kuroko/modules/","/usr/share/kuroko/"]
|
|
|
|
|
2020-12-28 13:25:33 +03:00
|
|
|
return object()
|