示例#1
0
/*
  Evaluate C string.

  \param cmd  String to evaluate.

  \return UR_OK or UR_THROW.
*/
int calc_evalCStr( UThread* ut, const char* cmd, double* result )
{
    UCell cell;
    UIndex blkN;
    UIndex hold;
    int ok;
    int len = strlen( cmd );
    if( len )
    {
        blkN = ur_tokenize( ut, cmd, cmd + len, &cell );
        if( blkN )
        {
            ur_bind(ut, ur_buffer(blkN), ur_threadContext(ut), UR_BIND_THREAD);

            /* Since the program cell is not part of the dataStore,
             * the block must be manually held. */
            hold = ur_hold( blkN );
            ok = calc_eval( ut, &cell, result );
            ur_release( hold );

            return ok;
        }
        return UR_THROW;
    }
    return UR_OK;
}
示例#2
0
/*
  Define the words 'pi and 'e.
*/
void defineWords( UThread* ut )
{
    static double constants[2] = { 3.14159265358979, 2.71828182845904 };
    UAtom atoms[2];
    UBuffer* ctx;
    UCell* cell;
    int i;

    ur_internAtoms( ut, "pi e", atoms );

    ctx = ur_threadContext( ut );
    for( i = 0; i < 2; ++i )
    {
        cell = ur_ctxAddWord( ctx, atoms[i] );
        ur_setId( cell, UT_DECIMAL );
        ur_decimal(cell) = constants[i];
    }
    ur_ctxSort( ctx );
}
示例#3
0
void boron_installThreadPort( UThread* ut, const UCell* portC, UThread* utB )
{
    static char portStr[] = "thread-port";
    UBuffer* ctx;
    const UBuffer* port;
    UBuffer* buf;
    UCell* cell;
    ThreadExt* ext;


    port = ur_bufferSer( portC );
    ext = (ThreadExt*) port->ptr.v;
    ext->A.END_OPEN = 1;


    // Make port for SIDE_B.

    ctx = ur_threadContext( utB );
    cell = ur_ctxAddWord( ctx, ur_internAtom(ut, portStr, portStr + 11) );
    buf = boron_makePort( utB, ext->dev, ext, cell );
    buf->SIDE = SIDE_B;
}