Ejemplo n.º 1
0
def namespace_require_kernel():

    namespace_require = get_primitive("namespace-require")

    kernel = W_WrappedConsProper.make(W_Symbol.make("quote"),
                                      W_WrappedConsProper.make(W_Symbol.make("#%kernel"), w_null))
    namespace_require.call_interpret([kernel])
Ejemplo n.º 2
0
def namespace_require_kernel():

    namespace_require = get_primitive("namespace-require")

    kernel = W_WrappedConsProper.make(W_Symbol.make("quote"),
                                      W_WrappedConsProper.make(W_Symbol.make("#%kernel"), w_null))
    namespace_require.call_interpret([kernel])
Ejemplo n.º 3
0
def configure_runtime(m):
    dynamic_require = get_primitive("dynamic-require")
    module_declared = get_primitive("module-declared?")
    join = get_primitive("module-path-index-join")
    submod = W_WrappedConsProper.make(W_Symbol.make("submod"),
                                      W_WrappedConsProper.make(W_String.make("."),
                                                               W_WrappedConsProper(W_Symbol.make("configure-runtime"), w_null)))

    config_m = join.call_interpret([submod, m])
    if module_declared.call_interpret([config_m, w_true]) is w_true:
        dynamic_require.call_interpret([config_m, w_false])
Ejemplo n.º 4
0
def test_env_structure_apps():
    p = expr_ast("(let ([a 1] [b 2]) (+ a b))")
    a = W_Symbol.make("a")
    b = W_Symbol.make("b")
    assert isinstance(p, Let)
    env_structure = p.body[0].env_structure
    assert env_structure is not None
    i, d = env_structure.depth_of_var(a)
    assert i == 0 and d == 0
    i, d = env_structure.depth_of_var(b)
    assert i == 1 and d == 0
Ejemplo n.º 5
0
def test_env_structure_apps():
    p = expr_ast("(let ([a 1] [b 2]) (+ a b))")
    a = W_Symbol.make("a")
    b = W_Symbol.make("b")
    assert isinstance(p, Let)
    env_structure = p.body[0].env_structure
    assert env_structure is not None
    i, d = env_structure.depth_of_var(a)
    assert i == 0 and d == 0
    i, d = env_structure.depth_of_var(b)
    assert i == 1 and d == 0
Ejemplo n.º 6
0
def configure_runtime(m):
    dynamic_require = get_primitive("dynamic-require")
    module_declared = get_primitive("module-declared?")
    join = get_primitive("module-path-index-join")
    submod = W_WrappedConsProper.make(W_Symbol.make("submod"),
                                      W_WrappedConsProper.make(W_String.make("."),
                                                               W_WrappedConsProper(W_Symbol.make("configure-runtime"), w_null)))

    config_m = join.call_interpret([submod, m])
    if module_declared.call_interpret([config_m, w_true]) is w_true:
        dynamic_require.call_interpret([config_m, w_false])
Ejemplo n.º 7
0
def load_linklet_from_fasl(file_name, set_version=False):
    from pycket.fasl import Fasl
    from pycket.env import w_version
    from pycket.util import console_log
    from pycket.ast_vs_sexp import deserialize_loop

    debug_start("loading-linklet")
    debug_print("Loading linklet from fasl -- %s" % file_name)
    sexp = Fasl().to_sexp_from_file(file_name)
    version_sexp, linklet_sexp = W_String.make(""), None
    if set_version:
        version_sexp = sexp.car()
        linklet_sexp = sexp.cdr()
    else:
        linklet_sexp = sexp
    linklet = None
    if "zo" in file_name:
        linklet = deserialize_loop(linklet_sexp)
    else:
        console_log("Run pycket with --make-linklet-zos to make the compiled zo files for bootstrap linklets", 1)
        compile_linklet = get_primitive("compile-linklet")
        linklet = compile_linklet.call_interpret([linklet_sexp, W_Symbol.make("linkl"), w_false, w_false, w_false])

    if set_version:
        ver = version_sexp.as_str_ascii()
        console_log("Setting the version to %s" % ver)
        w_version.set_version(ver)

    debug_stop("loading-linklet")
    return linklet, version_sexp
Ejemplo n.º 8
0
def load_linklet_from_fasl(file_name, set_version=False):
    from pycket.fasl import Fasl
    from pycket.env import w_version
    from pycket.util import console_log
    from pycket.ast_vs_sexp import deserialize_loop

    debug_start("loading-linklet")
    debug_print("Loading linklet from fasl -- %s" % file_name)
    sexp = Fasl().to_sexp_from_file(file_name)
    version_sexp, linklet_sexp = W_String.make(""), None
    if set_version:
        version_sexp = sexp.car()
        linklet_sexp = sexp.cdr()
    else:
        linklet_sexp = sexp
    linklet = None
    if "zo" in file_name:
        linklet = deserialize_loop(linklet_sexp)
    else:
        console_log("Run pycket with --make-linklet-zos to make the compiled zo files for bootstrap linklets", 1)
        compile_linklet = get_primitive("compile-linklet")
        linklet = compile_linklet.call_interpret([linklet_sexp, W_Symbol.make("linkl"), w_false, w_false, w_false])

    if set_version:
        ver = version_sexp.as_str_ascii()
        console_log("Setting the version to %s" % ver)
        w_version.set_version(ver)

    debug_stop("loading-linklet")
    return linklet, version_sexp
Ejemplo n.º 9
0
def namespace_require_plus(spec):
    namespace_require = get_primitive("namespace-require")
    dynamic_require = get_primitive("dynamic-require")
    module_declared = get_primitive("module-declared?")
    join = get_primitive("module-path-index-join")
    m = join.call_interpret([spec, w_false])
    submod = W_WrappedConsProper.make(W_Symbol.make("submod"),
                                      W_WrappedConsProper.make(W_String.make("."),
                                                               W_WrappedConsProper(W_Symbol.make("main"), w_null)))
    # FIXME: configure-runtime
    if need_runtime_configure[0]:
        configure_runtime(m)
        need_runtime_configure[0] = False
    namespace_require.call_interpret([m])
    main = join.call_interpret([submod, m])
    if module_declared.call_interpret([main, w_true]) is w_true:
        dynamic_require.call_interpret([main, w_false])
Ejemplo n.º 10
0
def set_path(kind_str, path_str):
    import os
    from pycket.racket_paths import racket_sys_paths

    if not os.path.exists(path_str):
        raise Exception("File not found : %s" % path_str)

    racket_sys_paths.set_path(W_Symbol.make(kind_str), W_Path(path_str))
Ejemplo n.º 11
0
def wrap_linklet_sexp(body_sexp):
    return W_Cons.make(
        W_Symbol.make("linklet"),
        W_Cons.make(
            w_null,  # imports
            W_Cons.make(
                w_null,  # exports
                W_Cons.make(body_sexp, w_null))))
Ejemplo n.º 12
0
def namespace_require_plus(spec):
    namespace_require = get_primitive("namespace-require")
    dynamic_require = get_primitive("dynamic-require")
    module_declared = get_primitive("module-declared?")
    join = get_primitive("module-path-index-join")
    m = join.call_interpret([spec, w_false])
    submod = W_WrappedConsProper.make(W_Symbol.make("submod"),
                                      W_WrappedConsProper.make(W_String.make("."),
                                                               W_WrappedConsProper(W_Symbol.make("main"), w_null)))
    # FIXME: configure-runtime
    if need_runtime_configure[0]:
        configure_runtime(m)
        need_runtime_configure[0] = False
    namespace_require.call_interpret([m])
    main = join.call_interpret([submod, m])
    if module_declared.call_interpret([main, w_true]) is w_true:
        dynamic_require.call_interpret([main, w_false])
Ejemplo n.º 13
0
def set_path(kind_str, path_str):
    import os
    from pycket.racket_paths import racket_sys_paths

    if not os.path.exists(path_str):
        raise Exception("File not found : %s" % path_str)

    racket_sys_paths.set_path(W_Symbol.make(kind_str), W_Path(path_str))
Ejemplo n.º 14
0
def get_primitive(prim_name_str):
    from pycket.prims.expose import prim_env
    from pycket.error import SchemeException

    prim_sym = W_Symbol.make(prim_name_str)
    if not prim_sym in prim_env:
        raise SchemeException("Primitive not found : %s" % prim_name_str)

    return prim_env[prim_sym]
Ejemplo n.º 15
0
def test_instantiate_uninitialize_undefined_exports():
    l = make_linklet("(linklet () (x))")
    _, t = eval_fixnum(l, empty_target())
    assert t.is_var_uninitialized(W_Symbol.make("x"))

    # don't touch if target has it
    l = make_linklet("(linklet () (x))")
    t = make_instance("(linklet () () (define-values (x) 10))")
    _, t = eval_fixnum(l, t)
    assert not t.is_var_uninitialized(W_Symbol.make("x"))

    # target exports the same var with another external name
    l = make_linklet("(linklet () (x2) (+ x2 x2))")
    t = make_instance("(linklet () ((x x2)) (define-values (x) 10))")
    result, t = eval_fixnum(l, t)
    assert result == 20
    assert check_val(t, "x2", 10)
    assert not defines(t, "x")
Ejemplo n.º 16
0
def get_undef_prims_in(table):
    from pycket.prims.expose import prim_env
    from pycket.values import W_Symbol, W_Prim
    ls = []
    for name in table:
        p = prim_env[W_Symbol.make(name)]
        if isinstance(p, W_Prim) and not p.is_implemented():
            ls.append(name)
    return ls
Ejemplo n.º 17
0
def get_primitive(prim_name_str):
    from pycket.prims.expose import prim_env
    from pycket.error import SchemeException

    prim_sym = W_Symbol.make(prim_name_str)
    if not prim_sym in prim_env:
        raise SchemeException("Primitive not found : %s" % prim_name_str)

    return prim_env[prim_sym]
Ejemplo n.º 18
0
def get_undef_prims_in(table):
    from pycket.prims.expose import prim_env
    from pycket.values import W_Symbol, W_Prim
    ls = []
    for name in table:
        p = prim_env[W_Symbol.make(name)]
        if isinstance(p, W_Prim) and not p.is_implemented():
            ls.append(name)
    return ls
Ejemplo n.º 19
0
def test_instantiate_uninitialize_undefined_exports():
    l = make_linklet("(linklet () (x))")
    _, t = eval_fixnum(l, empty_target())
    assert t.vars[W_Symbol.make("x")].val is w_uninitialized

    # don't touch if target has it
    l = make_linklet("(linklet () (x))")
    t = make_instance({'x':10})
    _, t = eval_fixnum(l, t)
    assert t.vars[W_Symbol.make("x")].val is not w_uninitialized

    # target exports the same var with another external name
    l = make_linklet("(linklet () (x2) (+ x2 x2))")
    t = inst(make_linklet("(linklet () ((x x2)) (define-values (x) 10))"))
    result, t = eval_fixnum(l, t)
    assert result == 20
    assert check_val(t, "x2", 10)
    assert not defines(t, "x")
Ejemplo n.º 20
0
def test_cache_recursive_lambda_if_no_frees():
    from pycket.interpreter import interpret_one
    from pycket.values import W_PromotableClosure
    letrec = expr_ast("(letrec ([self (lambda (y) (set! y (self 2)))]) self)")
    assert isinstance(letrec, Let) and isinstance(letrec.rhss[0], CaseLambda)

    lamb = letrec.rhss[0]
    assert lamb.recursive_sym is W_Symbol.make("self")

    w_cl1 = interpret_one(lamb)
    assert isinstance(w_cl1, W_PromotableClosure)
Ejemplo n.º 21
0
def test_cache_recursive_lambda_if_no_frees():
    from pycket.interpreter import interpret_one
    from pycket.values import W_PromotableClosure
    letrec = expr_ast("(letrec ([self (lambda (y) (set! y (self 2)))]) self)")
    assert isinstance(letrec, Let) and isinstance(letrec.rhss[0], CaseLambda)

    lamb = letrec.rhss[0]
    assert lamb.recursive_sym is W_Symbol.make("self")

    w_cl1 = interpret_one(lamb)
    assert isinstance(w_cl1, W_PromotableClosure)
Ejemplo n.º 22
0
def dev_mode_entry_sexp(eval_sexp_str=None):
    from pycket.values import W_Fixnum
    from pycket.util import console_log
    from pycket.prims.linklet import W_LinkletInstance


    from pycket.prims.linklet import do_compile_linklet
    from pycket.env import ToplevelEnv
    from pycket.cont import NilCont

    linkl_sexp = racket_read_str(eval_sexp_str)
    linkl = None
    try:
        do_compile_linklet(linkl_sexp, W_Symbol.make("linkl"), w_false, w_false, w_false, ToplevelEnv(), NilCont())
    except Done, e:
        linkl = e.values
Ejemplo n.º 23
0
def dev_mode_entry_sexp(eval_sexp_str=None):
    from pycket.values import W_Fixnum
    from pycket.util import console_log
    from pycket.prims.linklet import W_LinkletInstance


    from pycket.prims.linklet import do_compile_linklet
    from pycket.env import ToplevelEnv
    from pycket.cont import NilCont

    linkl_sexp = racket_read_str(eval_sexp_str)
    linkl = None
    try:
        do_compile_linklet(linkl_sexp, W_Symbol.make("linkl"), w_false, w_false, w_false, ToplevelEnv(), NilCont())
    except Done, e:
        linkl = e.values
Ejemplo n.º 24
0
def make_zo_for(linklet_name):
    from pycket.ast_vs_sexp import ast_to_sexp
    from pycket.values import W_Cons
    from pycket.prims.input_output import open_outfile

    # load the linklet
    linklet, version_sexp = load_linklet_from_fasl(linklet_name + ".fasl", set_version="expander" in linklet_name)

    # s-exp->fasl the linklet into a .zo
    sexp_to_fasl = get_primitive("s-exp->fasl")
    out_port = open_outfile(W_Path(linklet_name + ".zo"), "w", W_Symbol.make("replace"))
    linklet_sexp = ast_to_sexp(linklet)
    if "expander" in linklet_name:
        sexp_to_fasl.call_interpret([W_Cons.make(version_sexp, linklet_sexp), out_port])
    else:
        sexp_to_fasl.call_interpret([linklet_sexp, out_port])
    out_port.close()
Ejemplo n.º 25
0
def make_zo_for(linklet_name):
    from pycket.ast_vs_sexp import ast_to_sexp
    from pycket.values import W_Cons
    from pycket.prims.input_output import open_outfile

    # load the linklet
    linklet, version_sexp = load_linklet_from_fasl(linklet_name + ".fasl", set_version="expander" in linklet_name)

    # s-exp->fasl the linklet into a .zo
    sexp_to_fasl = get_primitive("s-exp->fasl")
    out_port = open_outfile(W_Path(linklet_name + ".zo"), "w", W_Symbol.make("replace"))
    linklet_sexp = ast_to_sexp(linklet)
    if "expander" in linklet_name:
        sexp_to_fasl.call_interpret([W_Cons.make(version_sexp, linklet_sexp), out_port])
    else:
        sexp_to_fasl.call_interpret([linklet_sexp, out_port])
    out_port.close()
Ejemplo n.º 26
0
def string_to_sexp(sexp):
    stack = []
    out = []
    if dbg:
        print("%-6s %-14s %-44s %-s" % tuple("term value out stack".split()))
    for termtypes in re.finditer(term_regex, sexp):
        term, value = [(t, v) for t, v in termtypes.groupdict().items()
                       if v][0]
        if dbg: print("%-7s %-14s %-44r %-r" % (term, value, out, stack))
        if term == 'l_paren' or term == 'll_paren':
            stack.append(out)
            out = []
        elif term == 'r_paren' or term == 'rr_paren':
            assert stack, "Trouble with nesting of brackets"
            tmpout, out = out, stack.pop(-1)
            out.append(tmpout)
        elif term == 'rational':
            v = to_num(value)
            out.append(v)
        elif term == 'compnum':
            real_part, imag_part = split_complex(value)
            v = W_Complex.make(to_num(real_part), to_num(imag_part))
            out.append(v)
        elif term == 'num':
            v = to_num(value)
            out.append(v)
        elif term == 'string':
            s = W_String.make(value[1:-1])
            out.append(s)
        elif term == 'char':
            c = W_Character(value[2:])
            out.append(c)
        elif term == 'bool':
            if value in ['#t', '#T', 'true', '#true']:
                b = w_true
            else:
                b = w_false
            out.append(b)
        elif term == 'sym':
            s = W_Symbol.make(value)
            out.append(s)
        else:
            raise NotImplementedError("Error: %r" % (term, value))
    assert not stack, "Trouble with nesting of brackets"
    return to_w_list(out[0])
Ejemplo n.º 27
0
def dev_mode_metainterp_fasl_zo():
    load_fasl()
    from pycket.prims.input_output import open_infile, open_outfile
    from pycket.values import W_Path
    import os

    # Stuff for writing out the fasl
    if not os.path.exists("sample.fasl"):
        print("Generating sample.fasl first")
        sexp_to_fasl = get_primitive("s-exp->fasl")
        w_replace_sym = W_Symbol.make("replace")
        sexp = sample_sexp()
        out_port = open_outfile(W_Path("sample.fasl"), "w", w_replace_sym)
        sexp_to_fasl.call_interpret([sexp, out_port])
        out_port.close()

    fasl_to_sexp = get_primitive("fasl->s-exp")
    port = open_infile(W_Path("sample.fasl"), "r")
    r = fasl_to_sexp.call_interpret([port, w_true])
Ejemplo n.º 28
0
def dev_mode_metainterp_fasl_zo():
    load_fasl()
    from pycket.prims.input_output import open_infile, open_outfile
    from pycket.values import W_Path
    import os

    # Stuff for writing out the fasl
    if not os.path.exists("sample.fasl"):
        print("Generating sample.fasl first")
        sexp_to_fasl = get_primitive("s-exp->fasl")
        w_replace_sym = W_Symbol.make("replace")
        sexp = sample_sexp()
        out_port = open_outfile(W_Path("sample.fasl"), "w", w_replace_sym)
        sexp_to_fasl.call_interpret([sexp, out_port])
        out_port.close()

    fasl_to_sexp = get_primitive("fasl->s-exp")
    port = open_infile(W_Path("sample.fasl"), "r")
    r = fasl_to_sexp.call_interpret([port, w_true])
Ejemplo n.º 29
0
def test_let_remove_num_envs_edge_case():
    m = run_mod("""
    #lang pycket
    (define d
      (let-values (((es) values))
        (let-values (((adj) '0))
          (let-values ((() (es)))
            adj))))
    """)
    d = W_Symbol.make("d")
    assert type(m.defs[d]) is W_Fixnum and m.defs[d].value == 0

    m = run_mod("""
    #lang pycket
    (define d
      (let-values (((es) '0))
        (let-values (((adj) '1))
          (let-values (((a b c) (begin es (values '2 '3 '4))))
            (+ adj a)))))
    """)
    assert type(m.defs[d]) is W_Fixnum and m.defs[d].value == 3
Ejemplo n.º 30
0
def test_let_remove_num_envs_edge_case():
    m = run_mod(
    """
    #lang pycket
    (define d
      (let-values (((es) values))
        (let-values (((adj) '0))
          (let-values ((() (es)))
            adj))))
    """)
    d = W_Symbol.make("d")
    assert type(m.defs[d]) is W_Fixnum and m.defs[d].value == 0

    m = run_mod(
    """
    #lang pycket
    (define d
      (let-values (((es) '0))
        (let-values (((adj) '1))
          (let-values (((a b c) (begin es (values '2 '3 '4))))
            (+ adj a)))))
    """)
    assert type(m.defs[d]) is W_Fixnum and m.defs[d].value == 3
Ejemplo n.º 31
0
def test_remove_simple_if():
    p = expr_ast("(if #t 'then 'else)")
    assert isinstance(p, Quote) and p.w_val is W_Symbol.make("then")
    p = expr_ast("(if #f 'then 'else)")
    assert isinstance(p, Quote) and p.w_val is W_Symbol.make("else")
Ejemplo n.º 32
0
def make_symbols(d):
    v = variable_set()
    for i, j in d.iteritems():
        v[ModuleVar(W_Symbol.make(i), None, W_Symbol.make(i))] = j
    return v
Ejemplo n.º 33
0
def make_primitive_table(ls_str):
    table = [None] * len(ls_str)
    for i, exposed_id in enumerate(ls_str):
        table[i] = W_Symbol.make(exposed_id)

    return table
Ejemplo n.º 34
0
# [core:correlated-property-symbol-keys syntax-property-symbol-keys]))
@expose("syntax-property-symbol-keys", [W_Correlated])
def correlated_property_symbol_keys(c):
    acc = w_null
    for k,v in c.get_props().iteritems():
        acc = W_Cons.make(k, acc)
    return acc

# [core:correlated-property syntax-property]
@expose("syntax-property", [W_Correlated, W_Object, default(W_Object, None)])
def correlated_property(stx, key, v):
    if v is None:
        # getting
        props = stx.get_props()
        if key in props:
            return props[key]
        return w_false
    else:
        # setting
        # FIXME: should not use mutation!
        stx.extend_prop(key, v)
        return stx

_syntax_primitives = ["syntax?", "syntax-e", "syntax->datum",
                      "datum->syntax", "syntax-source", "syntax-line",
                      "syntax-column", "syntax-position", "syntax-span",
                      "syntax-property-symbol-keys", "syntax-property"]

syntax_primitives = [W_Symbol.make(f) for f in _syntax_primitives]
Ejemplo n.º 35
0
def correlated_property_symbol_keys(c):
    acc = w_null
    for k, v in c.get_props().iteritems():
        acc = W_Cons.make(k, acc)
    return acc


# [core:correlated-property syntax-property]
@expose("syntax-property", [W_Correlated, W_Object, default(W_Object, None)])
def correlated_property(stx, key, v):
    if v is None:
        # getting
        props = stx.get_props()
        if key in props:
            return props[key]
        return w_false
    else:
        # setting
        # FIXME: should not use mutation!
        stx.extend_prop(key, v)
        return stx


_syntax_primitives = [
    "syntax?", "syntax-e", "syntax->datum", "datum->syntax", "syntax-source",
    "syntax-line", "syntax-column", "syntax-position", "syntax-span",
    "syntax-property-symbol-keys", "syntax-property"
]

syntax_primitives = [W_Symbol.make(f) for f in _syntax_primitives]
Ejemplo n.º 36
0
    from pycket.prims.linklet import W_LinkletInstance


    from pycket.prims.linklet import do_compile_linklet
    from pycket.env import ToplevelEnv
    from pycket.cont import NilCont

    linkl_sexp = racket_read_str(eval_sexp_str)
    linkl = None
    try:
        do_compile_linklet(linkl_sexp, W_Symbol.make("linkl"), w_false, w_false, w_false, ToplevelEnv(), NilCont())
    except Done, e:
        linkl = e.values

    instantiate_linklet = get_primitive("instantiate-linklet")
    target = W_LinkletInstance(W_Symbol.make("target"), {})

    res = instantiate_linklet.call_interpret([linkl, w_null, target, w_false])
    print("result : %s" % res.tostring())
    raise ExitException(linkl_sexp)

#FIXME : tidy up the arguments (e.g. pass the options dict)
def initiate_boot_sequence(command_line_arguments,
                           use_compiled=False,
                           debug=False,
                           set_run_file="",
                           set_collects_dir="",
                           set_config_dir="",
                           set_addon_dir="",
                           compile_any=False,
                           do_load_regexp=False):
Ejemplo n.º 37
0
def racket_entry(names, config, command_line_arguments):
    from pycket.prims.general import executable_yield_handler
    from pycket.values import W_Fixnum

    if config['make-zos']:
        make_bootstrap_zos()
        return 0

    linklet_perf.init()

    loads, startup_options, flags = get_options(names, config)

    init_library     = startup_options['init_library'][0]
    set_run_file     = startup_options['set_run_file'][0]
    set_collects_dir = startup_options['set_collects_dir'][0]
    set_config_dir   = startup_options['set_config_dir'][0]
    set_addon_dir    = startup_options['set_addon_dir'][0]
    eval_sexp        = startup_options['eval_sexp'][0]
    run_as_linklet   = startup_options['run_as_linklet'][0]
    load_linklets    = startup_options['load_linklets']
    load_as_linklets = startup_options['load_as_linklets']

    is_repl          = flags['is_repl']
    no_lib           = flags['no_lib']
    just_kernel      = flags['just_kernel']
    just_init        = flags['just_init']
    use_compiled     = flags['use_compiled']
    debug            = flags['debug']
    version          = flags['version']
    c_a              = flags['compile_any']
    do_load_regexp   = flags['do_load_regexp']
    dev_mode         = flags['dev_mode']

    if load_as_linklets:
        for rkt in load_as_linklets:
            create_linklet_json(rkt)
            load_inst_linklet("%s.linklet" % rkt)
        return 0

    if load_linklets:
        load_linklets_at_startup(load_linklets)
        return 0

    if dev_mode:
        dev_mode_entry(dev_mode, eval_sexp, run_as_linklet)
        return 0

    with PerfRegion("startup"):
        initiate_boot_sequence(command_line_arguments,
                               use_compiled,
                               debug,
                               set_run_file,
                               set_collects_dir,
                               set_config_dir,
                               set_addon_dir,
                               compile_any=c_a,
                               do_load_regexp=do_load_regexp)

    if just_init:
        return 0

    namespace_require = get_primitive("namespace-require")
    load = get_primitive("load")

    if just_kernel:
        console_log("Running on just the #%kernel")
        namespace_require_kernel()

    if not no_lib:
        with PerfRegion("init-lib"):
            init_lib = W_WrappedConsProper.make(W_Symbol.make("lib"),
                                                W_WrappedConsProper.make(W_String.make(init_library), w_null))
            console_log("(namespace-require %s) ..." % init_lib.tostring())

            namespace_require_plus(init_lib)
            console_log("Init lib : %s loaded..." % (init_library))

    put_newline = False
    if loads:
        for rator_str, rand_str in loads:
            if rator_str == "load":
                # -f
                console_log("(load %s)" % (rand_str))
                load.call_interpret([W_String.make(rand_str)])
            elif rator_str == "file" or rator_str == "lib":
                # -t & -l
                require_spec = W_WrappedConsProper.make(W_Symbol.make(rator_str),
                                                        W_WrappedConsProper.make(W_String.make(rand_str), w_null))
                console_log("(namespace-require '(%s %s))" % (rator_str, rand_str))
                namespace_require_plus(require_spec)
            elif rator_str == "eval":
                # -e
                console_log("(eval (read (open-input-string %s)))" % rand_str)
                read_eval_print_string(rand_str, False, debug)

    if version:
        from pycket.env import w_version
        print("Welcome to Pycket v%s" % w_version.get_version())

    if is_repl: # -i
        put_newline = True
        dynamic_require = get_primitive("dynamic-require")
        repl = dynamic_require.call_interpret([W_Symbol.make("racket/repl"),
                                               W_Symbol.make("read-eval-print-loop")])
        from pycket.env import w_global_config
        w_global_config.set_config_val('repl_loaded', 1)
        repl.call_interpret([])

    if put_newline:
        print


    linklet_perf.print_report()

    # we just want the global value anyway
    eyh = executable_yield_handler.call_interpret([])
    eyh.call_interpret([W_Fixnum.ZERO])

    exit = get_primitive("exit")
    exit.call_interpret([])

    return 0
Ejemplo n.º 38
0
def racket_entry(names, config, command_line_arguments):
    from pycket.prims.general import executable_yield_handler
    from pycket.values import W_Fixnum

    if config['make-zos']:
        make_bootstrap_zos()
        return 0

    linklet_perf.init()

    loads, startup_options, flags = get_options(names, config)

    init_library     = startup_options['init_library'][0]
    set_run_file     = startup_options['set_run_file'][0]
    set_collects_dir = startup_options['set_collects_dir'][0]
    set_config_dir   = startup_options['set_config_dir'][0]
    set_addon_dir    = startup_options['set_addon_dir'][0]
    eval_sexp        = startup_options['eval_sexp'][0]
    run_as_linklet   = startup_options['run_as_linklet'][0]
    load_linklets    = startup_options['load_linklets']
    load_as_linklets = startup_options['load_as_linklets']

    is_repl          = flags['is_repl']
    no_lib           = flags['no_lib']
    just_kernel      = flags['just_kernel']
    just_init        = flags['just_init']
    use_compiled     = flags['use_compiled']
    debug            = flags['debug']
    version          = flags['version']
    c_a              = flags['compile_any']
    do_load_regexp   = flags['do_load_regexp']
    dev_mode         = flags['dev_mode']

    if load_as_linklets:
        for rkt in load_as_linklets:
            create_linklet_json(rkt)
            load_inst_linklet("%s.linklet" % rkt)
        return 0

    if load_linklets:
        load_linklets_at_startup(load_linklets)
        return 0

    if dev_mode:
        dev_mode_entry(dev_mode, eval_sexp, run_as_linklet)
        return 0

    with PerfRegion("startup"):
        initiate_boot_sequence(command_line_arguments,
                               use_compiled,
                               debug,
                               set_run_file,
                               set_collects_dir,
                               set_config_dir,
                               set_addon_dir,
                               compile_any=c_a,
                               do_load_regexp=do_load_regexp)

    if just_init:
        return 0

    namespace_require = get_primitive("namespace-require")
    load = get_primitive("load")

    if just_kernel:
        console_log("Running on just the #%kernel")
        namespace_require_kernel()

    if not no_lib:
        with PerfRegion("init-lib"):
            init_lib = W_WrappedConsProper.make(W_Symbol.make("lib"),
                                                W_WrappedConsProper.make(W_String.make(init_library), w_null))
            console_log("(namespace-require %s) ..." % init_lib.tostring())

            namespace_require_plus(init_lib)
            console_log("Init lib : %s loaded..." % (init_library))

    put_newline = False
    if loads:
        for rator_str, rand_str in loads:
            if rator_str == "load":
                # -f
                console_log("(load %s)" % (rand_str))
                load.call_interpret([W_String.make(rand_str)])
            elif rator_str == "file" or rator_str == "lib":
                # -t & -l
                require_spec = W_WrappedConsProper.make(W_Symbol.make(rator_str),
                                                        W_WrappedConsProper.make(W_String.make(rand_str), w_null))
                console_log("(namespace-require '(%s %s))" % (rator_str, rand_str))
                namespace_require_plus(require_spec)
            elif rator_str == "eval":
                # -e
                console_log("(eval (read (open-input-string %s)))" % rand_str)
                read_eval_print_string(rand_str, False, debug)

    if version:
        from pycket.env import w_version
        print("Welcome to Pycket v%s" % w_version.get_version())

    if is_repl: # -i
        put_newline = True
        dynamic_require = get_primitive("dynamic-require")
        repl = dynamic_require.call_interpret([W_Symbol.make("racket/repl"),
                                               W_Symbol.make("read-eval-print-loop")])
        from pycket.env import w_global_config
        w_global_config.set_config_val('repl_loaded', 1)
        repl.call_interpret([])

    if put_newline:
        print


    linklet_perf.print_report()

    # we just want the global value anyway
    eyh = executable_yield_handler.call_interpret([])
    eyh.call_interpret([W_Fixnum.ZERO])

    exit = get_primitive("exit")
    exit.call_interpret([])

    return 0
Ejemplo n.º 39
0
def test_remove_simple_if():
    p = expr_ast("(if #t 'then 'else)")
    assert isinstance(p, Quote) and p.w_val is W_Symbol.make("then")
    p = expr_ast("(if #f 'then 'else)")
    assert isinstance(p, Quote) and p.w_val is W_Symbol.make("else")
Ejemplo n.º 40
0
paramz = make_primitive_table(paramz_str)
internal = make_primitive_table(internal_str)
futures = make_primitive_table(futures_str)
flfxnum = make_primitive_table(flfxnum_str)
extfl = make_primitive_table(extfl_str)
network = make_primitive_table(network_str)
foreign = make_primitive_table(foreign_str)
linklet = make_primitive_table(linklet_str)
unsafe = make_primitive_table(unsafe_str)
# FIXME : make it a #%pycket-extra, instead of piggybacking on the #%kernel
kernel = make_primitive_table(kernel_str)
pycket = make_primitive_table(pycket_extra_str + schemify_hooks)



select_prim_table = {W_Symbol.make("#%linklet"): linklet,
                     W_Symbol.make("#%kernel"): kernel,
                     W_Symbol.make("#%paramz"): paramz,
                     W_Symbol.make("#%unsafe"): unsafe,
                     W_Symbol.make("#%foreign"): foreign,
                     W_Symbol.make("#%futures"): futures,
                     W_Symbol.make("#%place"): place,
                     W_Symbol.make("#%flfxnum"): flfxnum,
                     W_Symbol.make("#%extfl"): extfl,
                     W_Symbol.make("#%pycket"): pycket,
                     W_Symbol.make("#%network"): network}

all_prims = linklet_str + \
            kernel_str + \
            paramz_str + \
            unsafe_str + \
Ejemplo n.º 41
0
              "syntax->datum", "datum->syntax", "syntax-property",
              "syntax-property-symbol-keys", "syntax-binding-set-extend"]

place = make_primitive_table(place_str)
paramz = make_primitive_table(paramz_str)
internal = make_primitive_table(internal_str)
futures = make_primitive_table(futures_str)
flfxnum = make_primitive_table(flfxnum_str)
extfl = make_primitive_table(extfl_str)
network = make_primitive_table(network_str)
foreign = make_primitive_table(foreign_str)
linklet = make_primitive_table(linklet_str)
unsafe = make_primitive_table(unsafe_str)
kernel = make_primitive_table(kernel_str)

select_prim_table = {W_Symbol.make("#%linklet"): linklet,
                     W_Symbol.make("#%kernel"): kernel,
                     W_Symbol.make("#%paramz"): paramz,
                     W_Symbol.make("#%unsafe"): unsafe,
                     W_Symbol.make("#%foreign"): foreign,
                     W_Symbol.make("#%futures"): futures,
                     W_Symbol.make("#%place"): place,
                     W_Symbol.make("#%flfxnum"): flfxnum,
                     W_Symbol.make("#%extfl"): extfl,
                     W_Symbol.make("#%network"): network}

all_prims = linklet_str + \
            kernel_str + \
            paramz_str + \
            unsafe_str + \
            foreign_str + \
Ejemplo n.º 42
0
place = make_primitive_table(place_str)
paramz = make_primitive_table(paramz_str)
internal = make_primitive_table(internal_str)
futures = make_primitive_table(futures_str)
flfxnum = make_primitive_table(flfxnum_str)
extfl = make_primitive_table(extfl_str)
network = make_primitive_table(network_str)
foreign = make_primitive_table(foreign_str)
linklet = make_primitive_table(linklet_str)
unsafe = make_primitive_table(unsafe_str)
# FIXME : make it a #%pycket-extra, instead of piggybacking on the #%kernel
kernel = make_primitive_table(kernel_str)
pycket = make_primitive_table(pycket_extra_str + schemify_hooks)

select_prim_table = {
    W_Symbol.make("#%linklet"): linklet,
    W_Symbol.make("#%kernel"): kernel,
    W_Symbol.make("#%paramz"): paramz,
    W_Symbol.make("#%unsafe"): unsafe,
    W_Symbol.make("#%foreign"): foreign,
    W_Symbol.make("#%futures"): futures,
    W_Symbol.make("#%place"): place,
    W_Symbol.make("#%flfxnum"): flfxnum,
    W_Symbol.make("#%extfl"): extfl,
    W_Symbol.make("#%pycket"): pycket,
    W_Symbol.make("#%network"): network
}

all_prims = linklet_str + \
            kernel_str + \
            paramz_str + \
Ejemplo n.º 43
0
def make_primitive_table(ls_str):
    table = [None] * len(ls_str)
    for i, exposed_id in enumerate(ls_str):
        table[i] = W_Symbol.make(exposed_id)

    return table
Ejemplo n.º 44
0
def make_symbols(d):
    v = variable_set()
    for i, j in d.iteritems():
        v[ModuleVar(W_Symbol.make(i), None, W_Symbol.make(i))] = j
    return v
Ejemplo n.º 45
0
    from pycket.prims.linklet import W_LinkletInstance


    from pycket.prims.linklet import do_compile_linklet
    from pycket.env import ToplevelEnv
    from pycket.cont import NilCont

    linkl_sexp = racket_read_str(eval_sexp_str)
    linkl = None
    try:
        do_compile_linklet(linkl_sexp, W_Symbol.make("linkl"), w_false, w_false, w_false, ToplevelEnv(), NilCont())
    except Done, e:
        linkl = e.values

    instantiate_linklet = get_primitive("instantiate-linklet")
    target = W_LinkletInstance(W_Symbol.make("target"), {})

    res = instantiate_linklet.call_interpret([linkl, w_null, target, w_false])
    print("result : %s" % res.tostring())
    raise ExitException(linkl_sexp)

#FIXME : tidy up the arguments (e.g. pass the options dict)
def initiate_boot_sequence(command_line_arguments,
                           use_compiled=False,
                           debug=False,
                           set_run_file="",
                           set_collects_dir="",
                           set_config_dir="",
                           set_addon_dir="",
                           compile_any=False,
                           do_load_regexp=False):