Ignore:
Timestamp:
Apr 17, 2011, 10:28:12 AM (11 years ago)
Author:
Sam Hocevar
Message:

lisp: make all lisp object inherit a common type.

File:
1 edited

Legend:

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

    r481 r482  
    4343       L_FIXED_POINT, L_COLLECTED_OBJECT };
    4444
    45 typedef uint64_t ltype;    // make sure structures aren't packed differently on various compiler
     45typedef uint32_t ltype;    // make sure structures aren't packed differently on various compiler
    4646                       // and sure that word, etc are word aligned
    4747
    48 struct lisp_object_var
    49 {
    50   ltype type;
    51   long number;
    52 } ;
    53 
    54 struct cons_cell
    55 {
    56   ltype type;
    57   void *cdr,*car;
    58 } ;
    59 
    60 struct lisp_number
    61 {
    62   ltype type;
    63   long num;
    64 } ;
    65 
    66 struct lisp_collected_object
    67 {
    68   ltype type;
    69   void *new_reference;
    70 } ;
    71 
    72 struct lisp_symbol
    73 {
    74   ltype type;
     48struct LispObject
     49{
     50    ltype type;
     51};
     52
     53struct LispObjectVar : LispObject
     54{
     55    long number;
     56};
     57
     58struct LispList : LispObject
     59{
     60    void *cdr, *car;
     61};
     62
     63struct LispNumber : LispObject
     64{
     65    long num;
     66};
     67
     68struct LispRedirect : LispObject
     69{
     70    void *new_reference;
     71};
     72
     73struct LispSymbol : LispObject
     74{
    7575#ifdef L_PROFILE
    76   float time_taken;
    77 #endif
    78   void *value, *function, *name;
    79   lisp_symbol *left,*right;       // tree structure
    80 } ;
    81 
    82 struct lisp_sys_function
    83 {
    84   ltype type;
    85   short min_args,max_args,
    86         fun_number;
    87 } ;
    88 
    89 struct lisp_user_function
    90 {
    91   ltype type;
     76    float time_taken;
     77#endif
     78    void *value, *function, *name;
     79    LispSymbol *left, *right; // tree structure
     80};
     81
     82struct LispSysFunction : LispObject
     83{
     84    short min_args, max_args;
     85    short fun_number;
     86};
     87
     88struct LispUserFunction : LispObject
     89{
    9290#ifndef NO_LIBS
    93   intptr_t alist,blist;      // id for cached blocks
     91    intptr_t alist, blist;      // id for cached blocks
    9492#else
    95   void *arg_list,*block_list;
    96 #endif
    97 } ;
    98 
    99 struct lisp_1d_array
    100 {
    101   ltype type;
    102   unsigned short size;
    103   // size * sizeof (void *) follows1
    104 } ;
    105 
    106 struct lisp_string
    107 {
    108   ltype type;
    109 } ;
    110 
    111 struct lisp_character
    112 {
    113   ltype type;
    114   int16_t pad;
    115   uint16_t ch;
    116 } ;
    117 
    118 struct lisp_pointer
    119 {
    120   ltype type;
    121   void *addr;
    122 } ;
    123 
    124 
    125 struct lisp_fixed_point
    126 {
    127   ltype type;
    128   int32_t x;
    129 } ;
    130 
    131 static inline void *&CAR(void *x) { return ((cons_cell *)x)->car; }
    132 static inline void *&CDR(void *x) { return ((cons_cell *)x)->cdr; }
     93    void *arg_list, *block_list;
     94#endif
     95};
     96
     97struct LispArray : LispObject
     98{
     99    unsigned short size;
     100    // size * sizeof (void *) follows1
     101};
     102
     103struct LispString : LispObject
     104{
     105};
     106
     107struct LispChar : LispObject
     108{
     109    int16_t pad;
     110    uint16_t ch;
     111};
     112
     113struct LispPointer : LispObject
     114{
     115    void *addr;
     116};
     117
     118
     119struct LispFixedPoint : LispObject
     120{
     121    int32_t x;
     122};
     123
     124static inline void *&CAR(void *x) { return ((LispList *)x)->car; }
     125static inline void *&CDR(void *x) { return ((LispList *)x)->cdr; }
    133126
    134127void perm_space();
     
    147140void *lisp_eq(void *n1, void *n2);
    148141void *lisp_equal(void *n1, void *n2);
    149 lisp_symbol *find_symbol(char const *name);
     142LispSymbol *find_symbol(char const *name);
    150143long list_length(void *i);
    151144void lprint(void *i);
    152145void *eval(void *prog);
    153146void *eval_block(void *list);
    154 void *eval_function(lisp_symbol *sym, void *arg_list);
    155 void *eval_user_fun(lisp_symbol *sym, void *arg_list);
     147void *eval_function(LispSymbol *sym, void *arg_list);
     148void *eval_user_fun(LispSymbol *sym, void *arg_list);
    156149void *compile(char const *&s);
    157150void *symbol_value(void *symbol);
     
    163156void resize_tmp(int new_size);
    164157void resize_perm(int new_size);
    165 lisp_symbol *make_find_symbol(char const *name);
     158LispSymbol *make_find_symbol(char const *name);
    166159
    167160void push_onto_list(void *object, void *&list);
    168 lisp_symbol *add_c_object(void *symbol, int16_t number);
    169 lisp_symbol *add_c_function(char const *name, short min_args, short max_args, short number);
    170 lisp_symbol *add_c_bool_fun(char const *name, short min_args, short max_args, short number);
    171 lisp_symbol *add_lisp_function(char const *name, short min_args, short max_args, short number);
     161LispSymbol *add_c_object(void *symbol, int16_t number);
     162LispSymbol *add_c_function(char const *name, short min_args, short max_args, short number);
     163LispSymbol *add_c_bool_fun(char const *name, short min_args, short max_args, short number);
     164LispSymbol *add_lisp_function(char const *name, short min_args, short max_args, short number);
    172165int read_ltoken(char *&s, char *buffer);
    173 cons_cell *new_cons_cell();
     166LispList *new_cons_cell();
    174167void print_trace_stack(int max_levels);
    175168
    176169
    177 lisp_number *new_lisp_number(long num);
    178 lisp_pointer *new_lisp_pointer(void *addr);
    179 lisp_character *new_lisp_character(uint16_t ch);
    180 lisp_string *new_lisp_string(char const *string);
    181 lisp_string *new_lisp_string(char const *string, int length);
    182 lisp_string *new_lisp_string(int length);
    183 lisp_fixed_point *new_lisp_fixed_point(int32_t x);
    184 lisp_object_var *new_lisp_object_var(int16_t number);
    185 lisp_1d_array   *new_lisp_1d_array(int size, void *rest);
    186 lisp_sys_function *new_lisp_sys_function(int min_args, int max_args, int fun_number);
    187 lisp_sys_function *new_lisp_c_function(int min_args, int max_args, int fun_number);
    188 lisp_sys_function *new_lisp_c_bool(int min_args, int max_args, int fun_number);
     170LispNumber *new_lisp_number(long num);
     171LispPointer *new_lisp_pointer(void *addr);
     172LispChar *new_lisp_character(uint16_t ch);
     173LispString *new_lisp_string(char const *string);
     174LispString *new_lisp_string(char const *string, int length);
     175LispString *new_lisp_string(int length);
     176LispFixedPoint *new_lisp_fixed_point(int32_t x);
     177LispObjectVar *new_lisp_object_var(int16_t number);
     178LispArray   *new_lisp_1d_array(int size, void *rest);
     179LispSysFunction *new_lisp_sys_function(int min_args, int max_args, int fun_number);
     180LispSysFunction *new_lisp_c_function(int min_args, int max_args, int fun_number);
     181LispSysFunction *new_lisp_c_bool(int min_args, int max_args, int fun_number);
    189182
    190183#ifdef NO_LIBS
    191 lisp_user_function *new_lisp_user_function(void *arg_list, void *block_list);
     184LispUserFunction *new_lisp_user_function(void *arg_list, void *block_list);
    192185#else
    193 lisp_user_function *new_lisp_user_function(intptr_t arg_list, intptr_t block_list);
    194 #endif
    195 
    196 lisp_sys_function *new_user_lisp_function(int min_args, int max_args, int fun_number);
     186LispUserFunction *new_lisp_user_function(intptr_t arg_list, intptr_t block_list);
     187#endif
     188
     189LispSysFunction *new_user_lisp_function(int min_args, int max_args, int fun_number);
    197190
    198191int end_of_program(char *s);
     
    200193void lisp_init(long perm_size, long tmp_size);
    201194void lisp_uninit();
    202 extern lisp_symbol *lsym_root;
     195extern LispSymbol *lsym_root;
    203196
    204197extern uint8_t *space[4], *free_space[4];
Note: See TracChangeset for help on using the changeset viewer.