lac : d78530acb39b62b482c7bc34a16e499ac5223e8b

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

Generated by git2html.