Ejemplo n.º 1
0
def requireClj(filename, stopafter="concat"):
    with open(filename) as fl:
        r = StringReader(fl.read())

    RT.init()
    comp = Compiler()
    comp.setFile(filename)

    pushThreadBindings({currentCompiler: comp})

    #o = open(filename+".cljc", "w")
    try:
        while True:
            EOF = object()
            s = read(r, False, EOF, True)
            if s is EOF:
                break
            #cPickle.dump(s, o)
            try:
                res = comp.compile(s)
                print s, res

                comp.executeCode(res)
                if stopafter is not None and hasattr(comp.getNS(), stopafter):
                    break
            except Exception as exp:
                print s, filename
                raise
    except IOError as e:
        pass
    finally:
        popThreadBindings()
Ejemplo n.º 2
0
def requireClj(filename, stopafter=None):
    """Compiles and executes the code in a clj file.
    
    If `stopafter` is given, then stop execution as soon as the `stopafter`
    name is defined in the current namespace of the compiler.
    """
    with open(filename) as fl:
        r = StringReader(fl.read())

    RT.init()
    comp = Compiler()
    comp.setFile(filename)

    with threadBindings({currentCompiler: comp}): #, open(filename + ".cljc", "w") as o:
        try:
            while True:
                EOF = object()
                s = read(r, False, EOF, True)
                if s is EOF:
                    break
                #cPickle.dump(s, o)
                try:
                    res = comp.compile(s)
                    comp.executeCode(res)
                    if stopafter is not None and hasattr(comp.getNS(), stopafter):
                        break
                except Exception as exp:
                    print s, filename
                    raise
        except IOError as e:
            pass
Ejemplo n.º 3
0
def requireClj(filename, stopafter=None):
    with open(filename) as fl:
        r = StringReader(fl.read())

    RT.init()
    comp = Compiler()
    comp.setFile(filename)

    pushThreadBindings({currentCompiler: comp})

    #o = open(filename+".cljc", "w")
    try:
        while True:
            EOF = object()
            s = read(r, False, EOF, True)
            if s is EOF:
                break
            #cPickle.dump(s, o)
            try:
                res = comp.compile(s)
                comp.executeCode(res)
                if stopafter is not None:
                    if hasattr(comp.getNS(), stopafter):
                        break
            except Exception as exp:
                print s, filename
                raise
    except IOError as e:
        pass
    finally:
        popThreadBindings()
Ejemplo n.º 4
0
def requireClj(filename, stopafter=None):
    with open(filename) as fl:
        r = StringReader(fl.read())

    RT.init()
    comp = Compiler()
    comp.setFile(filename)
    currentCompiler.set(comp)

    try:
        while True:
            s = read(r, True, None, True)
            try:
                res = comp.compile(s)
                comp.executeCode(res)
                if stopafter is not None:
                    if hasattr(comp.getNS(), stopafter):
                        break
            except IOError as exp:
                print s
                raise exp

            while True:
                ch = r.read()

                if ch == "":
                    raise IOError()

                if ch not in [" ", "\t", "\n", "\r"]:
                    r.back()
                    break
    except IOError as e:
        pass
Ejemplo n.º 5
0
def requireClj(filename, stopafter=None):
    with open(filename) as fl:
        r = StringReader(fl.read())

    RT.init()
    comp = Compiler()
    comp.setFile(filename)
    currentCompiler.set(comp)

    # o = open(filename+".cljc", "w")
    try:
        while True:
            s = read(r, False, None, True)
            if s is None:
                break
            # cPickle.dump(s, o)
            try:
                res = comp.compile(s)
                comp.executeCode(res)
                if stopafter is not None:
                    if hasattr(comp.getNS(), stopafter):
                        break
            except Exception as exp:
                print s, filename
                raise

            while True:
                ch = r.read()

                if ch == "":
                    raise IOError()

                if ch not in [" ", "\t", "\n", "\r"]:
                    r.back()
                    break
    except IOError as e:
        pass