Exemplo n.º 1
0
 bool apply(expr const & a, expr const & b) {
     if (is_eqp(a, b))          return true;
     if (a.hash() != b.hash())  return false;
     if (a.kind() != b.kind())  return false;
     if (is_var(a))             return var_idx(a) == var_idx(b);
     if (m_cache.check(a, b))
         return true;
     switch (a.kind()) {
     case expr_kind::Var:
         lean_unreachable(); // LCOV_EXCL_LINE
     case expr_kind::Constant:
         return
             const_name(a) == const_name(b) &&
             compare(const_levels(a), const_levels(b), [](level const & l1, level const & l2) { return l1 == l2; });
     case expr_kind::Meta:
         return
             mlocal_name(a) == mlocal_name(b) &&
             apply(mlocal_type(a), mlocal_type(b));
     case expr_kind::Local:
         return
             mlocal_name(a) == mlocal_name(b) &&
             apply(mlocal_type(a), mlocal_type(b)) &&
             (!CompareBinderInfo || local_pp_name(a) == local_pp_name(b)) &&
             (!CompareBinderInfo || local_info(a) == local_info(b));
     case expr_kind::App:
         check_system();
         return
             apply(app_fn(a), app_fn(b)) &&
             apply(app_arg(a), app_arg(b));
     case expr_kind::Lambda: case expr_kind::Pi:
         check_system();
         return
             apply(binding_domain(a), binding_domain(b)) &&
             apply(binding_body(a), binding_body(b)) &&
             (!CompareBinderInfo || binding_name(a) == binding_name(b)) &&
             (!CompareBinderInfo || binding_info(a) == binding_info(b));
     case expr_kind::Let:
         check_system();
         return
             apply(let_type(a), let_type(b)) &&
             apply(let_value(a), let_value(b)) &&
             apply(let_body(a), let_body(b)) &&
             (!CompareBinderInfo || let_name(a) == let_name(b));
     case expr_kind::Sort:
         return sort_level(a) == sort_level(b);
     case expr_kind::Macro:
         check_system();
         if (macro_def(a) != macro_def(b) || macro_num_args(a) != macro_num_args(b))
             return false;
         for (unsigned i = 0; i < macro_num_args(a); i++) {
             if (!apply(macro_arg(a, i), macro_arg(b, i)))
                 return false;
         }
         return true;
     }
     lean_unreachable(); // LCOV_EXCL_LINE
 }
Exemplo n.º 2
0
    expr visit(expr const & e) {
        switch (e.kind()) {
        case expr_kind::Sort:  case expr_kind::Constant:
        case expr_kind::Var:   case expr_kind::Meta:
        case expr_kind::Local:
            return e;
        default:
            break;
        }

        check_system("unfold macros");
        auto it = m_cache.find(e);
        if (it != m_cache.end())
            return it->second;

        switch (e.kind()) {
        case expr_kind::Sort:  case expr_kind::Constant:
        case expr_kind::Var:   case expr_kind::Meta:
        case expr_kind::Local:
            lean_unreachable();
        case expr_kind::Macro:
            return save_result(e, visit_macro(e));
        case expr_kind::App:
            return save_result(e, visit_app(e));
        case expr_kind::Lambda: case expr_kind::Pi:
            return save_result(e, visit_binding(e));
        }
        lean_unreachable();
    }
Exemplo n.º 3
0
expr replace_visitor::visit(expr const & e) {
    check_system("expression replacer");
    bool shared = false;
    if (is_shared(e)) {
        shared = true;
        auto it = m_cache.find(e);
        if (it != m_cache.end())
            return it->second;
    }

    switch (e.kind()) {
    case expr_kind::Sort:      return save_result(e, visit_sort(e), shared);
    case expr_kind::Macro:     return save_result(e, visit_macro(e), shared);
    case expr_kind::Constant:  return save_result(e, visit_constant(e), shared);
    case expr_kind::Var:       return save_result(e, visit_var(e), shared);
    case expr_kind::Meta:      return save_result(e, visit_meta(e), shared);
    case expr_kind::Local:     return save_result(e, visit_local(e), shared);
    case expr_kind::App:       return save_result(e, visit_app(e), shared);
    case expr_kind::Lambda:    return save_result(e, visit_lambda(e), shared);
    case expr_kind::Pi:        return save_result(e, visit_pi(e), shared);
    case expr_kind::Let:       return save_result(e, visit_let(e), shared);
    }

    lean_unreachable(); // LCOV_EXCL_LINE
}
Exemplo n.º 4
0
 expr apply(expr const & a) {
     check_system("max_sharing");
     auto r = m_expr_cache.find(a);
     if (r != m_expr_cache.end())
         return *r;
     expr res;
     switch (a.kind()) {
     case expr_kind::Var:
         res = a;
         break;
     case expr_kind::Constant:
         res = update_constant(a, map(const_levels(a), [&](level const & l) { return apply(l); }));
         break;
     case expr_kind::Sort:
         res = update_sort(a, apply(sort_level(a)));
         break;
     case expr_kind::App:
         res = update_app(a, apply(app_fn(a)), apply(app_arg(a)));
         break;
     case expr_kind::Lambda: case expr_kind::Pi:
         res = update_binding(a, apply(binding_domain(a)), apply(binding_body(a)));
         break;
     case expr_kind::Meta:  case expr_kind::Local:
         res = update_mlocal(a, apply(mlocal_type(a)));
         break;
     case expr_kind::Macro: {
         buffer<expr> new_args;
         for (unsigned i = 0; i < macro_num_args(a); i++)
             new_args.push_back(macro_arg(a, i));
         res = update_macro(a, new_args.size(), new_args.data());
         break;
     }}
     m_expr_cache.insert(res);
     return res;
 }
Exemplo n.º 5
0
bool expr_eq_fn::apply(expr const & a, expr const & b) {
    if (is_eqp(a, b))          return true;
    if (a.hash() != b.hash())  return false;
    if (a.kind() != b.kind())  return false;
    if (is_var(a))             return var_idx(a) == var_idx(b);
    if (m_counter >= LEAN_EQ_CACHE_THRESHOLD && is_shared(a) && is_shared(b)) {
        auto p = std::make_pair(a.raw(), b.raw());
        if (!m_eq_visited)
            m_eq_visited.reset(new expr_cell_pair_set);
        if (m_eq_visited->find(p) != m_eq_visited->end())
            return true;
        m_eq_visited->insert(p);
    }
    check_system("expression equality test");
    switch (a.kind()) {
    case expr_kind::Var:
        lean_unreachable(); // LCOV_EXCL_LINE
    case expr_kind::Constant:
        return
            const_name(a) == const_name(b) &&
            compare(const_levels(a), const_levels(b), [](level const & l1, level const & l2) { return l1 == l2; });
    case expr_kind::Local: case expr_kind::Meta:
        return
            mlocal_name(a) == mlocal_name(b) &&
            apply(mlocal_type(a), mlocal_type(b));
    case expr_kind::App:
        m_counter++;
        return
            apply(app_fn(a), app_fn(b)) &&
            apply(app_arg(a), app_arg(b));
    case expr_kind::Lambda: case expr_kind::Pi:
        m_counter++;
        return
            apply(binding_domain(a), binding_domain(b)) &&
            apply(binding_body(a), binding_body(b)) &&
            (!m_compare_binder_info || binding_info(a) == binding_info(b));
    case expr_kind::Sort:
        return sort_level(a) == sort_level(b);
    case expr_kind::Macro:
        m_counter++;
        if (macro_def(a) != macro_def(b) || macro_num_args(a) != macro_num_args(b))
            return false;
        for (unsigned i = 0; i < macro_num_args(a); i++) {
            if (!apply(macro_arg(a, i), macro_arg(b, i)))
                return false;
        }
        return true;
    case expr_kind::Let:
        m_counter++;
        return
            apply(let_type(a), let_type(b)) &&
            apply(let_value(a), let_value(b)) &&
            apply(let_body(a), let_body(b));
    }
    lean_unreachable(); // LCOV_EXCL_LINE
}
Exemplo n.º 6
0
static
int slvDOF_destroy(slvDOF_system_t sys)
{
  if (check_system(sys)) return 1;
  destroy_matrices(sys);
  sys->integrity = DESTROYED;
  if (sys->s.cost) ascfree(sys->s.cost);
  ascfree( (POINTER)sys );
  return 0;
}
Exemplo n.º 7
0
 /**
    \brief Given
               C1 : H1,  where C1 contains l
               C2 : H2,  where C2 contains not_l
     Return a proof of the resolvent R of C1 and C2
 */
 expr mk_or_elim_tree1(expr const & l, expr const & not_l, expr C1, expr const & H1, expr const & C2, expr const & H2,
                       expr const & R, extension_context & ctx) const {
     check_system("resolve macro");
     expr lhs, rhs;
     if (is_or(C1, lhs, rhs)) {
         return mk_or_elim_tree1(l, not_l, lhs, rhs, H1, C2, H2, R, ctx);
     } else {
         C1 = whnf(C1, ctx);
         if (is_or(C1, lhs, rhs)) {
             return mk_or_elim_tree1(l, not_l, lhs, rhs, H1, C2, H2, R, ctx);
         } else if (is_def_eq(C1, l, ctx)) {
             return mk_or_elim_tree2(C1, H1, not_l, C2, H2, R, ctx);
         } else {
             return mk_or_intro(C1, H1, R, ctx);
         }
     }
 }
Exemplo n.º 8
0
 /**
    Given
          l  : H
          C2 : H2, where C2 contains not_l
    produce a proof for R
 */
 expr mk_or_elim_tree2(expr const & l, expr const & H, expr const & not_l, expr C2, expr const & H2,
                       expr const & R, extension_context & ctx) const {
     check_system("resolve macro");
     expr lhs, rhs;
     if (is_or(C2, lhs, rhs)) {
         return mk_or_elim_tree2(l, H, not_l, lhs, rhs, H2, R, ctx);
     } else {
         C2 = whnf(C2, ctx);
         if (is_or(C2, lhs, rhs)) {
             return mk_or_elim_tree2(l, H, not_l, lhs, rhs, H2, R, ctx);
         } else if (is_def_eq(C2, not_l, ctx)) {
             // absurd_elim {a : Prop} (b : Prop) (H1 : a) (H2 : ¬ a) : b
             return mk_app(*g_absurd_elim, l, R, H, H2);
         } else {
             return mk_or_intro(C2, H2, R, ctx);
         }
     }
 }
Exemplo n.º 9
0
 bool collect(expr cls, expr const & l, buffer<expr> & R, extension_context & ctx) const {
     check_system("resolve macro");
     expr lhs, rhs;
     if (is_or(cls, lhs, rhs)) {
         return collect(lhs, rhs, l, R, ctx);
     } else {
         cls = whnf(cls, ctx);
         if (is_or(cls, lhs, rhs)) {
             return collect(lhs, rhs, l, R, ctx);
         } else if (is_def_eq(cls, l, ctx)) {
             return true; // found literal l
         } else {
             if (!already_contains(cls, R, ctx))
                 R.push_back(cls);
             return false;
         }
     }
 }
Exemplo n.º 10
0
 expr normalize(expr e) {
     check_system("normalize");
     if (!m_pred(e))
         return e;
     auto w = m_tc.whnf(e);
     e = w.first;
     if (m_save_cnstrs)
         m_cnstrs += w.second;
     switch (e.kind()) {
     case expr_kind::Var:  case expr_kind::Constant: case expr_kind::Sort:
     case expr_kind::Meta: case expr_kind::Local: case expr_kind::Macro:
         return e;
     case expr_kind::Lambda: case expr_kind::Pi:
         return normalize_binding(e);
     case expr_kind::App:
         return normalize_app(e);
     }
     lean_unreachable(); // LCOV_EXCL_LINE
 }
Exemplo n.º 11
0
 /** \brief Given l : H, and R == (or ... l ...), create a proof term for R using or_intro_left and or_intro_right */
 expr mk_or_intro(expr const & l, expr const & H, expr const & R, extension_context & ctx) const {
     check_system("resolve macro");
     if (is_or_app(R)) {
         expr lhs = app_arg(app_fn(R));
         expr rhs = app_arg(R);
         // or_intro_left {a : Prop} (H : a) (b : Prop) : a ∨ b
         // or_intro_right {b : Prop} (a : Prop) (H : b) : a ∨ b
         if (is_def_eq(l, lhs, ctx)) {
             return mk_app(*g_or_intro_left, l, H, rhs);
         } else if (is_def_eq(l, rhs, ctx)) {
             return mk_app(*g_or_intro_right, l, lhs, H);
         } else {
             return mk_app(*g_or_intro_right, rhs, lhs, mk_or_intro(l, H, rhs, ctx));
         }
     } else if (is_def_eq(l, R, ctx)) {
         return H;
     } else {
         throw_kernel_exception(ctx.env(), "bug in resolve macro");
     }
 }
Exemplo n.º 12
0
expr dsimplify_core_fn::visit(expr const & e) {
    check_system("dsimplify");
    inc_num_steps();

    lean_trace_inc_depth("dsimplify");
    lean_dsimp_trace(m_ctx, "dsimplify", tout() << e << "\n";);
Exemplo n.º 13
0
result simplifier::simplify(expr const & e, bool is_root) {
    check_system("simplifier");
    m_num_steps++;
    lean_trace_inc_depth("simplifier");
    lean_trace_d("simplifier", tout() << m_rel << ": " << ppb(e) << "\n";);
Exemplo n.º 14
0
int
main (int argc, char **argv)
{
    char *script_filename = NULL;
    GError *error = NULL;
    SwfdecAsContext *context;
    SwfdecAsObject *array;
    SwfdecScript *script;
    SwfdecAsValue val;
    int i, ret;
    gboolean dump = FALSE;
    gboolean no_check = FALSE, only_check = FALSE;

    GOptionEntry options[] = {
        { "dump", 'd', 0, G_OPTION_ARG_NONE, &dump, "dump informative output on failure", FALSE },
        { "no-check", 0, 0, G_OPTION_ARG_NONE, &no_check, "don't check if the system is ok for running the testsuite", FALSE },
        { "self-check", 0, 0, G_OPTION_ARG_NONE, &only_check, "run a system check and exit", FALSE },
        { "player", 'p', 0, G_OPTION_ARG_STRING, &swfdec_test_plugin_name, "player to test", "NAME" },
        { "script", 's', 0, G_OPTION_ARG_STRING, &script_filename, "script to execute if not ./default.sts", "FILENAME" },
        { NULL }
    };
    GOptionContext *ctx;

    /* set the right warning levels */
    g_log_set_always_fatal (G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING);
    /* by default get rid of the loads of warnings the tests produce */
    g_setenv ("SWFDEC_DEBUG", "2", FALSE);

    g_thread_init (NULL);
    swfdec_init ();

    ctx = g_option_context_new ("");
    g_option_context_add_main_entries (ctx, options, "options");
    g_option_context_parse (ctx, &argc, &argv, &error);
    g_option_context_free (ctx);

    if (error) {
        g_printerr ("ERROR: wrong command line arguments: %s\n", error->message);
        g_error_free (error);
        return EXIT_FAILURE;
    }

    if (only_check || !no_check) {
        gboolean result = check_system (only_check);
        if (!result) {
            g_print ("ERROR: System checked failed, aborting. Use --no-check to disable.\n");
            return 1;
        } else if (only_check) {
            return 0;
        }
    }
    g_assert (!only_check);

    /* allow env vars instead of options - eases running make check with different settings */
    if (swfdec_test_plugin_name == NULL)
        swfdec_test_plugin_name = g_strdup (g_getenv ("SWFDEC_TEST_PLAYER"));

    script = load_script (script_filename);
    g_free (script_filename);
    if (script == NULL)
        return EXIT_FAILURE;

    context = g_object_new (SWFDEC_TYPE_AS_CONTEXT, NULL);
    swfdec_as_context_startup (context);

    SWFDEC_AS_VALUE_SET_BOOLEAN (&val, dump);
    swfdec_as_object_set_variable (context->global,
                                   swfdec_as_context_get_string (context, "dump"), &val);

    swfdec_test_function_init_context (context);
    swfdec_as_context_run_init_script (context, swfdec_test_initialize,
                                       sizeof (swfdec_test_initialize), SWFDEC_TEST_VERSION);

    array = swfdec_as_array_new (context);
    if (array == NULL) {
        g_print ("ERROR: Not enough memory");
        return EXIT_FAILURE;
    }
    if (argc < 2) {
        GDir *dir;
        const char *file;
        dir = g_dir_open (".", 0, NULL);
        while ((file = g_dir_read_name (dir))) {
            if (!g_str_has_suffix (file, ".swf"))
                continue;
            SWFDEC_AS_VALUE_SET_STRING (&val, swfdec_as_context_get_string (context, file));
            swfdec_as_array_push (SWFDEC_AS_ARRAY (array), &val);
        }
        g_dir_close (dir);
    } else {
        for (i = 1; i < argc; i++) {
            SWFDEC_AS_VALUE_SET_STRING (&val, swfdec_as_context_get_string (context, argv[i]));
            swfdec_as_array_push (SWFDEC_AS_ARRAY (array), &val);
        }
    }
    SWFDEC_AS_VALUE_SET_OBJECT (&val, array);
    swfdec_as_object_set_variable (context->global,
                                   swfdec_as_context_get_string (context, "filenames"), &val);
    swfdec_as_object_run (context->global, script);
    if (swfdec_as_context_catch (context, &val)) {
        g_print ("ERROR: %s\n", swfdec_as_value_to_string (context, &val));
        ret = EXIT_FAILURE;
    } else {
        g_print ("SUCCESS\n");
        ret = EXIT_SUCCESS;
    }

    swfdec_script_unref (script);
    g_object_unref (context);

    return ret;
}
Exemplo n.º 15
0
bool is_equivalent(level const & lhs, level const & rhs) {
    check_system("level constraints");
    return lhs == rhs || normalize(lhs) == normalize(rhs);
}
Exemplo n.º 16
0
int
main (int argc, char *argv[])
{
  int i;
  char tmp[256], *env;

  struct stat st;

  if (getenv("USE_PHPMAKE") != NULL)
  if (stat("phpmake/library.php", &st) != -1)
     config_phpmake=1;

  for (i = 1; i < argc; i++)
    if (argv[i][0] == '-')
      switch (argv[i][1])
	{
	case 'A':
	  strcpy (arch, &argv[i][2]);
	  printf ("Arch=%s\n", arch);
	  break;
	case 'K':
	  kernelonly = 1;
	  break;		/* Compile only the kernel mode parts */
	case 'U':
	  useronly = 1;
	  break;		/* Compile only the user land utilities */
	}

  if (getenv("NO_WARNING_CHECKS")!=NULL)
     do_warning_checks = 0;

  hostcc = getenv ("HOSTCC");
  targetcc = getenv ("CC");
  if (hostcc == NULL) hostcc = DEFAULT_CC;
  if (targetcc == NULL) targetcc = DEFAULT_CC;

#if defined(linux) || defined(__FreeBSD__) || defined(__SCO_VERSION__)
  mkdir ("target", 0755);
  mkdir ("target/build", 0755);
  system ("touch target/build/.nomake");
#endif

  if (getenv ("SOL9") != NULL)
    system ("touch kernel/drv/oss_usb/.nomake");

  check_system (&conf);

/*
 * Check if setup/$CROSSCOMPILE.conf exists and load the settings in it.
 */
  if ((env=getenv("CROSSCOMPILE"))!=NULL)
     {
	     FILE *cf;

	     sprintf (tmp, "setup/%s.conf", env);
  	     if ((cf = fopen (tmp, "r")) != NULL)
    		{
      	     		parse_config (cf, &conf, tmp);
			fclose (cf);
     		}
     }
  

  produce_output (&conf);

  produce_errno_h();
  exit (0);
}