Beispiel #1
0
/* CSF_abs - built-in function 'abs' */
static value CSF_abs(VM *c)
{
    CsCheckArgCnt(c,3);
    CsCheckType(c,3,CsNumberP);
    if (CsIntegerP(CsGetArg(c,3))) {
        int_t v = CsIntegerValue(CsGetArg(c,3));
        return CsMakeInteger(v >= 0 ? v : -v);
    }
    else {
        float_t v = CsFloatValue(CsGetArg(c,3));
        return CsMakeFloat(c,v >= 0.0 ? v : -v);
    }
}
/* writeValue - write a value */
bool write_ctx::writeValue(value v)
{
    if (v == UNDEFINED_VALUE)
        return s->put(CsFaslTagUndefined);
    else if (v == NULL_VALUE)
        return s->put(CsFaslTagNull);
    else if (v == TRUE_VALUE)
        return s->put(CsFaslTagTrue);
    else if (v == FALSE_VALUE)
        return s->put(CsFaslTagFalse);
    else if (CsCompiledCodeP(v))
        return writeCodeValue(v);
    else if (CsVectorP(v))
    {
        uint n = 0;
        if(object2id.find(v,n))
          return writeProxyValue(n);
        else
        {
          n = object2id.size();
          object2id[v] = n;
          return writeVectorValue(v);
        }
    }
    else if (CsObjectP(v))
    {
        uint n = 0;
        if(object2id.find(v,n))
          return writeProxyValue(n);
        else
        {
          n = object2id.size();
          object2id[v] = n;
          return writeObjectValue(v);
        }
    }
    else if (CsSymbolP(v))
        return writeSymbolValue(v);
    else if (CsStringP(v))
        return writeStringValue(v);
    else if (CsIntegerP(v))
        return writeIntegerValue(v);
    else if (CsFloatP(v))
        return writeFloatValue(v);
    else if (CsTupleP(v))
        return writeTupleValue(v);
    else if (CsByteVectorP(v))
        return writeByteVectorValue(v);
    else if (CsDateP(c,v))
        return writeDateValue(v);
    else if (CsColorP(v))
        return writeColorValue(v);
    else if (CsLengthP(v))
        return writeLengthValue(v);
    else if (CsAngleP(v))
        return writeAngleValue(v);
    else if (CsDurationP(v))
        return writeDurationValue(v);
    else {
#ifdef _DEBUG
        dispatch* pd = CsGetDispatch(v);
#endif
        assert(false);
        return false;
    }
}