text:
//---------------------------------------------------------------------------//
// Copyright (c) 2015 Jakub Szuppe <j.szuppe@gmail.com>
//
// Distributed under the Boost Software License, Version 1.0
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//
// See http://boostorg.github.com/compute for more information.
//---------------------------------------------------------------------------//

#ifndef BOOST_COMPUTE_ALGORITHM_DETAIL_FIND_EXTREMA_REDUCE_HPP
#define BOOST_COMPUTE_ALGORITHM_DETAIL_FIND_EXTREMA_REDUCE_HPP

#include <algorithm>
#include <vector>

#include <boost/compute/types.hpp>
#include <boost/compute/command_queue.hpp>
#include <boost/compute/algorithm/copy.hpp>
#include <boost/compute/container/vector.hpp>
#include <boost/compute/detail/meta_kernel.hpp>
#include <boost/compute/detail/iterator_range_size.hpp>
#include <boost/compute/detail/parameter_cache.hpp>
#include <boost/compute/memory/local_buffer.hpp>
#include <boost/compute/type_traits/type_name.hpp>
#include <boost/compute/utility/program_cache.hpp>

namespace boost {
namespace compute {
namespace detail {

template<class InputIterator>
bool find_extrema_reduce_requirements_met(InputIterator first,
                                          InputIterator last,
                                          command_queue &queue)
{
    typedef typename std::iterator_traits<InputIterator>::value_type input_type;

    const device &device = queue.get_device();

    // device must have dedicated local memory storage
    // otherwise reduction would be highly inefficient
    if(device.get_info<CL_DEVICE_LOCAL_MEM_TYPE>() != CL_LOCAL)
    {
        return false;
    }

    const size_t max_work_group_size = device.get_info<CL_DEVICE_MAX_WORK_GROUP_SIZE>();
    // local memory size in bytes (per compute unit)
    const size_t local_mem_size = device.get_info<CL_DEVICE_LOCAL_MEM_SIZE>();

    std::string cache_key = std::string("__boost_find_extrema_reduce_")
        + type_name<input_type>();
    // load parameters
    boost::shared_ptr<parameter_cache> parameters =
        detail::parameter_cache::get_global_cache(device);

    // Get preferred work group size
    size_t work_group_size = parameters->get(cache_key, "wgsize", 256);

    work_group_size = (std::min)(max_work_group_size, work_group_size);

    // local memory size needed to perform parallel reduction
    size_t required_local_mem_size = 0;
    // indices size
    required_local_mem_size += sizeof(uint_) * work_group_size;
    // values size
    required_local_mem_size += sizeof(input_type) * work_group_size;

    // at least 4 work groups per compute unit otherwise reduction
    // would be highly inefficient
    return ((required_local_mem_size * 4) <= local_mem_size);
}

template<class InputIterator, class ResultIterator>
inline size_t find_extrema_reduce(InputIterator first,
                                  size_t count,
                                  ResultIterator result,
                                  vector<uint_>::iterator result_idx,
                                  size_t work_groups_no,
                                  size_t work_group_size,
                                  char sign,
                                  command_queue &queue)
{
    typedef typename std::iterator_traits<InputIterator>::value_type input_type;

    const context &context = queue.get_context();

    meta_kernel k("find_extrema_reduce");
    size_t count_arg = k.add_arg<uint_>("count");
    size_t output_arg = k.add_arg<input_type *>(memory_object::global_memory, "output");
    size_t output_idx_arg = k.add_arg<uint_ *>(memory_object::global_memory, "output_idx");
    size_t block_arg = k.add_arg<input_type *>(memory_object::local_memory, "block");
    size_t block_idx_arg = k.add_arg<uint_ *>(memory_object::local_memory, "block_idx");

    k <<
        // Work item global id
        k.decl<const uint_>("gid") << " = get_global_id(0);\n" <<
        //
        "if(gid >= count) {\n return;\n }\n" <<

        // Index of element that will be read from input buffer
        k.decl<uint_>("idx") << " = gid;\n" <<

        k.decl<input_type>("acc") << ";\n" <<
        // Index of currently best element
        k.decl<uint_>("acc_idx") << " = idx;\n" <<

        // Init accumulator with first[get_global_id(0)]
        "acc = " << first[k.var<uint_>("idx")] << ";\n" <<
        "idx += get_global_size(0);\n" <<

        k.decl<bool>("compare_result") << ";\n" <<
        "while( idx < count ){\n" <<
            // Next element
            k.decl<input_type>("next") << " = " << first[k.var<uint_>("idx")] << ";\n" <<
            // Comparison between currently best element (acc) and next element
            "compare_result = acc " << sign << " next;\n" <<
            "acc = compare_result ? acc : next;\n" <<
            "acc_idx = compare_result ? acc_idx : idx;\n" <<
            "idx += get_global_size(0);\n" <<
        "}\n" <<

        // Work item local id
        k.decl<const uint_>("lid") << " = get_local_id(0);\n" <<
        "block[lid] = acc;\n" <<
        "block_idx[lid] = acc_idx;\n" <<
        "barrier(CLK_LOCAL_MEM_FENCE);\n" <<

        k.decl<uint_>("group_offset") << " = count - (get_local_size(0) * get_group_id(0));\n";

    k <<
        "#pragma unroll\n"
        "for(" << k.decl<uint_>("offset") << " = " << uint_(work_group_size) << " / 2; offset > 0; " <<
             "offset = offset / 2) {\n" <<
             "if((lid < offset) && ((lid + offset) < group_offset)) { \n" <<
                 k.decl<input_type>("mine") << " = block[lid];\n" <<
                 k.decl<input_type>("other") << " = block[lid+offset];\n" <<
                 "compare_result = mine " << sign << " other;\n" <<
                 "block[lid] = compare_result ? mine : other;\n" <<
                 "block_idx[lid] = compare_result ? " <<
                     "block_idx[lid] : block_idx[lid+offset];\n" <<
             "}\n"
             "barrier(CLK_LOCAL_MEM_FENCE);\n" <<
        "}\n" <<

         // write block result to global output
        "if(lid == 0){\n" <<
        "    output[get_group_id(0)] = block[0];\n" <<
        "    output_idx[get_group_id(0)] = block_idx[0];\n" <<
        "}";

    kernel kernel = k.compile(context);
    kernel.set_arg(count_arg, static_cast<uint_>(count));
    kernel.set_arg(output_arg, result.get_buffer());
    kernel.set_arg(output_idx_arg, result_idx.get_buffer());
    kernel.set_arg(block_arg, local_buffer<input_type>(work_group_size));
    kernel.set_arg(block_idx_arg, local_buffer<uint_>(work_group_size));

    queue.enqueue_1d_range_kernel(kernel,
                                  0,
                                  work_groups_no * work_group_size,
                                  work_group_size);

    return 0;
}

template<class InputIterator>
InputIterator find_extrema_reduce(InputIterator first,
                                  InputIterator last,
                                  char sign,
                                  command_queue &queue)
{
    typedef typename std::iterator_traits<InputIterator>::difference_type difference_type;
    typedef typename std::iterator_traits<InputIterator>::value_type input_type;

    const context &context = queue.get_context();
    const device &device = queue.get_device();

    // Getting information about used queue and device
    const size_t compute_units_no = device.get_info<CL_DEVICE_MAX_COMPUTE_UNITS>();
    const size_t max_work_group_size = device.get_info<CL_DEVICE_MAX_WORK_GROUP_SIZE>();

    const size_t count = detail::iterator_range_size(first, last);

    std::string cache_key = std::string("__boost_find_extrema_reduce_")
        + type_name<input_type>();

    // load parameters
    boost::shared_ptr<parameter_cache> parameters =
        detail::parameter_cache::get_global_cache(device);

    // get preferred work group size and preferred number
    // of work groups per compute unit
    size_t work_group_size = parameters->get(cache_key, "wgsize", 256);
    size_t work_groups_per_cu = parameters->get(cache_key, "wgpcu", 64);

    // calculate work group size and number of work groups
    work_group_size = (std::min)(max_work_group_size, work_group_size);
    size_t work_groups_no = compute_units_no * work_groups_per_cu;
    work_groups_no = (std::min)(
            work_groups_no,
            static_cast<size_t>(std::ceil(float(count) / work_group_size)));

    // device vectors for extremum candidates and their indices
    vector<input_type> results(work_groups_no, context);
    vector<uint_> results_idx(work_groups_no, context);

    // find extremum candidates and their indices
    find_extrema_reduce(first, count,
                        results.begin(), results_idx.begin(),
                        work_groups_no, work_group_size,
                        sign,
                        queue);

    // host vectors
    std::vector<input_type> host_results(work_groups_no);
    std::vector<uint_> host_results_idx(work_groups_no);

    // copying extremum candidates found by
    // find_extrema_reduce(...) to host
    copy(results_idx.begin(),
         results_idx.end(),
         host_results_idx.begin(), queue);
    copy(results.begin(),
         results.end(),
         host_results.begin(), queue);

    typename std::vector<input_type>::iterator i = host_results.begin();
    std::vector<uint_>::iterator idx = host_results_idx.begin();
    std::vector<uint_>::iterator extreme_idx = idx;
    input_type extreme = *i;

    // find extremum from candidates found by find_extrema_reduce(...)
    if(sign == '>') {
        while(idx != host_results_idx.end()) {
            bool compare_result =  *i > extreme;
            extreme = compare_result ? *i : extreme;
            extreme_idx = compare_result ? idx : extreme_idx;
            idx++, i++;
        }
    }
    else {
        while(idx != host_results_idx.end()) {
            bool compare_result =  *i < extreme;
            extreme = compare_result ? *i : extreme;
            extreme_idx = compare_result ? idx : extreme_idx;
            idx++, i++;
        }
    }

    // return iterator to extremum
    return first + static_cast<difference_type>(*extreme_idx);
}

} // end detail namespace
} // end compute namespace
} // end boost namespace

#endif // BOOST_COMPUTE_ALGORITHM_DETAIL_FIND_EXTREMA_REDUCE_HPP


text:
// Copyright (c) 2006, 2007 Julio M. Merino Vidal
// Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
// Copyright (c) 2009 Boris Schaeling
// Copyright (c) 2010 Felipe Tanus, Boris Schaeling
// Copyright (c) 2011, 2012 Jeff Flinn, Boris Schaeling
// Copyright (c) 2016 Klemens D. Morgenstern
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

/**
 * \file boost/process/spawn.hpp
 *
 * Defines the spawn function.
 */

#ifndef BOOST_PROCESS_SPAWN_HPP
#define BOOST_PROCESS_SPAWN_HPP

#include <boost/process/detail/config.hpp>
#include <boost/process/detail/child_decl.hpp>
#include <boost/process/detail/execute_impl.hpp>
#include <boost/process/detail/async_handler.hpp>

#if defined(BOOST_POSIX_API)
#include <boost/process/posix.hpp>
#endif

namespace boost {

namespace process {

namespace detail {

}

/** Launch a process and detach it. Returns no handle.

This function starts a process and immediately detaches it. It thereby prevents the system from creating a zombie process,
but will also cause the system to be unable to wait for the child to exit.

\note This will set `SIGCHLD` to `SIGIGN` on posix.

\warning This function does not allow asynchronous operations, since it cannot wait for the end of the process.
It will fail to compile if a reference to `boost::asio::io_context` is passed.

 */
template<typename ...Args>
inline void spawn(Args && ...args)
{
    typedef typename ::boost::process::detail::has_async_handler<Args...>::type
            has_async;

    static_assert(
            !has_async::value,
            "Spawn cannot wait for exit, so async properties cannot be used");

    auto c = ::boost::process::detail::execute_impl(
#if defined(BOOST_POSIX_API)
            ::boost::process::posix::sig.ign(),
#endif
             std::forward<Args>(args)...);
    c.detach();
}

}}
#endif

ext: hpp


text:
#pragma once
#include <graphene/chain/protocol/asset.hpp>
#include <graphene/db/object.hpp>
#include <graphene/db/generic_index.hpp>
#include <boost/multi_index/composite_key.hpp>
#include <graphene/crosschain/crosschain.hpp>
#include <map>

namespace graphene {
	namespace chain {
		enum coldhot_trx_state {
			coldhot_without_sign_trx_uncreate = 0,
			coldhot_without_sign_trx_create = 1,
			coldhot_sign_trx = 2,
			coldhot_combine_trx_create = 3,
			coldhot_transaction_confirm = 4,
			coldhot_transaction_fail = 5,
			coldhot_eth_guard_need_sign = 6,
			coldhot_eth_guard_sign =7
		};
		class coldhot_transfer_object;
		class coldhot_transfer_object :public graphene::db::abstract_object<coldhot_transfer_object> {
		public:
			static const uint8_t space_id = protocol_ids;
			static const uint8_t type_id = coldhot_transfer_object_type;
			//Relate transaction witch the current trx is based
			transaction_id_type relate_trx_id;
			transaction_id_type current_id;
			signed_transaction  current_trx;
			string				original_trx_id;
			uint64_t			op_type;
			coldhot_trx_state	curret_trx_state;
			uint32_t block_num;
			string symbol;
			coldhot_transfer_object() {}
		};
		struct by_optype;
		struct by_current_trx_state;
		struct by_relate_trx_id;
		struct by_current_trx_id;
		struct by_relate_trxidstate;
		struct by_current_trxidstate;
		struct by_original_trxid_optype;
		struct by_symbol_block_num_state;
		struct by_block_num_state;
		using coldhot_transfer_multi_index_type = multi_index_container <
			coldhot_transfer_object,
			indexed_by <
			ordered_unique< tag<by_id>,
			member<object, object_id_type, &object::id>
			>,
			ordered_non_unique< tag<by_optype>,
			member<coldhot_transfer_object, uint64_t, &coldhot_transfer_object::op_type>
			>,
			ordered_non_unique< tag<by_current_trx_state>,
			member<coldhot_transfer_object, coldhot_trx_state, &coldhot_transfer_object::curret_trx_state>
			>,
			ordered_non_unique<	tag<by_relate_trx_id>,
			member<coldhot_transfer_object, transaction_id_type, &coldhot_transfer_object::relate_trx_id>
			>,
			ordered_unique< tag<by_current_trx_id>,
			member<coldhot_transfer_object, transaction_id_type, &coldhot_transfer_object::current_id>
			>,
			ordered_unique<	tag<by_block_num_state>,
			composite_key<
			coldhot_transfer_object,
			member<coldhot_transfer_object, coldhot_trx_state, &coldhot_transfer_object::curret_trx_state>,
			member<coldhot_transfer_object, uint32_t, &coldhot_transfer_object::block_num>,
			member<coldhot_transfer_object, transaction_id_type, &coldhot_transfer_object::current_id>
			>
			>,
			ordered_unique<	tag<by_symbol_block_num_state>,
			composite_key<
			coldhot_transfer_object,
			member<coldhot_transfer_object, std::string, &coldhot_transfer_object::symbol>,
			member<coldhot_transfer_object, coldhot_trx_state, &coldhot_transfer_object::curret_trx_state>,
			member<coldhot_transfer_object, uint32_t, &coldhot_transfer_object::block_num>,
			member<coldhot_transfer_object, transaction_id_type, &coldhot_transfer_object::current_id>
			>
			>,
			ordered_non_unique<	tag<by_original_trxid_optype>,
			composite_key<
			coldhot_transfer_object,
			member<coldhot_transfer_object, std::string, &coldhot_transfer_object::original_trx_id>,
			member<coldhot_transfer_object, uint64_t, &coldhot_transfer_object::op_type>
			>
			>,
			ordered_non_unique<
			tag<by_relate_trxidstate>,
			composite_key<
			coldhot_transfer_object,
			member<coldhot_transfer_object, transaction_id_type, &coldhot_transfer_object::relate_trx_id>,
			member<coldhot_transfer_object, coldhot_trx_state, &coldhot_transfer_object::curret_trx_state>
			>,
			composite_key_compare<
			std::less< transaction_id_type >,
			std::less<coldhot_trx_state>
			>
			>,
			ordered_non_unique<
			tag<by_current_trxidstate>,
			composite_key<
			coldhot_transfer_object,
			member<coldhot_transfer_object, transaction_id_type, &coldhot_transfer_object::current_id>,
			member<coldhot_transfer_object, coldhot_trx_state, &coldhot_transfer_object::curret_trx_state>
			>,
			composite_key_compare<
			std::less< transaction_id_type >,
			std::less<coldhot_trx_state>
			>
			>
			>
		> ;
		using coldhot_transfer_index = generic_index<coldhot_transfer_object, coldhot_transfer_multi_index_type>;
	}
}
FC_REFLECT_ENUM(graphene::chain::coldhot_trx_state,
	(coldhot_without_sign_trx_uncreate)
	(coldhot_without_sign_trx_create)
	(coldhot_sign_trx)
	(coldhot_combine_trx_create)
	(coldhot_transaction_confirm)
	(coldhot_transaction_fail)
	(coldhot_eth_guard_need_sign)
	(coldhot_eth_guard_sign)
)
FC_REFLECT_DERIVED(graphene::chain::coldhot_transfer_object, (graphene::db::object),
	(relate_trx_id)
	(current_id)
	(original_trx_id)
	(current_trx)
	(op_type)
	(curret_trx_state)
	(symbol)
	(block_num)

)

max_stars_repo_name: hbchain/hbcore

max_issues_repo_name: hbchain/hbcore

max_forks_repo_name: hbchain/hbcore


text:
//---------------------------------------------------------------------------//
// Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
//
// Distributed under the Boost Software License, Version 1.0
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//
// See http://boostorg.github.com/compute for more information.
//---------------------------------------------------------------------------//

#define BOOST_TEST_MODULE TestArray
#include <boost/test/unit_test.hpp>

#include <boost/compute/system.hpp>
#include <boost/compute/algorithm/copy.hpp>
#include <boost/compute/container/array.hpp>
#include <boost/compute/container/vector.hpp>

#include "check_macros.hpp"
#include "context_setup.hpp"

BOOST_AUTO_TEST_CASE(concept_check)
{
    BOOST_CONCEPT_ASSERT((boost::Container<boost::compute::array<int, 3> >));
//    BOOST_CONCEPT_ASSERT((boost::SequenceConcept<boost::compute::array<int, 3> >));
    BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<boost::compute::array<int, 3>::iterator>));
    BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<boost::compute::array<int, 3>::const_iterator>));
}

BOOST_AUTO_TEST_CASE(size)
{
    boost::compute::array<int, 0> empty_array(context);
    BOOST_CHECK_EQUAL(empty_array.size(), size_t(0));

    boost::compute::array<int, 10> array10(context);
    BOOST_CHECK_EQUAL(array10.size(), size_t(10));
}

BOOST_AUTO_TEST_CASE(at)
{
    boost::compute::array<int, 3> array;
    array[0] = 3;
    array[1] = -2;
    array[2] = 5;
    BOOST_CHECK_EQUAL(array.at(0), 3);
    BOOST_CHECK_EQUAL(array.at(1), -2);
    BOOST_CHECK_EQUAL(array.at(2), 5);
    BOOST_CHECK_THROW(array.at(3), std::out_of_range);
}

BOOST_AUTO_TEST_CASE(copy_from_vector)
{
    int data[] = { 3, 6, 9, 12 };
    boost::compute::vector<int> vector(data, data + 4, queue);

    boost::compute::array<int, 4> array(context);
    boost::compute::copy(vector.begin(), vector.end(), array.begin(), queue);
    CHECK_RANGE_EQUAL(int, 4, array, (3, 6, 9, 12));
}

BOOST_AUTO_TEST_CASE(fill)
{
    boost::compute::array<int, 4> array(context);
    array.fill(0);
    CHECK_RANGE_EQUAL(int, 4, array, (0, 0, 0, 0));

    array.fill(17);
    CHECK_RANGE_EQUAL(int, 4, array, (17, 17, 17, 17));
}

BOOST_AUTO_TEST_CASE(swap)
{
    int data[] = { 1, 2, 6, 9 };
    boost::compute::array<int, 4> a(context);
    boost::compute::copy(data, data + 4, a.begin(), queue);
    CHECK_RANGE_EQUAL(int, 4, a, (1, 2, 6, 9));

    boost::compute::array<int, 4> b(context);
    b.fill(3);
    CHECK_RANGE_EQUAL(int, 4, b, (3, 3, 3, 3));

    a.swap(b);
    CHECK_RANGE_EQUAL(int, 4, a, (3, 3, 3, 3));
    CHECK_RANGE_EQUAL(int, 4, b, (1, 2, 6, 9));
}

BOOST_AUTO_TEST_SUITE_END()

ext: cpp


text:
#include <boost/format.hpp>

#include "word.h"
#include "typedValue.h"
#include "stack.h"
#include "context.h"

const BigInt gBI_DBL_MAX(DBL_MAX);
const BigInt gBI_FLT_MAX(FLT_MAX);

const BigFloat gBF_DBL_MAX(DBL_MAX);
const BigFloat gBF_FLT_MAX(FLT_MAX);

PP_API double TypedValue::ToDouble(Context& inContext) {
	switch(dataType) {
		case kTypeInt:		return (double)intValue;
		case kTypeLong:		return (double)longValue;
		case kTypeFloat:	return (double)floatValue;
		case kTypeDouble:	return doubleValue;
		case kTypeBigInt: {
			const BigInt& bigInt=*bigIntPtr;
			if(abs(bigInt)<=gBI_DBL_MAX) {
				return static_cast<double>(bigInt);
			} else {
				inContext.Error(E_CAN_NOT_CONVERT_TO_DOUBLE_DUE_TO_OVERFLOW);
			}
		}
		case kTypeBigFloat: {
			const BigFloat& bigFloat=*bigFloatPtr;
			if(abs(bigFloat)<gBF_DBL_MAX) {
				return static_cast<double>(bigFloat);
			} else {
				inContext.Error(E_CAN_NOT_CONVERT_TO_DOUBLE_DUE_TO_OVERFLOW);
			}
		}
		default:
			inContext.Error_InvalidType(E_TOS_CAN_NOT_CONVERT_TO_DOUBLE,*this);
	}
	return std::numeric_limits<double>::quiet_NaN();
}

PP_API float TypedValue::ToFloat(Context& inContext) {
	switch(dataType) {
		case kTypeInt:		return (float)intValue;
		case kTypeLong:		return (float)longValue;
		case kTypeFloat:	return floatValue;
		case kTypeDouble:	return (float)doubleValue;
		case kTypeBigInt: {
			const BigInt& bigInt=*bigIntPtr;
			if(abs(bigInt)<=gBI_FLT_MAX) {
				return static_cast<float>(*bigIntPtr);
			} else {
				inContext.Error(E_CAN_NOT_CONVERT_TO_FLOAT_DUE_TO_OVERFLOW);
			}
		}
		case kTypeBigFloat: {
			const BigFloat& bigFloat=*bigFloatPtr;
			if(abs(bigFloat)<=gBF_FLT_MAX) {
				return static_cast<float>(*bigFloatPtr);
			} else {
				inContext.Error(E_CAN_NOT_CONVERT_TO_FLOAT_DUE_TO_OVERFLOW);
			}
		}
		default:
			inContext.Error_InvalidType(E_TOS_CAN_NOT_CONVERT_TO_FLOAT,*this);
	}
	return std::numeric_limits<float>::quiet_NaN();
}

PP_API std::string TypedValue::GetTypeStr() const {
	switch(dataType) {
		case kTypeInvalid:		return std::string("(INVALID)");
		case kTypeEOC:			return std::string("EOC");
		case kTypeEmptySlot:	return std::string("(EMPRY-SLOT)");
		case kTypeDirectWord:	return std::string("(WORD-PTR)");
		case kTypeIP:			return std::string("(IPDATA)");
		case kTypeParamDest:	return std::string("PARAM-DEST");
		case kTypeNewWord:		return std::string("(NEW-WORD-PTR)");
		case kTypeAddress:		return std::string("(ADDRESS)");
		case kTypeThreshold:	return std::string("(Threshold)");

		case kTypeBool:		 	return std::string("bool");
		case kTypeInt:			return std::string("int");
		case kTypeLong:			return std::string("long");
		case kTypeBigInt:		return std::string("bigInt");
		case kTypeFloat:		return std::string("float");
		case kTypeDouble:		return std::string("double");
		case kTypeBigFloat:		return std::string("bigFloat");
		case kTypeString:		return std::string("string");
		case kTypeWord:			return std::string("word");
		case kTypeArray:		return std::string("array");
		case kTypeList:			return std::string("list");
		case kTypeSymbol:		return std::string("symbol");
		case kTypeFile:			return std::string("file");
		case kTypeEOF:			return std::string("eof");

		case kTypeMiscInt:		return std::string("(MISC-INT)");
	}
	fprintf(stderr,"UNKNOWN dataType=%d\n",dataType);
	return std::string("### SYSTEM_ERROR ###");
}

static void printIndent(int inIndent);
static std::string indentStr(int inIndent);

int TypedValue::GetLevel() const {
	return dataType==kTypeDirectWord ? (int)wordPtr->level : 0;
}

PP_API void TypedValue::PrintValue(int inIndent) const {
	printIndent(inIndent);
	std::string valueStr=GetValueString(inIndent);
	printf("%s",valueStr.c_str());
}

PP_API std::string TypedValue::GetValueString(int inIndent) const {
	std::string ret;
	switch(dataType) {
		case kTypeInvalid:	ret="(invalid-value)";	break;
		case kTypeEOC:		ret="(EOC)";			break;

		case kTypeIP:
			ret=(boost::format("(internal-data:IP %p)")%ipValue).str();
			break;
		case kTypeParamDest:
			ret=(boost::format("(PARAM-DEST %p)")%ipValue).str();
			break;

		case kTypeDirectWord:
		case kTypeNewWord:
		case kTypeWord:
			ret=(boost::format("%p[%s]")%wordPtr%wordPtr->longName).str();
			break;

		case kTypeBool:
		case kTypeEmptySlot:
			ret = boolValue ? "true" : "false";
			break;

		case kTypeAddress:
		case kTypeThreshold:
		case kTypeInt:
			ret=std::to_string(intValue);
			break;

		case kTypeLong:		ret=std::to_string(longValue);		break;
		case kTypeFloat:	ret=std::to_string(floatValue); 	break;
		case kTypeDouble:	ret=std::to_string(doubleValue);	break;

		case kTypeBigInt:	ret=bigIntPtr->str();	break;
		case kTypeBigFloat:	ret=bigFloatPtr->str();	break;

		case kTypeSymbol:
		case kTypeString:
			ret=std::string(*stringPtr);
			break;

		case kTypeArray:
			ret=(boost::format("array (size=%d data=%p)")
				 %arrayPtr->length%arrayPtr->data).str();
			if(inIndent>=0) {
				for(int i=0; i<arrayPtr->length; i++) {
					ret+=indentStr(inIndent);
					ret+=(boost::format("\t[%d]=")%i).str();
					ret+=arrayPtr->data[i].GetValueString(inIndent+1);
				}
			} else {
				ret+="...";
			}
			break;

		case kTypeList: {
				ret="( ";
				const size_t n=listPtr->size();
				for(size_t i=0; i<n; i++) {
					ret+=listPtr->at(i).GetValueString(inIndent);
					ret+=" ";
				}
				ret+=")";
			}
			break;

		case kTypeFile:
			ret=(boost::format("(file-pointer: %p)")%filePtr.get()).str();
			break;

		case kTypeEOF:		ret="(EOC)";			break;

		default:
			fprintf(stderr,"SYSTEM ERROR at TypedValue::GetValueString().\n");
			exit(-1);
	}
	return ret;
}
static void printIndent(int inIndent) {
	for(int i=0; i<inIndent; i++) {
		putchar('\t');
	}
}
static std::string indentStr(int inIndent) {
	std::string ret;
	for(int i=0; i<inIndent; i++) {
		ret+="\t";
	}
	return ret;
}

PP_API void TypedValue::Dump() const {
	printf("dataType:%s ",GetTypeStr().c_str());
	printf("value:"); PrintValue(); printf("\n");
}

max_stars_repo_name: objectx/Paraphrase

max_issues_repo_name: objectx/Paraphrase

max_forks_repo_name: objectx/Paraphrase