Beispiel #1
0
Expr*
subst(Expr* e, const Subst& sub) {
  switch (e->kind) {
  case id_expr: return e;
  case unit_term: return e;
  case true_term: return e;
  case false_term: return e;
  case if_term: return subst_ternary_term(as<If>(e), sub);
  case int_term: return e;
  case and_term: return subst_binary_term(as<And>(e), sub);
  case or_term: return subst_binary_term(as<Or>(e), sub);
  case equals_term: return subst_binary_term(as<Equals>(e), sub);
  case less_term: return subst_binary_term(as<Less>(e), sub);
  case not_term: return subst_unary_term(as<Not>(e), sub);
  case succ_term: return subst_unary_term(as<Succ>(e), sub);
  case pred_term: return subst_unary_term(as<Pred>(e), sub);
  case iszero_term: return subst_unary_term(as<Iszero>(e), sub);
  case var_term: return subst_var(as<Var>(e), sub);
  case abs_term: return subst_binary_term(as<Abs>(e), sub);
  case app_term: return subst_binary_term(as<App>(e), sub);
  case ref_term: return subst_ref(as<Ref>(e), sub);
  case mem_term: return subst_mem(as<Mem>(e), sub);
  case kind_type: return e;
  case unit_type: return e;
  case bool_type: return e;
  case nat_type: return e;
  case arrow_type: return e;
  case record_term: return e;
  default: break;
  }
  lang_unreachable(format("substitution into unkown term '{}'", node_name(e)));
}
Beispiel #2
0
// Save the named term t in the current scope.
Expr*
declare(Expr* t) {
  if (Var* v = as<Var>(t))
    return declare(v->name(), v);
  if (Def* d = as<Def>(t))
    return declare(d->name(), d);
  lang_unreachable(format("cannot declare expression '{}'", node_name(t)));
}
Beispiel #3
0
// Returns the integer elaboration of the token. If the token is
// not one of the integer tokens, behavior is undefined.
Integer
as_integer(const Token& k) {
  lang_assert(token::get_type(k.kind) == token_int_type,
               format("token '{0}' is not an integer value", k));
  switch (k.kind) {
  case binary_literal_tok: return {k.text, 2};
  case octal_literal_tok: return {k.text, 8};
  case decimal_literal_tok: return {k.text, 10};
  case hexadecimal_literal_tok: return {k.text, 16};
  default: break;
  }
  lang_unreachable("invalid integer token");
}
Beispiel #4
0
// Render the given term into the output stream.
void
print(std::ostream& os, Tree* t) {
  if (not t) {
    os << "<null>";
    return;
  }

  switch (t->kind) {
  case id_tree: return pp_terminal(os, as<Id_tree>(t));
  case lit_tree: return pp_terminal(os, as<Lit_tree>(t));
  case var_tree: return pp_var(os, as<Var_tree>(t));
  case init_tree: return pp_init(os, as<Init_tree>(t));
  case abs_tree: return pp_abs(os, as<Abs_tree>(t));
  case fn_tree: return pp_fn(os, as<Fn_tree>(t));
  case app_tree: return pp_app(os, as<App_tree>(t));
  case if_tree:  return pp_if(os, as<If_tree>(t));
  case succ_tree: return pp_succ(os, as<Succ_tree>(t));
  case pred_tree: return pp_pred(os, as<Pred_tree>(t));
  case ls_tree: return pp_ls(os, as<Ls_tree>(t));//Rishi
  case mkdir_tree: return pp_mkdir(os, as<Mkdir_tree>(t));//Rishi
  case rmdir_tree: return pp_rmdir(os, as<Rmdir_tree>(t));//Rishi
  case cd_tree: return pp_cd(os, as<Cd_tree>(t));//Rishi
  case mv_tree: return pp_mv(os, as<Mv_tree>(t));//Rishi
  case iszero_tree: return pp_iszero(os, as<Iszero_tree>(t));
  case arrow_tree: return pp_arrow(os, as<Arrow_tree>(t));
  case def_tree: return pp_def(os, as<Def_tree>(t));
  case print_tree: return pp_print(os, as<Print_tree>(t));
  case typeof_tree: return pp_typeof(os, as<Typeof_tree>(t));
  case tuple_tree: return pp_tuple(os, as<Tuple_tree>(t));
  case list_tree: return pp_list(os, as<List_tree>(t));
  case variant_tree: return pp_variant(os, as<Variant_tree>(t));
  case comma_tree: return pp_comma(os, as<Comma_tree>(t));
  case dot_tree: return pp_dot(os, as<Dot_tree>(t));
  case prog_tree: return pp_prog(os, as<Prog_tree>(t));
  }
  lang_unreachable(format("print unknown node '{}'", node_name(t)));
}
Beispiel #5
0
// Compute the one-step evaluation of the term t.
Term*
step(Term* t) {
  lang_unreachable("not implemented");
}