lac : 46ff2979ade76bf8654d79568ca74b699701ea4f

     1: #include "private.h"
     2: #include <string.h>
     3: 
     4: /*
     5:  * External type handling.
     6:  */
     7: 
     8: static lac_exttype_t *ext_types[LREG_TYPES];
     9: 
    10: #define EXTTY_IS_VALID(typeno) \
    11: 	( typeno > LREG_EXTT && typeno <= LREG_TYPES )
    12: 
    13: int
    14: lac_extty_register (unsigned typeno, lac_exttype_t * extty)
    15: {
    16:   if (!EXTTY_IS_VALID (typeno))
    17:     return -1;
    18:   ext_types[typeno] = extty;
    19:   return 0;
    20: }
    21: 
    22: unsigned
    23: lac_extty_get_type (lreg_t lr)
    24: {
    25:   struct treg_hdr *treg = lreg_raw_ptr (lr);
    26:   return treg->type;
    27: }
    28: 
    29: size_t
    30: lac_extty_get_size (lreg_t lr)
    31: {
    32:   struct treg_hdr *treg = lreg_raw_ptr (lr);
    33:   return treg->size;
    34: }
    35: 
    36: lreg_t
    37: lac_extty_box (unsigned typeno, void *ptr, size_t sz)
    38: {
    39:   struct treg_hdr *treg = lac_alloc (sizeof (struct treg_hdr) + sz);
    40:   treg->type = typeno;
    41:   treg->size = sz;
    42:   treg->ptr = ptr;
    43: 
    44:   return lreg_raw (treg, LREG_EXTT);
    45: }
    46: 
    47: 
    48: size_t
    49: lac_extty_unbox (lreg_t lr, void **ptr)
    50: {
    51:   struct treg_hdr *treg = lreg_raw_ptr (lr);
    52: 
    53:   if (ptr)
    54:     *ptr = treg->ptr;
    55:   return treg->size;
    56: }
    57: 
    58: int
    59: lac_extty_print (FILE * fd, lreg_t lr)
    60: {
    61:   unsigned typeno = lac_extty_get_type (lr);
    62:   if (EXTTY_IS_VALID (typeno) && ext_types[typeno] != NULL)
    63:     ext_types[typeno]->print (fd, lr);
    64:   else
    65:     return 0;
    66: 
    67:   return 1;
    68: }
    69: 
    70: int
    71: lacint_extty_equal (lreg_t arg1, lreg_t arg2)
    72: {
    73:   int rc = 0;
    74:   unsigned typeno1 = lac_extty_get_type (arg1);
    75:   unsigned typeno2 = lac_extty_get_type (arg2);
    76: 
    77:   if (!EXTTY_IS_VALID (typeno1)
    78:       || !EXTTY_IS_VALID (typeno2)
    79:       || typeno1 != typeno2 || ext_types[typeno1] == NULL)
    80:     raise_exception ("Internal error", NIL);
    81: 
    82:   if (ext_types[typeno1]->equal == NULL)
    83:     {
    84:       void *ptr1 = ((struct treg_hdr *) lreg_raw_ptr (arg1))->ptr;
    85:       void *ptr2 = ((struct treg_hdr *) lreg_raw_ptr (arg2))->ptr;
    86:       rc = ptr1 == ptr2;
    87:     }
    88:   else
    89:     rc = ext_types[typeno1]->equal (arg1, arg2);
    90: 
    91:   return rc;
    92: }

Generated by git2html.