misc/liblua/ldump.c
changeset 10017 de822cd3df3a
parent 2812 0a24853de796
equal deleted inserted replaced
10015:4feced261c68 10017:de822cd3df3a
    21  void* data;
    21  void* data;
    22  int strip;
    22  int strip;
    23  int status;
    23  int status;
    24 } DumpState;
    24 } DumpState;
    25 
    25 
    26 #define DumpMem(b,n,size,D)	DumpBlock(b,(n)*(size),D)
    26 #define DumpMem(b,n,size,D) DumpBlock(b,(n)*(size),D)
    27 #define DumpVar(x,D)	 	DumpMem(&x,1,sizeof(x),D)
    27 #define DumpVar(x,D)        DumpMem(&x,1,sizeof(x),D)
    28 
    28 
    29 static void DumpBlock(const void* b, size_t size, DumpState* D)
    29 static void DumpBlock(const void* b, size_t size, DumpState* D)
    30 {
    30 {
    31  if (D->status==0)
    31  if (D->status==0)
    32  {
    32  {
    65   size_t size=0;
    65   size_t size=0;
    66   DumpVar(size,D);
    66   DumpVar(size,D);
    67  }
    67  }
    68  else
    68  else
    69  {
    69  {
    70   size_t size=s->tsv.len+1;		/* include trailing '\0' */
    70   size_t size=s->tsv.len+1;     /* include trailing '\0' */
    71   DumpVar(size,D);
    71   DumpVar(size,D);
    72   DumpBlock(getstr(s),size,D);
    72   DumpBlock(getstr(s),size,D);
    73  }
    73  }
    74 }
    74 }
    75 
    75 
    76 #define DumpCode(f,D)	 DumpVector(f->code,f->sizecode,sizeof(Instruction),D)
    76 #define DumpCode(f,D)    DumpVector(f->code,f->sizecode,sizeof(Instruction),D)
    77 
    77 
    78 static void DumpFunction(const Proto* f, const TString* p, DumpState* D);
    78 static void DumpFunction(const Proto* f, const TString* p, DumpState* D);
    79 
    79 
    80 static void DumpConstants(const Proto* f, DumpState* D)
    80 static void DumpConstants(const Proto* f, DumpState* D)
    81 {
    81 {
    86   const TValue* o=&f->k[i];
    86   const TValue* o=&f->k[i];
    87   DumpChar(ttype(o),D);
    87   DumpChar(ttype(o),D);
    88   switch (ttype(o))
    88   switch (ttype(o))
    89   {
    89   {
    90    case LUA_TNIL:
    90    case LUA_TNIL:
    91 	break;
    91     break;
    92    case LUA_TBOOLEAN:
    92    case LUA_TBOOLEAN:
    93 	DumpChar(bvalue(o),D);
    93     DumpChar(bvalue(o),D);
    94 	break;
    94     break;
    95    case LUA_TNUMBER:
    95    case LUA_TNUMBER:
    96 	DumpNumber(nvalue(o),D);
    96     DumpNumber(nvalue(o),D);
    97 	break;
    97     break;
    98    case LUA_TSTRING:
    98    case LUA_TSTRING:
    99 	DumpString(rawtsvalue(o),D);
    99     DumpString(rawtsvalue(o),D);
   100 	break;
   100     break;
   101    default:
   101    default:
   102 	lua_assert(0);			/* cannot happen */
   102     lua_assert(0);          /* cannot happen */
   103 	break;
   103     break;
   104   }
   104   }
   105  }
   105  }
   106  n=f->sizep;
   106  n=f->sizep;
   107  DumpInt(n,D);
   107  DumpInt(n,D);
   108  for (i=0; i<n; i++) DumpFunction(f->p[i],f->source,D);
   108  for (i=0; i<n; i++) DumpFunction(f->p[i],f->source,D);