Beispiel #1
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")
Beispiel #2
0
 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)
Beispiel #3
0
def library(path, func, dependencies, decorator):
    path = path.string
    if path.endswith(u".so") or path.endswith(u".json") or path.endswith(u".dll"):
        path = path.rsplit(u'.', 1)[0]
    json_path = pathobj.parse(path + u".json")
    so_path = path + u"." + platform.so_ext.decode('utf-8')
    api = open_api(json_path, dependencies, decorator)
    if func is not None:
        return FuncLibrary(api, func)
    return ffi.Library.interface.call([String(so_path), api])
Beispiel #4
0
def library(path, func, dependencies, decorator):
    path = path.string
    if path.endswith(u".so") or path.endswith(u".json") or path.endswith(u".dll"):
        path = path.rsplit(u'.', 1)[0]
    json_path = pathobj.parse(path + u".json")
    so_path = path + u"." + platform.so_ext.decode('utf-8')
    api = read_file(json_path, dependencies, decorator)
    if func is not None:
        return FuncLibrary(api, func)
    return ffi.Library.interface.call([String(so_path), api])
Beispiel #5
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)
Beispiel #6
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
Beispiel #7
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
Beispiel #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
Beispiel #9
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
Beispiel #10
0
    def getattr(self, name):
        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")
Beispiel #11
0
def init(lever_path):
    conf.headers_dir = pathobj.concat(lever_path, pathobj.parse(u"headers"))
Beispiel #12
0
def init(lever_path):
    conf.headers_dir = pathobj.concat(lever_path, pathobj.parse(u"headers"))
Beispiel #13
0
        listing = Object.listattr(self)
        listing.extend([
            String(u"path"),
            String(u"module"),
            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.
Beispiel #14
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")
Beispiel #15
0
    def getattr(self, name):
        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)
root_module.base_module = base.module
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)
root_module.setcache(pathobj.parse(u"builtin:/" + base.module.name), base.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)
    attach_compiler(lib_scope)
    main_path = pathobj.os_parse(resuffix(main_script.string, u".lc", u""))
    mi = moduleinfo(pathobj.abspath(main_path))
    scope = ModuleScope(mi.directory, lib_scope)
Beispiel #16
0
        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):