80 lines
2.1 KiB
Plaintext
80 lines
2.1 KiB
Plaintext
# This is a module
|
|
class SystemModule:
|
|
|
|
class HashMap:
|
|
def __init__(self):
|
|
self._get = __krk_builtin_hash_get
|
|
self._set = __krk_builtin_hash_set
|
|
self._map = __krk_builtin_hash_new()
|
|
def __get__(self, ind):
|
|
return self._get(self._map, ind)
|
|
def __set__(self, ind, val):
|
|
self._set(self._map, ind, val)
|
|
def __str__(self):
|
|
return "<HashMap>"
|
|
|
|
class List:
|
|
def __init__(self):
|
|
self._get = __krk_builtin_list_get
|
|
self._set = __krk_builtin_list_set
|
|
self._app = __krk_builtin_list_append
|
|
self._len = __krk_builtin_list_length
|
|
self._list = __krk_builtin_list_new()
|
|
def __get__(self, ind):
|
|
return self._get(self._list, ind)
|
|
def __set__(self, ind, val):
|
|
return self._set(self._list, ind, val)
|
|
def append(self, val):
|
|
return self._app(self._list, val)
|
|
def length(self):
|
|
return self._len(self._list)
|
|
def __str__(self):
|
|
let base = "["
|
|
let len = self._len(self._list)
|
|
for i = 0, i < len, i = i + 1:
|
|
if i > 0:
|
|
base = base + ", "
|
|
base = base + self._get(self._list,i)
|
|
return base + "]"
|
|
def __iter__(self):
|
|
let me = self
|
|
def makeIter(ind):
|
|
let l = me
|
|
let len = l.length()
|
|
let i = ind
|
|
def iter():
|
|
if i >= len:
|
|
return iter
|
|
let out = l[i]
|
|
i = i + 1
|
|
return out
|
|
return iter
|
|
return makeIter(0)
|
|
|
|
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)
|
|
|
|
let module = SystemModule()
|
|
module.sleep = __krk_builtin_sleep
|
|
|
|
module.HashMap = HashMap
|
|
module.List = List
|
|
module.Range = Range
|
|
|
|
return module
|