def expr(state, node): """typecheck expression nodes""" with state.current(node), tool.debug_scope(node) as scope: t = type(node) rule = dispatch.get(t, None) if rule: res = state.pure(rule(state, node)) scope[0] += " : " + res.show() return res # and now for the experimental stuff if t is ast.Sel: # attribute selection literals # attribute type attr_type = state.fresh() # row polymorphism happens here # FIXME broken encapsulation rest_type = row.Var(state.depth) return state.pure(row.Extension(node.attr, attr_type, rest_type) >> attr_type) elif t is ast.GenCheck: arg_type = expr(state, node.expr) # TODO is this even right ? if type(arg_type) is not Var: raise error.Type("gencheck argument type must be a type variable") # try to generalize poly = state.generalize(arg_type) # generalization failed if not poly.bound: raise GenCheckError() return state.pure(arg_type) elif t is ast.Move: arg_type = expr(state, node.expr) # TODO typeclass constraint ? # erase from scope del state[node.expr.name] return state.pure(arg_type) else: raise error.Type("unimplemented lol: {0}".format(node))
poly = hm.toplevel(ts, node ) try: out = node.name except AttributeError: out = '-' out += ' : ' + str(poly) ts.cleanup() if not args.codegen: print(out) continue with tool.debug_scope('closure conversion'): # closure conversion node = closure.toplevel( closure.State(), node) # typecheck closure conversion with tool.debug_scope('typecheck closure conversion'): poly = hm.toplevel(cc, node ) tool.debug('closure conversion type:', poly) with tool.debug_scope("codegen"): code = codegen.toplevel(cs, node) if code and type(node) in ast.expression_types: code = codegen.print_expr(cs, poly.body, code, out)