示例#1
0
文件: jit.py 项目: yws/pycket-1
    def _cons_map(self):
        from pycket.expand import expand_string
        from pycket.json import loads

        ast = to_ast(
            loads(
                expand_string("""
        (letrec ([range-it (lambda (n a)
                                   (if (<= n 0)
                                       a
                                       (range-it (- n 1) (cons n a))))]
                 [range (lambda (n) (range-it n '()))])
          (foldl + 0 (range 1000)))
        """,
                              wrap=True,
                              stdlib=True)))

        def interp_w():
            val = interpret_one(ast)
            ov = check_one_val(val)
            assert isinstance(ov, W_Fixnum)
            return ov.value

        assert interp_w() == 500500

        self.meta_interp(interp_w, [],
                         listcomp=True,
                         listops=True,
                         backendopt=True)
示例#2
0
文件: targetjson.py 项目: 8l/pycket
def main(argv):
    assert len(argv) > 1
    data = readfile_rpython(argv[1])
    #data = readfile(argv[1])
    json = loads(data)
    print json
    print json.tostring()
    return 0
示例#3
0
def main(argv):
    assert len(argv) > 1
    data = readfile_rpython(argv[1])
    #data = readfile(argv[1])
    json = loads(data)
    print json
    print json.tostring()
    return 0
示例#4
0
    def _cons_map(self):
        from pycket.expand import expand_string
        from pycket.json import loads

        ast = to_ast(loads(expand_string("""
        (letrec ([range-it (lambda (n a)
                                   (if (<= n 0)
                                       a
                                       (range-it (- n 1) (cons n a))))]
                 [range (lambda (n) (range-it n '()))])
          (foldl + 0 (range 1000)))
        """, wrap=True, stdlib=True)))

        def interp_w():
            val = interpret_one(ast)
            ov = check_one_val(val)
            assert isinstance(ov, W_Fixnum)
            return ov.value
        assert interp_w() == 500500

        self.meta_interp(interp_w, [],
                         listcomp=True, listops=True, backendopt=True)