Example #1
0
def moduleinfo(module_path):
    module_path = pathobj.abspath(module_path)
    module_name = module_path.getattr(u"basename")
    assert isinstance(module_name, String)
    s = pathobj.os_stringify(module_path).encode('utf-8')
    is_dir = False
    if os.path.isdir(s):
        w = os.path.join(s, "init")
        if os.path.exists(w + ".lc.cb") or os.path.exists(w + ".lc"):
            is_dir = True
            s = w
    else:
        module_path = pathobj.directory(module_path)
    cb_path = s + ".lc.cb"
    cb_present = os.path.exists(cb_path)
    cb_mtime = 0.0
    lc_path = s + ".lc"
    lc_present = os.path.exists(lc_path)
    lc_mtime = 0.0
    if cb_present:
        cb_mtime = os.path.getmtime(cb_path)
    if lc_present:
        lc_mtime = os.path.getmtime(lc_path)
    # This ignores outdated bytecode objects.
    if cb_present and lc_present:
        cb_present = not cb_mtime < lc_mtime
    return ModuleInfo(
        module_name, module_path,
        pathobj.os_parse(cb_path.decode('utf-8')), cb_present, cb_mtime,
        pathobj.os_parse(lc_path.decode('utf-8')), lc_present, lc_mtime,
    )
Example #2
0
def moduleinfo(module_path):
    module_path = pathobj.abspath(module_path)
    module_name = module_path.getattr(u"basename")
    assert isinstance(module_name, String)
    s = pathobj.os_stringify(module_path).encode('utf-8')
    is_dir = False
    if os.path.isdir(s):
        w = os.path.join(s, "init")
        if os.path.exists(w + ".lc.cb") or os.path.exists(w + ".lc"):
            is_dir = True
            s = w
    else:
        module_path = pathobj.directory(module_path)
    cb_path = s + ".lc.cb"
    cb_present = os.path.exists(cb_path)
    cb_mtime = 0.0
    lc_path = s + ".lc"
    lc_present = os.path.exists(lc_path)
    lc_mtime = 0.0
    if cb_present:
        cb_mtime = os.path.getmtime(cb_path)
    if lc_present:
        lc_mtime = os.path.getmtime(lc_path)
    # This ignores outdated bytecode objects.
    if cb_present and lc_present:
        cb_present = not cb_mtime < lc_mtime
    return ModuleInfo(
        module_name, module_path,
        pathobj.os_parse(cb_path.decode('utf-8')), cb_present, cb_mtime,
        pathobj.os_parse(lc_path.decode('utf-8')), lc_present, lc_mtime,
    )
Example #3
0
def start(main_script):
    assert isinstance(main_script, String)
    lib_scope = ModuleScope(
        pathobj.concat(main.get_ec().lever_path, pathobj.parse(u"lib")),
        root_module)
    main_path = pathobj.os_parse(resuffix(main_script.string, u".lc", u""))
    mi = moduleinfo(pathobj.abspath(main_path))
    scope = ModuleScope(mi.directory, lib_scope)
    this = Module(mi.name.string, {}, extends=base.module) # base.module
    if not (mi.lc_present or mi.cb_present):
        raise OldError(u"main module not present")
    mi.default_config(this, scope)
    mi.loadit(this)
    scope.setcache(main_path, this, max(mi.lc_mtime, mi.cb_mtime))
    return this
Example #4
0
def start(main_script):
    assert isinstance(main_script, String)
    lib_scope = ModuleScope(
        pathobj.concat(main.get_ec().lever_path, pathobj.parse(u"lib")),
        root_module)
    main_path = pathobj.os_parse(resuffix(main_script.string, u".lc", u""))
    mi = moduleinfo(pathobj.abspath(main_path))
    scope = ModuleScope(mi.directory, lib_scope)
    this = Module(mi.name.string, {}, extends=base.module)  # base.module
    if not (mi.lc_present or mi.cb_present):
        raise OldError(u"main module not present")
    mi.default_config(this, scope)
    mi.loadit(this)
    scope.setcache(main_path, this, max(mi.lc_mtime, mi.cb_mtime))
    return this
Example #5
0
    def entry_point(raw_argv):
        lever_path = os.environ.get('LEVER_PATH')
        if lever_path is None:
            lever_path = pathobj.parse(default_lever_path)
        else:
            lever_path = pathobj.os_parse(lever_path.decode('utf-8'))
        lever_path = pathobj.concat(pathobj.getcwd(), lever_path)

        # This should happen only once.
        uv_loop = uv.default_loop()
        uv_idler = uv.malloc_bytes(uv.idle_ptr, uv.handle_size(uv.IDLE))
        uv.idle_init(uv_loop, uv_idler)

        uv_stdin = initialize_stdio(uv_loop, 0, 1)
        uv_stdout = initialize_stdio(uv_loop, 1, 0)
        uv_stderr = initialize_stdio(uv_loop, 2, 0)

        base.module.setattr_force(u"stdin", uv_stdin)
        base.module.setattr_force(u"stdout", uv_stdout)
        base.module.setattr_force(u"stderr", uv_stderr)
        base.module.setattr_force(u"runtime_path", lever_path)

        ec = core.init_executioncontext(config, lever_path, uv_loop, uv_idler)
        core.g.log = log = uv_logging.Logger(ec, uv_stdout, uv_stderr)
        api.init(lever_path)
        vectormath.init_random()

        argv = [normal_startup]
        for arg in raw_argv[1:]:
            argv.append(space.String(arg.decode('utf-8')))
        core.schedule(argv)

        uv.run(ec.uv_loop, uv.RUN_DEFAULT)

        #uv.loop_close(ec.uv_loop)

        uv.tty_reset_mode()
        log.last_chance_logging()
        return ec.exit_status