Exemple #1
0
int main(int argc, char** argv)
{
	char ops = 'r';
	FILE* fd = fopen(argv[1], &ops);
	if(fd == NULL)
	{
		perror("Unable to open source file");
		return 1;
	}
	
	fseek(fd, 0L, SEEK_END);
	sourceSize = ftell(fd);
	rewind(fd);

	source = malloc(sizeof(char)*sourceSize);

	int i;
	for(i = 0; !feof(fd) && i < sourceSize; i++)
	{
		source[i] = fgetc(fd);
	}
	
	syntaxCheck(source, sourceSize);
	
	//Setup tape
	start = calloc(0, sizeof(unsigned char) * 30000);
	pos = start;
	end = start + sizeof(unsigned char) * 30000;

	interpretCommands(source, sourceSize);

	return 0;
}
Exemple #2
0
//-------------------------------------------------------------------------------------------------
void LuaWorker::on_checkFile(const IFile *pFile)
{
    if (m_pConsole==NULL || pFile==NULL)
        return;

    try
    {
        Q_ASSERT(pFile!=NULL);
        Locker lock(pFile);

        if (m_luaState==NULL)
            throw LuaException(QString("Can't execute Lua code fragment \"%1\": Lua state is not initialized").arg(pFile->getName()));

    //    qDebug() << "syntaxCheck(" << pFile->getName() << ")";

        const QVector<QString> &vLines = pFile->getLines();
        QString sScript;
        for (int i=0; i<vLines.size(); ++i)
        {
            const QString &sLine = vLines[i];
            sScript += sLine;
        }

        syntaxCheck(sScript, pFile->getName());
        emit syntaxCheckSuccess(pFile);
    }
    catch(LuaException &exc)
    {
        exc.setFile(pFile);

        QString sMsg = QString("%1 in Line %2").arg(exc.getMessage())
                                               .arg(exc.getLine());
        emit syntaxCheckFail(pFile, sMsg, (int)exc.getLine());
    }
    catch(Exception &exc)
    {
        emit syntaxCheckFail(pFile, exc.getMessage(), -1);
    }
    catch(std::exception &exc)
    {
        emit syntaxCheckFail(pFile, exc.what(), -1);
    }
    catch(...)
    {
        emit syntaxCheckFail(pFile, "Internal error: FrmConsole::executeCommand", -1);
    }
}
Exemple #3
0
/*----------------------------------------------------------------------------*/
bool moreRbspData(const StreamAccessLayer &streamAccessLayer)
{
    if(!streamAccessLayer.isEndOfStream())
    {
        const auto rbspTailBitsNum = streamAccessLayer.getSizeInBits();

        /* search for rbsp_trailing_bits */

        bool rbspStopOneBitPresent = false;
        size_t alignmentZeroBitNum = 0;

        for(const auto bit : streamAccessLayer)
        {
            if(bit)
            {
                /* rbsp_stop_one_bit */
                rbspStopOneBitPresent = true;
                alignmentZeroBitNum = 0;
            }
            else
            {
                /* rbsp_alignment_zero_bit */
                if(rbspStopOneBitPresent)
                {
                    ++alignmentZeroBitNum;
                }
            }
        }

        if(rbspStopOneBitPresent)
        {
            return
                rbspTailBitsNum
                - (1 /* rbsp_stop_one_bit */ + alignmentZeroBitNum);
        }
        else
        {
            syntaxCheck(false);
        }
    }

    return false;
}
Exemple #4
0
/*----------------------------------------------------------------------------*/
void SAO::onParse(StreamAccessLayer &streamAccessLayer, Decoder::State &decoder)
{
    /* start: derived from arguments */
    auto saoCoord = get<Coord>()->inUnits();
    /* end: derived from arguments */

    const auto rx = saoCoord.x();
    const auto ry = saoCoord.y();

    /* start: inferrable */
    auto saoMergeLeftFlag = embed<SaoMergeLeftFlag>(*this);
    auto saoMergeUpFlag = embed<SaoMergeUpFlag>(*this);
    auto saoTypeIdxLuma = embed<SaoTypeIdxLuma>(*this);
    auto saoTypeIdxChroma = embed<SaoTypeIdxChroma>(*this);
    auto saoOffsetAbs = embed<SaoOffsetAbs>(*this);
    auto saoOffsetSign = embed<SaoOffsetSign>(*this);
    auto saoBandPosition = embed<SaoBandPosition>(*this);
    auto saoEoClassLuma = embed<SaoEoClassLuma>(*this);
    auto saoEoClassChroma = embed<SaoEoClassChroma>(*this);
    auto saoTypeIdx = embed<SaoTypeIdx>(*this);
    auto saoOffsetVal = embed<SaoOffsetVal>(*this);
    auto saoEoClass = embed<SaoEoClass>(*this);
    /* end: inferrable */

    const auto picture = decoder.picture();
    const auto chromaFormatIdc = picture->chromaFormatIdc;
    const auto slice = picture->slice(saoCoord);
    const auto sh = slice->header();
    const auto ctu = picture->getCodingTreeUnit(saoCoord);

    typedef SliceSegmentHeader SSH;
    typedef CodingTreeUnit CTU;

    const auto sliceAddrInRs = slice->addr().inRs;
    const auto ctbAddrInRs = ctu->get<CTU::CtbAddrInRs>()->inUnits();

    if(0_pel < rx)
    {
        const auto leftCtbInSliceSeg = ctbAddrInRs > sliceAddrInRs;

        const auto leftCtbInTile =
            picture->tileId(picture->toCoord(ctbAddrInRs))
            == picture->tileId(picture->toCoord(ctbAddrInRs - 1_ctb));

        if(leftCtbInSliceSeg && leftCtbInTile)
        {
            parse(streamAccessLayer, decoder, *saoMergeLeftFlag);
        }
    }

    if(0_pel < ry && !*saoMergeLeftFlag)
    {
        const auto picWidthInCtbsY = picture->widthInCtbsY;

        const auto upCtbInSliceSeg =
            (ctbAddrInRs - picWidthInCtbsY) >= sliceAddrInRs;
        const auto upCtbInTile =
            picture->tileId(picture->toCoord(ctbAddrInRs))
            == picture->tileId(picture->toCoord(ctbAddrInRs - picWidthInCtbsY));

        if(upCtbInSliceSeg && upCtbInTile)
        {
            parse(streamAccessLayer, decoder, *saoMergeUpFlag);
        }
    }

    if(*saoMergeLeftFlag || *saoMergeUpFlag)
    {
        const auto deriveAdjCoord =
            [saoCoord, saoMergeLeftFlag, saoMergeUpFlag]()
            {
                if(*saoMergeLeftFlag)
                {
                    syntaxCheck(0_pel < saoCoord.x());
                    return PelCoord{saoCoord.x() - 1_pel, saoCoord.y()};
                }
                else if(*saoMergeUpFlag)
                {
                    syntaxCheck(0_pel < saoCoord.y());
                    return PelCoord{saoCoord.x(), saoCoord.y() - 1_pel};
                }
                else
                {
                    syntaxCheck(false);
                }

                return PelCoord{saoCoord};
            };

        const auto adjCoord = deriveAdjCoord();
        const auto adj = picture->getCodingTreeUnit(adjCoord)->getSAO();

        saoTypeIdx->merge(*adj);
        saoOffsetVal->merge(*adj);
        saoBandPosition->merge(*adj);
        saoEoClass->merge(*adj);
    }
    else
    {
        for(const auto cIdx : EnumRange<Plane>())
        {
            const auto component = toComponent(cIdx);
            const auto isLuma = Component::Luma == component;
            const auto isChroma = !isLuma;

            if(
                    isLuma && !(*sh->get<SSH::SliceSaoLumaFlag>())
                    || ChromaFormatIdc::f400 == chromaFormatIdc && isChroma
                    || isChroma && !(*sh->get<SSH::SliceSaoChromaFlag>()))
            {
                continue;
            }

            if(Plane::Y == cIdx)
            {
                parse(streamAccessLayer, decoder, *saoTypeIdxLuma);
                saoTypeIdx->set(*saoTypeIdxLuma);
            }
            else if(Plane::Cb == cIdx)
            {
                parse(streamAccessLayer, decoder, *saoTypeIdxChroma);
                saoTypeIdx->set(*saoTypeIdxChroma);
            }

            if(SaoType::NotApplied != (*saoTypeIdx)[component])
            {
                for(auto i = 0; i < 4; ++i)
                {
                    parse(streamAccessLayer, decoder, *saoOffsetAbs, cIdx, i);
                }

                saoOffsetSign->init(cIdx, (*saoTypeIdx)[component]);

                if(SaoType::BandOffset == (*saoTypeIdx)[component])
                {
                    for(auto i = 0; i < 4; ++i)
                    {
                        if(0 != (*saoOffsetAbs)[makeTuple(cIdx, i)])
                        {
                            parse(streamAccessLayer, decoder, *saoOffsetSign, cIdx, i);
                        }
                    }

                    parse(streamAccessLayer, decoder, *saoBandPosition, cIdx);
                }
                else
                {
                    syntaxCheck(SaoType::EdgeOffset == (*saoTypeIdx)[component]);

                    if(Plane::Y == cIdx)
                    {
                        parse(streamAccessLayer, decoder, *saoEoClassLuma);
                    }

                    if(Plane::Cb == cIdx)
                    {
                        parse(streamAccessLayer, decoder, *saoEoClassChroma);
                    }
                }
            }
        }

        typedef PpsRangeExtension PPSRE;

        const auto ppsre = picture->ppsre;
        const auto saoOffsetScaleLuma =
            ppsre ? ppsre->get<PPSRE::SaoOffsetScaleLuma>()->inUnits() : 0_log2;
        const auto saoOffsetScaleChroma =
            ppsre ? ppsre->get<PPSRE::SaoOffsetScaleChroma>()->inUnits() : 0_log2;

        saoOffsetVal->set(
                *saoOffsetAbs, *saoOffsetSign,
                saoOffsetScaleLuma, saoOffsetScaleChroma);

        saoEoClass->set(*saoEoClassLuma, *saoEoClassChroma);
    }
}