Exemple #1
0
Assembly *Assembly::create(LSLuaState *vm, const utString& name)
{
    Assembly *a = new Assembly();

    a->vm   = vm;
    a->name = name;

    utHashTable<utHashedString, Assembly *> *lookup = NULL;

    UTsize idx = assemblies.find(vm);

    if (idx != UT_NPOS)
    {
        lookup = assemblies.at(idx);
    }
    else
    {
        lookup = new utHashTable<utHashedString, Assembly *>();
        assemblies.insert(vm, lookup);
    }

    utHashedString key = a->name;
    lookup->insert(key, a);

    vm->assemblies.insert(utHashedString(a->getName()), a);

    return a;
}
Exemple #2
0
Module *Assembly::getModule(const utString& name)
{
    UTsize idx = modules.find(utHashedString(name));

    if (idx == UT_NPOS)
    {
        return NULL;
    }

    return modules.at(idx);
}
Exemple #3
0
Type *BinReader::readType()
{
    int startPosition = bytes->getPosition();

    const char *stype       = readPoolString();
    const char *packageName = readPoolString();
    const char *name        = readPoolString();
    int        typeID       = bytes->readInt();
    const char *source      = readPoolString();
    int        linenumber   = bytes->readInt();

    utString fullname = packageName;

    fullname += ".";
    fullname += name;

    TypeIndex *tindex = *(types.get(utHashedString(fullname)));

    Type *type = tindex->type;

    type->setTypeID((LSTYPEID)typeID);
    type->packageName = packageName;
    type->fullName    = fullname;

    if (!strcmp(stype, "CLASS"))
    {
        type->attr.isClass = true;
    }
    else if (!strcmp(stype, "INTERFACE"))
    {
        type->attr.isInterface = true;
    }
    else if (!strcmp(stype, "STRUCT"))
    {
        type->attr.isStruct = true;
    }
    else if (!strcmp(stype, "DELEGATE"))
    {
        type->attr.isDelegate = true;
    }
    else if (!strcmp(stype, "ENUM"))
    {
        type->attr.isEnum = true;
    }
    else
    {
        lmAssert(0, "Unknown type: %s", stype);
    }

    readClass(type);

    return type;
}
void AssemblyReader::parseLinkedAssemblies(json_t *executableJSON)
{
    json_t *ref_array = json_object_get(executableJSON, "references");

    lmAssert(ref_array, "Error with executable assembly, missing references section");

    for (size_t j = 0; j < json_array_size(ref_array); j++)
    {
        json_t   *jref    = json_array_get(ref_array, j);
        utString name     = json_string_value(json_object_get(jref, "name"));
        json_t   *jbinary = json_object_get(jref, "binary");
        lmAssert(jbinary, "Error with linked assembly %s, missing binary section", name.c_str());
        utString binary = (const char *)utBase64::decode64(json_string_value(jbinary)).getData().ptr();
        linkedAssemblies.insert(utHashedString(name), binary);
    }
}
Exemple #5
0
void Assembly::registerModule(Module *module)
{
    module->setAssembly(this);
    modules.insert(utHashedString(module->getName()), module);
}
Exemple #6
0
void BinWriter::writeAssembly(json_t *json)
{
    // reserve 32 megs
    bytes.reserve(1024 * 1024 * 32);

    int itype = poolJString(json_object_get(json, "type"));

    const char *name = json_string_value(json_object_get(json, "name"));

    binWriters.insert(utHashedString(name), this);

    int iname       = poolString(name);
    int iversion    = poolJString(json_object_get(json, "version"));
    int iloomconfig = 0;

    bool executable = false;
    if (json_object_get(json, "executable") && json_is_true(json_object_get(json, "executable")))
    {
        executable = true;
    }

    iloomconfig = poolJString(json_object_get(json, "loomconfig"));

    bool jit = false;
    if (json_object_get(json, "jit") && json_is_true(json_object_get(json, "jit")))
    {
        jit = true;
    }

    bool debugbuild = false;
    if (json_object_get(json, "debugbuild") && json_is_true(json_object_get(json, "debugbuild")))
    {
        debugbuild = true;
    }

    // basic info
    bytes.writeInt(itype);
    bytes.writeInt(iname);
    bytes.writeInt(iversion);
    bytes.writeInt(iloomconfig);

    // write out flags
    bytes.writeBoolean(executable);
    bytes.writeBoolean(jit);
    bytes.writeBoolean(debugbuild);

    // recursively write references

    json_t *ref_array = json_object_get(json, "references");
    lmAssert(ref_array, "Error with executable assembly, missing references section");

    // write number of references
    bytes.writeInt((int)json_array_size(ref_array));

    for (size_t j = 0; j < json_array_size(ref_array); j++)
    {
        json_t     *jref    = json_array_get(ref_array, j);
        json_t     *jbinary = json_object_get(jref, "binary");
        const char *refname = json_string_value(json_object_get(jref, "name"));

        bytes.writeInt(poolString(refname));

        // already referenced
        if (binWriters.get(utHashedString(refname)))
        {
            continue;
        }

        if (executable)
        {
            lmAssert(jbinary, "Error with linked assembly %s, missing binary section", refname);
            utString  refjson  = (const char *)utBase64::decode64(json_string_value(jbinary)).getData().ptr();
            BinWriter *bwriter = new BinWriter;
            bwriter->writeAssembly(refjson.c_str(), refjson.length());
        }
    }

    writeModules(json);
}
Assembly *AssemblyReader::deserialize(LSLuaState *vm, const utString& sjson)
{
    json_error_t jerror;
    json_t       *json = json_loadb(sjson.c_str(), sjson.size(), 0, &jerror);

    lmAssert(json, "Error loading Assembly json: %s\n %s %i\n", jerror.source, jerror.text, jerror.line);

    utString type       = json_string_value(json_object_get(json, "type"));
    utString name       = json_string_value(json_object_get(json, "name"));
    utString version    = json_string_value(json_object_get(json, "version"));
    utString loomconfig = json_string_value(json_object_get(json, "loomconfig"));

    bool executable = false;
    if (json_object_get(json, "executable") && json_is_true(json_object_get(json, "executable")))
    {
        executable = true;
        parseLinkedAssemblies(json);
        printf("Loading executable assembly: %s.loom\n", name.c_str());
    }

    if (type != "ASSEMBLY")
    {
        LSError("Assembly %s type string not found", name.c_str());
    }

#ifdef LOOM_ENABLE_JIT
    if (!json_is_true(json_object_get(json, "jit")))
    {
        LSError("Assembly %s.loom has interpreted bytecode, JIT required", name.c_str());
    }
#else
    if (json_is_true(json_object_get(json, "jit")))
    {
        LSError("Assembly %s.loom has JIT bytecode, interpreted required", name.c_str());
    }
#endif

    Assembly *assembly = Assembly::create(vm, name);

    assembly->setLoomConfig(loomconfig);

    if (json_is_false(json_object_get(json, "debugbuild")))
    {
        assembly->setDebugBuild(false);
    }
    else
    {
        assembly->setDebugBuild(true);
    }

    // load references
    json_t *refArray = json_object_get(json, "references");

    for (UTsize i = 0; i < json_array_size(refArray); i++)
    {
        Assembly *rasm = NULL;

        json_t *ref = json_array_get(refArray, i);

        utString refname = json_string_value(json_object_get(ref, "name"));

        assembly->addReference(refname);

        // if we've already loaded this assembly continue
        if (vm->getAssembly(refname))
        {
            continue;
        }

        utString *sjson = linkedAssemblies.get(utHashedString(refname));

        if (sjson)
        {
            rasm = vm->loadAssemblyJSON(*sjson);
        }
        else
        {
            utString fileJSON;
            if (loadLibraryAssemblyJSON(refname, fileJSON))
            {
                rasm = vm->loadAssemblyJSON(fileJSON);
            }
            else
            {
                lmAssert(0, "Unable to load assembly '%s' as either a library or an executable!'", refname.c_str());
            }
        }
    }

    // modules
    json_t *moduleArray = json_object_get(json, "modules");

    // first pass is to declare module types
    for (UTsize i = 0; i < json_array_size(moduleArray); i++)
    {
        json_t *jmodule = json_array_get(moduleArray, i);

        ModuleReader::declareTypes(assembly, jmodule);
    }

    // next pass is to deserialize fully
    for (UTsize i = 0; i < json_array_size(moduleArray); i++)
    {
        json_t *jmodule = json_array_get(moduleArray, i);

        ModuleReader::deserialize(assembly, jmodule);
    }

    if (executable)
    {
        linkedAssemblies.clear();
    }

    return assembly;
}
Exemple #8
0
void akDemo::init(void)
{

	m_camera->m_transform.identity();
	m_camera->m_transform.loc = akVector3(7.4811316,-6.5076399,5.3436651);
	m_camera->m_transform.rot = akQuat(0.48170695,0.21292172,0.33425143,0.78159994);
	m_camera->m_fov = 49.134342;
	m_camera->m_clipStart = 0.1;
	m_camera->m_clipEnd = 100;


	akMesh* mesh = new akMesh();
	m_canUseVbo = true;
	bool hasNormals= false;
	bool hasColors=false;
	int uvlayers=0;
	utArray<float> uvs;

	akSubMesh* subMesh = new akSubMesh(akSubMesh::ME_TRIANGLES,hasNormals,hasColors,uvlayers);
	akVector3 xyz[NUM_VERTS]={
		akVector3(1.000000,1.000000,-1.000000),
 akVector3(1.000000,-1.000000,-1.000000),
 akVector3(-1.000000,-1.000000,-1.000000),
 akVector3(-1.000000,1.000000,-1.000000),
 akVector3(1.000000,1.000000,-1.000000),
 akVector3(1.000000,0.999999,1.000000),
 akVector3(1.000000,-1.000000,-1.000000),
 akVector3(0.999999,-1.000001,1.000000),
 akVector3(1.000000,-1.000000,-1.000000),
 akVector3(0.999999,-1.000001,1.000000),
 akVector3(-1.000000,-1.000000,-1.000000),
 akVector3(-1.000000,-1.000000,1.000000),
 akVector3(-1.000000,-1.000000,-1.000000),
 akVector3(-1.000000,-1.000000,1.000000),
 akVector3(-1.000000,1.000000,1.000000),
 akVector3(-1.000000,1.000000,-1.000000),
 akVector3(1.000000,0.999999,1.000000),
 akVector3(1.000000,1.000000,-1.000000),
 akVector3(-1.000000,1.000000,1.000000),
 akVector3(-1.000000,1.000000,-1.000000),
 akVector3(-1.000000,1.000000,1.000000),
 akVector3(-1.000000,1.000000,3.000000),
 akVector3(-1.000000,-1.000000,3.000000),
 akVector3(-1.000000,-1.000000,1.000000),
 akVector3(-1.000000,-1.000000,3.000000),
 akVector3(0.999999,-1.000001,3.000000),
 akVector3(-1.000000,1.000000,1.000000),
 akVector3(1.000000,0.999999,3.000000),
 akVector3(-1.000000,1.000000,3.000000),
 akVector3(0.999999,-1.000001,1.000000),
 akVector3(0.999999,-1.000001,3.000000),
 akVector3(1.000000,0.999999,3.000000),
 akVector3(0.999999,-1.000001,3.000000),
 akVector3(1.000000,0.999999,3.000000),
 akVector3(0.999999,-1.000001,5.000000),
 akVector3(1.000000,0.999999,5.000000),
 akVector3(1.000000,0.999999,3.000000),
 akVector3(-1.000000,1.000000,3.000000),
 akVector3(1.000000,0.999999,5.000000),
 akVector3(-1.000000,1.000000,5.000000),
 akVector3(-1.000000,-1.000000,3.000000),
 akVector3(0.999999,-1.000001,3.000000),
 akVector3(-1.000000,-1.000000,5.000000),
 akVector3(0.999999,-1.000001,5.000000),
 akVector3(-1.000000,1.000000,3.000000),
 akVector3(-1.000000,-1.000000,3.000000),
 akVector3(-1.000000,1.000000,5.000000),
 akVector3(-1.000000,-1.000000,5.000000),
 akVector3(1.000000,0.999999,5.000000),
 akVector3(-1.000000,1.000000,5.000000)	};


	int indices[NUM_TRIANGLES*3]={0,1,2,2,3,0,4,5,6,6,5,7,8,9,10,10,9,11,12,13,14,14,15,12,16,17,18,18,17,19,20,13
		,21,21,13,22,23,9,24,24,9,25,16,26,27,27,26,28,29,5,30,30,5,31,32,33,34,34,33,35
		,36,37,38,38,37,39,40,41,42,42,41,43,44,45,46,46,45,47,48,49,34,34,49,47
	};

	akVector3 normal(0,1,0);//s[NUM_VERTS];
	unsigned int color = 0;

	int numIndices = sizeof(indices)/sizeof(int);
	for (int v=0;v<NUM_VERTS;v++)
	{
		subMesh->addVertex(xyz[v],normal,color,uvs);
	}

	for (int i=0;i<NUM_TRIANGLES*3;i++)
	{
		subMesh->addIndex(indices[i]);
	}


	mesh->addSubMesh(subMesh);
	
	int numTris = mesh->getTriangleCount();

	
	utHashedString meshName("myMesh");
	addMesh(meshName, mesh);
	

	akEntity* entity = new akEntity();
	akTransformState trans = akTransformState::identity();
	entity->setTransformState(trans);
	entity->setMesh(mesh);
	this->addEntity(utHashedString("MyEntity"),entity);

	utHashedString jointNames[NUM_JOINTS]={utHashedString("Bone"),utHashedString("Bone.001"),utHashedString("Bone.002")};
	
	akSkeleton* skeleton = new akSkeleton();
	int parent = skeleton->addJoint(jointNames[0],AK_JOINT_NO_PARENT);
	parent = skeleton->addJoint(jointNames[1],parent);
	parent = skeleton->addJoint(jointNames[2],parent);

	akSkeletonPose* bindPose = new akSkeletonPose(skeleton, akSkeletonPose::SP_MODEL_SPACE);

	akTransformState jointPoses[NUM_JOINTS] = {
		akTransformState(akVector3(0,0,0),akQuat(0.70710671, 0.00000000,0.00000000,0.70710677)),
		akTransformState(akVector3(0,0,1),akQuat(0.0,0.70710671,0.70710677,0.0)),
		akTransformState(akVector3(0,0,2),akQuat(0.0,0.70710671,0.70710677,0.f))};

	for (int i=0;i<NUM_JOINTS;i++)
	{
		*bindPose->getJointPose(i) = jointPoses[i];
	}

	skeleton->setBindingPose(bindPose);
	
	addSkeleton(utHashedString("MySkeleton"),skeleton);

	entity->setSkeleton(skeleton);

	for(int i=0;i<NUM_JOINTS; i++)
	{
		akVertexGroup* vg = new akVertexGroup();
		vg->setName(jointNames[i].str());
		mesh->getSubMesh(0)->addVertexGroup(vg);
	}


	int indices0[40]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,36,37,40,41,44,45};
	int indices1[40]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,36,37,40,41,44,45};
	int indices2[38]={5,7,9,11,13,14,16,18,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49};

	float weights0[NUM_WEIGHTS0]={
		0.895997,0.895092,0.895997,0.895092,0.895997,0.496942,0.895092,0.496901,0.895092
		,0.496901,0.895997,0.496942,0.895997,0.496942,0.496901,0.895092,0.496942,0.895997,
		0.496901,0.895092,0.496901,0.051515,0.051474,0.496942,0.051474,0.051515,0.496901,
		0.051474,0.051515,0.496901,0.051515,0.051474,0.051515,0.051474,0.051474,0.051515,
		0.051474,0.051515,0.051515,0.051474};

	float weights1[NUM_WEIGHTS1]={0.093034,0.093843,0.093034,0.093843,0.093034,0.449999,0.093843,0.450039,0.093843,
			0.450039,0.093034,0.449999,0.093034,0.449999,0.450039,0.093843,0.449999,0.093034,
			0.450039,0.093843,0.450039,0.043311,0.043225,0.449999,0.043225,0.043311,0.450039,
			0.043225,0.043311,0.450039,0.043311,0.043225,0.043311,0.043225,0.043225,0.043311,
			0.043225,0.043311,0.043311,0.043225};

	float weights2[NUM_WEIGHTS2]={0.053059,0.053060,0.053060,0.053059,0.053059,0.053060,0.053059,0.053060,0.053060,
		0.901830,0.901914,0.053059,0.901914,0.901830,0.053060,0.901914,0.901830,0.053060,
		0.901830,0.901914,0.901830,0.901914,0.964282,0.965462,0.901914,0.901830,0.965462,
		0.964282,0.901914,0.901830,0.965462,0.964282,0.901830,0.901914,0.964282,0.965462,
		0.965462,0.964282};

	for (int i=0;i<NUM_WEIGHTS0;i++)
	{
		mesh->getSubMesh(0)->getVertexGroup(0)->add(indices0[i],weights0[i]);
	}
	for (int i=0;i<NUM_WEIGHTS1;i++)
	{
		mesh->getSubMesh(0)->getVertexGroup(1)->add(indices1[i],weights1[i]);
	}
	for (int i=0;i<NUM_WEIGHTS2;i++)
	{
		mesh->getSubMesh(0)->getVertexGroup(2)->add(indices2[i],weights2[i]);
	}

	mesh->generateBoneWeightsFromVertexGroups(skeleton, true);


	akAnimationClip* act = new akAnimationClip();
	

	
	{
		akAnimationChannel* chan = new akAnimationChannel(akAnimationChannel::AC_BONE, jointNames[0]);
			akAnimationCurve* spline = 0;
			spline = new akAnimationCurve(1, akAnimationCurve::AC_CODE_ROT_QUAT_W, akAnimationCurve::BEZ_CUBIC);
			spline->setSample(0,0.00000000,1.0000000,-0.041666668,1.0000000,0.041666668	,1.0000000);
			chan->addCurve(spline);

			spline = new akAnimationCurve(1, akAnimationCurve::AC_CODE_ROT_QUAT_X, akAnimationCurve::BEZ_CUBIC);
			spline->setSample(0,0.00000000,0.00000000,-0.041666668,0.00000000,0.041666668,0.00000000);
			chan->addCurve(spline);

			spline = new akAnimationCurve(1, akAnimationCurve::AC_CODE_ROT_QUAT_Y, akAnimationCurve::BEZ_CUBIC);
			spline->setSample(0,0.00000000,0.00000000,-0.041666668,0.00000000,0.041666668,0.00000000);
			chan->addCurve(spline);

			spline = new akAnimationCurve(1, akAnimationCurve::AC_CODE_ROT_QUAT_Z, akAnimationCurve::BEZ_CUBIC);
			spline->setSample(0,0.00000000,0.00000000,-0.041666668,0.00000000,0.041666668,0.00000000);
			chan->addCurve(spline);
		
		act->addChannel(chan);
	}

	{
		akAnimationChannel* chan = new akAnimationChannel(akAnimationChannel::AC_BONE, jointNames[1]);
			akAnimationCurve* spline = 0;
			spline = new akAnimationCurve(2, akAnimationCurve::AC_CODE_ROT_QUAT_W, akAnimationCurve::BEZ_CUBIC);
			spline->setSample(0,0.00000000,1.0000000,-0.89469218,1.0000000,0.89469218,1.0000000);
			spline->setSample(1,2.2916667,0.92387956,1.3969746,0.92387956,3.1863589,0.92387956);
			chan->addCurve(spline);
			spline = new akAnimationCurve(2, akAnimationCurve::AC_CODE_ROT_QUAT_X, akAnimationCurve::BEZ_CUBIC);
			spline->setSample(0,0.00000000	,0.00000000	,-0.89467138	,0.00000000	,0.89467138	,0.00000000	);
			spline->setSample(1	,2.2916667,0.38268343,1.3969953,0.38268343	,3.1863382	,0.38268343);
			chan->addCurve(spline);
			spline = new akAnimationCurve(2, akAnimationCurve::AC_CODE_ROT_QUAT_Y, akAnimationCurve::BEZ_CUBIC);
			spline->setSample(0,0.00000000,0.00000000,-0.89469308,0.00000000,0.89469308	,0.00000000	);
			spline->setSample(1,2.2916667	,-3.8454296e-015	,1.3969736	,-3.8454296e-015	,3.1863599	,-3.8454296e-015	);
			chan->addCurve(spline);

			spline = new akAnimationCurve(2, akAnimationCurve::AC_CODE_ROT_QUAT_Z, akAnimationCurve::BEZ_CUBIC);
			spline->setSample(0,0.00000000	,0.00000000	,-0.89469308	,0.00000000	,0.89469308	,0.00000000);
			spline->setSample(1	,2.2916667	,5.7783591e-008	,1.3969736	,5.7783591e-008	,3.1863599	,5.7783591e-008	);
			chan->addCurve(spline);
		act->addChannel(chan);
	}

	{
		akAnimationChannel* chan = new akAnimationChannel(akAnimationChannel::AC_BONE, jointNames[2]);
			akAnimationCurve* spline = 0;

			spline = new akAnimationCurve(2, akAnimationCurve::AC_CODE_ROT_QUAT_W, akAnimationCurve::BEZ_CUBIC);
			spline->setSample(0	,0.00000000	,1.0000000	,-0.40667677	,1.0000000	,0.40667677	,1.0000000);
			spline->setSample(1,1.0416667	,0.92387956	,0.63498992	,0.92387956	,1.4483435	,0.92387956	);
			chan->addCurve(spline);

			spline = new akAnimationCurve(2, akAnimationCurve::AC_CODE_ROT_QUAT_X, akAnimationCurve::BEZ_CUBIC);
			spline->setSample(0,0.00000000	,0.00000000	,-0.40663099	,0.00000000	,0.40663099	,0.00000000	);
			spline->setSample(1,1.0416667	,0.38268343	,0.63503569	,0.38268343	,1.4482977	,0.38268343	);
			chan->addCurve(spline);
			
			spline = new akAnimationCurve(2, akAnimationCurve::AC_CODE_ROT_QUAT_Y, akAnimationCurve::BEZ_CUBIC);
			spline->setSample(0	,0.00000000	,0.00000000	,-0.40667865	,0.00000000	,0.40667865	,0.00000000	);
			spline->setSample(	1,1.0416667	,-3.8454296e-015	,0.63498801	,-3.8454296e-015	,1.4483454	,-3.8454296e-015);
			chan->addCurve(spline);
			
			spline = new akAnimationCurve(2, akAnimationCurve::AC_CODE_ROT_QUAT_Z, akAnimationCurve::BEZ_CUBIC);
			spline->setSample(	0,0.00000000	,0.00000000	,-0.40667865	,0.00000000	,0.40667865	,0.00000000	);
			spline->setSample(	1,1.0416667	,3.3455247e-008	,0.63498801	,3.3455247e-008	,1.4483454	,3.3455247e-008	);
			chan->addCurve(spline);

		act->addChannel(chan);
	}
	
	float animfps = 24.f;
	float actionStart = 5.f;
	float actionEnd = 60.f;

	act->setLength( (actionEnd-actionStart )/animfps);
	addAnimation(utHashedString("MyActionClip"), act);

	akAnimationPlayer* play = entity->getAnimationPlayers()->addNewAnimationPlayer(act);

}
Exemple #9
0
Assembly *BinReader::loadExecutable(LSLuaState *_vm, utByteArray *byteArray)
{
    sBytes = byteArray;
    vm     = _vm;

    // load up the string pool
    readStringPool();

    // read the type table

    int numTypes = sBytes->readInt();

    for (UTsize i = 0; i < (UTsize)numTypes; i++)
    {
        TypeIndex *tindex = lmNew(NULL) TypeIndex;
        tindex->type     = NULL;
        tindex->refIdx   = sBytes->readInt();
        tindex->fullName = readPoolString();

        // within the ref
        tindex->position = sBytes->readInt();
        tindex->length   = sBytes->readInt();
        types.insert(utHashedString(tindex->fullName), tindex);
    }

    // load up reference assemblies
    // write out the number of references
    int numRefs = sBytes->readInt();

    for (int i = 0; i < numRefs; i++)
    {
        Reference *ref = lmNew(NULL) Reference;
        ref->name     = readPoolString();

        lmAssert(ref->name[0] != 0, "Assembly reference name is empty, try recompiling the .loom executable");

        ref->length   = sBytes->readInt();
        ref->position = sBytes->readInt();
        ref->loaded   = false;
        ref->assembly = NULL;
        
        references.insert(utHashedString(ref->name), ref);

        // offset the types to global position
        for (UTsize j = 0; j < types.size(); j++)
        {
            TypeIndex *tindex = types.at(j);

            if (tindex->refIdx == (int)i)
            {
                tindex->position += ref->position;
            }
        }
    }

    Assembly *assembly = NULL;

    // declare types
    for (UTsize i = 0; i < types.size(); i++)
    {
        TypeIndex *tindex = types.at(i);
        tindex->type = lmNew(NULL) Type();
    }

    for (UTsize i = 0; i < references.size(); i++)
    {
        Reference *ref = references.at(i);
        if (ref->loaded)
        {
            continue;
        }

        sBytes->setPosition(ref->position);
        BinReader reader;
        Assembly  *rassembly = reader.readAssembly(vm, sBytes);
        ref->assembly = rassembly;
        if (!assembly)
        {
            assembly = rassembly;
        }
    }

    // cleanup
    for (UTsize i = 0; i < references.size(); i++)
    {
        Reference *ref = references.at(i);
        if (!ref->assembly)
            continue;
        ref->assembly->freeByteCode();
    }
    
    sBytes = NULL;
    
	if (stringBuffer)
    {
        lmFree(NULL, (void*)stringBuffer);
		stringBuffer = NULL;
	}
    
	stringPool.clear();
    references.clear();
    types.clear();
    
	vm = NULL;

    return assembly;
}
Exemple #10
0
Assembly *BinReader::readAssembly(LSLuaState *_vm, utByteArray *_bytes)
{
    vm->beginAssemblyLoad();

    bytes = _bytes;

    const char *type       = readPoolString();
    const char *name       = readPoolString();
    const char *version    = readPoolString();
    const char *loomconfig = readPoolString();

    // write out flags
    bool executable = bytes->readBoolean();
    bool jit        = bytes->readBoolean();
    bool debugbuild = bytes->readBoolean();

#ifdef LOOM_ENABLE_JIT
    if (!jit)
    {
        LSError("Assembly %s.loom has interpreted bytecode, JIT required", name);
    }
#else
    if (jit)
    {
        LSError("Assembly %s.loom has JIT bytecode, interpreted required", name);
    }
#endif


    if (!executable)
    {
        Reference *aref = *(references.get(utHashedString(name)));
        aref->loaded = true;
    }

    // number of references
    utArray<Reference *> assrefs;

    int numrefs = bytes->readInt();
    for (int i = 0; i < numrefs; i++)
    {
        const char *refname = readPoolString();

        Reference *ref = *(references.get(utHashedString(refname)));

        assrefs.push_back(ref);

        if (ref->loaded)
        {
            continue;
        }

        int position = bytes->getPosition();
        bytes->setPosition(ref->position);
        BinReader refReader;
        refReader.readAssembly(_vm, bytes);
        bytes->setPosition(position);
    }

    assembly = Assembly::create(vm, name);

    for (UTsize i = 0; i < assrefs.size(); i++)
    {
        assembly->addReference(assrefs.at(i)->name);
    }

    if (loomconfig && loomconfig[0])
    {
        assembly->setLoomConfig(loomconfig);
    }

    assembly->setDebugBuild(debugbuild);

    readModules();

    utArray<Type *> asstypes;
    assembly->getTypes(asstypes);
    vm->cacheAssemblyTypes(assembly, asstypes);
    vm->finalizeAssemblyLoad(assembly, asstypes);

    vm->endAssemblyLoad();


    return assembly;
}