SCI: Begun conversion of the MemObject union (used to implement poor man's fake inheritance) into a base class of all the various union members
svn-id: r40272
This commit is contained in:
parent
50c8821072
commit
79b0711cfd
3 changed files with 36 additions and 30 deletions
|
@ -445,12 +445,12 @@ static void sync_MemObjPtr(Common::Serializer &s, MemObject *&obj) {
|
||||||
if (s.isLoading()) {
|
if (s.isLoading()) {
|
||||||
//assert(!obj);
|
//assert(!obj);
|
||||||
obj = (MemObject *)sci_calloc(1, sizeof(MemObject));
|
obj = (MemObject *)sci_calloc(1, sizeof(MemObject));
|
||||||
obj->_type = type;
|
obj->data.tmp_dummy._type = type;
|
||||||
} else {
|
} else {
|
||||||
assert(obj);
|
assert(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
s.syncAsSint32LE(obj->_segmgrId);
|
s.syncAsSint32LE(obj->data.tmp_dummy._segmgrId);
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case MEM_OBJ_SCRIPT:
|
case MEM_OBJ_SCRIPT:
|
||||||
sync_Script(s, obj->data.script);
|
sync_Script(s, obj->data.script);
|
||||||
|
|
|
@ -367,8 +367,8 @@ MemObject *SegManager::memObjAllocate(SegmentId segid, int hash_id, memObjType t
|
||||||
memset(heap + oldhs, 0, sizeof(MemObject *) * (heap_size - oldhs));
|
memset(heap + oldhs, 0, sizeof(MemObject *) * (heap_size - oldhs));
|
||||||
}
|
}
|
||||||
|
|
||||||
mem->_segmgrId = hash_id;
|
mem->data.tmp_dummy._segmgrId = hash_id;
|
||||||
mem->_type = type;
|
mem->data.tmp_dummy._type = type;
|
||||||
|
|
||||||
// hook it to the heap
|
// hook it to the heap
|
||||||
heap[segid] = mem;
|
heap[segid] = mem;
|
||||||
|
@ -970,7 +970,7 @@ SystemStrings *SegManager::allocateSysStrings(SegmentId *segid) {
|
||||||
MemObject *memobj = allocNonscriptSegment(MEM_OBJ_SYS_STRINGS, segid);
|
MemObject *memobj = allocNonscriptSegment(MEM_OBJ_SYS_STRINGS, segid);
|
||||||
SystemStrings *retval = &(memobj->data.sys_strings);
|
SystemStrings *retval = &(memobj->data.sys_strings);
|
||||||
|
|
||||||
memset(retval, 0, sizeof(SystemString)*SYS_STRINGS_MAX);
|
memset(retval->strings, 0, sizeof(retval->strings));
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,28 @@
|
||||||
|
|
||||||
namespace Sci {
|
namespace Sci {
|
||||||
|
|
||||||
|
enum memObjType {
|
||||||
|
MEM_OBJ_INVALID = 0,
|
||||||
|
MEM_OBJ_SCRIPT = 1,
|
||||||
|
MEM_OBJ_CLONES = 2,
|
||||||
|
MEM_OBJ_LOCALS = 3,
|
||||||
|
MEM_OBJ_STACK = 4,
|
||||||
|
MEM_OBJ_SYS_STRINGS = 5,
|
||||||
|
MEM_OBJ_LISTS = 6,
|
||||||
|
MEM_OBJ_NODES = 7,
|
||||||
|
MEM_OBJ_HUNK = 8,
|
||||||
|
MEM_OBJ_DYNMEM = 9,
|
||||||
|
MEM_OBJ_STRING_FRAG = 10,
|
||||||
|
|
||||||
|
MEM_OBJ_MAX // For sanity checking
|
||||||
|
};
|
||||||
|
|
||||||
|
struct MemObjectNEW {
|
||||||
|
memObjType _type;
|
||||||
|
int _segmgrId; /**< Internal value used by the seg_manager's hash map */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
struct IntMapper;
|
struct IntMapper;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
@ -51,7 +73,7 @@ struct SystemString {
|
||||||
reg_t *value;
|
reg_t *value;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SystemStrings {
|
struct SystemStrings : public MemObjectNEW {
|
||||||
SystemString strings[SYS_STRINGS_MAX];
|
SystemString strings[SYS_STRINGS_MAX];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -149,7 +171,7 @@ struct CallsStruct {
|
||||||
int type; /**< Same as ExecStack.type */
|
int type; /**< Same as ExecStack.type */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LocalVariables {
|
struct LocalVariables : public MemObjectNEW {
|
||||||
int script_id; /**< Script ID this local variable block belongs to */
|
int script_id; /**< Script ID this local variable block belongs to */
|
||||||
reg_t *locals;
|
reg_t *locals;
|
||||||
int nr;
|
int nr;
|
||||||
|
@ -198,7 +220,7 @@ struct CodeBlock {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct Script {
|
struct Script : public MemObjectNEW {
|
||||||
int nr; /**< Script number */
|
int nr; /**< Script number */
|
||||||
byte* buf; /**< Static data buffer, or NULL if not used */
|
byte* buf; /**< Static data buffer, or NULL if not used */
|
||||||
size_t buf_size;
|
size_t buf_size;
|
||||||
|
@ -233,7 +255,7 @@ struct Script {
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Data stack */
|
/** Data stack */
|
||||||
struct dstack_t {
|
struct dstack_t : MemObjectNEW {
|
||||||
int nr; /**< Number of stack entries */
|
int nr; /**< Number of stack entries */
|
||||||
reg_t *entries;
|
reg_t *entries;
|
||||||
};
|
};
|
||||||
|
@ -262,7 +284,7 @@ struct Hunk {
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T, int INITIAL, int INCREMENT>
|
template<typename T, int INITIAL, int INCREMENT>
|
||||||
struct Table {
|
struct Table : public MemObjectNEW {
|
||||||
struct Entry : public T {
|
struct Entry : public T {
|
||||||
int next_free; /* Only used for free entries */
|
int next_free; /* Only used for free entries */
|
||||||
};
|
};
|
||||||
|
@ -324,31 +346,15 @@ void free_Hunk_entry(HunkTable *table, int index);
|
||||||
|
|
||||||
|
|
||||||
// Free-style memory
|
// Free-style memory
|
||||||
struct DynMem {
|
struct DynMem : public MemObjectNEW {
|
||||||
int size;
|
int size;
|
||||||
char *description;
|
char *description;
|
||||||
byte *buf;
|
byte *buf;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum memObjType {
|
|
||||||
MEM_OBJ_INVALID = 0,
|
|
||||||
MEM_OBJ_SCRIPT = 1,
|
|
||||||
MEM_OBJ_CLONES = 2,
|
|
||||||
MEM_OBJ_LOCALS = 3,
|
|
||||||
MEM_OBJ_STACK = 4,
|
|
||||||
MEM_OBJ_SYS_STRINGS = 5,
|
|
||||||
MEM_OBJ_LISTS = 6,
|
|
||||||
MEM_OBJ_NODES = 7,
|
|
||||||
MEM_OBJ_HUNK = 8,
|
|
||||||
MEM_OBJ_DYNMEM = 9,
|
|
||||||
MEM_OBJ_STRING_FRAG = 10,
|
|
||||||
MEM_OBJ_MAX = 11 // For sanity checking
|
|
||||||
};
|
|
||||||
|
|
||||||
struct MemObject {
|
struct MemObject {
|
||||||
memObjType _type;
|
|
||||||
int _segmgrId; /**< Internal value used by the seg_manager's hash map */
|
|
||||||
union {
|
union {
|
||||||
|
MemObjectNEW tmp_dummy;
|
||||||
Script script;
|
Script script;
|
||||||
CloneTable clones;
|
CloneTable clones;
|
||||||
LocalVariables locals;
|
LocalVariables locals;
|
||||||
|
@ -360,8 +366,8 @@ struct MemObject {
|
||||||
DynMem dynmem;
|
DynMem dynmem;
|
||||||
} data;
|
} data;
|
||||||
|
|
||||||
inline memObjType getType() const { return _type; }
|
inline memObjType getType() const { return data.tmp_dummy._type; }
|
||||||
inline int getSegMgrId() const { return _segmgrId; }
|
inline int getSegMgrId() const { return data.tmp_dummy._segmgrId; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue