int main(){ char prefixBuffer[STR_SIZE*2]; int prefixIndex = 0; double result = 0.0; STACK charStack; STACK intStack; initStack(&charStack, "char"); initStack(&intStack, "double"); makePrefix(prefixBuffer, &charStack, &prefixIndex); result = calcPrefix(prefixBuffer, &intStack, &prefixIndex); printf(" %.2lf \n", result); return 0; }
Handoff OverlayImpl::onHandoff (std::unique_ptr <beast::asio::ssl_bundle>&& ssl_bundle, beast::http::message&& request, endpoint_type remote_endpoint) { auto const id = next_id_++; beast::WrappedSink sink (deprecatedLogs()["Peer"], makePrefix(id)); beast::Journal journal (sink); Handoff handoff; if (processRequest(request, handoff)) return handoff; if (! isPeerUpgrade(request)) return handoff; handoff.moved = true; if (journal.trace) journal.trace << "Peer connection upgrade from " << remote_endpoint; error_code ec; auto const local_endpoint (ssl_bundle->socket.local_endpoint(ec)); if (ec) { if (journal.trace) journal.trace << remote_endpoint << " failed: " << ec.message(); return handoff; } auto consumer = m_resourceManager.newInboundEndpoint( beast::IPAddressConversion::from_asio(remote_endpoint)); if (consumer.disconnect()) return handoff; auto const slot = m_peerFinder->new_inbound_slot ( beast::IPAddressConversion::from_asio(local_endpoint), beast::IPAddressConversion::from_asio(remote_endpoint)); if (slot == nullptr) { // self-connect, close handoff.moved = false; return handoff; } // TODO Validate HTTP request { auto const types = beast::rfc2616::split_commas( request.headers["Connect-As"]); if (std::find_if(types.begin(), types.end(), [](std::string const& s) { return beast::ci_equal(s, "peer"); }) == types.end()) { handoff.moved = false; handoff.response = makeRedirectResponse(slot, request, remote_endpoint.address()); handoff.keep_alive = request.keep_alive(); return handoff; } } handoff.moved = true; bool success = true; protocol::TMHello hello; std::tie(hello, success) = parseHello (request, journal); if(! success) return handoff; uint256 sharedValue; std::tie(sharedValue, success) = makeSharedValue( ssl_bundle->stream.native_handle(), journal); if(! success) return handoff; RippleAddress publicKey; std::tie(publicKey, success) = verifyHello (hello, sharedValue, journal, getApp()); if(! success) return handoff; std::string name; bool const cluster = getApp().getUNL().nodeInCluster( publicKey, name); auto const result = m_peerFinder->activate (slot, publicKey.toPublicKey(), cluster); if (result != PeerFinder::Result::success) { if (journal.trace) journal.trace << "Peer " << remote_endpoint << " redirected, slots full"; handoff.moved = false; handoff.response = makeRedirectResponse(slot, request, remote_endpoint.address()); handoff.keep_alive = request.keep_alive(); return handoff; } auto const peer = std::make_shared<PeerImp>(id, remote_endpoint, slot, std::move(request), hello, publicKey, consumer, std::move(ssl_bundle), *this); { // As we are not on the strand, run() must be called // while holding the lock, otherwise new I/O can be // queued after a call to stop(). std::lock_guard <decltype(mutex_)> lock (mutex_); add(peer); peer->run(); } handoff.moved = true; return handoff; }
refObject skolemize(refObject layer, refObject type) { struct { refFrame link; int count; refObject first; refObject labeler; refObject last; refObject layer; refObject next; refObject type; } f0; // IS SKOLEMIZABLE. Test if TYPE, which is ground in LAYER, can be the base of // a Skolem type. It can be, if it has a subtype that's different from itself. // For example, OBJ has an infinite number of such subtypes but INT0 has none. // The WHILE loop helps simulate tail recursions. bool isSkolemizable(refObject layer, refObject type) { while (true) { if (isName(type)) { getKey(r(layer), r(type), layer, type); } else // Visit a type. If LABELER says we've been here before, then return false. If // we haven't, then record TYPE in LABELER so we won't come here again. if (isPair(type)) { if (gotKey(toss, toss, f0.labeler, type)) { return false; } else { refObject pars; setKey(f0.labeler, type, nil, nil); switch (toHook(car(type))) // Visit a trivially Skolemizable type. An ALTS, FORM, or GEN type can have an // ALTS type as a subtype. A REF or ROW type can have NULL as a subtype. { case altsHook: case arraysHook: case formHook: case genHook: case jokerHook: case referHook: case rowHook: case skoHook: case tuplesHook: { return true; } // Visit a type that is trivially not Skolemizable. case cellHook: case char0Hook: case char1Hook: case int0Hook: case int1Hook: case int2Hook: case listHook: case nullHook: case real0Hook: case real1Hook: case strTypeHook: case symHook: case voidHook: { return false; } // Visit an ARRAY type. It's Skolemizable if its base type is. case arrayHook: { type = caddr(type); break; } // Visit a PROC type. It's Skolemizable if (1) it has a Skolemizable parameter // type, (2) it has the missing name NO NAME as a parameter name, (3) it has a // Skolemizable yield type. case procHook: { type = cdr(type); pars = car(type); while (pars != nil) { pars = cdr(pars); if (car(pars) == noName) { return true; } else { pars = cdr(pars); }} pars = car(type); while (pars != nil) { if (isSkolemizable(layer, car(pars))) { return true; } else { pars = cddr(pars); }} type = cadr(type); break; } // Visit a TUPLE type. It's Skolemizable if it has a Skolemizable slot type or // if it has the missing name NO NAME as a slot name. case tupleHook: { pars = cdr(type); while (pars != nil) { pars = cdr(pars); if (car(pars) == noName) { return true; } else { pars = cdr(pars); }} pars = cdr(type); while (pars != nil) { if (isSkolemizable(layer, car(pars))) { return true; } else { pars = cddr(pars); }} return false; } // Visit a prefix type. It's Skolemizable if its base type is. case typeHook: case varHook: { type = cadr(type); break; } // Visit an illegal type. We should never get here. default: { fail("Got ?%s(...) in isSkolemizable!", hookTo(car(type))); }}}} // Visit an illegal object. We should never get here either. else { fail("Got bad type in isSkolemizable!"); }}} // Lost? This is SKOLEMIZE's body. These identities show what's going on. // // S(type T B) => T S(B) // S(U) => ?sko(U) // S(V) => V // // Here S(X) is the Skolem type for type X. T is a series of zero or more TYPE // prefixes. B is a type, U is a type with at least one subtype different from // itself, and V is a type with no subtypes different from itself. push(f0, 6); f0.labeler = pushLayer(nil, plainInfo); f0.layer = layer; f0.type = type; while (isName(f0.type)) { getKey(r(f0.layer), r(f0.type), f0.layer, f0.type); } if (isCar(f0.type, typeHook)) { f0.type = cadr(f0.type); if (isSkolemizable(f0.layer, f0.type)) { if (isCar(f0.type, typeHook)) { f0.first = f0.last = makePair(hooks[typeHook], nil); f0.type = cadr(f0.type); while (isCar(f0.type, typeHook)) { f0.next = makePair(hooks[typeHook], nil); cdr(f0.last) = makePair(f0.next, nil); f0.last = f0.next; f0.type = cadr(f0.type); } f0.next = makePrefix(skoHook, f0.type); cdr(f0.last) = makePair(f0.next, nil); } else { f0.first = makePrefix(skoHook, f0.type); }} else { f0.first = makePair(car(f0.type), cdr(f0.type)); }} else { fail("Type type expected in skolemize!"); } pop(); destroyLayer(f0.labeler); return f0.first; }
cellSimple = makePair(hooks[cellHook], nil); char0Simple = makePair(hooks[char0Hook], nil); char1Simple = makePair(hooks[char1Hook], nil); int0Simple = makePair(hooks[int0Hook], nil); int1Simple = makePair(hooks[int1Hook], nil); int2Simple = makePair(hooks[int2Hook], nil); listSimple = makePair(hooks[listHook], nil); nullSimple = makePair(hooks[nullHook], nil); real0Simple = makePair(hooks[real0Hook], nil); real1Simple = makePair(hooks[real1Hook], nil); voidSimple = makePair(hooks[voidHook], nil); // Bind names to simple types. bindName("char0", makePrefix(typeHook, char0Simple), char0Simple); bindName("char1", makePrefix(typeHook, char1Simple), char1Simple); bindName("int0", makePrefix(typeHook, int0Simple), int0Simple); bindName("int1", makePrefix(typeHook, int1Simple), int1Simple); bindName("int2", makePrefix(typeHook, int2Simple), int2Simple); bindName("list", makePrefix(typeHook, listSimple), listSimple); bindName("null", makePrefix(typeHook, nullSimple), nullSimple); bindName("real0", makePrefix(typeHook, real0Simple), real0Simple); bindName("real1", makePrefix(typeHook, real1Simple), real1Simple); bindName("void", makePrefix(typeHook, voidSimple), voidSimple); // Bind the name EOS to the integer end-of-stream sentinel. bindName("eos", int2Simple, makeInteger(EOF)); // We use SKIP a lot, so the variable SKIP points to it.