예제 #1
0
파일: target.py 프로젝트: btlachance/jam
def entry_point(argv):
    # Pycket's params
    jit.set_param(None, 'trace_limit', 1000000)
    jit.set_param(None, 'threshold', 131)
    jit.set_param(None, 'trace_eagerness', 50)
    jit.set_param(None, 'max_unroll_loops', 15)

    # HT pyrolog
    for i in range(len(argv)):
        if argv[i] == '--jit':
            if len(argv) == i + 1:
                print 'missing argument after --jit'
                return 2
            jitarg = argv[i + 1]
            del argv[i:i + 2]
            jit.set_user_param(None, jitarg)
            break
    if len(argv) > 1:
        print 'too many arguments'

    if we_are_translated():
        from rpython.rlib import streamio
        from pycket import pycket_json
        stdin = streamio.fdopen_as_stream(0, "r")
        json = pycket_json.loads(stdin.readall())
        return main(core.json_to_term(json))

    else:
        import sys, json
        import pycket_json_adapter as pja
        adapted = pja.adapt(json.load(sys.stdin))
        sys.exit(main(core.json_to_term(adapted)))
예제 #2
0
def sample_sexp():
    from pycket.expand import readfile_rpython, getkey
    from pycket import pycket_json

    data = readfile_rpython('sample-module.json')
    json = pycket_json.loads(data)
    ast = JsonLoader().to_ast(json) #module
    return ast.to_sexp()
예제 #3
0
def sample_sexp():
    from pycket.expand import readfile_rpython, getkey
    from pycket import pycket_json

    data = readfile_rpython('sample-module.json')
    json = pycket_json.loads(data)
    ast = JsonLoader().to_ast(json) #module
    return ast.to_sexp()
예제 #4
0
 def expand_to_ast(self, fname):
     assert fname is not None
     fname = rpath.realpath(fname)
     data = expand_file_rpython(fname, self._lib_string())
     self.modtable.enter_module(fname)
     module = self.to_module(pycket_json.loads(data))
     module = finalize_module(module)
     self.modtable.exit_module(fname, module)
     return module
예제 #5
0
 def load_json_ast_rpython(self, modname, fname):
     assert modname is not None
     modname = rpath.realpath(modname)
     data = readfile_rpython(fname)
     self.modtable.enter_module(modname)
     module = self.to_module(pycket_json.loads(data))
     module = finalize_module(module)
     self.modtable.exit_module(modname, module)
     return module
예제 #6
0
 def expand_to_ast(self, fname):
     assert fname is not None
     fname = rpath.realpath(fname)
     data = expand_file_rpython(fname, self._lib_string())
     self.modtable.enter_module(fname)
     module = self.to_module(pycket_json.loads(data))
     module = finalize_module(module)
     self.modtable.exit_module(fname, module)
     return module
예제 #7
0
파일: expand.py 프로젝트: fenildf/pycket
 def load_json_ast_rpython(self, modname, fname):
     assert modname is not None
     modname = rpath.realpath(modname)
     data = readfile_rpython(fname)
     self.modtable.enter_module(modname)
     module = self.to_module(pycket_json.loads(data))
     module = finalize_module(module)
     self.modtable.exit_module(modname, module)
     return module
예제 #8
0
def string_to_term(s):
  if we_are_translated():
    from pycket import pycket_json
    json = pycket_json.loads(s)
    return json_to_term(json)
  else:
    import json
    import pycket_json_adapter as pja
    adapted = pja.adapt(json.loads(s))
    return json_to_term(adapted)
예제 #9
0
    def load_json_ast_rpython(self, modname, fname):
        assert modname is not None
        modname = rpath.realpath(modname)
        self.modtable.enter_module(modname)

        if self.multi_mod_flag:
            mod_ast = self.multi_mod_mapper.get_mod(modname)
            module = self.to_module(mod_ast)
        else:
            data = readfile_rpython(fname)
            module = self.to_module(pycket_json.loads(data))

        module = finalize_module(module)
        self.modtable.exit_module(modname, module)
        return module
예제 #10
0
파일: expand.py 프로젝트: pycket/pycket
    def load_json_ast_rpython(self, modname, fname):
        assert modname is not None
        modname = rpath.realpath(modname)
        self.modtable.enter_module(modname)

        if self.multi_mod_flag:
            mod_ast = self.multi_mod_mapper.get_mod(modname)
            module = self.to_module(mod_ast)
        else:
            data = readfile_rpython(fname)
            module = self.to_module(pycket_json.loads(data))

        module = finalize_module(module)
        self.modtable.exit_module(modname, module)
        return module
예제 #11
0
파일: jit.py 프로젝트: rjnw/pycket
    def run_string(self, str):
        _json = pycket_json.loads(expand_string(str))
        _env = ToplevelEnv()

        def interp_w():
            loader = JsonLoader(False)
            ast = loader.to_module((_json)).assign_convert_module()
            env = (_env)
            env.globalconfig.load(ast)
            env.commanline_arguments = []
            interpret_module(ast, env)

        interp_w() # check that it runs

        # ast = parse_module(expand_string(str))
        self.meta_interp(interp_w, [], listcomp=True, listops=True, backendopt=True)
예제 #12
0
파일: expand.py 프로젝트: 8l/pycket
def expand(s, wrap=False, stdlib=False):
    data = expand_string(s)
    return pycket_json.loads(data)
예제 #13
0
파일: expand.py 프로젝트: 8l/pycket
def expand_to_ast(fname, modtable):
    data = expand_file_rpython(fname)
    return _to_module(pycket_json.loads(data), modtable).assign_convert_module()
예제 #14
0
def load_json_ast(fname):
    data = readfile(fname)
    return _to_module(pycket_json.loads(data)).assign_convert_module()
예제 #15
0
def parse_module(json_string, bytecode_expand=False):
    json = pycket_json.loads(json_string)
    modtable = ModTable()
    reader = JsonLoader(bytecode_expand)
    module = reader.to_module(json)
    return finalize_module(module)
예제 #16
0
def expand(s, wrap=False, stdlib=False):
    data = expand_string(s)
    return pycket_json.loads(data)
예제 #17
0
파일: expand.py 프로젝트: 8l/pycket
def parse_module(json_string):
    json = pycket_json.loads(json_string)
    modtable = ModTable()
    return _to_module(json, modtable).assign_convert_module()
예제 #18
0
def test_tostring_string_escaping():
    json = loads('"\\n"')
    assert json.tostring() == '"\\n"'
예제 #19
0
파일: expand.py 프로젝트: cderici/pycket
def expand_to_ast(fname, modtable, lib=fn, byte_flag=False):
    if byte_flag:
        lib = be
    data = expand_file_rpython(fname, lib)
    return _to_module(pycket_json.loads(data), modtable, lib).assign_convert_module()
예제 #20
0
def _compare(string, expected):
    json = loads(string)
    val = json._unpack_deep()
    assert val == expected
예제 #21
0
파일: expand.py 프로젝트: 8l/pycket
def parse_module(json_string):
    json = pycket_json.loads(json_string)
    modtable = ModTable()
    return _to_module(json, modtable).assign_convert_module()
예제 #22
0
파일: expand.py 프로젝트: 8l/pycket
def load_json_ast_rpython(fname, modtable):
    data = readfile_rpython(fname)
    return _to_module(pycket_json.loads(data),
                      modtable).assign_convert_module()
예제 #23
0
파일: expand.py 프로젝트: 8l/pycket
def expand_to_ast(fname, modtable):
    data = expand_file_rpython(fname)
    return _to_module(pycket_json.loads(data),
                      modtable).assign_convert_module()
예제 #24
0
파일: expand.py 프로젝트: 8l/pycket
def load_json_ast_rpython(fname, modtable):
    data = readfile_rpython(fname)
    return _to_module(pycket_json.loads(data), modtable).assign_convert_module()
예제 #25
0
def parse_module(json_string, bytecode_expand=False):
    json = pycket_json.loads(json_string)
    modtable = ModTable()
    reader = JsonLoader(bytecode_expand)
    module = reader.to_module(json)
    return finalize_module(module)
예제 #26
0
파일: expand.py 프로젝트: 8l/pycket
def parse_ast(json_string):
    json = pycket_json.loads(json_string)
    modtable = ModTable()
    return to_ast(json, modtable)
예제 #27
0
파일: linklet.py 프로젝트: pycket/pycket
    def load_linklet(json_file_name, set_version=False):
        from pycket.expand import readfile_rpython, getkey, JsonLoader
        from pycket.util import console_log
        from pycket.env import w_version

        """ Expands and loads a linklet from a JSON file"""
        with PerfRegion("json-load"):
            data = readfile_rpython(json_file_name)
            json = pycket_json.loads(data)
            console_log("Finished reading JSON from %s" % json_file_name, 2)
            assert json.is_object
            json_python_dict = json.value_object()
            assert "linklet" in json_python_dict
            linklet_dict = getkey(json_python_dict, "linklet", type='o')
            assert "exports" in linklet_dict and "body" in linklet_dict

            # list of JsonObject
            exports_list = getkey(linklet_dict, "exports", type='a')

        if set_version:
            from pycket.util import console_log
            conf = getkey(linklet_dict, "config", type='o')
            ver = conf['version'].value_string()
            console_log("Setting the version to %s" % ver)
            w_version.set_version(ver)

        exports = {}
        for exp in exports_list:
            if exp.is_array:
                arr = exp.value_array()
                internal_str = arr[0].value_object()['quote'].value_object()['toplevel'].value_string()
                internal_name = W_Symbol.make(internal_str)
                external_name = W_Symbol.make(arr[1].value_object()['quote'].value_object()['toplevel'].value_string())
                w_internal_name = Gensym.gensym(internal_str)
                exports[internal_name] = Export(w_internal_name, external_name)
            else:
                exp_str = exp.value_object()['quote'].value_object()['toplevel'].value_string()
                exp_sym = W_Symbol.make(exp_str)
                w_exp_sym = Gensym.gensym(exp_str)
                exports[exp_sym] = Export(w_exp_sym, exp_sym)

        imports_list = getkey(linklet_dict, "importss", type='a', default=[])

        importss = [None]*len(imports_list) # list of dict

        if "importss" in linklet_dict:
            for index, imports in enumerate(imports_list):
                arr = imports.value_array()
                # bootstrap linklets have no imports at all
                # this is only for debugging purposes
                instance_imports = []
                for id_str in arr:
                    imp_str = id_str.value_object()['quote'].value_object()['toplevel'].value_string()
                    imp_sym = W_Symbol.make(imp_str)
                    w_imp_sym = Gensym.gensym(imp_str)
                    instance_imports.append(Import(W_Fixnum(index), imp_sym, w_imp_sym, w_imp_sym))
                importss[index] = instance_imports

        console_log("Converting linklet forms to AST ...", 2)

        loader = JsonLoader()
        with PerfRegion("json-to-ast"):
            all_forms = []
            for body_form in getkey(linklet_dict, "body", type='a'):
                form_2 = loader.to_ast(body_form)
                form_1 = Context.normalize_term(form_2)
                form = assign_convert(form_1)
                all_forms.append(form)
            # for each exported defined id, we need to add a
            # variable-set! for the exported var with the defined id
            for exp_sym, exp_obj in exports.iteritems():
                rator = ModuleVar(var_set_sym, "#%kernel", var_set_sym, None)
                exp_var = LinkletVar(exp_obj.int_id)
                top_var = ToplevelVar(exp_sym)
                mode = Quote(values.w_false) # FIXME: possible optimization
                rands = [exp_var, top_var, mode]
                all_forms.append(App.make(rator,rands))

        linkl = W_Linklet(W_Symbol.make(json_file_name), importss, exports, all_forms)
        console_log("Finished converting linklet forms to AST ...", 2)

        config = {}
        config_obj = getkey(linklet_dict, "config", type='o')
        if config_obj is not None:
            for k, v in config_obj.iteritems():
                config[k] = v.value_string()

        return linkl, config
예제 #28
0
파일: linklet.py 프로젝트: pycket/pycket
    def load_linklet(json_file_name, set_version=False):
        from pycket.expand import readfile_rpython, getkey, JsonLoader
        from pycket.util import console_log
        from pycket.env import w_version
        """ Expands and loads a linklet from a JSON file"""
        with PerfRegion("json-load"):
            data = readfile_rpython(json_file_name)
            json = pycket_json.loads(data)
            console_log("Finished reading JSON from %s" % json_file_name, 2)
            assert json.is_object
            json_python_dict = json.value_object()
            assert "linklet" in json_python_dict
            linklet_dict = getkey(json_python_dict, "linklet", type='o')
            assert "exports" in linklet_dict and "body" in linklet_dict

            # list of JsonObject
            exports_list = getkey(linklet_dict, "exports", type='a')

        if set_version:
            from pycket.util import console_log
            conf = getkey(linklet_dict, "config", type='o')
            ver = conf['version'].value_string()
            console_log("Setting the version to %s" % ver)
            w_version.set_version(ver)

        exports = {}
        for exp in exports_list:
            if exp.is_array:
                arr = exp.value_array()
                internal_str = arr[0].value_object()['quote'].value_object(
                )['toplevel'].value_string()
                internal_name = W_Symbol.make(internal_str)
                external_name = W_Symbol.make(
                    arr[1].value_object()['quote'].value_object()
                    ['toplevel'].value_string())
                w_internal_name = Gensym.gensym(internal_str)
                exports[internal_name] = Export(w_internal_name, external_name)
            else:
                exp_str = exp.value_object()['quote'].value_object(
                )['toplevel'].value_string()
                exp_sym = W_Symbol.make(exp_str)
                w_exp_sym = Gensym.gensym(exp_str)
                exports[exp_sym] = Export(w_exp_sym, exp_sym)

        imports_list = getkey(linklet_dict, "importss", type='a', default=[])

        importss = [None] * len(imports_list)  # list of dict

        if "importss" in linklet_dict:
            for index, imports in enumerate(imports_list):
                arr = imports.value_array()
                # bootstrap linklets have no imports at all
                # this is only for debugging purposes
                instance_imports = []
                for id_str in arr:
                    imp_str = id_str.value_object()['quote'].value_object(
                    )['toplevel'].value_string()
                    imp_sym = W_Symbol.make(imp_str)
                    w_imp_sym = Gensym.gensym(imp_str)
                    instance_imports.append(
                        Import(W_Fixnum(index), imp_sym, w_imp_sym, w_imp_sym))
                importss[index] = instance_imports

        console_log("Converting linklet forms to AST ...", 2)

        loader = JsonLoader()
        with PerfRegion("json-to-ast"):
            all_forms = []
            for body_form in getkey(linklet_dict, "body", type='a'):
                form_2 = loader.to_ast(body_form)
                form_1 = Context.normalize_term(form_2)
                form = assign_convert(form_1)
                all_forms.append(form)
            # for each exported defined id, we need to add a
            # variable-set! for the exported var with the defined id
            for exp_sym, exp_obj in exports.iteritems():
                rator = ModuleVar(var_set_sym, "#%kernel", var_set_sym, None)
                exp_var = LinkletVar(exp_obj.int_id)
                top_var = ToplevelVar(exp_sym)
                mode = Quote(values.w_false)  # FIXME: possible optimization
                rands = [exp_var, top_var, mode]
                all_forms.append(App.make(rator, rands))

        linkl = W_Linklet(W_Symbol.make(json_file_name), importss, exports,
                          all_forms)
        console_log("Finished converting linklet forms to AST ...", 2)

        config = {}
        config_obj = getkey(linklet_dict, "config", type='o')
        if config_obj is not None:
            for k, v in config_obj.iteritems():
                config[k] = v.value_string()

        return linkl, config
예제 #29
0
def parse_module(json_string):
    json = pycket_json.loads(json_string)
    return _to_module(json).assign_convert_module()
예제 #30
0
def parse_ast(json_string):
    json = pycket_json.loads(json_string)
    modtable = ModTable()
    return to_ast(json, modtable)
예제 #31
0
파일: linklet.py 프로젝트: samth/pycket
    def load_linklet(json_file_name, set_version=False, generate_zo=False):
        from pycket.expand import readfile_rpython, getkey, JsonLoader
        from pycket.util import console_log
        from pycket.env import w_version
        import os

        if generate_zo:
            try:
                os.remove("expander.zo")
            except OSError:
                pass

        if set_version and os.path.exists("expander.zo"):
            console_log("Loading the expander linklet from expander.zo")
            # We're loading the expander, so try fasl->sexp
            from pycket.racket_entry import get_primitive
            from pycket.prims.input_output import open_input_file

            with PerfRegion("expander-linklet"):
                fasl_to_s_exp = get_primitive("fasl->s-exp")
                in_file = open_input_file.w_prim.call_interpret(
                    [W_Path("expander.zo")])
                try:
                    expander_zo_sexp = fasl_to_s_exp.call_interpret(
                        [in_file, w_true])
                    version = expander_zo_sexp.car()
                    expander_sexp = expander_zo_sexp.cdr()
                    expander_linkl = deserialize_loop(expander_sexp)
                    w_version.set_version(version.tostring())
                    console_log("Setting the version to %s" %
                                version.tostring())
                    return expander_linkl, None
                except (SchemeException, OSError):
                    console_log("Couldn't read from expander.zo")
        """ Expands and loads a linklet from a JSON file"""
        with PerfRegion("json-load"):
            data = readfile_rpython(json_file_name)
            json = pycket_json.loads(data)
            console_log("Finished reading JSON from %s" % json_file_name, 2)
            assert json.is_object
            json_python_dict = json.value_object()
            assert "linklet" in json_python_dict
            linklet_dict = getkey(json_python_dict, "linklet", type='o')
            assert "exports" in linklet_dict and "body" in linklet_dict

            # list of JsonObject
            exports_list = getkey(linklet_dict, "exports", type='a')

        if set_version:
            from pycket.util import console_log
            conf = getkey(linklet_dict, "config", type='o')
            ver = conf['version'].value_string()
            console_log("Setting the version to %s" % ver)
            w_version.set_version(ver)

        exports = {}
        for exp in exports_list:
            if exp.is_array:
                arr = exp.value_array()
                internal_str = arr[0].value_object()['quote'].value_object(
                )['toplevel'].value_string()
                internal_name = W_Symbol.make(internal_str)
                external_name = W_Symbol.make(
                    arr[1].value_object()['quote'].value_object()
                    ['toplevel'].value_string())
                w_internal_name = Gensym.gensym(internal_str)
                exports[internal_name] = Export(w_internal_name, external_name)
            else:
                exp_str = exp.value_object()['quote'].value_object(
                )['toplevel'].value_string()
                exp_sym = W_Symbol.make(exp_str)
                w_exp_sym = Gensym.gensym(exp_str)
                exports[exp_sym] = Export(w_exp_sym, exp_sym)

        imports_list = getkey(linklet_dict, "importss", type='a', default=[])

        importss = [None] * len(imports_list)  # list of dict

        if "importss" in linklet_dict:
            for index, imports in enumerate(imports_list):
                arr = imports.value_array()
                # bootstrap linklets have no imports at all
                # this is only for debugging purposes
                instance_imports = []
                for id_str in arr:
                    imp_str = id_str.value_object()['quote'].value_object(
                    )['toplevel'].value_string()
                    imp_sym = W_Symbol.make(imp_str)
                    w_imp_sym = Gensym.gensym(imp_str)
                    instance_imports.append(
                        Import(W_Fixnum(index), imp_sym, w_imp_sym, w_imp_sym))
                importss[index] = instance_imports

        console_log("Converting linklet forms to AST ...", 2)

        loader = JsonLoader()
        with PerfRegion("json-to-ast"):
            all_forms = []
            for body_form in getkey(linklet_dict, "body", type='a'):
                form_2 = loader.to_ast(body_form)
                form_1 = Context.normalize_term(form_2)
                # if form_1.tostring() != form_2.tostring():
                #     import pdb;pdb.set_trace()
                form = assign_convert(form_1)
                all_forms.append(form)
            # for each exported defined id, we need to add a
            # variable-set! for the exported var with the defined id
            for exp_sym, exp_obj in exports.iteritems():
                rator = ModuleVar(var_set_sym, "#%kernel", var_set_sym, None)
                exp_var = LinkletStaticVar(exp_obj.int_id)
                top_var = ToplevelVar(exp_sym)
                mode = Quote(values.w_false)  # FIXME: possible optimization
                rands = [exp_var, top_var, mode]
                all_forms.append(App.make(rator, rands))

        linkl = W_Linklet(W_Symbol.make(json_file_name), importss, exports,
                          all_forms)
        console_log("Finished converting linklet forms to AST ...", 2)

        config = {}
        config_obj = getkey(linklet_dict, "config", type='o')
        if config_obj is not None:
            for k, v in config_obj.iteritems():
                config[k] = v.value_string()

        if set_version and not os.path.exists("expander.zo"):
            console_log("Serializing the expander linklet into expander.zo")
            from pycket.racket_entry import get_primitive
            from pycket.prims.input_output import open_output_file
            s_exp_to_fasl = get_primitive("s-exp->fasl")
            expander_sexp = ast_to_sexp(linkl)
            version = W_Symbol.make(w_version.get_version())
            expander_zo_sexp = W_Cons.make(version, expander_sexp)
            try:
                out_file = open_output_file.w_prim.call_interpret(
                    [W_Path("expander.zo")])
                s_exp_to_fasl.call_interpret(
                    [expander_zo_sexp, out_file, values.w_false])
            except (SchemeException, OSError):
                console_log("Couldn't write the expander.zo")

        return linkl, config
예제 #32
0
 def __init__(self, json_file_name):
     assert json_file_name is not None and json_file_name != ""
     data = readfile_rpython(rpath.realpath(os.path.abspath(json_file_name)))
     self.source_json = json_file_name
     self.mod_map = pycket_json.loads(data)
예제 #33
0
def parse_ast(json_string):
    json = pycket_json.loads(json_string)
    return to_ast(json)
예제 #34
0
파일: expand.py 프로젝트: pycket/pycket
 def __init__(self, json_file_name):
     assert json_file_name is not None and json_file_name != ""
     data = readfile_rpython(rpath.realpath(os.path.abspath(json_file_name)))
     self.source_json = json_file_name
     self.mod_map = pycket_json.loads(data)
예제 #35
0
파일: expand.py 프로젝트: cderici/pycket
def load_json_ast_rpython(fname, modtable, lib=fn, byte_flag=False):
    dbgprint("load_json_ast_rpython", "", lib=lib, filename=fname)
    if byte_flag:
        lib = be
    data = readfile_rpython(fname)
    return _to_module(pycket_json.loads(data), modtable, lib).assign_convert_module()