Ignore:
Timestamp:
May 11, 2011, 1:26:15 AM (11 years ago)
Author:
Sam Hocevar
Message:

lisp: merge the Lisp and LispGC classes and improve coding style.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • abuse/trunk/src/lisp/lisp.h

    r635 r636  
    3838       L_FIXED_POINT, L_COLLECTED_OBJECT };
    3939
    40 typedef uint32_t ltype;    // make sure structures aren't packed differently on various compiler
     40typedef uint8_t ltype;    // make sure structures aren't packed differently on various compiler
    4141                       // and sure that word, etc are word aligned
    42 
    43 class Lisp
    44 {
    45 public:
    46     static void Init();
    47     static void Uninit();
    48 };
    4942
    5043struct LSpace
     
    7366    /* Methods */
    7467    LObject *Eval();
     68    LObject *Assoc(LObject *item);
    7569    void Print();
    7670
    7771    /* Members */
    78     ltype type;
     72    ltype m_type;
    7973};
    8074
     
    8579
    8680    /* Members */
    87     int index;
     81    int m_index;
    8882};
    8983
     
    9791
    9892    /* Members */
    99     LObject *cdr, *car;
     93    LObject *m_cdr, *m_car;
    10094};
    10195
     
    106100
    107101    /* Members */
    108     long num;
     102    long m_num;
    109103};
    110104
     
    112106{
    113107    /* Members */
    114     LObject *ref;
     108    LObject *m_ref;
    115109};
    116110
     
    127121    /* Members */
    128122private:
    129     char str[1]; /* Can be allocated much larger than 1 */
     123    char m_str[1]; /* Can be allocated much larger than 1 */
    130124};
    131125
     
    152146    float time_taken;
    153147#endif
    154     LObject *value;
    155     LObject *function;
    156     LString *name;
    157     LSymbol *left, *right; // tree structure
     148    LObject *m_value;
     149    LObject *m_function;
     150    LString *m_name;
     151    LSymbol *m_left, *m_right; // tree structure
    158152
    159153    /* Static members */
     
    183177
    184178    /* Methods */
    185     inline LObject **GetData() { return data; }
     179    inline LObject **GetData() { return m_data; }
    186180    LObject *Get(int x);
    187181
    188182    /* Members */
    189     size_t len;
     183    size_t m_len;
    190184
    191185private:
    192     LObject *data[1]; /* Can be allocated much larger than 1 */
     186    LObject *m_data[1]; /* Can be allocated much larger than 1 */
    193187};
    194188
     
    198192    static LChar *Create(uint16_t ch);
    199193
    200     /* Members */
    201     uint16_t ch;
     194    /* Methods */
     195    uint16_t GetValue();
     196
     197    /* Members */
     198    uint16_t m_ch;
    202199};
    203200
     
    208205
    209206    /* Members */
    210     void *addr;
     207    void *m_addr;
    211208};
    212209
     
    217214
    218215    /* Members */
    219     int32_t x;
    220 };
    221 
    222 static inline LObject *&CAR(void *x) { return ((LList *)x)->car; }
    223 static inline LObject *&CDR(void *x) { return ((LList *)x)->cdr; }
     216    int32_t m_fixed;
     217};
     218
     219class Lisp
     220{
     221public:
     222    static void Init();
     223    static void Uninit();
     224
     225    static void InitConstants();
     226
     227    // Collect temporary or permanent spaces
     228    static void CollectSpace(LSpace *which_space, int grow);
     229
     230private:
     231    static LArray *CollectArray(LArray *x);
     232    static LList *CollectList(LList *x);
     233    static LObject *CollectObject(LObject *x);
     234    static void CollectSymbols(LSymbol *root);
     235    static void CollectStacks();
     236};
     237
     238static inline LObject *&CAR(void *x) { return ((LList *)x)->m_car; }
     239static inline LObject *&CDR(void *x) { return ((LList *)x)->m_cdr; }
    224240static inline ltype item_type(void *x) { if (x) return *(ltype *)x; return L_CONS_CELL; }
    225241
     
    228244void *lpointer_value(void *lpointer);
    229245int32_t lnumber_value(void *lnumber);
    230 unsigned short lcharacter_value(void *c);
    231246long lfixed_point_value(void *c);
    232247void *lisp_atom(void *i);
     
    236251void *lisp_equal(void *n1, void *n2);
    237252void *eval_block(void *list);
    238 void *assoc(void *item, void *list);
    239253void resize_tmp(size_t new_size);
    240254void resize_perm(size_t new_size);
     
    258272
    259273int end_of_program(char *s);
    260 void lisp_init();
    261 void lisp_uninit();
    262274
    263275void *nth(int num, void *list);
     
    265277int32_t lisp_sin(int32_t x);
    266278int32_t lisp_cos(int32_t x);
    267 void restore_heap(void *val, int heap);
    268 void *mark_heap(int heap);
    269279
    270280extern "C" {
Note: See TracChangeset for help on using the changeset viewer.