📄 type.h
字号:
#ifndef __TYPE_H_
#define __TYPE_H_
#include "config.h"
#include "corlist.h"
#include "hashtable.h"
#include "filelist.h"
union variant
{
S8 s8;
U8 u8;
S16 s16;
U16 u16;
S32 s32;
U32 u32;
F32 f32;
};
enum ValueType
{
Void = 0x00,
Int8 = 0x01,
UInt8 = 0x02,
Int16 = 0x03,
UInt16 = 0x04,
Int32 = 0x05,
UInt32 = 0x06,
Int64 = 0x07,
UInt64 = 0x08,
Float32 = 0x09,
Float64 = 0x0A,
};
struct FieldDesc
{
public:
FieldDesc();
U32 _name;
U8 _size;
ValueType _type;
};
struct MethodDesc
{
public:
MethodDesc();
U32 _name;
ValueType _retType;
U32 _maxStack;
U32 _addr;
List<int> _params;
bool _isEntry;
};
struct MethodBucket
{
MethodBucket()
:_index(-1)
{
}
MethodBucket(MethodDesc& desc)
:_index(-1), _params(desc._params), _name(desc._name)
{
}
bool operator >(MethodBucket& mb)
{
return _name > mb._name;
}
bool operator == (MethodBucket& mb)
{
return _name == mb._name && _params == mb._params;
}
bool operator <(MethodBucket& mb)
{
return !operator >(mb);
}
U32 _name;
List<int> _params;
int _index;
};
struct MapBucket
{
MapBucket()
:_index(-1)
{
}
MapBucket(std::string str)
:_str(str), _index(-1)
{
}
operator >(const MapBucket& b)const
{
if (_str > b._str)
{
return true;
}
return false;
}
operator <(const MapBucket& b)const
{
return !operator >(b);
}
operator ==(const MapBucket& b)const
{
if (_str == b._str)
{
return true;
}
return false;
}
std::string _str;
int _index;
};
int Key(const MapBucket& b);
int Key(const MethodBucket& b);
struct MetaDataDesc
{
public:
MetaDataDesc();
void AddMethod(MethodDesc& method);
void Store(FILE* file);
List<FieldDesc> _fields;
List<MethodDesc> _methods;
HashTable<MapBucket> _fieldIndexer;
HashTable<MethodBucket> _methodIndexer;
};
struct Instr
{
Instr() :opcode(0), arg(0), hasArg(false)
{}
U16 opcode;
S64 arg;
bool hasArg;
};
class StringPool
{
public:
StringPool();
int Add(const char* str);
void Store(FILE* fp);
int Size() { return _curPos; }
char _pool[65535];
private:
int _curPos;
HashTable<MapBucket> _indexer;
};
struct FileHeader
{
FileHeader()
:_nMethods(0), _nFields(0), _cbinstr(0), _cbStrPool(0), _entry(-1)
{}
void Store(FILE* fp)
{
fwrite(this, sizeof(FileHeader), 1, fp);
}
int _nMethods;
int _nFields;
long _cbinstr;
long _cbStrPool;
int _entry;
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -