static int create_synonyms (void) { static SLFUTURE_CONST char *names[8] = { "Int16_Type", "UInt16_Type", "Int32_Type", "UInt32_Type", "Int64_Type", "UInt64_Type", "Float32_Type", "Float64_Type" }; int types[8]; unsigned int i; memset ((char *) types, 0, sizeof (types)); /* The assumption is that sizeof(unsigned X) == sizeof (X) */ types[0] = _pSLANG_INT16_TYPE; types[1] = _pSLANG_UINT16_TYPE; types[2] = _pSLANG_INT32_TYPE; types[3] = _pSLANG_UINT32_TYPE; types[4] = _pSLANG_INT64_TYPE; types[5] = _pSLANG_UINT64_TYPE; #if SLANG_HAS_FLOAT #if SIZEOF_FLOAT == 4 types[6] = SLANG_FLOAT_TYPE; #else # if SIZEOF_DOUBLE == 4 types[6] = SLANG_DOUBLE_TYPE; # endif #endif #if SIZEOF_FLOAT == 8 types[7] = SLANG_FLOAT_TYPE; #else # if SIZEOF_DOUBLE == 8 types[7] = SLANG_DOUBLE_TYPE; # endif #endif #endif if ((-1 == SLclass_create_synonym ("Int_Type", SLANG_INT_TYPE)) || (-1 == SLclass_create_synonym ("UInt_Type", SLANG_UINT_TYPE))) return -1; for (i = 0; i < 8; i++) { if (types[i] == 0) continue; if (-1 == SLclass_create_synonym (names[i], types[i])) return -1; } for (i = 0; i < MAX_ARITHMETIC_TYPES; i++) { Alias_Map[i] = TABLE_INDEX_TO_TYPE(i); } #if SHORT_IS_INT Alias_Map [TYPE_TO_TABLE_INDEX(SLANG_SHORT_TYPE)] = SLANG_INT_TYPE; Alias_Map [TYPE_TO_TABLE_INDEX(SLANG_USHORT_TYPE)] = SLANG_UINT_TYPE; if ((-1 == SLclass_create_synonym ("Short_Type", SLANG_INT_TYPE)) || (-1 == SLclass_create_synonym ("UShort_Type", SLANG_UINT_TYPE)) || (-1 == _pSLclass_copy_class (SLANG_SHORT_TYPE, SLANG_INT_TYPE)) || (-1 == _pSLclass_copy_class (SLANG_USHORT_TYPE, SLANG_UINT_TYPE))) return -1; #endif #if LONG_IS_INT Alias_Map [TYPE_TO_TABLE_INDEX(SLANG_LONG_TYPE)] = SLANG_INT_TYPE; Alias_Map [TYPE_TO_TABLE_INDEX(SLANG_ULONG_TYPE)] = SLANG_UINT_TYPE; if ((-1 == SLclass_create_synonym ("Long_Type", SLANG_INT_TYPE)) || (-1 == SLclass_create_synonym ("ULong_Type", SLANG_UINT_TYPE)) || (-1 == _pSLclass_copy_class (SLANG_LONG_TYPE, SLANG_INT_TYPE)) || (-1 == _pSLclass_copy_class (SLANG_ULONG_TYPE, SLANG_UINT_TYPE))) return -1; #endif #if LLONG_IS_LONG Alias_Map [TYPE_TO_TABLE_INDEX(SLANG_LLONG_TYPE)] = _pSLANG_LONG_TYPE; Alias_Map [TYPE_TO_TABLE_INDEX(SLANG_ULLONG_TYPE)] = _pSLANG_ULONG_TYPE; if ((-1 == SLclass_create_synonym ("LLong_Type", _pSLANG_LONG_TYPE)) || (-1 == SLclass_create_synonym ("ULLong_Type", _pSLANG_ULONG_TYPE)) || (-1 == _pSLclass_copy_class (SLANG_LLONG_TYPE, _pSLANG_LONG_TYPE)) || (-1 == _pSLclass_copy_class (SLANG_ULLONG_TYPE, _pSLANG_ULONG_TYPE))) return -1; #endif return 0; }
int _pSLregister_types (void) { SLang_Class_Type *cl; #if 1 /* A good compiler should optimize this code away. */ if ((sizeof(short) != SIZEOF_SHORT) || (sizeof(int) != SIZEOF_INT) || (sizeof(long) != SIZEOF_LONG) || (sizeof(float) != SIZEOF_FLOAT) || (sizeof(double) != SIZEOF_DOUBLE)) SLang_exit_error ("S-Lang Library not built properly. Fix SIZEOF_* in config.h and recompile"); #endif if (-1 == _pSLclass_init ()) return -1; /* Undefined Type */ if (NULL == (cl = SLclass_allocate_class ("Undefined_Type"))) return -1; (void) SLclass_set_push_function (cl, undefined_method); (void) SLclass_set_pop_function (cl, undefined_method); (void) SLclass_set_destroy_function (cl, void_undefined_method); if (-1 == SLclass_register_class (cl, SLANG_UNDEFINED_TYPE, sizeof (int), SLANG_CLASS_TYPE_SCALAR)) return -1; /* Make Void_Type a synonym for Undefined_Type. Note that this does * not mean that Void_Type represents SLANG_VOID_TYPE. Void_Type is * used by array_map to indicate no array is to be created. */ if (-1 == SLclass_create_synonym ("Void_Type", SLANG_UNDEFINED_TYPE)) return -1; if (-1 == _pSLarith_register_types ()) return -1; /* SLANG_INTP_TYPE -- not used within the interpreter */ if (NULL == (cl = SLclass_allocate_class ("_IntegerP_Type"))) return -1; (void) SLclass_set_push_function (cl, intp_push); (void) SLclass_set_pop_function (cl, intp_pop); if (-1 == SLclass_register_class (cl, SLANG_INTP_TYPE, sizeof (int *), SLANG_CLASS_TYPE_SCALAR)) return -1; /* String Type */ if (NULL == (cl = SLclass_allocate_class ("String_Type"))) return -1; (void) SLclass_set_destroy_function (cl, string_destroy); (void) SLclass_set_push_function (cl, string_push); (void) SLclass_set_acopy_function (cl, string_acopy); cl->cl_foreach_open = _pSLbstring_foreach_open; cl->cl_foreach_close = _pSLbstring_foreach_close; cl->cl_foreach = _pSLbstring_foreach; cl->cl_cmp = string_cmp; if (-1 == SLclass_register_class (cl, SLANG_STRING_TYPE, sizeof (char *), SLANG_CLASS_TYPE_PTR)) return -1; /* ref Type */ if (NULL == (cl = SLclass_allocate_class ("Ref_Type"))) return -1; cl->cl_dereference = ref_dereference; cl->cl_push = ref_push; cl->cl_destroy = ref_destroy; cl->cl_string = ref_string; cl->cl_cmp = ref_cmp; if (-1 == SLclass_register_class (cl, SLANG_REF_TYPE, sizeof (SLang_Ref_Type *), SLANG_CLASS_TYPE_PTR)) return -1; /* NULL Type */ if (NULL == (cl = SLclass_allocate_class ("Null_Type"))) return -1; cl->cl_push = null_push; cl->cl_pop = null_pop; cl->cl_foreach_open = null_foreach_open; cl->cl_foreach_close = null_foreach_close; cl->cl_foreach = null_foreach; cl->cl_to_bool = null_to_bool; if (-1 == SLclass_register_class (cl, SLANG_NULL_TYPE, sizeof (char *), SLANG_CLASS_TYPE_SCALAR)) return -1; /* AnyType */ if (NULL == (cl = SLclass_allocate_class ("Any_Type"))) return -1; (void) SLclass_set_push_function (cl, anytype_push); (void) SLclass_set_destroy_function (cl, anytype_destroy); #if 0 (void) SLclass_set_apush_function (cl, anytype_apush); #endif cl->cl_dereference = anytype_dereference; if (-1 == SLclass_register_class (cl, SLANG_ANY_TYPE, sizeof (VOID_STAR), SLANG_CLASS_TYPE_PTR)) return -1; if (-1 == _pSLang_init_bstring ()) return -1; if ((-1 == SLclass_add_typecast (SLANG_STRING_TYPE, SLANG_INT_TYPE, string_to_int, 0)) || (-1 == SLclass_add_binary_op (SLANG_STRING_TYPE, SLANG_STRING_TYPE, string_string_bin_op, string_string_bin_op_result))) return -1; return 0; }