Ejemplo n.º 1
0
    def syntax_quote(form):
        if isinstance(form, Symbol) and compiler.is_compiler_special(form):
            ret = rt.list(QUOTE, form)

        elif isinstance(form, Symbol):
            if rt.namespace(form) is None and rt.name(form).endswith("#"):
                gmap = rt.deref(GEN_SYM_ENV)
                affirm(gmap is not nil, u"Gensym literal used outside a syntax quote")
                gs = rt.get(gmap, form)
                if gs is nil:
                    gs = rt.symbol(rt.str(form, rt.wrap(u"__"), rt.gensym()))
                    GEN_SYM_ENV.set_value(rt.assoc(gmap, form, gs))
                form = gs
            else:
                var = rt.resolve_in(compiler.NS_VAR.deref(), form)
                if var is nil:
                    form = rt.symbol(rt.str(rt.wrap(rt.name(rt.deref(compiler.NS_VAR))), rt.wrap(u"/"), form))
                else:
                    form = rt.symbol(rt.str(rt.wrap(rt.namespace(var)), rt.wrap(u"/"), rt.str(rt.wrap(rt.name(var)))))
            ret = rt.list(QUOTE, form)
        elif is_unquote(form):
            ret = rt.first(rt.next(form))
        elif is_unquote_splicing(form):
            return runtime_error(u"Unquote splicing not used inside list")
        elif rt.vector_QMARK_(form) is true:
            ret = rt.list(APPLY, CONCAT, SyntaxQuoteReader.expand_list(form))
        elif rt.map_QMARK_(form) is true:
            mes = SyntaxQuoteReader.flatten_map(form)
            ret = rt.list(APPLY, HASHMAP, rt.list(APPLY, CONCAT, SyntaxQuoteReader.expand_list(mes)))
        elif form is not nil and rt.seq_QMARK_(form) is true:
            ret = rt.list(APPLY, LIST, rt.cons(CONCAT, SyntaxQuoteReader.expand_list(rt.seq(form))))
        else:
            ret = rt.list(QUOTE, form)
        return ret
Ejemplo n.º 2
0
    def load_lib(self):
        if not self._is_inited:
            load_paths = rt.deref(rt.deref(rt.load_paths))

            for x in range(rt.count(load_paths)):
                s = rffi.str2charp(
                    str(rt.name(rt.nth(load_paths, rt.wrap(x)))) + "/" +
                    str(self._name))
                try:
                    self._dyn_lib = dynload.dlopen(s)
                    self._is_inited = True
                except dynload.DLOpenError as ex:
                    continue
                finally:
                    rffi.free_charp(s)
                break

            if not self._is_inited:
                s = rffi.str2charp(str(self._name))
                try:
                    self._dyn_lib = dynload.dlopen(s)
                    self._is_inited = True
                except dynload.DLOpenError as ex:
                    raise object.runtime_error(
                        u"Couldn't Load Library: " + self._name,
                        u"pixie.stdlib/LibraryNotFoundException")
                finally:
                    rffi.free_charp(s)
Ejemplo n.º 3
0
def load_ns(filename):
    import pixie.vm.string as string
    import pixie.vm.symbol as symbol

    if isinstance(filename, symbol.Symbol):
        affirm(
            rt.namespace(filename) is None,
            u"load-file takes a un-namespaced symbol")
        filename_str = rt.name(filename).replace(u".", u"/") + u".pxi"

        loaded_ns = code._ns_registry.get(rt.name(filename), None)
        if loaded_ns is not None:
            return loaded_ns
    else:
        affirm(isinstance(filename, string.String), u"Filename must be string")
        filename_str = rt.name(filename)

    paths = rt.deref(rt.deref(rt.load_paths))
    f = None
    for x in range(rt.count(paths)):
        path_x = rt.nth(paths, rt.wrap(x))
        affirm(isinstance(path_x, string.String),
               u"Contents of load-paths must be strings")
        full_path = path.join(str(rt.name(path_x)), str(filename_str))
        if path.isfile(full_path):
            f = full_path
            break

    if f is None:
        affirm(
            False, u"File '" + rt.name(filename) +
            u"' does not exist in any directory found in load-paths")
    else:
        rt.load_file(rt.wrap(f))
    return nil
Ejemplo n.º 4
0
    def syntax_quote(form):
        if isinstance(form, Symbol) and compiler.is_compiler_special(form):
            ret = rt.list(QUOTE, form)

        elif isinstance(form, Symbol):
            if rt.namespace(form) is None and rt.name(form).endswith("#"):
                gmap = rt.deref(GEN_SYM_ENV)
                affirm(gmap is not nil, u"Gensym literal used outside a syntax quote")
                gs = rt.get(gmap, form)
                if gs is nil:
                    gs = rt.symbol(rt.str(form, rt.wrap(u"__"), rt.gensym()))
                    GEN_SYM_ENV.set_value(rt.assoc(gmap, form, gs))
                form = gs
            else:
                var = rt.resolve_in(compiler.NS_VAR.deref(), form)
                if var is nil:
                    form = rt.symbol(rt.str(rt.wrap(rt.name(rt.deref(compiler.NS_VAR))), rt.wrap(u"/"), form))
                else:
                    form = rt.symbol(rt.str(rt.wrap(rt.namespace(var)), rt.wrap(u"/"), rt.str(rt.wrap(rt.name(var)))))
            ret = rt.list(QUOTE, form)
        elif is_unquote(form):
            ret = rt.first(rt.next(form))
        elif is_unquote_splicing(form):
            raise Exception("Unquote splicing not used inside list")
        elif rt.vector_QMARK_(form) is true:
            ret = rt.list(APPLY, CONCAT, SyntaxQuoteReader.expand_list(form))
        elif rt.seq_QMARK_(form) is true:
            ret = rt.list(APPLY, LIST, rt.cons(CONCAT, SyntaxQuoteReader.expand_list(rt.seq(form))))
        else:
            ret = rt.list(QUOTE, form)
        return ret
Ejemplo n.º 5
0
def load_ns(filename):
    import pixie.vm.string as string
    import pixie.vm.symbol as symbol
    import os.path as path

    if isinstance(filename, symbol.Symbol):
        affirm(rt.namespace(filename) is None, u"load-file takes a un-namespaced symbol")
        filename_str = rt.name(filename).replace(u".", u"/") + u".pxi"

        loaded_ns = code._ns_registry.get(rt.name(filename), None)
        if loaded_ns is not None:
            return loaded_ns
    else:
        affirm(isinstance(filename, string.String), u"Filename must be string")
        filename_str = rt.name(filename)

    paths = rt.deref(rt.deref(rt.load_paths))
    f = None
    for x in range(rt.count(paths)):
        path_x = rt.nth(paths, rt.wrap(x))
        affirm(isinstance(path_x, string.String), u"Contents of load-paths must be strings")
        full_path = path.join(str(rt.name(path_x)), str(filename_str))
        if path.isfile(full_path):
            f = full_path
            break

    if f is None:
        affirm(False, u"File '" + rt.name(filename) + u"' does not exist in any directory found in load-paths")
    else:
        rt.load_file(rt.wrap(f))
    return nil
Ejemplo n.º 6
0
Archivo: ffi.py Proyecto: kidaa/pixie
    def load_lib(self):
        if not self._is_inited:
            load_paths = rt.deref(rt.deref(rt.load_paths))

            for x in range(rt.count(load_paths)):
                s = rffi.str2charp(str(rt.name(rt.nth(load_paths, rt.wrap(x)))) + "/" + str(self._name))
                try:
                    self._dyn_lib = dynload.dlopen(s)
                    self._is_inited = True
                except dynload.DLOpenError as ex:
                    continue
                finally:
                    rffi.free_charp(s)
                break

            if not self._is_inited:
                s = rffi.str2charp(str(self._name))
                try:
                    self._dyn_lib = dynload.dlopen(s)
                    self._is_inited = True
                except dynload.DLOpenError as ex:
                    raise object.runtime_error(u"Couldn't Load Library: " + self._name,
                                               u"pixie.stdlib/LibraryNotFoundException")
                finally:
                    rffi.free_charp(s)
Ejemplo n.º 7
0
def _reduce(self, f, init):
    assert isinstance(self, Path)
    for dirpath, dirnames, filenames in os.walk(str(self._path)):
        for dirname in dirnames:
            init = f.invoke([init, Path(rt.wrap(dirpath + "/" + dirname))])
            if rt.reduced_QMARK_(init):
                return rt.deref(init)

        for filename in filenames:
            init = f.invoke([init, Path(rt.wrap(dirpath + "/" + filename))])
            if rt.reduced_QMARK_(init):
                return rt.deref(init)

    return init
Ejemplo n.º 8
0
def _reduce(self, f, init):
    assert isinstance(self, Path)
    for dirpath, dirnames, filenames in os.walk(str(self._path)):
        for dirname in dirnames:
            init = f.invoke([init, Path(rt.wrap(dirpath + "/" + dirname))])
            if rt.reduced_QMARK_(init):
                return rt.deref(init)

        for filename in filenames:
            init = f.invoke([init, Path(rt.wrap(dirpath + "/" + filename))])
            if rt.reduced_QMARK_(init):
                return rt.deref(init)

    return init
Ejemplo n.º 9
0
def load_file(filename):
    import pixie.vm.reader as reader
    import pixie.vm.compiler as compiler
    import pixie.vm.string as string
    import pixie.vm.symbol as symbol
    import os.path as path
    if isinstance(filename, symbol.Symbol):

        affirm(rt.namespace(filename) is None, u"load-file takes a un-namespaced symbol")
        filename_str = rt.name(filename).replace(u".", u"/") + u".lisp"

        loaded_ns = code._ns_registry.get(rt.name(filename), None)
        if loaded_ns is not None:
            return loaded_ns

    else:
        affirm(isinstance(filename, string.String), u"Filename must be string")
        filename_str = rt.name(filename)

    paths = rt.deref(rt.deref(rt.load_paths))
    f = None
    for x in range(rt.count(paths)):
        path_x = rt.nth(paths, rt.wrap(x))
        affirm(isinstance(path_x, string.String), u"Contents of load-paths must be strings")
        full_path = path.join(str(rt.name(path_x)), str(filename_str))
        if path.isfile(full_path):
            f = open(str(full_path))
            break

    if f is None:
        affirm(False, u"File does not exist in any directory found in load-paths")
    else:
        data = f.read()
        f.close()

        if data.startswith("#!"):
            newline_pos = data.find("\n")
            if newline_pos > 0:
                data = data[newline_pos:]
        rdr = reader.StringReader(unicode(data))

        with compiler.with_ns(u"user"):
            while True:
                form = reader.read(rdr, False)
                if form is reader.eof:
                    return nil
                result = compiler.compile(form).invoke([])
    return nil
Ejemplo n.º 10
0
def add_env_to_load_path():
    pp = os.environ.get("PIXIE_PATH")
    if pp is not None:
        LP = rt.deref(LOAD_PATHS.deref())
        for path in pp.split(":"):
            LP = rt.conj(LP, rt.wrap(path))
        LOAD_PATHS.set_root(Atom(LP))
Ejemplo n.º 11
0
def _reduce(self, f, init):
    assert isinstance(self, Environment)
    val = self.reduce_vars(f, init)
    if rt.reduced_QMARK_(val):
        return rt.deref(val)

    return val
Ejemplo n.º 12
0
def _reduce(self, f, init):
    assert isinstance(self, FileList)
    for dirpath, dirnames, filenames in os.walk(str(self._top)):
        for dirname in dirnames:
            init = f.invoke([init, rt.vector(rt.wrap(dirpath), KW_DIR, rt.wrap(dirname))])
            if rt.reduced_QMARK_(init):
                return rt.deref(init)

        for filename in filenames:
            init = f.invoke([init, rt.vector(rt.wrap(dirpath), KW_FILE, rt.wrap(filename))])
            if rt.reduced_QMARK_(init):
                return rt.deref(init)



    return init
Ejemplo n.º 13
0
def _reduce(self, f, init):
    assert isinstance(self, Environment)
    val = self.reduce_vars(f, init)
    if rt.reduced_QMARK_(val):
        return rt.deref(val)

    return val
Ejemplo n.º 14
0
def _reduce(self, f, init):
    if self._root is None:
        return init
    val = self._root.reduce_inode(f, init)
    if rt.reduced_QMARK_(val):
        return rt.deref(val)

    return val
Ejemplo n.º 15
0
def _reduce(self, f, init):
    assert isinstance(self, PersistentHashMap)
    if self._root is None:
        return init
    val = self._root.reduce_inode(f, init)
    if rt.reduced_QMARK_(val):
        return rt.deref(val)

    return val
Ejemplo n.º 16
0
def _reduce(self, f, init):
    assert isinstance(self, PersistentHashMap)
    if self._root is None:
        return init
    val = self._root.reduce_inode(f, init)
    if rt.reduced_QMARK_(val):
        return rt.deref(val)

    return val
Ejemplo n.º 17
0
def _reduce(self, f, init):
    assert isinstance(self, PersistentVector)
    i = 0
    while i < self._cnt:
        array = self.array_for(i)
        for j in range(len(array)):
            _reduce_driver.jit_merge_point(f=f)

            init = f.invoke([init, array[j]])
            if rt.reduced_QMARK_(init):
                return rt.deref(init)

        step = len(array)
        i += step
    return init
Ejemplo n.º 18
0
def _reduce(self, f, init):
    assert isinstance(self, PersistentVector)
    i = 0
    while i < self._cnt:
        array = self.array_for(i)
        for j in range(len(array)):
            _reduce_driver.jit_merge_point(f=f)

            init = f.invoke([init, array[j]])
            if rt.reduced_QMARK_(init):
                return rt.deref(init)

        step = len(array)
        i += step
    return init
Ejemplo n.º 19
0
def _reduce(self, f, init):
    i = 0
    while i < self._cnt:
        array = self.array_for(i)
        for j in range(len(array)):
            item = array[j]
            _reduce_driver.jit_merge_point(f=f)

            init = f.invoke([init, array[j]])
            if rt.reduced_QMARK_(init):
                return rt.deref(init)

        step = len(array)
        i += step
    return init
Ejemplo n.º 20
0
 def reduce(self, f, init):
     for x in range(self._idx, rt.count(self._w_array)):
         if rt.reduced_QMARK_(init):
             return rt.deref(init)
         init = f.invoke([init, rt.nth(self._w_array, rt.wrap(x))])
     return init
Ejemplo n.º 21
0
def add_to_load_paths(path):
    rt.reset_BANG_(LOAD_PATHS.deref(),
                   rt.conj(rt.deref(LOAD_PATHS.deref()), rt.wrap(path)))
Ejemplo n.º 22
0
 def reduce(self, f, init):
     for x in range(self._idx, rt.count(self._w_array)):
         if rt.reduced_QMARK_(init):
             return rt.deref(init)
         init = f.invoke([init, rt.nth(self._w_array, rt.wrap(x))])
     return init
Ejemplo n.º 23
0
def gensym2(prefix):
    rt.reset_BANG_(gensym_id, rt._add(rt.deref(gensym_id), rt.wrap(1)))
    i = rt.deref(gensym_id)

    return rt.symbol(rt.str(prefix, i))
Ejemplo n.º 24
0
 def reduce_large(self, f, init):
     for x in range(self._cnt):
         if rt.reduced_QMARK_(init):
             return rt.deref(init)
         init = f.invoke([init, rt.wrap(ord(self._buffer[x]))])
     return init
Ejemplo n.º 25
0
 def reduce_large(self, f, init):
     for x in range(len(self._list)):
         if rt.reduced_QMARK_(init):
             return rt.deref(init)
         init = f.invoke([init, self._list[x]])
     return init
Ejemplo n.º 26
0
def gensym():
    rt.reset_BANG_(gensym_id, rt._add(rt.deref(gensym_id), rt.wrap(1)))
    i = rt.deref(gensym_id)

    return rt.symbol(rt.str(rt.wrap(u"gensym_"), i))
Ejemplo n.º 27
0
 def reduce_large(self, f, init):
     for x in range(len(self._list)):
         if rt.reduced_QMARK_(init):
             return rt.deref(init)
         init = f.invoke([init, self._list[x]])
     return init
Ejemplo n.º 28
0
 def reduce_large(self, f, init):
     for x in range(self._cnt):
         if rt.reduced_QMARK_(init):
             return rt.deref(init)
         init = f.invoke([init, rt.wrap(ord(self._buffer[x]))])
     return init
Ejemplo n.º 29
0
def add_to_load_paths(path):
    rt.reset_BANG_(LOAD_PATHS.deref(), rt.conj(rt.deref(LOAD_PATHS.deref()), rt.wrap(path)))
Ejemplo n.º 30
0
def gensym2(prefix):
    rt.reset_BANG_(gensym_id, rt._add(rt.deref(gensym_id), rt.wrap(1)))
    i = rt.deref(gensym_id)

    return rt.symbol(rt.str(prefix, i))