class Path(Object): _type = Type(u"pixie.path.Path") def __init__(self, top): self._path = rt.name(top) # keyword args don't seem to work nicely. #def rel_path(self, other): # "Returns the path relative to other path" # return rt.wrap(str(os.path.relpath(self._path, start=other._path))) def abs_path(self): "Returns the absolute path" return rt.wrap(os.path.abspath(str(self._path))) # Basename doesn't play well with pypy... #def basename(self): # return rt.wrap(rt.name(os.path.basename("a"))) def exists(self): return true if os.path.exists(str(self._path)) else false def is_file(self): return true if os.path.isfile(str(self._path)) else false def is_dir(self): return true if os.path.isdir(str(self._path)) else false
class Keyword(Object): _type = Type(u"pixie.stdlib.Keyword") __immutable_fields__ = ["_hash"] def __init__(self, name): self._str = name self._w_name = None self._w_ns = None self._hash = 0 def type(self): return Keyword._type def init_names(self): if self._w_name is None: s = self._str.split(u"/") if len(s) == 2: self._w_ns = rt.wrap(s[0]) self._w_name = rt.wrap(s[1]) elif len(s) == 1: self._w_name = rt.wrap(s[0]) self._w_ns = nil else: self._w_ns = rt.wrap(s[0]) self._w_name = rt.wrap(u"/".join(s[1:]))
class Environment(Object): _type = Type(u"pixie.stdlib.Environment") def type(self): return Environment._type def val_at(self, key, not_found): if not isinstance(key, String): runtime_error(u"Environment variables are strings ") key_str = str(rt.name(key)) try: var = os.environ[key_str] return rt.wrap(var) except KeyError: return not_found # TODO: Implement me. # def dissoc(self): # def asssoc(self): def reduce_vars(self, f, init): for k, v in os.environ.items(): init = f.invoke([init, rt.map_entry(rt.wrap(k), rt.wrap(v))]) if rt.reduced_QMARK_(init): return init return init
class FileList(Object): _type = Type(u"pixie.path.FileList") def type(self): return FileList._type def __init__(self, top): self._top = rt.name(top)
class AbstractMutableCell(Object): _type = Type(u"pixie.stdlib.AbstractMutableCell") def set_mutable_cell_value(self, ct, fields, nm, idx, value): pass def get_mutable_cell_value(self): pass
class NativeIterator(Object): _type = Type(u"pixie.vm.NativeIterator") def type(self): return NativeIterator._type def __init__(self): pass
class Lock(Object): _type = Type(u"pixie.stdlib.Lock") def __init__(self, ll_lock): self._ll_lock = ll_lock def type(self): return Lock._type
class WriterBox(Object): _type = Type(u"pixie.stdlib.WriterBox") def __init__(self, wtr): self._pxic_writer = wtr def get_pxic_writer(self): return self._pxic_writer
class String(Object): _type = Type(u"pixie.stdlib.String") def type(self): return String._type def __init__(self, s): #assert isinstance(s, unicode) self._str = s
class Character(Object): _type = Type(u"pixie.stdlib.Character") _immutable_fields_ = ["_char_val"] def __init__(self, i): assert isinstance(i, int) self._char_val = i def char_val(self): return self._char_val
class StringBuilder(Object): _type = Type(u"pixie.stdlib.StringBuilder") def __init__(self): self._strs = [] def add_str(self, s): self._strs.append(s) return self def to_string(self): return u"".join(self._strs)
class EmptyIterator(Object): _type = Type(u"pixie.vm.Iterator") def type(self): return EmptyIterator._type def __init__(self): pass def move_next(self): runtime_error(u"Empty Iterator") def at_end(self): return True
class ShallowContinuation(Object): _type = Type(u"pixie.stdlib.ShallowContinuation") def __init__(self, frame, val): assert isinstance(frame, Frame) self._frame = frame self._val = val def is_finished(self): return self._frame.finished def invoke(self, args): affirm(len(args) == 1, u"Generators only take one argument") self._frame.push(args[0]) val = interpret(frame=self._frame) self._val = val return self._val
class StackletHandle(Object): _type = Type(u"StackletHandle") def __init__(self, h): self._stacklet_handle = h self._used = False def type(self): return self._type def invoke(self, args): affirm(not self._used, u"Can only call a given stacklet handle once.") affirm(len(args) == 1, u"Only one arg should be handed to a stacklet handle") self._used = True global_state._val = args[0] new_h = StackletHandle(global_state._th.switch(self._stacklet_handle)) val = global_state._val global_state._val = None return rt.vector(new_h, val)
class HashingState(Object): _type = Type(u"pixie.stdlib.HashingState") def __init__(self): self._n = r_uint(0) self._hash = r_uint(1) def update_hash_ordered(self, itm): self._n += 1 self._hash = 31 * self._hash + rt.hash(itm) return self def update_hash_unordered(self, itm): self._n += 1 self._hash += rt.hash(itm) return self def finish(self): return rt.wrap(intmask(mix_coll_hash(self._hash, self._n)))
def __init__(self, name, slots): Type.__init__(self, name) self._slots = slots
def __init__(self, name, slots): Type.__init__(self, name) self._slots = slots self._mutable_slots = {} self._rev = 0