Example #1
0
void RTCMemStore::setSensorState(int sensorIdx, bool state) {
  uint32_t sensors = getGenData(GEN_SENSOR_STATE);
//  Serial << "setState_Before:"  << sensorIdx << " sensors: " << _BIN(sensors) <<endl;
  setBit(sensors, sensorIdx, state);
//  Serial << "setState_After: "  << sensorIdx << " sensors: " << _BIN(sensors) <<endl;
  setGenData(GEN_SENSOR_STATE, sensors);
}
Example #2
0
bool RTCMemStore::hasSensor(int sensorIdx) {
  uint32_t sensors = getGenData(GEN_SENSOR_STATE);
//  Serial << "hasSensor: "  << sensorIdx << " sensors: " << _BIN(sensors) <<endl;//
//  Serial << GPIOClass::isBitSet(sensors, sensorIdx);
  //return isBitSet(sensors, sensorIdx);
  return true;
}
Example #3
0
void CgSetTypeExact(            // SET EXACT TYPE FOR GENERATION
    TYPE type )                 // - the type
{
    CGFILE_GEN *gen;            // - generation data

    gen = getGenData();
    gen->curr_type = type;
}
Example #4
0
void CgFrontCode(               // EMIT TO CODE SEGMENT
    CGINTEROP opcode )          // - intermediate code
{
    CGINTER ins = { 0 };        // - instruction

    ins.opcode = opcode;
    cgEmit( getGenData(), &ins );
}
Example #5
0
void CgFrontCode(               // EMIT TO CODE SEGMENT
    int opcode )                // - intermediate code
{
    CGINTER ins;                // - instruction

    ins.opcode = opcode;
    ins.value.ivalue = 0;
    cgEmit( getGenData(), &ins );
}
Example #6
0
void CgFrontResultBoolean(      // SET RESULTANT TYPE TO BE BOOLEAN
    void )
{
    CGFILE_GEN *gen;            // - generation data

    gen = getGenData();
    gen->emit_type = GetBasicType( TYP_BOOL );
    gen->curr_type = gen->emit_type;
}
Example #7
0
void CgFrontSymbol(             // EMIT A SYMBOL
    SYMBOL sym )                // - the symbol
{
    CGFILE_GEN *gen;            // - generation data

    gen = getGenData();
    gen->emit_type = sym->sym_type;
    CgSetType( sym->sym_type );
    CgFrontCodePtr( IC_LEAF_NAME_FRONT, sym );
}
Example #8
0
void CgFrontCodePtr(            // EMIT (code,ptr) TO CODE SEGMENT
    int opcode,                 // - opcode
    void *value )               // - value
{
    CGINTER ins;                // - instruction

    ins.opcode = opcode;
    ins.value.pvalue = value;
    cgEmit( getGenData(), &ins );
}
Example #9
0
void CgFrontCodeUint(           // EMIT (code,unsigned) TO CODE SEGMENT
    int opcode,                 // - opcode
    unsigned value )            // - value
{
    CGINTER ins;                // - instruction

    ins.opcode = opcode;
    ins.value.uvalue = value;
    cgEmit( getGenData(), &ins );
}
Example #10
0
void CgFrontCodeInt(            // EMIT (code,int) TO CODE SEGMENT
    int opcode,                 // - opcode
    int value )                 // - value
{
    CGINTER ins;                // - instruction

    ins.opcode = opcode;
    ins.value.ivalue = value;
    cgEmit( getGenData(), &ins );
}
Example #11
0
unsigned CgFrontLabelGoto(      // GET NEXT AVAILABLE LABEL # (GOTO)
    void )
{
    CGFILE_GEN *gen;            // - generation data

    gen = getGenData();
    gen->goto_label++;
    cgEmitCodeUint( gen, IC_LABGET_GOTO, 0 );
    dump_label( printf( "LabelGoto -- %d\n", gen->goto_label ) );
    return( gen->goto_label );
}
Example #12
0
void CgFrontLabfreeCs(          // FREE CS LABELS
    unsigned count )            // - number of labels to be freed
{
    CGFILE_GEN *gen;            // - generation data

    gen = getGenData();
    gen->cs_label -= count;
    count += gen->cs_allocated;
    gen->cs_allocated = 0;
    dump_label( printf( "LabfreeCs -- %d\n", count ) );
    cgEmitCodeUint( gen, IC_LABFREE_CS, count );
}
Example #13
0
void CgFrontSwitchDefault(      // DEFAULT STATEMENT IN SWITCH STATEMENT
    SCOPE scope_sw,             // - scope for switch jump
    boolean deadcode,           // - dead-code state
    TOKEN_LOCN *posn )          // - source-file position
{
    CGFILE_GEN *gen;            // - generation data

    gen = getGenData();
    emitSourcePosn( gen, posn );
    CgFrontCode( IC_SWITCH_DEFAULT );
    LabelSwitchLabel( scope_sw, deadcode );
    cgfront_debug( "default" );
}
Example #14
0
void CgFrontDbgLine(            // SET LINE FOR DEBUGGING
    TOKEN_LOCN* posn )          // - source file position
{
    CGFILE_GEN *gen;            // - generation data

    gen = getGenData();
    emitSourcePosn( gen, posn );
#ifndef NDEBUG
    if( PragDbgToggle.dump_tokens || PragDbgToggle.dump_emit_ic ) {
        printf( "CgFrontDbgLine: %d\n", posn->line );
    }
#endif
}
Example #15
0
void CgFrontSwitchCase(         // CASE STATEMENT IN SWITCH STATEMENT
    SCOPE scope_sw,             // - scope for switch jump
    boolean deadcode,           // - dead-code state
    TOKEN_LOCN *posn,           // - source-file position
    uint_32 value )             // - switch value
{
    CGFILE_GEN *gen;            // - generation data

    gen = getGenData();
    emitSourcePosn( gen, posn );
    CgFrontCodeUint( IC_SWITCH_CASE, value );
    LabelSwitchLabel( scope_sw, deadcode );
    cgfront_debug( "case" );
}
Example #16
0
void CgFrontStatInit(           // START OF STATIC-INIT TEST IN FUNCTION
    void )
{
    CGFILE_GEN *gen;            // - generation data

    if( emitDataCGFILE == &codeCGFILE ) {
        gen = getGenData();
        ins_init_done.value.pvalue = gen->init_sym;
        cgWriteIC( codeCGFILE, &ins_init_done );
        ins_init_test.value.pvalue = gen->init_sym;
        cgWriteIC( codeCGFILE, &ins_init_test );
        flags.init_data_beg = FALSE;
        flags.init_data_end = TRUE;
    }
}
Example #17
0
unsigned CgFrontLabelCs(        // GET NEXT AVAILABLE LABEL # (CONTROL SEQ)
    void )
{
    CGFILE_GEN *gen;            // - generation data

    gen = getGenData();
    gen->cs_label++;
    if( gen->cs_allocated != 0 ) {
        gen->cs_allocated--;
    } else {
        cgEmitCodeUint( gen, IC_LABGET_CS, CS_LABEL_BLOCK );
        gen->cs_allocated = CS_LABEL_BLOCK - 1;
    }
    dump_label( printf( "Allocate CS Label: %u\n", gen->cs_label ) );
    return( gen->cs_label );
}
Example #18
0
void DgInitBegin(               // START INITIALIZATION OF SYMBOL
    SYMBOL sym )                // - the symbol
{
    CGFILE_GEN *gen;            // - generation data

    ins_init_beg.value.pvalue = sym;
    gen = getGenData();
    flags.init_data_beg = TRUE;
    flags.init_data_end = FALSE;
    gen->init_sym = sym;
    if( sym->id == SC_STATIC && ScopeId( SymScope( sym ) ) != SCOPE_FILE ) {
        emitDataCGFILE = &codeCGFILE;
    } else {
        gen->emit_init_beg = TRUE;
        gen->emit_init_end = FALSE;
    }
}
Example #19
0
void DgInitDone(                // COMPLETE INITIALIZATION OF SYMBOL
    void )
{
    CGFILE_GEN *gen;            // - generation data

    gen = getGenData();
    if( gen->emit_init_end ) {
        cgEmit( gen, &ins_init_done );
    }
    gen->emit_init_beg = FALSE;
    gen->emit_init_end = FALSE;
    if( flags.init_data_end ) {
        cgEmitData( &ins_init_done );
    }
    flags.init_data_beg = FALSE;
    flags.init_data_end = FALSE;
    emitDataCGFILE = &dataCGFILE;
}
Example #20
0
CGFILE_INS CgFrontFuncOpen(     // OPEN A FUNCTION (AND ITS FILE)
    SYMBOL func,                // - symbol for function
    TOKEN_LOCN *posn )          // - source position
{
    CGFILE_GEN *gen;            // - generation data
    DT_METHOD dtm;              // - destruction method for function
    CGFILE_INS reg;             // - position to zap for function registration

    codeCGFILE = CgioCreateFile( func );
    if( posn != NULL ) {
        codeCGFILE->defined = *posn;
    }
    gen = getGenData();
    if( posn != NULL ) {
        emitSourcePosn( gen, posn );
    }
    CgFrontCodePtr( IC_FUNCTION_OPEN, func );
    CgFrontCodePtr( IC_FUNCTION_ARGS, GetCurrScope() );
    dtm = CompInfo.dt_method_speced;
    if( ! SymIsDtor( func ) ) {
        switch( dtm ) {
          case DTM_DIRECT_SMALL :
            dtm = DTM_DIRECT;
            break;
          case DTM_TABLE_SMALL :
            dtm = DTM_TABLE;
            break;
        }
    }
    CompInfo.dt_method = dtm;
    CgFrontCodeUint( IC_FUNCTION_DTM, dtm );
    CgFrontCode( IC_NO_OP );    // - may be zapped to IC_FUNCTION_STAB
    reg = CgioLastWrite( codeCGFILE );
    gen->emit_line_no.src_file = NULL;
    if( posn != NULL ) {
        emitSourcePosn( gen, posn );
    }
    return reg;
}
int CIEC_DT_WSTRING::fromUTF8(const char *pa_pacValue, int pa_nLen, bool pa_bUnescape) {
	int nSrcLen = pa_nLen >= 0 ? pa_nLen : (pa_bUnescape ? determineEscapedStringLength(pa_pacValue, '"') : (int)strlen(pa_pacValue));
	int nSrcCappedLength = nSrcLen;

	if (0 <= nSrcLen) {
		if ((0 == pa_pacValue) || (pa_pacValue[0] == '\0') || (nSrcLen == 0)) {
			assign("", 0);
			return 0;
		}

		if (nSrcLen > static_cast<int>(scm_unMaxStringLen)) {
			// If we get a to large string we will truncate it
			// This is a conservative guess
			nSrcCappedLength = scm_unMaxStringLen;
			FZRTE_WARNING("Too large string, destination will be truncated!\n");
		}

		// The needed space is surely not larger than original length - it can
		// only be smaller if there are chars outside the BMP
		reserve(static_cast<FzrteUInt16>(nSrcCappedLength));
		if (0 == getGenData()) {
			return -1;
		}

		unsigned int nMaxWidth;
		int nLength = c_unicode_utils::checkUTF8((const char *)pa_pacValue, nSrcCappedLength, nMaxWidth);

		// Only accept if this is valid UTF-8, otherwise we can get major
		// problems when serializing
		if (nLength < 0) {
			FZRTE_WARNING("Invalid UTF-8 string given to fromString!\n");
			*this = "***INVALID UTF-8***";
			return -1;
		}
		else if (nMaxWidth > 16) {
			FZRTE_WARNING("UTF-8 string with characters outside of BMP given to fromString!\n");
		}

		// If BMP, all is well - simply assign
		if (nMaxWidth <= 16) {
			assign(pa_pacValue, static_cast<FzrteUInt16>(nSrcCappedLength));
		}
		else {
			FzrteUInt32 nCodepoint;
			const FzrteByte *pRunner = (const FzrteByte *)pa_pacValue;
			FzrteByte *pEncBuffer = (FzrteByte *)getValue();
			FzrteByte *pEncRunner = pEncBuffer;

			while (*pRunner && (pRunner - (const FzrteByte *)pa_pacValue) < nSrcCappedLength) {
				int nRes;
				nRes = c_unicode_utils::parseUTF8Codepoint(pRunner, nCodepoint);
				pRunner += nRes;
				if (nCodepoint == c_unicode_utils::scm_uiBomMarker)
					continue;
				if (nCodepoint >= 0x10000)
					nCodepoint = '?';
				nRes = c_unicode_utils::encodeUTF8Codepoint(pEncRunner, static_cast<unsigned int>(nSrcCappedLength - (pEncRunner - pEncBuffer)), nCodepoint);
				if (nRes < 1)
					break;
				pEncRunner += nRes;
			}

			*pEncRunner = '\0';
			setLength(static_cast<FzrteUInt16>(pEncRunner - pEncBuffer));
		}

		if (pa_bUnescape) {
			nLength = unescapeFromString(getValue(), '"');
			if (-1 == nLength) {
				return -1;
			}
		}
	}
	return nSrcLen;
}
bool CIEC_DT_WSTRING::fromUTF16(const FzrteByte *pa_pacBuffer, unsigned int pa_nBufferLen) {
	bool bLittleEndian = false;
	FzrteUInt32 nCodepoint;
	int nRes;
	unsigned int nRemLen = pa_nBufferLen;
	const FzrteByte *pacBuffer = pa_pacBuffer;

	if (pa_nBufferLen == 0) {
		assign("", 0);
		return true;
	}
	else if ((pa_nBufferLen & 1) == 1) {
		return false;
	}

	// Check the BOM, default to big endian
	nRes = c_unicode_utils::parseUTF16Codepoint(pa_pacBuffer, nCodepoint, false);
	if (nRes < 0)
		return false;
	if (nRes == 2) {
		if (nCodepoint == c_unicode_utils::scm_uiBomMarkerToSwap) {
			bLittleEndian = true;
			nRemLen -= 2;
			pacBuffer += 2;
		}
		else if (nCodepoint == c_unicode_utils::scm_uiBomMarker) {
			nRemLen -= 2;
			pacBuffer += 2;
		}
	}

	// Count the needed space
	const FzrteByte *pRunner = pacBuffer;
	unsigned int i = 0;
	unsigned int nNeededLength = 0;
	while (i < nRemLen) {
		nRes = c_unicode_utils::parseUTF16Codepoint(pRunner, nCodepoint, bLittleEndian);
		if (nRes < 0 || nRes + i > nRemLen)
			return false;
		i += nRes;
		pRunner += nRes;
		nRes = c_unicode_utils::encodeUTF8Codepoint(0, 0, nCodepoint);
		if (nRes < 0)
			return false;
		nNeededLength += nRes;
	}

	if (nNeededLength > scm_unMaxStringLen)
		return false;

	// Reserve and encode
	reserve(static_cast<FzrteUInt16>(nNeededLength));
	if (getGenData() == 0)
		return false;

	FzrteByte *pEncRunner = (FzrteByte *)getValue();
	FzrteByte *pDataEnd = pEncRunner + nNeededLength;
	pRunner = pacBuffer;
	i = 0;
	while (i < nRemLen) {
		nRes = c_unicode_utils::parseUTF16Codepoint(pRunner, nCodepoint, bLittleEndian);
		i += nRes;
		pRunner += nRes;
		nRes = c_unicode_utils::encodeUTF8Codepoint(pEncRunner, static_cast<unsigned int>(pDataEnd - pEncRunner), nCodepoint);
		pEncRunner += nRes;
	}
	setLength(static_cast<FzrteUInt16>(nNeededLength));
	*pEncRunner = '\0';

	return true;
}