示例#1
0
def load_builtins():
    astconv.setup_builtin_module()
    root = BuiltinList(map(snd, sorted(atom.BUILTINS.items())))
    mod = Module(t_DT(BuiltinList), root)
    add_extrinsic(Name, mod, 'builtins')
    exports = {}
    for name, sym in atom.BUILTINS.iteritems():
        exports[name] = sym
    astconv.loaded_module_export_names[mod] = exports

    atom.write_mod_repr('views/symbols', mod)

    native.serialize(mod)
示例#2
0
def load_forms(modName, init):
    resolve_forward_type_refs()

    pending = set(t_DT(dt).data for dt in init)
    forms = []
    names = {}

    def found_dt(dt, apps):
        if dt not in SERIALIZED_FORMS:
            assert isinstance(dt, DataType), '%s is not a DT form' % (dt,)
            pending.add(dt)
        map_(scan_type_deps, apps)

    def found_tvar(tvar):
        names[tvar] = extrinsic(Name, tvar)

    def scan_type_deps(t):
        assert isinstance(t, Type), "%r is not a type" % (t,)
        match(t,
            ('TTuple(ts)', lambda ts: map_(scan_type_deps, ts)),
            ('TFunc(a, Ret(r), _)', lambda a, r: map_(scan_type_deps, a+[r])),
            ('TFunc(a, _, _)', lambda a: map_(scan_type_deps, a)),
            ('TData(dt, apps)', found_dt),
            ('TArray(e, _)', scan_type_deps),
            ('TWeak(t)', scan_type_deps),
            ('TVar(tvar)', found_tvar),
            ('TPrim(_)', nop))

    while pending:
        dt = pending.pop()
        SERIALIZED_FORMS.add(dt)
        if not has_extrinsic(Location, dt):
            for ctor in dt.ctors:
                for field in ctor.fields:
                    scan_type_deps(field.type)
                    names[field] = extrinsic(Name, field)
                names[ctor] = extrinsic(Name, ctor)
            forms.append(dt)
            names[dt] = extrinsic(Name, dt)

    mod = Module(t_DT(DtList), DtList(forms))
    add_extrinsic(Name, mod, modName)
    atom.write_mod_repr('views/%s' % (modName,), mod)
    native.serialize(mod)

    names_mod = extrinsic_mod(Name, names, mod)
    native.serialize(names_mod)

    if modName == 'forms':
        deserialize.save_form_meanings(forms)
示例#3
0
def build_mod(decl_mod, defn_mod, plan):
    name = extrinsic(Filename, decl_mod)
    impv = 'views/%s' % (name,)
    view = '%s_xdecls' % (impv,)

    checkpoint()
    casts = check.check_types(decl_mod, defn_mod)
    checkpoint('checked types')
    atom.write_mod_repr(impv, defn_mod, [TypeOf, TypeCast])

    checkpoint()
    new_decls, flat_unit = sub_profile('expanding module',
            lambda: expand.expand_module(decl_mod, defn_mod))
    xdecl_mod = Module(t_DT(atom.ModuleDecls), new_decls)
    defn_mod = Module(t_DT(quilt.BlockUnit), flat_unit)
    add_extrinsic(Name, xdecl_mod, '%sX' % (name,))
    add_extrinsic(Name, defn_mod, name)
    atom.write_mod_repr(view, xdecl_mod, [TypeOf])
    atom.write_mod_repr(impv+'_x', defn_mod, [quilt.LLVMTypeOf, TypeCast])
    checkpoint()
    native.serialize(xdecl_mod)
    native.serialize(defn_mod)
    checkpoint('serialized expanded module')

    llvm.compute_link_deps(decl_mod, xdecl_mod, defn_mod)

    compiled = False
    if isJust(plan.writeIR):
        ir = fromJust(plan.writeIR)
        checkpoint()
        llvm.write_ir(decl_mod, xdecl_mod, defn_mod, ir)
        checkpoint('wrote ir')
        compiled = llvm.compile(decl_mod)
        write_mod_headers(decl_mod, ir)

    if isJust(plan.linkBinary):
        binFilename = fromJust(plan.linkBinary)
        import os
        try:
            os.unlink(binFilename)
        except OSError:
            pass
        if compiled:
            if llvm.link(decl_mod, binFilename):
                print col('Green', 'Linked'), name
示例#4
0
def load_module_dep(src, deps, plan):
    name = plan.moduleName
    if name in WRITTEN_MODULES:
        mod = WRITTEN_MODULES[name]
        assert mod is not None, "%s is not ready yet!" % (name,)
        deps.add(mod)
        return mod
    WRITTEN_MODULES[name] = None
    names = {}

    def conv_mod():
        checkpoint()
        bundle_mod = capture_extrinsic(Name, names,
            lambda: astconv.convert_file(src, name, deps))
        decl_mod = bundle_mod.root.decls[0]
        add_extrinsic(Filename, decl_mod, name)
        view = 'views/%s' % (name,)
        if len(bundle_mod.root.units) == 0:
            atom.write_mod_repr(view, decl_mod)
            prop.prop_module_decls(decl_mod.root)
            atom.write_mod_repr(view, decl_mod, [TypeOf])
            return bundle_mod
        profile_separator()

        defn_mod = bundle_mod.root.units[0]

        impv = view
        view += '_decls'
        atom.write_mod_repr(view, decl_mod)
        atom.write_mod_repr(impv, defn_mod)

        scan.scan_unit(defn_mod.root)

        prop.prop_module_decls(decl_mod.root)
        atom.write_mod_repr(view, decl_mod, [TypeOf])
        checkpoint('module conversion and setup')
        prop.prop_compilation_unit(defn_mod.root)
        checkpoint('propped defns')
        atom.write_mod_repr(impv, defn_mod, [TypeOf, Instantiation])
        checkpoint()

        return bundle_mod
    bundle_mod = scope_extrinsic(InstMap,
            lambda: scope_extrinsic(astconv.AstType,
            lambda: scope_extrinsic(astconv.AstHint, conv_mod)))
    bundle = bundle_mod.root

    checkpoint()
    for decl_mod in bundle.decls:
        native.serialize(decl_mod)
        names_mod = extrinsic_mod(Name, names, decl_mod)
        native.serialize(names_mod)
        bundle.overlays.append(names_mod)

    if len(bundle.units) > 0:
        for mod in bundle.units:
            native.serialize(mod)
            names_mod = extrinsic_mod(Name, names, mod)
            native.serialize(names_mod)
            bundle.overlays.append(names_mod)
        checkpoint('serialized decls and defns')

        native.serialize(bundle_mod)

        def build():
            # really should link unit to its decl mod
            for decl_mod, defn_mod in ezip(bundle.decls, bundle.units):
                build_mod(decl_mod, defn_mod, plan)
        expand.in_intramodule_env(lambda: check.in_check_env(build))
    else:
        native.serialize(bundle_mod)
        checkpoint('serialized just decls')
        for decl_mod in bundle.decls:
            expand.expand_decls(decl_mod.root)
        checkpoint('expanded decls')
        if isJust(plan.writeIR):
            for decl_mod in bundle.decls:
                write_mod_headers(decl_mod, fromJust(plan.writeIR))

    assert WRITTEN_MODULES[name] is None
    WRITTEN_MODULES[name] = bundle_mod

    if name == 'maybe':
        # Stupid hack
        # expanded forms depend on maybe, but maybe depends on type forms
        # so just load the xforms now
        load_forms('xforms', [quilt.BlockUnit])

    return bundle_mod