Main Page | Class List | Directories | File List | Class Members | File Members

encode.c File Reference

#include "global.h"
#include "stralloc.h"
#include "pike_macros.h"
#include "object.h"
#include "constants.h"
#include "interpret.h"
#include "svalue.h"
#include "mapping.h"
#include "array.h"
#include "multiset.h"
#include "lex.h"
#include "dynamic_buffer.h"
#include "pike_error.h"
#include "operators.h"
#include "builtin_functions.h"
#include "module_support.h"
#include "fsort.h"
#include "threads.h"
#include "stuff.h"
#include "version.h"
#include "bignum.h"
#include "pikecode.h"
#include "pike_types.h"
#include "opcodes.h"
#include "peep.h"
#include <math.h>
#include "program_areas.h"

Classes

struct  encode_data
struct  unfinished_prog_link
struct  unfinished_obj_link
struct  decode_data

Defines

#define EDB(N, X)   do { debug_malloc_touch(data); } while (0)
#define TAG_ARRAY   0
#define TAG_MAPPING   1
#define TAG_MULTISET   2
#define TAG_OBJECT   3
#define TAG_FUNCTION   4
#define TAG_PROGRAM   5
#define TAG_STRING   6
#define TAG_FLOAT   7
#define TAG_INT   8
#define TAG_TYPE   9
#define TAG_DELAYED   14
#define TAG_AGAIN   15
#define TAG_MASK   15
#define TAG_NEG   16
#define TAG_SMALL   32
#define SIZE_SHIFT   6
#define MAX_SMALL   (1<<(8-SIZE_SHIFT))
#define COUNTER_START   (-MAX_SMALL)
#define ID_ENTRY_TYPE_CONSTANT   -4
#define ID_ENTRY_EFUN_CONSTANT   -3
#define ID_ENTRY_RAW   -2
#define ID_ENTRY_EOT   -1
#define ID_ENTRY_VARIABLE   0
#define ID_ENTRY_FUNCTION   1
#define ID_ENTRY_CONSTANT   2
#define ID_ENTRY_INHERIT   3
#define CONVERT_ENTRY_ID(ID)   (-((ID) - COUNTER_START) - (-COUNTER_START + 1))
#define addstr(s, l)   low_my_binary_strcat((s), (l), &(data->buf))
#define addchar(t)   low_my_putchar((char)(t), &(data->buf))
#define ENCODE_DATA(S)
#define adddata(S)
#define adddata3(S)
#define adddata2(s, l)   addstr((char *)(s),(l) * sizeof((s)[0]));
#define Pike_FP_SNAN   -4
#define Pike_FP_QNAN   -3
#define Pike_FP_NINF   -2
#define Pike_FP_PINF   -1
#define Pike_FP_ZERO   0
#define Pike_FP_NZERO   1
#define Pike_FP_PZERO   0
#define Pike_FP_UNKNOWN   -4711
#define FOO(NUMTYPE, TYPE, ARGTYPE, NAME)   code_number( p->PIKE_CONCAT(num_,NAME), data);
#define GETC()   my_extract_char(data)
#define DECODE(Z)
#define decode_entry(X, Y, Z)
#define getdata2(S, L)
#define BITFLIP(S)
#define get_string_data(STR, LEN, data)
#define getdata(X)
#define getdata3(X)
#define decode_number(X, data)
#define SETUP_DECODE_MEMOBJ(TYPE, U, VAR, ALLOCATE, SCOUR)
#define decode_type(X, data)
#define SIGNED_CHAR(X)   X
#define EMIT_BYTECODE2(STR)
#define EMIT_BYTECODE(STR, X)
#define SIGNED_CHAR(X)   0
#define EMIT_BYTECODE2(X)
#define FOO(NUMTYPE, TYPE, ARGTYPE, NAME)   decode_number( p->PIKE_CONCAT(num_,NAME), data);
#define FOO(NUMTYPE, TYPE, ARGTYPE, NAME)
#define FOO(NUMTYPE, TYPE, ARGTYPE, NAME)
#define FOO(NUMTYPE, Y, ARGTYPE, NAME)   NUMTYPE PIKE_CONCAT(local_num_, NAME) = 0;
#define FOO(NUMTYPE, TYPE, ARGTYPE, NAME)   decode_number(PIKE_CONCAT(local_num_, NAME), data);
#define FOO(NUMTYPE, TYPE, ARGTYPE, NAME)

Functions

void f_encode_value (INT32 args)
void f_encode_value_canonic (INT32 args)
void f_decode_value (INT32 args)

Define Documentation

#define addchar  )     low_my_putchar((char)(t), &(data->buf))
 

#define adddata  ) 
 

Value:

do {                                    \
  if((S)->size_shift)                                   \
  {                                                     \
    int q;                                              \
    code_entry(TAG_STRING,-1, data);                    \
    code_entry((S)->size_shift, (S)->len, data);        \
    ENCODE_DATA(S);                                     \
  }else{                                                \
    code_entry(TAG_STRING, (S)->len, data);             \
    addstr((char *)((S)->str),(S)->len);                \
  }                                                     \
}while(0)

#define adddata2 s,
 )     addstr((char *)(s),(l) * sizeof((s)[0]));
 

#define adddata3  ) 
 

Value:

do {                    \
  if(S) {                                       \
    adddata(S);                                 \
  } else {                                      \
    code_entry(TAG_INT, 0, data);                       \
  }                                             \
}while(0)

#define addstr s,
 )     low_my_binary_strcat((s), (l), &(data->buf))
 

#define BITFLIP  ) 
 

Value:

switch(what)                                                    \
   {                                                            \
     case 1: for(e=0;e<num;e++) STR1(S)[e]=ntohs(STR1(S)[e]); break;    \
     case 2: for(e=0;e<num;e++) STR2(S)[e]=ntohl(STR2(S)[e]); break;    \
   }

#define CONVERT_ENTRY_ID ID   )     (-((ID) - COUNTER_START) - (-COUNTER_START + 1))
 

#define COUNTER_START   (-MAX_SMALL)
 

#define DECODE  ) 
 

#define decode_entry X,
Y,
 ) 
 

Value:

do {                                                            \
    INT32 what, e, num, numh;                                   \
    DECODE("decode_entry");                                     \
    if((what & TAG_MASK) != (X))                                \
      Pike_error("Failed to decode, wrong bits (%d).\n", what & TAG_MASK); \
    (Y)=num;                                                    \
  } while(0);

#define decode_number X,
data   ) 
 

Value:

do {    \
   INT32 what, e, num, numh;            \
   DECODE("decode_number");                     \
   X=(what & TAG_MASK) | (num<<4);              \
   EDB(5, fprintf(stderr, "%*s  ==>%ld\n",      \
                  data->depth, "", (long) X));  \
  }while(0)                                     \

#define decode_type X,
data   ) 
 

Value:

do {            \
  type_stack_mark();                            \
  low_decode_type(data);                        \
  (X)=pop_unfinished_type();                    \
} while(0)

#define EDB N,
 )     do { debug_malloc_touch(data); } while (0)
 

#define EMIT_BYTECODE STR,
 ) 
 

Value:

do {            \
    for (e = 0; e < bytecode->len; e += 3) {    \
      X(STR)                                    \
      {                                         \
        insert_opcode2(STR(bytecode)[e],        \
                       STR(bytecode)[e+1],      \
                       STR(bytecode)[e+2],      \
                       current_line,            \
                       current_file);           \
      }                                         \
    }                                           \
  } while(0)

#define EMIT_BYTECODE2  ) 
 

#define EMIT_BYTECODE2 STR   ) 
 

Value:

if (STR(bytecode)[e] == F_FILENAME) {           \
        INT32 strno = STR(bytecode)[e+1];               \
        if (SIGNED_CHAR(strno < 0) ||                   \
            (strno >= p->num_strings)) {                \
          Pike_error("Bad filename directive number:"   \
                     " %d (expected 0 - %d).\n",        \
                     strno, p->num_strings);            \
        }                                               \
        current_file = p->strings[strno];               \
      } else if (STR(bytecode)[e] == F_LINE) {          \
        current_line = STR(bytecode)[e+1];              \
      } else

#define ENCODE_DATA  ) 
 

Value:

switch((S)->size_shift)                 \
    {                                           \
      case 1:                                   \
        for(q=0;q<(S)->len;q++) {               \
           INT16 s=htons( STR1(S)[q] );         \
           addstr( (char *)&s, sizeof(s));      \
        }                                       \
        break;                                  \
      case 2:                                   \
        for(q=0;q<(S)->len;q++) {               \
           INT32 s=htonl( STR2(S)[q] );         \
           addstr( (char *)&s, sizeof(s));      \
        }                                       \
        break;                                  \
    }

#define FOO NUMTYPE,
TYPE,
ARGTYPE,
NAME   ) 
 

Value:

if (PIKE_CONCAT(local_num_, NAME) != p->PIKE_CONCAT(num_,NAME)) { \
            ref_push_program (p);                                       \
            decode_error(Pike_sp - 1, NULL,                             \
                         "Value mismatch for num_" TOSTR(NAME) ": "     \
                         "%"PRINTSIZET"d != %"PRINTSIZET"d "            \
                         "(bytecode method: %d)\n",                     \
                         (size_t) PIKE_CONCAT(local_num_, NAME),        \
                         (size_t) p->PIKE_CONCAT(num_, NAME),           \
                         bytecode_method);                              \
          }

#define FOO NUMTYPE,
TYPE,
ARGTYPE,
NAME   )     decode_number(PIKE_CONCAT(local_num_, NAME), data);
 

#define FOO NUMTYPE,
Y,
ARGTYPE,
NAME   )     NUMTYPE PIKE_CONCAT(local_num_, NAME) = 0;
 

#define FOO NUMTYPE,
TYPE,
ARGTYPE,
NAME   ) 
 

Value:

size=DO_ALIGN(size, ALIGNOF(TYPE)); \
          p->NAME=(TYPE *)(dat+size); \
          size+=p->PIKE_CONCAT(num_,NAME)*sizeof(p->NAME[0]);

#define FOO NUMTYPE,
TYPE,
ARGTYPE,
NAME   ) 
 

Value:

size=DO_ALIGN(size, ALIGNOF(TYPE)); \
          size+=p->PIKE_CONCAT(num_,NAME)*sizeof(p->NAME[0]);

#define FOO NUMTYPE,
TYPE,
ARGTYPE,
NAME   )     decode_number( p->PIKE_CONCAT(num_,NAME), data);
 

#define FOO NUMTYPE,
TYPE,
ARGTYPE,
NAME   )     code_number( p->PIKE_CONCAT(num_,NAME), data);
 

#define get_string_data STR,
LEN,
data   ) 
 

Value:

do {                                \
  if((LEN) == -1)                                                           \
  {                                                                         \
    INT32 what, e, num, numh;                                               \
    DECODE("get_string_data");                                              \
    what &= TAG_MASK;                                                       \
    if(data->ptr + num > data->len || num <0)                               \
      Pike_error("Failed to decode string. (string range error)\n");                \
    if(what<0 || what>2)                                                    \
      Pike_error("Failed to decode string. (Illegal size shift)\n");                \
    STR=begin_wide_shared_string(num, what);                                \
    MEMCPY(STR->str, data->data + data->ptr, num << what);                  \
    data->ptr+=(num << what);                                               \
    BITFLIP(STR);                                                           \
    STR=end_shared_string(STR);                                             \
  }else{                                                                    \
    if(data->ptr + (LEN) > data->len || (LEN) <0)                           \
      Pike_error("Failed to decode string. (string range error)\n");                \
    STR=make_shared_binary_string((char *)(data->data + data->ptr), (LEN)); \
    data->ptr+=(LEN);                                                       \
  }                                                                         \
}while(0)

 
#define GETC  )     my_extract_char(data)
 

#define getdata  ) 
 

Value:

do {                            \
   long length;                                 \
   decode_entry(TAG_STRING, length,data);       \
   if(data->pass == 1)                          \
     get_string_data(X, length, data);          \
   else                                         \
     data->ptr+=length;                         \
  }while(0)

#define getdata2 S,
 ) 
 

Value:

do {                                            \
      if(data->ptr + (ptrdiff_t)(sizeof(S[0])*(L)) > data->len)         \
        Pike_error("Failed to decode string. (string range error)\n");  \
      MEMCPY((S),(data->data + data->ptr), sizeof(S[0])*(L));           \
      data->ptr+=sizeof(S[0])*(L);                                      \
  }while(0)

#define getdata3  ) 
 

Value:

do {                                                 \
  INT32 what, e, num, numh;                                                  \
  DECODE("getdata3");                                                        \
  switch(what & TAG_MASK)                                                    \
  {                                                                          \
    case TAG_INT:                                                            \
      X=0;                                                                   \
      break;                                                                 \
                                                                             \
    case TAG_STRING:                                                         \
      get_string_data(X,num,data);                                           \
      break;                                                                 \
                                                                             \
    default:                                                                 \
      Pike_error("Failed to decode string, tag is wrong: %d\n",              \
            what & TAG_MASK);                                                \
    }                                                                        \
}while(0)

#define ID_ENTRY_CONSTANT   2
 

#define ID_ENTRY_EFUN_CONSTANT   -3
 

#define ID_ENTRY_EOT   -1
 

#define ID_ENTRY_FUNCTION   1
 

#define ID_ENTRY_INHERIT   3
 

#define ID_ENTRY_RAW   -2
 

#define ID_ENTRY_TYPE_CONSTANT   -4
 

#define ID_ENTRY_VARIABLE   0
 

#define MAX_SMALL   (1<<(8-SIZE_SHIFT))
 

#define Pike_FP_NINF   -2
 

#define Pike_FP_NZERO   1
 

#define Pike_FP_PINF   -1
 

#define Pike_FP_PZERO   0
 

#define Pike_FP_QNAN   -3
 

#define Pike_FP_SNAN   -4
 

#define Pike_FP_UNKNOWN   -4711
 

#define Pike_FP_ZERO   0
 

#define SETUP_DECODE_MEMOBJ TYPE,
U,
VAR,
ALLOCATE,
SCOUR   ) 
 

Value:

do {            \
  struct svalue *tmpptr;                                                \
  struct svalue tmp;                                                    \
  if(data->pass > 1 &&                                                  \
     (tmpptr=low_mapping_lookup(data->decoded, & entry_id)))            \
  {                                                                     \
    tmp=*tmpptr;                                                        \
    VAR=tmp.u.U;                                                        \
    SCOUR;                                                              \
  }else{                                                                \
    tmp.type=TYPE;                                                      \
    tmp.u.U=VAR=ALLOCATE;                                               \
    mapping_insert(data->decoded, & entry_id, &tmp);                    \
  /* Since a reference to the object is stored in the mapping, we can   \
   * safely decrease this reference here. Thus it will be automatically \
   * freed if something goes wrong.                                     \
   */                                                                   \
    sub_ref(VAR);                                                       \
  }                                                                     \
}while(0)

#define SIGNED_CHAR  )     0
 

#define SIGNED_CHAR  )     X
 

#define SIZE_SHIFT   6
 

#define TAG_AGAIN   15
 

#define TAG_ARRAY   0
 

#define TAG_DELAYED   14
 

#define TAG_FLOAT   7
 

#define TAG_FUNCTION   4
 

#define TAG_INT   8
 

#define TAG_MAPPING   1
 

#define TAG_MASK   15
 

#define TAG_MULTISET   2
 

#define TAG_NEG   16
 

#define TAG_OBJECT   3
 

#define TAG_PROGRAM   5
 

#define TAG_SMALL   32
 

#define TAG_STRING   6
 

#define TAG_TYPE   9
 


Function Documentation

void f_decode_value INT32  args  ) 
 

void f_encode_value INT32  args  ) 
 

void f_encode_value_canonic INT32  args  ) 
 


Generated on Fri Jul 22 23:44:28 2005 for Pike by  doxygen 1.3.9.1