Exemple #1
0
def run_load_stdlib():
    global stdlib_loaded
    if stdlib_loaded.is_true():
        return
    import pixie.vm.compiler as compiler
    import pixie.vm.reader as reader
    f = open(rpath.rjoin(str(rt.name(load_path.deref())), "pixie/stdlib.pxi"))
    data = f.read()
    f.close()
    rdr = reader.MetaDataReader(reader.StringReader(unicode(data)), u"pixie/stdlib.pxi")
    result = nil

    if not we_are_translated():
        print "Loading stdlib while interpreted, this will take some time..."

    with compiler.with_ns(u"pixie.stdlib"):
        while True:
            if not we_are_translated():
                sys.stdout.write(".")
                sys.stdout.flush()
            form = reader.read(rdr, False)
            if form is reader.eof:
                break
            result = compiler.compile(form).invoke([])

    if not we_are_translated():
        print "done"

    stdlib_loaded.set_true()
Exemple #2
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 = filename._str

    affirm(path.isfile(str(filename_str)), u"File does not exist on path")

    f = open(str(filename_str))
    data = f.read()
    f.close()
    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([])
Exemple #3
0
    def inner_invoke(self, args):
        from pixie.vm.keyword import keyword
        import pixie.vm.rt as rt
        from pixie.vm.string import String
        import pixie.vm.persistent_vector as vector

        with with_ns(u"user"):
            NS_VAR.deref().include_stdlib()

        acc = vector.EMPTY
        for x in self._argv:
            acc = rt.conj(acc, rt.wrap(x))

        PROGRAM_ARGUMENTS.set_root(acc)


        rdr = MetaDataReader(PromptReader())
        with with_ns(u"user"):
            while True:
                try:
                    val = read(rdr, False)
                    if val is eof:
                        break
                    val = interpret(compile(val))
                except WrappedException as ex:
                    print "Error: ", ex._ex.__repr__()
                    rdr.reset_line()
                    continue
                if val is keyword(u"exit-repl"):
                    break
                val = rt.str(val)
                assert isinstance(val, String), "str should always return a string"
                print val._str
Exemple #4
0
    def test_forms(self):
        for s in data:
            tst = data[s]
            result = read(StringReader(s), True)
            assert isinstance(result, Object)

            self._compare(result, tst)
Exemple #5
0
def load_reader(rdr):
    import pixie.vm.reader as reader
    import pixie.vm.compiler as compiler
    import sys

    if not we_are_translated():
        print "Loading file while interpreted, this may take time"

    val = PXIC_WRITER.deref()
    if val is nil:
        pxic_writer = None
    else:
        pxic_writer = val.get_pxic_writer()

    with compiler.with_ns(u"user"):
        compiler.NS_VAR.deref().include_stdlib()
        while True:
            if not we_are_translated():
                sys.stdout.write(".")
                sys.stdout.flush()
            form = reader.read(rdr, False)
            if form is reader.eof:
                return nil
            compiled = compiler.compile(form)

            if pxic_writer is not None:
                pxic_writer.write_object(compiled)

            compiled.invoke([])

    if not we_are_translated():
        print "done"

    return nil
Exemple #6
0
    def inner_invoke(self, args):
        import pixie.vm.rt as rt
        import pixie.vm.persistent_vector as vector

        with with_ns(u"user"):
            NS_VAR.deref().include_stdlib()

        acc = vector.EMPTY
        for x in self._argv:
            acc = rt.conj(acc, rt.wrap(x))

        PROGRAM_ARGUMENTS.set_root(acc)

        with with_ns(u"user"):
            try:
                f = None
                if self._file == '-':
                    f, _, _ = create_stdio()
                else:
                    if not path.isfile(self._file):
                        print "Error: Cannot open '" + self._file + "'"
                        os._exit(1)
                    f = open(self._file)
                data = f.read()
                f.close()

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

                interpret(compile(read(StringReader(unicode(data)), True)))
            except WrappedException as ex:
                print "Error: ", ex._ex.__repr__()
                os._exit(1)
Exemple #7
0
    def inner_invoke(self, args):
        import pixie.vm.rt as rt

        with with_ns(u"user"):
            NS_VAR.deref().include_stdlib()

            interpret(compile(read(StringReader(unicode(self._expr)), True)))
Exemple #8
0
    def test_forms(self):
        for s in data:
            tst = data[s]
            result = read(StringReader(s), True)
            assert isinstance(result, Object)

            self._compare(result, tst)
Exemple #9
0
def run_load_stdlib():
    global stdlib_loaded
    if stdlib_loaded.is_true():
        return
    import pixie.vm.compiler as compiler
    import pixie.vm.reader as reader
    f = open(rpath.rjoin(str(rt.name(load_path.deref())), "pixie/stdlib.pxi"))
    data = f.read()
    f.close()
    rdr = reader.MetaDataReader(reader.StringReader(unicode(data)),
                                u"pixie/stdlib.pxi")
    result = nil

    if not we_are_translated():
        print "Loading stdlib while interpreted, this will take some time..."

    with compiler.with_ns(u"pixie.stdlib"):
        while True:
            if not we_are_translated():
                sys.stdout.write(".")
                sys.stdout.flush()
            form = reader.read(rdr, False)
            if form is reader.eof:
                break
            result = compiler.compile(form).invoke([])

    if not we_are_translated():
        print "done"

    stdlib_loaded.set_true()
Exemple #10
0
def load_reader(rdr):
    import pixie.vm.reader as reader
    import pixie.vm.compiler as compiler
    import sys

    if not we_are_translated():
        print "Loading file while interpreted, this may take time"

    val = PXIC_WRITER.deref()
    if val is nil:
        pxic_writer = None
    else:
        pxic_writer = val.get_pxic_writer()

    with compiler.with_ns(u"user"):
        compiler.NS_VAR.deref().include_stdlib()
        while True:
            if not we_are_translated():
                sys.stdout.write(".")
                sys.stdout.flush()
            form = reader.read(rdr, False)
            if form is reader.eof:
                return nil
            compiled = compiler.compile(form)

            if pxic_writer is not None:
                pxic_writer.write_object(compiled)

            compiled.invoke([])

    if not we_are_translated():
        print "done"

    return nil
Exemple #11
0
 def run_load_stdlib():
     with compiler.with_ns(u"pixie.stdlib"):
         while True:
             form = reader.read(rdr, False)
             if form is reader.eof:
                 return result
             result = compiler.compile(form).invoke([])
             reinit()
Exemple #12
0
def eval_string(s):
    rdr = StringReader(unicode(s))
    result = nil
    while True:
        form = read(rdr, False)
        if form is eof:
            return result

        result = compile(form).invoke([])
Exemple #13
0
    def inner_invoke(self, args):
        import pixie.vm.rt as rt

        with with_ns(u"user"):
            NS_VAR.deref().include_stdlib()

            interpret(
                compile(read(StringReader(unicode_from_utf8(self._expr)),
                             True)))
Exemple #14
0
def eval_string(s):
    with with_ns(u"user", True):
        rdr = StringReader(unicode(s))
        result = nil
        while True:
            form = read(rdr, False)
            if form is eof:
                return result

            result = compile(form).invoke([])
Exemple #15
0
def load_reader(rdr):
    import pixie.vm.reader as reader
    import pixie.vm.compiler as compiler

    with compiler.with_ns(u"user"):
        while True:
            form = reader.read(rdr, False)
            if form is reader.eof:
                return nil
            compiler.compile(form).invoke([])
    return nil
Exemple #16
0
def load_reader(rdr):
    import pixie.vm.reader as reader
    import pixie.vm.compiler as compiler

    with compiler.with_ns(u"user"):
        while True:
            form = reader.read(rdr, False)
            if form is reader.eof:
                return nil
            compiler.compile(form).invoke([])
    return nil
Exemple #17
0
def load_reader(rdr):
    import pixie.vm.reader as reader
    import pixie.vm.compiler as compiler
    import sys

    if not we_are_translated():
        print "Loading file while interpreted, this may take time"

    val = PXIC_WRITER.deref()
    if val is nil:
        pxic_writer = None
    else:
        pxic_writer = val.get_pxic_writer()

    with compiler.with_ns(u"user"):
        compiler.NS_VAR.deref().include_stdlib()
        while True:
            if not we_are_translated():
                sys.stdout.write(".")
                sys.stdout.flush()
            form = reader.read(rdr, False)
            if form is reader.eof:
                return nil

            try:
                compiled = compiler.compile(form)

            except WrappedException as ex:
                meta = rt.meta(form)
                if meta is not nil:
                    ci = rt.interpreter_code_info(meta)
                    add_info(ex, ci.__repr__())
                add_info(ex, u"Compiling: " + rt.name(rt.str(form)))
                raise ex

            try:
                if pxic_writer is not None:
                    pxic_writer.write_object(compiled)

                compiled.invoke([])

            except WrappedException as ex:
                meta = rt.meta(form)
                if meta is not nil:
                    ci = rt.interpreter_code_info(meta)
                    add_info(ex, ci.__repr__())
                add_info(ex, u"Running: " + rt.name(rt.str(form)))
                raise ex


    if not we_are_translated():
        print "done"

    return nil
Exemple #18
0
def load_reader(rdr):
    import pixie.vm.reader as reader
    import pixie.vm.compiler as compiler
    import sys

    if not we_are_translated():
        print "Loading file while interpreted, this may take time"

    val = PXIC_WRITER.deref()
    if val is nil:
        pxic_writer = None
    else:
        pxic_writer = val.get_pxic_writer()

    with compiler.with_ns(u"user"):
        compiler.NS_VAR.deref().include_stdlib()
        while True:
            if not we_are_translated():
                sys.stdout.write(".")
                sys.stdout.flush()
            form = reader.read(rdr, False)
            if form is reader.eof:
                return nil

            try:
                compiled = compiler.compile(form)

            except WrappedException as ex:
                meta = rt.meta(form)
                if meta is not nil:
                    ci = rt.interpreter_code_info(meta)
                    add_info(ex, ci.__repr__())
                add_info(ex, u"Compiling: " + rt.name(rt.str(form)))
                raise ex

            try:
                if pxic_writer is not None:
                    pxic_writer.write_object(compiled)

                compiled.invoke([])

            except WrappedException as ex:
                meta = rt.meta(form)
                if meta is not nil:
                    ci = rt.interpreter_code_info(meta)
                    add_info(ex, ci.__repr__())
                add_info(ex, u"Running: " + rt.name(rt.str(form)))
                raise ex

    if not we_are_translated():
        print "done"

    return nil
Exemple #19
0
def run_load_stdlib():
    import pixie.vm.compiler as compiler
    import pixie.vm.reader as reader
    f = open("pixie/stdlib.lisp")
    data = f.read()
    f.close()
    rdr = reader.MetaDataReader(reader.StringReader(unicode(data)), u"pixie/stdlib.pixie")
    result = nil

    with compiler.with_ns(u"pixie.stdlib"):
        while True:
            form = reader.read(rdr, False)
            if form is reader.eof:
                return result
            result = compiler.compile(form).invoke([])
Exemple #20
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
Exemple #21
0
def load_file(filename):
    import pixie.vm.reader as reader
    import pixie.vm.compiler as compiler
    import pixie.vm.string as string
    affirm(isinstance(filename, string.String), u"Filename must be string")
    f = open(str(filename._str))
    data = f.read()
    f.close()
    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([])
Exemple #22
0
def load_file(filename):
    import pixie.vm.reader as reader
    import pixie.vm.compiler as compiler
    f = open(str(filename._str))
    data = f.read()
    f.close()
    rdr = reader.StringReader(unicode(data))
    result = nil
    while True:
        form = reader.read(rdr, False)
        print "printing"
        print rt.str(form)._str
        if form is reader.eof:
            return result
        print "compiling"
        result = compiler.compile(form).invoke([])
        print "compiled"
Exemple #23
0
    def inner_invoke(self, args):
        import pixie.vm.rt as rt
        import pixie.vm.persistent_vector as vector

        with with_ns(u"user"):
            NS_VAR.deref().include_stdlib()

        acc = vector.EMPTY
        for x in self._argv:
            acc = rt.conj(acc, rt.wrap(x))

        PROGRAM_ARGUMENTS.set_root(acc)

        with with_ns(u"user"):
            if self._file == '-':
                stdin, _, _ = create_stdio()
                code = stdin.read()
                interpret(compile(read(StringReader(unicode(code)), True)))
            else:
                rt.load_file(rt.wrap(self._file))
Exemple #24
0
def repl():
    from pixie.vm.keyword import keyword
    import pixie.vm.rt as rt
    from pixie.vm.string import String

    with with_ns(u"user"):
        NS_VAR.deref().include_stdlib()

    rdr = PromptReader()
    while True:
        with with_ns(u"user"):
            try:
                val = interpret(compile(read(rdr, True)))
            except WrappedException as ex:
                print "Error: ", ex._ex.__repr__()
                continue
            if val is keyword(u"exit-repl"):
                break
            val = rt.str(val)
            assert isinstance(val, String), "str should always return a string"
            print val._str
Exemple #25
0
    def inner_invoke(self, args):
        from pixie.vm.keyword import keyword
        import pixie.vm.rt as rt
        from pixie.vm.string import String
        import pixie.vm.persistent_vector as vector

        print "Pixie 0.1 - Interactive REPL"
        print "(" + platform.name + ", " + platform.cc + ")"
        print ":exit-repl or Ctrl-D to quit"
        print "----------------------------"

        with with_ns(u"user"):
            NS_VAR.deref().include_stdlib()

        acc = vector.EMPTY
        for x in self._argv:
            acc = rt.conj(acc, rt.wrap(x))

        PROGRAM_ARGUMENTS.set_root(acc)

        rdr = MetaDataReader(PromptReader())
        with with_ns(u"user"):
            while True:
                try:
                    val = read(rdr, False)
                    if val is eof:
                        break
                    val = interpret(compile(val))
                    self.set_recent_vars(val)
                except WrappedException as ex:
                    print "Error: ", ex._ex.__repr__()
                    rdr.reset_line()
                    self.set_error_var(ex._ex)
                    continue
                if val is keyword(u"exit-repl"):
                    break
                val = rt._repr(val)
                assert isinstance(val,
                                  String), "str should always return a string"
                print unicode_to_utf8(val._str)
Exemple #26
0
    def inner_invoke(self, args):
        from pixie.vm.keyword import keyword
        import pixie.vm.rt as rt
        from pixie.vm.string import String
        import pixie.vm.persistent_vector as vector

        print "Pixie 0.1 - Interactive REPL"
        print "(" + platform.name + ", " + platform.cc + ")"
        print ":exit-repl or Ctrl-D to quit"
        print "----------------------------"

        with with_ns(u"user"):
            NS_VAR.deref().include_stdlib()

        acc = vector.EMPTY
        for x in self._argv:
            acc = rt.conj(acc, rt.wrap(x))

        PROGRAM_ARGUMENTS.set_root(acc)

        rdr = MetaDataReader(PromptReader())
        with with_ns(u"user"):
            while True:
                try:
                    val = read(rdr, False)
                    if val is eof:
                        break
                    val = interpret(compile(val))
                    self.set_recent_vars(val)
                except WrappedException as ex:
                    print "Error: ", ex._ex.__repr__()
                    rdr.reset_line()
                    self.set_error_var(ex._ex)
                    continue
                if val is keyword(u"exit-repl"):
                    break
                val = rt._repr(val)
                assert isinstance(val, String), "str should always return a string"
                print unicode_to_utf8(val._str)
Exemple #27
0
def _read_string(s):
    import pixie.vm.reader as reader
    return reader.read(reader.StringReader(unicode(rt.name(s))), True)
Exemple #28
0
def read_code(s):
    with with_ns(u"user"):
        return read(StringReader(unicode(s)), False)
Exemple #29
0
def read_code(s):
    return read(StringReader(unicode(s)), False)
Exemple #30
0
def read_code(s):
    with with_ns(u"user"):
        return read(StringReader(unicode(s)), False)
Exemple #31
0
def _read_string(s):
    import pixie.vm.reader as reader
    return reader.read(reader.StringReader(unicode(rt.name(s))), True)