Yhc/RTS/hbc

From HaskellWiki
< Yhc‎ | RTS
Revision as of 23:51, 15 January 2006 by NeilMitchell (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

FIXME: needs more explanation.

.hbc File

 struct HbcFile {
   Header          header;
   StringTable     strings;
   QualifId        moduleName;
   ObjectTable     objects;
 };

Header

 struct Header {
   Char           magic[4];        /* 'H' 'S' 'B' 'C' */
   UShort         majorVersion;
   UShort         minorVersion;
   UShort         zero;            /* 0 */
   UShort         numObjects;      
 };

StringTable

 struct StringTable {
   UShort         numStrings;
   String         strings[numStrings];
 };
 struct String {
   UShort         length;
   Char           data[length];
 };

ObjectTable

 struct ObjectTable {
   Object         objects[numObjects];
 };
 struct Object {
   QualifId      name;
   UShort        length;
   Char          data[length];
 };

The first byte of the 'data' section identifies the object type. Depending on the object type the rest of the data for and object has different structures.

Object types

 'F'            function object (FunObj)
 'C'            constructor object (ConObj)
 'P'            primitive object (PrimObj)
 'X'            external object (ExtObj)

FunObj

 struct FunObj {
   Char        type;                 /* 'F' */
   UByte       arity;
   UShort      stack;
   ConstTable  consts;
   UShort      codeLength;
   UByte       code[codeLength];
 };
 struct ConstTable {
   UShort     numConsts;
   Constant   consts[numConsts];
 };
 struct Constant {
   Char      type;
   Char      constData[??];
 };

The type of the constant identifies the size and type of the rest of the constant data.

Constant Types

 Type   Name      ConstData         Desc
 'A'    CAF       FullyQualifId     Reference to a CAF node
 'F'    FUN       FullyQualifId     Reference to a FInfo
 '0'    FUN0      FullyQualifId     Reference to a zero arity FInfo
 'C'    CON       FullyQualifId     Reference to a CInfo
 'Z'    ZCON      FullyQualifId     Reference to a zero arity constructor node
 'P'    PRIM      FullyQualifId     Reference to a primitive function (XInfo)
 'X'    EXT       FullyQualifId     Reference to an external function (XInfo)
 'i'    INT       Int               Int constant
 'l'    INTEGER   Integer           Integer constant
 'f'    FLOAT     Float             Float constant
 'd'    DOUBLE    Float             Double constant
 's'    STRING    String            String constant

ConObj

 struct ConObj {
   Char      type;          /* 'C' */
   UByte     size; 
   UByte     tag;        
 };

PrimObj

 struct PrimObj {
   Char           type;         /* 'P' */
   FullyQualifId  name;
 };

ExtObj

 struct ExtObj {
   Char          type;          /* 'X' */
   String        cName;         
   UShort        arity;
 };

FullyQualifId

 struct FullyQualifId {
   QualifId     module;
   QualifId     item;
 };

QualifId

 struct QualifId {
   UByte       length;
   UShort      stringIndexs[length];
 };

Integer

 struct Integer {
   SByte      length;
   UByte      data[abs(length)];
 };

If length < 0 then the whole Integer is negative.

Float

 struct Float {
   Integer   mant;
   Short     exp;
 };