text:
#pragma once

#include <string>
#include <vector>
#include <stack>
#include <map>
#include <list>
#include <set>

#include <boost/regex_fwd.hpp>
#include <boost/unordered_map.hpp>
#include <boost/intrusive_ptr.hpp>

#include <OpenImageIO/ustring.h>
#include <OpenImageIO/thread.h>
#include <OpenImageIO/paramlist.h>
#include <OpenImageIO/refcnt.h>

#include "oslexec.h"
#include "oslclosure.h"
#include "osl_pvt.h"
#include "constantpool.h"

using namespace OSL;
using namespace OSL::pvt;

using OIIO::atomic_int;
using OIIO::atomic_ll;
using OIIO::RefCnt;
using OIIO::ParamValueList;
using OIIO::mutex;
using OIIO::lock_guard;
using OIIO::spin_mutex;
using OIIO::spin_lock;
using OIIO::thread_specific_ptr;
using OIIO::ustringHash;
namespace Strutil = OIIO::Strutil;

OSL_NAMESPACE_ENTER

struct PerThreadInfo
{
    PerThreadInfo ();
    ~PerThreadInfo ();
    ShadingContext *pop_context ();  ///< Get the pool top and then pop

    std::stack<ShadingContext *> context_pool;
};

namespace pvt {

// forward definitions
class ShadingSystemImpl;
class ShaderInstance;
typedef shared_ptr<ShaderInstance> ShaderInstanceRef;
class Dictionary;
class RuntimeOptimizer;
class BackendLLVM;

void print_closure (std::ostream &out, const ClosureColor *closure, ShadingSystemImpl *ss);

/// Signature of the function that LLVM generates to run the shader
/// group.
typedef void (*RunLLVMGroupFunc)(void* /* shader globals */, void*);

/// Signature of a constant-folding method
typedef int (*OpFolder) (RuntimeOptimizer &rop, int opnum);

/// Signature of an LLVM-IR-generating method
typedef bool (*OpLLVMGen) (BackendLLVM &rop, int opnum);

struct OpDescriptor {
    ustring name;           // name of op
    OpLLVMGen llvmgen;      // llvm-generating routine
    OpFolder folder;        // constant-folding routine
    bool simple_assign;     // wholy overwites arg0, no other writes,
                            //     no side effects
    OpDescriptor () { }
    OpDescriptor (const char *n, OpLLVMGen ll, OpFolder f=NULL,
                  bool simple=false)
        : name(n), llvmgen(ll), folder(f), simple_assign(simple)
    {}
};

// Prefix for OSL shade up declarations, so LLVM can find them
#define OSL_SHADEOP extern "C" OSL_LLVM_EXPORT

/// Like an int (of type T), but also internally keeps track of the
/// maximum value is has held, and the total "requested" deltas.
/// You really shouldn't use an unsigned type for T, for two reasons:
/// (1) Our implementation of '-=' will fail; and (2) you actually
/// want to allow the counter to go negative, to detect if you have
/// made a mistake in your bookkeeping by forgetting an allocation.
template<typename T>
class PeakCounter
{
public:
    typedef T value_t;
    PeakCounter () : m_current(0), m_requested(0), m_peak(0) { }
    /// Reset all counts to zero.
    ///
    void clear () {
        m_current = 0;  m_requested = 0;  m_peak = 0;
    }
    /// Return the current value.
    ///
    value_t operator() () const { return m_current; }

    /// Return the current value.
    ///
    value_t current (void) const { return m_current; }
    /// Return the sum of all requests.
    ///
    value_t requested (void) const { return m_requested; }
    /// Return the peak value we saw.
    ///
    value_t peak (void) const { return m_peak; }

    /// Reassign the current value, adjust peak and requested as necessary.
    ///
    const value_t operator= (value_t newval) {
        value_t cur = m_current;
        if (newval > cur)
            m_requested += (cur-newval);
        m_current = newval;
        if (newval > m_peak)
            m_peak = newval;
        return m_current;
    }
    /// Add to current value, adjust peak and requested as necessary.
    ///
    const value_t operator+= (value_t sz) {
        m_current += sz;
        if (sz > 0) {
            m_requested += sz;
            if (m_current > m_peak)
                m_peak = m_current;
        }
        return m_current;
    }
    /// Subtract from current value
    ///
    const value_t operator-= (value_t sz) {
        *this += (-sz);
        return m_current;
    }

    const value_t operator++ ()    { *this += 1;  return m_current; }
    const value_t operator++ (int) { *this += 1;  return m_current-1; }
    const value_t operator-- ()    { *this -= 1;  return m_current; }
    const value_t operator-- (int) { *this -= 1;  return m_current+1; }

    friend std::ostream & operator<< (std::ostream &out, const PeakCounter &p)
    {
        out << p.requested() << " requested, " << p.peak() << " peak, "
            << p.current() << " current";
        return out;
    }

    std::string memstat () const {
        return Strutil::memformat(requested()) + " requested, "
             + Strutil::memformat(peak()) + " peak, "
             + Strutil::memformat(current()) + " current";
    }

private:
    value_t m_current, m_requested, m_peak;
};

/// Template to count a vector's allocated size, in bytes.
///
template<class T>
inline off_t vectorbytes (const std::vector<T> &v)
{
    return v.capacity() * sizeof(T);
}

/// Template to fully deallocate a stl container using the swap trick.
///
template<class T>
inline void stlfree (T &v)
{
    T tmp;
    std::swap (tmp, v);
    // Now v is no allocated space, and tmp has v's old allocated space.
    // When tmp leaves scope as we return, that space will be freed.
}

/// ShaderMaster is the full internal representation of a complete
/// shader that would be a .oso file on disk: symbols, instructions,
/// arguments, you name it.  A master copy is shared by all the
/// individual instances of the shader.
class ShaderMaster : public RefCnt {
public:
    typedef boost::intrusive_ptr<ShaderMaster> ref;
    ShaderMaster (ShadingSystemImpl &shadingsys) : m_shadingsys(shadingsys) { }
    ~ShaderMaster ();

    std::string print ();  // Debugging

    /// Return a pointer to the shading system for this master.
    ///
    ShadingSystemImpl & shadingsys () const { return m_shadingsys; }

    /// Run through the symbols and set up various things we can know
    /// with just the master: the size (including padding), and their
    /// data pointers if they are constants or params (to the defaults).
    /// As a side effect, also set this->m_firstparam/m_lastparam.
    void resolve_syms ();

    /// Find the named symbol, return its index in the symbol array, or
    /// -1 if not found.
    int findsymbol (ustring name) const;

    /// Return a pointer to the symbol (specified by integer index),
    /// or NULL (if index was -1, as returned by 'findsymbol').
    Symbol *symbol (int index) {
        DASSERT (index < (int)m_symbols.size());
        return index >= 0 ? &m_symbols[index] : NULL;
    }
    const Symbol *symbol (int index) const {
        DASSERT (index < (int)m_symbols.size());
        return index >= 0 ? &m_symbols[index] : NULL;
    }

    /// Return the name of the shader.
    ///
    const std::string &shadername () const { return m_shadername; }

    /// Where is the location that holds the parameter's default value?
    void *param_default_storage (int index);
    const void *param_default_storage (int index) const;

private:
    ShadingSystemImpl &m_shadingsys;    ///< Back-ptr to the shading system
    ShaderType m_shadertype;            ///< Type of shader
    std::string m_shadername;           ///< Shader name
    std::string m_osofilename;          ///< Full path of oso file
    OpcodeVec m_ops;                    ///< Actual code instructions
    std::vector<int> m_args;            ///< Arguments for all the ops
    // Need the code offsets for each code block
    SymbolVec m_symbols;                ///< Symbols used by the shader
    std::vector<int> m_idefaults;       ///< int default param values
    std::vector<float> m_fdefaults;     ///< float default param values
    std::vector<ustring> m_sdefaults;   ///< string default param values
    std::vector<int> m_iconsts;         ///< int constant values
    std::vector<float> m_fconsts;       ///< float constant values
    std::vector<ustring> m_sconsts;     ///< string constant values
    int m_firstparam, m_lastparam;      ///< Subset of symbols that are params
    int m_maincodebegin, m_maincodeend; ///< Main shader code range

    friend class OSOReaderToMaster;
    friend class ShaderInstance;
};

/// Describe one end of a parameter connetion: the parameter number, and
/// optinally an array index and/or channel number within that parameter.
struct ConnectedParam {
    int param;            ///< Parameter number (in the symbol table)
    int arrayindex:27;    ///< Array index (-1 for not an index)
    int channel:5;        ///< Channel number (-1 for no channel selection)
    TypeSpec type;        ///< Type of data being connected
    // N.B. Use bitfields to squeeze the structure down by 4 bytes.
    // Consequence is that you can't connect individual elements of
    // arrays with more than 2^26 (32M) elements. Somehow I don't think
    // that's going to be a limitation to worry about.
    ConnectedParam () : param(-1), arrayindex(-1), channel(-1) { }

    bool valid () const { return (param >= 0); }

    bool operator== (const ConnectedParam &p) const {
        return param == p.param && arrayindex == p.arrayindex &&
            channel == p.channel && type == p.type;
    }

    // Is it a complete connection, not partial?
    bool is_complete () const {
        return arrayindex == -1 && channel == -1;
    }
};

/// Describe a parameter connection to an earlier layer.
///
struct Connection {
    int srclayer;          ///< Layer (within our group) of the source
    ConnectedParam src;    ///< Which source parameter (or part thereof)
    ConnectedParam dst;    ///< Which destination parameter (or part thereof)

    Connection (int srclay, const ConnectedParam &srccon,
                const ConnectedParam &dstcon)
        : srclayer (srclay), src (srccon), dst (dstcon)
    { }
    bool operator== (const Connection &c) const {
        return srclayer == c.srclayer && src == c.src && dst == c.dst;
    }
};

typedef std::vector<Connection> ConnectionVec;

/// ShaderInstance is a particular instance of a shader, with its own
/// set of parameter values, coordinate transform, and connections to
/// other instances within the same shader group.
class ShaderInstance {
public:
    typedef ShaderInstanceRef ref;
    ShaderInstance (ShaderMaster::ref master, const char *layername="");
    ~ShaderInstance ();

    /// Return the layer name of this instance
    ///
    ustring layername () const { return m_layername; }

    /// Return the name of the shader used by this instance.
    ///
    const std::string &shadername () const { return m_master->shadername(); }

    /// Return a pointer to the master for this instance.
    ///
    ShaderMaster *master () const { return m_master.get(); }

    /// Return a reference to the shading system for this instance.
    ///
    ShadingSystemImpl & shadingsys () const { return m_master->shadingsys(); }

    /// Apply pending parameters
    ///
    void parameters (const ParamValueList &params);

    /// Find the named symbol, return its index in the symbol array, or
    /// -1 if not found.
    int findsymbol (ustring name) const;

    /// Find the named parameter, return its index in the symbol array, or
    /// -1 if not found.
    int findparam (ustring name) const;

    /// Return a pointer to the symbol (specified by integer index),
    /// or NULL (if index was -1, as returned by 'findsymbol').
    Symbol *symbol (int index) {
        return index >= 0 && index < (int)m_instsymbols.size()
            ? &m_instsymbols[index] : NULL;
    }
    const Symbol *symbol (int index) const {
        return index >= 0 && index < (int)m_instsymbols.size()
            ? &m_instsymbols[index] : NULL;
    }

    /// Given symbol pointer, what is its index in the table?
    int symbolindex (Symbol *s) { return s - &m_instsymbols[0]; }

    /// Return a pointer to the master's version of the indexed symbol.
    /// It's a const*, since you shouldn't mess with the master's copy.
    const Symbol *mastersymbol (int index) const {
        return index >= 0 ? master()->symbol(index) : NULL;
    }

    /// Where is the location that holds the parameter's instance value?
    void *param_storage (int index);
    const void *param_storage (int index) const;

    /// Add a connection
    ///
    void add_connection (int srclayer, const ConnectedParam &srccon,
                         const ConnectedParam &dstcon);

    /// How many connections to earlier layers do we have?
    ///
    int nconnections () const { return (int) m_connections.size (); }

    /// Return a reference to the i-th connection to an earlier layer.
    ///
    const Connection & connection (int i) const { return m_connections[i]; }
    Connection & connection (int i) { return m_connections[i]; }

    /// Reference to the connection list.
    ///
    ConnectionVec & connections () { return m_connections; }
    const ConnectionVec & connections () const { return m_connections; }

    /// Free all the connection data, return the amount of memory they
    /// previously consumed.
    size_t clear_connections () {
        size_t mem = vectorbytes (m_connections);
        ConnectionVec().swap (m_connections);
        return mem;
    }

    /// Return the unique ID of this instance.
    ///
    int id () const { return m_id; }

    /// Does this instance potentially write to any global vars?
    ///
    bool writes_globals () const { return m_writes_globals; }

    /// Should this instance only be run lazily (i.e., not
    /// unconditionally)?
    bool run_lazily () const { return m_run_lazily; }
    void run_lazily (bool lazy) { m_run_lazily = lazy; }

    /// Does this instance have any outgoing connections?
    ///
    bool outgoing_connections () const { return m_outgoing_connections; }
    /// Set whether this instance has outgoing connections.
    ///
    void outgoing_connections (bool out) { m_outgoing_connections = out; }

    int maincodebegin () const { return m_maincodebegin; }
    int maincodeend () const { return m_maincodeend; }

    int firstparam () const { return m_firstparam; }
    int lastparam () const { return m_lastparam; }

    /// Return a begin/end Symbol* pair for the set of param symbols
    /// that is suitable to pass as a range for BOOST_FOREACH.
    friend std::pair<Symbol *,Symbol *> param_range (ShaderInstance *i) {
        if (i->firstparam() == i->lastparam())
            return std::pair<Symbol*,Symbol*> ((Symbol*)NULL, (Symbol*)NULL);
        else
            return std::pair<Symbol*,Symbol*> (&i->m_instsymbols[0] + i->firstparam(),
                                               &i->m_instsymbols[0] + i->lastparam());
    }

    friend std::pair<const Symbol *,const Symbol *> param_range (const ShaderInstance *i) {
        if (i->firstparam() == i->lastparam())
            return std::pair<const Symbol*,const Symbol*> ((const Symbol*)NULL, (const Symbol*)NULL);
        else
            return std::pair<const Symbol*,const Symbol*> (&i->m_instsymbols[0] + i->firstparam(),
                                                           &i->m_instsymbols[0] + i->lastparam());
    }

    int Psym () const { return m_Psym; }
    int Nsym () const { return m_Nsym; }

    const std::vector<int> & args () const { return m_instargs; }
    std::vector<int> & args () { return m_instargs; }
    int arg (int argnum) { return args()[argnum]; }
    Symbol *argsymbol (int argnum) { return symbol(arg(argnum)); }
    const OpcodeVec & ops () const { return m_instops; }
    OpcodeVec & ops () { return m_instops; }

    std::string print ();  // Debugging

    SymbolVec &symbols () { return m_instsymbols; }
    const SymbolVec &symbols () const { return m_instsymbols; }

    /// Make sure there's room for more symbols.
    ///
    void make_symbol_room (size_t moresyms=1);

    /// Does it appear that the layer is completely unused?
    ///
    bool unused () const { return run_lazily() && ! outgoing_connections(); }

    /// Make our own version of the code and args from the master.
    ///
    void copy_code_from_master ();

    /// Small data structure to hold just the symbol info that the
    /// instance overrides from the master copy.
    struct SymOverrideInfo {
        char m_valuesource;
        bool m_connected_down;
        bool m_lockgeom;

        SymOverrideInfo () : m_valuesource(Symbol::DefaultVal),
                             m_connected_down(false), m_lockgeom(true) { }
        void valuesource (Symbol::ValueSource v) { m_valuesource = v; }
        Symbol::ValueSource valuesource () const { return (Symbol::ValueSource) m_valuesource; }
        const char *valuesourcename () const { return Symbol::valuesourcename(valuesource()); }
        bool connected_down () const { return m_connected_down; }
        void connected_down (bool c) { m_connected_down = c; }
        bool lockgeom () const { return m_lockgeom; }
        void lockgeom (bool l) { m_lockgeom = l; }
        friend bool equivalent (const SymOverrideInfo &a, const SymOverrideInfo &b) {
            return a.valuesource() == b.valuesource() &&
                   a.lockgeom() == b.lockgeom();
        }
    };
    typedef std::vector<SymOverrideInfo> SymOverrideInfoVec;

    SymOverrideInfo *instoverride (int i) { return &m_instoverrides[i]; }
    const SymOverrideInfo *instoverride (int i) const { return &m_instoverrides[i]; }

    /// Are two shader instances (assumed to be in the same group)
    /// equivalent, in that they may be merged into a single instance?
    bool mergeable (const ShaderInstance &b, const ShaderGroup &g) const;

private:
    ShaderMaster::ref m_master;         ///< Reference to the master
    SymOverrideInfoVec m_instoverrides; ///< Instance parameter info
    SymbolVec m_instsymbols;            ///< Symbols used by the instance
    OpcodeVec m_instops;                ///< Actual code instructions
    std::vector<int> m_instargs;        ///< Arguments for all the ops
    ustring m_layername;                ///< Name of this layer
    std::vector<int> m_iparams;         ///< int param values
    std::vector<float> m_fparams;       ///< float param values
    std::vector<ustring> m_sparams;     ///< string param values
    int m_id;                           ///< Unique ID for the instance
    bool m_writes_globals;              ///< Do I have side effects?
    bool m_run_lazily;                  ///< OK to run this layer lazily?
    bool m_outgoing_connections;        ///< Any outgoing connections?
    ConnectionVec m_connections;        ///< Connected input params
    int m_firstparam, m_lastparam;      ///< Subset of symbols that are params
    int m_maincodebegin, m_maincodeend; ///< Main shader code range
    int m_Psym, m_Nsym;                 ///< Quick lookups of common syms

    friend class ShadingSystemImpl;
    friend class RuntimeOptimizer;
};

/// Macro to loop over just the params & output params of an instance,
/// with each iteration providing a Symbol& to symbolref.  Use like this:
///        FOREACH_PARAM (Symbol &s, inst) { ... stuff with s... }
///
#define FOREACH_PARAM(symboldecl,inst) \
    BOOST_FOREACH (symboldecl, param_range(inst))

class ClosureRegistry {
public:

    struct ClosureEntry {
        // normally a closure is fully identified by its
        // name, but we might want to have an internal id
        // for fast dispatching
        int                       id;
        // The name again
        ustring                   name;
        // Number of formal arguments
        int                       nformal;
        // Number of keyword arguments
        int                       nkeyword;
        // The parameters
        std::vector<ClosureParam> params;
        // the needed size for the structure
        int                       struct_size;
        // Creation callbacks
        PrepareClosureFunc        prepare;
        SetupClosureFunc          setup;
    };

    void register_closure (const char *name, int id, const ClosureParam *params,
                           PrepareClosureFunc prepare, SetupClosureFunc setup);

    const ClosureEntry *get_entry (ustring name) const;
    const ClosureEntry *get_entry (int id) const {
        DASSERT((size_t)id < m_closure_table.size());
        return &m_closure_table[id];
    }

    bool empty () const { return m_closure_table.empty(); }

private:

    // A mapping from name to ID for the compiler
    std::map<ustring, int>    m_closure_name_to_id;
    // And the internal global table, indexed
    // by the internal ID for fast dispatching
    std::vector<ClosureEntry> m_closure_table;
};

class ShadingSystemImpl : public ShadingSystem
{
public:
    ShadingSystemImpl (RendererServices *renderer=NULL,
                       TextureSystem *texturesystem=NULL,
                       ErrorHandler *err=NULL);
    virtual ~ShadingSystemImpl ();

    virtual bool attribute (const std::string &name, TypeDesc type, const void *val);
    virtual bool getattribute (const std::string &name, TypeDesc type, void *val);

    virtual bool LoadMemoryCompiledShader (const char *shadername,
                                   const char *buffer);
    virtual bool Parameter (const char *name, TypeDesc t, const void *val);
    virtual bool Parameter (const char *name, TypeDesc t, const void *val,
                            bool lockgeom);
    virtual bool Shader (const char *shaderusage,
                         const char *shadername=NULL,
                         const char *layername=NULL);
    virtual ShaderGroupRef ShaderGroupBegin (const char *groupname=NULL);
    virtual bool ShaderGroupEnd (void);
    virtual bool ConnectShaders (const char *srclayer, const char *srcparam,
                                 const char *dstlayer, const char *dstparam);
    virtual ShaderGroupRef state ();
    virtual bool ReParameter (ShaderGroup &group,
                              const char *layername, const char *paramname,
                              TypeDesc type, const void *val);

    /// Internal error reporting routine, with printf-like arguments.
    ///
    void error (const char *message, ...);
    /// Internal warning reporting routine, with printf-like arguments.
    ///
    void warning (const char *message, ...);
    /// Internal info printing routine, with printf-like arguments.
    ///
    void info (const char *message, ...);
    /// Internal message printing routine, with printf-like arguments.
    ///
    void message (const char *message, ...);

    /// Error reporting routines that take a pre-formatted string only.
    ///
    void error (const std::string &message);
    void warning (const std::string &message);
    void info (const std::string &message);
    void message (const std::string &message);

    virtual std::string getstats (int level=1) const;

    ErrorHandler &errhandler () const { return *m_err; }

    ShaderMaster::ref loadshader (const char *name);

    virtual PerThreadInfo * create_thread_info();

    virtual void destroy_thread_info (PerThreadInfo *threadinfo);

    virtual ShadingContext *get_context (PerThreadInfo *threadinfo = NULL);

    virtual void release_context (ShadingContext *ctx);

    virtual bool execute (ShadingContext &ctx, ShaderGroup &group,
                          ShaderGlobals &ssg, bool run=true);

    virtual const void* get_symbol (ShadingContext &ctx, ustring name,
                                    TypeDesc &type);

    void operator delete (void *todel) { ::delete ((char *)todel); }

    /// Is the shading system in debug mode, and if so, how verbose?
    ///
    int debug () const { return m_debug; }

    /// Return a pointer to the renderer services object.
    ///
    RendererServices *renderer () const { return m_renderer; }

    /// Return a pointer to the texture system.
    ///
    TextureSystem *texturesys () const { return m_texturesys; }

    bool debug_nan () const { return m_debugnan; }
    bool debug_uninit () const { return m_debug_uninit; }
    bool lockgeom_default () const { return m_lockgeom_default; }
    bool strict_messages() const { return m_strict_messages; }
    bool range_checking() const { return m_range_checking; }
    bool unknown_coordsys_error() const { return m_unknown_coordsys_error; }
    int optimize () const { return m_optimize; }
    int llvm_optimize () const { return m_llvm_optimize; }
    int llvm_debug () const { return m_llvm_debug; }
    bool fold_getattribute () { return m_opt_fold_getattribute; }
    int max_warnings_per_thread() const { return m_max_warnings_per_thread; }
    bool countlayerexecs() const { return m_countlayerexecs; }

    ustring commonspace_synonym () const { return m_commonspace_synonym; }

    ustring debug_groupname() const { return m_debug_groupname; }
    ustring debug_layername() const { return m_debug_layername; }

    /// Look within the group for separate nodes that are actually
    /// duplicates of each other and combine them.  Return the number of
    /// instances that were eliminated.
    int merge_instances (ShaderGroup &group, bool post_opt = false);

    /// The group is set and won't be changed again; take advantage of
    /// this by optimizing the code knowing all our instance parameters
    /// (at least the ones that can't be overridden by the geometry).
    void optimize_group (ShaderGroup &group);

    /// After doing all optimization and code JIT, we can clean up by
    /// deleting the instances' code and arguments, and paring their
    /// symbol tables down to just parameters.
    void group_post_jit_cleanup (ShaderGroup &group);

    int *alloc_int_constants (size_t n) { return m_int_pool.alloc (n); }
    float *alloc_float_constants (size_t n) { return m_float_pool.alloc (n); }
    ustring *alloc_string_constants (size_t n) { return m_string_pool.alloc (n); }

    virtual void register_closure(const char *name, int id, const ClosureParam *params,
                                  PrepareClosureFunc prepare, SetupClosureFunc setup);
    virtual bool query_closure(const char **name, int *id,
                               const ClosureParam **params);
    const ClosureRegistry::ClosureEntry *find_closure(ustring name) const {
        return m_closure_registry.get_entry(name);
    }
    const ClosureRegistry::ClosureEntry *find_closure(int id) const {
        return m_closure_registry.get_entry(id);
    }

    /// Convert a color in the named space to RGB.
    ///
    Color3 to_rgb (ustring fromspace, float a, float b, float c);

    /// Convert an XYZ color to RGB in our preferred color space.
    Color3 XYZ_to_RGB (const Color3 &XYZ) { return XYZ * m_XYZ2RGB; }
    Color3 XYZ_to_RGB (float X, float Y, float Z) { return Color3(X,Y,Z) * m_XYZ2RGB; }
    /// Convert an RGB color in our preferred color space to XYZ.
    Color3 RGB_to_XYZ (const Color3 &RGB) { return RGB * m_RGB2XYZ; }
    Color3 RGB_to_XYZ (float R, float G, float B) { return Color3(R,G,B) * m_RGB2XYZ; }

    /// Return the luminance of an RGB color in the current color space.
    float luminance (const Color3 &RGB) { return RGB.dot(m_luminance_scale); }

    /// Return the RGB in the current color space for blackbody radiation
    /// at temperature T (in Kelvin).
    Color3 blackbody_rgb (float T /*Kelvin*/);

    /// Set the current color space.
    bool set_colorspace (ustring colorspace);

    virtual int raytype_bit (ustring name);

    virtual void optimize_all_groups (int nthreads=0);

    typedef boost::unordered_map<ustring,OpDescriptor,ustringHash> OpDescriptorMap;

    /// Look up OpDescriptor for the named op, return NULL for unknown op.
    ///
    const OpDescriptor *op_descriptor (ustring opname) {
        OpDescriptorMap::const_iterator i = m_op_descriptor.find (opname);
        if (i != m_op_descriptor.end())
            return &(i->second);
        else
            return NULL;
    }

    void pointcloud_stats (int search, int get, int results, int writes=0);

    /// Is the named symbol among the renderer outputs?
    bool is_renderer_output (ustring name) const;

private:
    void printstats () const;

    /// Find the index of the named layer in the current shader group.
    /// If found, return the index >= 0 and put a pointer to the instance
    /// in inst; if not found, return -1 and set inst to NULL.
    /// (This is a helper for ConnectShaders.)
    int find_named_layer_in_group (ustring layername, ShaderInstance * &inst);

    /// Turn a connectionname (such as "Kd" or "Cout[1]", etc.) into a
    /// ConnectedParam descriptor.  This routine is strictly a helper for
    /// ConnectShaders, and will issue error messages on its behalf.
    /// The return value will not be valid() if there is an error.
    ConnectedParam decode_connected_param (const char *connectionname,
                               const char *layername, ShaderInstance *inst);

    /// Get the per-thread info, create it if necessary.
    ///
    PerThreadInfo *get_perthread_info () const {
        PerThreadInfo *p = m_perthread_info.get ();
        if (! p) {
            p = new PerThreadInfo;
            m_perthread_info.reset (p);
        }
        return p;
    }

    /// Set up LLVM -- make sure we have a Context, Module, ExecutionEngine,
    /// retained JITMemoryManager, etc.
    void SetupLLVM ();

    void setup_op_descriptors ();

    RendererServices *m_renderer;         ///< Renderer services
    TextureSystem *m_texturesys;          ///< Texture system

    ErrorHandler *m_err;                  ///< Error handler
    std::list<std::string> m_errseen, m_warnseen;
    static const int m_errseenmax = 32;
    mutable mutex m_errmutex;

    typedef std::map<ustring,ShaderMaster::ref> ShaderNameMap;
    ShaderNameMap m_shader_masters;       ///< name -> shader masters map

    ConstantPool<int> m_int_pool;
    ConstantPool<Float> m_float_pool;
    ConstantPool<ustring> m_string_pool;

    OpDescriptorMap m_op_descriptor;

    // Options
    int m_statslevel;                     ///< Statistics level
    bool m_lazylayers;                    ///< Evaluate layers on demand?
    bool m_lazyglobals;                   ///< Run lazily even if globals write?
    bool m_clearmemory;                   ///< Zero mem before running shader?
    bool m_debugnan;                      ///< Root out NaN's?
    bool m_debug_uninit;                  ///< Find use of uninitialized vars?
    bool m_lockgeom_default;              ///< Default value of lockgeom
    bool m_strict_messages;               ///< Strict checking of message passing usage?
    bool m_range_checking;                ///< Range check arrays & components?
    bool m_unknown_coordsys_error;        ///< Error to use unknown xform name?
    bool m_greedyjit;                     ///< JIT as much as we can?
    bool m_countlayerexecs;               ///< Count number of layer execs?
    int m_max_warnings_per_thread;        ///< How many warnings to display per thread before giving up?
    int m_optimize;                       ///< Runtime optimization level
    bool m_opt_simplify_param;            ///< Turn instance params into const?
    bool m_opt_constant_fold;             ///< Allow constant folding?
    bool m_opt_stale_assign;              ///< Optimize stale assignments?
    bool m_opt_elide_useless_ops;         ///< Optimize away useless ops?
    bool m_opt_elide_unconnected_outputs; ///< Elide unconnected outputs?
    bool m_opt_peephole;                  ///< Do some peephole optimizations?
    bool m_opt_coalesce_temps;            ///< Coalesce temporary variables?
    bool m_opt_assign;                    ///< Do various assign optimizations?
    bool m_opt_mix;                       ///< Special 'mix' optimizations
    bool m_opt_merge_instances;           ///< Merge identical instances?
    bool m_opt_fold_getattribute;         ///< Constant-fold getattribute()?
    bool m_opt_middleman;                 ///< Middle-man optimization?
    bool m_optimize_nondebug;             ///< Fully optimize non-debug!
    int m_llvm_optimize;                  ///< OSL optimization strategy
    int m_debug;                          ///< Debugging output
    int m_llvm_debug;                     ///< More LLVM debugging output
    ustring m_debug_groupname;            ///< Name of sole group to debug
    ustring m_debug_layername;            ///< Name of sole layer to debug
    ustring m_opt_layername;              ///< Name of sole layer to optimize
    ustring m_only_groupname;             ///< Name of sole group to compile
    std::string m_searchpath;             ///< Shader search path
    std::vector<std::string> m_searchpath_dirs; ///< All searchpath dirs
    ustring m_commonspace_synonym;        ///< Synonym for "common" space
    std::vector<ustring> m_raytypes;      ///< Names of ray types
    std::vector<ustring> m_renderer_outputs; ///< Names of renderer outputs
    ustring m_colorspace;                 ///< What RGB colors mean
    int m_max_local_mem_KB;               ///< Local storage can a shader use
    bool m_compile_report;

    // Derived/cached calculations from options:
    Color3 m_Red, m_Green, m_Blue;        ///< Color primaries (xyY)
    Color3 m_White;                       ///< White point (xyY)
    Matrix33 m_XYZ2RGB;                   ///< XYZ to RGB conversion matrix
    Matrix33 m_RGB2XYZ;                   ///< RGB to XYZ conversion matrix
    Color3 m_luminance_scale;             ///< Scaling for RGB->luma
    std::vector<Color3> m_blackbody_table; ///< Precomputed blackbody table

    // State
    bool m_in_group;                      ///< Are we specifying a group?
    ShaderUse m_group_use;                ///< Use of group
    ParamValueList m_pending_params;      ///< Pending Parameter() values
    ShaderGroupRef m_curgroup;            ///< Current shading attribute state
    mutable mutex m_mutex;                ///< Thread safety
    mutable thread_specific_ptr<PerThreadInfo> m_perthread_info;

    // Stats
    atomic_int m_stat_shaders_loaded;     ///< Stat: shaders loaded
    atomic_int m_stat_shaders_requested;  ///< Stat: shaders requested
    PeakCounter<int> m_stat_instances;    ///< Stat: instances
    PeakCounter<int> m_stat_contexts;     ///< Stat: shading contexts
    int m_stat_groups;                    ///< Stat: shading groups
    int m_stat_groupinstances;            ///< Stat: total inst in all groups
    atomic_int m_stat_instances_compiled; ///< Stat: instances compiled
    atomic_int m_stat_groups_compiled;    ///< Stat: groups compiled
    atomic_int m_stat_empty_instances;    ///< Stat: shaders empty after opt
    atomic_int m_stat_merged_inst;        ///< Stat: number of merged instances
    atomic_int m_stat_merged_inst_opt;    ///< Stat: merged insts after opt
    atomic_int m_stat_empty_groups;       ///< Stat: groups empty after opt
    atomic_int m_stat_regexes;            ///< Stat: how many regex's compiled
    atomic_int m_stat_preopt_syms;        ///< Stat: pre-optimization symbols
    atomic_int m_stat_postopt_syms;       ///< Stat: post-optimization symbols
    atomic_int m_stat_preopt_ops;         ///< Stat: pre-optimization ops
    atomic_int m_stat_postopt_ops;        ///< Stat: post-optimization ops
    atomic_int m_stat_middlemen_eliminated; ///< Stat: middlemen eliminated
    atomic_int m_stat_const_connections;  ///< Stat: const connections elim'd
    atomic_int m_stat_global_connections; ///< Stat: global connections elim'd
    double m_stat_optimization_time;      ///< Stat: time spent optimizing
    double m_stat_opt_locking_time;       ///<   locking time
    double m_stat_specialization_time;    ///<   runtime specialization time
    double m_stat_total_llvm_time;        ///<   total time spent on LLVM
    double m_stat_llvm_setup_time;        ///<     llvm setup time
    double m_stat_llvm_irgen_time;        ///<     llvm IR generation time
    double m_stat_llvm_opt_time;          ///<     llvm IR optimization time
    double m_stat_llvm_jit_time;          ///<     llvm JIT time
    double m_stat_inst_merge_time;        ///< Stat: time merging instances
    double m_stat_getattribute_time;      ///< Stat: time spent in getattribute
    double m_stat_getattribute_fail_time; ///< Stat: time spent in getattribute
    atomic_ll m_stat_getattribute_calls;  ///< Stat: Number of getattribute
    long long m_stat_pointcloud_searches;
    long long m_stat_pointcloud_searches_total_results;
    int m_stat_pointcloud_max_results;
    int m_stat_pointcloud_failures;
    long long m_stat_pointcloud_gets;
    long long m_stat_pointcloud_writes;
    atomic_ll m_stat_layers_executed;     ///< Total layers executed

    int m_stat_max_llvm_local_mem;        ///< Stat: max LLVM local mem
    PeakCounter<off_t> m_stat_memory;     ///< Stat: all shading system memory

    PeakCounter<off_t> m_stat_mem_master; ///< Stat: master-related mem
    PeakCounter<off_t> m_stat_mem_master_ops;
    PeakCounter<off_t> m_stat_mem_master_args;
    PeakCounter<off_t> m_stat_mem_master_syms;
    PeakCounter<off_t> m_stat_mem_master_defaults;
    PeakCounter<off_t> m_stat_mem_master_consts;
    PeakCounter<off_t> m_stat_mem_inst;   ///< Stat: instance-related mem
    PeakCounter<off_t> m_stat_mem_inst_syms;
    PeakCounter<off_t> m_stat_mem_inst_paramvals;
    PeakCounter<off_t> m_stat_mem_inst_connections;

    spin_mutex m_stat_mutex;              ///< Mutex for non-atomic stats
    ClosureRegistry m_closure_registry;
    std::vector<ShaderGroupRef> m_groups_to_compile;
    atomic_int m_groups_to_compile_count;
    atomic_int m_threads_currently_compiling;
    spin_mutex m_groups_to_compile_mutex;

    friend class OSL::ShadingContext;
    friend class ShaderMaster;
    friend class ShaderInstance;
    friend class RuntimeOptimizer;
    friend class BackendLLVM;
};

template<int BlockSize>
class SimplePool {
public:
    SimplePool() {
        m_blocks.push_back(new char[BlockSize]);
        m_block_offset = BlockSize;
        m_current_block = 0;
    }

    ~SimplePool() {
        for (size_t i =0; i < m_blocks.size(); ++i)
            delete [] m_blocks[i];
    }

    char * alloc(size_t size, size_t alignment=1) {
        // Alignment must be power of two
        DASSERT ((alignment & (alignment - 1)) == 0);
        // Fail if beyond allocation limits or senseless alignment
        if (size > BlockSize || (size & (alignment - 1)) != 0)
            return NULL;
        m_block_offset -= (m_block_offset & (alignment - 1)); // Fix up alignment
        if (size <= m_block_offset) {
            // Enough space in current block
            m_block_offset -= size;
        } else {
            // Need to allocate a new block
            m_current_block++;
            m_block_offset = BlockSize - size;
            if (m_blocks.size() == m_current_block)
                m_blocks.push_back(new char[BlockSize]);
        }
        return m_blocks[m_current_block] + m_block_offset;
    }

    void clear () { m_current_block = 0; m_block_offset = BlockSize; }

private:
    std::vector<char *> m_blocks;
    size_t              m_current_block;
    size_t              m_block_offset;
};

/// Represents a single message for use by getmessage and setmessage opcodes
///
struct Message {
    Message(ustring name, const TypeDesc& type, int layeridx, ustring sourcefile, int sourceline, Message* next) :
       name(name), data(NULL), type(type), layeridx(layeridx), sourcefile(sourcefile), sourceline(sourceline), next(next) {}

    /// Some messages don't have data because getmessage() was called before setmessage
    /// (which is flagged as an error to avoid ambiguities caused by execution order)
    ///
    bool has_data() const { return data != NULL; }

    ustring name;           ///< name of this message
    char* data;             ///< actual data of the message (will never change once the message is created)
    TypeDesc type;          ///< what kind of data is stored here? FIXME: should be TypeSpec
    int layeridx;           ///< layer index where this was message was created
    ustring sourcefile;     ///< source code file that contains the call that created this message
    int sourceline;         ///< source code line that contains the call that created this message
    Message* next;          ///< linked list of messages (managed by MessageList below)
};

/// Represents the list of messages set by a given shader using setmessage and getmessage
///
struct MessageList {
     MessageList() : list_head(NULL), message_data() {}

     void clear() {
         list_head = NULL;
         message_data.clear();
     }

    const Message* find(ustring name) const {
        for (const Message* m = list_head; m != NULL; m = m->next)
            if (m->name == name)
                return m; // name matches
        return NULL; // not found
    }

    void add(ustring name, void* data, const TypeDesc& type, int layeridx, ustring sourcefile, int sourceline) {
        list_head = new (message_data.alloc(sizeof(Message))) Message(name, type, layeridx, sourcefile, sourceline, list_head);
        if (data) {
            list_head->data = message_data.alloc(type.size());
            memcpy(list_head->data, data, type.size());
        }
    }

private:
    Message*         list_head;
    SimplePool<1024> message_data;
};

}; // namespace pvt

/// A ShaderGroup consists of one or more layers (each of which is a
/// ShaderInstance), and the connections among them.
class ShaderGroup {
public:
    ShaderGroup (const char *name);
    ShaderGroup (const ShaderGroup &g, const char *name);
    ~ShaderGroup ();

    /// Clear the layers
    ///
    void clear () { m_layers.clear ();  m_optimized = 0;  m_executions = 0; }

    /// Append a new shader instance on to the end of this group
    ///
    void append (ShaderInstanceRef newlayer) {
        ASSERT (! m_optimized && "should not append to optimized group");
        m_layers.push_back (newlayer);
    }

    /// How many layers are in this group?
    ///
    int nlayers () const { return (int) m_layers.size(); }

    /// Array indexing returns the i-th layer of the group
    ///
    ShaderInstance * operator[] (int i) const { return m_layers[i].get(); }

    int optimized () const { return m_optimized; }
    void optimized (int opt) { m_optimized = opt; }

    size_t llvm_groupdata_size () const { return m_llvm_groupdata_size; }
    void llvm_groupdata_size (size_t size) { m_llvm_groupdata_size = size; }

    RunLLVMGroupFunc llvm_compiled_version() const {
        return m_llvm_compiled_version;
    }
    void llvm_compiled_version (RunLLVMGroupFunc func) {
        m_llvm_compiled_version = func;
    }

    /// Is this shader group equivalent to ret void?
    bool does_nothing() const {
        return m_does_nothing;
    }
    void does_nothing(bool new_val) {
        m_does_nothing = new_val;
    }

    long long int executions () const { return m_executions; }

    void start_running () {
#ifndef NDEBUG
       m_executions++;
#endif
    }

    void name (ustring name) { m_name = name; }
    ustring name () const { return m_name; }

private:
    ustring m_name;
    std::vector<ShaderInstanceRef> m_layers;
    RunLLVMGroupFunc m_llvm_compiled_version;
    size_t m_llvm_groupdata_size;
    volatile int m_optimized;        ///< Is it already optimized?
    bool m_does_nothing;             ///< Is the shading group just func() { return; }
    atomic_ll m_executions;          ///< Number of times the group executed
    mutex m_mutex;                   ///< Thread-safe optimization
    friend class ShadingSystemImpl;
};

/// The full context for executing a shader group.
///
class OSLEXECPUBLIC ShadingContext {
public:
    ShadingContext (ShadingSystemImpl &shadingsys, PerThreadInfo *threadinfo);
    ~ShadingContext ();

    /// Return a reference to the shading system for this context.
    ///
    ShadingSystemImpl & shadingsys () const { return m_shadingsys; }

    /// Get a pointer to the RendererServices for this execution.
    ///
    RendererServices *renderer () const { return m_renderer; }

    /// Execute the shaders for the given use (for example,
    /// ShadUseSurface).  If 'run' is false, do all the usual
    /// preparation, but don't actually run the shader.  Return true if
    /// the shader executed, false if it did not (including if the
    /// shader itself was empty).
    bool execute (ShaderUse use, ShaderGroup &sas,
                  ShaderGlobals &ssg, bool run=true);

    /// Return the current shader use being executed.
    ///
    ShaderUse use () const { return (ShaderUse) m_curuse; }

    ClosureComponent * closure_component_allot(int id, size_t prim_size, int nattrs) {
        size_t needed = sizeof(ClosureComponent) + (prim_size >= 4 ? prim_size - 4 : 0)
                                                 + sizeof(ClosureComponent::Attr) * nattrs;
        ClosureComponent *comp = (ClosureComponent *) m_closure_pool.alloc(needed);
        comp->type = ClosureColor::COMPONENT;
        comp->id = id;
        comp->size = prim_size;
        comp->nattrs = nattrs;
        comp->w[0] = 1.0f;
        comp->w[1] = 1.0f;
        comp->w[2] = 1.0f;
        return comp;
    }

    ClosureComponent * closure_component_allot(int id, size_t prim_size, int nattrs, const Color3 &w) {
        // Allocate the component and the mul back to back
        size_t needed = sizeof(ClosureComponent) + (prim_size >= 4 ? prim_size - 4 : 0)
                                                 + sizeof(ClosureComponent::Attr) * nattrs;
        ClosureComponent *comp = (ClosureComponent *) m_closure_pool.alloc(needed);
        comp->type = ClosureColor::COMPONENT;
        comp->id = id;
        comp->size = prim_size;
        comp->nattrs = nattrs;
        comp->w = w;
        return comp;
    }

    ClosureMul *closure_mul_allot (const Color3 &w, const ClosureColor *c) {
        ClosureMul *mul = (ClosureMul *) m_closure_pool.alloc(sizeof(ClosureMul));
        mul->type = ClosureColor::MUL;
        mul->weight = w;
        mul->closure = c;
        return mul;
    }

    ClosureMul *closure_mul_allot (float w, const ClosureColor *c) {
        ClosureMul *mul = (ClosureMul *) m_closure_pool.alloc(sizeof(ClosureMul));
        mul->type = ClosureColor::MUL;
        mul->weight.setValue (w,w,w);
        mul->closure = c;
        return mul;
    }

    ClosureAdd *closure_add_allot (const ClosureColor *a, const ClosureColor *b) {
        ClosureAdd *add = (ClosureAdd *) m_closure_pool.alloc(sizeof(ClosureAdd));
        add->type = ClosureColor::ADD;
        add->closureA = a;
        add->closureB = b;
        return add;
    }

    /// Find the named symbol in the (already-executed!) stack of
    /// shaders of the given use, with priority given to
    /// later laters over earlier layers (if they name the same symbol).
    /// Return NULL if no such symbol is found.
    Symbol * symbol (ShaderUse use, ustring name);

    /// Return a pointer to where the symbol's data lives.
    void *symbol_data (Symbol &sym);

    /// Return a reference to a compiled regular expression for the
    /// given string, being careful to cache already-created ones so we
    /// aren't constantly compiling new ones.
    const boost::regex & find_regex (ustring r);

    /// Return a pointer to the shading attribs for this context.
    ///
    ShaderGroup *attribs () { return m_attribs; }

    /// Return a reference to the MessageList containing messages.
    ///
    MessageList & messages () { return m_messages; }

    /// Look up a query from a dictionary (typically XML), staring the
    /// search from the root of the dictionary, and returning ID of the
    /// first matching node.
    int dict_find (ustring dictionaryname, ustring query);
    /// Look up a query from a dictionary (typically XML), staring the
    /// search from the given nodeID within the dictionary, and
    /// returning ID of the first matching node.
    int dict_find (int nodeID, ustring query);
    /// Return the next match of the same query that gave the nodeID.
    int dict_next (int nodeID);
    /// Look up an attribute of the given dictionary node.  If
    /// attribname is "", return the value of the node itself.
    int dict_value (int nodeID, ustring attribname, TypeDesc type, void *data);

    /// Various setup of the context done by execute().  Return true if
    /// the function should be executed, otherwise false.
    bool prepare_execution (ShaderUse use, ShaderGroup &sas);

    bool osl_get_attribute (void *renderstate, void *objdata, int dest_derivs,
                            ustring obj_name, ustring attr_name,
                            int array_lookup, int index,
                            TypeDesc attr_type, void *attr_dest);

    PerThreadInfo *thread_info () { return m_threadinfo; }

    void * alloc_scratch (size_t size, size_t align=1) {
        return m_scratch_pool.alloc (size, align);
    }

    void incr_layers_executed () { shadingsys().m_stat_layers_executed += 1; }

    bool allow_warnings() {
        if (m_max_warnings > 0) {
            // at least one more to go
            m_max_warnings--;
            return true;
        } else {
            // we've processed enough with this context
            return false;
        }
    }

private:

    /// Execute the llvm-compiled shaders for the given use (for example,
    /// ShadUseSurface).  The context must already be bound.  If
    /// runflags are not supplied, they will be auto-generated with all
    /// points turned on.
    void execute_llvm (ShaderUse use, Runflag *rf=NULL,
                       int *ind=NULL, int nind=0);

    void free_dict_resources ();

    ShadingSystemImpl &m_shadingsys;    ///< Backpointer to shadingsys
    RendererServices *m_renderer;       ///< Ptr to renderer services
    PerThreadInfo *m_threadinfo;        ///< Ptr to our thread's info
    ShaderGroup *m_attribs;      ///< Ptr to shading attrib state
    std::vector<char> m_heap;           ///< Heap memory
    int m_curuse;                       ///< Current use that we're running
    typedef boost::unordered_map<ustring, boost::regex*, ustringHash> RegexMap;
    RegexMap m_regex_map;               ///< Compiled regex's
    MessageList m_messages;             ///< Message blackboard
    int m_max_warnings;                 ///< To avoid processing too many warnings

    SimplePool<20 * 1024> m_closure_pool;
    SimplePool<64*1024> m_scratch_pool;

    Dictionary *m_dictionary;

    // Struct for holding a record of getattributes we've tried and
    // failed, to speed up subsequent getattributes calls.
    struct GetAttribQuery {
        void *objdata;
        ustring obj_name, attr_name;
        TypeDesc attr_type;
        int array_lookup, index;
        GetAttribQuery () : objdata(NULL), array_lookup(0), index(0) { }
    };
    static const int FAILED_ATTRIBS = 16;
    GetAttribQuery m_failed_attribs[FAILED_ATTRIBS];
    int m_next_failed_attrib;
};

namespace Strings {
    extern OSLEXECPUBLIC ustring camera, common, object, shader, screen, NDC;
    extern OSLEXECPUBLIC ustring rgb, RGB, hsv, hsl, YIQ, XYZ, xyz, xyY;
    extern OSLEXECPUBLIC ustring null, default_;
    extern OSLEXECPUBLIC ustring label;
    extern OSLEXECPUBLIC ustring sidedness, front, back, both;
    extern OSLEXECPUBLIC ustring P, I, N, Ng, dPdu, dPdv, u, v, time, dtime, dPdtime, Ps;
    extern OSLEXECPUBLIC ustring Ci;
    extern OSLEXECPUBLIC ustring width, swidth, twidth, rwidth;
    extern OSLEXECPUBLIC ustring blur, sblur, tblur, rblur;
    extern OSLEXECPUBLIC ustring wrap, swrap, twrap, rwrap;
    extern OSLEXECPUBLIC ustring black, clamp, periodic, mirror;
    extern OSLEXECPUBLIC ustring firstchannel, fill, alpha;
    extern OSLEXECPUBLIC ustring interp, closest, linear, cubic, smartcubic;
    extern OSLEXECPUBLIC ustring perlin, uperlin, noise, snoise, pnoise, psnoise;
    extern OSLEXECPUBLIC ustring cell, cellnoise, pcellnoise;
    extern OSLEXECPUBLIC ustring genericnoise, genericpnoise, gabor, gabornoise, gaborpnoise;
    extern OSLEXECPUBLIC ustring simplex, usimplex, simplexnoise, usimplexnoise;
    extern OSLEXECPUBLIC ustring anisotropic, direction, do_filter, bandwidth, impulses;
    extern OSLEXECPUBLIC ustring op_dowhile, op_for, op_while, op_exit;
    extern OSLEXECPUBLIC ustring subimage, subimagename;
    extern OSLEXECPUBLIC ustring missingcolor, missingalpha;
    extern OSLEXECPUBLIC ustring uninitialized_string;
}; // namespace Strings

inline int
tex_interp_to_code (ustring modename)
{
    int mode = -1;
    if (modename == Strings::smartcubic)
        mode = TextureOpt::InterpSmartBicubic;
    else if (modename == Strings::linear)
        mode = TextureOpt::InterpBilinear;
    else if (modename == Strings::cubic)
        mode = TextureOpt::InterpBicubic;
    else if (modename == Strings::closest)
        mode = TextureOpt::InterpClosest;
    return mode;
}

// Layout of structure we use to pass noise parameters
struct NoiseParams {
    int anisotropic;
    int do_filter;
    Vec3 direction;
    float bandwidth;
    float impulses;

    NoiseParams ()
        : anisotropic(0), do_filter(true), direction(1.0f,0.0f,0.0f),
          bandwidth(1.0f), impulses(16.0f)
    {
    }
};

namespace pvt {

/// Base class for objects that examine compiled shader groups (oso).
/// This includes optimization passes, "back end" code generators, etc.
/// The base class holds common data structures and methods that all
/// such processors will need.
class OSOProcessorBase {
public:
    OSOProcessorBase (ShadingSystemImpl &shadingsys, ShaderGroup &group,
                      ShadingContext *context);

    virtual ~OSOProcessorBase ();

    /// Do its thing.
    virtual void run () { }

    /// Return a reference to the shader group being optimized.
    ShaderGroup &group () const { return m_group; }

    /// Return a reference to the shading system.
    ShadingSystemImpl &shadingsys () const { return m_shadingsys; }

    /// Return a reference to the texture system.
    TextureSystem *texturesys () const { return shadingsys().texturesys(); }

    /// Return a reference to the RendererServices.
    RendererServices *renderer () const { return shadingsys().renderer(); }

    /// Retrieve the dummy shading context.
    ShadingContext *shadingcontext () const { return m_context; }

    /// Re-set what debugging level we ought to be at.
    virtual void set_debug ();

    /// What debug level are we at?
    int debug() const { return m_debug; }

    /// Set which instance (layer within the group) we are currently
    /// examining.  This lets you walk through the layers in turn.
    virtual void set_inst (int layer);

    /// Return the layer number that we currently examining.
    int layer () const { return m_layer; }

    /// Return a pointer to the currently-examining instance within the
    /// group.
    ShaderInstance *inst () const { return m_inst; }

    /// Return a reference to a particular indexed op in the current inst
    Opcode &op (int opnum) { return inst()->ops()[opnum]; }

    /// Return a pointer to a particular indexed symbol in the current inst
    Symbol *symbol (int symnum) { return inst()->symbol(symnum); }

    /// Return the symbol index of the symbol that is the argnum-th argument
    /// to the given op in the current instance.
    int oparg (const Opcode &op, int argnum) const {
        return inst()->arg (op.firstarg()+argnum);
    }

    /// Return the ptr to the symbol that is the argnum-th argument to the
    /// given op in the current instance.
    Symbol *opargsym (const Opcode &op, int argnum) {
        return (argnum < op.nargs()) ?
                    inst()->argsymbol (op.firstarg()+argnum) : NULL;
    }

    /// Is the symbol a constant whose value is 0?
    static bool is_zero (const Symbol &A);

    /// Is the symbol a constant whose value is 1?
    static bool is_one (const Symbol &A);

    /// Set up m_in_conditional[] to be true for all ops that are inside of
    /// conditionals, false for all unconditionally-executed ops,
    /// m_in_loop[] to be true for all ops that are inside a loop, and
    /// m_first_return to be the op number of the first return/exit
    /// statement (or code.size() if there is no return/exit statement).
    void find_conditionals ();

    /// Identify basic blocks by assigning a basic block ID for each
    /// instruction.  Within any basic bock, there are no jumps in or out.
    /// Also note which instructions are inside conditional states.
    void find_basic_blocks ();

    /// Will the op executed for-sure unconditionally every time the
    /// shader is run?  (Not inside a loop or conditional or after a
    /// possible early exit from the shader.)
    bool op_is_unconditionally_executed (int opnum) const {
        return !m_in_conditional[opnum] && opnum < m_first_return;
    }

protected:
    ShadingSystemImpl &m_shadingsys;  ///< Backpointer to shading system
    ShaderGroup &m_group;             ///< Group we're processing
    ShadingContext *m_context;        ///< Shading context
    int m_debug;                      ///< Current debug level

    // All below is just for the one inst we're optimizing at the moment:
    ShaderInstance *m_inst;           ///< Instance we're optimizing
    int m_layer;                      ///< Layer we're optimizing
    std::vector<int> m_bblockids;       ///< Basic block IDs for each op
    std::vector<char> m_in_conditional; ///< Whether each op is in a cond
    std::vector<char> m_in_loop;        ///< Whether each op is in a loop
    int m_first_return;                 ///< Op number of first return or exit
};

}; // namespace pvt

OSL_NAMESPACE_EXIT


A couple of years ago, I was spending around 4 hours a week mowing through spring. The lengthening days and moist soil of spring sends the grass rocketing for the sky, and if you don't mow, it rapidly becomes too long to push the mower over. One spring of push-mowing was enough for me, and by last spring I had rearranged fences so that I could slash the majority of the grass with the tractor.
Slashing is easier and quicker than push-mowing, but it still involves fuel, noise and exhaust, and is not a job I look forward to, and this year I have hit upon a more bucolic solution to the long grass problem. Cows!
Bella (at front, above) and Caramel have been roaming the paddocks all winter, but with the grass in the veggie patch becoming unmanageable, I've been putting up two-strand electric tape around the beds and letting the cows do the work. Moving the electric fences around does take time, but much less time than it takes to mow, and less time than slashing as well, if you count the changing over of the implements on the tractor. And the cows do a good job, getting right up to the fences (and occasionally the veggies if I've put the fence too close!).
Most recently, they cleaned up a manifold of 21 beds that contained brassicas that were no good anymore. By the time they had eaten all the broccoli, they were a little bored, so when I moved them into a run 100 metres by 3 metres, there was some kicking up of heels and some running hither and thither, such happy cows in the long grass!
For the last seven months I have been living away from my farm. In the mornings I've been commuting to the farm to do the day's work, then driving again in the evening to the mate's who's kindly shared his home with me. It's been a time of frustration, of living out of the back of my car, of forgetting things and having to drive to get them, of not being at the farm when I'm needed, when the ducks are eating the salad, or the tunnels are being scrapped by the wind, and there's been many days of having to finish up early due to rain, without the option of turning out later in the day to finish the job.
And it's taken this long to work out all the difficult family stuff, amidst the sturm und drang, not to mention the lawyers and banks.
But at last, on Friday, the settlement went through, and I'll be moving back to the farm next week, on a tide of ebullience...in time to take hold of the garden as she rises strong to spring.


text:
Bio Information on Afghan Rebel
Gulbuddin Hekmatyar, 52, is a Ghilzai Pashtun from Kunduz province in northern Afghanistan. A former Afghan prime minister, he speaks several languages, including English, and has three wives and several children.
_ 1979-89 Soviet occupation: Is trusted U.S. ally against Soviets and primary recipient of billions of dollars in U.S. military assistance.
_ 1989-92: Continues fight against pro-Moscow government alongside other U.S.-backed rebel groups until regime's defeat.
_ 1992-96: Signs agreement with other guerrilla groups to form government in Afghan capital Kabul but despite being prime minister refuses to enter Kabul. Joins northern warlord Rashid Dostum; together they lay siege to Kabul, fighting Burhanuddin Rabbani and his Defense Minister Ahmed Shah Massood. Warring factions destroy 70 percent of Kabul, kill 50,000 people, mostly civilians.
_ 1996: Taliban take advantage of rival's feuding, capture Kabul. Hekmatyar flees to Iran where he continues to lead Hezb-e-Islami party.
_ 2001: Hekmatyar rejects U.N.-brokered accord forming new administration, saying pact negotiated in Germany amounts to U.S.-imposed Afghan government.
_ Feb. 2002: Iran closes Hekmatyar's offices. He's believed to have left country, though reports of continued Iranian aid persist. Labeled a war criminal by members of Karzai's government.
- Hekmatyar urges Taliban to form a broad-based alliance to fight the United States; says his troops ready to join such a force.
_ Offers rewards for those who killed U.S. troops, said by U.S. counterterrorism officials to be loosely associated with al-Qaida.
_ May 2002: CIA Predator attacks Hekmatyar near Kabul; misses him but kills some followers.
_ Sept. 2002: Calls in audio taped message for Jihad against United States, saying: "All true Muslim Afghans who want an Islamic government in their country must know it is possible only when the United States and allied soldiers are forced out."
_ Sept. 5, 2002: Considered suspect in assassination attempt on Karzai and car bombing in Kabul that killed more than dozen people.
_ 2003: Issues variety of open letters condemning Karzai's government; urges holy war on foreign soldiers in Afghanistan.

redpajama_set_name: RedPajamaCommonCrawl


text:
Home News Minister's Assurance For Retrenched Persons
Minister of Labour and Social Partnership Relations, Colin Jordan.
Minister of Labour and Social Partnership Relations, Colin Jordan, has given the assurance that persons interested in employment overseas will be facilitated.
He was speaking at a press conference on the work and effort of the Labour Department and his Ministry last week.
Acknowledging that his Ministry was aware that given the retrenchment process, people would look to overseas employment, he said the Barbados Employment and Career Counselling Service (BECCS), formerly known as the National Employment Bureau, seeks to find decent work for all Barbadians through the provision of job placement services for both local and overseas employment.
Noting that his Ministry had been exploring possibilities, he said just recently they had been involved in interviews on the issue of employment overseas, adding that these were in relation to a hotel overseas as well as the traditionally known Farm Labour Programme or the Seasonal Agricultural Workers' Programme, in Canada.
"We actually had a review meeting recently in St. Lucia, about three weeks ago … and Barbados made its position very clear that we wanted to make sure that we had opportunities for those persons who may want to leave and seek employment outside of Barbados," he disclosed.
The Minister made it clear that even though the country did not want a brain drain, government recognized that persons would want work experiences outside of the island or wherever these could be found.
Stating that they remained committed to seeking out these opportunities, he said Barbados would have met with the Canadian liaison officers and others in Miami to find meaningful and decent work for Barbadians who want to explore those possibilities.
"And, yes, especially at a time when persons are being separated from the public service, there is an increased need to make sure that those persons have opportunities if they have the desire to seek employment outside of Barbados. And as a caring administration, we continue to do all in our power to make sure that as many opportunities as possible become and remain available to our people," Mr. Jordan stressed.
Commending the work of the Labour Department, the Minister said it sought to build capacity and educate workers and employers about the legislation that governs the world of work and the relations in the workplace between workers and those who employ them.
Noting that his Ministry also aims to have a harmonious workplace that contribute to the development of the country and provide for the sustenance of those who work and those who invest, he said for this to happen, conflict had to be identified and addressed.
"So, the Labour Department spends a significant amount of time working with parties to understand what has caused the conflict; what the views of the different sides are and then attempting to broker a resolution so that people can get back to a situation where they are working comfortably and productively and that there are benefits for both the worker and the business or other organization," Minister Jordan explained.
VIAJOY-ANN GILL
SOURCEBGIS
Previous articleEmployers Told: Allow Workers To Share Views And Opinions
Next articleSocial Partnership Pleased With Gov't's Progress
Joyann Gill


Most ciliated protozoa in extreme environments are cryptic in the 'seed-bank'.
Galotti, A., Finlay, B.J., Jiménez-Gómez, F., Guerrero, F. and Esteban, G., 2014. Most ciliated protozoa in extreme environments are cryptic in the 'seed-bank'. Aquatic Microbial Ecology, 72:, 187 - 193 .
This study focuses on the species rich- ness of ciliated protozoa in inland saltpans. A low number of ciliates were found thriving under extreme high salinity; however, a diverse assem- blage of ciliate species was revealed by gradually diluting the salt concentration, meaning that most ciliate species in these environments are hidden in the seed bank awaiting favourable growth condi- tions. In some saltpan samples, up to 100 % of the cil- iate species found were retrieved from the seed bank. Our results highlight the importance of ciliate seed banks as repositories of microbial diversity in the natural environment, enabling ecosystems to react to environmental change. The ability of micro- bial communities to respond to a changing environ- ment depends on a large local diversity of rare and encysted species.


New Perspectives in Climate Change is a unique collection of articles that represent the very highest level of scholarship in the field. The articles published in this collection identify some important topics that have established themselves as key areas of research among academics in the field. These include the following:- Climate change adaptation- Vulnerability to and mitigation of climate change- The effects of climate change on specific geographical communities. This new collection provides an unparalleled insight into the subject of climate change and will enable readers to access the most important 'thinkers' active in this arena today.


text:
Jim Meyer
Ranked top criminal solicitor in lawyer directories
Home → FRAUD
QBD (Admin) (Farbey J)
A requested person's extradition to Poland for fraud was disproportionate, oppressive due to the passage of time, and breached ECHR art.8. The district judge's reasoning regarding the fact that the individual was not a fugitive had been unclear, he had erred in finding that the individual had previous convictions for fraud, and he had failed to give adequate weight to the fact that 19 years had passed since the offending.
[2019] EWCA Crim 1889
CA (Crim Div) (Simon LJ, Moulder J, Judge Thomas QC)
In respect of alleged offences of fraud and engaging in an unfair commercial practice, a judge had correctly concluded that the enforceability of late payment and cancellation fees relating to the supply of domestic Energy Performance Certificates was a matter for him to determine. There was no legitimate interest in the charging of disproportionate late payment fees for the supply of the certificates.
CA (Crim Div) (Leggatt LJ, Carr J, Judge Thomas QC)
Where a confiscation order had been made against a defendant who had been convicted of offences involving the improper retention of pension contributions, it was not disproportionate to require her to pay the full amount of the benefit obtained. Although she might have received the benefit of the pension contributions in any event, it was not open to her to argue that she would or might have acquired valuable rights had she acted honestly.
CA (Crim Div) (Thirlwall LJ, Fraser J, Sir David Foskett)
False identity document offences committed by a victim of human trafficking were quashed as they had been committed in the context of a life of repeated trafficking and sexual exploitation. The offences were integral to, and consequent upon, the trafficking and exploitation so as to extinguish culpability.
CA (Crim Div) (Holroyde LJ, Martin Spencer J, Judge Picton)
The appellant's conviction for fraudulently removing property in anticipation of the winding-up of a company contrary to the Insolvency Act 1986 s.206(1)(b) was unsafe, as the fraudulent conduct in question had not occurred within the requisite period, namely 12 months immediately preceding the commencement of the winding-up. Further, the conditions for substituting an offence involving "transactions in fraud of creditors" under s.207 of the Act were not met.
CA (Crim Div) (Fulford LJ, May J, Swift J)
Sentences of six years' imprisonment, 24 months' imprisonment suspended for two years and 27 months' imprisonment imposed for conspiracy to facilitate breaches of UK immigration law by abusing the Home Office Tier 4 Temporary Migration Programme through the sale of "confirmation of acceptance to study" at colleges where no education was offered were unduly lenient; the court replaced them with sentences of four years' imprisonment, eight years' imprisonment and 3 years and 11 months immediate imprisonment. Whilst the criminal activity may not have extended over a long period of time, the offenders had fully availed themselves of the opportunity presented, relatively large sums of money had been involved and the fraud had involved significant abuse of the points-based system.
[2019] EWCA Civ 588
CA (Civ Div) (Patten LJ, Hamblen LJ, Holroyde LJ)
Where a company had a proprietary claim over proceeds of fraud because they had been obtained through the unlawful use of its property by its directors, it was entitled to assert its claim in priority to a confiscation order obtained by the CPS.
CA (Civ Div) (Gross LJ, Peter Jackson LJ, Rose LJ)
HMRC had been entitled to impose penalties on a company and its directors under the Value Added Tax Act 1994 s.60 and s.61, as well as refusing a claim for input tax credit, where the company and its directors should have known that the company's transactions were connected with missing trader fraud. In imposing the penalties, HMRC had not imported a gloss on s.60 and s.61 from EU case law, nor had it impermissibly extended the circumstances in which a criminal penalty could be imposed.
CA (Crim Div) (Sir Brian Leveson, Jeremy Baker J, Simler J)
Where a fraud trial was discontinued and then reinstated after a complaint by the victim under the Victim's Right to Review scheme prompted the Chief Crown Prosecutor to reconsider the notice of discontinuance, the judge had not erred in refusing to stay the prosecution. Prosecution of the case did not constitute executive misconduct and was not an abuse of process.
[2019] UKSC 8
SC (Lord Kerr JSC, Lord Hodge JSC, Lady Black JSC, Lord Lloyd-Jones JSC, Lord Kitchin JSC)
The extradition of a Czech Republic national who had been convicted of fraud offences in his absence was not unjust or oppressive, nor did it constitute an interference with his ECHR art.8 rights, notwithstanding the nine-year delay between the date of sentence and certification of the European arrest warrant. The district judge had correctly characterised the EAW as a conviction warrant and had taken full account of the passage of time.
Older Content


Couple Gets Engaged During Thompson Square Concert!
Keifer and Shawna Thompson of Thompson Square have been bringing couples happiness ever since their #1 song "Are You Gonna Kiss Me Or Not" hit the airwaves! Even though it's been 8 years since the song came out, it hasn't lost steam for making proposals happen!
Another happy couple got engaged Sunday night, March 18 during the hit song! Thompson Square even brought them on stage to perform their first dance during the finale!
Shawna and Keifer played new music for the crowd that will be coming out soon on their brand new album! It's been five years since their last album and the duo is gearing up to reveal their album artwork this Wednesday during their "Wino Wednesday" show, live from Nashville at the City Winery! (Tickets) They performed new songs called: "A Love Like This," "Let's Do Something Stupid" and Shawna's favorite, "Masterpiece" which was written entirely by Keifer. You can watch performances of all three new songs and enjoy the photo gallery from the show!
CMA Fest Announces Nissan Stadium Performers!
Taylor Swift Performs at The Bluebird Cafe 14 Years After Being Discovered There!


text:
About Jadyn
The Impact of Technology Today
The Impact of Technology Today: What is the Impact of Technology on Society and Business? Technology has become an integral part of our daily lives, yet not everyone has equal access to it. Rather, it often creates changes that lead to increasing inequalities. Because of this, we need to focus on access for all. This article will discuss the impact of technology on society and business, as well as how it affects our health and education. Here are some ideas about the Future of Technology and its Impact on Society
Impact of technology on society
The impact of technology on society today cannot be overstated. Whether it is about business, education, communication, or comfort, people's lives have been transformed by technology. Some of these changes are positive, while others are negative. In some cases, technology is simply an extension of the society. However, some technology has also had negative effects on people. For example, excessive use of cell phones and computer monitors can reduce people's physical activity.
While technology has streamlined our lives, there are many drawbacks. For example, online gaming can replace outdoor games, and a decrease in social interaction in general. Although this makes our lives easier, a lack of interaction with society is detrimental. Moreover, it can cause us to lose social skills and become less aware of the real world. We should not lose touch with our communities through technology, though, but embrace it and make it better.
Impact of technology on business
Technology has changed the way we live and do business. It has revolutionized the work place and the entire working process of a business. It has allowed us to automate tasks that were once done by humans, such as customer service and employee evaluation. It has also given us new ways to monitor and track the scope of our businesses. The TED Talks on technology and business touch on how technology has impacted the work environment. As a result, businesses are facing significant risks in this ever-changing world.
Despite the challenges presented by the modern world, technological innovations have enabled businesses to become more efficient. Whether it's online shopping, faster delivery, or capitalisation, technology has transformed the way businesses do business. Companies have become more responsive to customer demands and have boosted their sales in a short period of time. And if you're a retailer, technology has streamlined the process from start to finish. Online retailers are also able to collect customer data to create targeted ads and provide personalized recommendations. Technology has also had a profound impact on revenue. Businesses are now able to reach new customers, sell products more efficiently, and monitor their operations better than ever.
Impact of technology on education
The most obvious impact of technology on schools is the elimination of time and geographical isolation. Thanks to the Internet, students all over the world can access educational materials instantly. Technology is redefining education by eliminating the rigid brick-and-mortar model, with some schools now offering free Massive Open Online Courses. Students can also access classroom materials through video recordings. These programs have significantly increased the efficiency of education systems, which is a good thing for students and teachers alike.
The advent of technology has changed many aspects of our lives, including education. Students now have computers for schoolwork and Internet access. Teachers are using technology to improve their lessons. Technology is transforming the educational experience in ways we never imagined. It is imperative for students to keep up with the latest trends and explore new ways to use it in education. The impact of technology on education is widespread and has reshaped every aspect of life. However, the impact on the classroom isn't as obvious as one might think.
Impact of technology on health
While there are many positives to using technology in the medical field, the impacts of technology today on health care may be even more mixed. The use of handheld devices in healthcare will help doctors and nurses to track patient medical history in seconds. This will decrease the chance of human error and improve clinical outcomes, but it could also lead to more serious health conditions. Here are some of the negative effects of technology in health care:
There are a lot of negative health effects associated with excessive screen time, such as physical inactivity. Excessive screen time has been linked to increased risk of heart disease, diabetes, and obesity. The Covid-19 pandemic, which left people indoors, prompted more use of digital technology. Many sporting events were cancelled worldwide because of the virus. Experts believe that physical inactivity is a major cause of death in children, costing an estimated 5.3 million lives each year.
Can My VPN See My Passwords?
What is the Number 1 VPN?
Does a VPN Steal Data?
Hi, I'm Jadyn. Welcome to Gray Area Gallery. The gray area in my life has always been ITSM, so I decided to create a blog around tech topics to help me and my audience expand their knowledge in this field.
Copyright © 2023 Gray Area Tech Theme: Adore Blog By Adore Themes.


Had the same problem that occured under 0.71/0.70. After disabling EMS and XMS the game runs but no music track were played. cycles=auto will cause this problem as previously stated.
Only problem I had may have come from using a frontend :P Tried to load "zone66~1.exe" as a bootable. Running from a batch file fixed that.
Otherwise, EMS/XMS disabled, 63MB available, 10000 cycles/dynamic and the game looks beautiful.
Of special note, if you have the Gravis Ultrasound pro patches, they do nothing for the music of this game over standard GUS support.
Yep, that's fixed it... Had cpu cycles on max, I guess it threw the timing out, how weird!
Anyway, working fine, happy now :) Cheers!!!
Confirmed, I get NO Music using 0.70, but I DO when I run zone66 /s using Dosbox 0.65, or 0.63.
I have the same issue with zone66, in game sound but no intro sound with the /u or other. I also tested with the 3.5 disk of the original demo.
I look forward to the day I can get the Gravis Ultrasound back on this game and many others.
0.65: no music at all, with /s /u or otherwise. sfx come out alright.
This program can not run with an XMS driver!!!
Please remedy this condition, or run README for help.
disabling ems and xms allows the game to run, showing me the "epic megagames presents" screen. At this point the theme music starts up (just as I remember it), but that's it. no video. ever. Any ideas folks?
Just set ems=false AND xms=false and that's it!
Memory adjustment is there, required some tweaking to get it working. When you disable EMS and XMS drivers, the game crasher: DOSBox informs about "No vm86 support".
No memory adjustment in DosBOX -> Whines about presence of XMS driver and won't start.


text:
6826 N 181st Ave, Waddell, AZ 85355, us
The Breed Standards
The "Pride"
Just a few Happy Folks
Proud to Endorse
Bette and Rick
A little special things
Arizona's House of Rags is a member of TICA's "Outstanding Cattery Program"
Arizona's House of Rags is a member of TICA's "Outstanding Cattery Program"Arizona's House of Rags is a member of TICA's "Outstanding Cattery Program"
What You Need To Know About Ragdoll Health
All cats have the potential to develop genetic health problems, just as all people have the potential to inherit a particular disease.
Any breeder who claims that her breed or lines has no health or genetic problems is either lying or is not knowledgeable about the breed.
Run, don't walk, from any breeder who does not offer a health guarantee on kittens, who tells you that the breed is 100 percent healthy and has no known problems, or who tells you that her kittens are isolated from the main part of the household for health reasons.
Ragdolls are generally healthy, but bladder stones and a heart condition known as hypertrophic cardiomyopathy are among the conditions that have been reported in the breed.
Hypertrophic cardiomyopathy (HCM) is the most common form of heart disease in cats. It causes thickening (hypertrophy) of the heart muscle. An echocardiogram can confirm whether a cat has HCM. Researchers have identified the genetic mutation that causes the development of HCM in the Ragdoll and have developed a genetic test that allows breeders to screen cats before breeding them. Cats identified with HCM should be removed from breeding programs. Avoid breeders who claim to have HCM-free lines. No one can guarantee that their cats will never develop HCM.
See our Results*
Ragdoll kittens can have rapid growth spurts and it's important for them to have plenty of food available all the time. If your Ragdoll kitten cleans his plate, offer him a little more until he stops eating. Once the cat reaches his full size at four years, then you can ration his food so he doesn't get fat.
*Arizona House of Rags is an up and coming breeder of Ragdolls in the West Phoenix Valley. I have been to Kathleen's house a few times for well checks on her cats. She has a large, clean, beautiful home that her cats thoroughly enjoy. I have examined her breeding stock and found them to be healthy, gorgeous Rags. They have all test N/N for HCM which means they do not carry that gene mutation and none of the kittens will. Her cats get a lot of individual attention with her which is important since kittens need to be socialized at a very young age.
Dr Monica Brown – Fetch a Vet – West Valley House call Veterinarian.
Copyright © 2023 Arizona's House of Rags - All Rights Reserved.


Tilde - The Multifunctional Space..
The Designer Child project aims to teach children graphic designs & explore and Build their skills based on a good foundations.
Let's make the Embrace Lifeline Operational 24/7..


text:
Keynan Anthony Middleton (né le  à Portland, Oregon, États-Unis) est un lanceur de relève droitier des Angels de Los Angeles de la Ligue majeure de baseball.

Carrière
Keynan Middleton est choisi par les Angels de Los Angeles au  tour de sélection du repêchage de 2013. Middleton est un athlète qui excelle surtout au basket-ball, mais décide de concentrer ses efforts sur le baseball après avoir reçu l'offre des Angels. À l'origine un lanceur partant dans les ligues mineures, le jeune droitier dont la balle rapide atteint régulièrement les , et parfois les , devient lanceur de relève à partir de la saison 2016.

Il fait ses débuts dans le baseball majeur avec les Angels le  face aux Astros de Houston.

Notes et références

Liens externes
  Statistiques de Keynan Middleton sur Baseball-Reference.
  Statistiques de Keynan Middleton sur le site des Ligues majeures de baseball.

Naissance en septembre 1993
Naissance à Portland (Oregon)
Joueur américain de baseball
Joueur des Angels de Los Angeles
Lanceur des ligues majeures de baseball

redpajama_set_name: RedPajamaWikipedia


Every Sunday night at Henrietta Hudson, join DJ Tikka, and E and Victoria on bar, for the West Village's favorite game night. There's free pool, ping-pong, board games, and the perfect ambience for making some friends and kicking back with chill eclectic tunes and the best vibes in the city. This is the perfect time and place to make some new friends and stay connected.
No cover and double Happy hour from 4-7 and 10-12.


Joy Denise's Blog: Oh Yes I Did!!
I fussy cut some accent pieces, just like Janet did, for the sashing corners.
I got a wild streak going and decided to miter my corners, and I picked a different portion of the border material for my border.... I'm loving it!
Whoo hooo! I learned a lot and I can't wait to make another one!
Good night! Or shall I say, good morning??!!
That is SEW awesome!! I LOVE the fussy cut pieces, and how the sashing strips set everything off!! Gorgeous! You are a craftswoman of excellence, sis!! Love you lots!
OH MY!!!!! YOU DID IT!!!!!!
I LOVE your border!!! I like it so much better than the floral part.
I hope you get lots of naps today, you deserve it. The quilt looks FANTASTIC!
WHOA HOA!!! You go girlfriend !! Really, really nice !!!
Your quilt looks beautiful. What a great job. YEA!!!!!!!!
OMG, I love it, Joy! That is totally awesome!!
A very pretty quilt Joy.Nice work!


text:
Sr Jr Podcast
Welcome To The Sr Jr Podcast: Advertising
January 18, 2022 Pulsar Advertising Season 1 Episode 1
Jan 18, 2022 Season 1 Episode 1
Pulsar Advertising
Welcome to the Sr Jr Podcast, the show where your host, Lisa Wharton, speaks with one person who's a seasoned veteran in their chosen field, and another who's a fresh-faced newbie just getting a career started. On today's episode, we're talking about advertising. Our Senior Level guest is Alberto Gonzalez, Executive Creative Director and CEO of Pulsar Advertising, with over three decades of marketing and creative advertising experience. Our Junior Level guest is Leah Press, Junior Art Director at Pulsar Advertising.
Alberto and Leah begin with their earliest memories of advertising, and explain what inspired them to get into the field. Alberto discusses the power of creating an ad that connects with people on a visceral level, and breaks down a typical day as the founder of an advertising agency. They talk about the process of creating an ad campaign, the difference between good and bad advertising, and whether certain age demographics are more receptive to advertising than others. Alberto and Leah both share what they have learned from people in each other's generations, and what advice they would give to them. And finally, Andy Ankowski, Creative Director at Pulsar Advertising, joins the show for the "Mid-Level Minute," summing up why advertising agencies can benefit from having people of all ages work for them.
Advertising 101
Alberto's first memory of advertising was a hairspray commercial featuring a Taekwondo Master
Leah's first memories of advertising were Tootsie Pop commercials and Teen Vogue ads
How Alberto and Leah each got started in advertising
Alberto discovered the power of creating an ad that truly connects with people and makes an impact in their lives, and got hooked
Leah enjoys working as a team and drawing inspiration from others around her
The step-by-step process of creating an ad or ad campaign
A good ad campaign connects with its intended audience in an emotional and intellectual way, and shows them how a product enhances their life
Directing advertising toward different demographics, like Baby Boomers, Millennials and Gen X, Y and Z
Advertising taps into your emotions, which can include nostalgia
The importance of learning about your audience and connecting with what is most important to them, regardless of age, ethnicity, background
Alberto has learned that younger generations are not afraid to invest in quality products and experiences
Leah has learned how to remove herself from her work and not take criticism personally, because it's all about what's best for the campaign or target audience
Mid-Level Minute with Andy Ankowski, who is in the middle of his career in advertising
Leah and Alberto's taglines for their generation
Pulsar Advertising website
All content © 2023 Sr Jr Podcast.


text:
Project Body Smart | Suspension Exercise: The Research
Category EXERCISE, Health and Wellness, TRAINING TIPS
Suspension Exercise: The Research
by Tony Nunez, MS and Len Kravitz, PhD on Oct 23, 2015
Suspension exercise combines body weight and anchored, seatbelt-like straps to provide an alternative to free weights and machines. The question on a lot of trainers' minds is whether these strap-based training systems work as well as more traditional resistance training tools. Though research into this question has been somewhat sparse, studies are starting to paint a picture of effective ways to integrate suspension exercise into a workout program.
(Note: Suspension Training™ and Suspension Trainer® are trademarked terms owned by TRX®. This article uses the generic terms suspension exercise and suspension exercise device.)
A Brief Overview of Suspension Exercise
Suspension straps are usually anchored to a fixed point about 6 feet above the floor or higher. Research studies often call them "labile" straps, denoting their unstable nature.
Though suspension exercise looks a bit like the still-rings event in men's gymnastics, the similarities are few: In the rings event, the hands remain in contact with the still rings, the legs are off the ground, and the body continually performs gymnastics skills below, above and around the rings. In suspension exercise, the arms and legs are placed interchangeably in the device, and exercises progressively and specifically challenge the musculoskeletal system.
Perhaps the best-known suspension exercise device is made by TRX®, founded by former U.S. Navy Seal Randy Hetrick, who developed the product while on active duty because he needed to stay in shape but had no access to free weights or machines. Today, a few companies are making suspension devices. The aim is to increase the body's functional movement capabilities by improving core muscle activation, posture, coordination, upper- and lower-body strength, total-body joint flexibility and dynamic balance.
Emerging research from the peer-reviewed studies summarized below illustrates some of the physiological benefits of suspension exercise. We have divided the studies into two broad research categories:
suspension exercise and core activation
suspension exercise vs. traditional resistance training
Suspension exercise devices are inherently unstable, requiring users to engage many muscles—particularly the core musculature surrounding, stabilizing and protecting the spine—to maintain optimal bodily form during exercise. Several research studies have addressed questions related to core activation during suspension exercise.
Low-Back Loading and Stiffness During Suspension Push-Ups
Beach, Howarth & Callaghan (2008) conducted a study that asked: Do the advantages outweigh the risks when performing suspended push-ups to activate the abdominal muscles?
Push-ups are workout mainstays because they can increase upper-body strength and endurance, while also requiring a great deal of core muscle activation to maintain proper form and position. Beach and colleagues investigated whether push-ups performed with a suspension exercise device require greater abdominal-wall and latissimus dorsi activation than traditional push-ups.
Eleven recreationally trained men (average age, 27) volunteered for the study. They all performed both the traditional push-up and the suspended push-up, completing one set of each—eight to 10 repetitions—with 2 minutes between sets to avoid fatigue. In the suspended push-up, participants' feet were stabilized on a solid platform and the hands were placed in the suspension device. Exercise order was randomized.
Familiarization trials before data collection ensured proper form, technique and rate of repetitions. Infrared light-emitting diodes were placed on the subjects to let researchers view kinematics, and electromyography markers on seven bilateral trunk muscle groups—rectus abdominis, external obliques, internal obliques, latissimus dorsi and erector spinae at T9, L3 and L5—provided EMG data.
Results showed that suspended push-ups generated more muscle recruitment of the abdominal wall and latissimus dorsi than standard push-ups. Average activation levels of the rectus abdominis, external abdominal obliques, internal abdominal obliques and latissimus dorsi were, respectively, 184%, 46%, 54% and 59% greater during suspended push-ups than they were during standard push-ups.
Suspended push-ups also produced greater compressive forces at L4/L5 of the lumbar spine than traditional push-ups, but the authors noted that the forces did not exceed established values for safe spine loading. The authors cautioned that while greater compressive forces can enhance spinal stability, the bigger loads increase the risk of pain in people with lower-back issues.
Take-home message: Suspended push-ups produce significantly greater challenge to the trunk muscles, latissimus dorsi and spine than standard push-ups. People with lower-back issues should proceed cautiously if performing suspended push-ups.
For six more research studies, two suspension exercise circuits (with photos), and full references, please see "The Science of Suspension Exercise" in the online IDEA Library or in the July–August 2015 issue of IDEA Fitness Journal. If you cannot access the full article and would like to, please contact the IDEA Inspired Service Team at (800) 999-4332, ext. 7
IDEA Fit Tips, Volume 13, Issue 11
© 2015 by IDEA Health & Fitness Inc. All rights reserved. Reproduction without permission is strictly prohibited.
Tony Nunez, MS IDEA Author/Presenter
Len Kravitz, PhD IDEA Author/Presenter
Len Kravitz, PhD, is the program coordinator of exercise science and a researcher at the University of New Mexico in Albuquerque, where he recently won the Outstanding Teacher of the Year award. Len w…
TAGS > Exercise, fitness, men's health, Suspension, Training, TRX, Women's Health


text:
The Mayan Apocalypse Is Coming? Not Really.
Artist's concept of a catastrophic asteroid impact with Earth. An impact with a 500-km-diameter asteroid would effectively sterilize the planet.
Image Credit: NASA (Artist: Don Davis)
One of the best things about StarTalk Radio is that, while we're totally willing to discuss pop culture items like ghosts and Mayan apocalypses and killer meteors and whether Santa could actually visit houses around the world in a single night, we do so from a place of scientific fact, experimentation and indisputable data.
Take this Sunday's upcoming new podcast on the "Mayan Apocalypse" and other doomsday fears and predictions.
It's hard to listen to astrophysicist Neil deGrasse Tyson discuss these fantasies in sober, rational tones and not wonder why people are just so obsessed with predicting the end of the world.
In this Cosmic Queries episode, Neil and comic co-host Chuck Nice take on some of the popular, prevailing doomsday scenarios, helpfully and playfully provided by our fans on Facebook, Google+ and right here on the website. Does the Mayan Calendar actually predict anything extraordinary at all? Could a solar flare cause an extinction level event here on Earth? What exactly is the likelihood that a meteor will wipe out humanity? And what about the possibility of an attack on humanity by intelligent, dinosaurs living deep under the surface of the Earth?
It's a show designed to use facts to put people's apocalyptic fears to rest… but if you find it funny, too, that's okay with us.
And for those of you who want to defend these predictions, feel free to do so in the comments below, although for the sake of discussion, it may work better if you save them and add them to the comments on the show archive page Sunday night. That way, they'll become part of the conversation for everyone who visits the show archive page. I expect that conversation will end up being a lively one…
Cosmic Queries: Mayan Apocalypse & Other Disasters will be available right here on our website and on iTunes this Sunday, December 16, 7:00pm ET.
That's it for now. Keep Looking Up!
–Jeffrey Simons
Get the most out of StarTalk!
Ad-Free Audio Downloads
Ad-Free Video Episodes
Stickers & Mugs
Live Streams with Neil
Priority Cosmic Queries
Early-Access Videos
Learn the Meaning of Life
...and much more
This Week Only! Free Meteor Shower and a Special Bonus Offer!
Watching Neil deGrasse Tyson connect with rapper GZA


The Defense Department announced Tuesday that it had awarded $976 million in contracts to build President Donald Trump's much-sought-after border wall with a completion date for these projects of October 2020.
The contracts were awarded by the US Army Corps of Engineers.
Lt. Col. Jamie Davis, a spokesman for the Department of Defense, told CNN that the El Paso sector contract would include the construction of "30-foot bollard fencing and a five-foot anti-climb plate," and that the Yuma Sector project will feature "18-foot bollard fencing and a five-foot anti-climb plate."
A spokesperson for the Army Corps of Engineers told CNN last month that the plan was to install 46 miles at El Paso and 11 miles of fencing at Yuma. CNN has reported that DHS had asked the Pentagon for assistance replacing existing vehicle barriers with pedestrian fencing, as well as light installation in El Paso and Yuma.
These are the first border wall contracts to use Pentagon funds that the Trump administration had repurposed from other Defense Department accounts to support the border wall.
CNN previously reported that the contract award was expected as early as Tuesday.
Officials had previously said that if the contracts were awarded in mid-April, construction could begin by late May, depending on whether the Department of Homeland Security issues environmental waivers, which is sometimes done to expedite construction.