コード例 #1
0
def read_file(path, dependencies, decorator):
    basename = path.getattr(u"basename")
    if isinstance(basename, String):
        if not basename.string.endswith(u".json"):
            dirname = path.getattr(u"dirname")
            path = pathobj.concat(dirname,
                pathobj.parse(basename.string + u".json"))
    path = pathobj.concat(conf.headers_dir, path)
    try:
        apispec = json.read_file(path)
    except OSError as error:
        raise OldError(u"[Errno %d]: %s\n" % (error.errno, pathobj.stringify(path)))
    return read_object(apispec, dependencies, decorator)
コード例 #2
0
def attach_compiler(lib_scope):
    mi = moduleinfo(pathobj.concat(lib_scope.local,
                                   pathobj.parse(u"compiler")))
    this = Module(mi.name.string, {}, extends=base.module)  # base.module
    mi.default_config(this, lib_scope)
    mi.loadit(this, lib_scope)
    lib_scope.compile_file = this.getattr(u"compile_file")
コード例 #3
0
ファイル: module_resolution.py プロジェクト: gordol/lever
 def call(self, argv):
     lib_scope = self.lib_scope
     mi = moduleinfo(pathobj.concat(lib_scope.local, pathobj.parse(u"compiler")))
     this = Module(mi.name.string, {}, extends=base.module) # base.module
     mi.default_config(this, lib_scope)
     mi.loadit(this, lib_scope)
     lib_scope.compile_file = this.getattr(u"compile_file")
     return lib_scope.compile_file.call(argv)
コード例 #4
0
 def call(self, argv):
     if len(argv) != 1:
         raise OldError(u"wrong number of arguments to import")
     name = argv[0]
     if isinstance(name, pathobj.Path):
         raise OldError(u"no direct loading yet")
     elif not isinstance(name, String):
         raise OldError(u"expected string")
     # import resolution:
     #  local/script.lc
     path = pathobj.concat(self.local, pathobj.to_path(name))
     cache = self.scope.getcache(path)
     if cache:
         return cache.module
     if not self.scope.frozen:
         mi = moduleinfo(path)
         if mi.lc_present or mi.cb_present:
             base_module = get_base_module(self.scope)
             this = Module(name.string, {},
                           extends=base_module)  # base.module
             self.scope.setcache(path, this, max(mi.lc_mtime, mi.cb_mtime))
             mi.default_config(this, self.scope)
             mi.loadit(this, self.scope)
             return this
     # scope/
     scope = self.scope
     while scope is not None:
         path = pathobj.concat(scope.local, pathobj.to_path(name))
         cache = scope.getcache(path)
         if cache:
             return cache.module
         if not scope.frozen:
             mi = moduleinfo(path)
             if mi.lc_present or mi.cb_present:
                 base_module = get_base_module(scope)
                 this = Module(name.string, {},
                               extends=base_module)  # base.module
                 scope.setcache(path, this, max(mi.lc_mtime, mi.cb_mtime))
                 mi.default_config(this, scope)
                 mi.loadit(this, scope)
                 return this
         scope = scope.parent
     raise OldError(u"module '%s' not present" % name.string)
コード例 #5
0
ファイル: module_resolution.py プロジェクト: cheery/lever
 def call(self, argv):
     if len(argv) != 1:
         raise OldError(u"wrong number of arguments to import")
     name = argv[0]
     if isinstance(name, pathobj.Path):
         raise OldError(u"no direct loading yet")
     elif not isinstance(name, String):
         raise OldError(u"expected string")
     # import resolution:
     #  local/script.lc
     path = pathobj.concat(self.local, pathobj.to_path(name))
     cache = self.scope.getcache(path)
     if cache:
         return cache.module
     if not self.scope.frozen:
         mi = moduleinfo(path)
         if mi.lc_present or mi.cb_present:
             base_module = get_base_module(self.scope)
             this = Module(name.string, {}, extends=base_module) # base.module
             mi.default_config(this, self.scope)
             mi.loadit(this, self.scope)
             self.scope.setcache(path, this, max(mi.lc_mtime, mi.cb_mtime))
             return this
     # scope/
     scope = self.scope
     while scope is not None:
         path = pathobj.concat(scope.local, pathobj.to_path(name))
         cache = scope.getcache(path)
         if cache:
             return cache.module
         if not scope.frozen:
             mi = moduleinfo(path)
             if mi.lc_present or mi.cb_present:
                 base_module = get_base_module(scope)
                 this = Module(name.string, {}, extends=base_module) # base.module
                 mi.default_config(this, scope)
                 mi.loadit(this, scope)
                 scope.setcache(path, this, max(mi.lc_mtime, mi.cb_mtime))
                 return this
         scope = scope.parent
     raise OldError(u"module '%s' not present" % name.string)
コード例 #6
0
ファイル: api.py プロジェクト: cheery/lever
def read_file(path, dependencies, decorator):
    basename = path.getattr(u"basename")
    if isinstance(basename, String):
        if not basename.string.endswith(u".json"):
            path.setattr(
                u"basename",
                String(basename.string + u".json"))
    path = pathobj.concat(conf.headers_dir, path)
    try:
        apispec = json.read_file(path)
    except OSError as error:
        raise OldError(u"[Errno %d]: %s\n" % (error.errno, pathobj.stringify(path)))
    return read_object(apispec, dependencies, decorator)
コード例 #7
0
ファイル: module_resolution.py プロジェクト: whitten/lever
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
コード例 #8
0
def normal_startup(argv):
    if len(argv) > 0:
        main_script = argv[0]
    else:
        main_script = pathobj.concat(core.get_ec().lever_path,
                                     pathobj.parse(u"app/main.lc"))
        main_script = space.String(pathobj.os_stringify(main_script))
    module = module_resolution.start(main_script)
    try:
        main_func = module.getattr(u"main")
    except space.Unwinder as unwinder:
        pass  # in this case main_func just isn't in the module.
    else:
        main_func.call([space.List(argv)])
    return space.null
コード例 #9
0
ファイル: module_resolution.py プロジェクト: Dohxis/lever
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
コード例 #10
0
def which(program):
    if isinstance(program, String):
        if program.string.count(u"/") > 0:
            program = pathobj.to_path(program)
    if isinstance(program, pathobj.Path):
        path = pathobj.os_stringify(program).encode('utf-8')
        if is_exe(path):
            return pathobj.concat(pathobj.getcwd(), program)
        return null
    elif not isinstance(program, String):
        raise OldError(u"string or path expected to .which()")
    program = as_cstring(program)
    for path in os.environ.get("PATH").split(os.pathsep):
        path = path.strip('"')
        exe_file = os.path.join(path, program)
        if is_exe(exe_file):
            return from_cstring(exe_file)
    return null
コード例 #11
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
コード例 #12
0
            String(u"mtime"),
        ])
        return listing


@ModuleCache.builtin_method
@signature(ModuleCache)
def get_moduleinfo(self):
    return moduleinfo(self.path)


root_module = ModuleScope(pathobj.parse(u"builtin:/"), frozen=True)
root_module.base_module = base.module
for py_module in stdlib.import_all_modules():
    assert isinstance(py_module.module, Module), "dependency cycle somewhere"
    p = pathobj.concat(root_module.local, pathobj.parse(py_module.module.name))
    py_module.module.setattr_force(
        u"doc", pathobj.parse(u"doc:/" + py_module.module.name))
    importer_poststage(py_module.module)
    root_module.setcache(p, py_module.module, 0.0)

base.module.setattr_force(u"doc", pathobj.parse(u"doc:/base"))
root_module.setcache(pathobj.parse(u"builtin:/" + base.module.name),
                     base.module, 0.0)
# the importer poststage for base module will take place in
# entry generation at runtime/main.py because there are so many
# items added into the base module all around the system.


def start(main_script):
    assert isinstance(main_script, String)
コード例 #13
0
ファイル: module_resolution.py プロジェクト: Dohxis/lever
        if name == u"path":
            return self.path
        if name == u"module":
            return self.module
        if name == u"mtime":
            return Float(self.mtime)
        return Object.getattr(self, name)

@ModuleCache.builtin_method
@signature(ModuleCache)
def get_moduleinfo(self):
    return moduleinfo(self.path)

root_module = ModuleScope(pathobj.parse(u"builtin:/"), frozen=True)
for py_module in stdlib.import_all_modules():
    p = pathobj.concat(root_module.local, pathobj.parse(py_module.module.name))
    root_module.setcache(p, py_module.module, 0.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)
コード例 #14
0
ファイル: api.py プロジェクト: pombredanne/lever
def get_header(path):
    return pathobj.concat(conf.headers_dir, path)
コード例 #15
0
ファイル: api.py プロジェクト: pombredanne/lever
def init(lever_path):
    conf.headers_dir = pathobj.concat(lever_path, pathobj.parse(u"headers"))
コード例 #16
0
def get_header(path):
    return pathobj.concat(conf.headers_dir, path)
コード例 #17
0
def init(lever_path):
    conf.headers_dir = pathobj.concat(lever_path, pathobj.parse(u"headers"))
コード例 #18
0
ファイル: module_resolution.py プロジェクト: cheery/lever
def attach_compiler(lib_scope):
    mi = moduleinfo(pathobj.concat(lib_scope.local, pathobj.parse(u"compiler")))
    this = Module(mi.name.string, {}, extends=base.module) # base.module
    mi.default_config(this, lib_scope)
    mi.loadit(this, lib_scope)
    lib_scope.compile_file = this.getattr(u"compile_file")