def sig(var, codom): """Create the term Sig x:A.B from its constituents Arguments: - `var`: a constant expr - `codom`: an expression possibly containing var """ if var.is_const(): codom_abs = e.abstract_expr([var.name], codom) return e.Bound(e.Sig(var.name), var.type, codom_abs) else: mess = "Expected {0!s} to be a constant".format(var) raise e.ExprError(mess, var)
def exists(var, prop): """Create the term exists x:A.t from its constituents Arguments: - `var`: a constant expr - `prop`: an expression possibly containing var """ if var.is_const(): prop_abs = e.abstract_expr([var.name], prop) return e.Bound(e.Exists(var.name), var.type, prop_abs) else: mess = "Expected {0!s} to be a constant".format(var) raise e.ExprError(mess, var)
def pi(var, codom, impl=None): """Create the term Pi x:A.B from its constituents Arguments: - `var`: a constant expr - `codom`: an expression possibly containing var - `impl`: a flag which notes if the argument is implicit. """ if var.is_const(): codom_abs = e.abstract_expr([var.name], codom) ret = e.Bound(e.Pi(var.name), var.type, codom_abs) if impl: ret.info['implicit'] = True return ret else: mess = "Expected {0!s} to be a constant".format(var) raise e.ExprError(mess, var)
def abst(var, body): """Create the term lambda x:A.t from its constituents Arguments: - `var`: a constant expr - `body`: an expression possibly containing var """ if var.is_const(): ty, _ = mvar_infer(var.type) if ty.equals(e.Bool()): body = enrich(var.name, var.type, body) else: pass body_abs = e.abstract_expr([var.name], body) return e.Bound(e.Abst(var.name), var.type, body_abs) else: print var.__class__ mess = "Expected {0!s} to be a constant".format(var) raise e.ExprError(mess, var)
def visit_mvar(self, expr): if expr.has_value(): sub_val = self.visit(expr._value) if self.undef is None: #we are in this case if we are still solving #constraints: the abstractions should not be applied #yet. pass else: for p in expr.pending: sub_val = p.now(sub_val) return sub_val else: if self.undef is None: return expr else: typ = self.visit(expr.type) mess = "Cannot find a value for {0!s}:{1!s}"\ .format(expr, typ) raise e.ExprError(mess, expr)