kuroko/builtins.krk

109 lines
2.3 KiB
Plaintext

class list():
def __init__():
self._list=__builtins__.list_new()
def __get__(i):
return __builtins__.list_get(self._list,i)
def __set__(i,v):
return __builtins__.list_set(self._list,i,v)
def append(v):
return __builtins__.list_append(self._list,v)
def length():
return __builtins__.list_length(self._list)
def extend(i):
for v in i:
self.append(v)
return self.length()
def __str__(self):
let b = "["
let l = self.length()
for i=0,i<l,i=i+1:
if i>0:
b=b+", "
b=b+__builtins__.list_get(self._list,i)
return b+"]"
def __iter__(self):
let m = self
def I(i):
let e=m
let l=e.length()
let x=i
def _():
if x>=l:
return _
let o=e[x]
x=x+1
return o
return _
return I(0)
class dict():
def __init__(self):
self._map = __builtins__.hash_new()
def __get__(self, ind):
return __builtins__.hash_get(self._map, ind)
def __set__(self, ind, val):
return __builtins__.hash_set(self._map, ind, val)
def __str__(self):
let out = "{"
let first = True
for v in self.keys():
if not first:
out = out + ", "
first = False
out = out + v + ": " + self[v]
out = out + "}"
return out
def length(self):
return __builtins__.hash_count(self._map)
def capacity(self):
return __builtins__.hash_capacity(self._map)
def keys(self):
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:
out = __builtins__.hash_key_at_index(m._map,i)
i = i + 1
if out == None:
return iter
else:
return out
return iter
return makeIter(0)
return KeyIterator(self)
class range:
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
i = i + 1
return out
return iter
return makeIter(self.min)
def len(obj): return obj.length()
def str(obj): return "" + obj
def int(obj): return obj.__int__()
def float(obj): return obj.__float__()
export list,dict,range,len,str,int,float
return object()