コード例 #1
0
ファイル: test-interp-base.c プロジェクト: Spudd86/compsl
int main()
{
	puts("Running base interpreter tests");

	VM *vm = createVM();
	compart *com = createComp(vm);
	bool ret = 0;

	/************************ Begin Tests *************************************/
	{ // PUSH,POP
		bytecode code[] =
		{
			{.code = BC_PUSH, { {.a1 =0} } }, //push local at address 0
			{.code = BC_POP, { {.a1 =1} }}, // pop into address 1
			{.code = BC_END}  // end
コード例 #2
0
ファイル: test-interp-jumps.c プロジェクト: Spudd86/compsl
int main()
{
	puts("Running interpreter jump tests");
	
	VM *vm = createVM();
	compart *com = createComp(vm);
	bool ret = 0;
	
	
	{ // JMP 1 
		bytecode code[] = 
		{ 
			{.code = BC_PUSH, { {.a1 =1} } }, //push local at address 1
			{.code = BC_PUSH, { {.a1 =2} } }, //push local at address 2
			{.code = BC_JMP, {.a = 2} }, // jump forward, skip next instruction
コード例 #3
0
ファイル: test-interp.c プロジェクト: Spudd86/compsl
int main()
{
	puts("Running interpreter tests");
	
	VM *vm = createVM();
	compart *com = createComp(vm);
	bool ret = 0;
	
	
	//Tests
	
	{ // LS/JMN 
		bytecode code[] = 
		{ 
			{.code = BC_CPUSH, { {.a1 =1} } }, //push const at address 1
			{.code = BC_CPUSH, { {.a1 =0} } }, //push const at address 0
			{.code = BC_CPUSH, { {.a1 =0} } }, //push const at address 0
コード例 #4
0
ファイル: osdPolySmooth.cpp プロジェクト: janba/OpenSubdiv
// Propagate objectGroups from inMesh to subdivided outMesh
// Note: Currently only supporting facet groups (for per-facet shading)
MStatus
createSmoothMesh_objectGroups(const MFnMeshData &inMeshDat,
    int subdivisionLevel, MFnMeshData &newMeshDat) {

    MStatus returnStatus;

    int facesPerBaseFace = (int)(pow(4.0f, subdivisionLevel));
    MIntArray newCompElems;

    for(unsigned int gi=0; gi < inMeshDat.objectGroupCount(); gi++) {
        unsigned int compId = inMeshDat.objectGroup(gi, &returnStatus);
        MCHECKERR(returnStatus, "cannot get objectGroup() comp ID.");
        MFn::Type compType = inMeshDat.objectGroupType(compId, &returnStatus);
        MCHECKERR(returnStatus, "cannot get objectGroupType().");

        // get elements from inMesh objectGroupComponent
        MIntArray compElems;
        MFnSingleIndexedComponent compFn(inMeshDat.objectGroupComponent(compId), &returnStatus );
        MCHECKERR(returnStatus, "cannot get MFnSingleIndexedComponent for inMeshDat.objectGroupComponent().");
        compFn.getElements(compElems);

        // Only supporting kMeshPolygonComponent ObjectGroups at this time
        // Skip the other types
        if (compType == MFn::kMeshPolygonComponent) {

            // convert/populate newCompElems from compElems of inMesh
            // (with new face indices) to outMesh
            newCompElems.setLength( compElems.length() * facesPerBaseFace );
            for (unsigned int i=0; i < compElems.length(); i++) {

                int startElemIndex = i * facesPerBaseFace;
                int startElemValue = compElems[i] * facesPerBaseFace;

                for (int j=0; j < facesPerBaseFace; j++) {
                    newCompElems[startElemIndex+j] = startElemValue+j;
                }
            }
            // create comp
            createComp(newMeshDat, compType, compId, newCompElems);
        }
    }
    return MS::kSuccess;
}
コード例 #5
0
ファイル: test-intern.c プロジェクト: Spudd86/compsl
int main()
{
	puts("Running internal tests");
	
	int ret = 0;
    
	{	//varTable tests 
		varTable vt;
		var *vs[6];
        
		varTableCreate(&vt, 6);
		
        vs[0] = addVar(&vt,INT_VAR, "foo");
		vs[1] = addVar(&vt,IS_GLBL | FLOAT_VAR, "bar");
		vs[2] = addVar(&vt, FLOAT_VAR | IS_ARRAY, "foobar");
		vs[3] = addVar(&vt, FLOAT_VAR, "baz");
		vs[4] = addVar(&vt, FLOAT_VAR, "foo");
		vs[5] = addVar(&vt, FLOAT_VAR | IS_ARRAY, "foobar");
		
		assert(vs[2] == vs[5]);
		
        for(int i=0;i< 5; i++)
			for(int j=0; j<5;j++)
				if(j != i) assert(vs[i] != vs[j]);
        
        int16_t ind;
        
        //int16_t findVar(const varTable *vt,const char *name)
        ind = findVar(&vt, "foo");
        assert(vs[0] ==  &(vt.vars[ind])); 
		
		varTableDestroy(&vt);
	}
    
	{ // comparment constant testing
        
        //int16_t com_addConst(compart *com, intfloat val);
	}
    
    {
        //test searchSym
//        typedef struct
//        {
//            int16_t id;
//            bool isvar;// if this is false then symbol is a native or built in function
//            bool local;
//            bool array;
//            bool isfloat;
//        }symbolinfo; // used for symbol table search (for compiler)
//        
//        /**
//         * search all symbol tables and return info on a symbol
//         * 
//         * Post: if symbol doesn't exist returns a symbolinfo with id=-1
//         *       else returns info on symbol
//         */
//        symbolinfo searchSym(const char *name, compart *com) __attribute__ ((pure));
        VM *vm = createVM();
        compart *com = createComp(vm);
        
        //int16_t com_addConst(compart *com, intfloat val);
        com_addConst(com,(intfloat)0);
        
        
        destroyComp(com);
        destroyVM(vm);
    }
    
    
	return ret;
}
コード例 #6
0
ファイル: mayaPolySmooth.cpp プロジェクト: AiYong/OpenSubdiv
// Propagate objectGroups from inMesh to subdivided outMesh
// Note: Currently only supporting facet groups (for per-facet shading)
MStatus
createSmoothMesh_objectGroups( MFnMesh const & inMeshFn,
    MFnMeshData const & inMeshDat, MFnMeshData &newMeshDat, int level, int numSubfaces ) {

    MStatus status;

    MIntArray newCompElems;

    std::vector<unsigned int> offsets; // mapping of offsets for subdivided faces

    for(unsigned int gi=0; gi<inMeshDat.objectGroupCount(); gi++) {

        unsigned int compId = inMeshDat.objectGroup(gi, &status);
        MCHECKERR(status, "cannot get objectGroup() comp ID.");

        MFn::Type compType = inMeshDat.objectGroupType(compId, &status);
        MCHECKERR(status, "cannot get objectGroupType().");

        // Only supporting kMeshPolygonComponent ObjectGroups at this time
        // Skip the other types
        if (compType == MFn::kMeshPolygonComponent) {

            // get elements from inMesh objectGroupComponent
            MIntArray compElems;
            MFnSingleIndexedComponent compFn(
                inMeshDat.objectGroupComponent(compId), &status );
            MCHECKERR(status, "cannot get MFnSingleIndexedComponent for inMeshDat.objectGroupComponent().");
            compFn.getElements(compElems);

            if (compElems.length()==0) {
                continue;
            }

            // over-allocation to maximum possible length
            newCompElems.setLength( numSubfaces );

            if (offsets.empty()) {
                // lazy population of the subface offsets table
                int nfaces = inMeshFn.numPolygons();

                offsets.resize(nfaces);

                for (int i=0, count=0; i<nfaces; ++i) {

                    int nverts = inMeshFn.polygonVertexCount(i),
                        nsubfaces = computeNumSubfaces(nverts, level);

                    offsets[i] = count;
                    count+=nsubfaces;
                }
            }

            unsigned int idx = 0;

            // convert/populate newCompElems from compElems of inMesh
            // (with new face indices) to outMesh
            for (unsigned int i=0; i < compElems.length(); i++) {

                int nverts = inMeshFn.polygonVertexCount(compElems[i]),
                    nsubfaces = computeNumSubfaces(nverts, level);

                unsigned int subFaceOffset = offsets[compElems[i]];

                for (int j=0; j<nsubfaces; ++j) {
                    newCompElems[idx++] = subFaceOffset++;
                }
            }

            // resize to actual length
            newCompElems.setLength( idx );

            // create comp
            createComp(newMeshDat, compType, compId, newCompElems);
        }
    }
    return MS::kSuccess;
}
コード例 #7
0
ファイル: test-comp.c プロジェクト: Spudd86/compsl
int main()
{
	puts("Running Compiler Tests");
	
	const int NUM_FILES=12;
	
	const char * files[] = 
	{
		"src/test/base.csl",
		"src/test/debug.csl",
		"src/test/decls.csl",
		"src/test/decls2.csl",
		"src/test/math.csl",
		"src/test/functions.csl",
		"src/test/expressions.csl",
		"src/test/casting.csl",
		"src/test/flow.csl",
		"src/test/mincrash.csl",
		"src/test/comparison.csl",
		"src/test/arrays.csl",
		NULL
	};
	
	const char *err_files[] =
	{
		"src/test/missingDec.csl",
		"src/test/error.csl",
		NULL
	};
	
	VM *veem = createVM();
	compart *com[NUM_FILES];
	addPrintLibToVm(veem);
	addDebugLibToVm(veem);
	
	for(int i=0;files[i] != NULL;i++) {
	  int ret;
	  printf("File %s: ",files[i]);
	  
	  com[i] = createComp(veem);
	  ret = fileCompile(files[i], com[i]);
	  fflush(stdout);
	  fflush(stderr);
	  if(ret==0){
	    printf("\tCompile: OK, Run: ");
	    runCubbyhole(com[i], 0); 
	    fflush(stdout);
	    fflush(stderr);
	    if(i==0)
	      printf("OK\n");
	  } else {
	    printf("\tCompile: FAIL with exit code %i\n", ret);
	  }
	  destroyComp(com[i]);
	}
	destroyVM(veem);
	
	puts("Beginning error testing");
	comp_out=fopen(BIT_BUCKET,"w");
	
	VM *evm = createVM();
	compart *ecom=NULL;
	
	if(evm == NULL) 
	{
		puts("Error creating VM");
		return 1;
	}
	
	for(int i=0;err_files[i] != NULL;i++) {
		int ret;
		printf("File %s: ",err_files[i]);
		  
		ecom = createComp(evm);
		if(ecom  == NULL) 
		{
		  printf("Error creating compartment");
		  return 1;
		}
	  	ret = fileCompile(err_files[i], ecom);
		fflush(stdout);
		fflush(stderr);
	  	if(ret==0){
		  printf("\tFAIL\n");
		  return 2;
	  	} else {
		  printf("\tPASS\n");
	  	}
		fflush(stdout);
		fflush(stderr);
	  	destroyComp(ecom);
	  	ecom = NULL;
	}
	destroyVM(evm);
	fclose(comp_out);
	
	return 0;
}