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; }
expr apply(expr const & a) { auto r = m_cache.find(a); if (r != m_cache.end()) { lean_assert((*r).raw()->max_shared()); return *r; } if (a.raw()->max_shared()) { m_cache.insert(a); return a; } switch (a.kind()) { case expr_kind::Var: case expr_kind::Constant: case expr_kind::Type: case expr_kind::Value: cache(a); return a; case expr_kind::App: { expr r = update_app(a, [=](expr const & c){ return apply(c); }); cache(r); return r; } case expr_kind::Eq : { expr r = update_eq(a, [=](expr const & l, expr const & r){ return std::make_pair(apply(l), apply(r)); }); cache(r); return r; } case expr_kind::Lambda: case expr_kind::Pi: { expr r = update_abst(a, [=](expr const & t, expr const & b) { return std::make_pair(apply(t), apply(b)); }); cache(r); return r; } case expr_kind::Let: { expr r = update_let(a, [=](expr const & t, expr const & v, expr const & b) { expr new_t = t ? apply(t) : expr(); return std::make_tuple(new_t, apply(v), apply(b)); }); cache(r); return r; } case expr_kind::MetaVar: { expr r = update_metavar(a, [=](meta_entry const & e) -> meta_entry { if (e.is_inst()) return mk_inst(e.s(), apply(e.v())); else return e; }); cache(r); return r; }} lean_unreachable(); }
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_computeparticles_ComputeParticles_step (JNIEnv *env, jclass jcls) { double curr_tick = get_elapsed_time(); double dt = curr_tick - last_tick; last_tick = curr_tick; update_app(dt); render_app(dt); GLenum error = glGetError(); bool were_errors = false; while (error != GL_NO_ERROR) { LOGD("An OPENGL error occured %s", get_gl_error_msg(error)); were_errors = true; error = glGetError(); } if (were_errors) exit(1); }
expr apply(expr const & e, unsigned offset) { bool shared = false; if (m_use_cache && is_shared(e)) { if (auto r = m_cache->find(e, offset)) return *r; shared = true; } check_interrupted(); check_memory("replace"); if (optional<expr> r = m_f(e, offset)) { return save_result(e, offset, *r, shared); } else { switch (e.kind()) { case expr_kind::Constant: case expr_kind::Sort: case expr_kind::Var: return save_result(e, offset, e, shared); case expr_kind::Meta: case expr_kind::Local: { expr new_t = apply(mlocal_type(e), offset); return save_result(e, offset, update_mlocal(e, new_t), shared); } case expr_kind::App: { expr new_f = apply(app_fn(e), offset); expr new_a = apply(app_arg(e), offset); return save_result(e, offset, update_app(e, new_f, new_a), shared); } case expr_kind::Pi: case expr_kind::Lambda: { expr new_d = apply(binding_domain(e), offset); expr new_b = apply(binding_body(e), offset+1); return save_result(e, offset, update_binding(e, new_d, new_b), shared); } case expr_kind::Macro: { buffer<expr> new_args; unsigned nargs = macro_num_args(e); for (unsigned i = 0; i < nargs; i++) new_args.push_back(apply(macro_arg(e, i), offset)); return save_result(e, offset, update_macro(e, new_args.size(), new_args.data()), shared); }} lean_unreachable(); } }
expr visit_app(expr const & e) { expr new_f = visit(app_fn(e)); expr new_v = visit(app_arg(e)); return update_app(e, new_f, new_v); }
expr replace_visitor::visit_app(expr const & e) { lean_assert(is_app(e)); return update_app(e, visit(app_fn(e)), visit(app_arg(e))); }
/** * update & send messages to Serial */ static void OtaUpdate() { //update_app(Serial); update_app(); }