コード例 #1
0
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
コード例 #2
0
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:]))
コード例 #3
0
ファイル: env.py プロジェクト: stuarth/pixie
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
コード例 #4
0
class FileList(Object):
    _type = Type(u"pixie.path.FileList")

    def type(self):
        return FileList._type

    def __init__(self, top):
        self._top = rt.name(top)
コード例 #5
0
ファイル: custom_types.py プロジェクト: zen3d/pixie
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
コード例 #6
0
class NativeIterator(Object):
    _type = Type(u"pixie.vm.NativeIterator")

    def type(self):
        return NativeIterator._type

    def __init__(self):
        pass
コード例 #7
0
ファイル: threads.py プロジェクト: kgann/pixie
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
コード例 #8
0
ファイル: writer.py プロジェクト: zen3d/pixie
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
コード例 #9
0
ファイル: string.py プロジェクト: mwfogleman/pixie
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
コード例 #10
0
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
コード例 #11
0
ファイル: string_builder.py プロジェクト: linpingchuan/pixie
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)
コード例 #12
0
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
コード例 #13
0
ファイル: interpreter.py プロジェクト: zen3d/pixie
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
コード例 #14
0
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)
コード例 #15
0
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)))
コード例 #16
0
ファイル: custom_types.py プロジェクト: andrewchambers/pixie
    def __init__(self, name, slots):
        Type.__init__(self, name)

        self._slots = slots
コード例 #17
0
ファイル: custom_types.py プロジェクト: mwfogleman/pixie
    def __init__(self, name, slots):
        Type.__init__(self, name)

        self._slots = slots
コード例 #18
0
ファイル: custom_types.py プロジェクト: kidaa/pixie
    def __init__(self, name, slots):
        Type.__init__(self, name)

        self._slots = slots
        self._mutable_slots = {}
        self._rev = 0
コード例 #19
0
ファイル: custom_types.py プロジェクト: zen3d/pixie
    def __init__(self, name, slots):
        Type.__init__(self, name)

        self._slots = slots
        self._mutable_slots = {}
        self._rev = 0