def replace_ctors(decls, flat): ctor_funcs = [] for dt in decls.dts: if extrinsic(Name, dt) == 'Maybe': continue # XXX maybe codegen for ctor in dt.ctors: ctor_funcs.append(generate_ctor(ctor, dt)) flat.funcs = ctor_funcs + flat.funcs vat.mutate(CtorReplacer, flat, t_DT(BlockUnit))
def walk_cfg(blockUnit): map_(walk_func, blockUnit.funcs) vat.mutate(DrumMutator, blockUnit, t_DT(BlockUnit))
def expand_unit(old_decl_mod, unit): checkpoint() t = t_DT(ExpandedUnit) expand_closures(unit) checkpoint('expanded closures') vat.mutate(FuncValGenerator, unit, t) vat.mutate(LitExpander, unit, t) vat.mutate(AssertionExpander, unit, t) checkpoint('expanded compound exprs') gen_gc_layouts(old_decl_mod.root) checkpoint('generated gc layouts') # Prepend generated TopFuncs now unit.funcs = env(EXGLOBAL).newDefns + unit.funcs flat = flatten.flatten_unit(unit) t = t_DT(BlockUnit) checkpoint('flattened') drum.walk(flat) checkpoint('did drum analysis') _prepare_decls(env(EXGLOBAL).newDecls) vat.mutate(TypeConverter, flat, t) checkpoint('convert to itypes') vat.mutate(MaybeConverter, flat, t) checkpoint('expanded maybes') vat.mutate(EnvExtrConverter, flat, t) checkpoint('expanded envs and extrs') replace_ctors(old_decl_mod.root, flat) _finish_decls(env(EXGLOBAL).newDecls) checkpoint('expanded ctors and types') vat.visit(ImportMarker, flat, t) checkpoint('marked imports') vat.visit(LocalVarUniquer, flat, t) checkpoint('uniqued vars') return flat
def expand_closures(unit): scope_extrinsic(ClosedVarFunc, lambda: scope_extrinsic(VarGlobalReplacement, lambda: vat.mutate(ClosureExpander, unit, t_DT(ExpandedUnit))))